aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/ip6_checksum.c
diff options
context:
space:
mode:
authorTom Herbert <therbert@google.com>2014-06-04 20:19:48 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-05 01:46:38 -0400
commitaf5fcba7f38f3166392f4087ab734433c84f160b (patch)
tree8a6deba10cd458a72e159112ab6381bcaa352b3e /net/ipv6/ip6_checksum.c
parent6579867c8b02606e101a6c511c2511b027ed3f4a (diff)
udp: Generic functions to set checksum
Added udp_set_csum and udp6_set_csum functions to set UDP checksums in packets. These are for simple UDP packets such as those that might be created in UDP tunnels. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/ip6_checksum.c')
-rw-r--r--net/ipv6/ip6_checksum.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/net/ipv6/ip6_checksum.c b/net/ipv6/ip6_checksum.c
index da26224a5993..9a4d7322fb22 100644
--- a/net/ipv6/ip6_checksum.c
+++ b/net/ipv6/ip6_checksum.c
@@ -84,3 +84,41 @@ int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto)
84 ip6_compute_pseudo); 84 ip6_compute_pseudo);
85} 85}
86EXPORT_SYMBOL(udp6_csum_init); 86EXPORT_SYMBOL(udp6_csum_init);
87
88/* Function to set UDP checksum for an IPv6 UDP packet. This is intended
89 * for the simple case like when setting the checksum for a UDP tunnel.
90 */
91void udp6_set_csum(bool nocheck, struct sk_buff *skb,
92 const struct in6_addr *saddr,
93 const struct in6_addr *daddr, int len)
94{
95 struct udphdr *uh = udp_hdr(skb);
96
97 if (nocheck)
98 uh->check = 0;
99 else if (skb_is_gso(skb))
100 uh->check = ~udp_v6_check(len, saddr, daddr, 0);
101 else if (skb_dst(skb) && skb_dst(skb)->dev &&
102 (skb_dst(skb)->dev->features & NETIF_F_IPV6_CSUM)) {
103
104 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
105
106 skb->ip_summed = CHECKSUM_PARTIAL;
107 skb->csum_start = skb_transport_header(skb) - skb->head;
108 skb->csum_offset = offsetof(struct udphdr, check);
109 uh->check = ~udp_v6_check(len, saddr, daddr, 0);
110 } else {
111 __wsum csum;
112
113 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
114
115 uh->check = 0;
116 csum = skb_checksum(skb, 0, len, 0);
117 uh->check = udp_v6_check(len, saddr, daddr, csum);
118 if (uh->check == 0)
119 uh->check = CSUM_MANGLED_0;
120
121 skb->ip_summed = CHECKSUM_UNNECESSARY;
122 }
123}
124EXPORT_SYMBOL(udp6_set_csum);