5 ms·
Common interface for Linux NIC statistics
- deleted 6y ago[deleted]
- sneak 6y agoParsing /proc/net/dev in perl and displaying deltas with ncurses was one of my first teenage hacks (ca ‘97), ages before iptraf. This has been an issue for a long time. This is a welcome change. Is the netlink interface described accessible in /proc or /sys with a standard fopen, or is it a special linuxism?
- AnssiH 6y agoNetlink 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 6y agoIt behaves much like a datagram socket IIRC.
- sneak 6y 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 6y ago+1 for the file interface
- zokier 6y 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 6y agoTry to open() or seek() a socket file descriptor.
- ahartmetz 6y agoAt least close() is universal (even for stuff like epoll descriptors), and read() and write() are very widely applicable.
- jfrunyon 6y 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 6y 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).
- pjmlp 6y agoI guess mainly because POSIX and UNIX in general doesn't matter that much on server room, only Linux APIs.
- jfrunyon 6y ago"Everything is a file" still involves platform-specific APIs. The filename and manner of operation on that file are, after all, platform-specific.
- idorosen 6y agoEthtool gets information from the SIOCETHTOOL ioctl and AF_NETLINK sockets. The former are traditional ioctls that can be performed on any socket (e.g. AF_INET), the latter is a message-oriented protocol for communicating networking information to/from the kernel. (For example, “ip route” and “route” tools transact routing info through RT_NETLINK messages on AF_NETLINK sockets.) There are many different protocols that sit on top of NETLINK sockets.