From: Blaisorblade <blaisorblade@yahoo.it>
To: Nic James Ferrier <nferrier@tapsellferrier.co.uk>
Cc: user-mode-linux-devel@lists.sourceforge.net,
user-mode-linux-user@lists.sourceforge.net
Subject: Re: [uml-devel] [uml-user] proc filesystem ipaddress
Date: Sun, 15 Oct 2006 19:24:04 +0200 [thread overview]
Message-ID: <200610151924.04559.blaisorblade@yahoo.it> (raw)
In-Reply-To: <871wpb16c3.fsf@nicferrier.tapsellferrier.co.uk>
On Saturday 14 October 2006 13:31, Nic James Ferrier wrote:
> Blaisorblade <blaisorblade@yahoo.it> 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-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
next prev parent reply other threads:[~2006-10-15 17:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1GYDno-0007SX-JC@nicferrier.tapsellferrier.co.uk>
2006-10-14 1:46 ` [uml-devel] [uml-user] proc filesystem ipaddress Blaisorblade
2006-10-14 1:50 ` Blaisorblade
2006-10-14 11:31 ` Nic James Ferrier
2006-10-15 17:24 ` Blaisorblade [this message]
2006-10-15 23:32 ` Nic James Ferrier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200610151924.04559.blaisorblade@yahoo.it \
--to=blaisorblade@yahoo.it \
--cc=nferrier@tapsellferrier.co.uk \
--cc=user-mode-linux-devel@lists.sourceforge.net \
--cc=user-mode-linux-user@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox