From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Greear Subject: Re: The SO_BINDTODEVICE was set to the desired interface, but packets are received from all interfaces. Date: Mon, 7 May 2018 09:14:17 -0700 Message-ID: <5361bef8-bdf9-af3d-12ae-a128b6502d2e@candelatech.com> References: <5a61e34b-75c2-0452-d6e2-6e4ea77d5ac2@oktetlabs.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Konstantin Ushakov , "Alexandra N. Kossovsky" , Andrey Dmitrov To: Damir Mansurov , netdev@vger.kernel.org Return-path: Received: from mail2.candelatech.com ([208.74.158.173]:45796 "EHLO mail2.candelatech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbeEGQOU (ORCPT ); Mon, 7 May 2018 12:14:20 -0400 In-Reply-To: <5a61e34b-75c2-0452-d6e2-6e4ea77d5ac2@oktetlabs.ru> Sender: netdev-owner@vger.kernel.org List-ID: 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 > dnman@oktetlabs.ru -- Ben Greear Candela Technologies Inc http://www.candelatech.com