From patchwork Mon Nov 27 21:53:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 841880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3ym0tD1PtFz9s3w for ; Tue, 28 Nov 2017 08:53:40 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A7A1CC24; Mon, 27 Nov 2017 21:53:36 +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 14087BD4 for ; Mon, 27 Nov 2017 21:53:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 776EFF4 for ; Mon, 27 Nov 2017 21:53:34 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id AF7A6A80D8; Mon, 27 Nov 2017 22:53:31 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Mon, 27 Nov 2017 13:53:28 -0800 Message-Id: <20171127215328.1947-1-blp@ovn.org> X-Mailer: git-send-email 2.10.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] netdev-tc-offloads: Use customary types for buffer. 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 This function uses local array set_buff[] to store Netlink attributes. It declares set_buff as an array of character pointers, which is a strange type for a buffer of non-character-pointer objects. In OVS it is customary to use an ofpbuf with a stub of uint64_t objecs (to ensure proper alignment, otherwise uint8_t would be more usual). This commit changes to that more usual form. Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- lib/netdev-tc-offloads.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 1f77b5595594..9364d94f05ef 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -581,18 +581,17 @@ parse_put_flow_set_masked_action(struct tc_flower *flower, bool hasmask) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); - char *set_buff[128], *set_data, *set_mask; + uint64_t set_stub[1024 / 8]; + struct ofpbuf set_buf = OFPBUF_STUB_INITIALIZER(set_stub); + char *set_data, *set_mask; char *key = (char *) &flower->rewrite.key; char *mask = (char *) &flower->rewrite.mask; const struct nlattr *attr; int i, j, type; size_t size; - ovs_assert(set_len <= 128); - /* copy so we can set attr mask to 0 for used ovs key struct members */ - memcpy(set_buff, set, set_len); - attr = (struct nlattr *) set_buff; + attr = ofpbuf_put(&set_buf, set, set_len); type = nl_attr_type(attr); size = nl_attr_get_size(attr) / 2; @@ -602,6 +601,7 @@ parse_put_flow_set_masked_action(struct tc_flower *flower, if (type >= ARRAY_SIZE(set_flower_map) || !set_flower_map[type][0].size) { VLOG_DBG_RL(&rl, "unsupported set action type: %d", type); + ofpbuf_uninit(&set_buf); return EOPNOTSUPP; } @@ -634,9 +634,11 @@ parse_put_flow_set_masked_action(struct tc_flower *flower, if (hasmask && !is_all_zeros(set_mask, size)) { VLOG_DBG_RL(&rl, "unsupported sub attribute of set action type %d", type); + ofpbuf_uninit(&set_buf); return EOPNOTSUPP; } + ofpbuf_uninit(&set_buf); return 0; }