diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-07-29 17:47:01 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-07-30 13:28:39 -0400 |
commit | 85c71240a3e6c151038d9ed3fa88fc0fb80043fb (patch) | |
tree | 3b1a1d5fbd7033b33ef68f155e4b10a2296da976 /net/6lowpan | |
parent | 4ebc960f9453d2610d150bef4fc9ca227bd33e22 (diff) |
6lowpan: iphc: cleanup use of lowpan_push_hc_data
This patch uses the lowpan_push_hc_data functions in several places
where we can use it. The lowpan_push_hc_data was introduced in some
previous patches.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/6lowpan')
-rw-r--r-- | net/6lowpan/iphc.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c index 0376684f28d0..636edd0f3724 100644 --- a/net/6lowpan/iphc.c +++ b/net/6lowpan/iphc.c | |||
@@ -532,15 +532,13 @@ static u8 lowpan_compress_addr_64(u8 **hc_ptr, u8 shift, | |||
532 | pr_debug("address compression 0 bits\n"); | 532 | pr_debug("address compression 0 bits\n"); |
533 | } else if (lowpan_is_iid_16_bit_compressable(ipaddr)) { | 533 | } else if (lowpan_is_iid_16_bit_compressable(ipaddr)) { |
534 | /* compress IID to 16 bits xxxx::XXXX */ | 534 | /* compress IID to 16 bits xxxx::XXXX */ |
535 | memcpy(*hc_ptr, &ipaddr->s6_addr16[7], 2); | 535 | lowpan_push_hc_data(hc_ptr, &ipaddr->s6_addr16[7], 2); |
536 | *hc_ptr += 2; | ||
537 | val = 2; /* 16-bits */ | 536 | val = 2; /* 16-bits */ |
538 | raw_dump_inline(NULL, "Compressed ipv6 addr is (16 bits)", | 537 | raw_dump_inline(NULL, "Compressed ipv6 addr is (16 bits)", |
539 | *hc_ptr - 2, 2); | 538 | *hc_ptr - 2, 2); |
540 | } else { | 539 | } else { |
541 | /* do not compress IID => xxxx::IID */ | 540 | /* do not compress IID => xxxx::IID */ |
542 | memcpy(*hc_ptr, &ipaddr->s6_addr16[4], 8); | 541 | lowpan_push_hc_data(hc_ptr, &ipaddr->s6_addr16[4], 8); |
543 | *hc_ptr += 8; | ||
544 | val = 1; /* 64-bits */ | 542 | val = 1; /* 64-bits */ |
545 | raw_dump_inline(NULL, "Compressed ipv6 addr is (64 bits)", | 543 | raw_dump_inline(NULL, "Compressed ipv6 addr is (64 bits)", |
546 | *hc_ptr - 8, 8); | 544 | *hc_ptr - 8, 8); |
@@ -696,10 +694,9 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
696 | if (hdr->nexthdr == UIP_PROTO_UDP) | 694 | if (hdr->nexthdr == UIP_PROTO_UDP) |
697 | iphc0 |= LOWPAN_IPHC_NH_C; | 695 | iphc0 |= LOWPAN_IPHC_NH_C; |
698 | 696 | ||
699 | if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) { | 697 | if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) |
700 | *hc_ptr = hdr->nexthdr; | 698 | lowpan_push_hc_data(&hc_ptr, &hdr->nexthdr, |
701 | hc_ptr += 1; | 699 | sizeof(hdr->nexthdr)); |
702 | } | ||
703 | 700 | ||
704 | /* | 701 | /* |
705 | * Hop limit | 702 | * Hop limit |
@@ -719,9 +716,8 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
719 | iphc0 |= LOWPAN_IPHC_TTL_255; | 716 | iphc0 |= LOWPAN_IPHC_TTL_255; |
720 | break; | 717 | break; |
721 | default: | 718 | default: |
722 | *hc_ptr = hdr->hop_limit; | 719 | lowpan_push_hc_data(&hc_ptr, &hdr->hop_limit, |
723 | hc_ptr += 1; | 720 | sizeof(hdr->hop_limit)); |
724 | break; | ||
725 | } | 721 | } |
726 | 722 | ||
727 | /* source address compression */ | 723 | /* source address compression */ |
@@ -736,8 +732,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
736 | "iphc1 0x%02x\n", &hdr->saddr, iphc1); | 732 | "iphc1 0x%02x\n", &hdr->saddr, iphc1); |
737 | } else { | 733 | } else { |
738 | pr_debug("send the full source address\n"); | 734 | pr_debug("send the full source address\n"); |
739 | memcpy(hc_ptr, &hdr->saddr.s6_addr16[0], 16); | 735 | lowpan_push_hc_data(&hc_ptr, &hdr->saddr.s6_addr[0], 16); |
740 | hc_ptr += 16; | ||
741 | } | 736 | } |
742 | 737 | ||
743 | /* destination address compression */ | 738 | /* destination address compression */ |
@@ -748,27 +743,28 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
748 | pr_debug("compressed to 1 octet\n"); | 743 | pr_debug("compressed to 1 octet\n"); |
749 | iphc1 |= LOWPAN_IPHC_DAM_11; | 744 | iphc1 |= LOWPAN_IPHC_DAM_11; |
750 | /* use last byte */ | 745 | /* use last byte */ |
751 | *hc_ptr = hdr->daddr.s6_addr[15]; | 746 | lowpan_push_hc_data(&hc_ptr, |
752 | hc_ptr += 1; | 747 | &hdr->daddr.s6_addr[15], 1); |
753 | } else if (lowpan_is_mcast_addr_compressable32(&hdr->daddr)) { | 748 | } else if (lowpan_is_mcast_addr_compressable32(&hdr->daddr)) { |
754 | pr_debug("compressed to 4 octets\n"); | 749 | pr_debug("compressed to 4 octets\n"); |
755 | iphc1 |= LOWPAN_IPHC_DAM_10; | 750 | iphc1 |= LOWPAN_IPHC_DAM_10; |
756 | /* second byte + the last three */ | 751 | /* second byte + the last three */ |
757 | *hc_ptr = hdr->daddr.s6_addr[1]; | 752 | lowpan_push_hc_data(&hc_ptr, |
758 | memcpy(hc_ptr + 1, &hdr->daddr.s6_addr[13], 3); | 753 | &hdr->daddr.s6_addr[1], 1); |
759 | hc_ptr += 4; | 754 | lowpan_push_hc_data(&hc_ptr, |
755 | &hdr->daddr.s6_addr[13], 3); | ||
760 | } else if (lowpan_is_mcast_addr_compressable48(&hdr->daddr)) { | 756 | } else if (lowpan_is_mcast_addr_compressable48(&hdr->daddr)) { |
761 | pr_debug("compressed to 6 octets\n"); | 757 | pr_debug("compressed to 6 octets\n"); |
762 | iphc1 |= LOWPAN_IPHC_DAM_01; | 758 | iphc1 |= LOWPAN_IPHC_DAM_01; |
763 | /* second byte + the last five */ | 759 | /* second byte + the last five */ |
764 | *hc_ptr = hdr->daddr.s6_addr[1]; | 760 | lowpan_push_hc_data(&hc_ptr, |
765 | memcpy(hc_ptr + 1, &hdr->daddr.s6_addr[11], 5); | 761 | &hdr->daddr.s6_addr[1], 1); |
766 | hc_ptr += 6; | 762 | lowpan_push_hc_data(&hc_ptr, |
763 | &hdr->daddr.s6_addr[11], 5); | ||
767 | } else { | 764 | } else { |
768 | pr_debug("using full address\n"); | 765 | pr_debug("using full address\n"); |
769 | iphc1 |= LOWPAN_IPHC_DAM_00; | 766 | iphc1 |= LOWPAN_IPHC_DAM_00; |
770 | memcpy(hc_ptr, &hdr->daddr.s6_addr[0], 16); | 767 | lowpan_push_hc_data(&hc_ptr, hdr->daddr.s6_addr, 16); |
771 | hc_ptr += 16; | ||
772 | } | 768 | } |
773 | } else { | 769 | } else { |
774 | /* TODO: context lookup */ | 770 | /* TODO: context lookup */ |
@@ -779,8 +775,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
779 | "iphc1 0x%02x\n", &hdr->daddr, iphc1); | 775 | "iphc1 0x%02x\n", &hdr->daddr, iphc1); |
780 | } else { | 776 | } else { |
781 | pr_debug("dest address unicast %pI6c\n", &hdr->daddr); | 777 | pr_debug("dest address unicast %pI6c\n", &hdr->daddr); |
782 | memcpy(hc_ptr, &hdr->daddr.s6_addr16[0], 16); | 778 | lowpan_push_hc_data(&hc_ptr, hdr->daddr.s6_addr, 16); |
783 | hc_ptr += 16; | ||
784 | } | 779 | } |
785 | } | 780 | } |
786 | 781 | ||