Skip to content

Commit 0b922b7

Browse files
David Aherndavem330
authored andcommitted
net: original ingress device index in PKTINFO
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>
1 parent 74b2058 commit 0b922b7

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

include/net/ip.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
struct sock;
3737

3838
struct inet_skb_parm {
39+
int iif;
3940
struct ip_options opt; /* Compiled IP options */
4041
unsigned char flags;
4142

net/ipv4/ip_input.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
478478

479479
/* Remove any debris in the socket control block */
480480
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
481+
IPCB(skb)->iif = skb->skb_iif;
481482

482483
/* Must drop socket now because of tproxy. */
483484
skb_orphan(skb);

net/ipv4/ip_sockglue.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,12 @@ void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
11931193
ipv6_sk_rxinfo(sk);
11941194

11951195
if (prepare && skb_rtable(skb)) {
1196-
pktinfo->ipi_ifindex = inet_iif(skb);
1196+
/* skb->cb is overloaded: prior to this point it is IP{6}CB
1197+
* which has interface index (iif) as the first member of the
1198+
* underlying inet{6}_skb_parm struct. This code then overlays
1199+
* PKTINFO_SKB_CB and in_pktinfo also has iif as the first
1200+
* element so the iif is picked up from the prior IPCB
1201+
*/
11971202
pktinfo->ipi_spec_dst.s_addr = fib_compute_spec_dst(skb);
11981203
} else {
11991204
pktinfo->ipi_ifindex = 0;

0 commit comments

Comments
 (0)