0

I have a Linux machine with two interfaces that have IPv4 addresses belonging to the same subnet. In my application, I create two sockets (AF_INET, SOCK_DGRAM), bind them to the respective interface IP addresses and apply the SO_BINDTODEVICE socket option with the corresponding interface name. The understanding is that when I send a UDP unicast packet through each socket, it goes out through the corresponding NIC. (see Linux: Bind UDP listening socket to specific interface (or find out the interface a datagram came in from)?).

My query is about the ARP request that precedes the actual UDP packet. Does SO_BINDTODEVICE also ensure that the ARP request goes out through the same NIC to which the socket responsible for generation of ARP is bound? Or does it depend only on the destination IP address?

This information is significant for me as the two NICs of a host connect to two independent networks managed by two switches. So if host A wants to communicate to host B's second address, the packet (both UDP and ARP) has to go out through A's second NIC.

PS: I'm aware that the problem will go away if I simply use two different subnets for the two networks.

Syam
  • 163
  • 1
  • 8
  • Linux seems to have separate ARP caches for each network interface. For this reason I think that Linux would be able to manage two different computers with the same IP address but different MAC addresses in the two networks. In this case the ARP request must of course be sent from the correct interface, however, it would be possible that the request is sent to both interfaces. – Martin Rosenau Sep 17 '20 at 17:14
  • I do not have two hosts (or two interfaces in one host) with the same IP address. The IP assesses of all interfaces are different. It's just that the first interfaces of all hosts are connected to one network (by a switch) and all the second interfaces to another network. And the first and second interfaces addresses belong to the same subnet. – Syam Sep 17 '20 at 21:20
  • Let's say one network card has the address 10.0.0.2 and the other one has the address 10.0.0.3. You want to send an UDP packet to 10.0.0.100. **I'm not sure**, but I think Linux would be capable to handle this due to the separate ARP caches even if you had two computers with the address 10.0.0.100 (one connected to each network card). This is of course only possible if Linux sends **different** ARP requests to resolve 10.0.0.100 depending on the source IP address (10.0.0.2 or 10.0.0.3). – Martin Rosenau Sep 18 '20 at 04:59

0 Answers0