Add a utility function to filter out a given type from a list of netlink attributes. This removes an item from the set.
Signed-off-by: Eric Garver <e...@erig.me> --- lib/netlink.c | 20 ++++++++++++++++++++ lib/netlink.h | 1 + 2 files changed, 21 insertions(+) diff --git a/lib/netlink.c b/lib/netlink.c index 4cf1aaca621c..420208a0c51e 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -927,3 +927,23 @@ nl_attr_find_nested(const struct nlattr *nla, uint16_t type) { return nl_attr_find__(nl_attr_get(nla), nl_attr_get_size(nla), type); } + +/* + * Filter nlattr type from set of nlattrs. + * This changes the data in place. So caller should make a copy if required. + */ +void +nl_attr_filter(struct nlattr *attrs, size_t *attrs_len, uint16_t type) +{ + size_t size = *attrs_len; + struct nlattr *nla; + size_t left; + + NL_ATTR_FOR_EACH (nla, left, attrs, size) { + if (nl_attr_type(nla) == type) { + *attrs_len -= nl_attr_len_pad(nla, left); + memmove(nla, nl_attr_next(nla), left - nl_attr_len_pad(nla, left)); + return; + } + } +} diff --git a/lib/netlink.h b/lib/netlink.h index 6dfac27c9d4b..256246676b4b 100644 --- a/lib/netlink.h +++ b/lib/netlink.h @@ -240,5 +240,6 @@ const struct nlattr *nl_attr_find(const struct ofpbuf *, size_t hdr_len, const struct nlattr *nl_attr_find_nested(const struct nlattr *, uint16_t type); const struct nlattr *nl_attr_find__(const struct nlattr *attrs, size_t size, uint16_t type); +void nl_attr_filter(struct nlattr *attrs, size_t *attrs_len, uint16_t type); #endif /* netlink.h */ -- 2.12.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev