hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/net/ipv6/udp_offload.c
....@@ -1,16 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * IPV6 GSO/GRO offload support
34 * Linux INET6 implementation
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * as published by the Free Software Foundation; either version
8
- * 2 of the License, or (at your option) any later version.
95 *
106 * UDPv6 GSO support
117 */
128 #include <linux/skbuff.h>
139 #include <linux/netdevice.h>
10
+#include <linux/indirect_call_wrapper.h>
1411 #include <net/protocol.h>
1512 #include <net/ipv6.h>
1613 #include <net/udp.h>
....@@ -49,7 +46,7 @@
4946 goto out;
5047
5148 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
52
- return __udp_gso_segment(skb, features);
49
+ return __udp_gso_segment(skb, features, true);
5350
5451 /* Do software UFO. Complete and fill in the UDP checksum as HW cannot
5552 * do checksum of UDP packets sent as multiple IP fragments.
....@@ -114,10 +111,22 @@
114111 return segs;
115112 }
116113
117
-static struct sk_buff *udp6_gro_receive(struct list_head *head,
118
- struct sk_buff *skb)
114
+static struct sock *udp6_gro_lookup_skb(struct sk_buff *skb, __be16 sport,
115
+ __be16 dport)
116
+{
117
+ const struct ipv6hdr *iph = skb_gro_network_header(skb);
118
+
119
+ return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport,
120
+ &iph->daddr, dport, inet6_iif(skb),
121
+ inet6_sdif(skb), &udp_table, NULL);
122
+}
123
+
124
+INDIRECT_CALLABLE_SCOPE
125
+struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
119126 {
120127 struct udphdr *uh = udp_gro_udphdr(skb);
128
+ struct sock *sk = NULL;
129
+ struct sk_buff *pp;
121130
122131 if (unlikely(!uh))
123132 goto flush;
....@@ -130,30 +139,50 @@
130139 ip6_gro_compute_pseudo))
131140 goto flush;
132141 else if (uh->check)
133
- skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
142
+ skb_gro_checksum_try_convert(skb, IPPROTO_UDP,
134143 ip6_gro_compute_pseudo);
135144
136145 skip:
137146 NAPI_GRO_CB(skb)->is_ipv6 = 1;
138
- return udp_gro_receive(head, skb, uh, udp6_lib_lookup_skb);
147
+ rcu_read_lock();
148
+
149
+ if (static_branch_unlikely(&udpv6_encap_needed_key))
150
+ sk = udp6_gro_lookup_skb(skb, uh->source, uh->dest);
151
+
152
+ pp = udp_gro_receive(head, skb, uh, sk);
153
+ rcu_read_unlock();
154
+ return pp;
139155
140156 flush:
141157 NAPI_GRO_CB(skb)->flush = 1;
142158 return NULL;
143159 }
144160
145
-static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
161
+INDIRECT_CALLABLE_SCOPE int udp6_gro_complete(struct sk_buff *skb, int nhoff)
146162 {
147163 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
148164 struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
149165
150
- if (uh->check) {
151
- skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
166
+ if (NAPI_GRO_CB(skb)->is_flist) {
167
+ uh->len = htons(skb->len - nhoff);
168
+
169
+ skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);
170
+ skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
171
+
172
+ if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
173
+ if (skb->csum_level < SKB_MAX_CSUM_LEVEL)
174
+ skb->csum_level++;
175
+ } else {
176
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
177
+ skb->csum_level = 0;
178
+ }
179
+
180
+ return 0;
181
+ }
182
+
183
+ if (uh->check)
152184 uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
153185 &ipv6h->daddr, 0);
154
- } else {
155
- skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
156
- }
157186
158187 return udp_gro_complete(skb, nhoff, udp6_lib_lookup_skb);
159188 }