ifplugd

Denys Vlasenko vda.linux at googlemail.com
Wed Apr 22 21:08:46 UTC 2009


On Wednesday 22 April 2009 18:06, Vladimir Dronnikov wrote:
> >>
> >> Curious, can we make a generic netlink listener? Just like tcpsvd? It
> >> could be extensively reused then. I see ifplugd itself, inotifyd,
> >> iptables ULOG helper, mdev-as-netlink-daemon at least.
> >
> > I'm try to apply it. Thanks for your opinion.
> >
> 
> I prepared a patch for generic netlink socket dumper -- nlcat.
> You can just run nlcat on one console, and try to modprobe/rmmod
> something on another
> 
> Denys, is it interesting to go on?

I propose to do it differently. Let all network applets
be able to use address of the format "netlink:XXXX".
That way, you can simply use nc to dump netlink data.

Since people normally don't want such crazy feature,
it needs to be a CONFIG_xxx.

Now to do it? Below is the copy of email I sent in response
to patch which was adding support for nc -U (Unix domain sockets).
Replace "Unix domain sockets" with "netlink"
and "local:" with "netlink:" below and you'll get
recipe for universal netlink socket support:

=============================================

Connecting to UNIX domain socket like this:

-                       cfd = create_and_connect_stream_or_die(argv[0],
-                               argv[1] ? bb_lookup_port(argv[1], "tcp", 0) : 0);
+                       if (do_local) {
+                               lsa = xzalloc(sizeof(*lsa));
+                               lsa->len = sizeof(lsa->u.sun);
+                               lsa->u.sa.sa_family = AF_UNIX;
+                               safe_strncpy(lsa->u.sun.sun_path,
+                                       argv[0], sizeof(lsa->u.sun.sun_path));
+                               cfd = xsocket(AF_UNIX, SOCK_STREAM, 0);
+                               xconnect(cfd, &lsa->u.sa, lsa->len);
+                               free(lsa);
+                       } else {
+                               cfd = create_and_connect_stream_or_die(argv[0],
+                                       argv[1] ? bb_lookup_port(argv[1], "tcp", 0) : 0);
+                       }

defeats the whole purpose of len_and_sockaddr data type
and create_and_connect_stream_or_die(name, port) function,
which is _supposed_ to_ derive the type of socket
(AF_INET? AF_INET6? AF_UNIX?...) by looking at its arguments.

Currently, it only understands IP and IPv6.

In order to make _all_ network utilities AF_UNIX capable,
it's much better to teach create_and_connect_stream_or_die
to understand some sort of AF_UNIX name.

It can be "unix:" or "local:" prefix, and/or
special port value (although this feels more like a hack,
since port param should not have been there in the first place,
it can be specified in 1st argument, name: "1.2.3.4:56",
"[12:34::56:78]:90" (IPv6), and we do understand these forms)

Unfortunately there is no standard for this syntax. Pity.
We need to invent our own, and then shoehorn nc -U into using it
internally:

echo "hi syslog!" | nc -U /dev/log >/dev/null

and internally nc.c does:

        if (option -U is given)
                 peer_name = xasprintf("local:%s", peer_name);

Tht's *all* what nc.c needs to do to support -U.
The rest is handled in create_and_connect_stream_or_die!

And then you also can do this:

echo "hi syslog!" | nc local:/dev/log >/dev/null

Or this:

httpd -p local:/var/run/httpd.socket

Or this:

tcpsvd -vE local:/var/run/telnet.socket 0 telnetd -i

--
vda


More information about the busybox mailing list