Libnetstack: Difference between revisions
Created page with "<tt>AF_NETLINK</tt> sockets allow one to enumerate networking stack elements, and subscribe to events regarding changes, additions, and deletions thereof. Netlink is kind..." |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Code lives at https://github.com/dankamongmen/libnetstack. | Code lives at https://github.com/dankamongmen/libnetstack. | ||
==rtnetlink== | |||
<tt>rtnetlink(7)</tt> (originally implemented AFAIK by Alexey Kuznetsov, the Mad Russian, whom I haven't seen post to [[LKML]] in many years, and miss) provides the <tt>NETLINK_ROUTE</tt> protocol for the <tt>AF_NETLINK</tt> family of sockets. According to <tt>netlink(7)</tt>,<blockquote>Netlink is a datagram-oriented service. Both <tt>SOCK_RAW</tt> and <tt>SOCK_DGRAM</tt> are valid values for socket_type. However, the netlink protocol does not distinguish between datagram and raw sockets."—<tt>netlink(7)</tt>, Linux man pages 5.03</blockquote> Creating and using such a socket does not require any special permissions, though <tt>CAP_NET_ADMIN</tt> is needed for many control messages (verified kernel-side, of course). Once established, we can directly request dumps of networking stack state with the <tt>RTM_GET*</tt> set of messages, and/or simply subscribe to the appropriate multicast groups, sit back, and let new events roll to us. | |||
{|class="wikitable" | |||
! Group !! Messages | |||
|- | |||
| <tt>RTNLGRP_LINK</tt> || <tt>RTM_NEWLINK</tt>, <tt>RTM_DELLINK</tt> | |||
|- | |||
| <tt>RTNLGRP_IPV4_IFADDR</tt> || <tt>RTM_NEWADDR</tt>, <tt>RTM_DELADDR</tt> (AF_INET only) | |||
|- | |||
| <tt>RTNLGRP_IPV6_IFADDR</tt> || <tt>RTM_NEWADDR</tt>, <tt>RTM_DELADDR</tt> (AF_INET6 only) | |||
|- | |||
| <tt>RTNLGRP_IPV4_ROUTE</tt> || <tt>RTM_NEWROUTE</tt>, <tt>RTM_DELROUTE</tt> (AF_INET only) | |||
|- | |||
| <tt>RTNLGRP_IPV6_ROUTE</tt> || <tt>RTM_NEWROUTE</tt>, <tt>RTM_DELROUTE</tt> (AF_INET6 only) | |||
|- | |||
| <tt>RTNLGRP_NEIGH</tt> || <tt>RTM_NEWNEIGH</tt>, <tt>RTM_DELNEIGH</tt> | |||
|- | |||
|} | |||
{{#github:README.md|dankamongmen/libnetstack}} | |||
==See also== | |||
* "[https://inai.de/documents/Netlink_Protocol.pdf The Netlink protocol: Mysteries Uncovered]", Jan Engelhardt 2010-10-30 | |||
[[CATEGORY: Projects]] | [[CATEGORY: Projects]] | ||