Skip to content

Commit cbea8f0

Browse files
dsaherndavem330
authored andcommitted
net: ipv4: fix l3slave check for index returned in IP_PKTINFO
rt_iif is only set to the actual egress device for the output path. The recent change to consider the l3slave flag when returning IP_PKTINFO works for local traffic (the correct device index is returned), but it broke the more typical use case of packets received from a remote host always returning the VRF index rather than the original ingress device. Update the fixup to consider l3slave and rt_iif actually getting set. Fixes: 1dfa763 ("net: ipv4: add check for l3slave for index returned in IP_PKTINFO") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2aa70f8 commit cbea8f0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/ipv4/ip_sockglue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,
12071207
void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
12081208
{
12091209
struct in_pktinfo *pktinfo = PKTINFO_SKB_CB(skb);
1210-
bool l3slave = ipv4_l3mdev_skb(IPCB(skb)->flags);
12111210
bool prepare = (inet_sk(sk)->cmsg_flags & IP_CMSG_PKTINFO) ||
12121211
ipv6_sk_rxinfo(sk);
12131212

@@ -1221,8 +1220,13 @@ void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
12211220
* (e.g., process binds socket to eth0 for Tx which is
12221221
* redirected to loopback in the rtable/dst).
12231222
*/
1224-
if (pktinfo->ipi_ifindex == LOOPBACK_IFINDEX || l3slave)
1223+
struct rtable *rt = skb_rtable(skb);
1224+
bool l3slave = ipv4_l3mdev_skb(IPCB(skb)->flags);
1225+
1226+
if (pktinfo->ipi_ifindex == LOOPBACK_IFINDEX)
12251227
pktinfo->ipi_ifindex = inet_iif(skb);
1228+
else if (l3slave && rt && rt->rt_iif)
1229+
pktinfo->ipi_ifindex = rt->rt_iif;
12261230

12271231
pktinfo->ipi_spec_dst.s_addr = fib_compute_spec_dst(skb);
12281232
} else {

0 commit comments

Comments
 (0)