input.c 35 KB

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