tcp_minisocks.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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. * Implementation of the Transmission Control Protocol(TCP).
  7. *
  8. * Version: $Id: tcp_minisocks.c,v 1.15 2002/02/01 22:01:04 davem Exp $
  9. *
  10. * Authors: Ross Biro
  11. * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12. * Mark Evans, <evansmp@uhura.aston.ac.uk>
  13. * Corey Minyard <wf-rch!minyard@relay.EU.net>
  14. * Florian La Roche, <flla@stud.uni-sb.de>
  15. * Charles Hedrick, <hedrick@klinzhai.rutgers.edu>
  16. * Linus Torvalds, <torvalds@cs.helsinki.fi>
  17. * Alan Cox, <gw4pts@gw4pts.ampr.org>
  18. * Matthew Dillon, <dillon@apollo.west.oic.com>
  19. * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
  20. * Jorge Cwik, <jorge@laser.satlink.net>
  21. */
  22. #include <linux/config.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/workqueue.h>
  27. #include <net/tcp.h>
  28. #include <net/inet_common.h>
  29. #include <net/xfrm.h>
  30. #ifdef CONFIG_SYSCTL
  31. #define SYNC_INIT 0 /* let the user enable it */
  32. #else
  33. #define SYNC_INIT 1
  34. #endif
  35. int sysctl_tcp_tw_recycle;
  36. int sysctl_tcp_max_tw_buckets = NR_FILE*2;
  37. int sysctl_tcp_syncookies = SYNC_INIT;
  38. int sysctl_tcp_abort_on_overflow;
  39. static void tcp_tw_schedule(struct inet_timewait_sock *tw, int timeo);
  40. static __inline__ int tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
  41. {
  42. if (seq == s_win)
  43. return 1;
  44. if (after(end_seq, s_win) && before(seq, e_win))
  45. return 1;
  46. return (seq == e_win && seq == end_seq);
  47. }
  48. /* New-style handling of TIME_WAIT sockets. */
  49. int tcp_tw_count;
  50. /* Must be called with locally disabled BHs. */
  51. static void tcp_timewait_kill(struct inet_timewait_sock *tw)
  52. {
  53. struct inet_bind_hashbucket *bhead;
  54. struct inet_bind_bucket *tb;
  55. /* Unlink from established hashes. */
  56. struct inet_ehash_bucket *ehead = &tcp_hashinfo.ehash[tw->tw_hashent];
  57. write_lock(&ehead->lock);
  58. if (hlist_unhashed(&tw->tw_node)) {
  59. write_unlock(&ehead->lock);
  60. return;
  61. }
  62. __hlist_del(&tw->tw_node);
  63. sk_node_init(&tw->tw_node);
  64. write_unlock(&ehead->lock);
  65. /* Disassociate with bind bucket. */
  66. bhead = &tcp_hashinfo.bhash[inet_bhashfn(tw->tw_num, tcp_hashinfo.bhash_size)];
  67. spin_lock(&bhead->lock);
  68. tb = tw->tw_tb;
  69. __hlist_del(&tw->tw_bind_node);
  70. tw->tw_tb = NULL;
  71. inet_bind_bucket_destroy(tcp_hashinfo.bind_bucket_cachep, tb);
  72. spin_unlock(&bhead->lock);
  73. #ifdef SOCK_REFCNT_DEBUG
  74. if (atomic_read(&tw->tw_refcnt) != 1) {
  75. printk(KERN_DEBUG "%s timewait_sock %p refcnt=%d\n",
  76. tw->tw_prot->name, tw, atomic_read(&tw->tw_refcnt));
  77. }
  78. #endif
  79. inet_twsk_put(tw);
  80. }
  81. /*
  82. * * Main purpose of TIME-WAIT state is to close connection gracefully,
  83. * when one of ends sits in LAST-ACK or CLOSING retransmitting FIN
  84. * (and, probably, tail of data) and one or more our ACKs are lost.
  85. * * What is TIME-WAIT timeout? It is associated with maximal packet
  86. * lifetime in the internet, which results in wrong conclusion, that
  87. * it is set to catch "old duplicate segments" wandering out of their path.
  88. * It is not quite correct. This timeout is calculated so that it exceeds
  89. * maximal retransmission timeout enough to allow to lose one (or more)
  90. * segments sent by peer and our ACKs. This time may be calculated from RTO.
  91. * * When TIME-WAIT socket receives RST, it means that another end
  92. * finally closed and we are allowed to kill TIME-WAIT too.
  93. * * Second purpose of TIME-WAIT is catching old duplicate segments.
  94. * Well, certainly it is pure paranoia, but if we load TIME-WAIT
  95. * with this semantics, we MUST NOT kill TIME-WAIT state with RSTs.
  96. * * If we invented some more clever way to catch duplicates
  97. * (f.e. based on PAWS), we could truncate TIME-WAIT to several RTOs.
  98. *
  99. * The algorithm below is based on FORMAL INTERPRETATION of RFCs.
  100. * When you compare it to RFCs, please, read section SEGMENT ARRIVES
  101. * from the very beginning.
  102. *
  103. * NOTE. With recycling (and later with fin-wait-2) TW bucket
  104. * is _not_ stateless. It means, that strictly speaking we must
  105. * spinlock it. I do not want! Well, probability of misbehaviour
  106. * is ridiculously low and, seems, we could use some mb() tricks
  107. * to avoid misread sequence numbers, states etc. --ANK
  108. */
  109. enum tcp_tw_status
  110. tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
  111. const struct tcphdr *th)
  112. {
  113. struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
  114. struct tcp_options_received tmp_opt;
  115. int paws_reject = 0;
  116. tmp_opt.saw_tstamp = 0;
  117. if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
  118. tcp_parse_options(skb, &tmp_opt, 0);
  119. if (tmp_opt.saw_tstamp) {
  120. tmp_opt.ts_recent = tcptw->tw_ts_recent;
  121. tmp_opt.ts_recent_stamp = tcptw->tw_ts_recent_stamp;
  122. paws_reject = tcp_paws_check(&tmp_opt, th->rst);
  123. }
  124. }
  125. if (tw->tw_substate == TCP_FIN_WAIT2) {
  126. /* Just repeat all the checks of tcp_rcv_state_process() */
  127. /* Out of window, send ACK */
  128. if (paws_reject ||
  129. !tcp_in_window(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq,
  130. tcptw->tw_rcv_nxt,
  131. tcptw->tw_rcv_nxt + tcptw->tw_rcv_wnd))
  132. return TCP_TW_ACK;
  133. if (th->rst)
  134. goto kill;
  135. if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt))
  136. goto kill_with_rst;
  137. /* Dup ACK? */
  138. if (!after(TCP_SKB_CB(skb)->end_seq, tcptw->tw_rcv_nxt) ||
  139. TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq) {
  140. inet_twsk_put(tw);
  141. return TCP_TW_SUCCESS;
  142. }
  143. /* New data or FIN. If new data arrive after half-duplex close,
  144. * reset.
  145. */
  146. if (!th->fin ||
  147. TCP_SKB_CB(skb)->end_seq != tcptw->tw_rcv_nxt + 1) {
  148. kill_with_rst:
  149. tcp_tw_deschedule(tw);
  150. inet_twsk_put(tw);
  151. return TCP_TW_RST;
  152. }
  153. /* FIN arrived, enter true time-wait state. */
  154. tw->tw_substate = TCP_TIME_WAIT;
  155. tcptw->tw_rcv_nxt = TCP_SKB_CB(skb)->end_seq;
  156. if (tmp_opt.saw_tstamp) {
  157. tcptw->tw_ts_recent_stamp = xtime.tv_sec;
  158. tcptw->tw_ts_recent = tmp_opt.rcv_tsval;
  159. }
  160. /* I am shamed, but failed to make it more elegant.
  161. * Yes, it is direct reference to IP, which is impossible
  162. * to generalize to IPv6. Taking into account that IPv6
  163. * do not undertsnad recycling in any case, it not
  164. * a big problem in practice. --ANK */
  165. if (tw->tw_family == AF_INET &&
  166. sysctl_tcp_tw_recycle && tcptw->tw_ts_recent_stamp &&
  167. tcp_v4_tw_remember_stamp(tw))
  168. tcp_tw_schedule(tw, tw->tw_timeout);
  169. else
  170. tcp_tw_schedule(tw, TCP_TIMEWAIT_LEN);
  171. return TCP_TW_ACK;
  172. }
  173. /*
  174. * Now real TIME-WAIT state.
  175. *
  176. * RFC 1122:
  177. * "When a connection is [...] on TIME-WAIT state [...]
  178. * [a TCP] MAY accept a new SYN from the remote TCP to
  179. * reopen the connection directly, if it:
  180. *
  181. * (1) assigns its initial sequence number for the new
  182. * connection to be larger than the largest sequence
  183. * number it used on the previous connection incarnation,
  184. * and
  185. *
  186. * (2) returns to TIME-WAIT state if the SYN turns out
  187. * to be an old duplicate".
  188. */
  189. if (!paws_reject &&
  190. (TCP_SKB_CB(skb)->seq == tcptw->tw_rcv_nxt &&
  191. (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq || th->rst))) {
  192. /* In window segment, it may be only reset or bare ack. */
  193. if (th->rst) {
  194. /* This is TIME_WAIT assasination, in two flavors.
  195. * Oh well... nobody has a sufficient solution to this
  196. * protocol bug yet.
  197. */
  198. if (sysctl_tcp_rfc1337 == 0) {
  199. kill:
  200. tcp_tw_deschedule(tw);
  201. inet_twsk_put(tw);
  202. return TCP_TW_SUCCESS;
  203. }
  204. }
  205. tcp_tw_schedule(tw, TCP_TIMEWAIT_LEN);
  206. if (tmp_opt.saw_tstamp) {
  207. tcptw->tw_ts_recent = tmp_opt.rcv_tsval;
  208. tcptw->tw_ts_recent_stamp = xtime.tv_sec;
  209. }
  210. inet_twsk_put(tw);
  211. return TCP_TW_SUCCESS;
  212. }
  213. /* Out of window segment.
  214. All the segments are ACKed immediately.
  215. The only exception is new SYN. We accept it, if it is
  216. not old duplicate and we are not in danger to be killed
  217. by delayed old duplicates. RFC check is that it has
  218. newer sequence number works at rates <40Mbit/sec.
  219. However, if paws works, it is reliable AND even more,
  220. we even may relax silly seq space cutoff.
  221. RED-PEN: we violate main RFC requirement, if this SYN will appear
  222. old duplicate (i.e. we receive RST in reply to SYN-ACK),
  223. we must return socket to time-wait state. It is not good,
  224. but not fatal yet.
  225. */
  226. if (th->syn && !th->rst && !th->ack && !paws_reject &&
  227. (after(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt) ||
  228. (tmp_opt.saw_tstamp &&
  229. (s32)(tcptw->tw_ts_recent - tmp_opt.rcv_tsval) < 0))) {
  230. u32 isn = tcptw->tw_snd_nxt + 65535 + 2;
  231. if (isn == 0)
  232. isn++;
  233. TCP_SKB_CB(skb)->when = isn;
  234. return TCP_TW_SYN;
  235. }
  236. if (paws_reject)
  237. NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED);
  238. if(!th->rst) {
  239. /* In this case we must reset the TIMEWAIT timer.
  240. *
  241. * If it is ACKless SYN it may be both old duplicate
  242. * and new good SYN with random sequence number <rcv_nxt.
  243. * Do not reschedule in the last case.
  244. */
  245. if (paws_reject || th->ack)
  246. tcp_tw_schedule(tw, TCP_TIMEWAIT_LEN);
  247. /* Send ACK. Note, we do not put the bucket,
  248. * it will be released by caller.
  249. */
  250. return TCP_TW_ACK;
  251. }
  252. inet_twsk_put(tw);
  253. return TCP_TW_SUCCESS;
  254. }
  255. /* Enter the time wait state. This is called with locally disabled BH.
  256. * Essentially we whip up a timewait bucket, copy the
  257. * relevant info into it from the SK, and mess with hash chains
  258. * and list linkage.
  259. */
  260. static void __tcp_tw_hashdance(struct sock *sk, struct inet_timewait_sock *tw)
  261. {
  262. const struct inet_sock *inet = inet_sk(sk);
  263. struct inet_ehash_bucket *ehead = &tcp_hashinfo.ehash[sk->sk_hashent];
  264. struct inet_bind_hashbucket *bhead;
  265. /* Step 1: Put TW into bind hash. Original socket stays there too.
  266. Note, that any socket with inet->num != 0 MUST be bound in
  267. binding cache, even if it is closed.
  268. */
  269. bhead = &tcp_hashinfo.bhash[inet_bhashfn(inet->num, tcp_hashinfo.bhash_size)];
  270. spin_lock(&bhead->lock);
  271. tw->tw_tb = inet->bind_hash;
  272. BUG_TRAP(inet->bind_hash);
  273. inet_twsk_add_bind_node(tw, &tw->tw_tb->owners);
  274. spin_unlock(&bhead->lock);
  275. write_lock(&ehead->lock);
  276. /* Step 2: Remove SK from established hash. */
  277. if (__sk_del_node_init(sk))
  278. sock_prot_dec_use(sk->sk_prot);
  279. /* Step 3: Hash TW into TIMEWAIT half of established hash table. */
  280. inet_twsk_add_node(tw, &(ehead + tcp_hashinfo.ehash_size)->chain);
  281. atomic_inc(&tw->tw_refcnt);
  282. write_unlock(&ehead->lock);
  283. }
  284. /*
  285. * Move a socket to time-wait or dead fin-wait-2 state.
  286. */
  287. void tcp_time_wait(struct sock *sk, int state, int timeo)
  288. {
  289. struct inet_timewait_sock *tw = NULL;
  290. const struct tcp_sock *tp = tcp_sk(sk);
  291. int recycle_ok = 0;
  292. if (sysctl_tcp_tw_recycle && tp->rx_opt.ts_recent_stamp)
  293. recycle_ok = tp->af_specific->remember_stamp(sk);
  294. if (tcp_tw_count < sysctl_tcp_max_tw_buckets)
  295. tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_slab, SLAB_ATOMIC);
  296. if (tw != NULL) {
  297. struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
  298. const struct inet_sock *inet = inet_sk(sk);
  299. const int rto = (tp->rto << 2) - (tp->rto >> 1);
  300. /* Remember our protocol */
  301. tw->tw_prot = sk->sk_prot_creator;
  302. /* Give us an identity. */
  303. tw->tw_daddr = inet->daddr;
  304. tw->tw_rcv_saddr = inet->rcv_saddr;
  305. tw->tw_bound_dev_if = sk->sk_bound_dev_if;
  306. tw->tw_num = inet->num;
  307. tw->tw_state = TCP_TIME_WAIT;
  308. tw->tw_substate = state;
  309. tw->tw_sport = inet->sport;
  310. tw->tw_dport = inet->dport;
  311. tw->tw_family = sk->sk_family;
  312. tw->tw_reuse = sk->sk_reuse;
  313. tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale;
  314. atomic_set(&tw->tw_refcnt, 1);
  315. tw->tw_hashent = sk->sk_hashent;
  316. tcptw->tw_rcv_nxt = tp->rcv_nxt;
  317. tcptw->tw_snd_nxt = tp->snd_nxt;
  318. tcptw->tw_rcv_wnd = tcp_receive_window(tp);
  319. tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
  320. tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
  321. inet_twsk_dead_node_init(tw);
  322. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  323. if (tw->tw_family == PF_INET6) {
  324. struct ipv6_pinfo *np = inet6_sk(sk);
  325. struct tcp6_timewait_sock *tcp6tw = tcp6_twsk((struct sock *)tw);
  326. ipv6_addr_copy(&tcp6tw->tw_v6_daddr, &np->daddr);
  327. ipv6_addr_copy(&tcp6tw->tw_v6_rcv_saddr, &np->rcv_saddr);
  328. tw->tw_ipv6only = np->ipv6only;
  329. } else
  330. tw->tw_ipv6only = 0;
  331. #endif
  332. /* Linkage updates. */
  333. __tcp_tw_hashdance(sk, tw);
  334. /* Get the TIME_WAIT timeout firing. */
  335. if (timeo < rto)
  336. timeo = rto;
  337. if (recycle_ok) {
  338. tw->tw_timeout = rto;
  339. } else {
  340. tw->tw_timeout = TCP_TIMEWAIT_LEN;
  341. if (state == TCP_TIME_WAIT)
  342. timeo = TCP_TIMEWAIT_LEN;
  343. }
  344. tcp_tw_schedule(tw, timeo);
  345. inet_twsk_put(tw);
  346. } else {
  347. /* Sorry, if we're out of memory, just CLOSE this
  348. * socket up. We've got bigger problems than
  349. * non-graceful socket closings.
  350. */
  351. if (net_ratelimit())
  352. printk(KERN_INFO "TCP: time wait bucket table overflow\n");
  353. }
  354. tcp_update_metrics(sk);
  355. tcp_done(sk);
  356. }
  357. /* Kill off TIME_WAIT sockets once their lifetime has expired. */
  358. static int tcp_tw_death_row_slot;
  359. static void tcp_twkill(unsigned long);
  360. /* TIME_WAIT reaping mechanism. */
  361. #define TCP_TWKILL_SLOTS 8 /* Please keep this a power of 2. */
  362. #define TCP_TWKILL_PERIOD (TCP_TIMEWAIT_LEN/TCP_TWKILL_SLOTS)
  363. #define TCP_TWKILL_QUOTA 100
  364. static struct hlist_head tcp_tw_death_row[TCP_TWKILL_SLOTS];
  365. static DEFINE_SPINLOCK(tw_death_lock);
  366. static struct timer_list tcp_tw_timer = TIMER_INITIALIZER(tcp_twkill, 0, 0);
  367. static void twkill_work(void *);
  368. static DECLARE_WORK(tcp_twkill_work, twkill_work, NULL);
  369. static u32 twkill_thread_slots;
  370. /* Returns non-zero if quota exceeded. */
  371. static int tcp_do_twkill_work(int slot, unsigned int quota)
  372. {
  373. struct inet_timewait_sock *tw;
  374. struct hlist_node *node;
  375. unsigned int killed;
  376. int ret;
  377. /* NOTE: compare this to previous version where lock
  378. * was released after detaching chain. It was racy,
  379. * because tw buckets are scheduled in not serialized context
  380. * in 2.3 (with netfilter), and with softnet it is common, because
  381. * soft irqs are not sequenced.
  382. */
  383. killed = 0;
  384. ret = 0;
  385. rescan:
  386. inet_twsk_for_each_inmate(tw, node, &tcp_tw_death_row[slot]) {
  387. __inet_twsk_del_dead_node(tw);
  388. spin_unlock(&tw_death_lock);
  389. tcp_timewait_kill(tw);
  390. inet_twsk_put(tw);
  391. killed++;
  392. spin_lock(&tw_death_lock);
  393. if (killed > quota) {
  394. ret = 1;
  395. break;
  396. }
  397. /* While we dropped tw_death_lock, another cpu may have
  398. * killed off the next TW bucket in the list, therefore
  399. * do a fresh re-read of the hlist head node with the
  400. * lock reacquired. We still use the hlist traversal
  401. * macro in order to get the prefetches.
  402. */
  403. goto rescan;
  404. }
  405. tcp_tw_count -= killed;
  406. NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITED, killed);
  407. return ret;
  408. }
  409. static void tcp_twkill(unsigned long dummy)
  410. {
  411. int need_timer, ret;
  412. spin_lock(&tw_death_lock);
  413. if (tcp_tw_count == 0)
  414. goto out;
  415. need_timer = 0;
  416. ret = tcp_do_twkill_work(tcp_tw_death_row_slot, TCP_TWKILL_QUOTA);
  417. if (ret) {
  418. twkill_thread_slots |= (1 << tcp_tw_death_row_slot);
  419. mb();
  420. schedule_work(&tcp_twkill_work);
  421. need_timer = 1;
  422. } else {
  423. /* We purged the entire slot, anything left? */
  424. if (tcp_tw_count)
  425. need_timer = 1;
  426. }
  427. tcp_tw_death_row_slot =
  428. ((tcp_tw_death_row_slot + 1) & (TCP_TWKILL_SLOTS - 1));
  429. if (need_timer)
  430. mod_timer(&tcp_tw_timer, jiffies + TCP_TWKILL_PERIOD);
  431. out:
  432. spin_unlock(&tw_death_lock);
  433. }
  434. extern void twkill_slots_invalid(void);
  435. static void twkill_work(void *dummy)
  436. {
  437. int i;
  438. if ((TCP_TWKILL_SLOTS - 1) > (sizeof(twkill_thread_slots) * 8))
  439. twkill_slots_invalid();
  440. while (twkill_thread_slots) {
  441. spin_lock_bh(&tw_death_lock);
  442. for (i = 0; i < TCP_TWKILL_SLOTS; i++) {
  443. if (!(twkill_thread_slots & (1 << i)))
  444. continue;
  445. while (tcp_do_twkill_work(i, TCP_TWKILL_QUOTA) != 0) {
  446. if (need_resched()) {
  447. spin_unlock_bh(&tw_death_lock);
  448. schedule();
  449. spin_lock_bh(&tw_death_lock);
  450. }
  451. }
  452. twkill_thread_slots &= ~(1 << i);
  453. }
  454. spin_unlock_bh(&tw_death_lock);
  455. }
  456. }
  457. /* These are always called from BH context. See callers in
  458. * tcp_input.c to verify this.
  459. */
  460. /* This is for handling early-kills of TIME_WAIT sockets. */
  461. void tcp_tw_deschedule(struct inet_timewait_sock *tw)
  462. {
  463. spin_lock(&tw_death_lock);
  464. if (inet_twsk_del_dead_node(tw)) {
  465. inet_twsk_put(tw);
  466. if (--tcp_tw_count == 0)
  467. del_timer(&tcp_tw_timer);
  468. }
  469. spin_unlock(&tw_death_lock);
  470. tcp_timewait_kill(tw);
  471. }
  472. /* Short-time timewait calendar */
  473. static int tcp_twcal_hand = -1;
  474. static int tcp_twcal_jiffie;
  475. static void tcp_twcal_tick(unsigned long);
  476. static struct timer_list tcp_twcal_timer =
  477. TIMER_INITIALIZER(tcp_twcal_tick, 0, 0);
  478. static struct hlist_head tcp_twcal_row[TCP_TW_RECYCLE_SLOTS];
  479. static void tcp_tw_schedule(struct inet_timewait_sock *tw, const int timeo)
  480. {
  481. struct hlist_head *list;
  482. int slot;
  483. /* timeout := RTO * 3.5
  484. *
  485. * 3.5 = 1+2+0.5 to wait for two retransmits.
  486. *
  487. * RATIONALE: if FIN arrived and we entered TIME-WAIT state,
  488. * our ACK acking that FIN can be lost. If N subsequent retransmitted
  489. * FINs (or previous seqments) are lost (probability of such event
  490. * is p^(N+1), where p is probability to lose single packet and
  491. * time to detect the loss is about RTO*(2^N - 1) with exponential
  492. * backoff). Normal timewait length is calculated so, that we
  493. * waited at least for one retransmitted FIN (maximal RTO is 120sec).
  494. * [ BTW Linux. following BSD, violates this requirement waiting
  495. * only for 60sec, we should wait at least for 240 secs.
  496. * Well, 240 consumes too much of resources 8)
  497. * ]
  498. * This interval is not reduced to catch old duplicate and
  499. * responces to our wandering segments living for two MSLs.
  500. * However, if we use PAWS to detect
  501. * old duplicates, we can reduce the interval to bounds required
  502. * by RTO, rather than MSL. So, if peer understands PAWS, we
  503. * kill tw bucket after 3.5*RTO (it is important that this number
  504. * is greater than TS tick!) and detect old duplicates with help
  505. * of PAWS.
  506. */
  507. slot = (timeo + (1<<TCP_TW_RECYCLE_TICK) - 1) >> TCP_TW_RECYCLE_TICK;
  508. spin_lock(&tw_death_lock);
  509. /* Unlink it, if it was scheduled */
  510. if (inet_twsk_del_dead_node(tw))
  511. tcp_tw_count--;
  512. else
  513. atomic_inc(&tw->tw_refcnt);
  514. if (slot >= TCP_TW_RECYCLE_SLOTS) {
  515. /* Schedule to slow timer */
  516. if (timeo >= TCP_TIMEWAIT_LEN) {
  517. slot = TCP_TWKILL_SLOTS-1;
  518. } else {
  519. slot = (timeo + TCP_TWKILL_PERIOD-1) / TCP_TWKILL_PERIOD;
  520. if (slot >= TCP_TWKILL_SLOTS)
  521. slot = TCP_TWKILL_SLOTS-1;
  522. }
  523. tw->tw_ttd = jiffies + timeo;
  524. slot = (tcp_tw_death_row_slot + slot) & (TCP_TWKILL_SLOTS - 1);
  525. list = &tcp_tw_death_row[slot];
  526. } else {
  527. tw->tw_ttd = jiffies + (slot << TCP_TW_RECYCLE_TICK);
  528. if (tcp_twcal_hand < 0) {
  529. tcp_twcal_hand = 0;
  530. tcp_twcal_jiffie = jiffies;
  531. tcp_twcal_timer.expires = tcp_twcal_jiffie + (slot<<TCP_TW_RECYCLE_TICK);
  532. add_timer(&tcp_twcal_timer);
  533. } else {
  534. if (time_after(tcp_twcal_timer.expires, jiffies + (slot<<TCP_TW_RECYCLE_TICK)))
  535. mod_timer(&tcp_twcal_timer, jiffies + (slot<<TCP_TW_RECYCLE_TICK));
  536. slot = (tcp_twcal_hand + slot)&(TCP_TW_RECYCLE_SLOTS-1);
  537. }
  538. list = &tcp_twcal_row[slot];
  539. }
  540. hlist_add_head(&tw->tw_death_node, list);
  541. if (tcp_tw_count++ == 0)
  542. mod_timer(&tcp_tw_timer, jiffies+TCP_TWKILL_PERIOD);
  543. spin_unlock(&tw_death_lock);
  544. }
  545. void tcp_twcal_tick(unsigned long dummy)
  546. {
  547. int n, slot;
  548. unsigned long j;
  549. unsigned long now = jiffies;
  550. int killed = 0;
  551. int adv = 0;
  552. spin_lock(&tw_death_lock);
  553. if (tcp_twcal_hand < 0)
  554. goto out;
  555. slot = tcp_twcal_hand;
  556. j = tcp_twcal_jiffie;
  557. for (n=0; n<TCP_TW_RECYCLE_SLOTS; n++) {
  558. if (time_before_eq(j, now)) {
  559. struct hlist_node *node, *safe;
  560. struct inet_timewait_sock *tw;
  561. inet_twsk_for_each_inmate_safe(tw, node, safe,
  562. &tcp_twcal_row[slot]) {
  563. __inet_twsk_del_dead_node(tw);
  564. tcp_timewait_kill(tw);
  565. inet_twsk_put(tw);
  566. killed++;
  567. }
  568. } else {
  569. if (!adv) {
  570. adv = 1;
  571. tcp_twcal_jiffie = j;
  572. tcp_twcal_hand = slot;
  573. }
  574. if (!hlist_empty(&tcp_twcal_row[slot])) {
  575. mod_timer(&tcp_twcal_timer, j);
  576. goto out;
  577. }
  578. }
  579. j += (1<<TCP_TW_RECYCLE_TICK);
  580. slot = (slot+1)&(TCP_TW_RECYCLE_SLOTS-1);
  581. }
  582. tcp_twcal_hand = -1;
  583. out:
  584. if ((tcp_tw_count -= killed) == 0)
  585. del_timer(&tcp_tw_timer);
  586. NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITKILLED, killed);
  587. spin_unlock(&tw_death_lock);
  588. }
  589. /* This is not only more efficient than what we used to do, it eliminates
  590. * a lot of code duplication between IPv4/IPv6 SYN recv processing. -DaveM
  591. *
  592. * Actually, we could lots of memory writes here. tp of listening
  593. * socket contains all necessary default parameters.
  594. */
  595. struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req, struct sk_buff *skb)
  596. {
  597. /* allocate the newsk from the same slab of the master sock,
  598. * if not, at sk_free time we'll try to free it from the wrong
  599. * slabcache (i.e. is it TCPv4 or v6?), this is handled thru sk->sk_prot -acme */
  600. struct sock *newsk = sk_alloc(PF_INET, GFP_ATOMIC, sk->sk_prot, 0);
  601. if(newsk != NULL) {
  602. struct inet_request_sock *ireq = inet_rsk(req);
  603. struct tcp_request_sock *treq = tcp_rsk(req);
  604. struct inet_sock *newinet = inet_sk(newsk);
  605. struct tcp_sock *newtp;
  606. struct sk_filter *filter;
  607. memcpy(newsk, sk, sizeof(struct tcp_sock));
  608. newsk->sk_state = TCP_SYN_RECV;
  609. /* SANITY */
  610. sk_node_init(&newsk->sk_node);
  611. newinet->bind_hash = NULL;
  612. /* Clone the TCP header template */
  613. newinet->dport = ireq->rmt_port;
  614. sock_lock_init(newsk);
  615. bh_lock_sock(newsk);
  616. rwlock_init(&newsk->sk_dst_lock);
  617. newsk->sk_dst_cache = NULL;
  618. atomic_set(&newsk->sk_rmem_alloc, 0);
  619. skb_queue_head_init(&newsk->sk_receive_queue);
  620. atomic_set(&newsk->sk_wmem_alloc, 0);
  621. skb_queue_head_init(&newsk->sk_write_queue);
  622. atomic_set(&newsk->sk_omem_alloc, 0);
  623. newsk->sk_wmem_queued = 0;
  624. newsk->sk_forward_alloc = 0;
  625. sock_reset_flag(newsk, SOCK_DONE);
  626. newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK;
  627. newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
  628. newsk->sk_send_head = NULL;
  629. rwlock_init(&newsk->sk_callback_lock);
  630. skb_queue_head_init(&newsk->sk_error_queue);
  631. newsk->sk_write_space = sk_stream_write_space;
  632. if ((filter = newsk->sk_filter) != NULL)
  633. sk_filter_charge(newsk, filter);
  634. if (unlikely(xfrm_sk_clone_policy(newsk))) {
  635. /* It is still raw copy of parent, so invalidate
  636. * destructor and make plain sk_free() */
  637. newsk->sk_destruct = NULL;
  638. sk_free(newsk);
  639. return NULL;
  640. }
  641. /* Now setup tcp_sock */
  642. newtp = tcp_sk(newsk);
  643. newtp->pred_flags = 0;
  644. newtp->rcv_nxt = treq->rcv_isn + 1;
  645. newtp->snd_nxt = treq->snt_isn + 1;
  646. newtp->snd_una = treq->snt_isn + 1;
  647. newtp->snd_sml = treq->snt_isn + 1;
  648. tcp_prequeue_init(newtp);
  649. tcp_init_wl(newtp, treq->snt_isn, treq->rcv_isn);
  650. newtp->retransmits = 0;
  651. newtp->backoff = 0;
  652. newtp->srtt = 0;
  653. newtp->mdev = TCP_TIMEOUT_INIT;
  654. newtp->rto = TCP_TIMEOUT_INIT;
  655. newtp->packets_out = 0;
  656. newtp->left_out = 0;
  657. newtp->retrans_out = 0;
  658. newtp->sacked_out = 0;
  659. newtp->fackets_out = 0;
  660. newtp->snd_ssthresh = 0x7fffffff;
  661. /* So many TCP implementations out there (incorrectly) count the
  662. * initial SYN frame in their delayed-ACK and congestion control
  663. * algorithms that we must have the following bandaid to talk
  664. * efficiently to them. -DaveM
  665. */
  666. newtp->snd_cwnd = 2;
  667. newtp->snd_cwnd_cnt = 0;
  668. newtp->frto_counter = 0;
  669. newtp->frto_highmark = 0;
  670. newtp->ca_ops = &tcp_reno;
  671. tcp_set_ca_state(newtp, TCP_CA_Open);
  672. tcp_init_xmit_timers(newsk);
  673. skb_queue_head_init(&newtp->out_of_order_queue);
  674. newtp->rcv_wup = treq->rcv_isn + 1;
  675. newtp->write_seq = treq->snt_isn + 1;
  676. newtp->pushed_seq = newtp->write_seq;
  677. newtp->copied_seq = treq->rcv_isn + 1;
  678. newtp->rx_opt.saw_tstamp = 0;
  679. newtp->rx_opt.dsack = 0;
  680. newtp->rx_opt.eff_sacks = 0;
  681. newtp->probes_out = 0;
  682. newtp->rx_opt.num_sacks = 0;
  683. newtp->urg_data = 0;
  684. /* Deinitialize accept_queue to trap illegal accesses. */
  685. memset(&newtp->accept_queue, 0, sizeof(newtp->accept_queue));
  686. /* Back to base struct sock members. */
  687. newsk->sk_err = 0;
  688. newsk->sk_priority = 0;
  689. atomic_set(&newsk->sk_refcnt, 2);
  690. /*
  691. * Increment the counter in the same struct proto as the master
  692. * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
  693. * is the same as sk->sk_prot->socks, as this field was copied
  694. * with memcpy), same rationale as the first comment in this
  695. * function.
  696. *
  697. * This _changes_ the previous behaviour, where
  698. * tcp_create_openreq_child always was incrementing the
  699. * equivalent to tcp_prot->socks (inet_sock_nr), so this have
  700. * to be taken into account in all callers. -acme
  701. */
  702. sk_refcnt_debug_inc(newsk);
  703. atomic_inc(&tcp_sockets_allocated);
  704. if (sock_flag(newsk, SOCK_KEEPOPEN))
  705. tcp_reset_keepalive_timer(newsk,
  706. keepalive_time_when(newtp));
  707. newsk->sk_socket = NULL;
  708. newsk->sk_sleep = NULL;
  709. newtp->rx_opt.tstamp_ok = ireq->tstamp_ok;
  710. if((newtp->rx_opt.sack_ok = ireq->sack_ok) != 0) {
  711. if (sysctl_tcp_fack)
  712. newtp->rx_opt.sack_ok |= 2;
  713. }
  714. newtp->window_clamp = req->window_clamp;
  715. newtp->rcv_ssthresh = req->rcv_wnd;
  716. newtp->rcv_wnd = req->rcv_wnd;
  717. newtp->rx_opt.wscale_ok = ireq->wscale_ok;
  718. if (newtp->rx_opt.wscale_ok) {
  719. newtp->rx_opt.snd_wscale = ireq->snd_wscale;
  720. newtp->rx_opt.rcv_wscale = ireq->rcv_wscale;
  721. } else {
  722. newtp->rx_opt.snd_wscale = newtp->rx_opt.rcv_wscale = 0;
  723. newtp->window_clamp = min(newtp->window_clamp, 65535U);
  724. }
  725. newtp->snd_wnd = ntohs(skb->h.th->window) << newtp->rx_opt.snd_wscale;
  726. newtp->max_window = newtp->snd_wnd;
  727. if (newtp->rx_opt.tstamp_ok) {
  728. newtp->rx_opt.ts_recent = req->ts_recent;
  729. newtp->rx_opt.ts_recent_stamp = xtime.tv_sec;
  730. newtp->tcp_header_len = sizeof(struct tcphdr) + TCPOLEN_TSTAMP_ALIGNED;
  731. } else {
  732. newtp->rx_opt.ts_recent_stamp = 0;
  733. newtp->tcp_header_len = sizeof(struct tcphdr);
  734. }
  735. if (skb->len >= TCP_MIN_RCVMSS+newtp->tcp_header_len)
  736. newtp->ack.last_seg_size = skb->len-newtp->tcp_header_len;
  737. newtp->rx_opt.mss_clamp = req->mss;
  738. TCP_ECN_openreq_child(newtp, req);
  739. if (newtp->ecn_flags&TCP_ECN_OK)
  740. sock_set_flag(newsk, SOCK_NO_LARGESEND);
  741. TCP_INC_STATS_BH(TCP_MIB_PASSIVEOPENS);
  742. }
  743. return newsk;
  744. }
  745. /*
  746. * Process an incoming packet for SYN_RECV sockets represented
  747. * as a request_sock.
  748. */
  749. struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb,
  750. struct request_sock *req,
  751. struct request_sock **prev)
  752. {
  753. struct tcphdr *th = skb->h.th;
  754. struct tcp_sock *tp = tcp_sk(sk);
  755. u32 flg = tcp_flag_word(th) & (TCP_FLAG_RST|TCP_FLAG_SYN|TCP_FLAG_ACK);
  756. int paws_reject = 0;
  757. struct tcp_options_received tmp_opt;
  758. struct sock *child;
  759. tmp_opt.saw_tstamp = 0;
  760. if (th->doff > (sizeof(struct tcphdr)>>2)) {
  761. tcp_parse_options(skb, &tmp_opt, 0);
  762. if (tmp_opt.saw_tstamp) {
  763. tmp_opt.ts_recent = req->ts_recent;
  764. /* We do not store true stamp, but it is not required,
  765. * it can be estimated (approximately)
  766. * from another data.
  767. */
  768. tmp_opt.ts_recent_stamp = xtime.tv_sec - ((TCP_TIMEOUT_INIT/HZ)<<req->retrans);
  769. paws_reject = tcp_paws_check(&tmp_opt, th->rst);
  770. }
  771. }
  772. /* Check for pure retransmitted SYN. */
  773. if (TCP_SKB_CB(skb)->seq == tcp_rsk(req)->rcv_isn &&
  774. flg == TCP_FLAG_SYN &&
  775. !paws_reject) {
  776. /*
  777. * RFC793 draws (Incorrectly! It was fixed in RFC1122)
  778. * this case on figure 6 and figure 8, but formal
  779. * protocol description says NOTHING.
  780. * To be more exact, it says that we should send ACK,
  781. * because this segment (at least, if it has no data)
  782. * is out of window.
  783. *
  784. * CONCLUSION: RFC793 (even with RFC1122) DOES NOT
  785. * describe SYN-RECV state. All the description
  786. * is wrong, we cannot believe to it and should
  787. * rely only on common sense and implementation
  788. * experience.
  789. *
  790. * Enforce "SYN-ACK" according to figure 8, figure 6
  791. * of RFC793, fixed by RFC1122.
  792. */
  793. req->rsk_ops->rtx_syn_ack(sk, req, NULL);
  794. return NULL;
  795. }
  796. /* Further reproduces section "SEGMENT ARRIVES"
  797. for state SYN-RECEIVED of RFC793.
  798. It is broken, however, it does not work only
  799. when SYNs are crossed.
  800. You would think that SYN crossing is impossible here, since
  801. we should have a SYN_SENT socket (from connect()) on our end,
  802. but this is not true if the crossed SYNs were sent to both
  803. ends by a malicious third party. We must defend against this,
  804. and to do that we first verify the ACK (as per RFC793, page
  805. 36) and reset if it is invalid. Is this a true full defense?
  806. To convince ourselves, let us consider a way in which the ACK
  807. test can still pass in this 'malicious crossed SYNs' case.
  808. Malicious sender sends identical SYNs (and thus identical sequence
  809. numbers) to both A and B:
  810. A: gets SYN, seq=7
  811. B: gets SYN, seq=7
  812. By our good fortune, both A and B select the same initial
  813. send sequence number of seven :-)
  814. A: sends SYN|ACK, seq=7, ack_seq=8
  815. B: sends SYN|ACK, seq=7, ack_seq=8
  816. So we are now A eating this SYN|ACK, ACK test passes. So
  817. does sequence test, SYN is truncated, and thus we consider
  818. it a bare ACK.
  819. If tp->defer_accept, we silently drop this bare ACK. Otherwise,
  820. we create an established connection. Both ends (listening sockets)
  821. accept the new incoming connection and try to talk to each other. 8-)
  822. Note: This case is both harmless, and rare. Possibility is about the
  823. same as us discovering intelligent life on another plant tomorrow.
  824. But generally, we should (RFC lies!) to accept ACK
  825. from SYNACK both here and in tcp_rcv_state_process().
  826. tcp_rcv_state_process() does not, hence, we do not too.
  827. Note that the case is absolutely generic:
  828. we cannot optimize anything here without
  829. violating protocol. All the checks must be made
  830. before attempt to create socket.
  831. */
  832. /* RFC793 page 36: "If the connection is in any non-synchronized state ...
  833. * and the incoming segment acknowledges something not yet
  834. * sent (the segment carries an unaccaptable ACK) ...
  835. * a reset is sent."
  836. *
  837. * Invalid ACK: reset will be sent by listening socket
  838. */
  839. if ((flg & TCP_FLAG_ACK) &&
  840. (TCP_SKB_CB(skb)->ack_seq != tcp_rsk(req)->snt_isn + 1))
  841. return sk;
  842. /* Also, it would be not so bad idea to check rcv_tsecr, which
  843. * is essentially ACK extension and too early or too late values
  844. * should cause reset in unsynchronized states.
  845. */
  846. /* RFC793: "first check sequence number". */
  847. if (paws_reject || !tcp_in_window(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq,
  848. tcp_rsk(req)->rcv_isn + 1, tcp_rsk(req)->rcv_isn + 1 + req->rcv_wnd)) {
  849. /* Out of window: send ACK and drop. */
  850. if (!(flg & TCP_FLAG_RST))
  851. req->rsk_ops->send_ack(skb, req);
  852. if (paws_reject)
  853. NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED);
  854. return NULL;
  855. }
  856. /* In sequence, PAWS is OK. */
  857. if (tmp_opt.saw_tstamp && !after(TCP_SKB_CB(skb)->seq, tcp_rsk(req)->rcv_isn + 1))
  858. req->ts_recent = tmp_opt.rcv_tsval;
  859. if (TCP_SKB_CB(skb)->seq == tcp_rsk(req)->rcv_isn) {
  860. /* Truncate SYN, it is out of window starting
  861. at tcp_rsk(req)->rcv_isn + 1. */
  862. flg &= ~TCP_FLAG_SYN;
  863. }
  864. /* RFC793: "second check the RST bit" and
  865. * "fourth, check the SYN bit"
  866. */
  867. if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN))
  868. goto embryonic_reset;
  869. /* ACK sequence verified above, just make sure ACK is
  870. * set. If ACK not set, just silently drop the packet.
  871. */
  872. if (!(flg & TCP_FLAG_ACK))
  873. return NULL;
  874. /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */
  875. if (tp->defer_accept && TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) {
  876. inet_rsk(req)->acked = 1;
  877. return NULL;
  878. }
  879. /* OK, ACK is valid, create big socket and
  880. * feed this segment to it. It will repeat all
  881. * the tests. THIS SEGMENT MUST MOVE SOCKET TO
  882. * ESTABLISHED STATE. If it will be dropped after
  883. * socket is created, wait for troubles.
  884. */
  885. child = tp->af_specific->syn_recv_sock(sk, skb, req, NULL);
  886. if (child == NULL)
  887. goto listen_overflow;
  888. tcp_synq_unlink(tp, req, prev);
  889. tcp_synq_removed(sk, req);
  890. tcp_acceptq_queue(sk, req, child);
  891. return child;
  892. listen_overflow:
  893. if (!sysctl_tcp_abort_on_overflow) {
  894. inet_rsk(req)->acked = 1;
  895. return NULL;
  896. }
  897. embryonic_reset:
  898. NET_INC_STATS_BH(LINUX_MIB_EMBRYONICRSTS);
  899. if (!(flg & TCP_FLAG_RST))
  900. req->rsk_ops->send_reset(skb);
  901. tcp_synq_drop(sk, req, prev);
  902. return NULL;
  903. }
  904. /*
  905. * Queue segment on the new socket if the new socket is active,
  906. * otherwise we just shortcircuit this and continue with
  907. * the new socket.
  908. */
  909. int tcp_child_process(struct sock *parent, struct sock *child,
  910. struct sk_buff *skb)
  911. {
  912. int ret = 0;
  913. int state = child->sk_state;
  914. if (!sock_owned_by_user(child)) {
  915. ret = tcp_rcv_state_process(child, skb, skb->h.th, skb->len);
  916. /* Wakeup parent, send SIGIO */
  917. if (state == TCP_SYN_RECV && child->sk_state != state)
  918. parent->sk_data_ready(parent, 0);
  919. } else {
  920. /* Alas, it is possible again, because we do lookup
  921. * in main socket hash table and lock on listening
  922. * socket does not protect us more.
  923. */
  924. sk_add_backlog(child, skb);
  925. }
  926. bh_unlock_sock(child);
  927. sock_put(child);
  928. return ret;
  929. }
  930. EXPORT_SYMBOL(tcp_check_req);
  931. EXPORT_SYMBOL(tcp_child_process);
  932. EXPORT_SYMBOL(tcp_create_openreq_child);
  933. EXPORT_SYMBOL(tcp_timewait_state_process);
  934. EXPORT_SYMBOL(tcp_tw_deschedule);