From: Andi Kleen <ak@suse.de>
To: "David S. Miller" <davem@redhat.com>
Cc: rddunlap@osdl.org, linux-net@vger.kernel.org, netdev@oss.sgi.com
Subject: Re: netlink tester program
Date: Sat, 31 May 2003 14:09:40 +0200 [thread overview]
Message-ID: <20030531120940.GB11898@wotan.suse.de> (raw)
In-Reply-To: <20030530.234211.102567405.davem@redhat.com>
> You really need something like rtnl_talk() or rtnl_dump_filter()
> from libnetlink to do this properly.
In case it's helpful I wrote manpages for libnetlink some time ago.
I also have some simple example programs using it. Other examples
can be found in the zebra or bird source code.
-Andi
-Andi
libnetlink(3) libnetlink(3)
NAME
libnetlink - A library for accessing the netlink service
SYNOPSIS
#include <asm/types.h>
#include <libnetlink.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
int rtnl_send(struct rtnl_handle *rth, char *buf, int len)
int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
int rtnl_dump_filter(struct rtnl_handle *rth,
int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
void *arg1,
int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *arg2)
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
unsigned groups, struct nlmsghdr *answer,
int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *jarg)
int rtnl_listen(struct rtnl_handle *rtnl,
int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *jarg)
int rtnl_from_file(FILE *rtnl,
int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *jarg)
int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
DESCRIPTION
libnetlink provides a higher level interface to
rtnetlink(7). The read functions return 0 on success and
a negative errno on failure. The send functions return
the amount of data sent, or -1 on error.
rtnl_open
Open a rtnetlink socket and save the state into the
rth handle. This handle is passed to all subsequent
calls. subscriptions is a bitmap of the rtnetlink
multicast groups the socket will be a member of.
rtnl_wilddump_request
Request a full dump of the type database for family
addresses. type is a rtnetlink message type.
rtnl_dump_request
Request a full dump of the type data buffer into
buf with maximum length of len. type is a
rtnetlink message type.
rtnl_dump_filter
Receive netlink data after a request and filter it.
The filter callback checks if the received message
is wanted. It gets the source address of the mes-
sage, the message itself and arg1 as arguments. 0
as return means that the filter passed, a negative
value is returned by rtnl_dump_filter in case of
error. NULL for filter means to not use a filter.
junk is used to filter messages not destined to the
local socket. Only one message bundle is received.
Unless there is no message pending, this function
does not block.
rtnl_listen
Receive netlink data after a request and pass it to
handler. handler is a callback that gets the mes-
sage source address, the message itself, and the
jarg cookie as arguments. It will get called for
all received messages. Only one message bundle is
received. Unless there is no message pending this
function does not block.
rtnl_from_file
Works like rtnl_listen, but reads a netlink message
bundle from the file file and passes the messages
to handler for parsing. The file contains raw data
as received from a rtnetlink socket.
The following functions are useful to construct custom
rtnetlink messages. For simple database dumping with fil-
tering it is better to use the higher level functions
above. See rtnetlink(3) and netlink(3) on how to generate
a rtnetlink message. The following utility functions
require a continuous buffer that already contains a
netlink message header and a rtnetlink request.
rtnl_send
Send the rtnetlink message in buf of length len to
handle rth.
addattr32
Add a __u32 attribute of type type and with value
data to netlink message n, which is part of a
buffer of length maxlen.
addattr_l
Add a variable length attribute of type type and
with value data and alen length to netlink message
n, which is part of a buffer of length maxlen.
data is copied.
rta_addattr32
Initialize the rtnetlink attribute rta with a __u32
data value.
rta_addattr32
Initialize the rtnetlink attribute rta with a vari-
able length data value.
BUGS
The functions sometimes use fprintf and exit when a fatal
error occurs. This library should be named librtnetlink.
AUTHORS
netlink/rtnetlink was designed and written by Alexey
Kuznetsov. Andi Kleen wrote the man page.
SEE ALSO
netlink(7), rtnetlink(7)
/usr/include/linux/rtnetlink.h
libnetlink(3)
>
next prev parent reply other threads:[~2003-05-31 12:09 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-30 16:00 netlink tester program Randy.Dunlap
2003-05-31 0:11 ` David S. Miller
2003-05-31 3:22 ` Randy.Dunlap
2003-05-31 6:42 ` David S. Miller
2003-05-31 12:09 ` Andi Kleen [this message]
2003-06-02 17:07 ` Randy.Dunlap
2003-06-02 21:04 ` Randy.Dunlap
2003-06-02 21:56 ` David S. Miller
2003-06-03 1:56 ` David Brownell
2003-06-03 2:02 ` David S. Miller
2003-06-03 3:34 ` David Brownell
2003-06-03 3:38 ` David S. Miller
2003-06-03 3:49 ` Randy.Dunlap
2003-06-03 3:51 ` David S. Miller
2003-06-03 7:57 ` Hisham Kotry
2003-06-09 1:35 ` Jamal Hadi
2003-06-09 14:37 ` Mr. James W. Laferriere
2003-06-09 17:16 ` David S. Miller
2003-06-03 2:33 ` John S. Denker
2003-06-03 2:38 ` David S. Miller
2003-06-03 3:20 ` John S. Denker
2003-06-03 3:22 ` David S. Miller
2003-06-03 3:41 ` John S. Denker
2003-06-03 3:46 ` David S. Miller
2003-06-03 3:54 ` Randy.Dunlap
2003-06-03 3:54 ` David S. Miller
2003-06-03 3:37 ` David Brownell
2003-06-03 3:32 ` Randy.Dunlap
2003-06-03 3:35 ` David S. Miller
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=20030531120940.GB11898@wotan.suse.de \
--to=ak@suse.de \
--cc=davem@redhat.com \
--cc=linux-net@vger.kernel.org \
--cc=netdev@oss.sgi.com \
--cc=rddunlap@osdl.org \
/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;
as well as URLs for NNTP newsgroup(s).