Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jul 2003 17:09:30 +0000
From:      "Matthew Grooms" <mgrooms@shrew.net>
To:        "Wes Peters" <wes@softweyr.com>, "Chuck Swiger" <cswiger@mac.com>
Cc:        "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>
Subject:   Re: broadcast udp packets ...
Message-ID:  <200307151709.h6FH9UOW055742@hole.shrew.net>
In-Reply-To: <200307111407.04591.wes@softweyr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hmmm,

>What we observed on our embedded system is the packet gets sent on all
>attached interfaces, with dest IP 255.255.255.255, and a src IP of the
>local address that has the default route.  If there isn't a default
>route, sending to 255.255.255.255 fails with "no route to host."
>

Maybe I am confused. When I use a udp socket bound to an interface,
packets that are generated from that socket get thier dest address
translated to a network specific broadcast address. Do I understad you
correctly when you say that you can generate packets destined to
255.255.255.255? Am I doing somthing different then you are? ...

int test_sock =3D socket( PF_INET, SOCK_DGRAM, 0 );
if( test_sock =3D=3D -1 )
    return -1;

struct ifreq ifr;
memset( &ifr, 0, sizeof( struct ifreq ) );
strcpy( ifr.ifr_name, config.get_service_iface() );
if( ioctl( test_sock, SIOCGIFADDR, &ifr ) =3D=3D -1 )
    return -1;

uint32_t value =3D  1;
if( setsockopt( test_sock, SOL_SOCKET, SO_BROADCAST,
    (char*) &value, sizeof( uint32_t ) ) =3D=3D -1
    return -1;

struct sockaddr_in serv_addr;
memset( &serv_addr, 0, sizeof( struct sockaddr_in ) );
memcpy( &serv_addr, &ifr.ifr_addr, sizeof( struct sockaddr_in ) );
serv_addr.sin_family =3D AF_INET;
serv_addr.sin_port   =3D htons( config.get_service_port() );

if( bind( test_sock, ( struct sockaddr * ) &serv_addr,
    sizeof( struct sockaddr_in ) ) =3D=3D - 1)
    return -1;

struct sockaddr_in bcast_addr;
memset( &bcast_addr, 0, sizeof( struct sockaddr_in ) );
bcast_addr.sin_family      =3D AF_INET;
bcast_addr.sin_addr.s_addr =3D 0xffffffff;
bcast_addr.sin_port        =3D htons( 100 );

char test_buff[] =3D { "TEST123TEST123" };
if( sendto( test_sock, test_buff, sizeof( test_buff ), 0,
    ( const struct sockaddr * ) &bcast_addr,
    sizeof( const struct sockaddr_in ) ) =3D=3D -1 )
    printf( "failed to generate broadcast packet( %d bytes )\n",
    sizeof( test_buff ) );
else
    printf( "broadcast packet generated ( %d bytes )\n",
    sizeof( test_buff ) );

>This is bogus, so I propose to change it to a special case, where
>packets sent to 255.255.255.255 will be sent on each attached
>interface, with src IP of the interface "primary" address.

When you say attached, do you mean the socket is bound to the ip address
of that interface or do you mean all configured interfaces on that host?
Should this be affected by the MSG_DONTROUTE flag? It would seem that if
you were requesting the packet be routed, that it would be emmitted on
all network interfaces. If the MSG_DONTROUTE were passed, that the
packet would only be generated on the interface the socket is bound to.

Then again, maybe I don't understand the scope of your proposal from
down here in userland. Im not a kernel hacker :(

>sound reasonable?  Should it work without a default route?  (I think it
>should, the special case of the all-call broadcast shouldn't even go
>into rtalloc.)
>
>I hope to have a working prototype done, on either -STABLE or -CURRENT,
>this weekend.  If testers like the behavior, I'll commit to CURRENT and
>MFC on a normal timeline; we'll want this fixed here before 5.2.
>

-Matthew



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200307151709.h6FH9UOW055742>