From patchwork Fri Jun 23 16:47:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Balogh X-Patchwork-Id: 780132 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 3wvPYc10d2z9sNW for ; Sat, 24 Jun 2017 02:49:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.onmicrosoft.com header.i=@ericsson.onmicrosoft.com header.b="Y2HRU8xZ"; dkim-atps=neutral Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 482C9BE8; Fri, 23 Jun 2017 16:48:03 +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 951A3AF7 for ; Fri, 23 Jun 2017 16:48:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sessmg22.ericsson.net (sessmg22.ericsson.net [193.180.251.58]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B8197E5 for ; Fri, 23 Jun 2017 16:47:59 +0000 (UTC) X-AuditID: c1b4fb3a-803ff70000001b2f-7f-594d463da473 Received: from ESESSHC017.ericsson.se (Unknown_Domain [153.88.183.69]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 8B.50.06959.D364D495; Fri, 23 Jun 2017 18:47:58 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.69) with Microsoft SMTP Server (TLS) id 14.3.339.0; Fri, 23 Jun 2017 18:47:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.onmicrosoft.com; s=selector1-ericsson-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qDRAm7CcOfTNtXaejKQqQacrPpYzahFEAyfvLQl1muc=; b=Y2HRU8xZMpAF64wy5+ooUWEtYswwykQH6uMKs9Wn2hSTclCYDd/U/8Pdgw2hzfCEfl2NL5rfS3gpJFRbu1Sy+ID7uah+hqaq0fcD5doGMnGnzDs2wzoYTkKQQpDAcAABgtAatWx5wRWuKHp2MvWC51p9whmg5/MEM8WZTNxBfAA= Received: from AM2PR07MB1042.eurprd07.prod.outlook.com (10.162.37.27) by AM2PR07MB0802.eurprd07.prod.outlook.com (10.161.71.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1220.5; Fri, 23 Jun 2017 16:47:55 +0000 Received: from AM2PR07MB1042.eurprd07.prod.outlook.com ([fe80::4060:619c:9386:3e1c]) by AM2PR07MB1042.eurprd07.prod.outlook.com ([fe80::4060:619c:9386:3e1c%13]) with mapi id 15.01.1199.012; Fri, 23 Jun 2017 16:47:55 +0000 From: =?iso-8859-1?Q?Zolt=E1n_Balogh?= To: "'dev@openvswitch.org'" Thread-Topic: [PATCH v4 2/7] nx-match: Add context argument to nxm_put__(). Thread-Index: AdLsPx2JVXY5Lc29RV6nlJ0xxKrOfQ== Date: Fri, 23 Jun 2017 16:47:54 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: openvswitch.org; dkim=none (message not signed) header.d=none;openvswitch.org; dmarc=none action=none header.from=ericsson.com; x-originating-ip: [91.82.100.59] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM2PR07MB0802; 7:hyY1YG5MmIi5eCz8JRn/DtfOZQTXyuL0iVmjqrXoyWjpQyDzqqrtUOcorFYsP8+b5F8whw1HaEDIs/8iGWNEJqb6mioEVUtKj9FUGJUzMy9jZIu9wSYiJWDt8dHEmWsJDJeKLwnQYfhd6tbwO6gxdO2n4GQ4o9U/O72+Ej+k+8Rs2XRFujBVQng8UunJp1ZuWv6JhzJTao7noMToxJMoogq1FgGeXJPq9Th6NelANKZNPhAIyOtFG5PSBOBinL1aapr/dWtFUEX+JLTFbnP2sjz3GplzWodPceY+mq+7OoRCxAhdgTSSGStwhYWteawMmIDns8zViz0S3BCGBe7PIYprTsejQ/P6mTo6a8FBbXpXHRBxQvp+nS/SlIXFq5b/1QMn9vboFvr4bioOQxMCepHRMNOW95uDmB9aKAxsaNIwswOiDL2uHA98Feb4wFkUZ97R1F0ZjALB2vj37eeyUF6xL8YO8Zt1fdzk17vPxlJjkl1LALIlJjyDt0ZXM+5vU0Ydt4Q1LzXq2+L5ZcwDfMVCrCogH3EiXOGHG42juavZdQdDA0ZYc4QaZhYCMkbAP2Wceszjz7DVa+FikEROArWQ7dJ+Ji6ApHcYRhLJbyi9sx07UOYVV1wZBUN5JBSI52tpW9nPyct/dXe2+zDm4NSV322MSYUBxDzzUYxbbxtqkjLK7n9xy7u9o9CExV3I6gS05oznGkb0vMuT2ySNynIgHp5XR4tUCgDNl+ZRX+kAQ3L6MczfldwCwWupwS8FPkJNBYYy8hORgOArtdZJdoN3N9SrdTjG7OzpDaRJ/lA= x-ld-processed: 92e84ceb-fbfd-47ab-be52-080c6b87953f,ExtAddr x-ms-office365-filtering-correlation-id: 280d0bc7-7afc-48d9-478f-08d4ba57988c x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(201703131423075)(201703031133081)(201702281549075); SRVR:AM2PR07MB0802; x-ms-traffictypediagnostic: AM2PR07MB0802: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(20161123562025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM2PR07MB0802; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM2PR07MB0802; x-forefront-prvs: 0347410860 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39400400002)(39410400002)(39850400002)(39450400003)(39840400002)(39860400002)(3280700002)(3660700001)(66066001)(38730400002)(9686003)(7696004)(53946003)(7736002)(25786009)(4326008)(33656002)(55016002)(102836003)(478600001)(99286003)(54906002)(110136004)(14454004)(53936002)(39060400002)(6506006)(8936002)(8676002)(74316002)(81166006)(5660300001)(305945005)(5250100002)(3846002)(6436002)(6116002)(2906002)(189998001)(54356999)(6916009)(2900100001)(50986999)(86362001)(491001)(579004)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR07MB0802; H:AM2PR07MB1042.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2017 16:47:54.8615 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR07MB0802 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0iTYRTHe/Ze9jobPE3Ng2nIIKJV8xrNElFTWZjQ7YNmUitfL6hT9ppk EvjBJC+h6cychtpF1NIPal7ylkspHWGZeQNL23LZTUMiStLc3gl9+z3n/z/n8D88DCF5QLkw iep0VqNWJUtpEVkR2RG6PyAsIsqz2UPxuTQbKYYMPYSivsVAKKa67BSrP9sFgZTyXs+iQFle ME8oF6bXkdI8UUgql/re0sepMyL/WDY5MYPVeAScFyWs9o/QaaO96HJJTSuRjfS5KB/ZMYB9 oeLmrDAfiRgJHkTwoXcU8Y8XCKqaTUKLi8Q3CFjPCbKwBGsF8H7Z1mFEMPH8DWERaHwEJrsX aQs7Yi8YKxmmLCYCryEo+V5nneSAw+Dh+rTNFA7vimo26swGy6GsDvhlu+B1cZfAwmJ8Fmaa V6zzEd4Ov0YeWesEdoYZU7WAj4Dhfs8owbMTLBrXrHsRrkTwtyvHZnKHlpolIc9uMFZdYI0J eI6G4vl2mhf84XZBuW1SBAwVNAl5UxGCj639JC/I4Jmh2daQBD+edgo369cHdQK+QU9BXv+U 7cSu0N39jeaFNgqe1DbQ/C1cYHY8DxUjme6/TDzLYapMS/O8F+pqvxA66z22wXCFiaxBZCNy 4liOS4n39pazmsSLHJeqlqvZ9Ba08XkG2lYPdaIBc5AeYQZJt4pPe0ZESShVBpeZokfAEFJH MVo/FiURx6oyr7Ca1HOaS8ksp0c7GFLqLA7sexUpwfGqdDaJZdNYzaYqYOxcslGCLETW1Bu2 J+ur9mXp3cPh0aLKQkdjlecnc0dIY4m7/YqD37VgWbgPKfeJjqkTuxcmjYwfDQ02HSiu1+Ti SUPwLfs5upCqqh5yzDLtW4r74/+74YTfSkilttFXdNC1NfLkVfOirjd2fGfcBbuUKrctEwt3 ljNi2Erjqccdq4m7pSSXoPKSERpO9Q89EX4iOAMAAA== X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: "simon.horman@netronome.com" , Jiri Benc Subject: [ovs-dev] [PATCH v4 2/7] nx-match: Add context argument to nxm_put__(). 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Ben Pfaff An upcoming commit will need to pass an extra piece of data from nx_put_raw() into all of its direct and indirect calls to nxm_put__(). This commit prepares for that by switching from a "struct ofpbuf *" parameter to a context structure that, currently, contains just a struct ofpbuf *. The upcoming commit will add another member to the context struct. This commit has no visible effect on behavior. Signed-off-by: Ben Pfaff --- lib/nx-match.c | 232 +++++++++++++++++++++++++++++------------------------ lib/nx-match.h | 6 +- lib/tun-metadata.c | 4 +- 3 files changed, 131 insertions(+), 111 deletions(-) diff --git a/lib/nx-match.c b/lib/nx-match.c index 334ecd4a3..6278b7758 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -772,203 +772,222 @@ oxm_pull_field_array(const void *fields_data, size_t fields_len, * 'put' functions whose names end in 'm' add a field that might be wildcarded. * Other 'put' functions add exact-match fields. */ + +struct nxm_put_ctx { + struct ofpbuf *output; +}; + void -nxm_put__(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, - const void *value, const void *mask, size_t n_bytes) +nxm_put_entry_raw(struct ofpbuf *b, + enum mf_field_id field, enum ofp_version version, + const void *value, const void *mask, size_t n_bytes) { nx_put_header_len(b, field, version, !!mask, n_bytes); ofpbuf_put(b, value, n_bytes); if (mask) { ofpbuf_put(b, mask, n_bytes); } +} +static void +nxm_put__(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, + const void *value, const void *mask, size_t n_bytes) +{ + nxm_put_entry_raw(ctx->output, field, version, value, mask, n_bytes); } static void -nxm_put(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, +nxm_put(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, const void *value, const void *mask, size_t n_bytes) { if (!is_all_zeros(mask, n_bytes)) { bool masked = !is_all_ones(mask, n_bytes); - nxm_put__(b, field, version, value, masked ? mask : NULL, n_bytes); + nxm_put__(ctx, field, version, value, masked ? mask : NULL, n_bytes); } } static void -nxm_put_8m(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, +nxm_put_8m(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, uint8_t value, uint8_t mask) { - nxm_put(b, field, version, &value, &mask, sizeof value); + nxm_put(ctx, field, version, &value, &mask, sizeof value); } static void -nxm_put_8(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, - uint8_t value) +nxm_put_8(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, uint8_t value) { - nxm_put__(b, field, version, &value, NULL, sizeof value); + nxm_put__(ctx, field, version, &value, NULL, sizeof value); } static void -nxm_put_16m(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, +nxm_put_16m(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, ovs_be16 value, ovs_be16 mask) { - nxm_put(b, field, version, &value, &mask, sizeof value); + nxm_put(ctx, field, version, &value, &mask, sizeof value); } static void -nxm_put_16(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, - ovs_be16 value) +nxm_put_16(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, ovs_be16 value) { - nxm_put__(b, field, version, &value, NULL, sizeof value); + nxm_put__(ctx, field, version, &value, NULL, sizeof value); } static void -nxm_put_32m(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, +nxm_put_32m(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, ovs_be32 value, ovs_be32 mask) { - nxm_put(b, field, version, &value, &mask, sizeof value); + nxm_put(ctx, field, version, &value, &mask, sizeof value); } static void -nxm_put_32(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, - ovs_be32 value) +nxm_put_32(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, ovs_be32 value) { - nxm_put__(b, field, version, &value, NULL, sizeof value); + nxm_put__(ctx, field, version, &value, NULL, sizeof value); } static void -nxm_put_64m(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version, +nxm_put_64m(struct nxm_put_ctx *ctx, + enum mf_field_id field, enum ofp_version version, ovs_be64 value, ovs_be64 mask) { - nxm_put(b, field, version, &value, &mask, sizeof value); + nxm_put(ctx, field, version, &value, &mask, sizeof value); } static void -nxm_put_128m(struct ofpbuf *b, +nxm_put_128m(struct nxm_put_ctx *ctx, enum mf_field_id field, enum ofp_version version, const ovs_be128 value, const ovs_be128 mask) { - nxm_put(b, field, version, &value, &mask, sizeof(value)); + nxm_put(ctx, field, version, &value, &mask, sizeof(value)); } static void -nxm_put_eth_masked(struct ofpbuf *b, +nxm_put_eth_masked(struct nxm_put_ctx *ctx, enum mf_field_id field, enum ofp_version version, const struct eth_addr value, const struct eth_addr mask) { - nxm_put(b, field, version, value.ea, mask.ea, ETH_ADDR_LEN); + nxm_put(ctx, field, version, value.ea, mask.ea, ETH_ADDR_LEN); } static void -nxm_put_ipv6(struct ofpbuf *b, +nxm_put_ipv6(struct nxm_put_ctx *ctx, enum mf_field_id field, enum ofp_version version, const struct in6_addr *value, const struct in6_addr *mask) { - nxm_put(b, field, version, value->s6_addr, mask->s6_addr, + nxm_put(ctx, field, version, value->s6_addr, mask->s6_addr, sizeof value->s6_addr); } static void -nxm_put_frag(struct ofpbuf *b, const struct match *match, +nxm_put_frag(struct nxm_put_ctx *ctx, const struct match *match, enum ofp_version version) { uint8_t nw_frag = match->flow.nw_frag & FLOW_NW_FRAG_MASK; uint8_t nw_frag_mask = match->wc.masks.nw_frag & FLOW_NW_FRAG_MASK; - nxm_put_8m(b, MFF_IP_FRAG, version, nw_frag, + nxm_put_8m(ctx, MFF_IP_FRAG, version, nw_frag, nw_frag_mask == FLOW_NW_FRAG_MASK ? UINT8_MAX : nw_frag_mask); } /* Appends to 'b' a set of OXM or NXM matches for the IPv4 or IPv6 fields in * 'match'. */ static void -nxm_put_ip(struct ofpbuf *b, const struct match *match, enum ofp_version oxm) +nxm_put_ip(struct nxm_put_ctx *ctx, + const struct match *match, enum ofp_version oxm) { const struct flow *flow = &match->flow; if (flow->dl_type == htons(ETH_TYPE_IP)) { - nxm_put_32m(b, MFF_IPV4_SRC, oxm, + nxm_put_32m(ctx, MFF_IPV4_SRC, oxm, flow->nw_src, match->wc.masks.nw_src); - nxm_put_32m(b, MFF_IPV4_DST, oxm, + nxm_put_32m(ctx, MFF_IPV4_DST, oxm, flow->nw_dst, match->wc.masks.nw_dst); } else { - nxm_put_ipv6(b, MFF_IPV6_SRC, oxm, + nxm_put_ipv6(ctx, MFF_IPV6_SRC, oxm, &flow->ipv6_src, &match->wc.masks.ipv6_src); - nxm_put_ipv6(b, MFF_IPV6_DST, oxm, + nxm_put_ipv6(ctx, MFF_IPV6_DST, oxm, &flow->ipv6_dst, &match->wc.masks.ipv6_dst); } - nxm_put_frag(b, match, oxm); + nxm_put_frag(ctx, match, oxm); if (match->wc.masks.nw_tos & IP_DSCP_MASK) { if (oxm) { - nxm_put_8(b, MFF_IP_DSCP_SHIFTED, oxm, + nxm_put_8(ctx, MFF_IP_DSCP_SHIFTED, oxm, flow->nw_tos >> 2); } else { - nxm_put_8(b, MFF_IP_DSCP, oxm, + nxm_put_8(ctx, MFF_IP_DSCP, oxm, flow->nw_tos & IP_DSCP_MASK); } } if (match->wc.masks.nw_tos & IP_ECN_MASK) { - nxm_put_8(b, MFF_IP_ECN, oxm, + nxm_put_8(ctx, MFF_IP_ECN, oxm, flow->nw_tos & IP_ECN_MASK); } if (match->wc.masks.nw_ttl) { - nxm_put_8(b, MFF_IP_TTL, oxm, flow->nw_ttl); + nxm_put_8(ctx, MFF_IP_TTL, oxm, flow->nw_ttl); } - nxm_put_32m(b, MFF_IPV6_LABEL, oxm, + nxm_put_32m(ctx, MFF_IPV6_LABEL, oxm, flow->ipv6_label, match->wc.masks.ipv6_label); if (match->wc.masks.nw_proto) { - nxm_put_8(b, MFF_IP_PROTO, oxm, flow->nw_proto); + nxm_put_8(ctx, MFF_IP_PROTO, oxm, flow->nw_proto); if (flow->nw_proto == IPPROTO_TCP) { - nxm_put_16m(b, MFF_TCP_SRC, oxm, + nxm_put_16m(ctx, MFF_TCP_SRC, oxm, flow->tp_src, match->wc.masks.tp_src); - nxm_put_16m(b, MFF_TCP_DST, oxm, + nxm_put_16m(ctx, MFF_TCP_DST, oxm, flow->tp_dst, match->wc.masks.tp_dst); - nxm_put_16m(b, MFF_TCP_FLAGS, oxm, + nxm_put_16m(ctx, MFF_TCP_FLAGS, oxm, flow->tcp_flags, match->wc.masks.tcp_flags); } else if (flow->nw_proto == IPPROTO_UDP) { - nxm_put_16m(b, MFF_UDP_SRC, oxm, + nxm_put_16m(ctx, MFF_UDP_SRC, oxm, flow->tp_src, match->wc.masks.tp_src); - nxm_put_16m(b, MFF_UDP_DST, oxm, + nxm_put_16m(ctx, MFF_UDP_DST, oxm, flow->tp_dst, match->wc.masks.tp_dst); } else if (flow->nw_proto == IPPROTO_SCTP) { - nxm_put_16m(b, MFF_SCTP_SRC, oxm, flow->tp_src, + nxm_put_16m(ctx, MFF_SCTP_SRC, oxm, flow->tp_src, match->wc.masks.tp_src); - nxm_put_16m(b, MFF_SCTP_DST, oxm, flow->tp_dst, + nxm_put_16m(ctx, MFF_SCTP_DST, oxm, flow->tp_dst, match->wc.masks.tp_dst); } else if (is_icmpv4(flow, NULL)) { if (match->wc.masks.tp_src) { - nxm_put_8(b, MFF_ICMPV4_TYPE, oxm, + nxm_put_8(ctx, MFF_ICMPV4_TYPE, oxm, ntohs(flow->tp_src)); } if (match->wc.masks.tp_dst) { - nxm_put_8(b, MFF_ICMPV4_CODE, oxm, + nxm_put_8(ctx, MFF_ICMPV4_CODE, oxm, ntohs(flow->tp_dst)); } } else if (is_icmpv6(flow, NULL)) { if (match->wc.masks.tp_src) { - nxm_put_8(b, MFF_ICMPV6_TYPE, oxm, + nxm_put_8(ctx, MFF_ICMPV6_TYPE, oxm, ntohs(flow->tp_src)); } if (match->wc.masks.tp_dst) { - nxm_put_8(b, MFF_ICMPV6_CODE, oxm, + nxm_put_8(ctx, MFF_ICMPV6_CODE, oxm, ntohs(flow->tp_dst)); } if (is_nd(flow, NULL)) { - nxm_put_ipv6(b, MFF_ND_TARGET, oxm, + nxm_put_ipv6(ctx, MFF_ND_TARGET, oxm, &flow->nd_target, &match->wc.masks.nd_target); if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)) { - nxm_put_eth_masked(b, MFF_ND_SLL, oxm, + nxm_put_eth_masked(ctx, MFF_ND_SLL, oxm, flow->arp_sha, match->wc.masks.arp_sha); } if (flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) { - nxm_put_eth_masked(b, MFF_ND_TLL, oxm, + nxm_put_eth_masked(ctx, MFF_ND_TLL, oxm, flow->arp_tha, match->wc.masks.arp_tha); } } @@ -1000,41 +1019,43 @@ nx_put_raw(struct ofpbuf *b, enum ofp_version oxm, const struct match *match, BUILD_ASSERT_DECL(FLOW_WC_SEQ == 39); + struct nxm_put_ctx ctx = { .output = b }; + /* Metadata. */ if (match->wc.masks.dp_hash) { - nxm_put_32m(b, MFF_DP_HASH, oxm, + nxm_put_32m(&ctx, MFF_DP_HASH, oxm, htonl(flow->dp_hash), htonl(match->wc.masks.dp_hash)); } if (match->wc.masks.recirc_id) { - nxm_put_32(b, MFF_RECIRC_ID, oxm, htonl(flow->recirc_id)); + nxm_put_32(&ctx, MFF_RECIRC_ID, oxm, htonl(flow->recirc_id)); } if (match->wc.masks.conj_id) { - nxm_put_32(b, MFF_CONJ_ID, oxm, htonl(flow->conj_id)); + nxm_put_32(&ctx, MFF_CONJ_ID, oxm, htonl(flow->conj_id)); } if (match->wc.masks.in_port.ofp_port) { ofp_port_t in_port = flow->in_port.ofp_port; if (oxm) { - nxm_put_32(b, MFF_IN_PORT_OXM, oxm, + nxm_put_32(&ctx, MFF_IN_PORT_OXM, oxm, ofputil_port_to_ofp11(in_port)); } else { - nxm_put_16(b, MFF_IN_PORT, oxm, + nxm_put_16(&ctx, MFF_IN_PORT, oxm, htons(ofp_to_u16(in_port))); } } if (match->wc.masks.actset_output) { - nxm_put_32(b, MFF_ACTSET_OUTPUT, oxm, + nxm_put_32(&ctx, MFF_ACTSET_OUTPUT, oxm, ofputil_port_to_ofp11(flow->actset_output)); } /* Ethernet. */ - nxm_put_eth_masked(b, MFF_ETH_SRC, oxm, + nxm_put_eth_masked(&ctx, MFF_ETH_SRC, oxm, flow->dl_src, match->wc.masks.dl_src); - nxm_put_eth_masked(b, MFF_ETH_DST, oxm, + nxm_put_eth_masked(&ctx, MFF_ETH_DST, oxm, flow->dl_dst, match->wc.masks.dl_dst); - nxm_put_16m(b, MFF_ETH_TYPE, oxm, + nxm_put_16m(&ctx, MFF_ETH_TYPE, oxm, ofputil_dl_type_to_openflow(flow->dl_type), match->wc.masks.dl_type); @@ -1045,124 +1066,124 @@ nx_put_raw(struct ofpbuf *b, enum ofp_version oxm, const struct match *match, ovs_be16 mask = match->wc.masks.vlans[0].tci & VID_CFI_MASK; if (mask == htons(VLAN_VID_MASK | VLAN_CFI)) { - nxm_put_16(b, MFF_VLAN_VID, oxm, vid); + nxm_put_16(&ctx, MFF_VLAN_VID, oxm, vid); } else if (mask) { - nxm_put_16m(b, MFF_VLAN_VID, oxm, vid, mask); + nxm_put_16m(&ctx, MFF_VLAN_VID, oxm, vid, mask); } if (vid && vlan_tci_to_pcp(match->wc.masks.vlans[0].tci)) { - nxm_put_8(b, MFF_VLAN_PCP, oxm, + nxm_put_8(&ctx, MFF_VLAN_PCP, oxm, vlan_tci_to_pcp(flow->vlans[0].tci)); } } else { - nxm_put_16m(b, MFF_VLAN_TCI, oxm, flow->vlans[0].tci, + nxm_put_16m(&ctx, MFF_VLAN_TCI, oxm, flow->vlans[0].tci, match->wc.masks.vlans[0].tci); } /* MPLS. */ if (eth_type_mpls(flow->dl_type)) { if (match->wc.masks.mpls_lse[0] & htonl(MPLS_TC_MASK)) { - nxm_put_8(b, MFF_MPLS_TC, oxm, + nxm_put_8(&ctx, MFF_MPLS_TC, oxm, mpls_lse_to_tc(flow->mpls_lse[0])); } if (match->wc.masks.mpls_lse[0] & htonl(MPLS_BOS_MASK)) { - nxm_put_8(b, MFF_MPLS_BOS, oxm, + nxm_put_8(&ctx, MFF_MPLS_BOS, oxm, mpls_lse_to_bos(flow->mpls_lse[0])); } if (match->wc.masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK)) { - nxm_put_32(b, MFF_MPLS_LABEL, oxm, + nxm_put_32(&ctx, MFF_MPLS_LABEL, oxm, htonl(mpls_lse_to_label(flow->mpls_lse[0]))); } } /* L3. */ if (is_ip_any(flow)) { - nxm_put_ip(b, match, oxm); + nxm_put_ip(&ctx, match, oxm); } else if (flow->dl_type == htons(ETH_TYPE_ARP) || flow->dl_type == htons(ETH_TYPE_RARP)) { /* ARP. */ if (match->wc.masks.nw_proto) { - nxm_put_16(b, MFF_ARP_OP, oxm, + nxm_put_16(&ctx, MFF_ARP_OP, oxm, htons(flow->nw_proto)); } - nxm_put_32m(b, MFF_ARP_SPA, oxm, + nxm_put_32m(&ctx, MFF_ARP_SPA, oxm, flow->nw_src, match->wc.masks.nw_src); - nxm_put_32m(b, MFF_ARP_TPA, oxm, + nxm_put_32m(&ctx, MFF_ARP_TPA, oxm, flow->nw_dst, match->wc.masks.nw_dst); - nxm_put_eth_masked(b, MFF_ARP_SHA, oxm, + nxm_put_eth_masked(&ctx, MFF_ARP_SHA, oxm, flow->arp_sha, match->wc.masks.arp_sha); - nxm_put_eth_masked(b, MFF_ARP_THA, oxm, + nxm_put_eth_masked(&ctx, MFF_ARP_THA, oxm, flow->arp_tha, match->wc.masks.arp_tha); } /* Tunnel ID. */ - nxm_put_64m(b, MFF_TUN_ID, oxm, + nxm_put_64m(&ctx, MFF_TUN_ID, oxm, flow->tunnel.tun_id, match->wc.masks.tunnel.tun_id); /* Other tunnel metadata. */ - nxm_put_16m(b, MFF_TUN_FLAGS, oxm, + nxm_put_16m(&ctx, MFF_TUN_FLAGS, oxm, htons(flow->tunnel.flags), htons(match->wc.masks.tunnel.flags)); - nxm_put_32m(b, MFF_TUN_SRC, oxm, + nxm_put_32m(&ctx, MFF_TUN_SRC, oxm, flow->tunnel.ip_src, match->wc.masks.tunnel.ip_src); - nxm_put_32m(b, MFF_TUN_DST, oxm, + nxm_put_32m(&ctx, MFF_TUN_DST, oxm, flow->tunnel.ip_dst, match->wc.masks.tunnel.ip_dst); - nxm_put_ipv6(b, MFF_TUN_IPV6_SRC, oxm, + nxm_put_ipv6(&ctx, MFF_TUN_IPV6_SRC, oxm, &flow->tunnel.ipv6_src, &match->wc.masks.tunnel.ipv6_src); - nxm_put_ipv6(b, MFF_TUN_IPV6_DST, oxm, + nxm_put_ipv6(&ctx, MFF_TUN_IPV6_DST, oxm, &flow->tunnel.ipv6_dst, &match->wc.masks.tunnel.ipv6_dst); - nxm_put_16m(b, MFF_TUN_GBP_ID, oxm, + nxm_put_16m(&ctx, MFF_TUN_GBP_ID, oxm, flow->tunnel.gbp_id, match->wc.masks.tunnel.gbp_id); - nxm_put_8m(b, MFF_TUN_GBP_FLAGS, oxm, + nxm_put_8m(&ctx, MFF_TUN_GBP_FLAGS, oxm, flow->tunnel.gbp_flags, match->wc.masks.tunnel.gbp_flags); tun_metadata_to_nx_match(b, oxm, match); /* Registers. */ if (oxm < OFP15_VERSION) { for (i = 0; i < FLOW_N_REGS; i++) { - nxm_put_32m(b, MFF_REG0 + i, oxm, + nxm_put_32m(&ctx, MFF_REG0 + i, oxm, htonl(flow->regs[i]), htonl(match->wc.masks.regs[i])); } } else { for (i = 0; i < FLOW_N_XREGS; i++) { - nxm_put_64m(b, MFF_XREG0 + i, oxm, + nxm_put_64m(&ctx, MFF_XREG0 + i, oxm, htonll(flow_get_xreg(flow, i)), htonll(flow_get_xreg(&match->wc.masks, i))); } } /* Packet mark. */ - nxm_put_32m(b, MFF_PKT_MARK, oxm, htonl(flow->pkt_mark), + nxm_put_32m(&ctx, MFF_PKT_MARK, oxm, htonl(flow->pkt_mark), htonl(match->wc.masks.pkt_mark)); /* Connection tracking. */ - nxm_put_32m(b, MFF_CT_STATE, oxm, htonl(flow->ct_state), + nxm_put_32m(&ctx, MFF_CT_STATE, oxm, htonl(flow->ct_state), htonl(match->wc.masks.ct_state)); - nxm_put_16m(b, MFF_CT_ZONE, oxm, htons(flow->ct_zone), + nxm_put_16m(&ctx, MFF_CT_ZONE, oxm, htons(flow->ct_zone), htons(match->wc.masks.ct_zone)); - nxm_put_32m(b, MFF_CT_MARK, oxm, htonl(flow->ct_mark), + nxm_put_32m(&ctx, MFF_CT_MARK, oxm, htonl(flow->ct_mark), htonl(match->wc.masks.ct_mark)); - nxm_put_128m(b, MFF_CT_LABEL, oxm, hton128(flow->ct_label), + nxm_put_128m(&ctx, MFF_CT_LABEL, oxm, hton128(flow->ct_label), hton128(match->wc.masks.ct_label)); - nxm_put_32m(b, MFF_CT_NW_SRC, oxm, + nxm_put_32m(&ctx, MFF_CT_NW_SRC, oxm, flow->ct_nw_src, match->wc.masks.ct_nw_src); - nxm_put_ipv6(b, MFF_CT_IPV6_SRC, oxm, + nxm_put_ipv6(&ctx, MFF_CT_IPV6_SRC, oxm, &flow->ct_ipv6_src, &match->wc.masks.ct_ipv6_src); - nxm_put_32m(b, MFF_CT_NW_DST, oxm, + nxm_put_32m(&ctx, MFF_CT_NW_DST, oxm, flow->ct_nw_dst, match->wc.masks.ct_nw_dst); - nxm_put_ipv6(b, MFF_CT_IPV6_DST, oxm, + nxm_put_ipv6(&ctx, MFF_CT_IPV6_DST, oxm, &flow->ct_ipv6_dst, &match->wc.masks.ct_ipv6_dst); if (flow->ct_nw_proto) { - nxm_put_8(b, MFF_CT_NW_PROTO, oxm, flow->ct_nw_proto); - nxm_put_16m(b, MFF_CT_TP_SRC, oxm, + nxm_put_8(&ctx, MFF_CT_NW_PROTO, oxm, flow->ct_nw_proto); + nxm_put_16m(&ctx, MFF_CT_TP_SRC, oxm, flow->ct_tp_src, match->wc.masks.ct_tp_src); - nxm_put_16m(b, MFF_CT_TP_DST, oxm, + nxm_put_16m(&ctx, MFF_CT_TP_DST, oxm, flow->ct_tp_dst, match->wc.masks.ct_tp_dst); } /* OpenFlow 1.1+ Metadata. */ - nxm_put_64m(b, MFF_METADATA, oxm, + nxm_put_64m(&ctx, MFF_METADATA, oxm, flow->metadata, match->wc.masks.metadata); /* Cookie. */ @@ -1326,7 +1347,8 @@ oxm_put_field_array(struct ofpbuf *b, const struct field_array *fa, memcpy(&value, fa->values + offset, mf->n_bytes); int len = mf_field_len(mf, &value, NULL, NULL); - nxm_put__(b, i, version, &value + mf->n_bytes - len, NULL, len); + nxm_put_entry_raw(b, i, version, + &value + mf->n_bytes - len, NULL, len); offset += mf->n_bytes; } @@ -1383,11 +1405,9 @@ nx_put_entry(struct ofpbuf *b, const struct mf_field *mff, len = mf_field_len(mff, value, mask, &masked); offset = mff->n_bytes - len; - nx_put_header_len(b, mff->id, version, masked, len); - ofpbuf_put(b, &value->u8 + offset, len); - if (masked) { - ofpbuf_put(b, &mask->u8 + offset, len); - } + nxm_put_entry_raw(b, mff->id, version, + &value->u8 + offset, masked ? &mask->u8 + offset : NULL, + len); } /* nx_match_to_string() and helpers. */ diff --git a/lib/nx-match.h b/lib/nx-match.h index 90cb6f8fd..e304072d3 100644 --- a/lib/nx-match.h +++ b/lib/nx-match.h @@ -85,9 +85,9 @@ enum ofperr nx_pull_entry(struct ofpbuf *, const struct vl_mff_map *, union mf_value *mask); enum ofperr nx_pull_header(struct ofpbuf *, const struct vl_mff_map *, const struct mf_field **, bool *masked); -void nxm_put__(struct ofpbuf *b, enum mf_field_id field, - enum ofp_version version, const void *value, - const void *mask, size_t n_bytes); +void nxm_put_entry_raw(struct ofpbuf *, enum mf_field_id field, + enum ofp_version version, const void *value, + const void *mask, size_t n_bytes); void nx_put_entry(struct ofpbuf *, const struct mf_field *, enum ofp_version, const union mf_value *value, const union mf_value *mask); void nx_put_header(struct ofpbuf *, enum mf_field_id, enum ofp_version, diff --git a/lib/tun-metadata.c b/lib/tun-metadata.c index 08858f114..2fbd9b67e 100644 --- a/lib/tun-metadata.c +++ b/lib/tun-metadata.c @@ -875,8 +875,8 @@ tun_metadata_to_nx_match(struct ofpbuf *b, enum ofp_version oxm, loc); memcpy_from_metadata(mask_opts.tun_metadata, &match->wc.masks.tunnel.metadata, loc); - nxm_put__(b, MFF_TUN_METADATA0 + i, oxm, opts.tun_metadata, - is_masked ? mask_opts.tun_metadata : NULL, loc->len); + nxm_put_entry_raw(b, MFF_TUN_METADATA0 + i, oxm, opts.tun_metadata, + is_masked ? mask_opts.tun_metadata : NULL, loc->len); } }