mirror of
https://github.com/torvalds/linux.git
synced 2024-11-15 00:21:59 +00:00
udp: introduce a udp_hashfn function
Currently the chain to store a UDP socket is calculated with simple (x & (UDP_HTABLE_SIZE - 1)). But taking net into account would make this calculation a bit more complex, so moving it into a function would help. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
942e7b102a
commit
d6266281f8
@ -46,6 +46,11 @@ static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
|
|||||||
|
|
||||||
#define UDP_HTABLE_SIZE 128
|
#define UDP_HTABLE_SIZE 128
|
||||||
|
|
||||||
|
static inline int udp_hashfn(const unsigned num)
|
||||||
|
{
|
||||||
|
return num & (UDP_HTABLE_SIZE - 1);
|
||||||
|
}
|
||||||
|
|
||||||
struct udp_sock {
|
struct udp_sock {
|
||||||
/* inet_sock has to be the first member */
|
/* inet_sock has to be the first member */
|
||||||
struct inet_sock inet;
|
struct inet_sock inet;
|
||||||
|
@ -134,7 +134,7 @@ static inline int __udp_lib_lport_inuse(struct net *net, __u16 num,
|
|||||||
struct sock *sk;
|
struct sock *sk;
|
||||||
struct hlist_node *node;
|
struct hlist_node *node;
|
||||||
|
|
||||||
sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)])
|
sk_for_each(sk, node, &udptable[udp_hashfn(num)])
|
||||||
if (net_eq(sock_net(sk), net) && sk->sk_hash == num)
|
if (net_eq(sock_net(sk), net) && sk->sk_hash == num)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -174,7 +174,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
|||||||
for (i = 0; i < UDP_HTABLE_SIZE; i++) {
|
for (i = 0; i < UDP_HTABLE_SIZE; i++) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
head = &udptable[rover & (UDP_HTABLE_SIZE - 1)];
|
head = &udptable[udp_hashfn(rover)];
|
||||||
if (hlist_empty(head))
|
if (hlist_empty(head))
|
||||||
goto gotit;
|
goto gotit;
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
|||||||
gotit:
|
gotit:
|
||||||
snum = rover;
|
snum = rover;
|
||||||
} else {
|
} else {
|
||||||
head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
|
head = &udptable[udp_hashfn(snum)];
|
||||||
|
|
||||||
sk_for_each(sk2, node, head)
|
sk_for_each(sk2, node, head)
|
||||||
if (sk2->sk_hash == snum &&
|
if (sk2->sk_hash == snum &&
|
||||||
@ -227,7 +227,7 @@ gotit:
|
|||||||
inet_sk(sk)->num = snum;
|
inet_sk(sk)->num = snum;
|
||||||
sk->sk_hash = snum;
|
sk->sk_hash = snum;
|
||||||
if (sk_unhashed(sk)) {
|
if (sk_unhashed(sk)) {
|
||||||
head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
|
head = &udptable[udp_hashfn(snum)];
|
||||||
sk_add_node(sk, head);
|
sk_add_node(sk, head);
|
||||||
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
|
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
|
|||||||
int badness = -1;
|
int badness = -1;
|
||||||
|
|
||||||
read_lock(&udp_hash_lock);
|
read_lock(&udp_hash_lock);
|
||||||
sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
|
sk_for_each(sk, node, &udptable[udp_hashfn(hnum)]) {
|
||||||
struct inet_sock *inet = inet_sk(sk);
|
struct inet_sock *inet = inet_sk(sk);
|
||||||
|
|
||||||
if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
|
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,
|
|||||||
int dif;
|
int dif;
|
||||||
|
|
||||||
read_lock(&udp_hash_lock);
|
read_lock(&udp_hash_lock);
|
||||||
sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]);
|
sk = sk_head(&udptable[udp_hashfn(ntohs(uh->dest))]);
|
||||||
dif = skb->dev->ifindex;
|
dif = skb->dev->ifindex;
|
||||||
sk = udp_v4_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
|
sk = udp_v4_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
|
||||||
if (sk) {
|
if (sk) {
|
||||||
|
@ -65,7 +65,7 @@ static struct sock *__udp6_lib_lookup(struct net *net,
|
|||||||
int badness = -1;
|
int badness = -1;
|
||||||
|
|
||||||
read_lock(&udp_hash_lock);
|
read_lock(&udp_hash_lock);
|
||||||
sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
|
sk_for_each(sk, node, &udptable[udp_hashfn(hnum)]) {
|
||||||
struct inet_sock *inet = inet_sk(sk);
|
struct inet_sock *inet = inet_sk(sk);
|
||||||
|
|
||||||
if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
|
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,
|
|||||||
int dif;
|
int dif;
|
||||||
|
|
||||||
read_lock(&udp_hash_lock);
|
read_lock(&udp_hash_lock);
|
||||||
sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]);
|
sk = sk_head(&udptable[udp_hashfn(ntohs(uh->dest))]);
|
||||||
dif = inet6_iif(skb);
|
dif = inet6_iif(skb);
|
||||||
sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
|
sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
|
Loading…
Reference in New Issue
Block a user