Skip to content

Commit

Permalink
[IPV4] UDP: Fix endianness bugs in hashing changes.
Browse files Browse the repository at this point in the history
I accidently applied an earlier version of Eric Dumazet's patch, from
March 21st.  His version from March 30th didn't have these bugs, so
this just interdiffs to the correct patch.

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
David S. Miller committed Apr 30, 2007
1 parent 40caf5e commit b7b5f48
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ static struct sock *__udp4_lib_lookup(__be32 saddr, __be16 sport,
struct sock *sk, *result = NULL;
struct hlist_node *node;
unsigned int hash, hashwild;
int score, best = -1;
int score, best = -1, hport = ntohs(dport);

hash = hash_port_and_addr(ntohs(dport), daddr);
hashwild = hash_port_and_addr(ntohs(dport), 0);
hash = hash_port_and_addr(hport, daddr);
hashwild = hash_port_and_addr(hport, 0);

read_lock(&udp_hash_lock);

Expand All @@ -283,7 +283,7 @@ static struct sock *__udp4_lib_lookup(__be32 saddr, __be16 sport,
struct inet_sock *inet = inet_sk(sk);

if (sk->sk_hash != hash || ipv6_only_sock(sk) ||
inet->num != dport)
inet->num != hport)
continue;

score = (sk->sk_family == PF_INET ? 1 : 0);
Expand Down Expand Up @@ -327,11 +327,10 @@ static struct sock *__udp4_lib_lookup(__be32 saddr, __be16 sport,
return result;
}

static inline struct sock *udp_v4_mcast_next(
struct sock *sk,
unsigned int hnum, __be16 loc_port, __be32 loc_addr,
__be16 rmt_port, __be32 rmt_addr,
int dif)
static inline struct sock *udp_v4_mcast_next(struct sock *sk, unsigned int hnum,
int hport, __be32 loc_addr,
__be16 rmt_port, __be32 rmt_addr,
int dif)
{
struct hlist_node *node;
struct sock *s = sk;
Expand All @@ -340,7 +339,7 @@ static inline struct sock *udp_v4_mcast_next(
struct inet_sock *inet = inet_sk(s);

if (s->sk_hash != hnum ||
inet->num != loc_port ||
inet->num != hport ||
(inet->daddr && inet->daddr != rmt_addr) ||
(inet->dport != rmt_port && inet->dport) ||
(inet->rcv_saddr && inet->rcv_saddr != loc_addr) ||
Expand Down Expand Up @@ -1173,8 +1172,9 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
{
struct sock *sk, *skw, *sknext;
int dif;
unsigned int hash = hash_port_and_addr(ntohs(uh->dest), daddr);
unsigned int hashwild = hash_port_and_addr(ntohs(uh->dest), 0);
int hport = ntohs(uh->dest);
unsigned int hash = hash_port_and_addr(hport, daddr);
unsigned int hashwild = hash_port_and_addr(hport, 0);

dif = skb->dev->ifindex;

Expand All @@ -1183,20 +1183,20 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
sk = sk_head(&udptable[hash & (UDP_HTABLE_SIZE - 1)]);
skw = sk_head(&udptable[hashwild & (UDP_HTABLE_SIZE - 1)]);

sk = udp_v4_mcast_next(sk, hash, uh->dest, daddr, uh->source, saddr, dif);
sk = udp_v4_mcast_next(sk, hash, hport, daddr, uh->source, saddr, dif);
if (!sk) {
hash = hashwild;
sk = udp_v4_mcast_next(skw, hash, uh->dest, daddr, uh->source,
sk = udp_v4_mcast_next(skw, hash, hport, daddr, uh->source,
saddr, dif);
}
if (sk) {
do {
struct sk_buff *skb1 = skb;
sknext = udp_v4_mcast_next(sk_next(sk), hash, uh->dest,
daddr, uh->source, saddr, dif);
sknext = udp_v4_mcast_next(sk_next(sk), hash, hport,
daddr, uh->source, saddr, dif);
if (!sknext && hash != hashwild) {
hash = hashwild;
sknext = udp_v4_mcast_next(skw, hash, uh->dest,
sknext = udp_v4_mcast_next(skw, hash, hport,
daddr, uh->source, saddr, dif);
}
if (sknext)
Expand Down Expand Up @@ -1295,7 +1295,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
return __udp4_lib_mcast_deliver(skb, uh, saddr, daddr, udptable);

sk = __udp4_lib_lookup(saddr, uh->source, daddr, uh->dest,
skb->dev->ifindex, udptable );
skb->dev->ifindex, udptable);

if (sk != NULL) {
int ret = udp_queue_rcv_skb(sk, skb);
Expand Down

0 comments on commit b7b5f48

Please sign in to comment.