[ovs-dev] [PreQoS 11/13] netlink: Add functions for handling nested attributes.

Justin Pettit jpettit at nicira.com
Thu Jun 3 17:03:45 UTC 2010


Looks good.*

--Justin

* Or as good as Netlink can look.


On May 27, 2010, at 1:33 PM, Ben Pfaff wrote:

> ---
> lib/netlink.c |   23 +++++++++++++++++++++++
> lib/netlink.h |    3 +++
> 2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/netlink.c b/lib/netlink.c
> index 73328e1..193b23e 100644
> --- a/lib/netlink.c
> +++ b/lib/netlink.c
> @@ -766,6 +766,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 },
> @@ -877,6 +886,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.  */
> 
> diff --git a/lib/netlink.h b/lib/netlink.h
> index dc68921..dba7f02 100644
> --- a/lib/netlink.h
> +++ b/lib/netlink.h
> @@ -103,6 +103,7 @@ uint16_t nl_attr_get_u16(const struct nlattr *);
> uint32_t nl_attr_get_u32(const struct nlattr *);
> uint64_t nl_attr_get_u64(const struct nlattr *);
> const char *nl_attr_get_string(const struct nlattr *);
> +void nl_attr_get_nested(const struct nlattr *, struct ofpbuf *);
> 
> /* Netlink attribute policy.
>  *
> @@ -118,6 +119,8 @@ struct nl_policy
> bool nl_policy_parse(const struct ofpbuf *, size_t offset,
>                      const struct nl_policy[],
>                      struct nlattr *[], size_t n_attrs);
> +bool nl_parse_nested(const struct nlattr *, const struct nl_policy[],
> +                     struct nlattr *[], size_t n_attrs);
> 
> /* Miscellaneous. */
> 
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org





More information about the dev mailing list