Subject: Re: [1/1] netlink: fix broadcasting to the wrong group.

From: Patrick McHardy <[email-masked]>
Date: Tue, 18 Apr 2006 01:13:35 +0200

Evgeniy Polyakov wrote:
> On Mon, Apr 17, 2006 at 10:14:58PM +0200, Patrick McHardy ([email-masked]) wrote:
> 
>>Not exactly, its not related to the group number. groups used in bind()
>>are considered as bitmask and groups used for setsockopt are considered
>>as group numbers. We can't change bind() because this behaviour is
>>required for compatibility.
> 
> 
> So bind and subscribing are almost exclusive and should not be used
> simultaneously?

No. You have to use bind() if you want to use a socket for sending.
bind() will overwrite the lower 32 groups with whatever is specified
in struct nladdr, if you have used setsockopt(NETLINK_ADD_MEMBERSHIP)
before the call to bind() for a group <= 32 you have to specify the
same group mask or it will get changed. Usually you would call bind()
first if you intend to use the socket for sending and subscribe
to multicast groups afterwards.

>>>But this introduce some problem with subscribing - if one subscribes to
>>>group 5 and is bound to the same group it allows to broadcast not only
>>>to group 5, and those which have the same bits set, but also to group 16
>>>(1<<(5-1)), which has nothing in common with the requested group number.
>>
>>Only if you use group numbers for bind(), which is plainly wrong.
> 
> 
> Even if one uses group bitmask at bind time and later subscribes to
> some group from that bitmask, this will introduce wrong behaviour with
> unrelated gropus.
> Maybe we should not allow to subscribe if group bitmask different from 1
> was used at bind() time?

I went over your mails again, but I don't understand the problem you're
seeing. Please just make a simple example showing the operation +
the arguments you're using to bind to group 5 which would result in
bit 0 beeing set or the kernel deciding to send to group 1 for some
other reason.