net: ipv4: add second dif to raw socket lookups
authorDavid Ahern <dsahern@gmail.com>
Mon, 7 Aug 2017 15:44:18 +0000 (08:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 7 Aug 2017 18:39:21 +0000 (11:39 -0700)
Add a second device index, sdif, to raw socket lookups. sdif is the
index for ingress devices enslaved to an l3mdev. It allows the lookups
to consider the enslaved device as well as the L3 domain when searching
for a socket.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/raw.h
net/ipv4/raw.c
net/ipv4/raw_diag.c

index 57c33dd22ec4dcb3955f3a6297631f9fab7e7237..99d26d0c4a1938632279df0e6677c8f0a0cad1ee 100644 (file)
@@ -26,7 +26,7 @@ extern struct proto raw_prot;
 extern struct raw_hashinfo raw_v4_hashinfo;
 struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
                             unsigned short num, __be32 raddr,
-                            __be32 laddr, int dif);
+                            __be32 laddr, int dif, int sdif);
 
 int raw_abort(struct sock *sk, int err);
 void raw_icmp_error(struct sk_buff *, int, u32);
index b0bb5d0a30bd50b84f0d6a3bccd39b996b4678b3..2726aecf224b3f6b1aa8b53cc316cb0448154a85 100644 (file)
@@ -122,7 +122,8 @@ void raw_unhash_sk(struct sock *sk)
 EXPORT_SYMBOL_GPL(raw_unhash_sk);
 
 struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
-               unsigned short num, __be32 raddr, __be32 laddr, int dif)
+                            unsigned short num, __be32 raddr, __be32 laddr,
+                            int dif, int sdif)
 {
        sk_for_each_from(sk) {
                struct inet_sock *inet = inet_sk(sk);
@@ -130,7 +131,8 @@ struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
                if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
                    !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
                    !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
-                   !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
+                   !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif &&
+                     sk->sk_bound_dev_if != sdif))
                        goto found; /* gotcha */
        }
        sk = NULL;
@@ -171,6 +173,7 @@ static int icmp_filter(const struct sock *sk, const struct sk_buff *skb)
  */
 static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
 {
+       int sdif = inet_sdif(skb);
        struct sock *sk;
        struct hlist_head *head;
        int delivered = 0;
@@ -184,7 +187,7 @@ static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
        net = dev_net(skb->dev);
        sk = __raw_v4_lookup(net, __sk_head(head), iph->protocol,
                             iph->saddr, iph->daddr,
-                            skb->dev->ifindex);
+                            skb->dev->ifindex, sdif);
 
        while (sk) {
                delivered = 1;
@@ -199,7 +202,7 @@ static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
                }
                sk = __raw_v4_lookup(net, sk_next(sk), iph->protocol,
                                     iph->saddr, iph->daddr,
-                                    skb->dev->ifindex);
+                                    skb->dev->ifindex, sdif);
        }
 out:
        read_unlock(&raw_v4_hashinfo.lock);
@@ -297,12 +300,15 @@ void raw_icmp_error(struct sk_buff *skb, int protocol, u32 info)
        read_lock(&raw_v4_hashinfo.lock);
        raw_sk = sk_head(&raw_v4_hashinfo.ht[hash]);
        if (raw_sk) {
+               int dif = skb->dev->ifindex;
+               int sdif = inet_sdif(skb);
+
                iph = (const struct iphdr *)skb->data;
                net = dev_net(skb->dev);
 
                while ((raw_sk = __raw_v4_lookup(net, raw_sk, protocol,
                                                iph->daddr, iph->saddr,
-                                               skb->dev->ifindex)) != NULL) {
+                                               dif, sdif)) != NULL) {
                        raw_err(raw_sk, skb, info);
                        raw_sk = sk_next(raw_sk);
                        iph = (const struct iphdr *)skb->data;
index e1a51ca68d23c324b6643234c6af399aacca83e0..c600d3c71d4dab6cfadcb27c52626ad699dde969 100644 (file)
@@ -46,7 +46,7 @@ static struct sock *raw_lookup(struct net *net, struct sock *from,
                sk = __raw_v4_lookup(net, from, r->sdiag_raw_protocol,
                                     r->id.idiag_dst[0],
                                     r->id.idiag_src[0],
-                                    r->id.idiag_if);
+                                    r->id.idiag_if, 0);
 #if IS_ENABLED(CONFIG_IPV6)
        else
                sk = __raw_v6_lookup(net, from, r->sdiag_raw_protocol,