[klibc] networking problems in kinit

Hubert Feurstein h.feurstein at gmail.com
Wed Apr 22 00:47:01 PDT 2009


Hi all,

I need UDP support in kinit. But when I did the implementation I ran into some
fundamental problems, maybe someone can help me.

First, the description what I did so far:
The network interface itself has been configured by 'do_ipconfig'
with a static configuration from the kernel cmdline:
ip=192.168.1.100:192.168.1.200:192.168.1.254:255.255.255.0::eth0:

I added the following (simplified) code somewhere after 'do_ipconfig':
...
int fd;
struct sockaddr_in addr;
...
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
bindresvport(fd, 0);
	
memset( &addr, 0, sizeof( addr ) );
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr( "192.168.1.1" );
addr.sin_port = htons( 60000 );
	
connect(fd, (struct sockaddr *)&addr, sizeof(addr))
send( fd, ... some data ... )
...

But now 'connect' fails with the error "Permission denied".
I've already checked whether the network interface is really up, so
I placed a 'sleep' after 'do_ipconfig' and tried to ping the
board (ARM9 based module) during this sleep-phase which was ok,
so the interface is up and running.

I still was wondering why this simple piece of code doesn't work,
so I tried to find the place in the kernel which returns the error:
It occours in net/ipv4/datagram.c in function

int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{
	...
	err = ip_route_connect(&rt, usin->sin_addr.s_addr, saddr,
			       RT_CONN_FLAGS(sk), oif,
			       sk->sk_protocol,
			       inet->sport, usin->sin_port, sk, 1);
	if (err)
		return err;

	if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) {
		ip_rt_put(rt);
		return -EACCES; >>>>>> This throws me out <<<<<<<<<
	}
	...
}

So for me it seems, that there is something wrong or not correctly set
up in the routing table.
(But the host is within the same net, so routing is not really required).

I tried to set the socketoption SO_BROADCAST to see whether it works
then, and it did.
But of course only boardcasts were sent, and I need unicasts.

Now this brings me to the following questions:
Do I have to do anything special to use UDP networking in early userspace?
Did I miss something in the configuration of the network interface or
routing table?

Any help is very appreciated.
Thanks in advance.

best regards
Hubert



More information about the klibc mailing list