Lines Matching refs:tw

28 int inet_twsk_unhash(struct inet_timewait_sock *tw)  in inet_twsk_unhash()  argument
30 if (hlist_nulls_unhashed(&tw->tw_node)) in inet_twsk_unhash()
33 hlist_nulls_del_rcu(&tw->tw_node); in inet_twsk_unhash()
34 sk_nulls_node_init(&tw->tw_node); in inet_twsk_unhash()
51 int inet_twsk_bind_unhash(struct inet_timewait_sock *tw, in inet_twsk_bind_unhash() argument
54 struct inet_bind_bucket *tb = tw->tw_tb; in inet_twsk_bind_unhash()
59 __hlist_del(&tw->tw_bind_node); in inet_twsk_bind_unhash()
60 tw->tw_tb = NULL; in inet_twsk_bind_unhash()
70 static void inet_twsk_kill(struct inet_timewait_sock *tw) in inet_twsk_kill() argument
72 struct inet_hashinfo *hashinfo = tw->tw_dr->hashinfo; in inet_twsk_kill()
76 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); in inet_twsk_kill()
79 refcnt = inet_twsk_unhash(tw); in inet_twsk_kill()
83 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num, in inet_twsk_kill()
87 refcnt += inet_twsk_bind_unhash(tw, hashinfo); in inet_twsk_kill()
90 BUG_ON(refcnt >= atomic_read(&tw->tw_refcnt)); in inet_twsk_kill()
91 atomic_sub(refcnt, &tw->tw_refcnt); in inet_twsk_kill()
92 atomic_dec(&tw->tw_dr->tw_count); in inet_twsk_kill()
93 inet_twsk_put(tw); in inet_twsk_kill()
96 void inet_twsk_free(struct inet_timewait_sock *tw) in inet_twsk_free() argument
98 struct module *owner = tw->tw_prot->owner; in inet_twsk_free()
99 twsk_destructor((struct sock *)tw); in inet_twsk_free()
101 pr_debug("%s timewait_sock %p released\n", tw->tw_prot->name, tw); in inet_twsk_free()
103 kmem_cache_free(tw->tw_prot->twsk_prot->twsk_slab, tw); in inet_twsk_free()
107 void inet_twsk_put(struct inet_timewait_sock *tw) in inet_twsk_put() argument
109 if (atomic_dec_and_test(&tw->tw_refcnt)) in inet_twsk_put()
110 inet_twsk_free(tw); in inet_twsk_put()
114 static void inet_twsk_add_node_rcu(struct inet_timewait_sock *tw, in inet_twsk_add_node_rcu() argument
117 hlist_nulls_add_head_rcu(&tw->tw_node, list); in inet_twsk_add_node_rcu()
120 static void inet_twsk_add_bind_node(struct inet_timewait_sock *tw, in inet_twsk_add_bind_node() argument
123 hlist_add_head(&tw->tw_bind_node, list); in inet_twsk_add_bind_node()
131 void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, in __inet_twsk_hashdance() argument
143 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->inet_num, in __inet_twsk_hashdance()
146 tw->tw_tb = icsk->icsk_bind_hash; in __inet_twsk_hashdance()
148 inet_twsk_add_bind_node(tw, &tw->tw_tb->owners); in __inet_twsk_hashdance()
164 atomic_set(&tw->tw_refcnt, 4); in __inet_twsk_hashdance()
165 inet_twsk_add_node_rcu(tw, &ehead->chain); in __inet_twsk_hashdance()
177 struct inet_timewait_sock *tw = (struct inet_timewait_sock *)data; in tw_timer_handler() local
179 if (tw->tw_kill) in tw_timer_handler()
180 NET_INC_STATS_BH(twsk_net(tw), LINUX_MIB_TIMEWAITKILLED); in tw_timer_handler()
182 NET_INC_STATS_BH(twsk_net(tw), LINUX_MIB_TIMEWAITED); in tw_timer_handler()
183 inet_twsk_kill(tw); in tw_timer_handler()
190 struct inet_timewait_sock *tw; in inet_twsk_alloc() local
195 tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_prot->twsk_slab, in inet_twsk_alloc()
197 if (tw) { in inet_twsk_alloc()
200 kmemcheck_annotate_bitfield(tw, flags); in inet_twsk_alloc()
202 tw->tw_dr = dr; in inet_twsk_alloc()
204 tw->tw_daddr = inet->inet_daddr; in inet_twsk_alloc()
205 tw->tw_rcv_saddr = inet->inet_rcv_saddr; in inet_twsk_alloc()
206 tw->tw_bound_dev_if = sk->sk_bound_dev_if; in inet_twsk_alloc()
207 tw->tw_tos = inet->tos; in inet_twsk_alloc()
208 tw->tw_num = inet->inet_num; in inet_twsk_alloc()
209 tw->tw_state = TCP_TIME_WAIT; in inet_twsk_alloc()
210 tw->tw_substate = state; in inet_twsk_alloc()
211 tw->tw_sport = inet->inet_sport; in inet_twsk_alloc()
212 tw->tw_dport = inet->inet_dport; in inet_twsk_alloc()
213 tw->tw_family = sk->sk_family; in inet_twsk_alloc()
214 tw->tw_reuse = sk->sk_reuse; in inet_twsk_alloc()
215 tw->tw_hash = sk->sk_hash; in inet_twsk_alloc()
216 tw->tw_ipv6only = 0; in inet_twsk_alloc()
217 tw->tw_transparent = inet->transparent; in inet_twsk_alloc()
218 tw->tw_prot = sk->sk_prot_creator; in inet_twsk_alloc()
219 atomic64_set(&tw->tw_cookie, atomic64_read(&sk->sk_cookie)); in inet_twsk_alloc()
220 twsk_net_set(tw, sock_net(sk)); in inet_twsk_alloc()
221 setup_timer(&tw->tw_timer, tw_timer_handler, (unsigned long)tw); in inet_twsk_alloc()
227 atomic_set(&tw->tw_refcnt, 0); in inet_twsk_alloc()
229 __module_get(tw->tw_prot->owner); in inet_twsk_alloc()
232 return tw; in inet_twsk_alloc()
241 void inet_twsk_deschedule(struct inet_timewait_sock *tw) in inet_twsk_deschedule() argument
243 if (del_timer_sync(&tw->tw_timer)) in inet_twsk_deschedule()
244 inet_twsk_kill(tw); in inet_twsk_deschedule()
248 void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, bool rearm) in __inet_twsk_schedule() argument
275 tw->tw_kill = timeo <= 4*HZ; in __inet_twsk_schedule()
277 BUG_ON(mod_timer_pinned(&tw->tw_timer, jiffies + timeo)); in __inet_twsk_schedule()
278 atomic_inc(&tw->tw_dr->tw_count); in __inet_twsk_schedule()
280 mod_timer_pending(&tw->tw_timer, jiffies + timeo); in __inet_twsk_schedule()
288 struct inet_timewait_sock *tw; in inet_twsk_purge() local
302 tw = inet_twsk(sk); in inet_twsk_purge()
303 if ((tw->tw_family != family) || in inet_twsk_purge()
304 atomic_read(&twsk_net(tw)->count)) in inet_twsk_purge()
307 if (unlikely(!atomic_inc_not_zero(&tw->tw_refcnt))) in inet_twsk_purge()
310 if (unlikely((tw->tw_family != family) || in inet_twsk_purge()
311 atomic_read(&twsk_net(tw)->count))) { in inet_twsk_purge()
312 inet_twsk_put(tw); in inet_twsk_purge()
318 inet_twsk_deschedule(tw); in inet_twsk_purge()
320 inet_twsk_put(tw); in inet_twsk_purge()