I have an embedded linux system with two network interfaces (lan0, wlan0) that are configured to the same subnet. A server on this system accepts tcp connections on both interfaces.
How I can assure that that all responses for a session are send on the same interface that the request was received on? I.e. how can all traffic of a tcp session be limited to a specific network interface?
The listen() socket and the accepted sockets can be bound to an interface/device with setsockopt(fd, BIND_TO_DEVICE). The server does this for both interfaces. This helps to detect on which interface the session was created and to limit the outbound traffic to the same interface.
But when the accept() happens, the SYN-ACK is send back to the client and a problem seems to be that this initial packet can be send over the other (wrong) interface because of the ARP lookup. The arp can find the ip address of the client on the other/"wrong" interface because the client is also visible there.