|
| 1 | +[](https://travis-ci.org/little-dude/netlink) |
| 2 | + |
| 3 | +# Netlink |
| 4 | + |
| 5 | +This project aims at providing building blocks for [netlink][man-netlink] (see `man 7 netlink`). |
| 6 | + |
| 7 | +## Organization |
| 8 | + |
| 9 | +- the [`netlink_sys`](./netlink-sys) crate provides netlink sockets. Integration with [`mio`][mio] and [`tokio`][tokio] |
| 10 | + is optional. |
| 11 | +- Each netlink protocol has a `netlink-packet-<protocol_name>` crate that provides the packets for this protocol: |
| 12 | + - [`netlink-packet-route`](./netlink-packet-route) provides messages for the [route protocol][man-rtnetlink] |
| 13 | + - [`netlink-packet-audit`](./netlink-packet-audit) provides messages for the [audit][man-audit] protocol |
| 14 | + - [`netlink-packet-sock-diag`](./netlink-packet-sock-diag) provides messages for the [sock-diag][man-sock-diag] |
| 15 | + protocol |
| 16 | + - [`netlink-packet-generic`](./netlink-packet-generic) provides message for the [generic netlink][man-genl] |
| 17 | + protocol |
| 18 | + - [`netlink-packet-netfilter`](./netlink-packet-netfilter) provides message for the `NETLINK_NETFILTER` |
| 19 | + protocol |
| 20 | +- the [`netlink-packet-core`](./netlink-packet-core) is the glue for all the other `netlink-packet-*` crates. It |
| 21 | + provides a `NetlinkMessage<T>` type that represent any netlink message for any sub-protocol. |
| 22 | +- the [`netlink_proto`](./netlink-proto) crate is an asynchronous implementation of the netlink protocol. It only |
| 23 | + depends on `netlink-packet-core` for the `NetlinkMessage` type and `netlink-sys` for the socket. |
| 24 | +- the [`rtnetlink`](./rtnetlink) crate provides higher level abstraction for the [route protocol][man-rtnetlink] |
| 25 | +- the [`audit`](./audit) crate provides higher level abstractions for the audit protocol. |
| 26 | +- the [`genetlink`](./genetlink) crate provide higher level abstraction for the |
| 27 | + [generic netlink protocol][man-genl] |
| 28 | +- the [`ethtool`](./ethtool) crate provide higher level abstraction for |
| 29 | + [ethtool netlink protocol][ethtool-kernel-doc] |
| 30 | + |
| 31 | + |
| 32 | +## Altnernatives |
| 33 | + |
| 34 | +- https://github.com/jbaublitz/neli: the main alternative to these crates, as it is actively developed. |
| 35 | +- Other but less actively developed alternatives: |
| 36 | + - https://github.com/achanda/netlink |
| 37 | + - https://github.com/polachok/pnetlink |
| 38 | + - https://github.com/crhino/netlink-rs |
| 39 | + - https://github.com/carrotsrc/rsnl |
| 40 | + - https://github.com/TaborKelly/nl-utils |
| 41 | + |
| 42 | +## Credits |
| 43 | + |
| 44 | +My main resource so far has been the source code of [`pyroute2`][pyroute2] (python) and [`netlink`][netlink-go] (golang) |
| 45 | +a lot. These two projects are great, and very nicely written. As someone who does not read C fluently, and that does not |
| 46 | +know much about netlink, they have been invaluable. |
| 47 | + |
| 48 | +I'd also like to praise [`libnl`][libnl] for its documentation. It helped me a lot in understanding the protocol basics. |
| 49 | + |
| 50 | +The whole packet parsing logic is inspired by @whitequark excellent blog posts ([part 1][whitequark-1], [part |
| 51 | +2][whitequark-2] and [part 3][whitequark-3], although I've only really used the concepts described in the first blog |
| 52 | +post). |
| 53 | + |
| 54 | +Thanks also to the people behind [tokio](tokio.rs) for the amazing |
| 55 | +tool they are building, and the support they provide. |
| 56 | + |
| 57 | +[man-netlink]: https://www.man7.org/linux/man-pages/man7/netlink.7.html |
| 58 | +[man-audit]: https://man7.org/linux/man-pages/man3/audit_open.3.html |
| 59 | +[man-sock-diag]: https://www.man7.org/linux/man-pages/man7/sock_diag.7.html |
| 60 | +[man-rtnetlink]: https://www.man7.org/linux/man-pages/man7/rtnetlink.7.html |
| 61 | +[man-genl]: https://www.man7.org/linux/man-pages/man8/genl.8.html |
| 62 | +[generic-netlink-lwn]: https://lwn.net/Articles/208755/ |
| 63 | +[mio]: https://github.com/tokio-rs/mio |
| 64 | +[tokio]: https://github.com/tokio-rs/tokio |
| 65 | +[route-proto-doc]: https://www.infradead.org/~tgr/libnl/doc/route.html |
| 66 | +[netlink-go]: https://github.com/vishvananda/netlink |
| 67 | +[pyroute2]: https://github.com/svinota/pyroute2/tree/master/pyroute2/netlink |
| 68 | +[libnl]: https://www.infradead.org/~tgr/libnl |
| 69 | +[whitequark-1]: https://lab.whitequark.org/notes/2016-12-13/abstracting-over-mutability-in-rust |
| 70 | +[whitequark-2]: https://lab.whitequark.org/notes/2016-12-17/owning-collections-in-heap-less-rust |
| 71 | +[whitequark-3]: https://lab.whitequark.org/notes/2017-01-16/abstracting-over-mutability-in-rust-macros |
| 72 | +[ethtool-kernel-doc]: https://www.kernel.org/doc/html/latest/networking/ethtool-netlink.html |
0 commit comments