From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
netdev@vger.kernel.org
Cc: David Ahern <dsahern@gmail.com>
Subject: [PATCH 1/3] libnetlink: add rtattr_for_each_nested() iteration macro
Date: Mon, 24 Aug 2020 19:51:06 +0200 [thread overview]
Message-ID: <20200824175108.53101-1-johannes@sipsolutions.net> (raw)
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(+)
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__ */
--
2.26.2
next reply other threads:[~2020-08-24 17:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 17:51 Johannes Berg [this message]
2020-08-24 17:51 ` [PATCH 2/3] libnetlink: add nl_print_policy() helper Johannes Berg
2020-10-25 21:23 ` Stephen Hemminger
2020-08-24 17:51 ` [PATCH 3/3] genl: ctrl: support dumping netlink policy Johannes Berg
2020-08-25 3:36 ` [PATCH 1/3] libnetlink: add rtattr_for_each_nested() iteration macro David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200824175108.53101-1-johannes@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=dsahern@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).