net: original ingress device index in PKTINFO
authorDavid Ahern <dsa@cumulusnetworks.com>
Tue, 10 May 2016 18:19:51 +0000 (11:19 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 11 May 2016 23:31:40 +0000 (19:31 -0400)
Applications such as OSPF and BFD need the original ingress device not
the VRF device; the latter can be derived from the former. To that end
add the skb_iif to inet_skb_parm and set it in ipv4 code after clearing
the skb control buffer similar to IPv6. From there the pktinfo can just
pull it from cb with the PKTINFO_SKB_CB cast.

The previous patch moving the skb->dev change to L3 means nothing else
is needed for IPv6; it just works.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/ip_input.c
net/ipv4/ip_sockglue.c

index 247ac82..37165fb 100644 (file)
@@ -36,6 +36,7 @@
 struct sock;
 
 struct inet_skb_parm {
+       int                     iif;
        struct ip_options       opt;            /* Compiled IP options          */
        unsigned char           flags;
 
index 37375ee..4b351af 100644 (file)
@@ -478,6 +478,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
 
        /* Remove any debris in the socket control block */
        memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
+       IPCB(skb)->iif = skb->skb_iif;
 
        /* Must drop socket now because of tproxy. */
        skb_orphan(skb);
index bdb222c..5805762 100644 (file)
@@ -1193,7 +1193,12 @@ void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
                       ipv6_sk_rxinfo(sk);
 
        if (prepare && skb_rtable(skb)) {
-               pktinfo->ipi_ifindex = inet_iif(skb);
+               /* skb->cb is overloaded: prior to this point it is IP{6}CB
+                * which has interface index (iif) as the first member of the
+                * underlying inet{6}_skb_parm struct. This code then overlays
+                * PKTINFO_SKB_CB and in_pktinfo also has iif as the first
+                * element so the iif is picked up from the prior IPCB
+                */
                pktinfo->ipi_spec_dst.s_addr = fib_compute_spec_dst(skb);
        } else {
                pktinfo->ipi_ifindex = 0;