An alternative interface, if we want this to be more flexible without adding new parameters for each possible variation is something like the following:
diff --git a/datapath/linux/compat/include/linux/netlink.h b/datapath/linux/compat/include/linux/netlink.h index f172590..e3d29a2 100644 --- a/datapath/linux/compat/include/linux/netlink.h +++ b/datapath/linux/compat/include/linux/netlink.h @@ -17,9 +17,26 @@ #endif #ifndef HAVE_NLA_PARSE_STRICT + +#define NLA_PARSE_F_INIT 0x01 /* Initialize the tb to zero. */ +#define NLA_PARSE_F_UNKNOWN 0x02 /* Allow unknown attributes. */ +#define NLA_PARSE_F_TRAILING 0x04 /* Allow trailing attributes. */ +#define NLA_PARSE_F_DUPLICATE 0x08 /* Allow duplicate attributes. */ +#define NLA_PARSE_F_EXACT_LEN 0x10 /* Lengths specified in the policy + specify both min and max length. */ +#define NLA_PARSE_F_NONZERO 0x20 /* Only store pointers for attributes + with nonzero values. */ +}; + +/* NLA_PARSE_LENIENT_MASK provides the equivalent behaviour of nla_parse(). */ +#define NLA_PARSE_LENIENT_MASK (NLA_PARSE_F_INIT | \ + NLA_PARSE_F_SKIP_UNKNOWN \ + NLA_PARSE_F_TRAILING | \ + NLA_PARSE_F_DUPLICATE) + int nla_parse_strict(const struct nlattr **tb, int maxtype, const struct nlattr *head, int len, - const struct nla_policy *policy, bool dup, bool nz); + const struct nla_policy *policy, u8 flags); #endif #endif diff --git a/datapath/linux/compat/nlattr.c b/datapath/linux/compat/nlattr.c index cdcc241..a53579c 100644 --- a/datapath/linux/compat/nlattr.c +++ b/datapath/linux/compat/nlattr.c @@ -122,47 +122,47 @@ static bool is_all_zero(const u8 *fp, size_t size) * @head: head of attribute stream * @len: length of attribute stream * @policy: validation policy - * @dup: allow duplicate attributes (later attributes override earlier) - * @nz: only store pointers for attributes with nonzero values + * @flags: mask of NLA_PARSE_F_* * - * Parses a stream of attributes and stores a pointer to each attribute in - * the tb array accessible via the attribute type. Attributes with unknown - * types or invalid lengths, duplicate attributes, or unexpected trailing - * bytes will cause parsing to fail. Unlike nla_parse(), this function - * requires the policy to be specified. Lengths specified by the policy - * indicate the exact length of the attribute, any variation will cause - * parsing to fail. + * Parses a stream of attributes and stores a pointer to each attribute in the + * tb array accessible via the attribute type. Unlike nla_parse(), this + * function requires the policy to be specified. * * Returns 0 on success or a negative error code. */ int nla_parse_strict(const struct nlattr **tb, int maxtype, const struct nlattr *head, int len, - const struct nla_policy *policy, - bool dup, bool nz) + const struct nla_policy *policy, u8 flags) { _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev