1 #include <linux/version.h>
3 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
7 /* Function to set UDP checksum for an IPv4 UDP packet. This is intended
8 * for the simple case like when setting the checksum for a UDP tunnel.
10 void rpl_udp_set_csum(bool nocheck, struct sk_buff *skb,
11 __be32 saddr, __be32 daddr, int len)
13 struct udphdr *uh = udp_hdr(skb);
17 else if (skb_is_gso(skb))
18 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
19 else if (skb_dst(skb) && skb_dst(skb)->dev &&
20 (skb_dst(skb)->dev->features & NETIF_F_V4_CSUM)) {
22 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
24 skb->ip_summed = CHECKSUM_PARTIAL;
25 skb->csum_start = skb_transport_header(skb) - skb->head;
26 skb->csum_offset = offsetof(struct udphdr, check);
27 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
29 int l4_offset = skb_transport_offset(skb);
32 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
35 csum = skb_checksum(skb, l4_offset, len, 0);
36 uh->check = udp_v4_check(len, saddr, daddr, csum);
38 uh->check = CSUM_MANGLED_0;
40 skb->ip_summed = CHECKSUM_UNNECESSARY;
43 EXPORT_SYMBOL_GPL(rpl_udp_set_csum);
45 #endif /* Linux version < 3.16 */
47 #ifdef OVS_CHECK_UDP_TUNNEL_ZERO_CSUM
48 void rpl_udp6_csum_zero_error(struct sk_buff *skb)
50 /* RFC 2460 section 8.1 says that we SHOULD log
51 * this error. Well, it is reasonable.
53 net_dbg_ratelimited("IPv6: udp checksum is 0 for [%pI6c]:%u->[%pI6c]:%u\n",
54 &ipv6_hdr(skb)->saddr, ntohs(udp_hdr(skb)->source),
55 &ipv6_hdr(skb)->daddr, ntohs(udp_hdr(skb)->dest));