Skip to content

Commit

Permalink
netlink: New macros NL_NESTED_FOR_EACH, NL_NESTED_FOR_EACH_UNSAFE.
Browse files Browse the repository at this point in the history
Upcoming commits will introduce more users.
  • Loading branch information
blp committed Oct 11, 2011
1 parent 3ee8a9f commit 6d23c6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/netlink-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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},
Expand Down
6 changes: 6 additions & 0 deletions lib/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit 6d23c6f

Please sign in to comment.