aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee802154
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2013-12-17 08:21:24 -0500
committerMarcel Holtmann <marcel@holtmann.org>2013-12-17 09:16:48 -0500
commite5d966eff3ac364e4505c7c4da632321657029b3 (patch)
treea2e6d1b2f9bc1211f9397894860674892c752b93 /net/ieee802154
parent95277eb1cdd63bd45dbd5a5f1a32b9d904d5f56d (diff)
6lowpan: fix udp byte ordering
The incoming udp header in lowpan_compress_udp_header function is already in network byte order. Everytime we read this values for source and destination port we need to convert this value to host byte order. In the outcoming header we need to set this value in network byte order which the upcoming process assumes. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/ieee802154')
-rw-r--r--net/ieee802154/6lowpan_iphc.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 1933f5b06718..02bf74d80e72 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -283,20 +283,21 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
283 break; 283 break;
284 case LOWPAN_NHC_UDP_CS_P_01: 284 case LOWPAN_NHC_UDP_CS_P_01:
285 memcpy(&uh->source, &skb->data[0], 2); 285 memcpy(&uh->source, &skb->data[0], 2);
286 uh->dest = 286 uh->dest = htons(skb->data[2] +
287 skb->data[2] + LOWPAN_NHC_UDP_8BIT_PORT; 287 LOWPAN_NHC_UDP_8BIT_PORT);
288 skb_pull(skb, 3); 288 skb_pull(skb, 3);
289 break; 289 break;
290 case LOWPAN_NHC_UDP_CS_P_10: 290 case LOWPAN_NHC_UDP_CS_P_10:
291 uh->source = skb->data[0] + LOWPAN_NHC_UDP_8BIT_PORT; 291 uh->source = htons(skb->data[0] +
292 LOWPAN_NHC_UDP_8BIT_PORT);
292 memcpy(&uh->dest, &skb->data[1], 2); 293 memcpy(&uh->dest, &skb->data[1], 2);
293 skb_pull(skb, 3); 294 skb_pull(skb, 3);
294 break; 295 break;
295 case LOWPAN_NHC_UDP_CS_P_11: 296 case LOWPAN_NHC_UDP_CS_P_11:
296 uh->source = 297 uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT +
297 LOWPAN_NHC_UDP_4BIT_PORT + (skb->data[0] >> 4); 298 (skb->data[0] >> 4));
298 uh->dest = 299 uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT +
299 LOWPAN_NHC_UDP_4BIT_PORT + (skb->data[0] & 0x0f); 300 (skb->data[0] & 0x0f));
300 skb_pull(skb, 1); 301 skb_pull(skb, 1);
301 break; 302 break;
302 default: 303 default:
@@ -306,7 +307,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
306 } 307 }
307 308
308 pr_debug("uncompressed UDP ports: src = %d, dst = %d\n", 309 pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
309 uh->source, uh->dest); 310 ntohs(uh->source), ntohs(uh->dest));
310 311
311 /* copy checksum */ 312 /* copy checksum */
312 memcpy(&uh->check, &skb->data[0], 2); 313 memcpy(&uh->check, &skb->data[0], 2);
@@ -318,7 +319,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
318 * frame 319 * frame
319 */ 320 */
320 uh->len = htons(skb->len + sizeof(struct udphdr)); 321 uh->len = htons(skb->len + sizeof(struct udphdr));
321 pr_debug("uncompressed UDP length: src = %d", uh->len); 322 pr_debug("uncompressed UDP length: src = %d", ntohs(uh->len));
322 } else { 323 } else {
323 pr_debug("ERROR: unsupported NH format\n"); 324 pr_debug("ERROR: unsupported NH format\n");
324 goto err; 325 goto err;
@@ -543,31 +544,31 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
543 struct udphdr *uh = udp_hdr(skb); 544 struct udphdr *uh = udp_hdr(skb);
544 u8 tmp; 545 u8 tmp;
545 546
546 if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) == 547 if (((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_MASK) ==
547 LOWPAN_NHC_UDP_4BIT_PORT) && 548 LOWPAN_NHC_UDP_4BIT_PORT) &&
548 ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) == 549 ((ntohs(uh->dest) & LOWPAN_NHC_UDP_4BIT_MASK) ==
549 LOWPAN_NHC_UDP_4BIT_PORT)) { 550 LOWPAN_NHC_UDP_4BIT_PORT)) {
550 pr_debug("UDP header: both ports compression to 4 bits\n"); 551 pr_debug("UDP header: both ports compression to 4 bits\n");
551 tmp = LOWPAN_NHC_UDP_CS_P_11; 552 tmp = LOWPAN_NHC_UDP_CS_P_11;
552 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 553 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
553 tmp = /* subtraction is faster */ 554 tmp = /* subtraction is faster */
554 (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) + 555 (u8)((ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT) +
555 ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4)); 556 ((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
556 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 557 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
557 } else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) == 558 } else if ((ntohs(uh->dest) & LOWPAN_NHC_UDP_8BIT_MASK) ==
558 LOWPAN_NHC_UDP_8BIT_PORT) { 559 LOWPAN_NHC_UDP_8BIT_PORT) {
559 pr_debug("UDP header: remove 8 bits of dest\n"); 560 pr_debug("UDP header: remove 8 bits of dest\n");
560 tmp = LOWPAN_NHC_UDP_CS_P_01; 561 tmp = LOWPAN_NHC_UDP_CS_P_01;
561 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 562 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
562 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source)); 563 lowpan_push_hc_data(hc06_ptr, &uh->source, sizeof(uh->source));
563 tmp = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT); 564 tmp = (u8)(ntohs(uh->dest) - LOWPAN_NHC_UDP_8BIT_PORT);
564 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 565 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
565 } else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) == 566 } else if ((ntohs(uh->source) & LOWPAN_NHC_UDP_8BIT_MASK) ==
566 LOWPAN_NHC_UDP_8BIT_PORT) { 567 LOWPAN_NHC_UDP_8BIT_PORT) {
567 pr_debug("UDP header: remove 8 bits of source\n"); 568 pr_debug("UDP header: remove 8 bits of source\n");
568 tmp = LOWPAN_NHC_UDP_CS_P_10; 569 tmp = LOWPAN_NHC_UDP_CS_P_10;
569 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 570 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
570 tmp = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT); 571 tmp = (u8)(ntohs(uh->source) - LOWPAN_NHC_UDP_8BIT_PORT);
571 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp)); 572 lowpan_push_hc_data(hc06_ptr, &tmp, sizeof(tmp));
572 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest)); 573 lowpan_push_hc_data(hc06_ptr, &uh->dest, sizeof(uh->dest));
573 } else { 574 } else {