Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	IPV4 GSO/GRO offload support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Linux INET implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	UDPv4 GSO support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	netdev_features_t features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct sk_buff *(*gso_inner_segment)(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 					     netdev_features_t features),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	__be16 new_protocol, bool is_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	bool remcsum, need_csum, offload_csum, gso_partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct sk_buff *segs = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct udphdr *uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u16 mac_offset = skb->mac_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	__be16 protocol = skb->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u16 mac_len = skb->mac_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int udp_offset, outer_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	__wsum partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	bool need_ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (unlikely(!pskb_may_pull(skb, tnl_hlen)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	/* Adjust partial header checksum to negate old length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 * We cannot rely on the value contained in uh->len as it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 * possible that the actual value exceeds the boundaries of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 * 16 bit length field due to the header being added outside of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	 * IP or IPv6 frame that was already limited to 64K - 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		partial = (__force __wsum)uh->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		partial = (__force __wsum)htonl(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	partial = csum_sub(csum_unfold(uh->check), partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* setup inner skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	skb->encapsulation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	SKB_GSO_CB(skb)->encap_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	__skb_pull(skb, tnl_hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	skb_set_network_header(skb, skb_inner_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	skb->mac_len = skb_inner_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	skb->protocol = new_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	need_csum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	skb->encap_hdr_csum = need_csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	remcsum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_TUNNEL_REMCSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	skb->remcsum_offload = remcsum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	need_ipsec = skb_dst(skb) && dst_xfrm(skb_dst(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* Try to offload checksum if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	offload_csum = !!(need_csum &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			  !need_ipsec &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			  (skb->dev->features &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			   (is_ipv6 ? (NETIF_F_HW_CSUM | NETIF_F_IPV6_CSUM) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				      (NETIF_F_HW_CSUM | NETIF_F_IP_CSUM))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	features &= skb->dev->hw_enc_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* The only checksum offload we care about from here on out is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 * outer one so strip the existing checksum feature flags and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 * instead set the flag based on our outer checksum offload value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (remcsum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		features &= ~NETIF_F_CSUM_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (!need_csum || offload_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			features |= NETIF_F_HW_CSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* segment inner packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	segs = gso_inner_segment(skb, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (IS_ERR_OR_NULL(segs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		skb_gso_error_unwind(skb, protocol, tnl_hlen, mac_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				     mac_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	gso_partial = !!(skb_shinfo(segs)->gso_type & SKB_GSO_PARTIAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	outer_hlen = skb_tnl_header_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	udp_offset = outer_hlen - tnl_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	skb = segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (remcsum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		/* Set up inner headers if we are offloading inner checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (skb->ip_summed == CHECKSUM_PARTIAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			skb_reset_inner_headers(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			skb->encapsulation = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		skb->mac_len = mac_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		skb->protocol = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		__skb_push(skb, outer_hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		skb_set_network_header(skb, mac_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		skb_set_transport_header(skb, udp_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		len = skb->len - udp_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		/* If we are only performing partial GSO the inner header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 * will be using a length value equal to only one MSS sized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		 * segment instead of the entire frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (gso_partial && skb_is_gso(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			uh->len = htons(skb_shinfo(skb)->gso_size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					SKB_GSO_CB(skb)->data_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					skb->head - (unsigned char *)uh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			uh->len = htons(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (!need_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		uh->check = ~csum_fold(csum_add(partial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				       (__force __wsum)htonl(len)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (skb->encapsulation || !offload_csum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			uh->check = gso_make_checksum(skb, ~uh->check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			if (uh->check == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				uh->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			skb->ip_summed = CHECKSUM_PARTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			skb->csum_start = skb_transport_header(skb) - skb->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			skb->csum_offset = offsetof(struct udphdr, check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	} while ((skb = skb->next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				       netdev_features_t features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				       bool is_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	__be16 protocol = skb->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	const struct net_offload **offloads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	const struct net_offload *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct sk_buff *segs = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct sk_buff *(*gso_inner_segment)(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					     netdev_features_t features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	switch (skb->inner_protocol_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	case ENCAP_TYPE_ETHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		protocol = skb->inner_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		gso_inner_segment = skb_mac_gso_segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case ENCAP_TYPE_IPPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		offloads = is_ipv6 ? inet6_offloads : inet_offloads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		ops = rcu_dereference(offloads[skb->inner_ipproto]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (!ops || !ops->callbacks.gso_segment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		gso_inner_segment = ops->callbacks.gso_segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	segs = __skb_udp_tunnel_segment(skb, features, gso_inner_segment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					protocol, is_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) EXPORT_SYMBOL(skb_udp_tunnel_segment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void __udpv4_gso_segment_csum(struct sk_buff *seg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				     __be32 *oldip, __be32 *newip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				     __be16 *oldport, __be16 *newport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (*oldip == *newip && *oldport == *newport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	uh = udp_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	iph = ip_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (uh->check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		inet_proto_csum_replace4(&uh->check, seg, *oldip, *newip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 					 true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		inet_proto_csum_replace2(&uh->check, seg, *oldport, *newport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 					 false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if (!uh->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			uh->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	*oldport = *newport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	csum_replace4(&iph->check, *oldip, *newip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	*oldip = *newip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static struct sk_buff *__udpv4_gso_segment_list_csum(struct sk_buff *segs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct sk_buff *seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct udphdr *uh, *uh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct iphdr *iph, *iph2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	seg = segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	uh = udp_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	iph = ip_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if ((udp_hdr(seg)->dest == udp_hdr(seg->next)->dest) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	    (udp_hdr(seg)->source == udp_hdr(seg->next)->source) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	    (ip_hdr(seg)->daddr == ip_hdr(seg->next)->daddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	    (ip_hdr(seg)->saddr == ip_hdr(seg->next)->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	while ((seg = seg->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		uh2 = udp_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		iph2 = ip_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		__udpv4_gso_segment_csum(seg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 					 &iph2->saddr, &iph->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 					 &uh2->source, &uh->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		__udpv4_gso_segment_csum(seg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					 &iph2->daddr, &iph->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					 &uh2->dest, &uh->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static struct sk_buff *__udp_gso_segment_list(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 					      netdev_features_t features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					      bool is_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unsigned int mss = skb_shinfo(skb)->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	skb = skb_segment_list(skb, features, skb_mac_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (IS_ERR(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	udp_hdr(skb)->len = htons(sizeof(struct udphdr) + mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return is_ipv6 ? skb : __udpv4_gso_segment_list_csum(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				  netdev_features_t features, bool is_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct sock *sk = gso_skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	unsigned int sum_truesize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct sk_buff *segs, *seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	unsigned int mss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	bool copy_dtor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	__sum16 check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	__be16 newlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return __udp_gso_segment_list(gso_skb, features, is_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	mss = skb_shinfo(gso_skb)->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (gso_skb->len <= sizeof(*uh) + mss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	skb_pull(gso_skb, sizeof(*uh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* clear destructor to avoid skb_segment assigning it to tail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	copy_dtor = gso_skb->destructor == sock_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (copy_dtor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		gso_skb->destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	segs = skb_segment(gso_skb, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (IS_ERR_OR_NULL(segs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (copy_dtor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			gso_skb->destructor = sock_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/* GSO partial and frag_list segmentation only requires splitting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 * the frame into an MSS multiple and possibly a remainder, both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * cases return a GSO skb. So update the mss now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (skb_is_gso(segs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		mss *= skb_shinfo(segs)->gso_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	seg = segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	uh = udp_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	/* preserve TX timestamp flags and TS key for first segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	skb_shinfo(seg)->tskey = skb_shinfo(gso_skb)->tskey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	skb_shinfo(seg)->tx_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			(skb_shinfo(gso_skb)->tx_flags & SKBTX_ANY_TSTAMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	/* compute checksum adjustment based on old length versus new */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	newlen = htons(sizeof(*uh) + mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (copy_dtor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			seg->destructor = sock_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			seg->sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			sum_truesize += seg->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		if (!seg->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		uh->len = newlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		uh->check = check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		if (seg->ip_summed == CHECKSUM_PARTIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			gso_reset_checksum(seg, ~check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			uh->check = gso_make_checksum(seg, ~check) ? :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				    CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		seg = seg->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		uh = udp_hdr(seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* last packet can be partial gso_size, account for that in checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	newlen = htons(skb_tail_pointer(seg) - skb_transport_header(seg) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		       seg->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	uh->len = newlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	uh->check = check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (seg->ip_summed == CHECKSUM_PARTIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		gso_reset_checksum(seg, ~check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		uh->check = gso_make_checksum(seg, ~check) ? : CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* update refcount for the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (copy_dtor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		int delta = sum_truesize - gso_skb->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		/* In some pathological cases, delta can be negative.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		 * We need to either use refcount_add() or refcount_sub_and_test()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		if (likely(delta >= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			refcount_add(delta, &sk->sk_wmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			WARN_ON_ONCE(refcount_sub_and_test(-delta, &sk->sk_wmem_alloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) EXPORT_SYMBOL_GPL(__udp_gso_segment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 					 netdev_features_t features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct sk_buff *segs = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	unsigned int mss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	__wsum csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (skb->encapsulation &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	    (skb_shinfo(skb)->gso_type &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	     (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		segs = skb_udp_tunnel_segment(skb, features, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_UDP | SKB_GSO_UDP_L4)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (!pskb_may_pull(skb, sizeof(struct udphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return __udp_gso_segment(skb, features, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	mss = skb_shinfo(skb)->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (unlikely(skb->len <= mss))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	/* Do software UFO. Complete and fill in the UDP checksum as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 * HW cannot do checksum of UDP packets sent as multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	 * IP fragments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	uh->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	csum = skb_checksum(skb, 0, skb->len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	uh->check = udp_v4_check(skb->len, iph->saddr, iph->daddr, csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (uh->check == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		uh->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	skb->ip_summed = CHECKSUM_UNNECESSARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	/* If there is no outer header we can fake a checksum offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * due to the fact that we have already done the checksum in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * software prior to segmenting the frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (!skb->encap_hdr_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		features |= NETIF_F_HW_CSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	/* Fragment the skb. IP headers of the fragments are updated in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	 * inet_gso_segment()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	segs = skb_segment(skb, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #define UDP_GRO_CNT_MAX 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 					       struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct udphdr *uh = udp_gro_udphdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct sk_buff *pp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct udphdr *uh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct sk_buff *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	unsigned int ulen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	/* requires non zero csum, for symmetry with GSO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (!uh->check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/* Do not deal with padded or malicious packets, sorry ! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	ulen = ntohs(uh->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (ulen <= sizeof(*uh) || ulen != skb_gro_len(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	/* pull encapsulating udp header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	skb_gro_pull(skb, sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	list_for_each_entry(p, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		if (!NAPI_GRO_CB(p)->same_flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		uh2 = udp_hdr(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		/* Match ports only, as csum is always non zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if ((*(u32 *)&uh->source != *(u32 *)&uh2->source)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			NAPI_GRO_CB(p)->same_flow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		if (NAPI_GRO_CB(skb)->is_flist != NAPI_GRO_CB(p)->is_flist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		/* Terminate the flow on len mismatch or if it grow "too much".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		 * Under small packet flood GRO count could elsewhere grow a lot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		 * leading to excessive truesize values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		 * On len mismatch merge the first packet shorter than gso_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		 * otherwise complete the GRO packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		if (ulen > ntohs(uh2->len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			pp = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			if (NAPI_GRO_CB(skb)->is_flist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 					NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 					return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 				if ((skb->ip_summed != p->ip_summed) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				    (skb->csum_level != p->csum_level)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 					NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 					return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 				ret = skb_gro_receive_list(p, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 				skb_gro_postpull_rcsum(skb, uh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 						       sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 				ret = skb_gro_receive(p, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		if (ret || ulen != ntohs(uh2->len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		    NAPI_GRO_CB(p)->count >= UDP_GRO_CNT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			pp = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		return pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* mismatch, but we never need to flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 				struct udphdr *uh, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	struct sk_buff *pp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct sk_buff *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct udphdr *uh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	unsigned int off = skb_gro_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	int flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	NAPI_GRO_CB(skb)->is_flist = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (skb->dev->features & NETIF_F_GRO_FRAGLIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		NAPI_GRO_CB(skb)->is_flist = sk ? !udp_sk(sk)->gro_enabled: 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	if ((sk && udp_sk(sk)->gro_enabled) || NAPI_GRO_CB(skb)->is_flist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		pp = call_gro_receive(udp_gro_receive_segment, head, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		return pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	if (!sk || NAPI_GRO_CB(skb)->encap_mark ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	    (uh->check && skb->ip_summed != CHECKSUM_PARTIAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	     NAPI_GRO_CB(skb)->csum_cnt == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	     !NAPI_GRO_CB(skb)->csum_valid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	    !udp_sk(sk)->gro_receive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	/* mark that this skb passed once through the tunnel gro layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	NAPI_GRO_CB(skb)->encap_mark = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	flush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	list_for_each_entry(p, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		if (!NAPI_GRO_CB(p)->same_flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		uh2 = (struct udphdr   *)(p->data + off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		/* Match ports and either checksums are either both zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		 * or nonzero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		if ((*(u32 *)&uh->source != *(u32 *)&uh2->source) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		    (!uh->check ^ !uh2->check)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			NAPI_GRO_CB(p)->same_flow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	skb_gro_pull(skb, sizeof(struct udphdr)); /* pull encapsulating udp header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	skb_gro_postpull_rcsum(skb, uh, sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	pp = call_gro_receive_sk(udp_sk(sk)->gro_receive, sk, head, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	skb_gro_flush_final(skb, pp, flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	return pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) EXPORT_SYMBOL(udp_gro_receive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static struct sock *udp4_gro_lookup_skb(struct sk_buff *skb, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 					__be16 dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	const struct iphdr *iph = skb_gro_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 				 iph->daddr, dport, inet_iif(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 				 inet_sdif(skb), &udp_table, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) INDIRECT_CALLABLE_SCOPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct sk_buff *udp4_gro_receive(struct list_head *head, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct udphdr *uh = udp_gro_udphdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	struct sk_buff *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	if (unlikely(!uh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		goto flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	/* Don't bother verifying checksum if we're going to flush anyway. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (NAPI_GRO_CB(skb)->flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 						 inet_gro_compute_pseudo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		goto flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	else if (uh->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		skb_gro_checksum_try_convert(skb, IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 					     inet_gro_compute_pseudo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	NAPI_GRO_CB(skb)->is_ipv6 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (static_branch_unlikely(&udp_encap_needed_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		sk = udp4_gro_lookup_skb(skb, uh->source, uh->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	pp = udp_gro_receive(head, skb, uh, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	return pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) flush:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	NAPI_GRO_CB(skb)->flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static int udp_gro_complete_segment(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct udphdr *uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	skb->csum_start = (unsigned char *)uh - skb->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	skb->csum_offset = offsetof(struct udphdr, check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	skb->ip_summed = CHECKSUM_PARTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	if (skb->encapsulation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		skb->inner_transport_header = skb->transport_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) int udp_gro_complete(struct sk_buff *skb, int nhoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		     udp_lookup_t lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	__be16 newlen = htons(skb->len - nhoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	int err = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	uh->len = newlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	sk = INDIRECT_CALL_INET(lookup, udp6_lib_lookup_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 				udp4_lib_lookup_skb, skb, uh->source, uh->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	if (sk && udp_sk(sk)->gro_complete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		skb_shinfo(skb)->gso_type = uh->check ? SKB_GSO_UDP_TUNNEL_CSUM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 					: SKB_GSO_UDP_TUNNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		/* Set encapsulation before calling into inner gro_complete()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		 * functions to make them set up the inner offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		skb->encapsulation = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		err = udp_sk(sk)->gro_complete(sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 				nhoff + sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		err = udp_gro_complete_segment(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (skb->remcsum_offload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		skb_shinfo(skb)->gso_type |= SKB_GSO_TUNNEL_REMCSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) EXPORT_SYMBOL(udp_gro_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	const struct iphdr *iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	if (NAPI_GRO_CB(skb)->is_flist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		uh->len = htons(skb->len - nhoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 			if (skb->csum_level < SKB_MAX_CSUM_LEVEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 				skb->csum_level++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 			skb->ip_summed = CHECKSUM_UNNECESSARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			skb->csum_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (uh->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		uh->check = ~udp_v4_check(skb->len - nhoff, iph->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 					  iph->daddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	return udp_gro_complete(skb, nhoff, udp4_lib_lookup_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static const struct net_offload udpv4_offload = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	.callbacks = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		.gso_segment = udp4_ufo_fragment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		.gro_receive  =	udp4_gro_receive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		.gro_complete =	udp4_gro_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) int __init udpv4_offload_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	return inet_add_offload(&udpv4_offload, IPPROTO_UDP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }