aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/udp.h5
-rw-r--r--net/ipv4/udp.c12
-rw-r--r--net/ipv6/udp.c4
3 files changed, 13 insertions, 8 deletions
diff --git a/include/linux/udp.h b/include/linux/udp.h
index 581ca2c14c52..9c94312b2de5 100644
--- a/include/linux/udp.h
+++ b/include/linux/udp.h
@@ -46,6 +46,11 @@ static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
46 46
47#define UDP_HTABLE_SIZE 128 47#define UDP_HTABLE_SIZE 128
48 48
49static inline int udp_hashfn(const unsigned num)
50{
51 return num & (UDP_HTABLE_SIZE - 1);
52}
53
49struct udp_sock { 54struct udp_sock {
50 /* inet_sock has to be the first member */ 55 /* inet_sock has to be the first member */
51 struct inet_sock inet; 56 struct inet_sock inet;
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index eba790dcd16b..d8f527d15701 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -134,7 +134,7 @@ static inline int __udp_lib_lport_inuse(struct net *net, __u16 num,
134 struct sock *sk; 134 struct sock *sk;
135 struct hlist_node *node; 135 struct hlist_node *node;
136 136
137 sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)]) 137 sk_for_each(sk, node, &udptable[udp_hashfn(num)])
138 if (net_eq(sock_net(sk), net) && sk->sk_hash == num) 138 if (net_eq(sock_net(sk), net) && sk->sk_hash == num)
139 return 1; 139 return 1;
140 return 0; 140 return 0;
@@ -174,7 +174,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
174 for (i = 0; i < UDP_HTABLE_SIZE; i++) { 174 for (i = 0; i < UDP_HTABLE_SIZE; i++) {
175 int size = 0; 175 int size = 0;
176 176
177 head = &udptable[rover & (UDP_HTABLE_SIZE - 1)]; 177 head = &udptable[udp_hashfn(rover)];
178 if (hlist_empty(head)) 178 if (hlist_empty(head))
179 goto gotit; 179 goto gotit;
180 180
@@ -211,7 +211,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
211gotit: 211gotit:
212 snum = rover; 212 snum = rover;
213 } else { 213 } else {
214 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)]; 214 head = &udptable[udp_hashfn(snum)];
215 215
216 sk_for_each(sk2, node, head) 216 sk_for_each(sk2, node, head)
217 if (sk2->sk_hash == snum && 217 if (sk2->sk_hash == snum &&
@@ -227,7 +227,7 @@ gotit:
227 inet_sk(sk)->num = snum; 227 inet_sk(sk)->num = snum;
228 sk->sk_hash = snum; 228 sk->sk_hash = snum;
229 if (sk_unhashed(sk)) { 229 if (sk_unhashed(sk)) {
230 head = &udptable[snum & (UDP_HTABLE_SIZE - 1)]; 230 head = &udptable[udp_hashfn(snum)];
231 sk_add_node(sk, head); 231 sk_add_node(sk, head);
232 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 232 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
233 } 233 }
@@ -264,7 +264,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
264 int badness = -1; 264 int badness = -1;
265 265
266 read_lock(&udp_hash_lock); 266 read_lock(&udp_hash_lock);
267 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { 267 sk_for_each(sk, node, &udptable[udp_hashfn(hnum)]) {
268 struct inet_sock *inet = inet_sk(sk); 268 struct inet_sock *inet = inet_sk(sk);
269 269
270 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 270 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
@@ -1068,7 +1068,7 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
1068 int dif; 1068 int dif;
1069 1069
1070 read_lock(&udp_hash_lock); 1070 read_lock(&udp_hash_lock);
1071 sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]); 1071 sk = sk_head(&udptable[udp_hashfn(ntohs(uh->dest))]);
1072 dif = skb->dev->ifindex; 1072 dif = skb->dev->ifindex;
1073 sk = udp_v4_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif); 1073 sk = udp_v4_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
1074 if (sk) { 1074 if (sk) {
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 09687f7a8564..6e4a822ba651 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -65,7 +65,7 @@ static struct sock *__udp6_lib_lookup(struct net *net,
65 int badness = -1; 65 int badness = -1;
66 66
67 read_lock(&udp_hash_lock); 67 read_lock(&udp_hash_lock);
68 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { 68 sk_for_each(sk, node, &udptable[udp_hashfn(hnum)]) {
69 struct inet_sock *inet = inet_sk(sk); 69 struct inet_sock *inet = inet_sk(sk);
70 70
71 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 71 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
@@ -361,7 +361,7 @@ static int __udp6_lib_mcast_deliver(struct sk_buff *skb, struct in6_addr *saddr,
361 int dif; 361 int dif;
362 362
363 read_lock(&udp_hash_lock); 363 read_lock(&udp_hash_lock);
364 sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]); 364 sk = sk_head(&udptable[udp_hashfn(ntohs(uh->dest))]);
365 dif = inet6_iif(skb); 365 dif = inet6_iif(skb);
366 sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif); 366 sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
367 if (!sk) { 367 if (!sk) {