Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In my Linux target I have an interface, say if0. The interface IP for this if0 is 128.0.0.16. There is a process P1, which has opened a raw socket (AF_INET, SOCK_RAW, xyz_protocol). It has done a SO_BINDTODEVICE to this interface if0. The socket also binds to this local interface IP address (128.0.0.16). Now this process (thru' this socket) is able to recvfrom() all packets arriving form a different Linux machine to this interface destined for this xyz_protocol. Everything is fine until now.
Now, there is another local process P2 running in the same machine as process P1. This process P2 also has a requirement to send similar xyz_protocol packets to this process P1. We don't want to create a separate IPC channel between these two processes. Rather we want to use the same socket infra. So, from process P2, I am again opening a similar socket (AF_INET, SOCK_RAW, xyz_protocol). I also do the same SO_BINDTODEVICE to this interface if0. The socket also binds to the same local interface IP address, as done by P1. The bind() is OK/success.
Now I send a packet from process P2 with both source and destination IP as 128.0.0.16. I am expecting the process P1 to receive the packet, as 128.0.0.16 is a local interface IP and the IP layer is supposed to loop it back to the higher application waiting for this xyz_protocol. But P1 doesn't seem to receive it.
My question is, is this is the right way of doing it. Of course it is not, as it is not working... Then how else can P2's packet can be made to be received by P1.
If destination & source address match, what is the logic inside IP stack. Will it blindly loop it back to higher layers?
In process P1 we make the socket to do a SO_BINDTODEVICE to if0? Is that the reason why is not able to receive the local packets from process P2. I read through some linux man pages. It says that SO_BINDTODEVICE will make the socket to receive packets only from the associated interface. Maybe that's why its not honoring the local packets from process P2?
Is there a reason you are binding to a specific interface, and not just to the IP?
Yes, as you mentioned, SO_BINDTODEVICE means "If a socket is bound to an interface, only packets received from that particular interface are processed by the socket." - see http://linux.die.net/man/7/socket.
Local traffic is usually not sent out onto the network, so these packets would not be received via the (physical) interface you have bound to.
There are some settings which, together with appropriate routing, could be used to force traffic out onto the wire between 2 local interfaces, namely:
Thanks for the clarification. SO_BINDTODEVICE to the interface is in a piece of code which i don't own. The owner is of the opinion that this socket should receive the traffic from that interface *ONLY*. Hence this SO_BINDTODEVICE has been done.
Binding the interface IP to socket will only ensure that traffic leaving the system from this socket will have src IP as this IP.
However, it will not ensure that this socket will receive traffic only from this interface.. Am i right?
Binding the interface IP to socket will only ensure that traffic leaving the system from this socket will have src IP as this IP.
However, it will not ensure that this socket will receive traffic only from this interface.. Am i right?
No, as far as I know, SO_BINDTODEVICE means "If a socket is bound to an interface, only packets received from that particular interface are processed by the socket." - see http://linux.die.net/man/7/socket.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.