From: Johannes Berg Date: Mon, 24 Aug 2020 17:51:06 +0000 (+0200) Subject: libnetlink: add rtattr_for_each_nested() iteration macro X-Git-Tag: v5.10.0~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=784fa9f62f0afed631abb974df517ed766ba9658;p=thirdparty%2Fiproute2.git libnetlink: add rtattr_for_each_nested() iteration macro This is useful for iterating elements in a nested attribute, if they're not parsed with a strict length limit or such. Signed-off-by: Johannes Berg Signed-off-by: David Ahern --- diff --git a/include/libnetlink.h b/include/libnetlink.h index e27516f76..0d4a9f29a 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -284,4 +284,9 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, * messages from dump file */ #define NLMSG_TSTAMP 15 +#define rtattr_for_each_nested(attr, nest) \ + for ((attr) = (void *)RTA_DATA(nest); \ + RTA_OK(attr, RTA_PAYLOAD(nest) - ((char *)(attr) - (char *)RTA_DATA((nest)))); \ + (attr) = RTA_TAIL((attr))) + #endif /* __LIBNETLINK_H__ */