Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 112242
b: refs/heads/master
c: f24d43c
h: refs/heads/master
v: v3
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Oct 9, 2008
1 parent 1e416d2 commit dcc95bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 626e264dd1989bdc98a5eaf2e059af4dba07ac4f
refs/heads/master: f24d43c07e208372aa3d3bff419afbf43ba87698
43 changes: 19 additions & 24 deletions trunk/net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,23 @@ EXPORT_SYMBOL(sysctl_udp_wmem_min);
atomic_t udp_memory_allocated;
EXPORT_SYMBOL(udp_memory_allocated);

static inline int __udp_lib_lport_inuse(struct net *net, __u16 num,
const struct hlist_head udptable[])
static int udp_lib_lport_inuse(struct net *net, __u16 num,
const struct hlist_head udptable[],
struct sock *sk,
int (*saddr_comp)(const struct sock *sk1,
const struct sock *sk2))
{
struct sock *sk;
struct sock *sk2;
struct hlist_node *node;

sk_for_each(sk, node, &udptable[udp_hashfn(net, num)])
if (net_eq(sock_net(sk), net) && sk->sk_hash == num)
sk_for_each(sk2, node, &udptable[udp_hashfn(net, num)])
if (net_eq(sock_net(sk2), net) &&
sk2 != sk &&
sk2->sk_hash == num &&
(!sk2->sk_reuse || !sk->sk_reuse) &&
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if
|| sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
(*saddr_comp)(sk, sk2))
return 1;
return 0;
}
Expand All @@ -146,9 +155,6 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
const struct sock *sk2 ) )
{
struct hlist_head *udptable = sk->sk_prot->h.udp_hash;
struct hlist_node *node;
struct hlist_head *head;
struct sock *sk2;
int error = 1;
struct net *net = sock_net(sk);

Expand All @@ -165,32 +171,21 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
rand = net_random();
snum = first = rand % remaining + low;
rand |= 1;
while (__udp_lib_lport_inuse(net, snum, udptable)) {
while (udp_lib_lport_inuse(net, snum, udptable, sk,
saddr_comp)) {
do {
snum = snum + rand;
} while (snum < low || snum > high);
if (snum == first)
goto fail;
}
} else {
head = &udptable[udp_hashfn(net, snum)];

sk_for_each(sk2, node, head)
if (sk2->sk_hash == snum &&
sk2 != sk &&
net_eq(sock_net(sk2), net) &&
(!sk2->sk_reuse || !sk->sk_reuse) &&
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if
|| sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
(*saddr_comp)(sk, sk2) )
goto fail;
}
} else if (udp_lib_lport_inuse(net, snum, udptable, sk, saddr_comp))
goto fail;

inet_sk(sk)->num = snum;
sk->sk_hash = snum;
if (sk_unhashed(sk)) {
head = &udptable[udp_hashfn(net, snum)];
sk_add_node(sk, head);
sk_add_node(sk, &udptable[udp_hashfn(net, snum)]);
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
}
error = 0;
Expand Down

0 comments on commit dcc95bb

Please sign in to comment.