public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] issue with raw bsd sockets
@ 2009-08-07 11:39 Mandeep Sandhu
  2009-08-07 12:49 ` Sergei Gavrikov
  0 siblings, 1 reply; 8+ messages in thread
From: Mandeep Sandhu @ 2009-08-07 11:39 UTC (permalink / raw)
  To: ecos-discuss

Hi,

I'm using the FreeBSD stack on my Linux Synthetic target to implement
a tiny DHCP
server. I can receive DHCP REQUEST packets coming over the tap interface, but am
unable to send back the broadcast resp packet (DHCP Offer).

I'm using raw socket to send a UDP packet on the IP broadcast addr
255.255.255.255.

I'm setting the MSG_DONTROUTE flag while making the sendto() call.

Basically in ip_output, if dont route flag is set, it tries to find an
interface using the network
address. In this case it wont be available as there is no interface
for the broadcast IP (my
local eth0's IP addr is 10.1.1.1).

Is this a bug in the stack or is there something wrong in the way I'm
trying to send the UDP
packet?

Any hint's appreciated.

Thanks,
-mandeep

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] issue with raw bsd sockets
  2009-08-07 11:39 [ECOS] issue with raw bsd sockets Mandeep Sandhu
@ 2009-08-07 12:49 ` Sergei Gavrikov
  2009-08-07 14:10   ` Mandeep Sandhu
  0 siblings, 1 reply; 8+ messages in thread
From: Sergei Gavrikov @ 2009-08-07 12:49 UTC (permalink / raw)
  To: Mandeep Sandhu; +Cc: ecos-discuss

Mandeep Sandhu wrote:
> I'm using the FreeBSD stack on my Linux Synthetic target to implement
> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
> tap interface, but am unable to send back the broadcast resp packet
> (DHCP Offer).
 
[snip]

> Any hint's appreciated.

Hi Mandeep,

I call that recently Jay Foster share on the list a solution
http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
Follow this thread. HIH.

Sergei

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] issue with raw bsd sockets
  2009-08-07 12:49 ` Sergei Gavrikov
@ 2009-08-07 14:10   ` Mandeep Sandhu
  2009-08-07 16:19     ` Jay Foster
  0 siblings, 1 reply; 8+ messages in thread
From: Mandeep Sandhu @ 2009-08-07 14:10 UTC (permalink / raw)
  To: Sergei Gavrikov; +Cc: ecos-discuss

On Fri, Aug 7, 2009 at 6:21 PM, Sergei
Gavrikov<sergei.gavrikov@gmail.com> wrote:
> Mandeep Sandhu wrote:
>> I'm using the FreeBSD stack on my Linux Synthetic target to implement
>> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
>> tap interface, but am unable to send back the broadcast resp packet
>> (DHCP Offer).
>
> [snip]
>
>> Any hint's appreciated.
>
> Hi Mandeep,
>
> I call that recently Jay Foster share on the list a solution
> http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
> Follow this thread. HIH.

Thanks Sergei. This is _exactly_ my problem too.

Though this patch didn't help much. Now my IP broadcast addr is not
converted to the subnet bcast addr of the interface...but my ip_output
function fails when trying to get an interface for 255.255.255.255

Here's where it fails:

packages/net/bsd_tcpip/v3_0/src/sys/netinet/ip_output.c

<snip>
...
    if (flags & IP_ROUTETOIF) {
        if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
            (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { <<---- PROBLEM!
            ipstat.ips_noroute++;
            error = ENETUNREACH; <<-- shows up as 'Network is unreachable'
            goto bad;
        }
        ifp = ia->ia_ifp;
        ip->ip_ttl = 1;
        isbroadcast = in_broadcast(dst->sin_addr, ifp);
    }
...
</snip>

Any other clue? Or should I switch stack to LWIP? Any idea if this works in
LWIP?

Looking at the same function in lwip stack...I see it picks up the
default interface
if the route lookup does not find a suitable match.

Thanks,
-mandeep

>
> Sergei
>

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] issue with raw bsd sockets
  2009-08-07 14:10   ` Mandeep Sandhu
@ 2009-08-07 16:19     ` Jay Foster
  2009-08-07 16:35       ` [ECOS] " Grant Edwards
                         ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jay Foster @ 2009-08-07 16:19 UTC (permalink / raw)
  To: Mandeep Sandhu; +Cc: ecos-discuss

DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast address. 
You probably need to set the interface broadcast address to match.  You 
may also need to add a route to allow broadcasts.  Look at the 
DHCP/BOOTP eCos code.  It does some of this too.

Jay

Mandeep Sandhu wrote:
> On Fri, Aug 7, 2009 at 6:21 PM, Sergei
> Gavrikov<sergei.gavrikov@gmail.com> wrote:
>> Mandeep Sandhu wrote:
>>> I'm using the FreeBSD stack on my Linux Synthetic target to implement
>>> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
>>> tap interface, but am unable to send back the broadcast resp packet
>>> (DHCP Offer).
>> [snip]
>>
>>> Any hint's appreciated.
>> Hi Mandeep,
>>
>> I call that recently Jay Foster share on the list a solution
>> http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
>> Follow this thread. HIH.
> 
> Thanks Sergei. This is _exactly_ my problem too.
> 
> Though this patch didn't help much. Now my IP broadcast addr is not
> converted to the subnet bcast addr of the interface...but my ip_output
> function fails when trying to get an interface for 255.255.255.255
> 
> Here's where it fails:
> 
> packages/net/bsd_tcpip/v3_0/src/sys/netinet/ip_output.c
> 
> <snip>
> ...
>     if (flags & IP_ROUTETOIF) {
>         if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
>             (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { <<---- PROBLEM!
>             ipstat.ips_noroute++;
>             error = ENETUNREACH; <<-- shows up as 'Network is unreachable'
>             goto bad;
>         }
>         ifp = ia->ia_ifp;
>         ip->ip_ttl = 1;
>         isbroadcast = in_broadcast(dst->sin_addr, ifp);
>     }
> ...
> </snip>
> 
> Any other clue? Or should I switch stack to LWIP? Any idea if this works in
> LWIP?
> 
> Looking at the same function in lwip stack...I see it picks up the
> default interface
> if the route lookup does not find a suitable match.
> 
> Thanks,
> -mandeep
> 
>> Sergei
>>
> 

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ECOS]  Re: issue with raw bsd sockets
  2009-08-07 16:19     ` Jay Foster
@ 2009-08-07 16:35       ` Grant Edwards
  2009-08-07 17:40         ` Mandeep Sandhu
  2009-08-07 17:41       ` [ECOS] " Mandeep Sandhu
  2009-08-10  6:31       ` Mandeep Sandhu
  2 siblings, 1 reply; 8+ messages in thread
From: Grant Edwards @ 2009-08-07 16:35 UTC (permalink / raw)
  To: ecos-discuss

On 2009-08-07, Jay Foster <jay@systech.com> wrote:

> DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast
> address.  You probably need to set the interface broadcast
> address to match.  You may also need to add a route to allow
> broadcasts.  Look at the DHCP/BOOTP eCos code.  It does some
> of this too.

IMO, this is a major bit of suckage in the BSD network stack.
People have been complaining about it for a long time, and
we've tripped over it several times under eCos.

Under Linux, you can set the destination IP address to
255.255.255.255, and it gets sent to 255.255.255.255.  IOW, it
"just works".  Under BSD and eCos you've got to jump through
all sorts of hoops to send a broadast packet.

-- 
Grant Edwards                   grante             Yow! I'm a GENIUS!  I want
                                  at               to dispute sentence
                               visi.com            structure with SUSAN
                                                   SONTAG!!


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] Re: issue with raw bsd sockets
  2009-08-07 16:35       ` [ECOS] " Grant Edwards
@ 2009-08-07 17:40         ` Mandeep Sandhu
  0 siblings, 0 replies; 8+ messages in thread
From: Mandeep Sandhu @ 2009-08-07 17:40 UTC (permalink / raw)
  To: Grant Edwards; +Cc: ecos-discuss

On Fri, Aug 7, 2009 at 10:04 PM, Grant Edwards<grant.b.edwards@gmail.com> wrote:
> On 2009-08-07, Jay Foster <jay@systech.com> wrote:
>
>> DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast
>> address.  You probably need to set the interface broadcast
>> address to match.  You may also need to add a route to allow
>> broadcasts.  Look at the DHCP/BOOTP eCos code.  It does some
>> of this too.
>
> IMO, this is a major bit of suckage in the BSD network stack.

I agree, this sucks! Is there nothing like a default interface here?

> People have been complaining about it for a long time, and
> we've tripped over it several times under eCos.
>
> Under Linux, you can set the destination IP address to
> 255.255.255.255, and it gets sent to 255.255.255.255.  IOW, it
> "just works".  Under BSD and eCos you've got to jump through
> all sorts of hoops to send a broadast packet.
>
> --
> Grant Edwards                   grante             Yow! I'm a GENIUS!  I want
>                                  at               to dispute sentence
>                               visi.com            structure with SUSAN
>                                                   SONTAG!!
>
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] issue with raw bsd sockets
  2009-08-07 16:19     ` Jay Foster
  2009-08-07 16:35       ` [ECOS] " Grant Edwards
@ 2009-08-07 17:41       ` Mandeep Sandhu
  2009-08-10  6:31       ` Mandeep Sandhu
  2 siblings, 0 replies; 8+ messages in thread
From: Mandeep Sandhu @ 2009-08-07 17:41 UTC (permalink / raw)
  To: Jay Foster; +Cc: ecos-discuss

On Fri, Aug 7, 2009 at 9:50 PM, Jay Foster<jay@systech.com> wrote:
> DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast address. You
> probably need to set the interface broadcast address to match.  You may also
> need to add a route to allow broadcasts.  Look at the DHCP/BOOTP eCos code.
>  It does some of this too.
Good idea. I'll refer to the dhcp client test code...that works with
my system...

Thanks,
-mandeep

>
> Jay
>
> Mandeep Sandhu wrote:
>>
>> On Fri, Aug 7, 2009 at 6:21 PM, Sergei
>> Gavrikov<sergei.gavrikov@gmail.com> wrote:
>>>
>>> Mandeep Sandhu wrote:
>>>>
>>>> I'm using the FreeBSD stack on my Linux Synthetic target to implement
>>>> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
>>>> tap interface, but am unable to send back the broadcast resp packet
>>>> (DHCP Offer).
>>>
>>> [snip]
>>>
>>>> Any hint's appreciated.
>>>
>>> Hi Mandeep,
>>>
>>> I call that recently Jay Foster share on the list a solution
>>> http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
>>> Follow this thread. HIH.
>>
>> Thanks Sergei. This is _exactly_ my problem too.
>>
>> Though this patch didn't help much. Now my IP broadcast addr is not
>> converted to the subnet bcast addr of the interface...but my ip_output
>> function fails when trying to get an interface for 255.255.255.255
>>
>> Here's where it fails:
>>
>> packages/net/bsd_tcpip/v3_0/src/sys/netinet/ip_output.c
>>
>> <snip>
>> ...
>>    if (flags & IP_ROUTETOIF) {
>>        if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
>>            (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { <<----
>> PROBLEM!
>>            ipstat.ips_noroute++;
>>            error = ENETUNREACH; <<-- shows up as 'Network is unreachable'
>>            goto bad;
>>        }
>>        ifp = ia->ia_ifp;
>>        ip->ip_ttl = 1;
>>        isbroadcast = in_broadcast(dst->sin_addr, ifp);
>>    }
>> ...
>> </snip>
>>
>> Any other clue? Or should I switch stack to LWIP? Any idea if this works
>> in
>> LWIP?
>>
>> Looking at the same function in lwip stack...I see it picks up the
>> default interface
>> if the route lookup does not find a suitable match.
>>
>> Thanks,
>> -mandeep
>>
>>> Sergei
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [ECOS] issue with raw bsd sockets
  2009-08-07 16:19     ` Jay Foster
  2009-08-07 16:35       ` [ECOS] " Grant Edwards
  2009-08-07 17:41       ` [ECOS] " Mandeep Sandhu
@ 2009-08-10  6:31       ` Mandeep Sandhu
  2 siblings, 0 replies; 8+ messages in thread
From: Mandeep Sandhu @ 2009-08-10  6:31 UTC (permalink / raw)
  To: Jay Foster; +Cc: ecos-discuss

On Fri, Aug 7, 2009 at 9:50 PM, Jay Foster<jay@systech.com> wrote:
> DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast address. You
> probably need to set the interface broadcast address to match.  You may also
> need to add a route to allow broadcasts.  Look at the DHCP/BOOTP eCos code.
>  It does some of this too.

I've setup my 'eth0' interface with a static address (config
time...not the manual setup).

IP: 10.1.1.1
netmask: 255.255.255.0
Broadcast: 255.255.255.255
gateway IP: 0
server IP: 0

Now I followed the dhcp test code to see how they are able to send
bcast UDP packets.
It set 'eth0's IP as 0.0.0.0 and the broadcast addr as
255.255.255.255. Then it adds
a route entry for the broadcast IP, where gw IP is 255.255.255.255 and
dst addr is
0.0.0.0 and device name is 'eth0'. This basically means that the
default route has gw
as 255.255.255.255 and dev eth0.

I did something similar but sans the interface setup part (cos that's
already done at setup
time). I'm pasting a part of that code. But the problem is that when I
try to add this route it
says that the 'Network is unreachable'!! :(

Should I purge the existing routing table before adding my route
entry? The dhcp code
does that via a call to cyg_route_reinit().

(i've remove error check here to keep it short...but the actual code
is checking for all
return values etc etc )

Should I try the more cumbersome 'manual' setup of eth0?

<snip>
...
struct sockaddr_in addrp;
struct ecos_rtentry route;

s = socket(AF_INET, SOCK_DGRAM, 0);
setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))
memset(&addrp, 0, sizeof(addrp));

    // Set up routing
    addrp.sin_family = AF_INET;
    addrp.sin_port = 0;
    addrp.sin_len = sizeof(addrp);  // Size of address

    /* the broadcast address is 255.255.255.255 */
    memset(&addrp.sin_addr, 255, sizeof(addrp.sin_addr));
    memset(&route, 0, sizeof(route));
    memcpy(&route.rt_gateway, &addrp, sizeof(addrp));

    addrp.sin_addr.s_addr = INADDR_ANY;
    memcpy(&route.rt_dst, &addrp, sizeof(addrp));
    memcpy(&route.rt_genmask, &addrp, sizeof(addrp));

    route.rt_dev = ifrp.ifr_name;
    route.rt_flags = RTF_UP|RTF_GATEWAY;
    route.rt_metric = 0;

    if (ioctl(s, SIOCADDRT, &route)) { /* add route */
        if (errno != EEXIST) {
            perror("SIOCADDRT 3");
            goto out;
        }
    }
...
</snip>



>
> Jay
>
> Mandeep Sandhu wrote:
>>
>> On Fri, Aug 7, 2009 at 6:21 PM, Sergei
>> Gavrikov<sergei.gavrikov@gmail.com> wrote:
>>>
>>> Mandeep Sandhu wrote:
>>>>
>>>> I'm using the FreeBSD stack on my Linux Synthetic target to implement
>>>> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
>>>> tap interface, but am unable to send back the broadcast resp packet
>>>> (DHCP Offer).
>>>
>>> [snip]
>>>
>>>> Any hint's appreciated.
>>>
>>> Hi Mandeep,
>>>
>>> I call that recently Jay Foster share on the list a solution
>>> http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
>>> Follow this thread. HIH.
>>
>> Thanks Sergei. This is _exactly_ my problem too.
>>
>> Though this patch didn't help much. Now my IP broadcast addr is not
>> converted to the subnet bcast addr of the interface...but my ip_output
>> function fails when trying to get an interface for 255.255.255.255
>>
>> Here's where it fails:
>>
>> packages/net/bsd_tcpip/v3_0/src/sys/netinet/ip_output.c
>>
>> <snip>
>> ...
>>    if (flags & IP_ROUTETOIF) {
>>        if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
>>            (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { <<----
>> PROBLEM!
>>            ipstat.ips_noroute++;
>>            error = ENETUNREACH; <<-- shows up as 'Network is unreachable'
>>            goto bad;
>>        }
>>        ifp = ia->ia_ifp;
>>        ip->ip_ttl = 1;
>>        isbroadcast = in_broadcast(dst->sin_addr, ifp);
>>    }
>> ...
>> </snip>
>>
>> Any other clue? Or should I switch stack to LWIP? Any idea if this works
>> in
>> LWIP?
>>
>> Looking at the same function in lwip stack...I see it picks up the
>> default interface
>> if the route lookup does not find a suitable match.
>>
>> Thanks,
>> -mandeep
>>
>>> Sergei
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-08-10  6:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-07 11:39 [ECOS] issue with raw bsd sockets Mandeep Sandhu
2009-08-07 12:49 ` Sergei Gavrikov
2009-08-07 14:10   ` Mandeep Sandhu
2009-08-07 16:19     ` Jay Foster
2009-08-07 16:35       ` [ECOS] " Grant Edwards
2009-08-07 17:40         ` Mandeep Sandhu
2009-08-07 17:41       ` [ECOS] " Mandeep Sandhu
2009-08-10  6:31       ` Mandeep Sandhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).