ofalk / libdnet

libdnet provides a simplified, portable interface to several low-level networking routines.
Other
153 stars 60 forks source link

fix payload size of Netlink message in route_get() #99

Open luznicky opened 5 months ago

luznicky commented 5 months ago

The len parameter of NLMSG_LENGTH was size of Netlink header instead of RtNetlink header.

Also make it more clear that the parameter of the macro is the payload size, which is RtNetlink message in this case.

ofalk commented 4 months ago

Did you see any errors with the previous code? I'm not aware of any. Let me know why you believe the size is wrong please.

luznicky commented 3 months ago

The description for NLMSG_LENGTH() is _Given the payload length, len, this macro returns the aligned length to store in the nlmsg_len field of the nlmsghdr._ In this case the payload is RtNetlink message. Therefore I expect that the len shoud be the size of RtNetlink header and RtNetlink payload size.

The Netlink message buffer contains [Netlink_hdr, Netlink_payload], where Netlink_payload is [RtNetlink hdr, RtNetlink_payload].

Also from the source code

#define     NLMSG_LENGTH(len)   ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))

In the code the macro expands to something like nlmsg_len = (2*NLMSG_HDRLEN) + RTA_LENGTH(alen). Which doesn't make much sense to me.

Hope it's understandable at lest from one of the tree explanation attempts.

Did you see any errors with the previous code?

No. Because because the size of Netlink header is greater than Rtnetlink header.