Commit 9cb429d6 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: early_demux fixes

1) Remove a non needed pskb_may_pull() in tcp_v4_early_demux()
   and fix a potential bug if skb->head was reallocated
   (iph & th pointers were not reloaded)

TCP stack will pull/check headers anyway.

2) must reload iph in ip_rcv_finish() after early_demux()
 call since skb->head might have changed.

3) skb->dev->ifindex can be now replaced by skb->skb_iif
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c20cd5d7
...@@ -326,8 +326,11 @@ static int ip_rcv_finish(struct sk_buff *skb) ...@@ -326,8 +326,11 @@ static int ip_rcv_finish(struct sk_buff *skb)
rcu_read_lock(); rcu_read_lock();
ipprot = rcu_dereference(inet_protos[protocol]); ipprot = rcu_dereference(inet_protos[protocol]);
if (ipprot && ipprot->early_demux) if (ipprot && ipprot->early_demux) {
ipprot->early_demux(skb); ipprot->early_demux(skb);
/* must reload iph, skb->head might have changed */
iph = ip_hdr(skb);
}
rcu_read_unlock(); rcu_read_unlock();
} }
......
...@@ -1686,7 +1686,6 @@ void tcp_v4_early_demux(struct sk_buff *skb) ...@@ -1686,7 +1686,6 @@ void tcp_v4_early_demux(struct sk_buff *skb)
struct net *net = dev_net(skb->dev); struct net *net = dev_net(skb->dev);
const struct iphdr *iph; const struct iphdr *iph;
const struct tcphdr *th; const struct tcphdr *th;
struct net_device *dev;
struct sock *sk; struct sock *sk;
if (skb->pkt_type != PACKET_HOST) if (skb->pkt_type != PACKET_HOST)
...@@ -1701,14 +1700,10 @@ void tcp_v4_early_demux(struct sk_buff *skb) ...@@ -1701,14 +1700,10 @@ void tcp_v4_early_demux(struct sk_buff *skb)
if (th->doff < sizeof(struct tcphdr) / 4) if (th->doff < sizeof(struct tcphdr) / 4)
return; return;
if (!pskb_may_pull(skb, ip_hdrlen(skb) + th->doff * 4))
return;
dev = skb->dev;
sk = __inet_lookup_established(net, &tcp_hashinfo, sk = __inet_lookup_established(net, &tcp_hashinfo,
iph->saddr, th->source, iph->saddr, th->source,
iph->daddr, ntohs(th->dest), iph->daddr, ntohs(th->dest),
dev->ifindex); skb->skb_iif);
if (sk) { if (sk) {
skb->sk = sk; skb->sk = sk;
skb->destructor = sock_edemux; skb->destructor = sock_edemux;
...@@ -1718,7 +1713,7 @@ void tcp_v4_early_demux(struct sk_buff *skb) ...@@ -1718,7 +1713,7 @@ void tcp_v4_early_demux(struct sk_buff *skb)
if (dst) if (dst)
dst = dst_check(dst, 0); dst = dst_check(dst, 0);
if (dst && if (dst &&
icsk->rx_dst_ifindex == dev->ifindex) icsk->rx_dst_ifindex == skb->skb_iif)
skb_dst_set_noref(skb, dst); skb_dst_set_noref(skb, dst);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment