summaryrefslogtreecommitdiff
path: root/lib/netlink.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-05-20 15:57:56 -0700
committerBen Pfaff <blp@nicira.com>2010-06-17 10:30:18 -0700
commit25eeae6a1e12445c6d17b27d092f5936a6150892 (patch)
tree7fa71b711beeae23199f95ba7858d2ed557415e8 /lib/netlink.c
parenta35fbea5bb1b49bcdad696a62c3814e02c4df6e2 (diff)
downloadopenvswitch-25eeae6a1e12445c6d17b27d092f5936a6150892.tar.gz
netlink: Add functions for handling nested attributes.
Diffstat (limited to 'lib/netlink.c')
-rw-r--r--lib/netlink.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/netlink.c b/lib/netlink.c
index 334e45af9..24ea290de 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -770,6 +770,15 @@ nl_attr_get_string(const struct nlattr *nla)
return nl_attr_get(nla);
}
+/* Initializes 'nested' to the payload of 'nla'. Doesn't initialize every
+ * field in 'nested', but enough to poke around with it in a read-only way. */
+void
+nl_attr_get_nested(const struct nlattr *nla, struct ofpbuf *nested)
+{
+ nested->data = (void *) nl_attr_get(nla);
+ nested->size = nl_attr_get_size(nla);
+}
+
/* Default minimum and maximum payload sizes for each type of attribute. */
static const size_t attr_len_range[][2] = {
[0 ... N_NL_ATTR_TYPES - 1] = { 0, SIZE_MAX },
@@ -881,6 +890,20 @@ nl_policy_parse(const struct ofpbuf *msg, size_t nla_offset,
}
return true;
}
+
+/* Parses the Netlink attributes within 'nla'. 'policy[i]', for 0 <= i <
+ * n_attrs, specifies how the attribute with nla_type == i is parsed; a pointer
+ * to attribute i is stored in attrs[i]. Returns true if successful, false on
+ * failure. */
+bool
+nl_parse_nested(const struct nlattr *nla, const struct nl_policy policy[],
+ struct nlattr *attrs[], size_t n_attrs)
+{
+ struct ofpbuf buf;
+
+ nl_attr_get_nested(nla, &buf);
+ return nl_policy_parse(&buf, 0, policy, attrs, n_attrs);
+}
/* Miscellaneous. */