From patchwork Fri Oct 4 01:55:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankur Sharma X-Patchwork-Id: 1171520 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nutanix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.b="C4WBp0tA"; dkim-atps=neutral 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 46ktKV1CwXz9sNw for ; Fri, 4 Oct 2019 11:57:02 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EA6F31713; Fri, 4 Oct 2019 01:56:22 +0000 (UTC) X-Original-To: ovs-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 7612A1709 for ; Fri, 4 Oct 2019 01:55:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id D910F5D3 for ; Fri, 4 Oct 2019 01:55:39 +0000 (UTC) Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x941sdad002964 for ; Thu, 3 Oct 2019 18:55:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=P3JN3HgaDvDJhtbc2z1gFzgpdtrNX7k6bBIzHgpP8Z4=; b=C4WBp0tAa/lPBPcx7tPf9NSlmv0QlZ+tHNxbu9TjE3bUGhJQtQDidksjKfFWD0ZwZI9D qzTl5e2R77y0mnsvoImFvEUdTnug7J3gR6O7XyHHHuhaaa/dvoztMjRMr7YXBjsoY6O+ ZlrxcuUX3XnV/sytsXWFe4DaaTpJFVDBP0vFKIRXQBlxQAxylb3OgzobwM9tckHkkCwn YbxkV3KSzmGGx+yguQ4hfwY0zTdlRQcbAfG+xpW8LrLzEaoZz8qGtySEJPWv0JK/J+Ii c+AKcrEz2DoTqGANqcFbsUWla9u/+wAsxWJwyEUeHccvffCE8A6n1LprIJVAxotS7HoA 5g== Received: from nam04-sn1-obe.outbound.protection.outlook.com (mail-sn1nam04lp2054.outbound.protection.outlook.com [104.47.44.54]) by mx0a-002c1b01.pphosted.com with ESMTP id 2va3uu4qfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 03 Oct 2019 18:55:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2uF2o+O6iGDmJWe0Cp9iKyPF+dZSohvtNkbEMNhyvavzZv2VhPVsECN/y2h4JBchiBaxmQerb6hryW8vyFlCpqjWpNgCBLaDGiizOBaiKhzsU634a0Ua0Ui4HQYAxgZ86k+AXkMuFHXGItWsq+P6XZMzbXF/yIt+J2TqeUJTx8Bk4mVx0thvzJ1D48bctm07I2xzNm4aNstqiNqDbAxymUwrwTNZNSL+ts0/DaZ5ihSEqHIN7gD2JKEkttMYnAHaW3Y4LQ/Qxw68tlJFlYtDfIpaCEvdSdc1xe8LeOC8gGw2HUvLzCYl0XMT7Irf2SGqyLByrlg+8/svfByj8V0bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P3JN3HgaDvDJhtbc2z1gFzgpdtrNX7k6bBIzHgpP8Z4=; b=V1lG5U6avzo+Ry7onnL6Ue0Bou8f1alx5QcnonGEkj8sH7hSzBDIUwgIbR68CnC2HE/nRKi6udTcH0JjEFQsi1P7X1XXviE7RMxP+TxuKM5WuN3kc73J6ccG3f7ojygf6XmGwzfewD+dFaG1GJRUp/Pz5WRX1eFy4cBw7ncEU8wbY0NJCGIZphkle5QpcLoKCADaDBOYpY4V9RKocDUCtMqGeg1e0LwkCsNJaUEgPFZieoZsOWCoNT0ALhdvZQBPWQs1219egcYwDsPbM5G3EZuBuy5WUtnN2AV6AEjHFTeMwBGAYXMEyBwLz/En44yHPDqPm7L3TxqBBK3kwuW3cA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from SN1PR02MB3901.namprd02.prod.outlook.com (52.132.194.18) by SN1PR02MB3695.namprd02.prod.outlook.com (52.132.198.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.17; Fri, 4 Oct 2019 01:55:38 +0000 Received: from SN1PR02MB3901.namprd02.prod.outlook.com ([fe80::fd4b:9ebb:e59a:f4c2]) by SN1PR02MB3901.namprd02.prod.outlook.com ([fe80::fd4b:9ebb:e59a:f4c2%4]) with mapi id 15.20.2305.023; Fri, 4 Oct 2019 01:55:38 +0000 From: Ankur Sharma To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v1 1/3 ovn] OVN: ADD new ovn actions to replace source and destination ip Thread-Index: AQHVelbRH9J9afkNAUGfTr056ecUNA== Date: Fri, 4 Oct 2019 01:55:38 +0000 Message-ID: <1570154179-14525-2-git-send-email-ankur.sharma@nutanix.com> References: <1570154179-14525-1-git-send-email-ankur.sharma@nutanix.com> In-Reply-To: <1570154179-14525-1-git-send-email-ankur.sharma@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR11CA0078.namprd11.prod.outlook.com (2603:10b6:a03:f4::19) To SN1PR02MB3901.namprd02.prod.outlook.com (2603:10b6:802:24::18) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [192.146.154.98] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bdd8f41c-0492-40c7-05a9-08d7486df414 x-ms-traffictypediagnostic: SN1PR02MB3695: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:415; x-forefront-prvs: 018093A9B5 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(39860400002)(376002)(136003)(366004)(396003)(189003)(199004)(36756003)(4326008)(66446008)(2501003)(50226002)(64756008)(8936002)(8676002)(81166006)(81156014)(86362001)(5640700003)(6512007)(76176011)(52116002)(6436002)(6486002)(99286004)(71190400001)(71200400001)(107886003)(14444005)(66066001)(256004)(11346002)(446003)(44832011)(3846002)(6116002)(386003)(6506007)(2616005)(486006)(476003)(305945005)(7736002)(186003)(102836004)(2906002)(26005)(478600001)(316002)(25786009)(66946007)(66476007)(4720700003)(5660300002)(14454004)(2351001)(66556008)(6916009)(64030200001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR02MB3695; H:SN1PR02MB3901.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hVJPx52lAJfey+ePiCdquQHzmsTrPxptWxNWXOHl3j8mFiC0TAXBIGuNCw0SNRaLEJ+UhoDSAEFKvlUYqV7JZjGr4pXBqVfYXgOO8vWx0MDFjMmjpoEUVI9P53NiGH7OrjHSrLKxY6h1GyOIZeqprPj2QecPF1QjbF5TOCVNedS6PHytsurn4RRfvPq42GQOVelRefZiUZ2jqu9kJVQ5v/pUZmrPi+MiZMQRHlBRYsiSJJZdGUE0Il5avcbil6lFr7ISlb89S0XJ7i0S6QeFl8Ph9wwoUNHvcWjqbLLlSwN0FclF8GHSRViqGKMIDxGxswoN1kQNNbfVRQuuv64fZ7RlYC28UXsqHuO9K/i+jLoaT6OBklH2EA6yVafsjc/xaVLJI7bb0Y8K3A3NKL2ONie8aNtQXsf+cKGr/Mry0EY= MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdd8f41c-0492-40c7-05a9-08d7486df414 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Oct 2019 01:55:38.1721 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: xy/ZFVP9KBvYsDePKfxwEbrh0jkmgkANqSgG55CleACgHEJ7AAVgVNqYC/spbYrVTLEyDq/HDTHeMC3z7fbBAs+GYhYd1SbgCeX+B+BH4QQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR02MB3695 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-04_01:2019-10-03,2019-10-04 signatures=0 X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 Subject: [ovs-dev] [PATCH v1 1/3 ovn] OVN: ADD new ovn actions to replace source and destination ip 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 This patch adds 2 new ovn actions, "replace_src_ip" and "replace_dst_ip" These actions map to mod_nw_src and mod_nw_dst OVS actions respectively. These actions simply replace the source and destination IPs of the packets, while changing the L3 and L4 checksums. Signed-off-by: Ankur Sharma --- include/ovn/actions.h | 10 ++++- lib/actions.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ovn.at | 26 +++++++++++++ utilities/ovn-trace.c | 6 +++ 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/include/ovn/actions.h b/include/ovn/actions.h index 145f27f..b451e95 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -86,7 +86,9 @@ struct ovn_extend_table; OVNACT(OVNFIELD_LOAD, ovnact_load) \ OVNACT(CHECK_PKT_LARGER, ovnact_check_pkt_larger) \ OVNACT(TRIGGER_EVENT, ovnact_controller_event) \ - OVNACT(BIND_VPORT, ovnact_bind_vport) + OVNACT(BIND_VPORT, ovnact_bind_vport) \ + OVNACT(REPLACE_SRC_IP, ovnact_ip_replace) \ + OVNACT(REPLACE_DST_IP, ovnact_ip_replace) /* enum ovnact_type, with a member OVNACT_ for each action. */ enum OVS_PACKED_ENUM ovnact_type { @@ -279,6 +281,12 @@ struct ovnact_put_opts { size_t n_options; }; +/* OVNACT_REPLACE_SRC_IP, OVNACT_REPLACE_DST_IP. */ +struct ovnact_ip_replace { + struct ovnact ovnact; + ovs_be32 ip; +}; + /* Valid arguments to SET_QUEUE action. * * QDISC_MIN_QUEUE_ID is the default queue, so user-defined queues should diff --git a/lib/actions.c b/lib/actions.c index 6a5907e..f305996 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -871,6 +871,105 @@ ovnact_ct_nat_free(struct ovnact_ct_nat *ct_nat OVS_UNUSED) { } + +static void +parse_replace_ip(struct action_context *ctx, struct ovnact_ip_replace *ipr) +{ + add_prerequisite(ctx, "ip"); + + if (lexer_match(ctx->lexer, LEX_T_LPAREN)) { + if (ctx->lexer->token.type != LEX_T_INTEGER + || ctx->lexer->token.format != LEX_F_IPV4) { + lexer_syntax_error(ctx->lexer, "expecting IPv4 address"); + return; + } + ipr->ip = ctx->lexer->token.value.ipv4; + lexer_get(ctx->lexer); + + if (!lexer_force_match(ctx->lexer, LEX_T_RPAREN)) { + return; + } + } else { + lexer_syntax_error(ctx->lexer, "Invalid token"); + } +} + +static void +parse_REPLACE_DST_IP(struct action_context *ctx) +{ + parse_replace_ip(ctx, ovnact_put_REPLACE_DST_IP(ctx->ovnacts)); +} + +static void +parse_REPLACE_SRC_IP(struct action_context *ctx) +{ + parse_replace_ip(ctx, ovnact_put_REPLACE_SRC_IP(ctx->ovnacts)); +} + +static void +format_replace_ip(const struct ovnact_ip_replace *ipr, + const char *name, struct ds *s) +{ + ds_put_cstr(s, name); + ds_put_format(s, "("IP_FMT")", IP_ARGS(ipr->ip)); + ds_put_char(s, ';'); +} + +static void +format_REPLACE_DST_IP(const struct ovnact_ip_replace *ipr, struct ds *s) +{ + format_replace_ip(ipr, "replace_dst_ip", s); +} + +static void +format_REPLACE_SRC_IP(const struct ovnact_ip_replace *ipr, struct ds *s) +{ + format_replace_ip(ipr, "replace_src_ip", s); +} + +static void +encode_replace_ip(const struct ovnact_ip_replace *ipr, + const struct ovnact_encode_params *ep OVS_UNUSED, + bool is_src, struct ofpbuf *ofpacts) +{ + struct ofpact_ipv4 *replace_ip; + const size_t ip_offset = ofpacts->size; + ofpbuf_pull(ofpacts, ip_offset); + + if (!is_src) { + replace_ip = ofpact_put_SET_IPV4_DST(ofpacts); + + } else { + replace_ip = ofpact_put_SET_IPV4_SRC(ofpacts); + } + + replace_ip->ipv4 = ipr->ip; + + ofpbuf_push_uninit(ofpacts, ip_offset); + ofpact_finish(ofpacts, &replace_ip->ofpact); +} + +static void +encode_REPLACE_SRC_IP(const struct ovnact_ip_replace *ipr, + const struct ovnact_encode_params *ep, + struct ofpbuf *ofpacts) +{ + encode_replace_ip(ipr, ep, true, ofpacts); +} + +static void +encode_REPLACE_DST_IP(const struct ovnact_ip_replace *ipr, + const struct ovnact_encode_params *ep, + struct ofpbuf *ofpacts) +{ + encode_replace_ip(ipr, ep, false, ofpacts); +} + +static void +ovnact_ip_replace_free(struct ovnact_ip_replace *ipr OVS_UNUSED) +{ +} + static void parse_ct_lb_action(struct action_context *ctx) { @@ -2798,6 +2897,10 @@ parse_action(struct action_context *ctx) parse_trigger_event(ctx, ovnact_put_TRIGGER_EVENT(ctx->ovnacts)); } else if (lexer_match_id(ctx->lexer, "bind_vport")) { parse_bind_vport(ctx); + } else if (lexer_match_id(ctx->lexer, "replace_src_ip")) { + parse_REPLACE_SRC_IP(ctx); + } else if (lexer_match_id(ctx->lexer, "replace_dst_ip")) { + parse_REPLACE_DST_IP(ctx); } else { lexer_syntax_error(ctx->lexer, "expecting action"); } diff --git a/tests/ovn.at b/tests/ovn.at index 04898dd..f4f0798 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -1432,6 +1432,32 @@ bind_vport("xyzzy",; bind_vport("xyzzy", inport; Syntax error at `;' expecting `)'. +# replace_src_ip +replace_src_ip(1.2.3.4); + encodes as mod_nw_src:1.2.3.4 + has prereqs ip +replace_src_ip; + Syntax error at `;' Invalid token. +replace_src_ip(; + Syntax error at `;' expecting IPv4 address. +replace_src_ip("; + Input ends inside quoted string. +replace_src_ip(1.2.3); + Invalid numeric constant. + +# replace_dst_ip +replace_dst_ip(1.2.3.4); + encodes as mod_nw_dst:1.2.3.4 + has prereqs ip +replace_dst_ip; + Syntax error at `;' Invalid token. +replace_dst_ip(; + Syntax error at `;' expecting IPv4 address. +replace_dst_ip("; + Input ends inside quoted string. +replace_dst_ip(1.2.3); + Invalid numeric constant. + # Miscellaneous negative tests. ; Syntax error at `;'. diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c index 0583610..2924e56 100644 --- a/utilities/ovn-trace.c +++ b/utilities/ovn-trace.c @@ -2147,6 +2147,12 @@ trace_actions(const struct ovnact *ovnacts, size_t ovnacts_len, case OVNACT_BIND_VPORT: break; + + case OVNACT_REPLACE_SRC_IP: + break; + + case OVNACT_REPLACE_DST_IP: + break; } } ds_destroy(&s);