On 05/07/2018 03:19 AM, Damir Mansurov wrote:
Greetings,
After successful call of the setsockopt(SO_BINDTODEVICE) function to set data
reception from only one interface, the data is still received from all
interfaces.
Function setsockopt() returns 0 but then recv() receives data from all
available network interfaces.
The problem is reproducible on linux kernels 4.14 - 4.16, but it does not on
linux kernels 4.4, 4.13.
I have written C-code to reproduce this issue (see attached files b2d_send.c
and b2d_recv.c). See below explanation of tested configuration.
Hello,
I am not sure if this is your problem or not, but if you are using VRF, then
you need
to call SO_BINDTODEVICE before you do the 'normal' bind() call.
Thanks,
Ben
PC-1 PC-2
------------------- -------------------
| b2d_send | | b2d_recv |
| | | |
| ------| |------ |
| | eth0 |---------------| eth0 | |
| ------| |------ |
| | | |
| ------| |------ |
| | eth1 |---------------| eth1 | |
| ------| |------ |
| | | |
------------------- -------------------
Steps:
1. Copy b2d_recv.c to PC-2, compile it ("gcc -o b2d_recv b2d_recv.c") and run
"./b2d_recv eth0 23777" to get derived data only from eth0 interface. Port number
in this example is 23777 only for sample.
2. Copy b2d_send.c to PC-1, compile it ("gcc -o b2d_send b2d_send.c") and run
"./b2d_send ip1 ip2 23777" where ip1 and ip2 are ip addresses of interfaces eth0
and eth1 of PC-2.
3. Result:
- b2d_recv prints out data from eth0 and eth1 on linux kernels from 4.14 up to
4.16.
- b2d_recv prints out data from only eth0 on linux kernels below 4.14.
******************
Thanks,
Damir Mansurov
[email protected]
--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com