virtual netlink device for packet sockets
Subsystems (2)
cover virtual netlink device for packet sockets
This set allows for a virtual netlink device that can be easily used without modification by tools like tcpdump, Wireshark et al. to debug and troubleshoot netlink traffic that is exchanged between user and kernel space. We could even record pcap files for a later analysis. No code change would be needed on the side of such analyzers, except adding a simple protocol dissector, for example.
Please have a look at the main description in patch 3. Patch 1 and 2 are just prerequisits for the actual 3rd patch.
I think the device idea is the cleanest solution. We have packet sockets and they do exactly what we want and expect from them, they have all the features etc, and user space would not even need to implement code. Thus adding more and more functionality into af_netlink would be a bigger surgery and further bloat it up with duplicate code, imho. By taking the approach with what I'm proposing, we have a clean segregation of functionality (as: packet sockets vs. netlink sockets), thus keeping it simple and stupid, and not too complex.
Thanks !
Daniel Borkmann (3):
net: if_arp: add ARPHRD_NETLINK type
net: netlink: add registration/unregistration of virtual tap devices
packet: nlmon: virtual netlink monitoring device for packet sockets
drivers/net/Kconfig | 10 +++ drivers/net/Makefile | 1 + drivers/net/nlmon.c | 170 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/netlink.h | 10 +++ include/uapi/linux/if_arp.h | 1 + net/netlink/af_netlink.c | 107 ++++++++++++++++++++++++++++ 6 files changed, 299 insertions(+) create mode 100644 drivers/net/nlmon.c
Signature · 1 line
1.7.11.7
PATCH 1/3 net: if_arp: add ARPHRD_NETLINK type
This small patch adds the definition of ARPHRD_NETLINK which can for example be used by netlink monitoring devices as device type. So that sockaddr_ll can pick it up and based on that choose the correct packet dissector.
--- include/uapi/linux/if_arp.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/if_arp.h +1 -0
@@ -93,6 +93,7 @@#define ARPHRD_PHONET_PIPE 821/* PhoNet pipe header */ #define ARPHRD_CAIF 822/* CAIF media type */ #define ARPHRD_IP6GRE 823/* GRE over IPv6 */ +#define ARPHRD_NETLINK 824/* Netlink header */ #define ARPHRD_VOID 0xFFFF/* Void type, nothing is known */ #define ARPHRD_NONE 0xFFFE/* zero header length */
Signature · 1 line
1.7.11.7
PATCH 2/3 net: netlink: virtual tap device management
In reply to Daniel BorkmannSimilarly to the networking receive path with ptype_all taps, we add the possibility to register netdevices that are for ARPHRD_NETLINK to the netlink subsystem, so that those can be used for netlink analyzers resp. debuggers. We do not offer a direct callback function as out-of-tree modules could do crap with it. Instead, a netdevice must be registered properly and only receives a clone, managed by the netlink layer. Symbols are exported as GPL-only.
--- include/linux/netlink.h | 10 +++++ net/netlink/af_netlink.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+)
include/linux/netlink.h +10 -0
@@ -145,4 +145,14 @@ static inline int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, return __netlink_dump_start(ssk, skb, nlh, control); } +struct netlink_tap { +struct net_device *dev; +struct module *module; +struct list_head list; +}; + +extern int netlink_add_tap (struct netlink_tap *nt); +extern int __netlink_remove_tap (struct netlink_tap *nt); +extern int netlink_remove_tap (struct netlink_tap *nt); +#endif /* __LINUX_NETLINK_H */
net/netlink/af_netlink.c +107 -0
143 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 3/3 packet: nlmon: virtual netlink monitoring device for packet sockets
In reply to Daniel BorkmannCurrently, there is no good possibility to debug netlink traffic that is being exchanged between kernel and user space. Therefore, this patch implements a netlink virtual device, so that netlink messages will be made visible to PF_PACKET sockets. Once there was an approach with a similar idea [1], but it got forgotten somehow.
I think it makes most sense to accept the "overhead" of an extra netlink net device over implementing the same functionality from PF_PACKET sockets once again into netlink sockets. We have BPF filters that can already be easily applied which even have netlink extensions, we have RX_RING zero-copy between kernel- and user space that can be reused, and much more features. So instead of re-implementing all of this, we simply pass the skb to a given PF_PACKET socket for further analysis.
Another nice benefit that comes from that is that no code needs to be changed in user space packet analyzers (maybe adding a dissector, but not more), thus out of the box, we can already capture pcap files of netlink traffic to debug/troubleshoot netlink problems.
Also thanks goes to Thomas Graf, Flavio Leitner, Jesper Dangaard Brouer.
[1] http://marc.info/?l=linux-netdev&m=113813401516110
--- drivers/net/Kconfig | 10 +++ drivers/net/Makefile | 1 + drivers/net/nlmon.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 drivers/net/nlmon.c
drivers/net/Kconfig +10 -0
@@ -244,6 +244,16 @@ config VIRTIO_NET This is the virtual network driver for virtio. It can be used with lguest or QEMU based VMMs (like KVM or Xen). Say Y or M. +config NLMON + tristate "Virtual netlink monitoring device" + ---help--- + This option enables a monitoring net device for netlink skbs. The + purpose of this is to analyze netlink messages with packet sockets. + Thus applications like tcpdump will be able to see local netlink + messages if they tap into the netlink device, record pcaps for further + diagnostics, etc. This is mostly intended for developers or support + to debug netlink issues. If unsure, say N. + endif # NET_CORE config SUNGEM_PHY
drivers/net/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VXLAN) += vxlan.o +obj-$(CONFIG_NLMON) += nlmon.o # # Networking Drivers
drivers/net/nlmon.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
1.7.11.7
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Fri, 21 Jun 2013 19:38:05 +0200
Quoted 10 lines
This set allows for a virtual netlink device that can be easily used without modification by tools like tcpdump, Wireshark et al. to debug and troubleshoot netlink traffic that is exchanged between user and kernel space. We could even record pcap files for a later analysis. No code change would be needed on the side of such analyzers, except adding a simple protocol dissector, for example.
Please have a look at the main description in patch 3. Patch 1 and 2 are just prerequisits for the actual 3rd patch.
Quoted 8 lines
I think the device idea is the cleanest solution. We have packet sockets and they do exactly what we want and expect from them, they have all the features etc, and user space would not even need to implement code. Thus adding more and more functionality into
af_netlinkwould be a bigger surgery and further bloat it up with duplicate code, imho. By taking the approach with what I'm proposing, we have a clean segregation of functionality (as: packet sockets vs. netlink sockets), thus keeping it simple and stupid, and not too complex.
Yep, this seems like a good tradeoff. Series applied, thanks!