diff options
author | Cong Wang <amwang@redhat.com> | 2013-01-07 15:52:40 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-08 20:56:10 -0500 |
commit | acb3e04119fbf9145eb6d6bb707f6fb662ab4d3b (patch) | |
tree | 16e6114957ce9d739dc3c0c63de3b7d52dd8812c /net/ipv6 | |
parent | b7394d2429c198b1da3d46ac39192e891029ec0f (diff) |
ipv6: move csum_ipv6_magic() and udp6_csum_init() into static library
As suggested by David, udp6_csum_init() is too big to be inlined,
move it to ipv6 static library, net/ipv6/ip6_checksum.c.
And the generic csum_ipv6_magic() too.
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/Makefile | 2 | ||||
-rw-r--r-- | net/ipv6/ip6_checksum.c | 97 | ||||
-rw-r--r-- | net/ipv6/udp.c | 34 |
3 files changed, 98 insertions, 35 deletions
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile index 4ea244891b58..309af19a0a0a 100644 --- a/net/ipv6/Makefile +++ b/net/ipv6/Makefile | |||
@@ -40,7 +40,7 @@ obj-$(CONFIG_IPV6_SIT) += sit.o | |||
40 | obj-$(CONFIG_IPV6_TUNNEL) += ip6_tunnel.o | 40 | obj-$(CONFIG_IPV6_TUNNEL) += ip6_tunnel.o |
41 | obj-$(CONFIG_IPV6_GRE) += ip6_gre.o | 41 | obj-$(CONFIG_IPV6_GRE) += ip6_gre.o |
42 | 42 | ||
43 | obj-y += addrconf_core.o exthdrs_core.o | 43 | obj-y += addrconf_core.o exthdrs_core.o ip6_checksum.o |
44 | obj-$(CONFIG_INET) += output_core.o protocol.o $(ipv6-offload) | 44 | obj-$(CONFIG_INET) += output_core.o protocol.o $(ipv6-offload) |
45 | 45 | ||
46 | obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o | 46 | obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o |
diff --git a/net/ipv6/ip6_checksum.c b/net/ipv6/ip6_checksum.c new file mode 100644 index 000000000000..72d198b8e4d2 --- /dev/null +++ b/net/ipv6/ip6_checksum.c | |||
@@ -0,0 +1,97 @@ | |||
1 | #include <net/ip.h> | ||
2 | #include <net/udp.h> | ||
3 | #include <net/udplite.h> | ||
4 | #include <asm/checksum.h> | ||
5 | |||
6 | #ifndef _HAVE_ARCH_IPV6_CSUM | ||
7 | __sum16 csum_ipv6_magic(const struct in6_addr *saddr, | ||
8 | const struct in6_addr *daddr, | ||
9 | __u32 len, unsigned short proto, | ||
10 | __wsum csum) | ||
11 | { | ||
12 | |||
13 | int carry; | ||
14 | __u32 ulen; | ||
15 | __u32 uproto; | ||
16 | __u32 sum = (__force u32)csum; | ||
17 | |||
18 | sum += (__force u32)saddr->s6_addr32[0]; | ||
19 | carry = (sum < (__force u32)saddr->s6_addr32[0]); | ||
20 | sum += carry; | ||
21 | |||
22 | sum += (__force u32)saddr->s6_addr32[1]; | ||
23 | carry = (sum < (__force u32)saddr->s6_addr32[1]); | ||
24 | sum += carry; | ||
25 | |||
26 | sum += (__force u32)saddr->s6_addr32[2]; | ||
27 | carry = (sum < (__force u32)saddr->s6_addr32[2]); | ||
28 | sum += carry; | ||
29 | |||
30 | sum += (__force u32)saddr->s6_addr32[3]; | ||
31 | carry = (sum < (__force u32)saddr->s6_addr32[3]); | ||
32 | sum += carry; | ||
33 | |||
34 | sum += (__force u32)daddr->s6_addr32[0]; | ||
35 | carry = (sum < (__force u32)daddr->s6_addr32[0]); | ||
36 | sum += carry; | ||
37 | |||
38 | sum += (__force u32)daddr->s6_addr32[1]; | ||
39 | carry = (sum < (__force u32)daddr->s6_addr32[1]); | ||
40 | sum += carry; | ||
41 | |||
42 | sum += (__force u32)daddr->s6_addr32[2]; | ||
43 | carry = (sum < (__force u32)daddr->s6_addr32[2]); | ||
44 | sum += carry; | ||
45 | |||
46 | sum += (__force u32)daddr->s6_addr32[3]; | ||
47 | carry = (sum < (__force u32)daddr->s6_addr32[3]); | ||
48 | sum += carry; | ||
49 | |||
50 | ulen = (__force u32)htonl((__u32) len); | ||
51 | sum += ulen; | ||
52 | carry = (sum < ulen); | ||
53 | sum += carry; | ||
54 | |||
55 | uproto = (__force u32)htonl(proto); | ||
56 | sum += uproto; | ||
57 | carry = (sum < uproto); | ||
58 | sum += carry; | ||
59 | |||
60 | return csum_fold((__force __wsum)sum); | ||
61 | } | ||
62 | EXPORT_SYMBOL(csum_ipv6_magic); | ||
63 | #endif | ||
64 | |||
65 | int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto) | ||
66 | { | ||
67 | int err; | ||
68 | |||
69 | UDP_SKB_CB(skb)->partial_cov = 0; | ||
70 | UDP_SKB_CB(skb)->cscov = skb->len; | ||
71 | |||
72 | if (proto == IPPROTO_UDPLITE) { | ||
73 | err = udplite_checksum_init(skb, uh); | ||
74 | if (err) | ||
75 | return err; | ||
76 | } | ||
77 | |||
78 | if (uh->check == 0) { | ||
79 | /* RFC 2460 section 8.1 says that we SHOULD log | ||
80 | this error. Well, it is reasonable. | ||
81 | */ | ||
82 | LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n"); | ||
83 | return 1; | ||
84 | } | ||
85 | if (skb->ip_summed == CHECKSUM_COMPLETE && | ||
86 | !csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, | ||
87 | skb->len, proto, skb->csum)) | ||
88 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
89 | |||
90 | if (!skb_csum_unnecessary(skb)) | ||
91 | skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | ||
92 | &ipv6_hdr(skb)->daddr, | ||
93 | skb->len, proto, 0)); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | EXPORT_SYMBOL(udp6_csum_init); | ||
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index dfaa29b8b293..1afb635d9b57 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -752,40 +752,6 @@ static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb, | |||
752 | return 0; | 752 | return 0; |
753 | } | 753 | } |
754 | 754 | ||
755 | static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, | ||
756 | int proto) | ||
757 | { | ||
758 | int err; | ||
759 | |||
760 | UDP_SKB_CB(skb)->partial_cov = 0; | ||
761 | UDP_SKB_CB(skb)->cscov = skb->len; | ||
762 | |||
763 | if (proto == IPPROTO_UDPLITE) { | ||
764 | err = udplite_checksum_init(skb, uh); | ||
765 | if (err) | ||
766 | return err; | ||
767 | } | ||
768 | |||
769 | if (uh->check == 0) { | ||
770 | /* RFC 2460 section 8.1 says that we SHOULD log | ||
771 | this error. Well, it is reasonable. | ||
772 | */ | ||
773 | LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n"); | ||
774 | return 1; | ||
775 | } | ||
776 | if (skb->ip_summed == CHECKSUM_COMPLETE && | ||
777 | !csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, | ||
778 | skb->len, proto, skb->csum)) | ||
779 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
780 | |||
781 | if (!skb_csum_unnecessary(skb)) | ||
782 | skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | ||
783 | &ipv6_hdr(skb)->daddr, | ||
784 | skb->len, proto, 0)); | ||
785 | |||
786 | return 0; | ||
787 | } | ||
788 | |||
789 | int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, | 755 | int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, |
790 | int proto) | 756 | int proto) |
791 | { | 757 | { |