Skip to content

Commit

Permalink
ipv6: Early TCP socket demux
Browse files Browse the repository at this point in the history
This is the IPv6 missing bits for infrastructure added in commit
41063e9 (ipv4: Early TCP socket demux.)

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Jul 26, 2012
1 parent c6cffba commit c710998
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
13 changes: 7 additions & 6 deletions include/net/inet6_hashtables.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
const __be16 sport,
const __be16 dport)
{
struct sock *sk;
struct sock *sk = skb_steal_sock(skb);

if (unlikely(sk = skb_steal_sock(skb)))
if (sk)
return sk;
else return __inet6_lookup(dev_net(skb_dst(skb)->dev), hashinfo,
&ipv6_hdr(skb)->saddr, sport,
&ipv6_hdr(skb)->daddr, ntohs(dport),
inet6_iif(skb));

return __inet6_lookup(dev_net(skb_dst(skb)->dev), hashinfo,
&ipv6_hdr(skb)->saddr, sport,
&ipv6_hdr(skb)->daddr, ntohs(dport),
inet6_iif(skb));
}

extern struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
Expand Down
2 changes: 2 additions & 0 deletions include/net/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct net_protocol {

#if IS_ENABLED(CONFIG_IPV6)
struct inet6_protocol {
void (*early_demux)(struct sk_buff *skb);

int (*handler)(struct sk_buff *skb);

void (*err_handler)(struct sk_buff *skb,
Expand Down
1 change: 1 addition & 0 deletions net/ipv4/ip_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ static inline bool ip_rcv_options(struct sk_buff *skb)
}

int sysctl_ip_early_demux __read_mostly = 1;
EXPORT_SYMBOL(sysctl_ip_early_demux);

static int ip_rcv_finish(struct sk_buff *skb)
{
Expand Down
13 changes: 11 additions & 2 deletions net/ipv6/ip6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@



inline int ip6_rcv_finish( struct sk_buff *skb)
int ip6_rcv_finish(struct sk_buff *skb)
{
if (skb_dst(skb) == NULL)
if (sysctl_ip_early_demux && !skb_dst(skb)) {
const struct inet6_protocol *ipprot;

rcu_read_lock();
ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]);
if (ipprot && ipprot->early_demux)
ipprot->early_demux(skb);
rcu_read_unlock();
}
if (!skb_dst(skb))
ip6_route_input(skb);

return dst_input(skb);
Expand Down
38 changes: 38 additions & 0 deletions net/ipv6/tcp_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,43 @@ static int tcp_v6_rcv(struct sk_buff *skb)
goto discard_it;
}

static void tcp_v6_early_demux(struct sk_buff *skb)
{
const struct ipv6hdr *hdr;
const struct tcphdr *th;
struct sock *sk;

if (skb->pkt_type != PACKET_HOST)
return;

if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(struct tcphdr)))
return;

hdr = ipv6_hdr(skb);
th = tcp_hdr(skb);

if (th->doff < sizeof(struct tcphdr) / 4)
return;

sk = __inet6_lookup_established(dev_net(skb->dev), &tcp_hashinfo,
&hdr->saddr, th->source,
&hdr->daddr, ntohs(th->dest),
inet6_iif(skb));
if (sk) {
skb->sk = sk;
skb->destructor = sock_edemux;
if (sk->sk_state != TCP_TIME_WAIT) {
struct dst_entry *dst = sk->sk_rx_dst;
struct inet_sock *icsk = inet_sk(sk);
if (dst)
dst = dst_check(dst, 0);
if (dst &&
icsk->rx_dst_ifindex == inet6_iif(skb))
skb_dst_set_noref(skb, dst);
}
}
}

static struct timewait_sock_ops tcp6_timewait_sock_ops = {
.twsk_obj_size = sizeof(struct tcp6_timewait_sock),
.twsk_unique = tcp_twsk_unique,
Expand Down Expand Up @@ -1984,6 +2021,7 @@ struct proto tcpv6_prot = {
};

static const struct inet6_protocol tcpv6_protocol = {
.early_demux = tcp_v6_early_demux,
.handler = tcp_v6_rcv,
.err_handler = tcp_v6_err,
.gso_send_check = tcp_v6_gso_send_check,
Expand Down

0 comments on commit c710998

Please sign in to comment.