11 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
30 if (hlist_nulls_unhashed(&tw->tw_node))
33 hlist_nulls_del_rcu(&tw->tw_node);
34 sk_nulls_node_init(&tw->tw_node);
59 __hlist_del(&tw->tw_bind_node);
83 bhead = &hashinfo->
bhash[inet_bhashfn(twsk_net(tw), tw->
tw_num,
86 spin_lock(&bhead->
lock);
88 spin_unlock(&bhead->
lock);
90 #ifdef SOCK_REFCNT_DEBUG
92 pr_debug(
"%s timewait_sock %p refcnt=%d\n",
93 tw->tw_prot->name, tw,
atomic_read(&tw->tw_refcnt));
105 twsk_destructor((
struct sock *)tw);
106 #ifdef SOCK_REFCNT_DEBUG
107 pr_debug(
"%s timewait_sock %p released\n", tw->tw_prot->name, tw);
109 release_net(twsk_net(tw));
129 const struct inet_sock *inet = inet_sk(sk);
132 spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
138 bhead = &hashinfo->
bhash[inet_bhashfn(twsk_net(tw), inet->
inet_num,
140 spin_lock(&bhead->
lock);
143 inet_twsk_add_bind_node(tw, &tw->
tw_tb->owners);
144 spin_unlock(&bhead->
lock);
153 inet_twsk_add_node_rcu(tw, &ehead->
twchain);
156 if (__sk_nulls_del_node_init_rcu(sk))
157 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
179 const struct inet_sock *inet = inet_sk(sk);
184 tw->tw_daddr = inet->inet_daddr;
185 tw->tw_rcv_saddr = inet->inet_rcv_saddr;
186 tw->tw_bound_dev_if = sk->sk_bound_dev_if;
193 tw->tw_family = sk->sk_family;
194 tw->tw_reuse = sk->sk_reuse;
195 tw->tw_hash = sk->sk_hash;
199 twsk_net_set(tw, hold_net(sock_net(sk)));
206 inet_twsk_dead_node_init(tw);
207 __module_get(tw->tw_prot->owner);
233 __inet_twsk_del_dead_node(tw);
235 __inet_twsk_kill(tw, twdr->
hashinfo);
257 #ifndef CONFIG_NET_NS
266 unsigned int need_timer;
275 if (inet_twdr_do_twkill_work(twdr, twdr->
slot)) {
307 while (inet_twdr_do_twkill_work(twdr, i) != 0) {
308 if (need_resched()) {
331 if (inet_twsk_del_dead_node(tw)) {
337 __inet_twsk_kill(tw, twdr->
hashinfo);
343 const int timeo,
const int timewait_len)
372 slot = (timeo + (1 << INET_TWDR_RECYCLE_TICK) - 1) >> INET_TWDR_RECYCLE_TICK;
377 if (inet_twsk_del_dead_node(tw))
384 if (timeo >= timewait_len) {
401 (slot << INET_TWDR_RECYCLE_TICK);
405 jiffies + (slot << INET_TWDR_RECYCLE_TICK)))
407 jiffies + (slot << INET_TWDR_RECYCLE_TICK));
446 __inet_twsk_del_dead_node(tw);
447 __inet_twsk_kill(tw, twdr->
hashinfo);
461 if (!hlist_empty(&twdr->
twcal_row[slot])) {
466 j += 1 << INET_TWDR_RECYCLE_TICK;
467 slot = (slot + 1) & (INET_TWDR_RECYCLE_SLOTS - 1);
472 if ((twdr->
tw_count -= killed) == 0)
474 #ifndef CONFIG_NET_NS
489 for (slot = 0; slot <= hashinfo->
ehash_mask; slot++) {
496 if ((tw->tw_family != family) ||
503 if (
unlikely((tw->tw_family != family) ||
520 if (get_nulls_value(node) != slot)