From 6d23c6f42206809f985d3fc7d95fca0589522836 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 5 Oct 2011 09:36:11 -0700 Subject: [PATCH] netlink: New macros NL_NESTED_FOR_EACH, NL_NESTED_FOR_EACH_UNSAFE. Upcoming commits will introduce more users. --- lib/netlink-socket.c | 6 ++---- lib/netlink.h | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 0f4e3e77..160edd23 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -790,9 +790,8 @@ nl_lookup_genl_mcgroup(const char *family_name, const char *group_name, unsigned int *multicast_group, unsigned int fallback) { struct nlattr *family_attrs[ARRAY_SIZE(family_policy)]; - struct ofpbuf all_mcs; + const struct nlattr *mc; struct ofpbuf *reply; - struct nlattr *mc; unsigned int left; int error; @@ -810,8 +809,7 @@ nl_lookup_genl_mcgroup(const char *family_name, const char *group_name, goto exit; } - nl_attr_get_nested(family_attrs[CTRL_ATTR_MCAST_GROUPS], &all_mcs); - NL_ATTR_FOR_EACH (mc, left, all_mcs.data, all_mcs.size) { + NL_NESTED_FOR_EACH (mc, left, family_attrs[CTRL_ATTR_MCAST_GROUPS]) { static const struct nl_policy mc_policy[] = { [CTRL_ATTR_MCAST_GRP_ID] = {.type = NL_A_U32}, [CTRL_ATTR_MCAST_GRP_NAME] = {.type = NL_A_STRING}, diff --git a/lib/netlink.h b/lib/netlink.h index 2206339c..2d345716 100644 --- a/lib/netlink.h +++ b/lib/netlink.h @@ -124,6 +124,12 @@ nl_attr_is_valid(const struct nlattr *nla, size_t maxlen) (LEFT) > 0; \ (LEFT) -= NLA_ALIGN((ITER)->nla_len), (ITER) = nl_attr_next(ITER)) +/* These variants are convenient for iterating nested attributes. */ +#define NL_NESTED_FOR_EACH(ITER, LEFT, A) \ + NL_ATTR_FOR_EACH(ITER, LEFT, nl_attr_get(A), nl_attr_get_size(A)) +#define NL_NESTED_FOR_EACH_UNSAFE(ITER, LEFT, A) \ + NL_ATTR_FOR_EACH_UNSAFE(ITER, LEFT, nl_attr_get(A), nl_attr_get_size(A)) + /* Netlink attribute parsing. */ int nl_attr_type(const struct nlattr *); const void *nl_attr_get(const struct nlattr *); -- 2.30.2