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)  * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2001-2003 International Business Machines, Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2001 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2001 Nokia, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (c) 2001 La Monte H.P. Yarroll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * These functions handle all input from the IP layer into SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *    lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Written or modified by:
^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)  *    Karl Knutson <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    Xingang Guo <xingang.guo@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *    Jon Grimm <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *    Hui Huang <hui.huang@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *    Daisy Chang <daisyc@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *    Sridhar Samudrala <sri@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *    Ardelle Fan <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/list.h> /* For struct list_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/time.h> /* For struct timeval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <net/sctp/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/rhashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <net/sock_reuseport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /* Forward declarations for internal helpers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static int sctp_rcv_ootb(struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static struct sctp_association *__sctp_rcv_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 				      struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 				      const union sctp_addr *paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 				      const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 				      struct sctp_transport **transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 					struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 					const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 					const union sctp_addr *daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) static struct sctp_association *__sctp_lookup_association(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 					const union sctp_addr *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 					const union sctp_addr *peer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 					struct sctp_transport **pt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /* Calculate the SCTP checksum of an SCTP packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	struct sctphdr *sh = sctp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	__le32 cmp = sh->checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	__le32 val = sctp_compute_cksum(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	if (val != cmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		/* CRC failure, dump it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		__SCTP_INC_STATS(net, SCTP_MIB_CHECKSUMERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  * This is the routine which IP calls when receiving an SCTP packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) int sctp_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	struct sctp_endpoint *ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	struct sctp_ep_common *rcvr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	struct sctp_transport *transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	union sctp_addr src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	union sctp_addr dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	int family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	bool is_gso = skb_is_gso(skb) && skb_is_gso_sctp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	if (skb->pkt_type != PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	__SCTP_INC_STATS(net, SCTP_MIB_INSCTPPACKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	/* If packet is too small to contain a single chunk, let's not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	 * waste time on it anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	if (skb->len < sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		       skb_transport_offset(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	/* If the packet is fragmented and we need to do crc checking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	 * it's better to just linearize it otherwise crc computing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	 * takes longer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	if ((!is_gso && skb_linearize(skb)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	    !pskb_may_pull(skb, sizeof(struct sctphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	/* Pull up the IP header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	__skb_pull(skb, skb_transport_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	skb->csum_valid = 0; /* Previous value not applicable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	if (skb_csum_unnecessary(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		__skb_decr_checksum_unnecessary(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	else if (!sctp_checksum_disable &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		 !is_gso &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		 sctp_rcv_checksum(net, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	skb->csum_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	__skb_pull(skb, sizeof(struct sctphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	family = ipver2af(ip_hdr(skb)->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	af = sctp_get_af_specific(family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	if (unlikely(!af))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	SCTP_INPUT_CB(skb)->af = af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	/* Initialize local addresses for lookups. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	af->from_skb(&src, skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	af->from_skb(&dest, skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	/* If the packet is to or from a non-unicast address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	 * silently discard the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	 * This is not clearly defined in the RFC except in section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	 * 8.4 - OOTB handling.  However, based on the book "Stream Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	 * Transmission Protocol" 2.1, "It is important to note that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	 * IP address of an SCTP transport address must be a routable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	 * unicast address.  In other words, IP multicast addresses and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	 * IP broadcast addresses cannot be used in an SCTP transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	 * address."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	if (!af->addr_valid(&src, NULL, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	    !af->addr_valid(&dest, NULL, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	/* Retrieve the common input handling substructure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	rcvr = asoc ? &asoc->base : &ep->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	sk = rcvr->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	 * If a frame arrives on an interface and the receiving socket is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	 * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 			asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 			transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 			sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 			ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		sk = net->sctp.ctl_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		sctp_endpoint_hold(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		rcvr = &ep->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	 * RFC 2960, 8.4 - Handle "Out of the blue" Packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	 * An SCTP packet is called an "out of the blue" (OOTB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	 * packet if it is correctly formed, i.e., passed the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	 * receiver's checksum check, but the receiver is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	 * able to identify the association to which this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	 * packet belongs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (!asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		if (sctp_rcv_ootb(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 			__SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			goto discard_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		}
^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) 	if (!xfrm_policy_check(sk, XFRM_POLICY_IN, skb, family))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		goto discard_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	if (sk_filter(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		goto discard_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	/* Create an SCTP packet structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	chunk = sctp_chunkify(skb, asoc, sk, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (!chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		goto discard_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	SCTP_INPUT_CB(skb)->chunk = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	/* Remember what endpoint is to handle this packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	chunk->rcvr = rcvr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	/* Remember the SCTP header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	chunk->sctp_hdr = sctp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	/* Set the source and destination addresses of the incoming chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	sctp_init_addrs(chunk, &src, &dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	/* Remember where we came from.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	chunk->transport = transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	/* Acquire access to the sock lock. Note: We are safe from other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	 * bottom halves on this lock, but a user may be in the lock too,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	 * so check if it is busy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (sk != rcvr->sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		/* Our cached sk is different from the rcvr->sk.  This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		 * because migrate()/accept() may have moved the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		 * to a new socket and released all the sockets.  So now we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		 * are holding a lock on the old socket while the user may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		 * be doing something with the new socket.  Switch our veiw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		 * of the current sk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		sk = rcvr->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	if (sock_owned_by_user(sk) || !sctp_newsk_ready(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		if (sctp_add_backlog(sk, skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 			bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 			sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			skb = NULL; /* sctp_chunk_free already freed the skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 			goto discard_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		__SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_BACKLOG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		__SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_SOFTIRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		sctp_inq_push(&chunk->rcvr->inqueue, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	/* Release the asoc/ep ref we took in the lookup calls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	if (transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) discard_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	__SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) discard_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	/* Release the asoc/ep ref we took in the lookup calls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	if (transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	goto discard_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) /* Process the backlog queue of the socket.  Every skb on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * the backlog holds a ref on an association or endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  * We hold this ref throughout the state machine to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  * sure that the structure we need is still around.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	struct sctp_inq *inqueue = &chunk->rcvr->inqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	struct sctp_transport *t = chunk->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	struct sctp_ep_common *rcvr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	int backloged = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	rcvr = chunk->rcvr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	/* If the rcvr is dead then the association or endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	 * has been deleted and we can safely drop the chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	 * and refs that we are holding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	if (rcvr->dead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	if (unlikely(rcvr->sk != sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		/* In this case, the association moved from one socket to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		 * another.  We are currently sitting on the backlog of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		 * old socket, so we need to move.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		 * However, since we are here in the process context we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		 * need to take make sure that the user doesn't own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		 * the new socket when we process the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		 * If the new socket is user-owned, queue the chunk to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		 * backlog of the new socket without dropping any refs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		 * Otherwise, we can safely push the chunk on the inqueue.
^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) 		sk = rcvr->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		if (sock_owned_by_user(sk) || !sctp_newsk_ready(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			if (sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 				sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 				backloged = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			sctp_inq_push(inqueue, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		/* If the chunk was backloged again, don't drop refs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		if (backloged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		if (!sctp_newsk_ready(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			if (!sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			sctp_inq_push(inqueue, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	/* Release the refs we took in sctp_add_backlog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	else if (SCTP_EP_TYPE_SOCKET == rcvr->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		sctp_endpoint_put(sctp_ep(rcvr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	struct sctp_transport *t = chunk->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	struct sctp_ep_common *rcvr = chunk->rcvr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	ret = sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		/* Hold the assoc/ep while hanging on the backlog queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		 * This way, we know structures we need will not disappear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		 * from us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			sctp_transport_hold(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		else if (SCTP_EP_TYPE_SOCKET == rcvr->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			sctp_endpoint_hold(sctp_ep(rcvr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) /* Handle icmp frag needed error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			   struct sctp_transport *t, __u32 pmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (!t || (t->pathmtu <= pmtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	if (sock_owned_by_user(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		atomic_set(&t->mtu_info, pmtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		asoc->pmtu_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		t->pmtu_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (!(t->param_flags & SPP_PMTUD_ENABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		/* We can't allow retransmitting in such case, as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		 * retransmission would be sized just as before, and thus we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		 * would get another icmp, and retransmit again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* Update transports view of the MTU. Return if no update was needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	 * If an update wasn't needed/possible, it also doesn't make sense to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	 * try to retransmit now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (!sctp_transport_update_pmtu(t, pmtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	/* Update association pmtu. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	sctp_assoc_sync_pmtu(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	/* Retransmit with the new pmtu setting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	sctp_retransmit(&asoc->outqueue, t, SCTP_RTXR_PMTUD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) void sctp_icmp_redirect(struct sock *sk, struct sctp_transport *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (sock_owned_by_user(sk) || !t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	dst = sctp_transport_dst_check(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		dst->ops->redirect(dst, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  * SCTP Implementer's Guide, 2.37 ICMP handling procedures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434)  * ICMP8) If the ICMP code is a "Unrecognized next header type encountered"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435)  *        or a "Protocol Unreachable" treat this message as an abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)  *        with the T bit set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438)  * This function sends an event to the state machine, which will abort the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)  * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) void sctp_icmp_proto_unreachable(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			   struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			   struct sctp_transport *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	if (sock_owned_by_user(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		if (timer_pending(&t->proto_unreach_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			if (!mod_timer(&t->proto_unreach_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 						jiffies + (HZ/20)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				sctp_transport_hold(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		pr_debug("%s: unrecognized next header type "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			 "encountered!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		if (del_timer(&t->proto_unreach_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		sctp_do_sm(net, SCTP_EVENT_T_OTHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			   SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			   asoc->state, asoc->ep, asoc, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			   GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) /* Common lookup code for icmp/icmpv6 error handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			     struct sctphdr *sctphdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			     struct sctp_association **app,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			     struct sctp_transport **tpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	struct sctp_init_chunk *chunkhdr, _chunkhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	union sctp_addr saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	union sctp_addr daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	struct sctp_transport *transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	__u32 vtag = ntohl(sctphdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	*app = NULL; *tpp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	af = sctp_get_af_specific(family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if (unlikely(!af)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	/* Initialize local addresses for lookups. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	af->from_skb(&saddr, skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	af->from_skb(&daddr, skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	/* Look for an association that matches the incoming ICMP error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	 * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	asoc = __sctp_lookup_association(net, &saddr, &daddr, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	/* RFC 4960, Appendix C. ICMP Handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	 * ICMP6) An implementation MUST validate that the Verification Tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	 * contained in the ICMP message matches the Verification Tag of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	 * the peer.  If the Verification Tag is not 0 and does NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	 * match, discard the ICMP message.  If it is 0 and the ICMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	 * message contains enough bytes to verify that the chunk type is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	 * an INIT chunk and that the Initiate Tag matches the tag of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	 * peer, continue with ICMP7.  If the ICMP message is too short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	 * or the chunk type or the Initiate Tag does not match, silently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	 * discard the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (vtag == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		/* chunk header + first 4 octects of init header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		chunkhdr = skb_header_pointer(skb, skb_transport_offset(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 					      sizeof(struct sctphdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 					      sizeof(struct sctp_chunkhdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 					      sizeof(__be32), &_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		if (!chunkhdr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		    chunkhdr->chunk_hdr.type != SCTP_CID_INIT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		    ntohl(chunkhdr->init_hdr.init_tag) != asoc->c.my_vtag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	} else if (vtag != asoc->c.peer_vtag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	/* If too many ICMPs get dropped on busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	 * servers this needs to be solved differently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	if (sock_owned_by_user(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		__NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	*app = asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	*tpp = transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return NULL;
^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) /* Common cleanup code for icmp/icmpv6 error handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) void sctp_err_finish(struct sock *sk, struct sctp_transport *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	__releases(&((__sk)->sk_lock.slock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  * This routine is called by the ICMP module when it gets some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)  * sort of error condition.  If err < 0 then the socket should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * be closed and the error returned to the user.  If err > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * it's just the icmp type << 8 | icmp code.  After adjustment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * header points to the first 8 bytes of the sctp header.  We need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  * to find the appropriate port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  * The locking strategy used here is very "optimistic". When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  * someone else accesses the socket the ICMP is just dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * and for some paths there is no check at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  * A more general error queue to queue errors for later handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  * is probably better.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) int sctp_v4_err(struct sk_buff *skb, __u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	const struct iphdr *iph = (const struct iphdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	const int ihlen = iph->ihl * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	const int type = icmp_hdr(skb)->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	const int code = icmp_hdr(skb)->code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	struct inet_sock *inet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	__u16 saveip, savesctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	/* Fix up skb to look at the embedded net header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	saveip = skb->network_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	savesctp = skb->transport_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	skb_set_transport_header(skb, ihlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	sk = sctp_err_lookup(net, AF_INET, skb, sctp_hdr(skb), &asoc, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	/* Put back, the original values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	skb->network_header = saveip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	skb->transport_header = savesctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	if (!sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		__ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	/* Warning:  The sock lock is held.  Remember to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 * sctp_err_finish!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	case ICMP_PARAMETERPROB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		err = EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	case ICMP_DEST_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		if (code > NR_ICMP_UNREACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		/* PMTU discovery (RFC1191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if (ICMP_FRAG_NEEDED == code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			sctp_icmp_frag_needed(sk, asoc, transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 					      SCTP_TRUNC4(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			if (ICMP_PROT_UNREACH == code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 				sctp_icmp_proto_unreachable(sk, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 							    transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		err = icmp_err_convert[code].errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	case ICMP_TIME_EXCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		/* Ignore any time exceeded errors due to fragment reassembly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		 * timeouts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		if (ICMP_EXC_FRAGTIME == code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		err = EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	case ICMP_REDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		sctp_icmp_redirect(sk, transport, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		/* Fall through to out_unlock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	if (!sock_owned_by_user(sk) && inet->recverr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		sk->sk_error_report(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	} else {  /* Only an error on timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		sk->sk_err_soft = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	sctp_err_finish(sk, transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^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)  * RFC 2960, 8.4 - Handle "Out of the blue" Packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)  * This function scans all the chunks in the OOTB packet to determine if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * the packet should be discarded right away.  If a response might be needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  * for this packet, or, if further processing is possible, the packet will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * be queued to a proper inqueue for the next phase of handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)  * Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  * Return 0 - If further processing is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  * Return 1 - If the packet can be discarded right away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) static int sctp_rcv_ootb(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	struct sctp_chunkhdr *ch, _ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	int ch_end, offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	/* Scan through all the chunks in the packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		/* Make sure we have at least the header there */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		if (offset + sizeof(_ch) > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		ch = skb_header_pointer(skb, offset, sizeof(*ch), &_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		/* Break out if chunk length is less then minimal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		if (!ch || ntohs(ch->length) < sizeof(_ch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		ch_end = offset + SCTP_PAD4(ntohs(ch->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		if (ch_end > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		/* RFC 8.4, 2) If the OOTB packet contains an ABORT chunk, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		 * receiver MUST silently discard the OOTB packet and take no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		 * further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (SCTP_CID_ABORT == ch->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		/* RFC 8.4, 6) If the packet contains a SHUTDOWN COMPLETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		 * chunk, the receiver should silently discard the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		 * and take no further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if (SCTP_CID_SHUTDOWN_COMPLETE == ch->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		/* RFC 4460, 2.11.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		 * This will discard packets with INIT chunk bundled as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		 * subsequent chunks in the packet.  When INIT is first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		 * the normal INIT processing will discard the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		if (SCTP_CID_INIT == ch->type && (void *)ch != skb->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		offset = ch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	} while (ch_end < skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) /* Insert endpoint into the hash table.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	struct sock *sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct sctp_hashbucket *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	struct sctp_ep_common *epb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	epb = &ep->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	head = &sctp_ep_hashtable[epb->hashent];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (sk->sk_reuseport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		bool any = sctp_is_ep_boundall(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		struct sctp_ep_common *epb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		struct list_head *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		int cnt = 0, err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		list_for_each(list, &ep->base.bind_addr.address_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		sctp_for_each_hentry(epb2, &head->chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			struct sock *sk2 = epb2->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			if (!net_eq(sock_net(sk2), net) || sk2 == sk ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			    !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			    !sk2->sk_reuseport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			err = sctp_bind_addrs_check(sctp_sk(sk2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 						    sctp_sk(sk), cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				err = reuseport_add_sock(sk, sk2, any);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 					return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			} else if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 				return err;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			err = reuseport_alloc(sk, any);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 				return err;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	write_lock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	hlist_add_head(&epb->node, &head->chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	write_unlock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) /* Add an endpoint to the hash. Local BH-safe. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) int sctp_hash_endpoint(struct sctp_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	err = __sctp_hash_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) /* Remove endpoint from the hash table.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	struct sock *sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	struct sctp_hashbucket *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	struct sctp_ep_common *epb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	epb = &ep->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	head = &sctp_ep_hashtable[epb->hashent];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (rcu_access_pointer(sk->sk_reuseport_cb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		reuseport_detach_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	write_lock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	hlist_del_init(&epb->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	write_unlock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) /* Remove endpoint from the hash.  Local BH-safe. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) void sctp_unhash_endpoint(struct sctp_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	__sctp_unhash_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 				const union sctp_addr *paddr, __u32 seed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	__u32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	if (paddr->sa.sa_family == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		addr = jhash(&paddr->v6.sin6_addr, 16, seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		addr = (__force __u32)paddr->v4.sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	return  jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			     (__force __u32)lport, net_hash_mix(net), seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) /* Look up an endpoint. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 					struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 					const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 					const union sctp_addr *paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	struct sctp_hashbucket *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	struct sctp_ep_common *epb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	__be16 lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	lport = laddr->v4.sin_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	hash = sctp_ep_hashfn(net, ntohs(lport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	head = &sctp_ep_hashtable[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	read_lock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	sctp_for_each_hentry(epb, &head->chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		ep = sctp_ep(epb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		if (sctp_endpoint_is_match(ep, net, laddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 			goto hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	ep = sctp_sk(net->sctp.ctl_sock)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) hit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	if (sk->sk_reuseport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		__u32 phash = sctp_hashfn(net, lport, paddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		sk = reuseport_select_sock(sk, phash, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 					   sizeof(struct sctphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		if (sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	sctp_endpoint_hold(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	read_unlock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	return ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) /* rhashtable for transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) struct sctp_hash_cmp_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	const union sctp_addr	*paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	const struct net	*net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	__be16			lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 				const void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	struct sctp_transport *t = (struct sctp_transport *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	const struct sctp_hash_cmp_arg *x = arg->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	int err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	if (!sctp_cmp_addr_exact(&t->ipaddr, x->paddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (!sctp_transport_hold(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (!net_eq(t->asoc->base.net, x->net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (x->lport != htons(t->asoc->base.bind_addr.port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	const struct sctp_transport *t = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return sctp_hashfn(t->asoc->base.net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			   htons(t->asoc->base.bind_addr.port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			   &t->ipaddr, seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	const struct sctp_hash_cmp_arg *x = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	return sctp_hashfn(x->net, x->lport, x->paddr, seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) static const struct rhashtable_params sctp_hash_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	.head_offset		= offsetof(struct sctp_transport, node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	.hashfn			= sctp_hash_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	.obj_hashfn		= sctp_hash_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	.obj_cmpfn		= sctp_hash_cmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	.automatic_shrinking	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) int sctp_transport_hashtable_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	return rhltable_init(&sctp_transport_hashtable, &sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) void sctp_transport_hashtable_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	rhltable_destroy(&sctp_transport_hashtable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) int sctp_hash_transport(struct sctp_transport *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	struct rhlist_head *tmp, *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	struct sctp_hash_cmp_arg arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	if (t->asoc->temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	arg.net   = t->asoc->base.net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	arg.paddr = &t->ipaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	arg.lport = htons(t->asoc->base.bind_addr.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	list = rhltable_lookup(&sctp_transport_hashtable, &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			       sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	rhl_for_each_entry_rcu(transport, tmp, list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		if (transport->asoc->ep == t->asoc->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				  &t->node, sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		pr_err_once("insert transport fail, errno %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) void sctp_unhash_transport(struct sctp_transport *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	if (t->asoc->temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	rhltable_remove(&sctp_transport_hashtable, &t->node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) /* return a transport with holding it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) struct sctp_transport *sctp_addrs_lookup_transport(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 				struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 				const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 				const union sctp_addr *paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	struct rhlist_head *tmp, *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	struct sctp_hash_cmp_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		.paddr = paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		.net   = net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		.lport = laddr->v4.sin_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	list = rhltable_lookup(&sctp_transport_hashtable, &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			       sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	rhl_for_each_entry_rcu(t, tmp, list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (!sctp_transport_hold(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		if (sctp_bind_addr_match(&t->asoc->base.bind_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 					 laddr, sctp_sk(t->asoc->base.sk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	return NULL;
^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) /* return a transport without holding it, as it's only used under sock lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) struct sctp_transport *sctp_epaddr_lookup_transport(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 				const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 				const union sctp_addr *paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	struct rhlist_head *tmp, *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	struct sctp_hash_cmp_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		.paddr = paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		.net   = ep->base.net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		.lport = htons(ep->base.bind_addr.port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	list = rhltable_lookup(&sctp_transport_hashtable, &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 			       sctp_hash_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	rhl_for_each_entry_rcu(t, tmp, list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		if (ep == t->asoc->ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) /* Look up an association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) static struct sctp_association *__sctp_lookup_association(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					const union sctp_addr *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 					const union sctp_addr *peer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 					struct sctp_transport **pt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	t = sctp_addrs_lookup_transport(net, local, peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	asoc = t->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	*pt = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /* Look up an association. protected by RCU read lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) struct sctp_association *sctp_lookup_association(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 						 const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 						 const union sctp_addr *paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 						 struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	asoc = __sctp_lookup_association(net, laddr, paddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	return asoc;
^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) /* Is there an association matching the given local and peer addresses? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) bool sctp_has_association(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			  const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 			  const union sctp_addr *paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	if (sctp_lookup_association(net, laddr, paddr, &transport)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)  * SCTP Implementors Guide, 2.18 Handling of address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)  * parameters within the INIT or INIT-ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)  * D) When searching for a matching TCB upon reception of an INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)  *    or INIT-ACK chunk the receiver SHOULD use not only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)  *    source address of the packet (containing the INIT or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)  *    INIT-ACK) but the receiver SHOULD also use all valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)  *    address parameters contained within the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)  * 2.18.3 Solution description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)  * This new text clearly specifies to an implementor the need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)  * to look within the INIT or INIT-ACK. Any implementation that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)  * does not do this, may not be able to establish associations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)  * in certain circumstances.
^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_association *__sctp_rcv_init_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	const union sctp_addr *laddr, struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	union sctp_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	union sctp_addr *paddr = &addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	struct sctphdr *sh = sctp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	union sctp_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	struct sctp_init_chunk *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	 * This code will NOT touch anything inside the chunk--it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	 * strictly READ-ONLY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 * RFC 2960 3  SCTP packet Format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	 * Multiple chunks can be bundled into one SCTP packet up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	 * the MTU size, except for the INIT, INIT ACK, and SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	 * COMPLETE chunks.  These chunks MUST NOT be bundled with any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	 * other chunk in a packet.  See Section 6.10 for more details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	 * on chunk bundling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	/* Find the start of the TLVs and the end of the chunk.  This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	 * the region we search for address parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	init = (struct sctp_init_chunk *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	/* Walk the parameters looking for embedded addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	sctp_walk_params(params, init, init_hdr.params) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		/* Note: Ignoring hostname addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		af = sctp_get_af_specific(param_type2af(params.p->type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		if (!af->from_addr_param(paddr, params.addr, sh->source, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		asoc = __sctp_lookup_association(net, laddr, paddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /* ADD-IP, Section 5.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)  * When an endpoint receives an ASCONF Chunk from the remote peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)  * special procedures may be needed to identify the association the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  * ASCONF Chunk is associated with. To properly find the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)  * the following procedures SHOULD be followed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * D2) If the association is not found, use the address found in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * Address Parameter TLV combined with the port number found in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  * SCTP common header. If found proceed to rule D4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * D2-ext) If more than one ASCONF Chunks are packed together, use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  * address found in the ASCONF Address Parameter TLV of each of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  * subsequent ASCONF Chunks. If found, proceed to rule D4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) static struct sctp_association *__sctp_rcv_asconf_lookup(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 					struct sctp_chunkhdr *ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 					const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 					__be16 peer_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 					struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	struct sctp_addip_chunk *asconf = (struct sctp_addip_chunk *)ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	union sctp_addr_param *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	union sctp_addr paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	if (ntohs(ch->length) < sizeof(*asconf) + sizeof(struct sctp_paramhdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	/* Skip over the ADDIP header and find the Address parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	param = (union sctp_addr_param *)(asconf + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	af = sctp_get_af_specific(param_type2af(param->p.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (unlikely(!af))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (!af->from_addr_param(&paddr, param, peer_port, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	return __sctp_lookup_association(net, laddr, &paddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) /* SCTP-AUTH, Section 6.3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) *    If the receiver does not find a STCB for a packet containing an AUTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) *    chunk as the first chunk and not a COOKIE-ECHO chunk as the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) *    chunk, it MUST use the chunks after the AUTH chunk to look up an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) *    association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * This means that any chunks that can help us identify the association need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * to be looked at to find this association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static struct sctp_association *__sctp_rcv_walk_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 				      struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 				      const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 				      struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	struct sctp_chunkhdr *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	int have_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	unsigned int chunk_num = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	__u8 *ch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	/* Walk through the chunks looking for AUTH or ASCONF chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	 * to help us find the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	ch = (struct sctp_chunkhdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		/* Break out if chunk length is less then minimal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		if (ntohs(ch->length) < sizeof(*ch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		if (ch_end > skb_tail_pointer(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		switch (ch->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		case SCTP_CID_AUTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 			have_auth = chunk_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		case SCTP_CID_COOKIE_ECHO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			/* If a packet arrives containing an AUTH chunk as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 			 * a first chunk, a COOKIE-ECHO chunk as the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			 * chunk, and possibly more chunks after them, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 			 * the receiver does not have an STCB for that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 			 * packet, then authentication is based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 			 * the contents of the COOKIE- ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 			if (have_auth == 1 && chunk_num == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		case SCTP_CID_ASCONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			if (have_auth || net->sctp.addip_noauth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 				asoc = __sctp_rcv_asconf_lookup(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 						net, ch, laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 						sctp_hdr(skb)->source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 						transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		ch = (struct sctp_chunkhdr *)ch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		chunk_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	} while (ch_end + sizeof(*ch) < skb_tail_pointer(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)  * There are circumstances when we need to look inside the SCTP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)  * for information to help us find the association.   Examples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)  * include looking inside of INIT/INIT-ACK chunks or after the AUTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)  * chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static struct sctp_association *__sctp_rcv_lookup_harder(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 				      struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 				      const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 				      struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	struct sctp_chunkhdr *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	/* We do not allow GSO frames here as we need to linearize and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	 * then cannot guarantee frame boundaries. This shouldn't be an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	 * issue as packets hitting this are mostly INIT or INIT-ACK and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	 * those cannot be on GSO-style anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	ch = (struct sctp_chunkhdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	/* The code below will attempt to walk the chunk and extract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	 * parameter information.  Before we do that, we need to verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	 * that the chunk length doesn't cause overflow.  Otherwise, we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	 * walk off the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	if (SCTP_PAD4(ntohs(ch->length)) > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	/* If this is INIT/INIT-ACK look inside the chunk too. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	if (ch->type == SCTP_CID_INIT || ch->type == SCTP_CID_INIT_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		return __sctp_rcv_init_lookup(net, skb, laddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	return __sctp_rcv_walk_lookup(net, skb, laddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) /* Lookup an association for an inbound skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) static struct sctp_association *__sctp_rcv_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 				      struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 				      const union sctp_addr *paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				      const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 				      struct sctp_transport **transportp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	asoc = __sctp_lookup_association(net, laddr, paddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	/* Further lookup for INIT/INIT-ACK packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	 * SCTP Implementors Guide, 2.18 Handling of address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	 * parameters within the INIT or INIT-ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	asoc = __sctp_rcv_lookup_harder(net, skb, laddr, transportp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	if (paddr->sa.sa_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		pr_debug("sctp: asoc not found for src:%pI4:%d dst:%pI4:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			 &laddr->v4.sin_addr, ntohs(laddr->v4.sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			 &paddr->v4.sin_addr, ntohs(paddr->v4.sin_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		pr_debug("sctp: asoc not found for src:%pI6:%d dst:%pI6:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 			 &laddr->v6.sin6_addr, ntohs(laddr->v6.sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			 &paddr->v6.sin6_addr, ntohs(paddr->v6.sin6_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }