2002-06-10 23:20:48

by Paul Menage

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

In article <[email protected]>,
you write:
>Is there any documentation on the netlink API, beyond UTSL(iproute)?
>Reference would be good, but a tutorial would be ideal.

The man pages for netlink(3), netlink(7), rtnetlink(3) and rtnetlink(7)
give a basic reference.

Paul


2002-06-10 23:35:42

by Brad Hards

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

On Tue, 11 Jun 2002 09:20, Paul Menage wrote:
> In article <[email protected]>,
>
> you write:
> >Is there any documentation on the netlink API, beyond UTSL(iproute)?
> >Reference would be good, but a tutorial would be ideal.
>
> The man pages for netlink(3), netlink(7), rtnetlink(3) and rtnetlink(7)
> give a basic reference.
Unfortunately my brain is not on the same level and scope as Alexey or davem.

I simply don't grok those pages. I also note caveats about incompleteness, and
recommendation to use libnetlink, which is also not documented much.

I sometimes hack on zcip (see ftp://ftp.kernel.org/pub/software/network/zcip
for an out of date version), and it could really use some netlink-ification.
But I can't even follow enough of iproute (or zebra, which also uses netlink,
AFAICT) to figure out how to do basic stuff like a list of configured
networking devices, or set the default route.

Brad

--
http://conf.linux.org.au. 22-25Jan2003. Perth, Australia. Birds in Black.

2002-06-10 23:41:11

by Randy.Dunlap

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

On Tue, 11 Jun 2002, Brad Hards wrote:

| On Tue, 11 Jun 2002 09:20, Paul Menage wrote:
| > In article <[email protected]>,
| >
| > you write:
| > >Is there any documentation on the netlink API, beyond UTSL(iproute)?
| > >Reference would be good, but a tutorial would be ideal.
| >
| > The man pages for netlink(3), netlink(7), rtnetlink(3) and rtnetlink(7)
| > give a basic reference.
| Unfortunately my brain is not on the same level and scope as Alexey or davem.
|
| I simply don't grok those pages. I also note caveats about incompleteness, and
| recommendation to use libnetlink, which is also not documented much.

Hi Brad,

There was an announcement earlier today of some networking
documentation. I think that it's still in its early stages, though.

>From the 'netdev' list:

Hi,

I am working on a doc on "Networking Subsystem" in the Linux kernel.
This
is part of the "Linux Kernel documentation project" (http://www.lkdp.tk).

Chapter 2 of this doc is almost complete. I was hoping for some feedback
on this doc. Its available at

http://www.corewars.org/~radical/lkdp

Only Chapter 2 has been started as of now, its nearing completion.

I am looking for feedback on the contents, the general feel of the book,
flow.. etc. Any kind of feedback actually.

Thank you
-Anks

--
~Randy

2002-06-11 00:07:13

by Paul Menage

[permalink] [raw]
Subject: Re: netlink documentation (was: of ethernet names)

>But I can't even follow enough of iproute (or zebra, which also uses netlink,
>AFAICT) to figure out how to do basic stuff like a list of configured
>networking devices, or set the default route.

E.g. to get the list of devices (untested, lacking error checking, etc),
use something like:

struct {
struct nlmsghdr hdr;
struct ifinfomsg info;
} msg;
struct sockaddr_nl addr;

/* Create and bind the netlink socket */
netlink_sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);

memset(&addr, 0, sizeof(addr));

addr.nl_family = AF_NETLINK;
addr.nl_pid = getpid();
addr.nl_groups = RTMGRP_IPV4_IFADDR;

bind(netlink_sk, (struct sockaddr *)&addr, sizeof(addr)));

/* Build the netlink request */
memset(&msg, 0, sizeof(msg));
msg.hdr.nlmsg_len = sizeof(msg);
msg.hdr.nlmsg_type = RTM_GETLINK;
msg.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH;
msg.hdr.nlmsg_pid = getpid();
msg.hdr.nlmsg_seq = 0;

msg.info.ifi_family = AF_UNSPEC;
msg.info.ifi_type = 0;
msg.info.ifi_index = 0;
msg.info.ifi_change = -1;

/* Send the message */
send(netlink_sk, &msg, msg.hdr.nlmsg_len, 0);

/* Loop, as we might get replies spread over several packets */
while((bytes = recv(netlink_sk, replybuf, sizeof(replybuf), 0))) {
struct nlmsghdr *hdr = (struct nlmsghdr *)replybuf;

if(hdr->nlmsg_type == NLMSG_DONE) {
break;
}

/* Loop over the messages in this packet */
while(bytes) {
int len = hdr->nlmsg_len;

struct ifinfomsg *info = NLMSG_DATA(hdr);
struct rtattr *rta = IFLA_RTA(info);


len -= NLMSG_LENGTH(sizeof(*info));

/* Loop over the attributes in this message */
while(RTA_OK(rta, len)) {
switch(rta->rta_type) {
case IFLA_IFNAME:
printf("Found device %s - %u\n",
RTA_DATA(rta), info->ifi_index);

break;
}

rta = RTA_NEXT(rta, len);
}

bytes -= hdr->nlmsg_len;
((void *)hdr) += hdr->nlmsg_len;
}

}

Paul

2002-06-11 00:14:24

by Brad Hards

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

On Tue, 11 Jun 2002 09:36, Randy.Dunlap wrote:
> On Tue, 11 Jun 2002, Brad Hards wrote:
> | On Tue, 11 Jun 2002 09:20, Paul Menage wrote:
> | > In article
> | > <[email protected]>,
> | >
> | > you write:
> | > >Is there any documentation on the netlink API, beyond UTSL(iproute)?
> | > >Reference would be good, but a tutorial would be ideal.
> | >
> | > The man pages for netlink(3), netlink(7), rtnetlink(3) and rtnetlink(7)
> | > give a basic reference.
> |
> | Unfortunately my brain is not on the same level and scope as Alexey or
> | davem.
> |
> | I simply don't grok those pages. I also note caveats about
> | incompleteness, and recommendation to use libnetlink, which is also not
> | documented much.
>
> Hi Brad,
>
> There was an announcement earlier today of some networking
> documentation. I think that it's still in its early stages, though.
Very early, from my review :)

> From the 'netdev' list:
>
> Hi,
>
> I am working on a doc on "Networking Subsystem" in the Linux kernel.
> This
> is part of the "Linux Kernel documentation project" (http://www.lkdp.tk).
And this is the wrong focus (for me). I need documentation from the userspace
view. The documentation I need shouldn't try to explain how the kernel works,
except as needed to understand what to do in userspace. My concept is
something like the tutorial I am working on for Linux HID programming
(explaination of the various interfaces and options - see
http://www.frogmouth.net/hid-doco/linux-hid.html for an early draft).

Not to suggest we shouldn't document the kernel mechanics - this is important
too.

But kernel programmers need to remember that user space programmers will take
the path of least resistance when trying to interact with the kernel. Good
documentation and easy-to-copy examples beats a slightly more powerful API
(where slightly depends on being able to accomplish task in both APIs, even
if it gets ugly) every time. If you want people to switch over to your new
API/ABI, its got to be easy.
--
http://conf.linux.org.au. 22-25Jan2003. Perth, Australia. Birds in Black.

2002-06-11 00:19:52

by Brad Hards

[permalink] [raw]
Subject: Re: netlink documentation (was: of ethernet names)

On Tue, 11 Jun 2002 10:06, Paul Menage wrote:
> >But I can't even follow enough of iproute (or zebra, which also uses
> > netlink, AFAICT) to figure out how to do basic stuff like a list of
> > configured networking devices, or set the default route.
>
> E.g. to get the list of devices (untested, lacking error checking, etc),
> use something like:
Bingo! I think I see what is happening, just by inspection. Beverage of choice
when we meet up!

Now, how did you get this? Just familarity with the API built up over time,
pure zen, or copied from some other app?

A couple of days of playing with this, I might even be able to write the
tutorial myself :)

Brad
--
http://conf.linux.org.au. 22-25Jan2003. Perth, Australia. Birds in Black.

2002-06-11 00:41:20

by Paul Menage

[permalink] [raw]
Subject: Re: netlink documentation (was: of ethernet names)

>Now, how did you get this? Just familarity with the API built up over time,
>pure zen, or copied from some other app?

A combination of the man pages, the iproute source, and the kernel
source. It's all pretty straightforward once you get a working skeleton.

Paul

2002-06-11 02:25:23

by Andi Kleen

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

Brad Hards <[email protected]> writes:

> I simply don't grok those pages. I also note caveats about incompleteness, and
> recommendation to use libnetlink, which is also not documented much.

I'm sorry you don't like my manpages.

I also wrote some manpages on libnetlink, but for some reason they were never
merged in the main distribution so you can only find them in the SuSE rpm
or at http://www.firstfloor.org/~andi/man/libnetlink.3.gz (source)
or http://www.firstfloor.org/~andi/man/libnetlink.3.txt (formatted manpage)

Jamal Hadi wrote a ietf draft on netlink. I don't know if it's publicly
available (if yes probably somewhere on ftp.ietf.org) it describes quite
a lot of basic concepts in netlink/rtnetlink although in a bit foreign
to linux terminology.

I also did a presentation on netlink and related topics at previous to
last year's Ottawa Linux symposium which may be also helpful. The slides
are at http://www.firstfloor.org/~andi/ols/OLSpres.htm

-Andi

2002-06-11 02:37:29

by Brad Hards

[permalink] [raw]
Subject: Re: of ethernet names (was [PATCH] Futex Asynchronous

On Tue, 11 Jun 2002 12:25, Andi Kleen wrote:
> Brad Hards <[email protected]> writes:
> > I simply don't grok those pages. I also note caveats about
> > incompleteness, and recommendation to use libnetlink, which is also not
> > documented much.
>
> I'm sorry you don't like my manpages.
Make no mistake. I do like them. I am relying on them now. I just need more
explanation and examples.

> I also wrote some manpages on libnetlink, but for some reason they were
> never merged in the main distribution so you can only find them in the SuSE
> rpm or at http://www.firstfloor.org/~andi/man/libnetlink.3.gz (source) or
> http://www.firstfloor.org/~andi/man/libnetlink.3.txt (formatted manpage)
Thanks.
> Jamal Hadi wrote a ietf draft on netlink. I don't know if it's publicly
> available (if yes probably somewhere on ftp.ietf.org) it describes quite
> a lot of basic concepts in netlink/rtnetlink although in a bit foreign
> to linux terminology.
Thanks again. Found it at
ftp://ftp.isi.edu/in-notes/search.ietf.org/internet-drafts/draft-ietf-forces-netlink-03.txt

> I also did a presentation on netlink and related topics at previous to
> last year's Ottawa Linux symposium which may be also helpful. The slides
> are at http://www.firstfloor.org/~andi/ols/OLSpres.htm
Its all coming together. Thanks again.

--
http://conf.linux.org.au. 22-25Jan2003. Perth, Australia. Birds in Black.