Lines Matching +full:loss +full:- +full:of +full:- +full:lock

1 // SPDX-License-Identifier: GPL-2.0-only
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
5 * interface as the means of communication with the user level.
21 * inet_twsk_bind_unhash - unhash a timewait socket from bind hash
26 * bind hash lock must be held by caller.
27 * Returns 1 if caller should call inet_twsk_put() after lock release.
32 struct inet_bind_bucket *tb = tw->tw_tb; in inet_twsk_bind_unhash()
37 __hlist_del(&tw->tw_bind_node); in inet_twsk_bind_unhash()
38 tw->tw_tb = NULL; in inet_twsk_bind_unhash()
39 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb); in inet_twsk_bind_unhash()
46 struct inet_hashinfo *hashinfo = tw->tw_dr->hashinfo; in inet_twsk_kill()
47 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); in inet_twsk_kill() local
50 spin_lock(lock); in inet_twsk_kill()
52 spin_unlock(lock); in inet_twsk_kill()
55 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num, in inet_twsk_kill()
56 hashinfo->bhash_size)]; in inet_twsk_kill()
58 spin_lock(&bhead->lock); in inet_twsk_kill()
60 spin_unlock(&bhead->lock); in inet_twsk_kill()
62 atomic_dec(&tw->tw_dr->tw_count); in inet_twsk_kill()
68 struct module *owner = tw->tw_prot->owner; in inet_twsk_free()
71 pr_debug("%s timewait_sock %p released\n", tw->tw_prot->name, tw); in inet_twsk_free()
73 kmem_cache_free(tw->tw_prot->twsk_prot->twsk_slab, tw); in inet_twsk_free()
79 if (refcount_dec_and_test(&tw->tw_refcnt)) in inet_twsk_put()
87 hlist_nulls_add_head_rcu(&tw->tw_node, list); in inet_twsk_add_node_rcu()
93 hlist_add_head(&tw->tw_bind_node, list); in inet_twsk_add_bind_node()
106 struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); in inet_twsk_hashdance()
107 spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash); in inet_twsk_hashdance() local
110 Note, that any socket with inet->num != 0 MUST be bound in in inet_twsk_hashdance()
113 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->inet_num, in inet_twsk_hashdance()
114 hashinfo->bhash_size)]; in inet_twsk_hashdance()
115 spin_lock(&bhead->lock); in inet_twsk_hashdance()
116 tw->tw_tb = icsk->icsk_bind_hash; in inet_twsk_hashdance()
117 WARN_ON(!icsk->icsk_bind_hash); in inet_twsk_hashdance()
118 inet_twsk_add_bind_node(tw, &tw->tw_tb->owners); in inet_twsk_hashdance()
119 spin_unlock(&bhead->lock); in inet_twsk_hashdance()
121 spin_lock(lock); in inet_twsk_hashdance()
123 inet_twsk_add_node_rcu(tw, &ehead->chain); in inet_twsk_hashdance()
127 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); in inet_twsk_hashdance()
129 spin_unlock(lock); in inet_twsk_hashdance()
132 * - one reference for bhash chain. in inet_twsk_hashdance()
133 * - one reference for ehash chain. in inet_twsk_hashdance()
134 * - one reference for timer. in inet_twsk_hashdance()
140 refcount_set(&tw->tw_refcnt, 3); in inet_twsk_hashdance()
148 if (tw->tw_kill) in tw_timer_handler()
161 if (atomic_read(&dr->tw_count) >= dr->sysctl_max_tw_buckets) in inet_twsk_alloc()
164 tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_prot->twsk_slab, in inet_twsk_alloc()
169 tw->tw_dr = dr; in inet_twsk_alloc()
171 tw->tw_daddr = inet->inet_daddr; in inet_twsk_alloc()
172 tw->tw_rcv_saddr = inet->inet_rcv_saddr; in inet_twsk_alloc()
173 tw->tw_bound_dev_if = sk->sk_bound_dev_if; in inet_twsk_alloc()
174 tw->tw_tos = inet->tos; in inet_twsk_alloc()
175 tw->tw_num = inet->inet_num; in inet_twsk_alloc()
176 tw->tw_state = TCP_TIME_WAIT; in inet_twsk_alloc()
177 tw->tw_substate = state; in inet_twsk_alloc()
178 tw->tw_sport = inet->inet_sport; in inet_twsk_alloc()
179 tw->tw_dport = inet->inet_dport; in inet_twsk_alloc()
180 tw->tw_family = sk->sk_family; in inet_twsk_alloc()
181 tw->tw_reuse = sk->sk_reuse; in inet_twsk_alloc()
182 tw->tw_reuseport = sk->sk_reuseport; in inet_twsk_alloc()
183 tw->tw_hash = sk->sk_hash; in inet_twsk_alloc()
184 tw->tw_ipv6only = 0; in inet_twsk_alloc()
185 tw->tw_transparent = inet->transparent; in inet_twsk_alloc()
186 tw->tw_prot = sk->sk_prot_creator; in inet_twsk_alloc()
187 atomic64_set(&tw->tw_cookie, atomic64_read(&sk->sk_cookie)); in inet_twsk_alloc()
189 timer_setup(&tw->tw_timer, tw_timer_handler, TIMER_PINNED); in inet_twsk_alloc()
195 refcount_set(&tw->tw_refcnt, 0); in inet_twsk_alloc()
197 __module_get(tw->tw_prot->owner); in inet_twsk_alloc()
208 /* This is for handling early-kills of TIME_WAIT sockets.
214 if (del_timer_sync(&tw->tw_timer)) in inet_twsk_deschedule_put()
226 * RATIONALE: if FIN arrived and we entered TIME-WAIT state, in __inet_twsk_schedule()
228 * FINs (or previous seqments) are lost (probability of such event in __inet_twsk_schedule()
230 * time to detect the loss is about RTO*(2^N - 1) with exponential in __inet_twsk_schedule()
235 * Well, 240 consumes too much of resources 8) in __inet_twsk_schedule()
244 * of PAWS. in __inet_twsk_schedule()
247 tw->tw_kill = timeo <= 4*HZ; in __inet_twsk_schedule()
249 BUG_ON(mod_timer(&tw->tw_timer, jiffies + timeo)); in __inet_twsk_schedule()
250 atomic_inc(&tw->tw_dr->tw_count); in __inet_twsk_schedule()
252 mod_timer_pending(&tw->tw_timer, jiffies + timeo); in __inet_twsk_schedule()
264 for (slot = 0; slot <= hashinfo->ehash_mask; slot++) { in inet_twsk_purge()
265 struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; in inet_twsk_purge()
270 sk_nulls_for_each_rcu(sk, node, &head->chain) { in inet_twsk_purge()
271 if (sk->sk_state != TCP_TIME_WAIT) in inet_twsk_purge()
274 if ((tw->tw_family != family) || in inet_twsk_purge()
275 refcount_read(&twsk_net(tw)->ns.count)) in inet_twsk_purge()
278 if (unlikely(!refcount_inc_not_zero(&tw->tw_refcnt))) in inet_twsk_purge()
281 if (unlikely((tw->tw_family != family) || in inet_twsk_purge()
282 refcount_read(&twsk_net(tw)->ns.count))) { in inet_twsk_purge()
293 /* If the nulls value we got at the end of this lookup is in inet_twsk_purge()