On Saturday 14 October 2006 13:31, Nic James Ferrier wrote:
> Blaisorblade <[EMAIL PROTECTED]> writes:
> > On Friday 13 October 2006 05:33, Nic James Ferrier wrote:
> >> I've patched the ipv4 stack so that it does proc registration of the
> >> IP address for an iface.
> >
> > Take a look at /proc/net/if_inet6, generated by
>
> I did take a look at that. It seems to be done a bit
> differently. There's what looks like a cleaner interface to config.
>
> I may be a confident C hacker, but I'm not going to start refactoring
> the ipv4 stack with my first patch /8->

Agreed - I started kernel coding with much more stupid work (I've never coded 
_large_ programs _in C_ before working on Linux).

> > I know you're beginning to write kernel code and this is not even a
> > finished patch, however I'm commenting _various_ improvable aspects of
> > the work. Do not worry for that.

> Any comments are *very* welcome.

> I've attached a cleaner copy of my patch with my debug and sketch code
> removed. It's down to the bear essentials which is a call to ioctl to
> retrieve the address only getting 16 bits of the necessary data.

> > Also, for mainline acceptance I guess they'd prefer to bypass ioctl and
> > access directly the needed fields.

> The ipv4 config and dhcp code uses the ioctl stuff which is why I
> did. I wasn't sure about this... I think it makes more sense for the
> kernel to be able to access the fields directly as well. And it's the
> ioctl that seems to be causing the problem. However, if you don't need
> the ioctl why does the ipv4 config code call it?

Ok, that was _my_ guess, and that code _does_ skip ioctl - but if you found 
code which uses it, then there are reasons for it.

> > Beyond that, I've found your bug. You can cast a (struct sockaddr*) to a
> > (struct sockaddr_in*), but your doing a worse cast; since ifr_addr is a
> > struct sockaddr,
>
> I don't think I'm doing that:
>
>   ifreq.ifr_addr
>
>   is the same as:  ifreq.ifr_ifru.ifru_addr
>
>   which is a:  struct sockaddr

Yes, what I said.

> So ifreq.ifr_addr.sa_data is a sockaddr_in right?

Not at all. This explains the 2 missing bytes.

Both struct sockaddr and struct sockaddr_in have the first member 
(sa_family_t), which is 2 bytes wide - that's because this is like 
inheritance but in C: sockaddr_{un,in,*} are all casted to struct sockaddr 
when passing them to generic APIs (look for a bind() or connect() example to 
see this).

I can find a bind example in libc docs (having libc's info pages) with

info libc socket "internet namespace" "inet example"
it's also at:
http://www.fifi.org/doc/glibc-doc/html/chapters_16.html#SEC327

> > the _below_ version is correct:
> > if_addr = (struct sockaddr_in *) ir.ifr_addr;
>
> This doesn't compile.

Very possible, I didn't test it - I guess I forgot an &:
if_addr = (struct sockaddr_in *) &ir.ifr_addr;
I also forgot that if_addr is in bigendian order, so before printing it as an 
unsigned integer you should convert it (you'll anyway convert it to dotted 
representation I guess, when the problem will be fixed).

You can also see it in include/linux/in.h:
struct in_addr {
        __be32  s_addr;
};
__be32 is a plain 32bit integer, however sparse (a static checking tool) makes 
conversions between __be32 and __le32 or u32 impossible (it will only warn 
for that, actually). Much like it warns for conversion between __user 
pointers and normal ones.

> > This is goto out_ipaddress (the naming is misleading, ok, but compare
> > with the above goto).

> Yes... sorry, that is an ommision from a previous edit.
You also forgot to replace get_ds() with KERNEL_DS.

$ grep '\(get_ds\|KERNEL_DS\)' kernel/*.c mm/*.c
finds only examples of KERNEL_DS.

-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
User-mode-linux-user mailing list
User-mode-linux-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Reply via email to