diff mbox series

[1/3] libnetlink: add rtattr_for_each_nested() iteration macro

Message ID 20200824175108.53101-1-johannes@sipsolutions.net
State Accepted
Delegated to: David Ahern
Headers show
Series [1/3] libnetlink: add rtattr_for_each_nested() iteration macro | expand

Commit Message

Johannes Berg Aug. 24, 2020, 5:51 p.m. UTC
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 <johannes@sipsolutions.net>
---
 include/libnetlink.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

David Ahern Aug. 25, 2020, 3:36 a.m. UTC | #1
On 8/24/20 11:51 AM, Johannes Berg wrote:
> 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 <johannes@sipsolutions.net>
> ---
>  include/libnetlink.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 

applied to iproute2-next. Thanks, Johannes.
diff mbox series

Patch

diff --git a/include/libnetlink.h b/include/libnetlink.h
index e27516f7648f..0d4a9f29afbd 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__ */