diff options
author | Tom Herbert <therbert@google.com> | 2014-09-20 17:52:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-26 00:22:46 -0400 |
commit | f71470b37e79d6eb151debd47364d920b7babd30 (patch) | |
tree | cef41e3672ce144ddb9d251afc93190dcc3931c8 /net | |
parent | d020f8f73318589bf41f864b7f89f95669350873 (diff) |
udp: move logic out of udp[46]_ufo_send_check
In udp[46]_ufo_send_check the UDP checksum initialized to the pseudo
header checksum. We can move this logic into udp[46]_ufo_fragment.
After this change udp[64]_ufo_send_check is a no-op.
Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/udp_offload.c | 37 | ||||
-rw-r--r-- | net/ipv6/udp_offload.c | 40 |
2 files changed, 33 insertions, 44 deletions
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index d7c43f764c71..2918cc914824 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c | |||
@@ -27,23 +27,6 @@ struct udp_offload_priv { | |||
27 | 27 | ||
28 | static int udp4_ufo_send_check(struct sk_buff *skb) | 28 | static int udp4_ufo_send_check(struct sk_buff *skb) |
29 | { | 29 | { |
30 | if (!pskb_may_pull(skb, sizeof(struct udphdr))) | ||
31 | return -EINVAL; | ||
32 | |||
33 | if (likely(!skb->encapsulation)) { | ||
34 | const struct iphdr *iph; | ||
35 | struct udphdr *uh; | ||
36 | |||
37 | iph = ip_hdr(skb); | ||
38 | uh = udp_hdr(skb); | ||
39 | |||
40 | uh->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len, | ||
41 | IPPROTO_UDP, 0); | ||
42 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
43 | skb->csum_offset = offsetof(struct udphdr, check); | ||
44 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
45 | } | ||
46 | |||
47 | return 0; | 30 | return 0; |
48 | } | 31 | } |
49 | 32 | ||
@@ -128,8 +111,9 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, | |||
128 | { | 111 | { |
129 | struct sk_buff *segs = ERR_PTR(-EINVAL); | 112 | struct sk_buff *segs = ERR_PTR(-EINVAL); |
130 | unsigned int mss; | 113 | unsigned int mss; |
131 | int offset; | ||
132 | __wsum csum; | 114 | __wsum csum; |
115 | struct udphdr *uh; | ||
116 | struct iphdr *iph; | ||
133 | 117 | ||
134 | if (skb->encapsulation && | 118 | if (skb->encapsulation && |
135 | (skb_shinfo(skb)->gso_type & | 119 | (skb_shinfo(skb)->gso_type & |
@@ -138,6 +122,9 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, | |||
138 | goto out; | 122 | goto out; |
139 | } | 123 | } |
140 | 124 | ||
125 | if (!pskb_may_pull(skb, sizeof(struct udphdr))) | ||
126 | goto out; | ||
127 | |||
141 | mss = skb_shinfo(skb)->gso_size; | 128 | mss = skb_shinfo(skb)->gso_size; |
142 | if (unlikely(skb->len <= mss)) | 129 | if (unlikely(skb->len <= mss)) |
143 | goto out; | 130 | goto out; |
@@ -165,10 +152,16 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, | |||
165 | * HW cannot do checksum of UDP packets sent as multiple | 152 | * HW cannot do checksum of UDP packets sent as multiple |
166 | * IP fragments. | 153 | * IP fragments. |
167 | */ | 154 | */ |
168 | offset = skb_checksum_start_offset(skb); | 155 | |
169 | csum = skb_checksum(skb, offset, skb->len - offset, 0); | 156 | uh = udp_hdr(skb); |
170 | offset += skb->csum_offset; | 157 | iph = ip_hdr(skb); |
171 | *(__sum16 *)(skb->data + offset) = csum_fold(csum); | 158 | |
159 | uh->check = 0; | ||
160 | csum = skb_checksum(skb, 0, skb->len, 0); | ||
161 | uh->check = udp_v4_check(skb->len, iph->saddr, iph->daddr, csum); | ||
162 | if (uh->check == 0) | ||
163 | uh->check = CSUM_MANGLED_0; | ||
164 | |||
172 | skb->ip_summed = CHECKSUM_NONE; | 165 | skb->ip_summed = CHECKSUM_NONE; |
173 | 166 | ||
174 | /* Fragment the skb. IP headers of the fragments are updated in | 167 | /* Fragment the skb. IP headers of the fragments are updated in |
diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index de85f809bf29..e4af6437ea3b 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c | |||
@@ -19,23 +19,6 @@ | |||
19 | 19 | ||
20 | static int udp6_ufo_send_check(struct sk_buff *skb) | 20 | static int udp6_ufo_send_check(struct sk_buff *skb) |
21 | { | 21 | { |
22 | const struct ipv6hdr *ipv6h; | ||
23 | struct udphdr *uh; | ||
24 | |||
25 | if (!pskb_may_pull(skb, sizeof(*uh))) | ||
26 | return -EINVAL; | ||
27 | |||
28 | if (likely(!skb->encapsulation)) { | ||
29 | ipv6h = ipv6_hdr(skb); | ||
30 | uh = udp_hdr(skb); | ||
31 | |||
32 | uh->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len, | ||
33 | IPPROTO_UDP, 0); | ||
34 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
35 | skb->csum_offset = offsetof(struct udphdr, check); | ||
36 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
37 | } | ||
38 | |||
39 | return 0; | 22 | return 0; |
40 | } | 23 | } |
41 | 24 | ||
@@ -49,7 +32,6 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, | |||
49 | u8 *packet_start, *prevhdr; | 32 | u8 *packet_start, *prevhdr; |
50 | u8 nexthdr; | 33 | u8 nexthdr; |
51 | u8 frag_hdr_sz = sizeof(struct frag_hdr); | 34 | u8 frag_hdr_sz = sizeof(struct frag_hdr); |
52 | int offset; | ||
53 | __wsum csum; | 35 | __wsum csum; |
54 | int tnl_hlen; | 36 | int tnl_hlen; |
55 | 37 | ||
@@ -83,13 +65,27 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, | |||
83 | (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM)) | 65 | (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM)) |
84 | segs = skb_udp_tunnel_segment(skb, features); | 66 | segs = skb_udp_tunnel_segment(skb, features); |
85 | else { | 67 | else { |
68 | const struct ipv6hdr *ipv6h; | ||
69 | struct udphdr *uh; | ||
70 | |||
71 | if (!pskb_may_pull(skb, sizeof(struct udphdr))) | ||
72 | goto out; | ||
73 | |||
86 | /* Do software UFO. Complete and fill in the UDP checksum as HW cannot | 74 | /* Do software UFO. Complete and fill in the UDP checksum as HW cannot |
87 | * do checksum of UDP packets sent as multiple IP fragments. | 75 | * do checksum of UDP packets sent as multiple IP fragments. |
88 | */ | 76 | */ |
89 | offset = skb_checksum_start_offset(skb); | 77 | |
90 | csum = skb_checksum(skb, offset, skb->len - offset, 0); | 78 | uh = udp_hdr(skb); |
91 | offset += skb->csum_offset; | 79 | ipv6h = ipv6_hdr(skb); |
92 | *(__sum16 *)(skb->data + offset) = csum_fold(csum); | 80 | |
81 | uh->check = 0; | ||
82 | csum = skb_checksum(skb, 0, skb->len, 0); | ||
83 | uh->check = udp_v6_check(skb->len, &ipv6h->saddr, | ||
84 | &ipv6h->daddr, csum); | ||
85 | |||
86 | if (uh->check == 0) | ||
87 | uh->check = CSUM_MANGLED_0; | ||
88 | |||
93 | skb->ip_summed = CHECKSUM_NONE; | 89 | skb->ip_summed = CHECKSUM_NONE; |
94 | 90 | ||
95 | /* Check if there is enough headroom to insert fragment header. */ | 91 | /* Check if there is enough headroom to insert fragment header. */ |