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) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * (C) Copyright IBM Corp. 2002, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 2001 Nokia, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2001 La Monte H.P. Yarroll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2002-2003 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * SCTP over IPv6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *    lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *    Le Yanqun		    <yanqun.le@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *    Hui Huang		    <hui.huang@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *    La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    Sridhar Samudrala	    <sri@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    Jon Grimm		    <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *    Ardelle Fan	    <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * Based on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *	linux/net/ipv6/tcp_ipv6.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/ipsec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <net/ipv6.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/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 					 union sctp_addr *s2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 			      __be16 port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 			    const union sctp_addr *addr2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) /* Event handler for inet6 address addition/deletion events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * The sctp_local_addr_list needs to be protocted by a spin lock since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * multiple notifiers (say IPv4 and IPv6) may be running at the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * time and thus corrupt the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  * The reader side is protected with RCU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 				void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	struct sctp_sockaddr_entry *addr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	struct sctp_sockaddr_entry *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	struct net *net = dev_net(ifa->idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	switch (ev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 		addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 			addr->a.v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 			addr->a.v6.sin6_addr = ifa->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 			addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			addr->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			spin_lock_bh(&net->sctp.local_addr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 			sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 			spin_unlock_bh(&net->sctp.local_addr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		spin_lock_bh(&net->sctp.local_addr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		list_for_each_entry_safe(addr, temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 					&net->sctp.local_addr_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 			if (addr->a.sa.sa_family == AF_INET6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 					ipv6_addr_equal(&addr->a.v6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 						&ifa->addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 				sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 				found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 				addr->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 				list_del_rcu(&addr->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		spin_unlock_bh(&net->sctp.local_addr_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		if (found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			kfree_rcu(addr, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	return NOTIFY_DONE;
^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) static struct notifier_block sctp_inet6addr_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	.notifier_call = sctp_inet6addr_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) /* ICMP error handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 			u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	struct ipv6_pinfo *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	__u16 saveip, savesctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	int err, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	idev = in6_dev_get(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	/* Fix up skb to look at the embedded net header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	saveip	 = skb->network_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	savesctp = skb->transport_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	skb_set_transport_header(skb, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	/* Put back, the original pointers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	skb->network_header   = saveip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	skb->transport_header = savesctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (!sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		__ICMP6_INC_STATS(net, idev, ICMP6_MIB_INERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/* Warning:  The sock lock is held.  Remember to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	 * sctp_err_finish!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	case ICMPV6_PKT_TOOBIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		if (ip6_sk_accept_pmtu(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	case ICMPV6_PARAMPROB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		if (ICMPV6_UNK_NEXTHDR == code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			sctp_icmp_proto_unreachable(sk, asoc, transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	case NDISC_REDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		sctp_icmp_redirect(sk, transport, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	icmpv6_err_convert(type, code, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	if (!sock_owned_by_user(sk) && np->recverr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		sk->sk_error_report(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	} else {  /* Only an error on timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		sk->sk_err_soft = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	sctp_err_finish(sk, transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	if (likely(idev != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct sock *sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	struct flowi6 *fl6 = &transport->fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	__u8 tclass = np->tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		 skb->len, &fl6->saddr, &fl6->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	if (transport->dscp & SCTP_DSCP_SET_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		tclass = transport->dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (INET_ECN_is_capable(tclass))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		IP6_ECN_flow_xmit(sk, fl6->flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (!(transport->param_flags & SPP_PMTUD_ENABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		skb->ignore_df = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		       tclass, sk->sk_priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) /* Returns the dst cache entry for the given source and destination ip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  * addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 			    struct flowi *fl, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	struct sctp_association *asoc = t->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	struct dst_entry *dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	struct flowi _fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct flowi6 *fl6 = &_fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	struct sctp_sockaddr_entry *laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	union sctp_addr *daddr = &t->ipaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	union sctp_addr dst_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	struct in6_addr *final_p, final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	enum sctp_scope scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	__u8 matchlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	memset(&_fl, 0, sizeof(_fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	fl6->daddr = daddr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	fl6->fl6_dport = daddr->v6.sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	fl6->flowi6_proto = IPPROTO_SCTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		fl6->flowi6_oif = daddr->v6.sin6_scope_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	else if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	if (t->flowlabel & SCTP_FLOWLABEL_SET_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		fl6->flowlabel = htonl(t->flowlabel & SCTP_FLOWLABEL_VAL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	if (np->sndflow && (fl6->flowlabel & IPV6_FLOWLABEL_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		struct ip6_flowlabel *flowlabel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		flowlabel = fl6_sock_lookup(sk, fl6->flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		if (IS_ERR(flowlabel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		fl6_sock_release(flowlabel);
^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) 	pr_debug("%s: dst=%pI6 ", __func__, &fl6->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		fl6->fl6_sport = htons(asoc->base.bind_addr.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	if (saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		fl6->saddr = saddr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		if (!fl6->fl6_sport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			fl6->fl6_sport = saddr->v6.sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		pr_debug("src=%pI6 - ", &fl6->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	if (!asoc || saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		t->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		memcpy(fl, &_fl, sizeof(_fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	bp = &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	scope = sctp_scope(daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	/* ip6_dst_lookup has filled in the fl6->saddr for us.  Check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	 * to see if we can use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	if (!IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		/* Walk through the bind address list and look for a bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		 * address that matches the source address of the returned dst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		sctp_v6_to_addr(&dst_saddr, &fl6->saddr, htons(bp->port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		list_for_each_entry_rcu(laddr, &bp->address_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			if (!laddr->valid || laddr->state == SCTP_ADDR_DEL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			    (laddr->state != SCTP_ADDR_SRC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			     !asoc->src_out_of_asoc_ok))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			/* Do not compare against v4 addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			if ((laddr->a.sa.sa_family == AF_INET6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			    (sctp_v6_cmp_addr(&dst_saddr, &laddr->a))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 				rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 				t->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 				memcpy(fl, &_fl, sizeof(_fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		/* None of the bound addresses match the source address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		 * dst. So release it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	/* Walk through the bind address list and try to get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	 * best source address for a given destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	list_for_each_entry_rcu(laddr, &bp->address_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		struct dst_entry *bdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		__u8 bmatchlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		if (!laddr->valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		    laddr->state != SCTP_ADDR_SRC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		    laddr->a.sa.sa_family != AF_INET6 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		    scope > sctp_scope(&laddr->a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		fl6->saddr = laddr->a.v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		fl6->fl6_sport = laddr->a.v6.sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		bdst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		if (IS_ERR(bdst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		if (ipv6_chk_addr(dev_net(bdst->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				  &laddr->a.v6.sin6_addr, bdst->dev, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			if (!IS_ERR_OR_NULL(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 				dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			dst = bdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			t->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			memcpy(fl, &_fl, sizeof(_fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			break;
^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) 		bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		if (matchlen > bmatchlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			dst_release(bdst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		if (!IS_ERR_OR_NULL(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		dst = bdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		matchlen = bmatchlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		t->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		memcpy(fl, &_fl, sizeof(_fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (!IS_ERR_OR_NULL(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		rt = (struct rt6_info *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		t->dst_cookie = rt6_get_cookie(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		pr_debug("rt6_dst:%pI6/%d rt6_src:%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			 &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			 &fl->u.ip6.saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		t->dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		pr_debug("no route\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) /* Returns the number of consecutive initial bits that match in the 2 ipv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)  * addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 					 union sctp_addr *s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	return ipv6_addr_diff(&s1->v6.sin6_addr, &s2->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) /* Fills in the source address(saddr) based on the destination address(daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  * and asoc's bind address list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) static void sctp_v6_get_saddr(struct sctp_sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			      struct sctp_transport *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			      struct flowi *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct flowi6 *fl6 = &fl->u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	union sctp_addr *saddr = &t->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	pr_debug("%s: asoc:%p dst:%p\n", __func__, t->asoc, t->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	if (t->dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		saddr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		saddr->v6.sin6_addr = fl6->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) /* Make a copy of all potential local addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) static void sctp_v6_copy_addrlist(struct list_head *addrlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 				  struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	struct inet6_dev *in6_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	struct sctp_sockaddr_entry *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	if ((in6_dev = __in6_dev_get(dev)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		return;
^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) 	read_lock_bh(&in6_dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		/* Add the address to the local list.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 			addr->a.v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			addr->a.v6.sin6_addr = ifp->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			addr->a.v6.sin6_scope_id = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			addr->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 			INIT_LIST_HEAD(&addr->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			list_add_tail(&addr->list, addrlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		}
^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) 	read_unlock_bh(&in6_dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) /* Copy over any ip options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) static void sctp_v6_copy_ip_options(struct sock *sk, struct sock *newsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	struct ipv6_txoptions *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	newnp = inet6_sk(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	opt = rcu_dereference(np->opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	if (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		opt = ipv6_dup_options(newsk, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			pr_err("%s: Failed to copy ip options\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	RCU_INIT_POINTER(newnp->opt, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) /* Account for the IP options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) static int sctp_v6_ip_options_len(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	struct ipv6_txoptions *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	opt = rcu_dereference(np->opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		len = opt->opt_flen + opt->opt_nflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) /* Initialize a sockaddr_storage from in incoming skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			     int is_saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	/* Always called on head skb, so this is safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	struct sctphdr *sh = sctp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	struct sockaddr_in6 *sa = &addr->v6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	addr->v6.sin6_flowinfo = 0; /* FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if (is_saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		sa->sin6_port = sh->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		sa->sin6_addr = ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		sa->sin6_port = sh->dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		sa->sin6_addr = ipv6_hdr(skb)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) /* Initialize an sctp_addr from a socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	addr->v6.sin6_port = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	addr->v6.sin6_addr = sk->sk_v6_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) /* Initialize sk->sk_rcv_saddr from sctp_addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (addr->sa.sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		sk->sk_v6_rcv_saddr.s6_addr32[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		sk->sk_v6_rcv_saddr.s6_addr32[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		sk->sk_v6_rcv_saddr.s6_addr32[2] = htonl(0x0000ffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		sk->sk_v6_rcv_saddr.s6_addr32[3] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			addr->v4.sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		sk->sk_v6_rcv_saddr = addr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) /* Initialize sk->sk_daddr from sctp_addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	if (addr->sa.sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		sk->sk_v6_daddr.s6_addr32[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		sk->sk_v6_daddr.s6_addr32[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		sk->sk_v6_daddr.s6_addr32[2] = htonl(0x0000ffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		sk->sk_v6_daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		sk->sk_v6_daddr = addr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) /* Initialize a sctp_addr from an address parameter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) static bool sctp_v6_from_addr_param(union sctp_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				    union sctp_addr_param *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 				    __be16 port, int iif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	if (ntohs(param->v6.param_hdr.length) < sizeof(struct sctp_ipv6addr_param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	addr->v6.sin6_port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	addr->v6.sin6_flowinfo = 0; /* BUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	addr->v6.sin6_addr = param->v6.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	addr->v6.sin6_scope_id = iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) /* Initialize an address parameter from a sctp_addr and return the length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  * of the address parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static int sctp_v6_to_addr_param(const union sctp_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 				 union sctp_addr_param *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	int length = sizeof(struct sctp_ipv6addr_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	param->v6.param_hdr.length = htons(length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	param->v6.addr = addr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) /* Initialize a sctp_addr from struct in6_addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 			      __be16 port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	addr->sa.sa_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	addr->v6.sin6_port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	addr->v6.sin6_flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	addr->v6.sin6_addr = *saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	addr->v6.sin6_scope_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static int __sctp_v6_cmp_addr(const union sctp_addr *addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 			      const union sctp_addr *addr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	if (addr1->sa.sa_family != addr2->sa.sa_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		if (addr1->sa.sa_family == AF_INET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		    addr2->sa.sa_family == AF_INET6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		    ipv6_addr_v4mapped(&addr2->v6.sin6_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		    addr2->v6.sin6_addr.s6_addr32[3] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		    addr1->v4.sin_addr.s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		if (addr2->sa.sa_family == AF_INET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		    addr1->sa.sa_family == AF_INET6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		    ipv6_addr_v4mapped(&addr1->v6.sin6_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		    addr1->v6.sin6_addr.s6_addr32[3] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		    addr2->v4.sin_addr.s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	/* If this is a linklocal address, compare the scope_id. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	    addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	    addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) /* Compare addresses exactly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609)  * v4-mapped-v6 is also in consideration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			    const union sctp_addr *addr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	return __sctp_v6_cmp_addr(addr1, addr2) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	       addr1->v6.sin6_port == addr2->v6.sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) /* Initialize addr struct to INADDR_ANY. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	memset(addr, 0x00, sizeof(union sctp_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	addr->v6.sin6_port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) /* Is this a wildcard address? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static int sctp_v6_is_any(const union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	return ipv6_addr_any(&addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) /* Should this be available for binding?   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	struct net *net = sock_net(&sp->inet.sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	const struct in6_addr *in6 = (const struct in6_addr *)&addr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	type = ipv6_addr_type(in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (IPV6_ADDR_ANY == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	if (type == IPV6_ADDR_MAPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		sctp_v6_map_v4(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		return sctp_get_af_specific(AF_INET)->available(addr, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	if (!(type & IPV6_ADDR_UNICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	return ipv6_can_nonlocal_bind(net, &sp->inet) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	       ipv6_chk_addr(net, in6, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) /* This function checks if the address is a valid address to be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)  * SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  * Return 0 - If the address is a non-unicast or an illegal address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * Return 1 - If the address is a unicast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) static int sctp_v6_addr_valid(union sctp_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 			      struct sctp_sock *sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 			      const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	int ret = ipv6_addr_type(&addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	/* Support v4-mapped-v6 address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (ret == IPV6_ADDR_MAPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		/* Note: This routine is used in input, so v4-mapped-v6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		 * are disallowed here when there is no sctp_sock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		sctp_v6_map_v4(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	/* Is this a non-unicast address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	if (!(ret & IPV6_ADDR_UNICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) /* What is the scope of 'addr'?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) static enum sctp_scope sctp_v6_scope(union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	enum sctp_scope retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	int v6scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	/* The IPv6 scope is really a set of bit fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	 * See IFA_* in <net/if_inet6.h>.  Map to a generic SCTP scope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	v6scope = ipv6_addr_scope(&addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	switch (v6scope) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	case IFA_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		retval = SCTP_SCOPE_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	case IFA_LINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		retval = SCTP_SCOPE_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	case IFA_SITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		retval = SCTP_SCOPE_PRIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		retval = SCTP_SCOPE_GLOBAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) /* Create and initialize a new sk for the socket to be returned by accept(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 					     struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 					     bool kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	struct sock *newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	struct sctp6_sock *newsctp6sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (!newsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	sock_init_data(NULL, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	sctp_copy_sock(newsk, sk, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	newsctp6sk = (struct sctp6_sock *)newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	inet_sk(newsk)->pinet6 = &newsctp6sk->inet6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	sctp_sk(newsk)->v4mapped = sctp_sk(sk)->v4mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	newnp = inet6_sk(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	memcpy(newnp, np, sizeof(struct ipv6_pinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	newnp->ipv6_mc_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	newnp->ipv6_ac_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	newnp->ipv6_fl_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	sctp_v6_copy_ip_options(sk, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	/* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	 * and getpeername().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	newsk->sk_v6_rcv_saddr = sk->sk_v6_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	sk_refcnt_debug_inc(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (newsk->sk_prot->init(newsk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		sk_common_release(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		newsk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	return newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) /* Format a sockaddr for return to user space. This makes sure the return is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  * AF_INET or AF_INET6 depending on the SCTP_I_WANT_MAPPED_V4_ADDR option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static int sctp_v6_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	if (sp->v4mapped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		if (addr->sa.sa_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			sctp_v4_map_v6(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		if (addr->sa.sa_family == AF_INET6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		    ipv6_addr_v4mapped(&addr->v6.sin6_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			sctp_v6_map_v4(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (addr->sa.sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		return sizeof(struct sockaddr_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	return sizeof(struct sockaddr_in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) /* Where did this skb come from?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) static int sctp_v6_skb_iif(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	return IP6CB(skb)->iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) /* Was this packet marked by Explicit Congestion Notification? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) static int sctp_v6_is_ce(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	return *((__u32 *)(ipv6_hdr(skb))) & (__force __u32)htonl(1 << 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) /* Dump the v6 addr to the seq file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) static void sctp_v6_ecn_capable(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	inet6_sk(sk)->tclass |= INET_ECN_ECT_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) /* Initialize a PF_INET msgname from a ulpevent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) static void sctp_inet6_event_msgname(struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 				     char *msgname, int *addrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	union sctp_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	union sctp_addr *paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	if (!msgname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	addr = (union sctp_addr *)msgname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	asoc = event->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	paddr = &asoc->peer.primary_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	if (paddr->sa.sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		addr->v4.sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		addr->v4.sin_port = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		addr->v4.sin_addr = paddr->v4.sin_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		addr->v6.sin6_flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		if (ipv6_addr_type(&paddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			addr->v6.sin6_scope_id = paddr->v6.sin6_scope_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			addr->v6.sin6_scope_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		addr->v6.sin6_port = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		addr->v6.sin6_addr = paddr->v6.sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	*addrlen = sctp_v6_addr_to_user(sctp_sk(asoc->base.sk), addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) /* Initialize a msg_name from an inbound skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 				   int *addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	union sctp_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	struct sctphdr *sh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (!msgname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	addr = (union sctp_addr *)msgname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	sh = sctp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	if (ip_hdr(skb)->version == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		addr->v4.sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		addr->v4.sin_port = sh->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		addr->v4.sin_addr.s_addr = ip_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		addr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		addr->v6.sin6_flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		addr->v6.sin6_port = sh->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		addr->v6.sin6_addr = ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			addr->v6.sin6_scope_id = sctp_v6_skb_iif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			addr->v6.sin6_scope_id = 0;
^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) 	*addr_len = sctp_v6_addr_to_user(sctp_sk(skb->sk), addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) /* Do we support this AF? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	switch (family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	/* v4-mapped-v6 addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		if (!__ipv6_only_sock(sctp_opt2sk(sp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) /* Address matching with wildcards allowed.  This extra level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  * of indirection lets us choose whether a PF_INET6 should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)  * disallow any v4 addresses if we so choose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			       const union sctp_addr *addr2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			       struct sctp_sock *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	struct sock *sk = sctp_opt2sk(opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	struct sctp_af *af1, *af2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	af1 = sctp_get_af_specific(addr1->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	af2 = sctp_get_af_specific(addr2->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	if (!af1 || !af2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	/* If the socket is IPv6 only, v4 addrs will not match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	if (__ipv6_only_sock(sk) && af1 != af2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	/* Today, wildcard AF_INET/AF_INET6. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	if (addr1->sa.sa_family == AF_INET && addr2->sa.sa_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		return addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	return __sctp_v6_cmp_addr(addr1, addr2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) /* Verify that the provided sockaddr looks bindable.   Common verification,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  * has already been taken care of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	/* ASSERT: address family has already been verified. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	if (addr->sa.sa_family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		af = sctp_get_af_specific(addr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		int type = ipv6_addr_type(&addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		if (type & IPV6_ADDR_LINKLOCAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			if (!addr->v6.sin6_scope_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 			net = sock_net(&opt->inet.sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			if (!dev || !(ipv6_can_nonlocal_bind(net, &opt->inet) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 				      ipv6_chk_addr(net, &addr->v6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 						    dev, 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 				rcu_read_unlock();
^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) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		af = opt->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	return af->available(addr, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) /* Verify that the provided sockaddr looks sendable.   Common verification,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)  * has already been taken care of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	struct sctp_af *af = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	/* ASSERT: address family has already been verified. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (addr->sa.sa_family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		af = sctp_get_af_specific(addr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		int type = ipv6_addr_type(&addr->v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		if (type & IPV6_ADDR_LINKLOCAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			if (!addr->v6.sin6_scope_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			dev = dev_get_by_index_rcu(sock_net(&opt->inet.sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 						   addr->v6.sin6_scope_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		af = opt->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return af != NULL;
^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) /* Fill in Supported Address Type information for INIT and INIT-ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)  * chunks.   Note: In the future, we may want to look at sock options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987)  * to determine whether a PF_INET6 socket really wants to have IPV4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)  * addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)  * Returns number of addresses supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) static int sctp_inet6_supported_addrs(const struct sctp_sock *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 				      __be16 *types)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	types[0] = SCTP_PARAM_IPV6_ADDRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if (!opt || !ipv6_only_sock(sctp_opt2sk(opt))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		types[1] = SCTP_PARAM_IPV4_ADDRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /* Handle SCTP_I_WANT_MAPPED_V4_ADDR for getpeername() and getsockname() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static int sctp_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	rc = inet6_getname(sock, uaddr, peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	rc = sctp_v6_addr_to_user(sctp_sk(sock->sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 					  (union sctp_addr *)uaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) static const struct proto_ops inet6_seqpacket_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	.family		   = PF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	.owner		   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	.release	   = inet6_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	.bind		   = inet6_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	.connect	   = sctp_inet_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	.socketpair	   = sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	.accept		   = inet_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	.getname	   = sctp_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	.poll		   = sctp_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	.ioctl		   = inet6_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	.gettstamp	   = sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	.listen		   = sctp_inet_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	.shutdown	   = inet_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	.setsockopt	   = sock_common_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	.getsockopt	   = sock_common_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	.sendmsg	   = inet_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	.recvmsg	   = inet_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	.mmap		   = sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	.compat_ioctl	   = inet6_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) static struct inet_protosw sctpv6_seqpacket_protosw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	.type          = SOCK_SEQPACKET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	.protocol      = IPPROTO_SCTP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	.prot 	       = &sctpv6_prot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	.ops           = &inet6_seqpacket_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	.flags         = SCTP_PROTOSW_FLAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static struct inet_protosw sctpv6_stream_protosw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	.type          = SOCK_STREAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	.protocol      = IPPROTO_SCTP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	.prot 	       = &sctpv6_prot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	.ops           = &inet6_seqpacket_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	.flags         = SCTP_PROTOSW_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static int sctp6_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	return sctp_rcv(skb) ? -1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static const struct inet6_protocol sctpv6_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	.handler      = sctp6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	.err_handler  = sctp_v6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	.flags        = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
^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 struct sctp_af sctp_af_inet6 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	.sa_family	   = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	.sctp_xmit	   = sctp_v6_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	.setsockopt	   = ipv6_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	.getsockopt	   = ipv6_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	.get_dst	   = sctp_v6_get_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	.get_saddr	   = sctp_v6_get_saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	.copy_addrlist	   = sctp_v6_copy_addrlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	.from_skb	   = sctp_v6_from_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	.from_sk	   = sctp_v6_from_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	.from_addr_param   = sctp_v6_from_addr_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	.to_addr_param	   = sctp_v6_to_addr_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	.cmp_addr	   = sctp_v6_cmp_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	.scope		   = sctp_v6_scope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	.addr_valid	   = sctp_v6_addr_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	.inaddr_any	   = sctp_v6_inaddr_any,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	.is_any		   = sctp_v6_is_any,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	.available	   = sctp_v6_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	.skb_iif	   = sctp_v6_skb_iif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	.is_ce		   = sctp_v6_is_ce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	.seq_dump_addr	   = sctp_v6_seq_dump_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	.ecn_capable	   = sctp_v6_ecn_capable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	.net_header_len	   = sizeof(struct ipv6hdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	.sockaddr_len	   = sizeof(struct sockaddr_in6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	.ip_options_len	   = sctp_v6_ip_options_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static struct sctp_pf sctp_pf_inet6 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	.event_msgname = sctp_inet6_event_msgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	.skb_msgname   = sctp_inet6_skb_msgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	.af_supported  = sctp_inet6_af_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	.cmp_addr      = sctp_inet6_cmp_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	.bind_verify   = sctp_inet6_bind_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	.send_verify   = sctp_inet6_send_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	.supported_addrs = sctp_inet6_supported_addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	.create_accept_sk = sctp_v6_create_accept_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	.addr_to_user  = sctp_v6_addr_to_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	.to_sk_saddr   = sctp_v6_to_sk_saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	.to_sk_daddr   = sctp_v6_to_sk_daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	.copy_ip_options = sctp_v6_copy_ip_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	.af            = &sctp_af_inet6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) /* Initialize IPv6 support and register with socket layer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) void sctp_v6_pf_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	/* Register the SCTP specific PF_INET6 functions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	sctp_register_pf(&sctp_pf_inet6, PF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	/* Register the SCTP specific AF_INET6 functions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	sctp_register_af(&sctp_af_inet6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) void sctp_v6_pf_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	list_del(&sctp_af_inet6.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) /* Initialize IPv6 support and register with socket layer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) int sctp_v6_protosw_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	rc = proto_register(&sctpv6_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	/* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	inet6_register_protosw(&sctpv6_seqpacket_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	inet6_register_protosw(&sctpv6_stream_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) void sctp_v6_protosw_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	inet6_unregister_protosw(&sctpv6_seqpacket_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	inet6_unregister_protosw(&sctpv6_stream_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	proto_unregister(&sctpv6_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) /* Register with inet6 layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) int sctp_v6_add_protocol(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	/* Register notifier for inet6 address additions/deletions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	register_inet6addr_notifier(&sctp_inet6addr_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /* Unregister with inet6 layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) void sctp_v6_del_protocol(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	unregister_inet6addr_notifier(&sctp_inet6addr_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) }