aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAndrea Bittau <a.bittau@cs.ucl.ac.uk>2006-03-20 22:23:32 -0500
committerDavid S. Miller <davem@davemloft.net>2006-03-20 22:23:32 -0500
commit60fe62e789076ae7c13f7ffb35fec4b24802530d (patch)
treecc8d507a4276c3d5a2bcb72746660d485bc2e045 /net
parenta193a4abdd1f742a57f3f70b6a83c3e536876e97 (diff)
[DCCP]: sparse endianness annotations
This also fixes the layout of dccp_hdr short sequence numbers, problem was not fatal now as we only support long (48 bits) sequence numbers. Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk> Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/dccp/ccids/ccid3.c6
-rw-r--r--net/dccp/dccp.h23
-rw-r--r--net/dccp/ipv4.c12
-rw-r--r--net/dccp/ipv6.c4
-rw-r--r--net/dccp/options.c27
-rw-r--r--net/dccp/proto.c6
6 files changed, 33 insertions, 45 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 0587f52e4af1..86201631fb6e 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -615,7 +615,7 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
615 __FUNCTION__, dccp_role(sk), sk); 615 __FUNCTION__, dccp_role(sk), sk);
616 rc = -EINVAL; 616 rc = -EINVAL;
617 } else { 617 } else {
618 opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); 618 opt_recv->ccid3or_loss_event_rate = ntohl(*(__be32 *)value);
619 ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", 619 ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n",
620 dccp_role(sk), sk, 620 dccp_role(sk), sk,
621 opt_recv->ccid3or_loss_event_rate); 621 opt_recv->ccid3or_loss_event_rate);
@@ -636,7 +636,7 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
636 __FUNCTION__, dccp_role(sk), sk); 636 __FUNCTION__, dccp_role(sk), sk);
637 rc = -EINVAL; 637 rc = -EINVAL;
638 } else { 638 } else {
639 opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); 639 opt_recv->ccid3or_receive_rate = ntohl(*(__be32 *)value);
640 ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", 640 ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n",
641 dccp_role(sk), sk, 641 dccp_role(sk), sk,
642 opt_recv->ccid3or_receive_rate); 642 opt_recv->ccid3or_receive_rate);
@@ -777,7 +777,7 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
777static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 777static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
778{ 778{
779 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 779 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
780 u32 x_recv, pinv; 780 __be32 x_recv, pinv;
781 781
782 BUG_ON(hcrx == NULL); 782 BUG_ON(hcrx == NULL);
783 783
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 93f26dd6e6cb..1764adb4f15e 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -262,7 +262,7 @@ extern int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
262 int addr_len); 262 int addr_len);
263 263
264extern int dccp_v4_checksum(const struct sk_buff *skb, 264extern int dccp_v4_checksum(const struct sk_buff *skb,
265 const u32 saddr, const u32 daddr); 265 const __be32 saddr, const __be32 daddr);
266 266
267extern int dccp_v4_send_reset(struct sock *sk, 267extern int dccp_v4_send_reset(struct sock *sk,
268 enum dccp_reset_codes code); 268 enum dccp_reset_codes code);
@@ -270,7 +270,7 @@ extern void dccp_send_close(struct sock *sk, const int active);
270extern int dccp_invalid_packet(struct sk_buff *skb); 270extern int dccp_invalid_packet(struct sk_buff *skb);
271 271
272static inline int dccp_bad_service_code(const struct sock *sk, 272static inline int dccp_bad_service_code(const struct sock *sk,
273 const __u32 service) 273 const __be32 service)
274{ 274{
275 const struct dccp_sock *dp = dccp_sk(sk); 275 const struct dccp_sock *dp = dccp_sk(sk);
276 276
@@ -334,27 +334,16 @@ static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss)
334{ 334{
335 struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh + 335 struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh +
336 sizeof(*dh)); 336 sizeof(*dh));
337 337 dh->dccph_seq2 = 0;
338#if defined(__LITTLE_ENDIAN_BITFIELD) 338 dh->dccph_seq = htons((gss >> 32) & 0xfffff);
339 dh->dccph_seq = htonl((gss >> 32)) >> 8;
340#elif defined(__BIG_ENDIAN_BITFIELD)
341 dh->dccph_seq = htonl((gss >> 32));
342#else
343#error "Adjust your <asm/byteorder.h> defines"
344#endif
345 dhx->dccph_seq_low = htonl(gss & 0xffffffff); 339 dhx->dccph_seq_low = htonl(gss & 0xffffffff);
346} 340}
347 341
348static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack, 342static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack,
349 const u64 gsr) 343 const u64 gsr)
350{ 344{
351#if defined(__LITTLE_ENDIAN_BITFIELD) 345 dhack->dccph_reserved1 = 0;
352 dhack->dccph_ack_nr_high = htonl((gsr >> 32)) >> 8; 346 dhack->dccph_ack_nr_high = htons(gsr >> 32);
353#elif defined(__BIG_ENDIAN_BITFIELD)
354 dhack->dccph_ack_nr_high = htonl((gsr >> 32));
355#else
356#error "Adjust your <asm/byteorder.h> defines"
357#endif
358 dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff); 347 dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff);
359} 348}
360 349
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index aa7708fed32e..be5ce57b8046 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -498,9 +498,9 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
498 struct dccp_sock dp; 498 struct dccp_sock dp;
499 struct request_sock *req; 499 struct request_sock *req;
500 struct dccp_request_sock *dreq; 500 struct dccp_request_sock *dreq;
501 const __u32 saddr = skb->nh.iph->saddr; 501 const __be32 saddr = skb->nh.iph->saddr;
502 const __u32 daddr = skb->nh.iph->daddr; 502 const __be32 daddr = skb->nh.iph->daddr;
503 const __u32 service = dccp_hdr_request(skb)->dccph_req_service; 503 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
504 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 504 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
505 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 505 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
506 506
@@ -662,8 +662,8 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
662 return sk; 662 return sk;
663} 663}
664 664
665int dccp_v4_checksum(const struct sk_buff *skb, const u32 saddr, 665int dccp_v4_checksum(const struct sk_buff *skb, const __be32 saddr,
666 const u32 daddr) 666 const __be32 daddr)
667{ 667{
668 const struct dccp_hdr* dh = dccp_hdr(skb); 668 const struct dccp_hdr* dh = dccp_hdr(skb);
669 int checksum_len; 669 int checksum_len;
@@ -683,7 +683,7 @@ int dccp_v4_checksum(const struct sk_buff *skb, const u32 saddr,
683} 683}
684 684
685static int dccp_v4_verify_checksum(struct sk_buff *skb, 685static int dccp_v4_verify_checksum(struct sk_buff *skb,
686 const u32 saddr, const u32 daddr) 686 const __be32 saddr, const __be32 daddr)
687{ 687{
688 struct dccp_hdr *dh = dccp_hdr(skb); 688 struct dccp_hdr *dh = dccp_hdr(skb);
689 int checksum_len; 689 int checksum_len;
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 80c4d048869e..ad5a1c66362d 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -264,7 +264,7 @@ failure:
264} 264}
265 265
266static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 266static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
267 int type, int code, int offset, __u32 info) 267 int type, int code, int offset, __be32 info)
268{ 268{
269 struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data; 269 struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
270 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset); 270 const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
@@ -678,7 +678,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
678 struct dccp_request_sock *dreq; 678 struct dccp_request_sock *dreq;
679 struct inet6_request_sock *ireq6; 679 struct inet6_request_sock *ireq6;
680 struct ipv6_pinfo *np = inet6_sk(sk); 680 struct ipv6_pinfo *np = inet6_sk(sk);
681 const __u32 service = dccp_hdr_request(skb)->dccph_req_service; 681 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
682 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 682 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
683 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 683 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
684 684
diff --git a/net/dccp/options.c b/net/dccp/options.c
index 7f99306c8e99..7d73b33a6043 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -155,7 +155,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
155 if (len != 4) 155 if (len != 4)
156 goto out_invalid_option; 156 goto out_invalid_option;
157 157
158 opt_recv->dccpor_timestamp = ntohl(*(u32 *)value); 158 opt_recv->dccpor_timestamp = ntohl(*(__be32 *)value);
159 159
160 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp; 160 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp;
161 dccp_timestamp(sk, &dp->dccps_timestamp_time); 161 dccp_timestamp(sk, &dp->dccps_timestamp_time);
@@ -169,7 +169,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
169 if (len != 4 && len != 6 && len != 8) 169 if (len != 4 && len != 6 && len != 8)
170 goto out_invalid_option; 170 goto out_invalid_option;
171 171
172 opt_recv->dccpor_timestamp_echo = ntohl(*(u32 *)value); 172 opt_recv->dccpor_timestamp_echo = ntohl(*(__be32 *)value);
173 173
174 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ", 174 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ",
175 debug_prefix, 175 debug_prefix,
@@ -183,9 +183,9 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
183 break; 183 break;
184 184
185 if (len == 6) 185 if (len == 6)
186 elapsed_time = ntohs(*(u16 *)(value + 4)); 186 elapsed_time = ntohs(*(__be16 *)(value + 4));
187 else 187 else
188 elapsed_time = ntohl(*(u32 *)(value + 4)); 188 elapsed_time = ntohl(*(__be32 *)(value + 4));
189 189
190 /* Give precedence to the biggest ELAPSED_TIME */ 190 /* Give precedence to the biggest ELAPSED_TIME */
191 if (elapsed_time > opt_recv->dccpor_elapsed_time) 191 if (elapsed_time > opt_recv->dccpor_elapsed_time)
@@ -199,9 +199,9 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
199 continue; 199 continue;
200 200
201 if (len == 2) 201 if (len == 2)
202 elapsed_time = ntohs(*(u16 *)value); 202 elapsed_time = ntohs(*(__be16 *)value);
203 else 203 else
204 elapsed_time = ntohl(*(u32 *)value); 204 elapsed_time = ntohl(*(__be32 *)value);
205 205
206 if (elapsed_time > opt_recv->dccpor_elapsed_time) 206 if (elapsed_time > opt_recv->dccpor_elapsed_time)
207 opt_recv->dccpor_elapsed_time = elapsed_time; 207 opt_recv->dccpor_elapsed_time = elapsed_time;
@@ -358,10 +358,10 @@ void dccp_insert_option_elapsed_time(struct sock *sk,
358 *to++ = len; 358 *to++ = len;
359 359
360 if (elapsed_time_len == 2) { 360 if (elapsed_time_len == 2) {
361 const u16 var16 = htons((u16)elapsed_time); 361 const __be16 var16 = htons((u16)elapsed_time);
362 memcpy(to, &var16, 2); 362 memcpy(to, &var16, 2);
363 } else { 363 } else {
364 const u32 var32 = htonl(elapsed_time); 364 const __be32 var32 = htonl(elapsed_time);
365 memcpy(to, &var32, 4); 365 memcpy(to, &var32, 4);
366 } 366 }
367 367
@@ -392,14 +392,13 @@ EXPORT_SYMBOL_GPL(dccp_timestamp);
392void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb) 392void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb)
393{ 393{
394 struct timeval tv; 394 struct timeval tv;
395 u32 now; 395 __be32 now;
396 396
397 dccp_timestamp(sk, &tv); 397 dccp_timestamp(sk, &tv);
398 now = timeval_usecs(&tv) / 10; 398 now = htonl(timeval_usecs(&tv) / 10);
399 /* yes this will overflow but that is the point as we want a 399 /* yes this will overflow but that is the point as we want a
400 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */ 400 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */
401 401
402 now = htonl(now);
403 dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now)); 402 dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now));
404} 403}
405 404
@@ -414,7 +413,7 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
414 "CLIENT TX opt: " : "server TX opt: "; 413 "CLIENT TX opt: " : "server TX opt: ";
415#endif 414#endif
416 struct timeval now; 415 struct timeval now;
417 u32 tstamp_echo; 416 __be32 tstamp_echo;
418 u32 elapsed_time; 417 u32 elapsed_time;
419 int len, elapsed_time_len; 418 int len, elapsed_time_len;
420 unsigned char *to; 419 unsigned char *to;
@@ -441,10 +440,10 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
441 to += 4; 440 to += 4;
442 441
443 if (elapsed_time_len == 2) { 442 if (elapsed_time_len == 2) {
444 const u16 var16 = htons((u16)elapsed_time); 443 const __be16 var16 = htons((u16)elapsed_time);
445 memcpy(to, &var16, 2); 444 memcpy(to, &var16, 2);
446 } else if (elapsed_time_len == 4) { 445 } else if (elapsed_time_len == 4) {
447 const u32 var32 = htonl(elapsed_time); 446 const __be32 var32 = htonl(elapsed_time);
448 memcpy(to, &var32, 4); 447 memcpy(to, &var32, 4);
449 } 448 }
450 449
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 1a8cf8ecfe63..53735ee2bbd1 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -221,7 +221,7 @@ int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg)
221 221
222EXPORT_SYMBOL_GPL(dccp_ioctl); 222EXPORT_SYMBOL_GPL(dccp_ioctl);
223 223
224static int dccp_setsockopt_service(struct sock *sk, const u32 service, 224static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
225 char __user *optval, int optlen) 225 char __user *optval, int optlen)
226{ 226{
227 struct dccp_sock *dp = dccp_sk(sk); 227 struct dccp_sock *dp = dccp_sk(sk);
@@ -349,7 +349,7 @@ int dccp_setsockopt(struct sock *sk, int level, int optname,
349EXPORT_SYMBOL_GPL(dccp_setsockopt); 349EXPORT_SYMBOL_GPL(dccp_setsockopt);
350 350
351static int dccp_getsockopt_service(struct sock *sk, int len, 351static int dccp_getsockopt_service(struct sock *sk, int len,
352 u32 __user *optval, 352 __be32 __user *optval,
353 int __user *optlen) 353 int __user *optlen)
354{ 354{
355 const struct dccp_sock *dp = dccp_sk(sk); 355 const struct dccp_sock *dp = dccp_sk(sk);
@@ -404,7 +404,7 @@ int dccp_getsockopt(struct sock *sk, int level, int optname,
404 break; 404 break;
405 case DCCP_SOCKOPT_SERVICE: 405 case DCCP_SOCKOPT_SERVICE:
406 return dccp_getsockopt_service(sk, len, 406 return dccp_getsockopt_service(sk, len,
407 (u32 __user *)optval, optlen); 407 (__be32 __user *)optval, optlen);
408 case 128 ... 191: 408 case 128 ... 191:
409 return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname, 409 return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname,
410 len, (u32 __user *)optval, optlen); 410 len, (u32 __user *)optval, optlen);