aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/inet_hashtables.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/inet_hashtables.c')
-rw-r--r--net/ipv4/inet_hashtables.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 343a890bd617..33d6cbe32cdc 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/config.h> 16#include <linux/config.h>
17#include <linux/module.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
18 19
19#include <net/inet_hashtables.h> 20#include <net/inet_hashtables.h>
@@ -49,3 +50,42 @@ void inet_bind_bucket_destroy(kmem_cache_t *cachep, struct inet_bind_bucket *tb)
49 kmem_cache_free(cachep, tb); 50 kmem_cache_free(cachep, tb);
50 } 51 }
51} 52}
53
54void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
55 const unsigned short snum)
56{
57 struct inet_sock *inet = inet_sk(sk);
58 inet->num = snum;
59 sk_add_bind_node(sk, &tb->owners);
60 inet->bind_hash = tb;
61}
62
63EXPORT_SYMBOL(inet_bind_hash);
64
65/*
66 * Get rid of any references to a local port held by the given sock.
67 */
68static void __inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk)
69{
70 struct inet_sock *inet = inet_sk(sk);
71 const int bhash = inet_bhashfn(inet->num, hashinfo->bhash_size);
72 struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash];
73 struct inet_bind_bucket *tb;
74
75 spin_lock(&head->lock);
76 tb = inet->bind_hash;
77 __sk_del_bind_node(sk);
78 inet->bind_hash = NULL;
79 inet->num = 0;
80 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
81 spin_unlock(&head->lock);
82}
83
84void inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk)
85{
86 local_bh_disable();
87 __inet_put_port(hashinfo, sk);
88 local_bh_enable();
89}
90
91EXPORT_SYMBOL(inet_put_port);