Skip to content

Commit f0c16ba

Browse files
asuka2001davem330
authored andcommitted
net: fix incorrect original ingress device index in PKTINFO
When we send a packet for our own local address on a non-loopback interface (e.g. eth0), due to the change had been introduced from commit 0b922b7 ("net: original ingress device index in PKTINFO"), the original ingress device index would be set as the loopback interface. However, the packet should be considered as if it is being arrived via the sending interface (eth0), otherwise it would break the expectation of the userspace application (e.g. the DHCPRELEASE message from dhcp_release binary would be ignored by the dnsmasq daemon, since it come from lo which is not the interface dnsmasq bind to) Fixes: 0b922b7 ("net: original ingress device index in PKTINFO") Acked-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: Wei Zhang <asuka.com@163.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4775cc1 commit f0c16ba

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

net/ipv4/ip_sockglue.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,14 @@ void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
12251225
* which has interface index (iif) as the first member of the
12261226
* underlying inet{6}_skb_parm struct. This code then overlays
12271227
* PKTINFO_SKB_CB and in_pktinfo also has iif as the first
1228-
* element so the iif is picked up from the prior IPCB
1228+
* element so the iif is picked up from the prior IPCB. If iif
1229+
* is the loopback interface, then return the sending interface
1230+
* (e.g., process binds socket to eth0 for Tx which is
1231+
* redirected to loopback in the rtable/dst).
12291232
*/
1233+
if (pktinfo->ipi_ifindex == LOOPBACK_IFINDEX)
1234+
pktinfo->ipi_ifindex = inet_iif(skb);
1235+
12301236
pktinfo->ipi_spec_dst.s_addr = fib_compute_spec_dst(skb);
12311237
} else {
12321238
pktinfo->ipi_ifindex = 0;

0 commit comments

Comments
 (0)