[PATCH] server: Use SO_BINDTODEVICE in bind_to_index() if possible.

Paul Gofman pgofman at codeweavers.com
Tue Oct 12 13:06:47 CDT 2021


Bug 33008 looks like about this. Bug 50499 is not related, that one is 
about SO_REUSEADDR explicitly used by an app (and not set by us to 
workaround broadcast issue) and behaving differently on Windows and 
Linux WRT which socket receives packets. I guess Bug 50499 can only be 
solved by using SO_ATTACH_REUSEPORT_CBPF as suggested there. But it is 
likely more complicated than just adding a filter as we probably need to 
track the 'reuse port' groups and adjust the filter accordingly on new 
binds and socket close. That should be easier now I guess when this all 
happens in wineserver than it would be before.

On 10/12/21 20:50, Stefan Dösinger wrote:
> Does this qualify for Wine-bug: 50499 and 33008?
>
>> Am 12.10.2021 um 19:55 schrieb Paul Gofman <pgofman at codeweavers.com>:
>>
>> Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
>> ---
>>     Using SO_REUSEADDR is currently problematic when more than one UDP socket is bound
>>     to different interfaces. While that succeeds, it is unspecified which socket will
>>     receive a packet coming to INADDR_ANY. The filter being installed for each socket
>>     with SO_ATTACH_FILTER can only reject the packet coming for another interface but
>>     that rejected packed doesn't arrive to another socket.
>>
>>     SO_BINDTODEVICE seems to do exactly what we want without installing any socket
>>     filters and without requiring SO_REUSEADDR or SO_REUSEPORT. It originally considered
>>     for implementing broadcast listen on interface bound sockets but it wasn't much
>>     useful by that time as the SO_BINDTODEVICE required CAP_NET_RAW privilege which
>>     is normally not available for a non-root user. However, that changed since Linux 5.7
>>     [2].
>>
>>     This patch uses SO_BINDTODEVICE but falls back to the previous way if that fails.
>>
>>     1. https://www.winehq.org/pipermail/wine-devel/2011-October/092681.html
>>     2. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=c427bfec18f2190b8f4718785ee8ed2db4f84ee6
>>
>> server/sock.c | 28 ++++++++++++++++++++++------
>> 1 file changed, 22 insertions(+), 6 deletions(-)




More information about the wine-devel mailing list