inet_connection_sock.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Support for INET connection oriented protocols.
  7. *
  8. * Authors: See the TCP sources
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or(at your option) any later version.
  14. */
  15. #include <linux/config.h>
  16. #include <linux/module.h>
  17. #include <linux/jhash.h>
  18. #include <net/inet_connection_sock.h>
  19. #include <net/inet_hashtables.h>
  20. #include <net/inet_timewait_sock.h>
  21. #include <net/ip.h>
  22. #include <net/route.h>
  23. #include <net/tcp_states.h>
  24. #include <net/xfrm.h>
  25. #ifdef INET_CSK_DEBUG
  26. const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
  27. EXPORT_SYMBOL(inet_csk_timer_bug_msg);
  28. #endif
  29. /*
  30. * This array holds the first and last local port number.
  31. * For high-usage systems, use sysctl to change this to
  32. * 32768-61000
  33. */
  34. int sysctl_local_port_range[2] = { 1024, 4999 };
  35. static inline int inet_csk_bind_conflict(struct sock *sk, struct inet_bind_bucket *tb)
  36. {
  37. const u32 sk_rcv_saddr = inet_rcv_saddr(sk);
  38. struct sock *sk2;
  39. struct hlist_node *node;
  40. int reuse = sk->sk_reuse;
  41. sk_for_each_bound(sk2, node, &tb->owners) {
  42. if (sk != sk2 &&
  43. !inet_v6_ipv6only(sk2) &&
  44. (!sk->sk_bound_dev_if ||
  45. !sk2->sk_bound_dev_if ||
  46. sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
  47. if (!reuse || !sk2->sk_reuse ||
  48. sk2->sk_state == TCP_LISTEN) {
  49. const u32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
  50. if (!sk2_rcv_saddr || !sk_rcv_saddr ||
  51. sk2_rcv_saddr == sk_rcv_saddr)
  52. break;
  53. }
  54. }
  55. }
  56. return node != NULL;
  57. }
  58. /* Obtain a reference to a local port for the given sock,
  59. * if snum is zero it means select any available local port.
  60. */
  61. int inet_csk_get_port(struct inet_hashinfo *hashinfo,
  62. struct sock *sk, unsigned short snum)
  63. {
  64. struct inet_bind_hashbucket *head;
  65. struct hlist_node *node;
  66. struct inet_bind_bucket *tb;
  67. int ret;
  68. local_bh_disable();
  69. if (!snum) {
  70. int low = sysctl_local_port_range[0];
  71. int high = sysctl_local_port_range[1];
  72. int remaining = (high - low) + 1;
  73. int rover;
  74. spin_lock(&hashinfo->portalloc_lock);
  75. if (hashinfo->port_rover < low)
  76. rover = low;
  77. else
  78. rover = hashinfo->port_rover;
  79. do {
  80. rover++;
  81. if (rover > high)
  82. rover = low;
  83. head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
  84. spin_lock(&head->lock);
  85. inet_bind_bucket_for_each(tb, node, &head->chain)
  86. if (tb->port == rover)
  87. goto next;
  88. break;
  89. next:
  90. spin_unlock(&head->lock);
  91. } while (--remaining > 0);
  92. hashinfo->port_rover = rover;
  93. spin_unlock(&hashinfo->portalloc_lock);
  94. /* Exhausted local port range during search? It is not
  95. * possible for us to be holding one of the bind hash
  96. * locks if this test triggers, because if 'remaining'
  97. * drops to zero, we broke out of the do/while loop at
  98. * the top level, not from the 'break;' statement.
  99. */
  100. ret = 1;
  101. if (remaining <= 0)
  102. goto fail;
  103. /* OK, here is the one we will use. HEAD is
  104. * non-NULL and we hold it's mutex.
  105. */
  106. snum = rover;
  107. } else {
  108. head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
  109. spin_lock(&head->lock);
  110. inet_bind_bucket_for_each(tb, node, &head->chain)
  111. if (tb->port == snum)
  112. goto tb_found;
  113. }
  114. tb = NULL;
  115. goto tb_not_found;
  116. tb_found:
  117. if (!hlist_empty(&tb->owners)) {
  118. if (sk->sk_reuse > 1)
  119. goto success;
  120. if (tb->fastreuse > 0 &&
  121. sk->sk_reuse && sk->sk_state != TCP_LISTEN) {
  122. goto success;
  123. } else {
  124. ret = 1;
  125. if (inet_csk_bind_conflict(sk, tb))
  126. goto fail_unlock;
  127. }
  128. }
  129. tb_not_found:
  130. ret = 1;
  131. if (!tb && (tb = inet_bind_bucket_create(hashinfo->bind_bucket_cachep, head, snum)) == NULL)
  132. goto fail_unlock;
  133. if (hlist_empty(&tb->owners)) {
  134. if (sk->sk_reuse && sk->sk_state != TCP_LISTEN)
  135. tb->fastreuse = 1;
  136. else
  137. tb->fastreuse = 0;
  138. } else if (tb->fastreuse &&
  139. (!sk->sk_reuse || sk->sk_state == TCP_LISTEN))
  140. tb->fastreuse = 0;
  141. success:
  142. if (!inet_csk(sk)->icsk_bind_hash)
  143. inet_bind_hash(sk, tb, snum);
  144. BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
  145. ret = 0;
  146. fail_unlock:
  147. spin_unlock(&head->lock);
  148. fail:
  149. local_bh_enable();
  150. return ret;
  151. }
  152. EXPORT_SYMBOL_GPL(inet_csk_get_port);
  153. /*
  154. * Wait for an incoming connection, avoid race conditions. This must be called
  155. * with the socket locked.
  156. */
  157. static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
  158. {
  159. struct inet_connection_sock *icsk = inet_csk(sk);
  160. DEFINE_WAIT(wait);
  161. int err;
  162. /*
  163. * True wake-one mechanism for incoming connections: only
  164. * one process gets woken up, not the 'whole herd'.
  165. * Since we do not 'race & poll' for established sockets
  166. * anymore, the common case will execute the loop only once.
  167. *
  168. * Subtle issue: "add_wait_queue_exclusive()" will be added
  169. * after any current non-exclusive waiters, and we know that
  170. * it will always _stay_ after any new non-exclusive waiters
  171. * because all non-exclusive waiters are added at the
  172. * beginning of the wait-queue. As such, it's ok to "drop"
  173. * our exclusiveness temporarily when we get woken up without
  174. * having to remove and re-insert us on the wait queue.
  175. */
  176. for (;;) {
  177. prepare_to_wait_exclusive(sk->sk_sleep, &wait,
  178. TASK_INTERRUPTIBLE);
  179. release_sock(sk);
  180. if (reqsk_queue_empty(&icsk->icsk_accept_queue))
  181. timeo = schedule_timeout(timeo);
  182. lock_sock(sk);
  183. err = 0;
  184. if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
  185. break;
  186. err = -EINVAL;
  187. if (sk->sk_state != TCP_LISTEN)
  188. break;
  189. err = sock_intr_errno(timeo);
  190. if (signal_pending(current))
  191. break;
  192. err = -EAGAIN;
  193. if (!timeo)
  194. break;
  195. }
  196. finish_wait(sk->sk_sleep, &wait);
  197. return err;
  198. }
  199. /*
  200. * This will accept the next outstanding connection.
  201. */
  202. struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
  203. {
  204. struct inet_connection_sock *icsk = inet_csk(sk);
  205. struct sock *newsk;
  206. int error;
  207. lock_sock(sk);
  208. /* We need to make sure that this socket is listening,
  209. * and that it has something pending.
  210. */
  211. error = -EINVAL;
  212. if (sk->sk_state != TCP_LISTEN)
  213. goto out_err;
  214. /* Find already established connection */
  215. if (reqsk_queue_empty(&icsk->icsk_accept_queue)) {
  216. long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
  217. /* If this is a non blocking socket don't sleep */
  218. error = -EAGAIN;
  219. if (!timeo)
  220. goto out_err;
  221. error = inet_csk_wait_for_connect(sk, timeo);
  222. if (error)
  223. goto out_err;
  224. }
  225. newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);
  226. BUG_TRAP(newsk->sk_state != TCP_SYN_RECV);
  227. out:
  228. release_sock(sk);
  229. return newsk;
  230. out_err:
  231. newsk = NULL;
  232. *err = error;
  233. goto out;
  234. }
  235. EXPORT_SYMBOL(inet_csk_accept);
  236. /*
  237. * Using different timers for retransmit, delayed acks and probes
  238. * We may wish use just one timer maintaining a list of expire jiffies
  239. * to optimize.
  240. */
  241. void inet_csk_init_xmit_timers(struct sock *sk,
  242. void (*retransmit_handler)(unsigned long),
  243. void (*delack_handler)(unsigned long),
  244. void (*keepalive_handler)(unsigned long))
  245. {
  246. struct inet_connection_sock *icsk = inet_csk(sk);
  247. init_timer(&icsk->icsk_retransmit_timer);
  248. init_timer(&icsk->icsk_delack_timer);
  249. init_timer(&sk->sk_timer);
  250. icsk->icsk_retransmit_timer.function = retransmit_handler;
  251. icsk->icsk_delack_timer.function = delack_handler;
  252. sk->sk_timer.function = keepalive_handler;
  253. icsk->icsk_retransmit_timer.data =
  254. icsk->icsk_delack_timer.data =
  255. sk->sk_timer.data = (unsigned long)sk;
  256. icsk->icsk_pending = icsk->icsk_ack.pending = 0;
  257. }
  258. EXPORT_SYMBOL(inet_csk_init_xmit_timers);
  259. void inet_csk_clear_xmit_timers(struct sock *sk)
  260. {
  261. struct inet_connection_sock *icsk = inet_csk(sk);
  262. icsk->icsk_pending = icsk->icsk_ack.pending = icsk->icsk_ack.blocked = 0;
  263. sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
  264. sk_stop_timer(sk, &icsk->icsk_delack_timer);
  265. sk_stop_timer(sk, &sk->sk_timer);
  266. }
  267. EXPORT_SYMBOL(inet_csk_clear_xmit_timers);
  268. void inet_csk_delete_keepalive_timer(struct sock *sk)
  269. {
  270. sk_stop_timer(sk, &sk->sk_timer);
  271. }
  272. EXPORT_SYMBOL(inet_csk_delete_keepalive_timer);
  273. void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
  274. {
  275. sk_reset_timer(sk, &sk->sk_timer, jiffies + len);
  276. }
  277. EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
  278. struct dst_entry* inet_csk_route_req(struct sock *sk,
  279. const struct request_sock *req)
  280. {
  281. struct rtable *rt;
  282. const struct inet_request_sock *ireq = inet_rsk(req);
  283. struct ip_options *opt = inet_rsk(req)->opt;
  284. struct flowi fl = { .oif = sk->sk_bound_dev_if,
  285. .nl_u = { .ip4_u =
  286. { .daddr = ((opt && opt->srr) ?
  287. opt->faddr :
  288. ireq->rmt_addr),
  289. .saddr = ireq->loc_addr,
  290. .tos = RT_CONN_FLAGS(sk) } },
  291. .proto = sk->sk_protocol,
  292. .uli_u = { .ports =
  293. { .sport = inet_sk(sk)->sport,
  294. .dport = ireq->rmt_port } } };
  295. if (ip_route_output_flow(&rt, &fl, sk, 0)) {
  296. IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
  297. return NULL;
  298. }
  299. if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway) {
  300. ip_rt_put(rt);
  301. IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
  302. return NULL;
  303. }
  304. return &rt->u.dst;
  305. }
  306. EXPORT_SYMBOL_GPL(inet_csk_route_req);
  307. static inline u32 inet_synq_hash(const u32 raddr, const u16 rport,
  308. const u32 rnd, const u16 synq_hsize)
  309. {
  310. return jhash_2words(raddr, (u32)rport, rnd) & (synq_hsize - 1);
  311. }
  312. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  313. #define AF_INET_FAMILY(fam) ((fam) == AF_INET)
  314. #else
  315. #define AF_INET_FAMILY(fam) 1
  316. #endif
  317. struct request_sock *inet_csk_search_req(const struct sock *sk,
  318. struct request_sock ***prevp,
  319. const __u16 rport, const __u32 raddr,
  320. const __u32 laddr)
  321. {
  322. const struct inet_connection_sock *icsk = inet_csk(sk);
  323. struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
  324. struct request_sock *req, **prev;
  325. for (prev = &lopt->syn_table[inet_synq_hash(raddr, rport, lopt->hash_rnd,
  326. lopt->nr_table_entries)];
  327. (req = *prev) != NULL;
  328. prev = &req->dl_next) {
  329. const struct inet_request_sock *ireq = inet_rsk(req);
  330. if (ireq->rmt_port == rport &&
  331. ireq->rmt_addr == raddr &&
  332. ireq->loc_addr == laddr &&
  333. AF_INET_FAMILY(req->rsk_ops->family)) {
  334. BUG_TRAP(!req->sk);
  335. *prevp = prev;
  336. break;
  337. }
  338. }
  339. return req;
  340. }
  341. EXPORT_SYMBOL_GPL(inet_csk_search_req);
  342. void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
  343. const unsigned timeout)
  344. {
  345. struct inet_connection_sock *icsk = inet_csk(sk);
  346. struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
  347. const u32 h = inet_synq_hash(inet_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port,
  348. lopt->hash_rnd, lopt->nr_table_entries);
  349. reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, timeout);
  350. inet_csk_reqsk_queue_added(sk, timeout);
  351. }
  352. /* Only thing we need from tcp.h */
  353. extern int sysctl_tcp_synack_retries;
  354. EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_hash_add);
  355. void inet_csk_reqsk_queue_prune(struct sock *parent,
  356. const unsigned long interval,
  357. const unsigned long timeout,
  358. const unsigned long max_rto)
  359. {
  360. struct inet_connection_sock *icsk = inet_csk(parent);
  361. struct request_sock_queue *queue = &icsk->icsk_accept_queue;
  362. struct listen_sock *lopt = queue->listen_opt;
  363. int max_retries = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
  364. int thresh = max_retries;
  365. unsigned long now = jiffies;
  366. struct request_sock **reqp, *req;
  367. int i, budget;
  368. if (lopt == NULL || lopt->qlen == 0)
  369. return;
  370. /* Normally all the openreqs are young and become mature
  371. * (i.e. converted to established socket) for first timeout.
  372. * If synack was not acknowledged for 3 seconds, it means
  373. * one of the following things: synack was lost, ack was lost,
  374. * rtt is high or nobody planned to ack (i.e. synflood).
  375. * When server is a bit loaded, queue is populated with old
  376. * open requests, reducing effective size of queue.
  377. * When server is well loaded, queue size reduces to zero
  378. * after several minutes of work. It is not synflood,
  379. * it is normal operation. The solution is pruning
  380. * too old entries overriding normal timeout, when
  381. * situation becomes dangerous.
  382. *
  383. * Essentially, we reserve half of room for young
  384. * embrions; and abort old ones without pity, if old
  385. * ones are about to clog our table.
  386. */
  387. if (lopt->qlen>>(lopt->max_qlen_log-1)) {
  388. int young = (lopt->qlen_young<<1);
  389. while (thresh > 2) {
  390. if (lopt->qlen < young)
  391. break;
  392. thresh--;
  393. young <<= 1;
  394. }
  395. }
  396. if (queue->rskq_defer_accept)
  397. max_retries = queue->rskq_defer_accept;
  398. budget = 2 * (lopt->nr_table_entries / (timeout / interval));
  399. i = lopt->clock_hand;
  400. do {
  401. reqp=&lopt->syn_table[i];
  402. while ((req = *reqp) != NULL) {
  403. if (time_after_eq(now, req->expires)) {
  404. if ((req->retrans < thresh ||
  405. (inet_rsk(req)->acked && req->retrans < max_retries))
  406. && !req->rsk_ops->rtx_syn_ack(parent, req, NULL)) {
  407. unsigned long timeo;
  408. if (req->retrans++ == 0)
  409. lopt->qlen_young--;
  410. timeo = min((timeout << req->retrans), max_rto);
  411. req->expires = now + timeo;
  412. reqp = &req->dl_next;
  413. continue;
  414. }
  415. /* Drop this request */
  416. inet_csk_reqsk_queue_unlink(parent, req, reqp);
  417. reqsk_queue_removed(queue, req);
  418. reqsk_free(req);
  419. continue;
  420. }
  421. reqp = &req->dl_next;
  422. }
  423. i = (i + 1) & (lopt->nr_table_entries - 1);
  424. } while (--budget > 0);
  425. lopt->clock_hand = i;
  426. if (lopt->qlen)
  427. inet_csk_reset_keepalive_timer(parent, interval);
  428. }
  429. EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_prune);
  430. struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
  431. const unsigned int __nocast priority)
  432. {
  433. struct sock *newsk = sk_clone(sk, priority);
  434. if (newsk != NULL) {
  435. struct inet_connection_sock *newicsk = inet_csk(newsk);
  436. newsk->sk_state = TCP_SYN_RECV;
  437. newicsk->icsk_bind_hash = NULL;
  438. inet_sk(newsk)->dport = inet_rsk(req)->rmt_port;
  439. newsk->sk_write_space = sk_stream_write_space;
  440. newicsk->icsk_retransmits = 0;
  441. newicsk->icsk_backoff = 0;
  442. newicsk->icsk_probes_out = 0;
  443. /* Deinitialize accept_queue to trap illegal accesses. */
  444. memset(&newicsk->icsk_accept_queue, 0, sizeof(newicsk->icsk_accept_queue));
  445. }
  446. return newsk;
  447. }
  448. EXPORT_SYMBOL_GPL(inet_csk_clone);
  449. /*
  450. * At this point, there should be no process reference to this
  451. * socket, and thus no user references at all. Therefore we
  452. * can assume the socket waitqueue is inactive and nobody will
  453. * try to jump onto it.
  454. */
  455. void inet_csk_destroy_sock(struct sock *sk)
  456. {
  457. BUG_TRAP(sk->sk_state == TCP_CLOSE);
  458. BUG_TRAP(sock_flag(sk, SOCK_DEAD));
  459. /* It cannot be in hash table! */
  460. BUG_TRAP(sk_unhashed(sk));
  461. /* If it has not 0 inet_sk(sk)->num, it must be bound */
  462. BUG_TRAP(!inet_sk(sk)->num || inet_csk(sk)->icsk_bind_hash);
  463. sk->sk_prot->destroy(sk);
  464. sk_stream_kill_queues(sk);
  465. xfrm_sk_free_policy(sk);
  466. sk_refcnt_debug_release(sk);
  467. atomic_dec(sk->sk_prot->orphan_count);
  468. sock_put(sk);
  469. }
  470. EXPORT_SYMBOL(inet_csk_destroy_sock);
  471. int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
  472. {
  473. struct inet_sock *inet = inet_sk(sk);
  474. struct inet_connection_sock *icsk = inet_csk(sk);
  475. int rc = reqsk_queue_alloc(&icsk->icsk_accept_queue, nr_table_entries);
  476. if (rc != 0)
  477. return rc;
  478. sk->sk_max_ack_backlog = 0;
  479. sk->sk_ack_backlog = 0;
  480. inet_csk_delack_init(sk);
  481. /* There is race window here: we announce ourselves listening,
  482. * but this transition is still not validated by get_port().
  483. * It is OK, because this socket enters to hash table only
  484. * after validation is complete.
  485. */
  486. sk->sk_state = TCP_LISTEN;
  487. if (!sk->sk_prot->get_port(sk, inet->num)) {
  488. inet->sport = htons(inet->num);
  489. sk_dst_reset(sk);
  490. sk->sk_prot->hash(sk);
  491. return 0;
  492. }
  493. sk->sk_state = TCP_CLOSE;
  494. __reqsk_queue_destroy(&icsk->icsk_accept_queue);
  495. return -EADDRINUSE;
  496. }
  497. EXPORT_SYMBOL_GPL(inet_csk_listen_start);
  498. /*
  499. * This routine closes sockets which have been at least partially
  500. * opened, but not yet accepted.
  501. */
  502. void inet_csk_listen_stop(struct sock *sk)
  503. {
  504. struct inet_connection_sock *icsk = inet_csk(sk);
  505. struct request_sock *acc_req;
  506. struct request_sock *req;
  507. inet_csk_delete_keepalive_timer(sk);
  508. /* make all the listen_opt local to us */
  509. acc_req = reqsk_queue_yank_acceptq(&icsk->icsk_accept_queue);
  510. /* Following specs, it would be better either to send FIN
  511. * (and enter FIN-WAIT-1, it is normal close)
  512. * or to send active reset (abort).
  513. * Certainly, it is pretty dangerous while synflood, but it is
  514. * bad justification for our negligence 8)
  515. * To be honest, we are not able to make either
  516. * of the variants now. --ANK
  517. */
  518. reqsk_queue_destroy(&icsk->icsk_accept_queue);
  519. while ((req = acc_req) != NULL) {
  520. struct sock *child = req->sk;
  521. acc_req = req->dl_next;
  522. local_bh_disable();
  523. bh_lock_sock(child);
  524. BUG_TRAP(!sock_owned_by_user(child));
  525. sock_hold(child);
  526. sk->sk_prot->disconnect(child, O_NONBLOCK);
  527. sock_orphan(child);
  528. atomic_inc(sk->sk_prot->orphan_count);
  529. inet_csk_destroy_sock(child);
  530. bh_unlock_sock(child);
  531. local_bh_enable();
  532. sock_put(child);
  533. sk_acceptq_removed(sk);
  534. __reqsk_free(req);
  535. }
  536. BUG_TRAP(!sk->sk_ack_backlog);
  537. }
  538. EXPORT_SYMBOL_GPL(inet_csk_listen_stop);