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)  *	PF_INET6 socket protocol family
^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)  *	Adapted from linux/net/ipv4/af_inet.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *	Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *	piggy, Karl Knutson	:	Socket protocol table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *	Hideaki YOSHIFUJI	:	sin6_scope_id support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *	Arnaldo Melo		:	check proc_net_create return, cleanups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #define pr_fmt(fmt) "IPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/timer.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/sockios.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/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/init.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/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/netfilter_ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <net/udplite.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <net/ping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <net/transp_v6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <net/ipv6_stubs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #ifdef CONFIG_IPV6_TUNNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <net/ip6_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <net/calipso.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <net/seg6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <net/rpl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <net/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/mroute6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include "ip6_offload.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) MODULE_AUTHOR("Cast of dozens");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) /* The inetsw6 table contains everything that inet6_create needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * build a new socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static struct list_head inetsw6[SOCK_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static DEFINE_SPINLOCK(inetsw6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) struct ipv6_params ipv6_defaults = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	.disable_ipv6 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	.autoconf = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static int disable_ipv6_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) module_param_named(disable, disable_ipv6_mod, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) bool ipv6_mod_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	return disable_ipv6_mod == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) EXPORT_SYMBOL_GPL(ipv6_mod_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static int inet6_create(struct net *net, struct socket *sock, int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 			int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	struct inet_sock *inet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	struct ipv6_pinfo *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	struct inet_protosw *answer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct proto *answer_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	unsigned char answer_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	int try_loading_module = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	if (protocol < 0 || protocol >= IPPROTO_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	/* Look for the requested type/protocol pair. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) lookup_protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	err = -ESOCKTNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		/* Check the non-wild match. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		if (protocol == answer->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 			if (protocol != IPPROTO_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 			/* Check for the two wild cases. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 			if (IPPROTO_IP == protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 				protocol = answer->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 			if (IPPROTO_IP == answer->protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		err = -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		if (try_loading_module < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 			 * Be more specific, e.g. net-pf-10-proto-132-type-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 			 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 			if (++try_loading_module == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 				request_module("net-pf-%d-proto-%d-type-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 						PF_INET6, protocol, sock->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 			 * Fall back to generic, e.g. net-pf-10-proto-132
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 			 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 				request_module("net-pf-%d-proto-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 						PF_INET6, protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			goto lookup_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 			goto out_rcu_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	if (sock->type == SOCK_RAW && !kern &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	    !ns_capable(net->user_ns, CAP_NET_RAW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		goto out_rcu_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	sock->ops = answer->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	answer_prot = answer->prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	answer_flags = answer->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	WARN_ON(!answer_prot->slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	if (INET_PROTOSW_REUSE & answer_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		sk->sk_reuse = SK_CAN_REUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	if (SOCK_RAW == sock->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		inet->inet_num = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		if (IPPROTO_RAW == protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			inet->hdrincl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	sk->sk_destruct		= inet_sock_destruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	sk->sk_family		= PF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	sk->sk_protocol		= protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	sk->sk_backlog_rcv	= answer->prot->backlog_rcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	np->hop_limit	= -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	np->mcast_hops	= IPV6_DEFAULT_MCASTHOPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	np->mc_loop	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	np->mc_all	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	np->pmtudisc	= IPV6_PMTUDISC_WANT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	np->repflow	= net->ipv6.sysctl.flowlabel_reflect & FLOWLABEL_REFLECT_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	sk->sk_ipv6only	= net->ipv6.sysctl.bindv6only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	/* Init the ipv4 part of the socket since we can have sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	 * using v6 API for ipv4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	inet->uc_ttl	= -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	inet->mc_loop	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	inet->mc_ttl	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	inet->mc_index	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	inet->mc_list	= NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	inet->rcv_tos	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	if (net->ipv4.sysctl_ip_no_pmtu_disc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		inet->pmtudisc = IP_PMTUDISC_DONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		inet->pmtudisc = IP_PMTUDISC_WANT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	 * Increment only the relevant sk_prot->socks debug field, this changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	 * the previous behaviour of incrementing both the equivalent to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	 * This allows better debug granularity as we'll know exactly how many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	 * transport protocol socks. -acme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	sk_refcnt_debug_inc(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	if (inet->inet_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		/* It assumes that any protocol which allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		 * the user to assign a number at socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		 * creation time automatically shares.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		inet->inet_sport = htons(inet->inet_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		err = sk->sk_prot->hash(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 			sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	if (sk->sk_prot->init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		err = sk->sk_prot->init(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	if (!kern) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) out_rcu_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	struct sockaddr_in6 *addr = (struct sockaddr_in6 *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	__be32 v4addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	unsigned short snum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	bool saved_ipv6only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	int addr_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (addr->sin6_family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	addr_type = ipv6_addr_type(&addr->sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if ((addr_type & IPV6_ADDR_MULTICAST) && sk->sk_type == SOCK_STREAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	snum = ntohs(addr->sin6_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	if (snum && inet_is_local_unbindable_port(net, snum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	if (snum && inet_port_requires_bind_service(net, snum) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	    !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	if (flags & BIND_WITH_LOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	/* Check these errors (active socket, double bind). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	/* Check if the address belongs to the host. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	if (addr_type == IPV6_ADDR_MAPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		int chk_addr_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		/* Binding to v4-mapped address on a v6-only socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		 * makes no sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		if (sk->sk_ipv6only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		if (sk->sk_bound_dev_if) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 				err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		/* Reproduce AF_INET checks to make the bindings consistent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		v4addr = addr->sin6_addr.s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		chk_addr_ret = inet_addr_type_dev_table(net, dev, v4addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		if (!inet_can_nonlocal_bind(net, inet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		    v4addr != htonl(INADDR_ANY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		    chk_addr_ret != RTN_LOCAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		    chk_addr_ret != RTN_MULTICAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		    chk_addr_ret != RTN_BROADCAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		if (addr_type != IPV6_ADDR_ANY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			if (__ipv6_addr_needs_scope_id(addr_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 				if (addr_len >= sizeof(struct sockaddr_in6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 				    addr->sin6_scope_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 					/* Override any existing binding, if another one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 					 * is supplied by user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 					sk->sk_bound_dev_if = addr->sin6_scope_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				/* Binding to link-local address requires an interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 				if (!sk->sk_bound_dev_if) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 					err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 					goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			if (sk->sk_bound_dev_if) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 				if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 					err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 					goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			/* ipv4 addr of the socket is invalid.  Only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			 * unspecified and mapped address have a v4 equivalent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			v4addr = LOOPBACK4_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			if (!(addr_type & IPV6_ADDR_MULTICAST))	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 				if (!ipv6_can_nonlocal_bind(net, inet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 				    !ipv6_chk_addr(net, &addr->sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 						   dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 					err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 					goto out_unlock;
^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) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	inet->inet_rcv_saddr = v4addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	inet->inet_saddr = v4addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	sk->sk_v6_rcv_saddr = addr->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (!(addr_type & IPV6_ADDR_MULTICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		np->saddr = addr->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	saved_ipv6only = sk->sk_ipv6only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (addr_type != IPV6_ADDR_ANY && addr_type != IPV6_ADDR_MAPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		sk->sk_ipv6only = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* Make sure we are allowed to bind here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	if (snum || !(inet->bind_address_no_port ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		      (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		if (sk->sk_prot->get_port(sk, snum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			sk->sk_ipv6only = saved_ipv6only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			inet_reset_saddr(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			err = -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		if (!(flags & BIND_FROM_BPF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			err = BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 				sk->sk_ipv6only = saved_ipv6only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 				inet_reset_saddr(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (addr_type != IPV6_ADDR_ANY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	if (snum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	inet->inet_sport = htons(inet->inet_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	inet->inet_dport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	inet->inet_daddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	if (flags & BIND_WITH_LOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) /* bind for INET6 API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	/* If the socket has its own bind function then use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (sk->sk_prot->bind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		return sk->sk_prot->bind(sk, uaddr, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	if (addr_len < SIN6_LEN_RFC2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	/* BPF prog is run before any checks are done so that if the prog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	 * changes context in a wrong way it will be caught.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	err = BPF_CGROUP_RUN_PROG_INET6_BIND(sk, uaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	return __inet6_bind(sk, uaddr, addr_len, BIND_WITH_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) EXPORT_SYMBOL(inet6_bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) int inet6_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	/* Free mc lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	ipv6_sock_mc_close(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	/* Free ac lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	ipv6_sock_ac_close(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	return inet_release(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) EXPORT_SYMBOL(inet6_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) void inet6_destroy_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	struct ipv6_txoptions *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	/* Release rx options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	skb = xchg(&np->pktoptions, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	skb = xchg(&np->rxpmtu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	/* Free flowlabels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	fl6_free_socklist(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	/* Free tx options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	opt = xchg((__force struct ipv6_txoptions **)&np->opt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	if (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		atomic_sub(opt->tot_len, &sk->sk_omem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		txopt_put(opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) EXPORT_SYMBOL_GPL(inet6_destroy_sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)  *	This does both peername and sockname.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		  int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	struct sockaddr_in6 *sin = (struct sockaddr_in6 *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	sin->sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	sin->sin6_flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	sin->sin6_scope_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	if (peer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		if (!inet->inet_dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 			return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		    peer == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		sin->sin6_port = inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		sin->sin6_addr = sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		if (np->sndflow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			sin->sin6_flowinfo = np->flow_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			sin->sin6_addr = np->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			sin->sin6_addr = sk->sk_v6_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		sin->sin6_port = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (cgroup_bpf_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		BPF_CGROUP_RUN_SA_PROG_LOCK(sk, (struct sockaddr *)sin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 					    peer ? BPF_CGROUP_INET6_GETPEERNAME :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 						   BPF_CGROUP_INET6_GETSOCKNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 					    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 						 sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return sizeof(*sin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) EXPORT_SYMBOL(inet6_getname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	case SIOCDELRT: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		struct in6_rtmsg rtmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		if (copy_from_user(&rtmsg, argp, sizeof(rtmsg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		return ipv6_route_ioctl(net, cmd, &rtmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	case SIOCSIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		return addrconf_add_ifaddr(net, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	case SIOCDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		return addrconf_del_ifaddr(net, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	case SIOCSIFDSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		return addrconf_set_dstaddr(net, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		if (!sk->sk_prot->ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 			return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		return sk->sk_prot->ioctl(sk, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	/*NOTREACHED*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) EXPORT_SYMBOL(inet6_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) struct compat_in6_rtmsg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	struct in6_addr		rtmsg_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	struct in6_addr		rtmsg_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	struct in6_addr		rtmsg_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	u32			rtmsg_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	u16			rtmsg_dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	u16			rtmsg_src_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	u32			rtmsg_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	u32			rtmsg_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	u32			rtmsg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	s32			rtmsg_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) static int inet6_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		struct compat_in6_rtmsg __user *ur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	struct in6_rtmsg rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	if (copy_from_user(&rt.rtmsg_dst, &ur->rtmsg_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			3 * sizeof(struct in6_addr)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	    get_user(rt.rtmsg_type, &ur->rtmsg_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	    get_user(rt.rtmsg_dst_len, &ur->rtmsg_dst_len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	    get_user(rt.rtmsg_src_len, &ur->rtmsg_src_len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	    get_user(rt.rtmsg_metric, &ur->rtmsg_metric) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	    get_user(rt.rtmsg_info, &ur->rtmsg_info) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	    get_user(rt.rtmsg_flags, &ur->rtmsg_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	    get_user(rt.rtmsg_ifindex, &ur->rtmsg_ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	return ipv6_route_ioctl(sock_net(sk), cmd, &rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) int inet6_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	void __user *argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		return inet6_compat_routing_ioctl(sk, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) EXPORT_SYMBOL_GPL(inet6_compat_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) #endif /* CONFIG_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) INDIRECT_CALLABLE_DECLARE(int udpv6_sendmsg(struct sock *, struct msghdr *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 					    size_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) int inet6_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	if (unlikely(inet_send_prepare(sk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	return INDIRECT_CALL_2(sk->sk_prot->sendmsg, tcp_sendmsg, udpv6_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			       sk, msg, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) INDIRECT_CALLABLE_DECLARE(int udpv6_recvmsg(struct sock *, struct msghdr *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 					    size_t, int, int, int *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) int inet6_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		  int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	int addr_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (likely(!(flags & MSG_ERRQUEUE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		sock_rps_record_flow(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	err = INDIRECT_CALL_2(sk->sk_prot->recvmsg, tcp_recvmsg, udpv6_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			      sk, msg, size, flags & MSG_DONTWAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			      flags & ~MSG_DONTWAIT, &addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		msg->msg_namelen = addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) const struct proto_ops inet6_stream_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	.family		   = PF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	.flags		   = PROTO_CMSG_DATA_ONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	.owner		   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	.release	   = inet6_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	.bind		   = inet6_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	.connect	   = inet_stream_connect,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	.socketpair	   = sock_no_socketpair,	/* a do nothing	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	.accept		   = inet_accept,		/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	.getname	   = inet6_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	.poll		   = tcp_poll,			/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	.ioctl		   = inet6_ioctl,		/* must change  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	.gettstamp	   = sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	.listen		   = inet_listen,		/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	.shutdown	   = inet_shutdown,		/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	.setsockopt	   = sock_common_setsockopt,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	.getsockopt	   = sock_common_getsockopt,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	.sendmsg	   = inet6_sendmsg,		/* retpoline's sake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	.recvmsg	   = inet6_recvmsg,		/* retpoline's sake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	.mmap		   = tcp_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	.sendpage	   = inet_sendpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	.sendmsg_locked    = tcp_sendmsg_locked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	.sendpage_locked   = tcp_sendpage_locked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	.splice_read	   = tcp_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	.read_sock	   = tcp_read_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	.peek_len	   = tcp_peek_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	.compat_ioctl	   = inet6_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	.set_rcvlowat	   = tcp_set_rcvlowat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) const struct proto_ops inet6_dgram_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	.family		   = PF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	.owner		   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	.release	   = inet6_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	.bind		   = inet6_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	.connect	   = inet_dgram_connect,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	.socketpair	   = sock_no_socketpair,	/* a do nothing	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	.accept		   = sock_no_accept,		/* a do nothing	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	.getname	   = inet6_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	.poll		   = udp_poll,			/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	.ioctl		   = inet6_ioctl,		/* must change  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	.gettstamp	   = sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	.listen		   = sock_no_listen,		/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	.shutdown	   = inet_shutdown,		/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	.setsockopt	   = sock_common_setsockopt,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	.getsockopt	   = sock_common_getsockopt,	/* ok		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	.sendmsg	   = inet6_sendmsg,		/* retpoline's sake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	.recvmsg	   = inet6_recvmsg,		/* retpoline's sake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	.mmap		   = sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	.sendpage	   = sock_no_sendpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	.set_peek_off	   = sk_set_peek_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	.compat_ioctl	   = inet6_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) static const struct net_proto_family inet6_family_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	.family = PF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	.create = inet6_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) int inet6_register_protosw(struct inet_protosw *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct list_head *lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	struct inet_protosw *answer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	struct list_head *last_perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	int protocol = p->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	spin_lock_bh(&inetsw6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	if (p->type >= SOCK_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		goto out_illegal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	/* If we are trying to override a permanent protocol, bail. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	answer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	last_perm = &inetsw6[p->type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	list_for_each(lh, &inetsw6[p->type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		answer = list_entry(lh, struct inet_protosw, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		/* Check only the non-wild match. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		if (INET_PROTOSW_PERMANENT & answer->flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			if (protocol == answer->protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			last_perm = lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		answer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if (answer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		goto out_permanent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	/* Add the new entry after the last permanent entry if any, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	 * the new entry does not override a permanent entry when matched with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	 * a wild-card protocol. But it is allowed to override any existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	 * non-permanent entry.  This means that when we remove this entry, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	 * system automatically returns to the old behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	list_add_rcu(&p->list, last_perm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	spin_unlock_bh(&inetsw6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) out_permanent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	pr_err("Attempt to override permanent protocol %d\n", protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) out_illegal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	pr_err("Ignoring attempt to register invalid socket type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	       p->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) EXPORT_SYMBOL(inet6_register_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) inet6_unregister_protosw(struct inet_protosw *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	if (INET_PROTOSW_PERMANENT & p->flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		pr_err("Attempt to unregister permanent protocol %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		       p->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		spin_lock_bh(&inetsw6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		list_del_rcu(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		spin_unlock_bh(&inetsw6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) EXPORT_SYMBOL(inet6_unregister_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) int inet6_sk_rebuild_header(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	dst = __sk_dst_check(sk, np->dst_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	if (!dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		struct in6_addr *final_p, final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		memset(&fl6, 0, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		fl6.flowi6_proto = sk->sk_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		fl6.daddr = sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		fl6.saddr = np->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		fl6.flowlabel = np->flow_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		fl6.flowi6_oif = sk->sk_bound_dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		fl6.flowi6_mark = sk->sk_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		fl6.fl6_dport = inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		fl6.fl6_sport = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		fl6.flowi6_uid = sk->sk_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		final_p = fl6_update_dst(&fl6, rcu_dereference(np->opt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 					 &final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			sk->sk_route_caps = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			sk->sk_err_soft = -PTR_ERR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			return PTR_ERR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		ip6_dst_store(sk, dst, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		       const struct inet6_skb_parm *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	const struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (np->rxopt.all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		if (((opt->flags & IP6SKB_HOPBYHOP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		     (np->rxopt.bits.hopopts || np->rxopt.bits.ohopopts)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		    (ip6_flowinfo((struct ipv6hdr *) skb_network_header(skb)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		     np->rxopt.bits.rxflow) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		    (opt->srcrt && (np->rxopt.bits.srcrt ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		     np->rxopt.bits.osrcrt)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		    ((opt->dst1 || opt->dst0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		     (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) static struct packet_type ipv6_packet_type __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	.type = cpu_to_be16(ETH_P_IPV6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	.func = ipv6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	.list_func = ipv6_list_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) static int __init ipv6_packet_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	dev_add_pack(&ipv6_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) static void ipv6_packet_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	dev_remove_pack(&ipv6_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) static int __net_init ipv6_init_mibs(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	net->mib.udp_stats_in6 = alloc_percpu(struct udp_mib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (!net->mib.udp_stats_in6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	net->mib.udplite_stats_in6 = alloc_percpu(struct udp_mib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	if (!net->mib.udplite_stats_in6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		goto err_udplite_mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	net->mib.ipv6_statistics = alloc_percpu(struct ipstats_mib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	if (!net->mib.ipv6_statistics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		goto err_ip_mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		struct ipstats_mib *af_inet6_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		af_inet6_stats = per_cpu_ptr(net->mib.ipv6_statistics, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		u64_stats_init(&af_inet6_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	net->mib.icmpv6_statistics = alloc_percpu(struct icmpv6_mib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (!net->mib.icmpv6_statistics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		goto err_icmp_mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	net->mib.icmpv6msg_statistics = kzalloc(sizeof(struct icmpv6msg_mib),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	if (!net->mib.icmpv6msg_statistics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		goto err_icmpmsg_mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) err_icmpmsg_mib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	free_percpu(net->mib.icmpv6_statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) err_icmp_mib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	free_percpu(net->mib.ipv6_statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) err_ip_mib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	free_percpu(net->mib.udplite_stats_in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) err_udplite_mib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	free_percpu(net->mib.udp_stats_in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) static void ipv6_cleanup_mibs(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	free_percpu(net->mib.udp_stats_in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	free_percpu(net->mib.udplite_stats_in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	free_percpu(net->mib.ipv6_statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	free_percpu(net->mib.icmpv6_statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	kfree(net->mib.icmpv6msg_statistics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) static int __net_init inet6_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	net->ipv6.sysctl.bindv6only = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	net->ipv6.sysctl.icmpv6_time = 1*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	net->ipv6.sysctl.icmpv6_echo_ignore_all = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	net->ipv6.sysctl.icmpv6_echo_ignore_multicast = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	net->ipv6.sysctl.icmpv6_echo_ignore_anycast = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	/* By default, rate limit error messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * Except for pmtu discovery, it would break it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 * proc_do_large_bitmap needs pointer to the bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	bitmap_set(net->ipv6.sysctl.icmpv6_ratemask, 0, ICMPV6_ERRMSG_MAX + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	bitmap_clear(net->ipv6.sysctl.icmpv6_ratemask, ICMPV6_PKT_TOOBIG, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	net->ipv6.sysctl.icmpv6_ratemask_ptr = net->ipv6.sysctl.icmpv6_ratemask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	net->ipv6.sysctl.flowlabel_consistency = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	net->ipv6.sysctl.idgen_retries = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	net->ipv6.sysctl.idgen_delay = 1 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	net->ipv6.sysctl.flowlabel_state_ranges = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	net->ipv6.sysctl.max_dst_opts_cnt = IP6_DEFAULT_MAX_DST_OPTS_CNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	net->ipv6.sysctl.max_hbh_opts_cnt = IP6_DEFAULT_MAX_HBH_OPTS_CNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	net->ipv6.sysctl.max_dst_opts_len = IP6_DEFAULT_MAX_DST_OPTS_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	net->ipv6.sysctl.max_hbh_opts_len = IP6_DEFAULT_MAX_HBH_OPTS_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	atomic_set(&net->ipv6.fib6_sernum, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	err = ipv6_init_mibs(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	err = udp6_proc_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	err = tcp6_proc_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		goto proc_tcp6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	err = ac6_proc_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		goto proc_ac6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) proc_ac6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	tcp6_proc_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) proc_tcp6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	udp6_proc_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	ipv6_cleanup_mibs(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) static void __net_exit inet6_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	udp6_proc_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	tcp6_proc_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	ac6_proc_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	ipv6_cleanup_mibs(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) static struct pernet_operations inet6_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	.init = inet6_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	.exit = inet6_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static int ipv6_route_input(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	ip6_route_input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	return skb_dst(skb)->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static const struct ipv6_stub ipv6_stub_impl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	.ipv6_sock_mc_join = ipv6_sock_mc_join,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	.ipv6_sock_mc_drop = ipv6_sock_mc_drop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	.ipv6_dst_lookup_flow = ip6_dst_lookup_flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	.ipv6_route_input  = ipv6_route_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	.fib6_get_table	   = fib6_get_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	.fib6_table_lookup = fib6_table_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	.fib6_lookup       = fib6_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	.fib6_select_path  = fib6_select_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	.ip6_mtu_from_fib6 = ip6_mtu_from_fib6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	.fib6_nh_init	   = fib6_nh_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	.fib6_nh_release   = fib6_nh_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	.fib6_update_sernum = fib6_update_sernum_stub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	.fib6_rt_update	   = fib6_rt_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	.ip6_del_rt	   = ip6_del_rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	.udpv6_encap_enable = udpv6_encap_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	.ndisc_send_na = ndisc_send_na,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) #if IS_ENABLED(CONFIG_XFRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	.xfrm6_local_rxpmtu = xfrm6_local_rxpmtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	.xfrm6_udp_encap_rcv = xfrm6_udp_encap_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	.xfrm6_rcv_encap = xfrm6_rcv_encap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	.nd_tbl	= &nd_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	.ipv6_fragment = ip6_fragment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	.inet6_bind = __inet6_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	.udp6_lib_lookup = __udp6_lib_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) static int __init inet6_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	struct list_head *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	sock_skb_cb_check_size(sizeof(struct inet6_skb_parm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	/* Register the socket-side information for inet6_create.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		INIT_LIST_HEAD(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (disable_ipv6_mod) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		pr_info("Loaded, but administratively disabled, reboot required to enable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	err = proto_register(&tcpv6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	err = proto_register(&udpv6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		goto out_unregister_tcp_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	err = proto_register(&udplitev6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto out_unregister_udp_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	err = proto_register(&rawv6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		goto out_unregister_udplite_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	err = proto_register(&pingv6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		goto out_unregister_raw_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	/* We MUST register RAW sockets before we create the ICMP6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	 * IGMP6, or NDISC control sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	err = rawv6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		goto out_unregister_ping_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	/* Register the family here so that the init calls below will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	 * be able to create sockets. (?? is this dangerous ??)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	err = sock_register(&inet6_family_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		goto out_sock_register_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	 *	ipngwg API draft makes clear that the correct semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	 *	for TCP and UDP is to consider one TCP and UDP instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	 *	in a host available by both INET and INET6 APIs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	 *	able to communicate via both network protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	err = register_pernet_subsys(&inet6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		goto register_pernet_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	err = ip6_mr_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		goto ipmr_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	err = icmpv6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		goto icmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	err = ndisc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		goto ndisc_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	err = igmp6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		goto igmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	err = ipv6_netfilter_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		goto netfilter_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	/* Create /proc/foo6 entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (raw6_proc_init())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		goto proc_raw6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	if (udplite6_proc_init())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		goto proc_udplite6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if (ipv6_misc_proc_init())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		goto proc_misc6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	if (if6_proc_init())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		goto proc_if6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	err = ip6_route_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		goto ip6_route_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	err = ndisc_late_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		goto ndisc_late_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	err = ip6_flowlabel_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		goto ip6_flowlabel_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	err = ipv6_anycast_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		goto ipv6_anycast_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	err = addrconf_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		goto addrconf_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	/* Init v6 extension headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	err = ipv6_exthdrs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		goto ipv6_exthdrs_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	err = ipv6_frag_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		goto ipv6_frag_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	/* Init v6 transport protocols. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	err = udpv6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		goto udpv6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	err = udplitev6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		goto udplitev6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	err = udpv6_offload_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		goto udpv6_offload_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	err = tcpv6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		goto tcpv6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	err = ipv6_packet_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		goto ipv6_packet_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	err = pingv6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		goto pingv6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	err = calipso_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		goto calipso_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	err = seg6_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		goto seg6_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	err = rpl_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		goto rpl_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	err = igmp6_late_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		goto igmp6_late_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	err = ipv6_sysctl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		goto sysctl_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	/* ensure that ipv6 stubs are visible only after ipv6 is ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	ipv6_stub = &ipv6_stub_impl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	ipv6_bpf_stub = &ipv6_bpf_stub_impl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) sysctl_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	igmp6_late_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) igmp6_late_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	rpl_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) rpl_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	seg6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) seg6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	calipso_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) calipso_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	pingv6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) pingv6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	ipv6_packet_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ipv6_packet_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	tcpv6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) tcpv6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	udpv6_offload_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) udpv6_offload_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	udplitev6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) udplitev6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	udpv6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) udpv6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	ipv6_frag_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) ipv6_frag_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	ipv6_exthdrs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) ipv6_exthdrs_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	addrconf_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) addrconf_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	ipv6_anycast_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) ipv6_anycast_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	ip6_flowlabel_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) ip6_flowlabel_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	ndisc_late_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) ndisc_late_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	ip6_route_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) ip6_route_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	if6_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) proc_if6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	ipv6_misc_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) proc_misc6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	udplite6_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) proc_udplite6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	raw6_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) proc_raw6_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	ipv6_netfilter_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) netfilter_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	igmp6_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) igmp_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	ndisc_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) ndisc_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	icmpv6_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) icmp_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	ip6_mr_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) ipmr_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	unregister_pernet_subsys(&inet6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) register_pernet_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	sock_unregister(PF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	rtnl_unregister_all(PF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) out_sock_register_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	rawv6_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) out_unregister_ping_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	proto_unregister(&pingv6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) out_unregister_raw_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	proto_unregister(&rawv6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) out_unregister_udplite_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	proto_unregister(&udplitev6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) out_unregister_udp_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	proto_unregister(&udpv6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) out_unregister_tcp_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	proto_unregister(&tcpv6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) module_init(inet6_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) MODULE_ALIAS_NETPROTO(PF_INET6);