Lines Matching +full:hw +full:- +full:gro
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IPV4 GSO/GRO offload support
10 #include <net/gro.h>
22 int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb); in __skb_udp_tunnel_segment()
24 struct sk_buff *segs = ERR_PTR(-EINVAL); in __skb_udp_tunnel_segment()
26 u16 mac_offset = skb->mac_header; in __skb_udp_tunnel_segment()
27 __be16 protocol = skb->protocol; in __skb_udp_tunnel_segment()
28 u16 mac_len = skb->mac_len; in __skb_udp_tunnel_segment()
37 * We cannot rely on the value contained in uh->len as it is in __skb_udp_tunnel_segment()
40 * IP or IPv6 frame that was already limited to 64K - 1. in __skb_udp_tunnel_segment()
42 if (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) in __skb_udp_tunnel_segment()
43 partial = (__force __wsum)uh->len; in __skb_udp_tunnel_segment()
45 partial = (__force __wsum)htonl(skb->len); in __skb_udp_tunnel_segment()
46 partial = csum_sub(csum_unfold(uh->check), partial); in __skb_udp_tunnel_segment()
49 skb->encapsulation = 0; in __skb_udp_tunnel_segment()
50 SKB_GSO_CB(skb)->encap_level = 0; in __skb_udp_tunnel_segment()
55 skb->mac_len = skb_inner_network_offset(skb); in __skb_udp_tunnel_segment()
56 skb->protocol = new_protocol; in __skb_udp_tunnel_segment()
58 need_csum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM); in __skb_udp_tunnel_segment()
59 skb->encap_hdr_csum = need_csum; in __skb_udp_tunnel_segment()
61 remcsum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_TUNNEL_REMCSUM); in __skb_udp_tunnel_segment()
62 skb->remcsum_offload = remcsum; in __skb_udp_tunnel_segment()
68 (skb->dev->features & in __skb_udp_tunnel_segment()
72 features &= skb->dev->hw_enc_features; in __skb_udp_tunnel_segment()
94 gso_partial = !!(skb_shinfo(segs)->gso_type & SKB_GSO_PARTIAL); in __skb_udp_tunnel_segment()
97 udp_offset = outer_hlen - tnl_hlen; in __skb_udp_tunnel_segment()
103 skb->ip_summed = CHECKSUM_NONE; in __skb_udp_tunnel_segment()
106 if (skb->ip_summed == CHECKSUM_PARTIAL) { in __skb_udp_tunnel_segment()
108 skb->encapsulation = 1; in __skb_udp_tunnel_segment()
111 skb->mac_len = mac_len; in __skb_udp_tunnel_segment()
112 skb->protocol = protocol; in __skb_udp_tunnel_segment()
118 len = skb->len - udp_offset; in __skb_udp_tunnel_segment()
126 uh->len = htons(skb_shinfo(skb)->gso_size + in __skb_udp_tunnel_segment()
127 SKB_GSO_CB(skb)->data_offset + in __skb_udp_tunnel_segment()
128 skb->head - (unsigned char *)uh); in __skb_udp_tunnel_segment()
130 uh->len = htons(len); in __skb_udp_tunnel_segment()
136 uh->check = ~csum_fold(csum_add(partial, in __skb_udp_tunnel_segment()
139 if (skb->encapsulation || !offload_csum) { in __skb_udp_tunnel_segment()
140 uh->check = gso_make_checksum(skb, ~uh->check); in __skb_udp_tunnel_segment()
141 if (uh->check == 0) in __skb_udp_tunnel_segment()
142 uh->check = CSUM_MANGLED_0; in __skb_udp_tunnel_segment()
144 skb->ip_summed = CHECKSUM_PARTIAL; in __skb_udp_tunnel_segment()
145 skb->csum_start = skb_transport_header(skb) - skb->head; in __skb_udp_tunnel_segment()
146 skb->csum_offset = offsetof(struct udphdr, check); in __skb_udp_tunnel_segment()
148 } while ((skb = skb->next)); in __skb_udp_tunnel_segment()
158 __be16 protocol = skb->protocol; in skb_udp_tunnel_segment()
160 struct sk_buff *segs = ERR_PTR(-EINVAL); in skb_udp_tunnel_segment()
166 switch (skb->inner_protocol_type) { in skb_udp_tunnel_segment()
168 protocol = skb->inner_protocol; in skb_udp_tunnel_segment()
173 ops = rcu_dereference(offloads[skb->inner_ipproto]); in skb_udp_tunnel_segment()
174 if (!ops || !ops->callbacks.gso_segment) in skb_udp_tunnel_segment()
176 gso_inner_segment = ops->callbacks.gso_segment; in skb_udp_tunnel_segment()
205 if (uh->check) { in __udpv4_gso_segment_csum()
206 inet_proto_csum_replace4(&uh->check, seg, *oldip, *newip, in __udpv4_gso_segment_csum()
208 inet_proto_csum_replace2(&uh->check, seg, *oldport, *newport, in __udpv4_gso_segment_csum()
210 if (!uh->check) in __udpv4_gso_segment_csum()
211 uh->check = CSUM_MANGLED_0; in __udpv4_gso_segment_csum()
215 csum_replace4(&iph->check, *oldip, *newip); in __udpv4_gso_segment_csum()
229 if ((udp_hdr(seg)->dest == udp_hdr(seg->next)->dest) && in __udpv4_gso_segment_list_csum()
230 (udp_hdr(seg)->source == udp_hdr(seg->next)->source) && in __udpv4_gso_segment_list_csum()
231 (ip_hdr(seg)->daddr == ip_hdr(seg->next)->daddr) && in __udpv4_gso_segment_list_csum()
232 (ip_hdr(seg)->saddr == ip_hdr(seg->next)->saddr)) in __udpv4_gso_segment_list_csum()
235 while ((seg = seg->next)) { in __udpv4_gso_segment_list_csum()
240 &iph2->saddr, &iph->saddr, in __udpv4_gso_segment_list_csum()
241 &uh2->source, &uh->source); in __udpv4_gso_segment_list_csum()
243 &iph2->daddr, &iph->daddr, in __udpv4_gso_segment_list_csum()
244 &uh2->dest, &uh->dest); in __udpv4_gso_segment_list_csum()
254 unsigned int mss = skb_shinfo(skb)->gso_size; in __udp_gso_segment_list()
260 udp_hdr(skb)->len = htons(sizeof(struct udphdr) + mss); in __udp_gso_segment_list()
268 struct sock *sk = gso_skb->sk; in __udp_gso_segment()
277 mss = skb_shinfo(gso_skb)->gso_size; in __udp_gso_segment()
278 if (gso_skb->len <= sizeof(*uh) + mss) in __udp_gso_segment()
279 return ERR_PTR(-EINVAL); in __udp_gso_segment()
283 !(skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST))) in __udp_gso_segment()
284 return ERR_PTR(-EINVAL); in __udp_gso_segment()
289 if (gso_skb->ip_summed != CHECKSUM_PARTIAL) in __udp_gso_segment()
294 skb_shinfo(gso_skb)->gso_segs = DIV_ROUND_UP(gso_skb->len - sizeof(*uh), in __udp_gso_segment()
299 if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST) { in __udp_gso_segment()
301 if (skb_pagelen(gso_skb) - sizeof(*uh) == skb_shinfo(gso_skb)->gso_size) in __udp_gso_segment()
305 gso_skb->csum_start = skb_transport_header(gso_skb) - gso_skb->head; in __udp_gso_segment()
306 gso_skb->csum_offset = offsetof(struct udphdr, check); in __udp_gso_segment()
307 gso_skb->ip_summed = CHECKSUM_PARTIAL; in __udp_gso_segment()
311 uh->check = ~udp_v6_check(gso_skb->len, in __udp_gso_segment()
312 &ipv6_hdr(gso_skb)->saddr, in __udp_gso_segment()
313 &ipv6_hdr(gso_skb)->daddr, 0); in __udp_gso_segment()
315 uh->check = ~udp_v4_check(gso_skb->len, in __udp_gso_segment()
316 ip_hdr(gso_skb)->saddr, in __udp_gso_segment()
317 ip_hdr(gso_skb)->daddr, 0); in __udp_gso_segment()
323 copy_dtor = gso_skb->destructor == sock_wfree; in __udp_gso_segment()
325 gso_skb->destructor = NULL; in __udp_gso_segment()
330 gso_skb->destructor = sock_wfree; in __udp_gso_segment()
339 mss *= skb_shinfo(segs)->gso_segs; in __udp_gso_segment()
345 skb_shinfo(seg)->tskey = skb_shinfo(gso_skb)->tskey; in __udp_gso_segment()
346 skb_shinfo(seg)->tx_flags |= in __udp_gso_segment()
347 (skb_shinfo(gso_skb)->tx_flags & SKBTX_ANY_TSTAMP); in __udp_gso_segment()
351 check = csum16_add(csum16_sub(uh->check, uh->len), newlen); in __udp_gso_segment()
355 seg->destructor = sock_wfree; in __udp_gso_segment()
356 seg->sk = sk; in __udp_gso_segment()
357 sum_truesize += seg->truesize; in __udp_gso_segment()
360 if (!seg->next) in __udp_gso_segment()
363 uh->len = newlen; in __udp_gso_segment()
364 uh->check = check; in __udp_gso_segment()
366 if (seg->ip_summed == CHECKSUM_PARTIAL) in __udp_gso_segment()
369 uh->check = gso_make_checksum(seg, ~check) ? : in __udp_gso_segment()
372 seg = seg->next; in __udp_gso_segment()
377 newlen = htons(skb_tail_pointer(seg) - skb_transport_header(seg) + in __udp_gso_segment()
378 seg->data_len); in __udp_gso_segment()
379 check = csum16_add(csum16_sub(uh->check, uh->len), newlen); in __udp_gso_segment()
381 uh->len = newlen; in __udp_gso_segment()
382 uh->check = check; in __udp_gso_segment()
384 if (seg->ip_summed == CHECKSUM_PARTIAL) in __udp_gso_segment()
387 uh->check = gso_make_checksum(seg, ~check) ? : CSUM_MANGLED_0; in __udp_gso_segment()
394 if (gso_skb->ip_summed == CHECKSUM_NONE) in __udp_gso_segment()
395 gso_skb->ip_summed = CHECKSUM_UNNECESSARY; in __udp_gso_segment()
399 int delta = sum_truesize - gso_skb->truesize; in __udp_gso_segment()
405 refcount_add(delta, &sk->sk_wmem_alloc); in __udp_gso_segment()
407 WARN_ON_ONCE(refcount_sub_and_test(-delta, &sk->sk_wmem_alloc)); in __udp_gso_segment()
416 struct sk_buff *segs = ERR_PTR(-EINVAL); in udp4_ufo_fragment()
422 if (skb->encapsulation && in udp4_ufo_fragment()
423 (skb_shinfo(skb)->gso_type & in udp4_ufo_fragment()
429 if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_UDP | SKB_GSO_UDP_L4))) in udp4_ufo_fragment()
435 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) in udp4_ufo_fragment()
438 mss = skb_shinfo(skb)->gso_size; in udp4_ufo_fragment()
439 if (unlikely(skb->len <= mss)) in udp4_ufo_fragment()
443 * HW cannot do checksum of UDP packets sent as multiple in udp4_ufo_fragment()
450 uh->check = 0; in udp4_ufo_fragment()
451 csum = skb_checksum(skb, 0, skb->len, 0); in udp4_ufo_fragment()
452 uh->check = udp_v4_check(skb->len, iph->saddr, iph->daddr, csum); in udp4_ufo_fragment()
453 if (uh->check == 0) in udp4_ufo_fragment()
454 uh->check = CSUM_MANGLED_0; in udp4_ufo_fragment()
456 skb->ip_summed = CHECKSUM_UNNECESSARY; in udp4_ufo_fragment()
462 if (!skb->encap_hdr_csum) in udp4_ufo_fragment()
487 if (!uh->check) { in udp_gro_receive_segment()
488 NAPI_GRO_CB(skb)->flush = 1; in udp_gro_receive_segment()
493 ulen = ntohs(uh->len); in udp_gro_receive_segment()
495 NAPI_GRO_CB(skb)->flush = 1; in udp_gro_receive_segment()
502 if (!NAPI_GRO_CB(p)->same_flow) in udp_gro_receive_segment()
508 if ((*(u32 *)&uh->source != *(u32 *)&uh2->source)) { in udp_gro_receive_segment()
509 NAPI_GRO_CB(p)->same_flow = 0; in udp_gro_receive_segment()
513 if (NAPI_GRO_CB(skb)->is_flist != NAPI_GRO_CB(p)->is_flist) { in udp_gro_receive_segment()
514 NAPI_GRO_CB(skb)->flush = 1; in udp_gro_receive_segment()
521 * Under small packet flood GRO count could elsewhere grow a lot in udp_gro_receive_segment()
524 * otherwise complete the GRO packet. in udp_gro_receive_segment()
526 if (ulen > ntohs(uh2->len) || flush) { in udp_gro_receive_segment()
529 if (NAPI_GRO_CB(skb)->is_flist) { in udp_gro_receive_segment()
531 NAPI_GRO_CB(skb)->flush = 1; in udp_gro_receive_segment()
534 if ((skb->ip_summed != p->ip_summed) || in udp_gro_receive_segment()
535 (skb->csum_level != p->csum_level)) { in udp_gro_receive_segment()
536 NAPI_GRO_CB(skb)->flush = 1; in udp_gro_receive_segment()
548 if (ret || ulen != ntohs(uh2->len) || in udp_gro_receive_segment()
549 NAPI_GRO_CB(p)->count >= UDP_GRO_CNT_MAX) in udp_gro_receive_segment()
573 NAPI_GRO_CB(skb)->is_flist = 0; in udp_gro_receive()
574 if (!sk || !udp_sk(sk)->gro_receive) { in udp_gro_receive()
576 * wasn't detected above, do not GRO. in udp_gro_receive()
578 if (skb->encapsulation) in udp_gro_receive()
581 if (skb->dev->features & NETIF_F_GRO_FRAGLIST) in udp_gro_receive()
582 NAPI_GRO_CB(skb)->is_flist = sk ? !udp_test_bit(GRO_ENABLED, sk) : 1; in udp_gro_receive()
584 if ((!sk && (skb->dev->features & NETIF_F_GRO_UDP_FWD)) || in udp_gro_receive()
585 (sk && udp_test_bit(GRO_ENABLED, sk)) || NAPI_GRO_CB(skb)->is_flist) in udp_gro_receive()
588 /* no GRO, be sure flush the current packet */ in udp_gro_receive()
592 if (NAPI_GRO_CB(skb)->encap_mark || in udp_gro_receive()
593 (uh->check && skb->ip_summed != CHECKSUM_PARTIAL && in udp_gro_receive()
594 NAPI_GRO_CB(skb)->csum_cnt == 0 && in udp_gro_receive()
595 !NAPI_GRO_CB(skb)->csum_valid)) in udp_gro_receive()
598 /* mark that this skb passed once through the tunnel gro layer */ in udp_gro_receive()
599 NAPI_GRO_CB(skb)->encap_mark = 1; in udp_gro_receive()
604 if (!NAPI_GRO_CB(p)->same_flow) in udp_gro_receive()
607 uh2 = (struct udphdr *)(p->data + off); in udp_gro_receive()
612 if ((*(u32 *)&uh->source != *(u32 *)&uh2->source) || in udp_gro_receive()
613 (!uh->check ^ !uh2->check)) { in udp_gro_receive()
614 NAPI_GRO_CB(p)->same_flow = 0; in udp_gro_receive()
621 pp = call_gro_receive_sk(udp_sk(sk)->gro_receive, sk, head, skb); in udp_gro_receive()
633 struct net *net = dev_net(skb->dev); in udp4_gro_lookup_skb()
638 return __udp4_lib_lookup(net, iph->saddr, sport, in udp4_gro_lookup_skb()
639 iph->daddr, dport, iif, in udp4_gro_lookup_skb()
640 sdif, net->ipv4.udp_table, NULL); in udp4_gro_lookup_skb()
654 if (NAPI_GRO_CB(skb)->flush) in udp4_gro_receive()
657 if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check, in udp4_gro_receive()
660 else if (uh->check) in udp4_gro_receive()
664 NAPI_GRO_CB(skb)->is_ipv6 = 0; in udp4_gro_receive()
667 sk = udp4_gro_lookup_skb(skb, uh->source, uh->dest); in udp4_gro_receive()
673 NAPI_GRO_CB(skb)->flush = 1; in udp4_gro_receive()
681 skb->csum_start = (unsigned char *)uh - skb->head; in udp_gro_complete_segment()
682 skb->csum_offset = offsetof(struct udphdr, check); in udp_gro_complete_segment()
683 skb->ip_summed = CHECKSUM_PARTIAL; in udp_gro_complete_segment()
685 skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; in udp_gro_complete_segment()
686 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_L4; in udp_gro_complete_segment()
688 if (skb->encapsulation) in udp_gro_complete_segment()
689 skb->inner_transport_header = skb->transport_header; in udp_gro_complete_segment()
697 __be16 newlen = htons(skb->len - nhoff); in udp_gro_complete()
698 struct udphdr *uh = (struct udphdr *)(skb->data + nhoff); in udp_gro_complete()
702 uh->len = newlen; in udp_gro_complete()
705 udp4_lib_lookup_skb, skb, uh->source, uh->dest); in udp_gro_complete()
706 if (sk && udp_sk(sk)->gro_complete) { in udp_gro_complete()
707 skb_shinfo(skb)->gso_type = uh->check ? SKB_GSO_UDP_TUNNEL_CSUM in udp_gro_complete()
713 NAPI_GRO_CB(skb)->encap_mark = 0; in udp_gro_complete()
718 skb->encapsulation = 1; in udp_gro_complete()
719 err = udp_sk(sk)->gro_complete(sk, skb, in udp_gro_complete()
725 if (skb->remcsum_offload) in udp_gro_complete()
726 skb_shinfo(skb)->gso_type |= SKB_GSO_TUNNEL_REMCSUM; in udp_gro_complete()
734 const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation]; in udp4_gro_complete()
735 const struct iphdr *iph = (struct iphdr *)(skb->data + offset); in udp4_gro_complete()
736 struct udphdr *uh = (struct udphdr *)(skb->data + nhoff); in udp4_gro_complete()
739 if (NAPI_GRO_CB(skb)->is_flist && !NAPI_GRO_CB(skb)->encap_mark) { in udp4_gro_complete()
740 uh->len = htons(skb->len - nhoff); in udp4_gro_complete()
742 skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4); in udp4_gro_complete()
743 skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; in udp4_gro_complete()
750 if (uh->check) in udp4_gro_complete()
751 uh->check = ~udp_v4_check(skb->len - nhoff, iph->saddr, in udp4_gro_complete()
752 iph->daddr, 0); in udp4_gro_complete()