From patchwork Fri Feb 17 01:11:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 728970 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 3vPZk32wPcz9s8N for ; Fri, 17 Feb 2017 12:11:55 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A382CBC1; Fri, 17 Feb 2017 01:11:25 +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 2F209B93 for ; Fri, 17 Feb 2017 01:11:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7F0FDA4 for ; Fri, 17 Feb 2017 01:11:22 +0000 (UTC) Received: by mail-pg0-f68.google.com with SMTP id a123so569882pgc.3 for ; Thu, 16 Feb 2017 17:11:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AsrVpQ8dnBwbhDI29AxXgrtxU+IoyHqx5doudho1ooI=; b=COdWdRhTbdvWq/XX+1DZPfmOMmfw0mg3gwCfWtRxd72tXT1kcpzlCNZXRpwYG6wX1i DBMNzcXjL/qoYB3vcabqkFKMzY+h6FoV4sFGvKkyjhtLQaTttHVkUQjhcDp98HrgjOdA r7sH7VQ+jkmwPcMVpFrgGXkjzukreup5mOrXByG91cCFn97b9+RPaFkyLppCrnu1Dy9x eDjrFMnOr7ab1hxnk+ts3lxvi4lT/5i30PzX85prDBzpB7XTw0y4/FuoYZida7r1MsDy ugy++bhY7dKraABpeIo8BN4fUfG7U0F+N8ZmhhzY8ubPA/afkc1KNujStxbqzsoszQkz TgPQ== X-Gm-Message-State: AMke39lae0emxqtEI2nCGRIYVMRAXNJllH3BOaoUU48jn2azpTmo2XDr8O7gLLtTFUmiHQ== X-Received: by 10.84.224.65 with SMTP id a1mr7526549plt.28.1487293882154; Thu, 16 Feb 2017 17:11:22 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id m6sm15631546pfg.126.2017.02.16.17.11.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Feb 2017 17:11:21 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Thu, 16 Feb 2017 17:11:07 -0800 Message-Id: <1487293868-21605-2-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487293868-21605-1-git-send-email-azhou@ovn.org> References: <1487293868-21605-1-git-send-email-azhou@ovn.org> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/3] lib: Refactor nested netlink APIs. 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 Future patches will make use of those changes. Signed-off-by: Andy Zhou Acked-by: Jarno Rajahalme --- lib/netlink.c | 19 ++++++++++++++++--- lib/netlink.h | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/netlink.c b/lib/netlink.c index ad7d35a..ae4c72a 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -467,16 +467,29 @@ nl_msg_end_nested(struct ofpbuf *msg, size_t offset) attr->nla_len = msg->size - offset; } -/* Same as nls_msg_end_nested() when the nested Netlink contains non empty - * message. Otherwise, drop the nested message header from 'msg'. */ +/* Cancel a nested Netlink attribute in 'msg'. 'offset' should be the value + * returned by nl_msg_start_nested(). */ void +nl_msg_cancel_nested(struct ofpbuf *msg, size_t offset) +{ + msg->size = offset; +} + +/* Same as nls_msg_end_nested() when the nested Netlink contains non empty + * message. Otherwise, drop the nested message header from 'msg'. + * + * Return true if the nested message has been dropped. */ +bool nl_msg_end_non_empty_nested(struct ofpbuf *msg, size_t offset) { nl_msg_end_nested(msg, offset); struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr); if (!nl_attr_get_size(attr)) { - msg->size = offset; + nl_msg_cancel_nested(msg, offset); + return true; + } else { + return false; } } diff --git a/lib/netlink.h b/lib/netlink.h index 7646f91..bb4dbf6 100644 --- a/lib/netlink.h +++ b/lib/netlink.h @@ -79,7 +79,8 @@ void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value); size_t nl_msg_start_nested(struct ofpbuf *, uint16_t type); void nl_msg_end_nested(struct ofpbuf *, size_t offset); -void nl_msg_end_non_empty_nested(struct ofpbuf *, size_t offset); +void nl_msg_cancel_nested(struct ofpbuf *, size_t offset); +bool nl_msg_end_non_empty_nested(struct ofpbuf *, size_t offset); void nl_msg_put_nested(struct ofpbuf *, uint16_t type, const void *data, size_t size);