On 2011/04/24 10:42, Claudio Jeker wrote:
> On Sat, Apr 23, 2011 at 08:58:12PM +0000, Stuart Henderson wrote:
> > On 2011-04-23, Henning Brauer <lists-openbsdpo...@bsws.de> wrote:
> > > * Stuart Henderson <s...@spacehopper.org> [2011-04-23 14:41]:
> > >> Should we do this or should we rethink allowing sockets to be
> > >> bound to broadcast IP addresses?
> > >
> > > i have no idea. and that seems to be common for all of us. i really
> > > dunno. anybody?
> > >
> > 
> > Unless there are objections I'll commit my samba diff tomorrow,
> > it can always come out again if anything else changes.
> 
> What is this socket used for? You can not send a packet out of that
> socket. I guess it is a UDP socket that should pickup the broadcast hellos
> that flood windows infested networks.

Yes, exactly.

> Our network stack will deliver broadcast datagram to all IP RAW and all
> UDP dgram sockets that match and are bound to 0.0.0.0 or ::.
>
> /*
>  * Deliver a multicast or broadcast datagram to *all* sockets
>  * for which the local and remote addresses and ports match
>  * those of the incoming datagram.  This allows more than
>  * one process to receive multi/broadcasts on the same port.
> 
> Now there is this bit of code in the loop as well:
> if (inp->inp_laddr.s_addr != INADDR_ANY) {
>       if (inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
>               continue;
> }
> 
> So it may make sense to bind to a specific broadcast addr for SOCK_DGRAM
> and SOCK_RAW AF_INET socks. In that case you only receive packets that are
> sent to the network specific broadcast (this does not work for
> packets sent to 255.255.255.255 on that LAN segment)

That would look something like this horror..

Index: in_pcb.c
===================================================================
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.116
diff -u -p -r1.116 in_pcb.c
--- in_pcb.c    19 Apr 2011 03:47:29 -0000      1.116
+++ in_pcb.c    24 Apr 2011 11:31:56 -0000
@@ -276,8 +276,12 @@ in_pcbbind(v, nam, p)
                } else if (sin->sin_addr.s_addr != INADDR_ANY) {
                        sin->sin_port = 0;              /* yech... */
                        if (!(so->so_options & SO_BINDANY) &&
-                           in_iawithaddr(sin->sin_addr,
-                           inp->inp_rtableid) == NULL)
+                           (ifa_ifwithaddr(sintosa(&sin),
+                           inp->inp_rtableid) == NULL) &&
+                           (so->so_type != SOCK_DGRAM) &&
+                           (so->so_type != SOCK_RAW) &&
+                           (in_iawithaddr(sin->sin_addr,
+                           inp->inp_rtableid) == NULL))
                                return (EADDRNOTAVAIL);
                }
                if (lport) {

Reply via email to