6 ms·
Netlink interface is a socket opened with socket(AF_NETLINK, ...). https://man.archlinux.org/man/netlink.7.en https://man.archlinux.org/man/netlink.7.en
by AnssiH 5y ago
Netlink interface is a socket opened with socket(AF_NETLINK, ...). https://man.archlinux.org/man/netlink.7.en https://man.archlinux.org/man/netlink.7.en
- CameronNemo 5y agoIt behaves much like a datagram socket IIRC.
- sneak 5y agoBummer that it requires platform-specific APIs; I much prefer the "everything is a file" approach. Is there a particular reason Linux chose to do it this way?
- rfraile 5y ago+1 for the file interface
- zokier 5y agoLinux interpretation of "everything is a file" includes that things like sockets (including netlink) are files, because you interact with them through file descriptors.
- pjmlp 5y agoTry to open() or seek() a socket file descriptor.
- ahartmetz 5y agoAt least close() is universal (even for stuff like epoll descriptors), and read() and write() are very widely applicable.
- jfrunyon 5y agoYou can't lseek() (what is seek()?) a socket because lseek doesn't make sense on 'streaming' data. There are multiple answers for how it can be done (i.e. receive it to a buffer) but you can do that yourself, in userspace, at no real expense. You also can't lseek a pipe, or files on some types of hardware, and "POSIX does not specify which devices must support lseek()" (https://man7.org/linux/man-pages/man2/lseek.2.html https://man7.org/linux/man-pages/man2/lseek.2.html) open(), of course, is an operation on a path/filename, not generally a descriptor. Not sure what usage you're referring to.
- sneak 5y agoI suppose, but if I want to consume it in an app or library, not only do I have to write the platform-specific parser, but I also have to write the platform-specific bytes-getter. Seems silly to me to not make it available to standard unix tools (ie cat, grep, sed, awk).
- touisteur 5y agoI think it's really intended for the power users. Updating firewall rules, routes, upgrading tc classes, reading qdiscs stats, all without ever forking a new process. It's also quite low-overhead when you subscribe to firewall or audit log rules... Netlink is quite amazing but also... Quite mysterious sometimes. libnl and reading the kernel source will help a lot for the new user. Also stracing the iproute2 tools will help see how it's done. Anyway, if anyone has a way of checking the state of a plug-qdisc (is it plugged or unplugged) I'd be quite interested ;-)
- ahartmetz 5y agoMany of the things that could be files not being files is because someone messed up. Why are network interfaces not in /dev? Well, during the UNIX wars, every vendor came up with their own stuff, and much of it wasn't very good. BSD and Linux inherited some of these needless inconsistencies. Plan 9 is a much more UNIXy system than the dominant UNIX derivatives.
- pjmlp 5y agoI guess mainly because POSIX and UNIX in general doesn't matter that much on server room, only Linux APIs.
- jfrunyon 5y ago"Everything is a file" still involves platform-specific APIs. The filename and manner of operation on that file are, after all, platform-specific.