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)  *	IPv6 output functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *	Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *	Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *	Pedro Roque		<roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *	Based on linux/net/ipv4/ip_output.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *	Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *	A.N.Kuznetsov	:	airthmetics in fragmentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *				extension headers are implemented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *				route changes now work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *				ip6_forward does not confuse sniffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *				etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *      H. von Brand    :       Added missing #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *	Imran Patel	:	frag id should be in NBO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *      Kazunori MIYAZAWA @USAGI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *			:       add ip6_append_data and related functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *				for datagram xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/bpf-cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/netfilter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/netfilter_ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <net/rawv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/mroute6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <net/l3mdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <net/lwtunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <net/ip_tunnels.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	struct net_device *dev = dst->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	unsigned int hh_len = LL_RESERVED_SPACE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	int delta = hh_len - skb_headroom(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	const struct in6_addr *nexthop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	struct neighbour *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	/* Be paranoid, rather than too clever. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	if (unlikely(delta > 0) && dev->header_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		/* pskb_expand_head() might crash, if skb is shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		if (skb_shared(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 			struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 			if (likely(nskb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 				if (skb->sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 					skb_set_owner_w(nskb, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 				consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 				kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 			skb = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		if (skb &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 		    pskb_expand_head(skb, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 			skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		if (!(dev->flags & IFF_LOOPBACK) && sk_mc_loop(sk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		    ((mroute6_is_socket(net, skb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		     !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		     ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 					 &ipv6_hdr(skb)->saddr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 			struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 			/* Do not check for IFF_ALLMULTI; multicast routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 			   is not supported in any case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 			if (newskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 				NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 					net, sk, newskb, NULL, newskb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 					dev_loopback_xmit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			if (ipv6_hdr(skb)->hop_limit == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 				IP6_INC_STATS(net, idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 					      IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 				kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUTMCAST, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		if (IPV6_ADDR_MC_SCOPE(&ipv6_hdr(skb)->daddr) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		    IPV6_ADDR_SCOPE_NODELOCAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		    !(dev->flags & IFF_LOOPBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	if (lwtunnel_xmit_redirect(dst->lwtstate)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		int res = lwtunnel_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		if (res < 0 || res == LWTUNNEL_XMIT_DONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	if (unlikely(!neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	if (!IS_ERR(neigh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		sock_confirm_neigh(skb, neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		ret = neigh_output(neigh, skb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) ip6_finish_output_gso_slowpath_drop(struct net *net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 				    struct sk_buff *skb, unsigned int mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	struct sk_buff *segs, *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	netdev_features_t features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	/* Please see corresponding comment in ip_finish_output_gso
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	 * describing the cases where GSO segment length exceeds the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	 * egress MTU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	features = netif_skb_features(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	if (IS_ERR_OR_NULL(segs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	skb_list_walk_safe(segs, segs, nskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		skb_mark_not_on_list(segs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		err = ip6_fragment(net, sk, segs, ip6_finish_output2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		if (err && ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 			ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static int __ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	unsigned int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) #if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	/* Policy lookup after SNAT yielded a new policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (skb_dst(skb)->xfrm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		IP6CB(skb)->flags |= IP6SKB_REROUTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		return dst_output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	mtu = ip6_skb_dst_mtu(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	if (skb_is_gso(skb) && !skb_gso_validate_network_len(skb, mtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		return ip6_finish_output_gso_slowpath_drop(net, sk, skb, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	if ((skb->len > mtu && !skb_is_gso(skb)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	    dst_allfrag(skb_dst(skb)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	    (IP6CB(skb)->frag_max_size && skb->len > IP6CB(skb)->frag_max_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		return ip6_fragment(net, sk, skb, ip6_finish_output2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		return ip6_finish_output2(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	ret = BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	case NET_XMIT_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		return __ip6_finish_output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	case NET_XMIT_CN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		return __ip6_finish_output(net, sk, skb) ? : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	struct net_device *dev = skb_dst(skb)->dev, *indev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	skb->protocol = htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	if (unlikely(idev->cnf.disable_ipv6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			    net, sk, skb, indev, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 			    ip6_finish_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			    !(IP6CB(skb)->flags & IP6SKB_REROUTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (!np->autoflowlabel_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		return ip6_default_np_autolabel(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		return np->autoflowlabel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  * xmit an sk_buff (used by TCP, SCTP and DCCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)  * Note : socket lock is not held for SYNACK packets, but might be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  * by calls to skb_set_owner_w() and ipv6_local_error(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * which are using proper atomic operations or spinlocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	     __u32 mark, struct ipv6_txoptions *opt, int tclass, u32 priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	const struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	struct in6_addr *first_hop = &fl6->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	unsigned int head_room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	struct ipv6hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	u8  proto = fl6->flowi6_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	int seg_len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	int hlimit = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dst->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		head_room += opt->opt_nflen + opt->opt_flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	if (unlikely(skb_headroom(skb) < head_room)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		if (!skb2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 				      IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		if (skb->sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			skb_set_owner_w(skb2, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		skb = skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	if (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		seg_len += opt->opt_nflen + opt->opt_flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		if (opt->opt_flen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			ipv6_push_frag_opts(skb, opt, &proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		if (opt->opt_nflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			ipv6_push_nfrag_opts(skb, opt, &proto, &first_hop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 					     &fl6->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	skb_push(skb, sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	 *	Fill in the IPv6 header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	if (np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		hlimit = np->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	if (hlimit < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		hlimit = ip6_dst_hoplimit(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	ip6_flow_hdr(hdr, tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 				ip6_autoflowlabel(net, np), fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	hdr->payload_len = htons(seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	hdr->nexthdr = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	hdr->hop_limit = hlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	hdr->saddr = fl6->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	hdr->daddr = *first_hop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	skb->protocol = htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	skb->priority = priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	skb->mark = mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	mtu = dst_mtu(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			      IPSTATS_MIB_OUT, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		/* if egress device is enslaved to an L3 master device pass the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		 * skb to its handler for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		skb = l3mdev_ip6_out((struct sock *)sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		/* hooks should never assume socket lock is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		 * we promote our socket to non const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			       net, (struct sock *)sk, skb, NULL, dst->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			       dst_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	skb->dev = dst->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	/* ipv6_local_error() does not require socket lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	 * we promote our socket to non const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	ipv6_local_error((struct sock *)sk, EMSGSIZE, fl6, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) EXPORT_SYMBOL(ip6_xmit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) static int ip6_call_ra_chain(struct sk_buff *skb, int sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	struct ip6_ra_chain *ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	struct sock *last = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	read_lock(&ip6_ra_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	for (ra = ip6_ra_chain; ra; ra = ra->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		struct sock *sk = ra->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		if (sk && ra->sel == sel &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		    (!sk->sk_bound_dev_if ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		     sk->sk_bound_dev_if == skb->dev->ifindex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			if (np && np->rtalert_isolate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			    !net_eq(sock_net(sk), dev_net(skb->dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			if (last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 				struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 				if (skb2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 					rawv6_rcv(last, skb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			last = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	if (last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		rawv6_rcv(last, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		read_unlock(&ip6_ra_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	read_unlock(&ip6_ra_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) static int ip6_forward_proxy_check(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	struct ipv6hdr *hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	u8 nexthdr = hdr->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	__be16 frag_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	if (ipv6_ext_hdr(nexthdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		offset = ipv6_skip_exthdr(skb, sizeof(*hdr), &nexthdr, &frag_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		if (offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		offset = sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (nexthdr == IPPROTO_ICMPV6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		struct icmp6hdr *icmp6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		if (!pskb_may_pull(skb, (skb_network_header(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 					 offset + 1 - skb->data)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		icmp6 = (struct icmp6hdr *)(skb_network_header(skb) + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		switch (icmp6->icmp6_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		case NDISC_ROUTER_SOLICITATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		case NDISC_ROUTER_ADVERTISEMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		case NDISC_NEIGHBOUR_SOLICITATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		case NDISC_NEIGHBOUR_ADVERTISEMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		case NDISC_REDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 			/* For reaction involving unicast neighbor discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			 * message destined to the proxied address, pass it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			 * input function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	 * The proxying router can't forward traffic sent to a link-local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	 * address, so signal the sender and discard the packet. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	 * behavior is clarified by the MIPv6 specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	if (ipv6_addr_type(&hdr->daddr) & IPV6_ADDR_LINKLOCAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		dst_link_failure(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) static inline int ip6_forward_finish(struct net *net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				     struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	__IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTFORWDATAGRAMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	__IP6_ADD_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTOCTETS, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) #ifdef CONFIG_NET_SWITCHDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	if (skb->offload_l3_fwd_mark) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	skb->tstamp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	return dst_output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (skb->len <= mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	/* ipv6 conntrack defrag sets max_frag_size + ignore_df */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (IP6CB(skb)->frag_max_size && IP6CB(skb)->frag_max_size > mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (skb->ignore_df)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) int ip6_forward(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	struct ipv6hdr *hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	struct inet6_skb_parm *opt = IP6CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	struct net *net = dev_net(dst->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	if (net->ipv6.devconf_all->forwarding == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	if (skb->pkt_type != PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	if (unlikely(skb->sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	if (skb_warn_if_lro(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (!net->ipv6.devconf_all->disable_policy &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	    !idev->cnf.disable_policy &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	    !xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	skb_forward_csum(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	 *	We DO NOT make any processing on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	 *	RA packets, pushing them to user level AS IS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	 *	without ane WARRANTY that application will be able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	 *	to interpret them. The reason is that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	 *	cannot make anything clever here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	 *	We are not end-node, so that if packet contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	 *	AH/ESP, we cannot make anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	 *	Defragmentation also would be mistake, RA packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	 *	cannot be fragmented, because there is no warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	 *	that different fragments will go along one path. --ANK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (unlikely(opt->flags & IP6SKB_ROUTERALERT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		if (ip6_call_ra_chain(skb, ntohs(opt->ra)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	 *	check and decrement ttl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	if (hdr->hop_limit <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	/* XXX: idev->cnf.proxy_ndp? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	if (net->ipv6.devconf_all->proxy_ndp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	    pneigh_lookup(&nd_tbl, net, &hdr->daddr, skb->dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		int proxied = ip6_forward_proxy_check(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		if (proxied > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			return ip6_input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		else if (proxied < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 			__IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (!xfrm6_route_forward(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	/* IPv6 specs say nothing about it, but it is clear that we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	   send redirects to source routed frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	   We don't send redirects to frames decapsulated from IPsec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (IP6CB(skb)->iif == dst->dev->ifindex &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	    opt->srcrt == 0 && !skb_sec_path(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		struct in6_addr *target = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		struct inet_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		 *	incoming and outgoing devices are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		 *	send a redirect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		rt = (struct rt6_info *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		if (rt->rt6i_flags & RTF_GATEWAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 			target = &rt->rt6i_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			target = &hdr->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		/* Limit redirects both by destination (here)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		   and by source (inside ndisc_send_redirect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		if (inet_peer_xrlim_allow(peer, 1*HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 			ndisc_send_redirect(skb, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		if (peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			inet_putpeer(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		int addrtype = ipv6_addr_type(&hdr->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		/* This check is security critical. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		if (addrtype == IPV6_ADDR_ANY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		    addrtype & (IPV6_ADDR_MULTICAST | IPV6_ADDR_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		if (addrtype & IPV6_ADDR_LINKLOCAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 			icmpv6_send(skb, ICMPV6_DEST_UNREACH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 				    ICMPV6_NOT_NEIGHBOUR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	mtu = ip6_dst_mtu_forward(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	if (mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	if (ip6_pkt_too_big(skb, mtu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		/* Again, force OUTPUT device used as source address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		skb->dev = dst->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INTOOBIGERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		__IP6_INC_STATS(net, ip6_dst_idev(dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				IPSTATS_MIB_FRAGFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		return -EMSGSIZE;
^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) 	if (skb_cow(skb, dst->dev->hard_header_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		__IP6_INC_STATS(net, ip6_dst_idev(dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 				IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	/* Mangling hops number delayed to point after skb COW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	hdr->hop_limit--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	return NF_HOOK(NFPROTO_IPV6, NF_INET_FORWARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		       net, NULL, skb, skb->dev, dst->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		       ip6_forward_finish);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	__IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	to->pkt_type = from->pkt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	to->priority = from->priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	to->protocol = from->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	skb_dst_drop(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	skb_dst_set(to, dst_clone(skb_dst(from)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	to->dev = from->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	to->mark = from->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	skb_copy_hash(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) #ifdef CONFIG_NET_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	to->tc_index = from->tc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	nf_copy(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	skb_ext_copy(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	skb_copy_secmark(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) int ip6_fraglist_init(struct sk_buff *skb, unsigned int hlen, u8 *prevhdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		      u8 nexthdr, __be32 frag_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		      struct ip6_fraglist_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	unsigned int first_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	struct frag_hdr *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	/* BUILD HEADER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	*prevhdr = NEXTHDR_FRAGMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	iter->tmp_hdr = kmemdup(skb_network_header(skb), hlen, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (!iter->tmp_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	iter->frag = skb_shinfo(skb)->frag_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	skb_frag_list_init(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	iter->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	iter->hlen = hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	iter->frag_id = frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	iter->nexthdr = nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	__skb_pull(skb, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	fh = __skb_push(skb, sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	__skb_push(skb, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	memcpy(skb_network_header(skb), iter->tmp_hdr, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	fh->nexthdr = nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	fh->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	fh->frag_off = htons(IP6_MF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	fh->identification = frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	first_len = skb_pagelen(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	skb->data_len = first_len - skb_headlen(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	skb->len = first_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	ipv6_hdr(skb)->payload_len = htons(first_len - sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) EXPORT_SYMBOL(ip6_fraglist_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) void ip6_fraglist_prepare(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			  struct ip6_fraglist_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct sk_buff *frag = iter->frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	unsigned int hlen = iter->hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	struct frag_hdr *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	frag->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	skb_reset_transport_header(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	fh = __skb_push(frag, sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	__skb_push(frag, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	skb_reset_network_header(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	memcpy(skb_network_header(frag), iter->tmp_hdr, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	iter->offset += skb->len - hlen - sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	fh->nexthdr = iter->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	fh->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	fh->frag_off = htons(iter->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	if (frag->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		fh->frag_off |= htons(IP6_MF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	fh->identification = iter->frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	ipv6_hdr(frag)->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	ip6_copy_metadata(frag, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) EXPORT_SYMBOL(ip6_fraglist_prepare);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) void ip6_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		   unsigned short needed_tailroom, int hdr_room, u8 *prevhdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		   u8 nexthdr, __be32 frag_id, struct ip6_frag_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	state->prevhdr = prevhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	state->nexthdr = nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	state->frag_id = frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	state->hlen = hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	state->mtu = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	state->left = skb->len - hlen;	/* Space per frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	state->ptr = hlen;		/* Where to start from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	state->hroom = hdr_room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	state->troom = needed_tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	state->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) EXPORT_SYMBOL(ip6_frag_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) struct sk_buff *ip6_frag_next(struct sk_buff *skb, struct ip6_frag_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	u8 *prevhdr = state->prevhdr, *fragnexthdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	struct frag_hdr *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	len = state->left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	/* IF: it doesn't fit, use 'mtu' - the data space left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	if (len > state->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		len = state->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	/* IF: we are not sending up to and including the packet end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	   then align the next start on an eight byte boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	if (len < state->left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		len &= ~7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	/* Allocate buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	frag = alloc_skb(len + state->hlen + sizeof(struct frag_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			 state->hroom + state->troom, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if (!frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	 *	Set up data on packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	ip6_copy_metadata(frag, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	skb_reserve(frag, state->hroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	skb_put(frag, len + state->hlen + sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	skb_reset_network_header(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	fh = (struct frag_hdr *)(skb_network_header(frag) + state->hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	frag->transport_header = (frag->network_header + state->hlen +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 				  sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	 *	Charge the memory for the fragment to any owner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	 *	it might possess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	if (skb->sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		skb_set_owner_w(frag, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	 *	Copy the packet header into the new buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	skb_copy_from_linear_data(skb, skb_network_header(frag), state->hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	fragnexthdr_offset = skb_network_header(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	fragnexthdr_offset += prevhdr - skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	*fragnexthdr_offset = NEXTHDR_FRAGMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	 *	Build fragment header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	fh->nexthdr = state->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	fh->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	fh->identification = state->frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	 *	Copy a block of the IP datagram.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	BUG_ON(skb_copy_bits(skb, state->ptr, skb_transport_header(frag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			     len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	state->left -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	fh->frag_off = htons(state->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	if (state->left > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		fh->frag_off |= htons(IP6_MF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	ipv6_hdr(frag)->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	state->ptr += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	state->offset += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	return frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) EXPORT_SYMBOL(ip6_frag_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		 int (*output)(struct net *, struct sock *, struct sk_buff *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 				inet6_sk(skb->sk) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	struct ip6_frag_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	unsigned int mtu, hlen, nexthdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	ktime_t tstamp = skb->tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	int hroom, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	__be32 frag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	u8 *prevhdr, nexthdr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	err = ip6_find_1stfragopt(skb, &prevhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	hlen = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	nexthdr = *prevhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	nexthdr_offset = prevhdr - skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	mtu = ip6_skb_dst_mtu(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	/* We must not fragment if the socket is set to force MTU discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	 * or if the skb it not generated by a local socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	if (unlikely(!skb->ignore_df && skb->len > mtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		goto fail_toobig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	if (IP6CB(skb)->frag_max_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		if (IP6CB(skb)->frag_max_size > mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			goto fail_toobig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		/* don't send fragments larger than what we received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		mtu = IP6CB(skb)->frag_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		if (mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	if (np && np->frag_size < mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		if (np->frag_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			mtu = np->frag_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	if (mtu < hlen + sizeof(struct frag_hdr) + 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		goto fail_toobig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	mtu -= hlen + sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	frag_id = ipv6_select_ident(net, &ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 				    &ipv6_hdr(skb)->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	if (skb->ip_summed == CHECKSUM_PARTIAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	    (err = skb_checksum_help(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	prevhdr = skb_network_header(skb) + nexthdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	hroom = LL_RESERVED_SPACE(rt->dst.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (skb_has_frag_list(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		unsigned int first_len = skb_pagelen(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		struct ip6_fraglist_iter iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		struct sk_buff *frag2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		if (first_len - hlen > mtu ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		    ((first_len - hlen) & 7) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		    skb_cloned(skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		    skb_headroom(skb) < (hroom + sizeof(struct frag_hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			goto slow_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		skb_walk_frags(skb, frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 			/* Correct geometry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 			if (frag->len > mtu ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			    ((frag->len & 7) && frag->next) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			    skb_headroom(frag) < (hlen + hroom + sizeof(struct frag_hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 				goto slow_path_clean;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			/* Partially cloned skb? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 			if (skb_shared(frag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 				goto slow_path_clean;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			BUG_ON(frag->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 			if (skb->sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 				frag->sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 				frag->destructor = sock_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			skb->truesize -= frag->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		err = ip6_fraglist_init(skb, hlen, prevhdr, nexthdr, frag_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 					&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 			/* Prepare header of the next frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			 * before previous one went down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			if (iter.frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 				ip6_fraglist_prepare(skb, &iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 			skb->tstamp = tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			err = output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 			if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 				IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 					      IPSTATS_MIB_FRAGCREATES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			if (err || !iter.frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 			skb = ip6_fraglist_next(&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		kfree(iter.tmp_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 			IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 				      IPSTATS_MIB_FRAGOKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		kfree_skb_list(iter.frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			      IPSTATS_MIB_FRAGFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) slow_path_clean:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		skb_walk_frags(skb, frag2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 			if (frag2 == frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			frag2->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			frag2->destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			skb->truesize += frag2->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) slow_path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	 *	Fragment the datagram.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	ip6_frag_init(skb, hlen, mtu, rt->dst.dev->needed_tailroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		      LL_RESERVED_SPACE(rt->dst.dev), prevhdr, nexthdr, frag_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		      &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	 *	Keep copying data until we run out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	while (state.left > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		frag = ip6_frag_next(skb, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		if (IS_ERR(frag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			err = PTR_ERR(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		 *	Put this fragment into the sending queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		frag->tstamp = tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		err = output(net, sk, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			      IPSTATS_MIB_FRAGCREATES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		      IPSTATS_MIB_FRAGOKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) fail_toobig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	if (skb->sk && dst_allfrag(skb_dst(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		sk_nocaps_add(skb->sk, NETIF_F_GSO_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		      IPSTATS_MIB_FRAGFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static inline int ip6_rt_check(const struct rt6key *rt_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 			       const struct in6_addr *fl_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 			       const struct in6_addr *addr_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	return (rt_key->plen != 128 || !ipv6_addr_equal(fl_addr, &rt_key->addr)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		(!addr_cache || !ipv6_addr_equal(fl_addr, addr_cache));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 					  struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 					  const struct flowi6 *fl6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	if (!dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	if (dst->ops->family != AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	rt = (struct rt6_info *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	/* Yes, checking route validity in not connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	 * case is not very simple. Take into account,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	 * that we do not support routing by source, TOS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	 * and MSG_DONTROUTE		--ANK (980726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	 * 1. ip6_rt_check(): If route was host route,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	 *    check that cached destination is current.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	 *    If it is network route, we still may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	 *    check its validity using saved pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	 *    to the last used address: daddr_cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	 *    We do not want to save whole address now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	 *    (because main consumer of this service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	 *    is tcp, which has not this problem),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	 *    so that the last trick works only on connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	 *    sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	 * 2. oif also should be the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (ip6_rt_check(&rt->rt6i_dst, &fl6->daddr, np->daddr_cache) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	    ip6_rt_check(&rt->rt6i_src, &fl6->saddr, np->saddr_cache) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	   (!(fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	      (fl6->flowi6_oif && fl6->flowi6_oif != dst->dev->ifindex))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			       struct dst_entry **dst, struct flowi6 *fl6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	/* The correct way to handle this would be to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	 * ip6_route_get_saddr, and then ip6_route_output; however,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	 * the route-specific preferred source forces the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	 * ip6_route_output call _before_ ip6_route_get_saddr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	 * In source specific routing (no src=any default route),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	 * ip6_route_output will fail given src=any saddr, though, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	 * that's why we try it again later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (ipv6_addr_any(&fl6->saddr) && (!*dst || !(*dst)->error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		struct fib6_info *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		bool had_dst = *dst != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		if (!had_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			*dst = ip6_route_output(net, sk, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		from = rt ? rcu_dereference(rt->from) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		err = ip6_route_get_saddr(net, from, &fl6->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 					  sk ? inet6_sk(sk)->srcprefs : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 					  &fl6->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			goto out_err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		/* If we had an erroneous initial result, pretend it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		 * never existed and let the SA-enabled version take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		 * over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		if (!had_dst && (*dst)->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			dst_release(*dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			*dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		if (fl6->flowi6_oif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 			flags |= RT6_LOOKUP_F_IFACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	if (!*dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		*dst = ip6_route_output_flags(net, sk, fl6, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	err = (*dst)->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		goto out_err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	 * Here if the dst entry we've looked up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	 * has a neighbour entry that is in the INCOMPLETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	 * state and the src address from the flow is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	 * marked as OPTIMISTIC, we release the found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	 * dst entry and replace it instead with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	 * dst entry of the nexthop router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	rt = (struct rt6_info *) *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	n = __ipv6_neigh_lookup_noref(rt->dst.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 				      rt6_nexthop(rt, &fl6->daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		struct flowi6 fl_gw6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		int redirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		ifp = ipv6_get_ifaddr(net, &fl6->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 				      (*dst)->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		redirect = (ifp && ifp->flags & IFA_F_OPTIMISTIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		if (ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		if (redirect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 			 * We need to get the dst entry for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 			 * default router instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			dst_release(*dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 			memcpy(&fl_gw6, fl6, sizeof(struct flowi6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			memset(&fl_gw6.daddr, 0, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			*dst = ip6_route_output(net, sk, &fl_gw6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			err = (*dst)->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 				goto out_err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (ipv6_addr_v4mapped(&fl6->saddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	    !(ipv6_addr_v4mapped(&fl6->daddr) || ipv6_addr_any(&fl6->daddr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		err = -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		goto out_err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) out_err_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	dst_release(*dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	*dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	if (err == -ENETUNREACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		IP6_INC_STATS(net, NULL, IPSTATS_MIB_OUTNOROUTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  *	ip6_dst_lookup - perform route lookup on flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  *	@net: Network namespace to perform lookup in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  *	@sk: socket which provides route info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  *	@dst: pointer to dst_entry * for result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  *	@fl6: flow to lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)  *	This function performs a route lookup on the given flow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)  *	It returns zero on success, or a standard errno code on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		   struct flowi6 *fl6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	*dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	return ip6_dst_lookup_tail(net, sk, dst, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) EXPORT_SYMBOL_GPL(ip6_dst_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)  *	ip6_dst_lookup_flow - perform route lookup on flow with ipsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)  *	@net: Network namespace to perform lookup in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)  *	@sk: socket which provides route info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)  *	@fl6: flow to lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)  *	@final_dst: final destination address for ipsec lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  *	This function performs a route lookup on the given flow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)  *	It returns a valid dst pointer on success, or a pointer encoded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)  *	error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 				      const struct in6_addr *final_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	struct dst_entry *dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	err = ip6_dst_lookup_tail(net, sk, &dst, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	if (final_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		fl6->daddr = *final_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	return xfrm_lookup_route(net, dst, flowi6_to_flowi(fl6), sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  *	ip6_sk_dst_lookup_flow - perform socket cached route lookup on flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)  *	@sk: socket which provides the dst cache and route info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)  *	@fl6: flow to lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)  *	@final_dst: final destination address for ipsec lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)  *	@connected: whether @sk is connected or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)  *	This function performs a route lookup on the given flow with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)  *	possibility of using the cached route in the socket if it is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)  *	It will take the socket dst lock when operating on the dst cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)  *	As a result, this function can only be used in process context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)  *	In addition, for a connected socket, cache the dst in the socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)  *	if the current cache is not valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)  *	It returns a valid dst pointer on success, or a pointer encoded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)  *	error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 					 const struct in6_addr *final_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 					 bool connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	dst = ip6_sk_dst_check(sk, dst, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	if (connected && !IS_ERR(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		ip6_sk_dst_store_flow(sk, dst_clone(dst), fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)  *      ip6_dst_lookup_tunnel - perform route lookup on tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)  *      @skb: Packet for which lookup is done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)  *      @dev: Tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)  *      @net: Network namespace of tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)  *      @sock: Socket which provides route info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)  *      @saddr: Memory to store the src ip address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)  *      @info: Tunnel information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)  *      @protocol: IP protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)  *      @use_cache: Flag to enable cache usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)  *      This function performs a route lookup on a tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)  *      It returns a valid dst pointer and stores src address to be used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)  *      tunnel in param saddr on success, else a pointer encoded error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 					struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 					struct socket *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 					struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 					const struct ip_tunnel_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 					u8 protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 					bool use_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	struct dst_entry *dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) #ifdef CONFIG_DST_CACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	struct dst_cache *dst_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	__u8 prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) #ifdef CONFIG_DST_CACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	dst_cache = (struct dst_cache *)&info->dst_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	if (use_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		dst = dst_cache_get_ip6(dst_cache, saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	memset(&fl6, 0, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	fl6.flowi6_mark = skb->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	fl6.flowi6_proto = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	fl6.daddr = info->key.u.ipv6.dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	fl6.saddr = info->key.u.ipv6.src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	prio = info->key.tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	fl6.flowlabel = ip6_make_flowinfo(RT_TOS(prio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 					  info->key.label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	dst = ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 					      NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		netdev_dbg(dev, "no route to %pI6\n", &fl6.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		return ERR_PTR(-ENETUNREACH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	if (dst->dev == dev) { /* is this necessary? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		netdev_dbg(dev, "circular route to %pI6\n", &fl6.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		return ERR_PTR(-ELOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) #ifdef CONFIG_DST_CACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	if (use_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		dst_cache_set_ip6(dst_cache, dst, &fl6.saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	*saddr = fl6.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) EXPORT_SYMBOL_GPL(ip6_dst_lookup_tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) static inline struct ipv6_opt_hdr *ip6_opt_dup(struct ipv6_opt_hdr *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 					       gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) static inline struct ipv6_rt_hdr *ip6_rthdr_dup(struct ipv6_rt_hdr *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 						gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) static void ip6_append_data_mtu(unsigned int *mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 				int *maxfraglen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 				unsigned int fragheaderlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 				struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 				struct rt6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 				unsigned int orig_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			/* first fragment, reserve header_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			*mtu = orig_mtu - rt->dst.header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			 * this fragment is not first, the headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			 * space is regarded as data space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			*mtu = orig_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		*maxfraglen = ((*mtu - fragheaderlen) & ~7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			      + fragheaderlen - sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 			  struct inet6_cork *v6_cork, struct ipcm6_cookie *ipc6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			  struct rt6_info *rt, struct flowi6 *fl6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	unsigned int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	struct ipv6_txoptions *opt = ipc6->opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	 * setup for corking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	if (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		if (WARN_ON(v6_cork->opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		v6_cork->opt = kzalloc(sizeof(*opt), sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		if (unlikely(!v6_cork->opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		v6_cork->opt->tot_len = sizeof(*opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		v6_cork->opt->opt_flen = opt->opt_flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		v6_cork->opt->opt_nflen = opt->opt_nflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		v6_cork->opt->dst0opt = ip6_opt_dup(opt->dst0opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 						    sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		if (opt->dst0opt && !v6_cork->opt->dst0opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		v6_cork->opt->dst1opt = ip6_opt_dup(opt->dst1opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 						    sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		if (opt->dst1opt && !v6_cork->opt->dst1opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		v6_cork->opt->hopopt = ip6_opt_dup(opt->hopopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 						   sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		if (opt->hopopt && !v6_cork->opt->hopopt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		v6_cork->opt->srcrt = ip6_rthdr_dup(opt->srcrt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 						    sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		if (opt->srcrt && !v6_cork->opt->srcrt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		/* need source address above miyazawa*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	dst_hold(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	cork->base.dst = &rt->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	cork->fl.u.ip6 = *fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	v6_cork->hop_limit = ipc6->hlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	v6_cork->tclass = ipc6->tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	if (rt->dst.flags & DST_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		      READ_ONCE(rt->dst.dev->mtu) : dst_mtu(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			READ_ONCE(rt->dst.dev->mtu) : dst_mtu(xfrm_dst_path(&rt->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	if (np->frag_size < mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		if (np->frag_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			mtu = np->frag_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	cork->base.fragsize = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	cork->base.gso_size = ipc6->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	cork->base.tx_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	cork->base.mark = ipc6->sockc.mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (dst_allfrag(xfrm_dst_path(&rt->dst)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		cork->base.flags |= IPCORK_ALLFRAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	cork->base.length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	cork->base.transmit_time = ipc6->sockc.transmit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) static int __ip6_append_data(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			     struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			     struct sk_buff_head *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 			     struct inet_cork *cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 			     struct inet6_cork *v6_cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 			     struct page_frag *pfrag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			     int getfrag(void *from, char *to, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 					 int len, int odd, struct sk_buff *skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 			     void *from, int length, int transhdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			     unsigned int flags, struct ipcm6_cookie *ipc6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	struct sk_buff *skb, *skb_prev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu, pmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	struct ubuf_info *uarg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	int exthdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	int dst_exthdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	int hh_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	int copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	u32 tskey = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	struct rt6_info *rt = (struct rt6_info *)cork->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	struct ipv6_txoptions *opt = v6_cork->opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	int csummode = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	unsigned int maxnonfragsize, headersize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	unsigned int wmem_alloc_delta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	bool paged, extra_uref = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	skb = skb_peek_tail(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		exthdrlen = opt ? opt->opt_flen : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		dst_exthdrlen = rt->dst.header_len - rt->rt6i_nfheader_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	paged = !!cork->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	mtu = cork->gso_size ? IP6_MAX_MTU : cork->fragsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	orig_mtu = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	if (cork->tx_flags & SKBTX_ANY_SW_TSTAMP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	    sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		tskey = sk->sk_tskey++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	hh_len = LL_RESERVED_SPACE(rt->dst.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	fragheaderlen = sizeof(struct ipv6hdr) + rt->rt6i_nfheader_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 			(opt ? opt->opt_nflen : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	headersize = sizeof(struct ipv6hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		     (opt ? opt->opt_flen + opt->opt_nflen : 0) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		     (dst_allfrag(&rt->dst) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		      sizeof(struct frag_hdr) : 0) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		     rt->rt6i_nfheader_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	if (mtu <= fragheaderlen ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	    ((mtu - fragheaderlen) & ~7) + fragheaderlen <= sizeof(struct frag_hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		goto emsgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 		     sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	/* as per RFC 7112 section 5, the entire IPv6 Header Chain must fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	 * the first fragment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	if (headersize + transhdrlen > mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		goto emsgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	if (cork->length + length > mtu - headersize && ipc6->dontfrag &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	    (sk->sk_protocol == IPPROTO_UDP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	     sk->sk_protocol == IPPROTO_RAW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		ipv6_local_rxpmtu(sk, fl6, mtu - headersize +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 				sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		goto emsgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	if (ip6_sk_ignore_df(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 		maxnonfragsize = sizeof(struct ipv6hdr) + IPV6_MAXPLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		maxnonfragsize = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	if (cork->length + length > maxnonfragsize - headersize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) emsgsize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		pmtu = max_t(int, mtu - headersize + sizeof(struct ipv6hdr), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		ipv6_local_error(sk, EMSGSIZE, fl6, pmtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	/* CHECKSUM_PARTIAL only with no extension headers and when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	 * we are not going to fragment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	if (transhdrlen && sk->sk_protocol == IPPROTO_UDP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	    headersize == sizeof(struct ipv6hdr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	    length <= mtu - headersize &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	    (!(flags & MSG_MORE) || cork->gso_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	    rt->dst.dev->features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		csummode = CHECKSUM_PARTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	if (flags & MSG_ZEROCOPY && length && sock_flag(sk, SOCK_ZEROCOPY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 		uarg = sock_zerocopy_realloc(sk, length, skb_zcopy(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		if (!uarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 			return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		extra_uref = !skb_zcopy(skb);	/* only ref on new uarg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		if (rt->dst.dev->features & NETIF_F_SG &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		    csummode == CHECKSUM_PARTIAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 			paged = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 			uarg->zerocopy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 			skb_zcopy_set(skb, uarg, &extra_uref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	 * Let's try using as much space as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	 * Use MTU if total length of the message fits into the MTU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	 * Otherwise, we need to reserve fragment header and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	 * fragment alignment (= 8-15 octects, in total).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	 * Note that we may need to "move" the data from the tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	 * of the buffer to the new fragment when we split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	 * the message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	 * FIXME: It may be fragmented into multiple chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	 *        at once if non-fragmentable extension headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	 *        are too large.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	 * --yoshfuji
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	cork->length += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		goto alloc_new_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	while (length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		/* Check if the remaining data fits into current packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		copy = (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 		if (copy < length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 			copy = maxfraglen - skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		if (copy <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 			char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			unsigned int datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 			unsigned int fraglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			unsigned int fraggap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 			unsigned int alloclen, alloc_extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			unsigned int pagedlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) alloc_new_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 			/* There's no room in the current skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 			if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 				fraggap = skb->len - maxfraglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 				fraggap = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			/* update mtu and maxfraglen if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 			if (!skb || !skb_prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 				ip6_append_data_mtu(&mtu, &maxfraglen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 						    fragheaderlen, skb, rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 						    orig_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 			skb_prev = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 			 * If remaining data exceeds the mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 			 * we know we need more fragment(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 			datalen = length + fraggap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 			if (datalen > (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 				datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			fraglen = datalen + fragheaderlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 			pagedlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			alloc_extra = hh_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			alloc_extra += dst_exthdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 			alloc_extra += rt->dst.trailer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			/* We just reserve space for fragment header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 			 * Note: this may be overallocation if the message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			 * (without MSG_MORE) fits into the MTU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 			alloc_extra += sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 			if ((flags & MSG_MORE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 			    !(rt->dst.dev->features&NETIF_F_SG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 				alloclen = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			else if (!paged &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 				 (fraglen + alloc_extra < SKB_MAX_ALLOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 				  !(rt->dst.dev->features & NETIF_F_SG)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 				alloclen = fraglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 				alloclen = min_t(int, fraglen, MAX_HEADER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 				pagedlen = fraglen - alloclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 			alloclen += alloc_extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 			if (datalen != length + fraggap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 				 * this is not the last fragment, the trailer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 				 * space is regarded as data space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 				datalen += rt->dst.trailer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 			fraglen = datalen + fragheaderlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 			copy = datalen - transhdrlen - fraggap - pagedlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			if (copy < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 				err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 			if (transhdrlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 				skb = sock_alloc_send_skb(sk, alloclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 						(flags & MSG_DONTWAIT), &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 				skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 				if (refcount_read(&sk->sk_wmem_alloc) + wmem_alloc_delta <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 				    2 * sk->sk_sndbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 					skb = alloc_skb(alloclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 							sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 				if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 					err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 			if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			 *	Fill in the control structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 			skb->protocol = htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 			skb->ip_summed = csummode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 			skb->csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			/* reserve for fragmentation and ipsec header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 			skb_reserve(skb, hh_len + sizeof(struct frag_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 				    dst_exthdrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			 *	Find where to start putting bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			data = skb_put(skb, fraglen - pagedlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			skb_set_network_header(skb, exthdrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 			data += fragheaderlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			skb->transport_header = (skb->network_header +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 						 fragheaderlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			if (fraggap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 				skb->csum = skb_copy_and_csum_bits(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 					skb_prev, maxfraglen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 					data + transhdrlen, fraggap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 				skb_prev->csum = csum_sub(skb_prev->csum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 							  skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 				data += fraggap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 				pskb_trim_unique(skb_prev, maxfraglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			if (copy > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 			    getfrag(from, data + transhdrlen, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 				    copy, fraggap, skb) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 				err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 				kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 			offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 			length -= copy + transhdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 			transhdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 			exthdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 			dst_exthdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 			/* Only the initial fragment is time stamped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 			skb_shinfo(skb)->tx_flags = cork->tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 			cork->tx_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 			skb_shinfo(skb)->tskey = tskey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 			tskey = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 			skb_zcopy_set(skb, uarg, &extra_uref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 			if ((flags & MSG_CONFIRM) && !skb_prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 				skb_set_dst_pending_confirm(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 			 * Put the packet on the pending queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 			if (!skb->destructor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 				skb->destructor = sock_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 				skb->sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 				wmem_alloc_delta += skb->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 			__skb_queue_tail(queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		if (copy > length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 			copy = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		if (!(rt->dst.dev->features&NETIF_F_SG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		    skb_tailroom(skb) >= copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 			unsigned int off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 			off = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 			if (getfrag(from, skb_put(skb, copy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 						offset, copy, off, skb) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 				__skb_trim(skb, off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 				err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		} else if (!uarg || !uarg->zerocopy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			int i = skb_shinfo(skb)->nr_frags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 			if (!sk_page_frag_refill(sk, pfrag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 			if (!skb_can_coalesce(skb, i, pfrag->page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 					      pfrag->offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 				err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 				if (i == MAX_SKB_FRAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 					goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 				__skb_fill_page_desc(skb, i, pfrag->page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 						     pfrag->offset, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 				skb_shinfo(skb)->nr_frags = ++i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 				get_page(pfrag->page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 			copy = min_t(int, copy, pfrag->size - pfrag->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 			if (getfrag(from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 				    page_address(pfrag->page) + pfrag->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 				    offset, copy, skb->len, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 				goto error_efault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 			pfrag->offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 			skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 			skb->len += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 			skb->data_len += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 			skb->truesize += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 			wmem_alloc_delta += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 			err = skb_zerocopy_iter_dgram(skb, from, copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		length -= copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	if (wmem_alloc_delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) error_efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	if (uarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		sock_zerocopy_put_abort(uarg, extra_uref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	cork->length -= length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) int ip6_append_data(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		    int getfrag(void *from, char *to, int offset, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 				int odd, struct sk_buff *skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		    void *from, int length, int transhdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		    struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		    struct rt6_info *rt, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	int exthdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	if (flags&MSG_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	if (skb_queue_empty(&sk->sk_write_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 		 * setup for corking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		err = ip6_setup_cork(sk, &inet->cork, &np->cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 				     ipc6, rt, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 		exthdrlen = (ipc6->opt ? ipc6->opt->opt_flen : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 		length += exthdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		transhdrlen += exthdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		fl6 = &inet->cork.fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 		transhdrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	return __ip6_append_data(sk, fl6, &sk->sk_write_queue, &inet->cork.base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 				 &np->cork, sk_page_frag(sk), getfrag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 				 from, length, transhdrlen, flags, ipc6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) EXPORT_SYMBOL_GPL(ip6_append_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) static void ip6_cork_release(struct inet_cork_full *cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 			     struct inet6_cork *v6_cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	if (v6_cork->opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		kfree(v6_cork->opt->dst0opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		kfree(v6_cork->opt->dst1opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		kfree(v6_cork->opt->hopopt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		kfree(v6_cork->opt->srcrt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 		kfree(v6_cork->opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 		v6_cork->opt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	if (cork->base.dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		dst_release(cork->base.dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		cork->base.dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		cork->base.flags &= ~IPCORK_ALLFRAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	memset(&cork->fl, 0, sizeof(cork->fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct sk_buff *__ip6_make_skb(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 			       struct sk_buff_head *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 			       struct inet_cork_full *cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			       struct inet6_cork *v6_cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	struct sk_buff *skb, *tmp_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	struct sk_buff **tail_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	struct in6_addr final_dst_buf, *final_dst = &final_dst_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	struct ipv6hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	struct ipv6_txoptions *opt = v6_cork->opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	struct rt6_info *rt = (struct rt6_info *)cork->base.dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	struct flowi6 *fl6 = &cork->fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	unsigned char proto = fl6->flowi6_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	skb = __skb_dequeue(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	tail_skb = &(skb_shinfo(skb)->frag_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	/* move skb->data to ip header from ext header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	if (skb->data < skb_network_header(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		__skb_pull(skb, skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	while ((tmp_skb = __skb_dequeue(queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		__skb_pull(tmp_skb, skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		*tail_skb = tmp_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 		tail_skb = &(tmp_skb->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		skb->len += tmp_skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		skb->data_len += tmp_skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		skb->truesize += tmp_skb->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		tmp_skb->destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		tmp_skb->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	/* Allow local fragmentation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	skb->ignore_df = ip6_sk_ignore_df(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	*final_dst = fl6->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	__skb_pull(skb, skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	if (opt && opt->opt_flen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		ipv6_push_frag_opts(skb, opt, &proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	if (opt && opt->opt_nflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	skb_push(skb, sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	ip6_flow_hdr(hdr, v6_cork->tclass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		     ip6_make_flowlabel(net, skb, fl6->flowlabel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 					ip6_autoflowlabel(net, np), fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	hdr->hop_limit = v6_cork->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	hdr->nexthdr = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	hdr->saddr = fl6->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	hdr->daddr = *final_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	skb->priority = sk->sk_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	skb->mark = cork->base.mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	skb->tstamp = cork->base.transmit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	skb_dst_set(skb, dst_clone(&rt->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	IP6_UPD_PO_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	if (proto == IPPROTO_ICMPV6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 		struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		ICMP6MSGOUT_INC_STATS(net, idev, icmp6_hdr(skb)->icmp6_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	ip6_cork_release(cork, v6_cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) int ip6_send_skb(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	err = ip6_local_out(net, skb->sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 			err = net_xmit_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 			IP6_INC_STATS(net, rt->rt6i_idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 				      IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) int ip6_push_pending_frames(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	skb = ip6_finish_skb(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	return ip6_send_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) EXPORT_SYMBOL_GPL(ip6_push_pending_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) static void __ip6_flush_pending_frames(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 				       struct sk_buff_head *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 				       struct inet_cork_full *cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 				       struct inet6_cork *v6_cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	while ((skb = __skb_dequeue_tail(queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 		if (skb_dst(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 			IP6_INC_STATS(sock_net(sk), ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 				      IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	ip6_cork_release(cork, v6_cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) void ip6_flush_pending_frames(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 	__ip6_flush_pending_frames(sk, &sk->sk_write_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 				   &inet_sk(sk)->cork, &inet6_sk(sk)->cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) EXPORT_SYMBOL_GPL(ip6_flush_pending_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) struct sk_buff *ip6_make_skb(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 			     int getfrag(void *from, char *to, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 					 int len, int odd, struct sk_buff *skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 			     void *from, int length, int transhdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 			     struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 			     struct rt6_info *rt, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			     struct inet_cork_full *cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	struct inet6_cork v6_cork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	struct sk_buff_head queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	int exthdrlen = (ipc6->opt ? ipc6->opt->opt_flen : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	if (flags & MSG_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	__skb_queue_head_init(&queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	cork->base.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	cork->base.addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	cork->base.opt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	cork->base.dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	v6_cork.opt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	err = ip6_setup_cork(sk, cork, &v6_cork, ipc6, rt, fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		ip6_cork_release(cork, &v6_cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	if (ipc6->dontfrag < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		ipc6->dontfrag = inet6_sk(sk)->dontfrag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	err = __ip6_append_data(sk, fl6, &queue, &cork->base, &v6_cork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 				&current->task_frag, getfrag, from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 				length + exthdrlen, transhdrlen + exthdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 				flags, ipc6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 		__ip6_flush_pending_frames(sk, &queue, cork, &v6_cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	return __ip6_make_skb(sk, &queue, cork, &v6_cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }