From patchwork Mon Jul 10 19:39:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 786338 X-Patchwork-Delegate: joestringer@nicira.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x5wYQ4y74z9s81 for ; Tue, 11 Jul 2017 05:40:42 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 86C1AB4B; Mon, 10 Jul 2017 19:40:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 180A5A86 for ; Mon, 10 Jul 2017 19:40:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 713B5201 for ; Mon, 10 Jul 2017 19:40:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C04264E4D4; Mon, 10 Jul 2017 19:40:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C04264E4D4 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=erig.me Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=e@erig.me DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C04264E4D4 Received: from dev-rhel7.localdomain (wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com [10.19.17.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F7715C550; Mon, 10 Jul 2017 19:40:00 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Mon, 10 Jul 2017 15:39:51 -0400 Message-Id: <20170710194000.21627-2-e@erig.me> In-Reply-To: <20170710194000.21627-1-e@erig.me> References: <20170710194000.21627-1-e@erig.me> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 19:40:01 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 01/10] netlink: Add function to filter nlattrs X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 --- 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 */