diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-07-29 17:47:02 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-07-30 13:28:39 -0400 |
commit | 556a5bfc03c35c6f0b4e85ef6a19d00f0eb6dd00 (patch) | |
tree | 401e9b530eebe89f9a2a5df0840eeef63b4fd1c8 | |
parent | 85c71240a3e6c151038d9ed3fa88fc0fb80043fb (diff) |
6lowpan: iphc: use ipv6 api to check address scope
This patch removes the own implementation to check of link-layer,
broadcast and any address type and use the IPv6 api for that.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r-- | include/net/6lowpan.h | 13 | ||||
-rw-r--r-- | net/6lowpan/iphc.c | 29 |
2 files changed, 17 insertions, 25 deletions
diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h index 79b530fb2c4d..18010bce68c8 100644 --- a/include/net/6lowpan.h +++ b/include/net/6lowpan.h | |||
@@ -75,20 +75,10 @@ | |||
75 | (((a)->s6_addr[14]) == (m)[6]) && \ | 75 | (((a)->s6_addr[14]) == (m)[6]) && \ |
76 | (((a)->s6_addr[15]) == (m)[7])) | 76 | (((a)->s6_addr[15]) == (m)[7])) |
77 | 77 | ||
78 | /* ipv6 address is unspecified */ | ||
79 | #define is_addr_unspecified(a) \ | ||
80 | ((((a)->s6_addr32[0]) == 0) && \ | ||
81 | (((a)->s6_addr32[1]) == 0) && \ | ||
82 | (((a)->s6_addr32[2]) == 0) && \ | ||
83 | (((a)->s6_addr32[3]) == 0)) | ||
84 | |||
85 | /* compare ipv6 addresses prefixes */ | 78 | /* compare ipv6 addresses prefixes */ |
86 | #define ipaddr_prefixcmp(addr1, addr2, length) \ | 79 | #define ipaddr_prefixcmp(addr1, addr2, length) \ |
87 | (memcmp(addr1, addr2, length >> 3) == 0) | 80 | (memcmp(addr1, addr2, length >> 3) == 0) |
88 | 81 | ||
89 | /* local link, i.e. FE80::/10 */ | ||
90 | #define is_addr_link_local(a) (((a)->s6_addr16[0]) == htons(0xFE80)) | ||
91 | |||
92 | /* | 82 | /* |
93 | * check whether we can compress the IID to 16 bits, | 83 | * check whether we can compress the IID to 16 bits, |
94 | * it's possible for unicast adresses with first 49 bits are zero only. | 84 | * it's possible for unicast adresses with first 49 bits are zero only. |
@@ -100,9 +90,6 @@ | |||
100 | (((a)->s6_addr[12]) == 0xfe) && \ | 90 | (((a)->s6_addr[12]) == 0xfe) && \ |
101 | (((a)->s6_addr[13]) == 0)) | 91 | (((a)->s6_addr[13]) == 0)) |
102 | 92 | ||
103 | /* multicast address */ | ||
104 | #define is_addr_mcast(a) (((a)->s6_addr[0]) == 0xFF) | ||
105 | |||
106 | /* check whether the 112-bit gid of the multicast address is mappable to: */ | 93 | /* check whether the 112-bit gid of the multicast address is mappable to: */ |
107 | 94 | ||
108 | /* 9 bits, for FF02::1 (all nodes) and FF02::2 (all routers) addresses only. */ | 95 | /* 9 bits, for FF02::1 (all nodes) and FF02::2 (all routers) addresses only. */ |
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c index 636edd0f3724..d4fc2dd8ad75 100644 --- a/net/6lowpan/iphc.c +++ b/net/6lowpan/iphc.c | |||
@@ -611,6 +611,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
611 | u8 tmp, iphc0, iphc1, *hc_ptr; | 611 | u8 tmp, iphc0, iphc1, *hc_ptr; |
612 | struct ipv6hdr *hdr; | 612 | struct ipv6hdr *hdr; |
613 | u8 head[100] = {}; | 613 | u8 head[100] = {}; |
614 | int addr_type; | ||
614 | 615 | ||
615 | if (type != ETH_P_IPV6) | 616 | if (type != ETH_P_IPV6) |
616 | return -EINVAL; | 617 | return -EINVAL; |
@@ -720,23 +721,27 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
720 | sizeof(hdr->hop_limit)); | 721 | sizeof(hdr->hop_limit)); |
721 | } | 722 | } |
722 | 723 | ||
724 | addr_type = ipv6_addr_type(&hdr->saddr); | ||
723 | /* source address compression */ | 725 | /* source address compression */ |
724 | if (is_addr_unspecified(&hdr->saddr)) { | 726 | if (addr_type == IPV6_ADDR_ANY) { |
725 | pr_debug("source address is unspecified, setting SAC\n"); | 727 | pr_debug("source address is unspecified, setting SAC\n"); |
726 | iphc1 |= LOWPAN_IPHC_SAC; | 728 | iphc1 |= LOWPAN_IPHC_SAC; |
727 | /* TODO: context lookup */ | ||
728 | } else if (is_addr_link_local(&hdr->saddr)) { | ||
729 | iphc1 |= lowpan_compress_addr_64(&hc_ptr, | ||
730 | LOWPAN_IPHC_SAM_BIT, &hdr->saddr, _saddr); | ||
731 | pr_debug("source address unicast link-local %pI6c " | ||
732 | "iphc1 0x%02x\n", &hdr->saddr, iphc1); | ||
733 | } else { | 729 | } else { |
734 | pr_debug("send the full source address\n"); | 730 | if (addr_type & IPV6_ADDR_LINKLOCAL) { |
735 | lowpan_push_hc_data(&hc_ptr, &hdr->saddr.s6_addr[0], 16); | 731 | iphc1 |= lowpan_compress_addr_64(&hc_ptr, |
732 | LOWPAN_IPHC_SAM_BIT, | ||
733 | &hdr->saddr, _saddr); | ||
734 | pr_debug("source address unicast link-local %pI6c iphc1 0x%02x\n", | ||
735 | &hdr->saddr, iphc1); | ||
736 | } else { | ||
737 | pr_debug("send the full source address\n"); | ||
738 | lowpan_push_hc_data(&hc_ptr, hdr->saddr.s6_addr, 16); | ||
739 | } | ||
736 | } | 740 | } |
737 | 741 | ||
742 | addr_type = ipv6_addr_type(&hdr->daddr); | ||
738 | /* destination address compression */ | 743 | /* destination address compression */ |
739 | if (is_addr_mcast(&hdr->daddr)) { | 744 | if (addr_type & IPV6_ADDR_MULTICAST) { |
740 | pr_debug("destination address is multicast: "); | 745 | pr_debug("destination address is multicast: "); |
741 | iphc1 |= LOWPAN_IPHC_M; | 746 | iphc1 |= LOWPAN_IPHC_M; |
742 | if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) { | 747 | if (lowpan_is_mcast_addr_compressable8(&hdr->daddr)) { |
@@ -767,8 +772,8 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev, | |||
767 | lowpan_push_hc_data(&hc_ptr, hdr->daddr.s6_addr, 16); | 772 | lowpan_push_hc_data(&hc_ptr, hdr->daddr.s6_addr, 16); |
768 | } | 773 | } |
769 | } else { | 774 | } else { |
770 | /* TODO: context lookup */ | 775 | if (addr_type & IPV6_ADDR_LINKLOCAL) { |
771 | if (is_addr_link_local(&hdr->daddr)) { | 776 | /* TODO: context lookup */ |
772 | iphc1 |= lowpan_compress_addr_64(&hc_ptr, | 777 | iphc1 |= lowpan_compress_addr_64(&hc_ptr, |
773 | LOWPAN_IPHC_DAM_BIT, &hdr->daddr, _daddr); | 778 | LOWPAN_IPHC_DAM_BIT, &hdr->daddr, _daddr); |
774 | pr_debug("dest address unicast link-local %pI6c " | 779 | pr_debug("dest address unicast link-local %pI6c " |