From patchwork Mon Oct 22 22:24:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mary Manohar X-Patchwork-Id: 987963 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" (1024-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.b="7AI/7Ahf"; 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 42fB096Cm3z9sN6 for ; Tue, 23 Oct 2018 09:24:41 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1105AA7B; Mon, 22 Oct 2018 22:24:10 +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 04F9086F for ; Mon, 22 Oct 2018 22:24:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7791481C for ; Mon, 22 Oct 2018 22:24:08 +0000 (UTC) Received: from pps.filterd (m0127843.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.0.23/8.16.0.23) with SMTP id w9MMK3Ev008312 for ; Mon, 22 Oct 2018 15:24:07 -0700 Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp0018.outbound.protection.outlook.com [216.32.180.18]) by mx0b-002c1b01.pphosted.com with ESMTP id 2n82fg45tu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 22 Oct 2018 15:24:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C1hVmXt3M3X16FJqoALahy4+d0eDMrnLQXfMeYMpIt8=; b=7AI/7AhfAwrMkJswH8ughtW2lDZF0nCzMu8tycYi+PFbfm1sS+KEFjED0jFKGirBpfrCOC0imEWe5cRQCGLc67EKg7RYD8RRaATbZiUlFnie3s12nmjnjGLD8bFGNaBOqr+QIKPfGd+y9Lz3/XKY04osSsIkpHJyOx/Ra+2VuCk= Received: from SN6PR02MB3933.namprd02.prod.outlook.com (52.135.69.14) by SN6PR02MB4160.namprd02.prod.outlook.com (52.135.70.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.30; Mon, 22 Oct 2018 22:24:06 +0000 Received: from SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27]) by SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27%3]) with mapi id 15.20.1250.028; Mon, 22 Oct 2018 22:24:06 +0000 From: Mary Manohar To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v1 1/3] [1/3]: Routing policies, add config in schema Thread-Index: AQHUalXx34x4qjDD9U28GCORf+gLHA== Date: Mon, 22 Oct 2018 22:24:06 +0000 Message-ID: <1540247132-167477-2-git-send-email-mary.manohar@nutanix.com> References: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> In-Reply-To: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR05CA0104.namprd05.prod.outlook.com (2603:10b6:a03:e0::45) To SN6PR02MB3933.namprd02.prod.outlook.com (2603:10b6:805:2b::14) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [205.209.132.11] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR02MB4160; 6:ApfPvYnI06p/HkxVVQIioZkySTzKSHEqS38nWzjnitRrPGHEEKV0JipquygWGoDfNlaTsiLG7uIGhcNBdR7M5+zt5SiTWJtuUIU7p3ncqfCSy1RwpGUc9vRoXQd5zxmO5XS/Kczj+0qz4SRQ/y6iNrtfmuaeHGQMr8rExIef3H175S7+EmuxcGMnBlEuPuE6O6bTmb1V0wtTTasOb6T1CiUUMXKb9oHulWJ+C2PmBGQ0WQD0d2Wg5Wr1KcF44lfRqCfOH3FmVLB+pu/VceJj+z1Y0lB2RIk1nZc5kfRMK7LADS2uq8uYeBZ58DOs/Z59G38nhqN1l5vSVtcbOawqJSa4a/YA/CuTROQq1rvnhizbwn+SVR/kCfbPkm32ACQOmfulELxq4pzxEuy4SQy94g/BrP3v850iJNEcuW1+G8kFKrUq5mWKYwpbHA6kn7aDSP6ydYZ1Yt2UMFKGoZcHWg==; 5:ybV+LTg1np2Ou7JKQpf2lelMRWKDUN0aNbeXZS5YBZig9KsTGacagCNJ3qrm4jRnBpSPF5eeMKXS6aT48QRftHPbdpFAhEcz4VH9NEuGwXJaJaNkNnUiV+v/Ed/7lEwdTp0zgScUGbzyo+Rv17oEAG0Z7Ip1pHhjoLxsDgkTiJk=; 7:4cSY99IH70QSBZS1aCzzNTIOHnq86wVbkWwUW+TjFlhfyibntVoLZl/Ag8YDvIo9x5ffeMRfss5B+zv1wENySafVaXQUvAbQIDP9fMZAS1hx2eWU5xqC7pNoKM64FtGCuTDpCBA01EgyrU6q9OvZEHB8P/M87KXOR4zwqpHF5jkF/iPPTHAnAUH252jMn+nt3NDcbRGwX/OQoNtCWobWvk/GjGdY0nXLUWzR6nvtP6NzUrWZo4SVEkMyGt8gvo2E x-ms-office365-filtering-correlation-id: b4d5a4a0-a73f-4b8f-d320-08d6386d1403 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7167020)(7153060)(7193020); SRVR:SN6PR02MB4160; x-ms-traffictypediagnostic: SN6PR02MB4160: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231355)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:SN6PR02MB4160; BCL:0; PCL:0; RULEID:; SRVR:SN6PR02MB4160; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(346002)(39860400002)(136003)(396003)(199004)(189003)(256004)(52116002)(14444005)(76176011)(5660300001)(99286004)(2351001)(316002)(106356001)(86362001)(105586002)(44832011)(107886003)(486006)(14454004)(25786009)(186003)(102836004)(26005)(11346002)(2616005)(305945005)(446003)(4326008)(476003)(6116002)(3846002)(478600001)(7736002)(2906002)(8676002)(5250100002)(81166006)(8936002)(6512007)(2501003)(81156014)(5640700003)(6436002)(68736007)(71190400001)(71200400001)(66066001)(6486002)(2900100001)(97736004)(55236004)(53936002)(6916009)(36756003)(386003)(6506007)(64030200001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR02MB4160; H:SN6PR02MB3933.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: XaxbRlTNihHLMJK0k9nALCfaRWXg3bIku2kAdiwHiRNLr+qXoVFwpqfhvabHOaNdgJx/1uy7oYT1hzoVNqSCATocz+BPgCUbLMp4btmqjRJyBrQEDqBrflitr/fF3LEoHWkwCT21hlGwWHan5MMVVZAgegg+PEsKWKydC5y5VpBf7nBk8ODZhFEOOpK6mMd4EINSR1m0Kg97rmG9qOV+QvmA4p3M71oL2zbhL+0MgTnQU48T+gOVXno3I8H+XhPrS+t46PjIuvCMqMJAdHh/5EyeOpwqiiAUXVzv9oWrWmJJPtAaM2Ghq6ZB0zivpNd/8GjcH9/RYsYQ6EgiJzzfvgVRJIRUYZceg9HYIK2Yawg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4d5a4a0-a73f-4b8f-d320-08d6386d1403 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 22:24:06.1742 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4160 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-22_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810220188 X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Mary Manohar Subject: [ovs-dev] [PATCH v1 1/3] [1/3]: Routing policies, add config in schema 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 Series: Policy-Based Routing. This Patch: Add routing policies in the northbound schema. --- ovn/ovn-nb.ovsschema | 20 ++++++++++++++++- ovn/ovn-nb.xml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/ovn/ovn-nb.ovsschema b/ovn/ovn-nb.ovsschema index 705cc27..8465f12 100644 --- a/ovn/ovn-nb.ovsschema +++ b/ovn/ovn-nb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Northbound", "version": "5.13.1", - "cksum": "749176366 20467", + "cksum": "3389984310 21532", "tables": { "NB_Global": { "columns": { @@ -241,6 +241,11 @@ "refType": "strong"}, "min": 0, "max": "unlimited"}}, + "policies": {"type": {"key": {"type": "uuid", + "refTable": "Logical_Router_Policy", + "refType": "strong"}, + "min": 0, + "max": "unlimited"}}, "enabled": {"type": {"key": "boolean", "min": 0, "max": 1}}, "nat": {"type": {"key": {"type": "uuid", "refTable": "NAT", @@ -302,6 +307,19 @@ "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"}}}, "isRoot": false}, + "Logical_Router_Policy": { + "columns": { + "name": {"type": {"key": {"type": "string", + "maxLength": 63}, + "min": 0, "max": 1}}, + "priority": {"type": {"key": {"type": "integer", + "minInteger": 0, + "maxInteger": 32767}}}, + "match": {"type": "string"}, + "action": {"type": {"key": {"type": "string", + "enum": ["set", ["allow", "drop", "reroute"]]}}}, + "nexthop": {"type": {"key": "string", "min": 0, "max": 1}}}, + "isRoot": false}, "NAT": { "columns": { "external_ip": {"type": "string"}, diff --git a/ovn/ovn-nb.xml b/ovn/ovn-nb.xml index c0739fe..496bcf6 100644 --- a/ovn/ovn-nb.xml +++ b/ovn/ovn-nb.xml @@ -1225,6 +1225,10 @@ One or more static routes for the router. + + One or more routing policies for the router. + + This column is used to administratively set router state. If this column is empty or is set to true, the router is enabled. If this @@ -1782,6 +1786,65 @@ + +

+ Each row in this table represents one routing policy for a logical router + that points to it through its column. The column for the highest- + matching row in this table determines a packet's treatment. If no row + matches, packets are allowed by default. (Default-deny treatment is + possible: add a rule with 0, 0 as + , and drop as .) +

+ + A name for the router policy. Names are ASCII and must match + [a-zA-Z_.][a-zA-Z_.0-9]*. + + +

+ The routing policy's priority. Rules with numerically higher priority + take precedence over those with lower. A rule is uniquely identified + by the priority and match string. +

+
+ +

+ The packets that the routing policy should match, in the same expression + language used for the column in the OVN Southbound database's + table. The + outport logical port is only available in the + to-lport direction (the inport is + available in both directions). +

+

+ By default all traffic is allowed. When writing a more + restrictive policy, it is important to remember to allow flows + such as ARP and IPv6 neighbor discovery packets. +

+
+ +

The action to take when the routing policy matches:

+
    +
  • + allow: Forward the packet. +
  • +
  • + drop: Silently drop the packet. +
  • +
  • + reroute: Reroute packet to nexthop +
  • +
+
+ +

+ Nexthop IP address for this route. Nexthop IP address should be the IP + address of a connected router port or the IP address of a logical port. +

+
+
+

Each record represents a NAT rule. From patchwork Mon Oct 22 22:24:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mary Manohar X-Patchwork-Id: 987964 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" (1024-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.b="RMQ7feeF"; 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 42fB0j4Wcfz9sMx for ; Tue, 23 Oct 2018 09:25:09 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id ACD2BB0B; Mon, 22 Oct 2018 22:24:13 +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 BC0A1A91 for ; Mon, 22 Oct 2018 22:24:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A212B833 for ; Mon, 22 Oct 2018 22:24:10 +0000 (UTC) Received: from pps.filterd (m0127843.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.0.23/8.16.0.23) with SMTP id w9MMK3Ew008312 for ; Mon, 22 Oct 2018 15:24:09 -0700 Received: from nam05-co1-obe.outbound.protection.outlook.com (mail-co1nam05lp0087.outbound.protection.outlook.com [216.32.181.87]) by mx0b-002c1b01.pphosted.com with ESMTP id 2n82fg45tx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 22 Oct 2018 15:24:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e0cxZmyMCrXbGQ1Hz+Zy11iUboi+JfjrPeAt0gfo9yE=; b=RMQ7feeFu1ONdzQjLW45RD+bbOI10gWtjbBpkaGnQgqIs0Oi0n6b2SfVw3W5EVgrABKNb7+BezhtsIE3luDXpOIjinvU05fpeHCViFet0sOGDPlbbV7N9y+dzjsXMTaKyCHGjFL3bKjZuOOXDMvJIwOnf6365W0ewmKg0WHZuS0= Received: from SN6PR02MB3933.namprd02.prod.outlook.com (52.135.69.14) by SN6PR02MB5135.namprd02.prod.outlook.com (52.135.99.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.26; Mon, 22 Oct 2018 22:24:07 +0000 Received: from SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27]) by SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27%3]) with mapi id 15.20.1250.028; Mon, 22 Oct 2018 22:24:07 +0000 From: Mary Manohar To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v1 2/3] [2/3] Routing policies, add routing-policies in ovn-nbctl Thread-Index: AQHUalXyumoXrgVnKkWpKpT7K2xdHg== Date: Mon, 22 Oct 2018 22:24:07 +0000 Message-ID: <1540247132-167477-3-git-send-email-mary.manohar@nutanix.com> References: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> In-Reply-To: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR05CA0104.namprd05.prod.outlook.com (2603:10b6:a03:e0::45) To SN6PR02MB3933.namprd02.prod.outlook.com (2603:10b6:805:2b::14) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [205.209.132.11] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR02MB5135; 6:c0jzQjDs6nax64Kk+kfydq2Fr0FwKBOybpp9C5fRIM30sBhbqOdG/qg2hNLElpEFTtyud2R5wHPpchujt65GT/e/+SdD+hRfvYc3I6W81SRg5G9XwVENoTRj82UwO5W+0vcRektSHbIOMpo75u2o0khDfCEAsW9+RNf9hgHhsjQUMUAG0ncmwEjQxMqXVuigl2oT6n1SCCr4RQEESscWhh/b1doZoLdZrp4T9OiCIlgcMh9kDBetqtpUrO6lB6X3J1Pv6GwCXjvWtNCBQnYi0h5TUhnGIud9rY23PCqD+S9DL1LM3668VcM3IZGw0xZ4GM8ZAxHPrEPDrphtqKj6KR/GvZfXcj2gsf+cIVBxZ8Utj71b/cdI3321XG5vIqVhi1q3oYALK7RKDB63VpB9o7pJjslkAY1jxWFY1fjR6r2mDSx/SDJgi7Kr/rZcTmNIb7lZ3VD1UfJhksDP1gejgA==; 5:Hliod+Th8ZEo4/RSni4y0PcTFBF+sE/Q3rMvPMKYLvYJS/foH7pixl+Iw8Y47Wl4s6xRJHV8sLSYdxyqX91KDCAY09CxrDGVO8Q48nWz9zyySo/nEedwr7zSb/rjETviWsvq+1VsIhf2b11YZWX4252mRw4pMrDoj+vVaiu81kg=; 7:U1IbilOCMO5oVG1xWMj/gvx8VNs2GybQGLyS9ohklYlzTUdkZHjMxp/UwfjY4OqZxUxSGhuf+cnXil6KnZoqu2F64O06YnT3A6kY9tp2olEjE1+2YHNroz/I3Ib629AM6UEnGQVp4cedcrskinDYPpYTLS6RizstYyJE9agaDXiMcLE18/ySHZMn/WRAXBKce1R0gkp0tSpDn8fR9nPgonzbXV0L3PFi9+3rggkCSZ3gWJjRyQJE8QMKGkFbNjLf x-ms-office365-filtering-correlation-id: f6952927-4f33-471f-7f66-08d6386d14c8 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7167020)(7153060)(7193020); SRVR:SN6PR02MB5135; x-ms-traffictypediagnostic: SN6PR02MB5135: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:SN6PR02MB5135; BCL:0; PCL:0; RULEID:; SRVR:SN6PR02MB5135; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(44832011)(68736007)(6506007)(55236004)(102836004)(107886003)(186003)(8676002)(386003)(14454004)(86362001)(2906002)(6512007)(478600001)(6916009)(25786009)(36756003)(6116002)(3846002)(316002)(53936002)(2900100001)(5250100002)(5660300001)(11346002)(2501003)(6486002)(446003)(2616005)(476003)(97736004)(486006)(2351001)(256004)(105586002)(81156014)(14444005)(71190400001)(99286004)(305945005)(106356001)(8936002)(81166006)(76176011)(52116002)(26005)(71200400001)(6436002)(66066001)(7736002)(4326008)(5640700003)(64030200001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR02MB5135; H:SN6PR02MB3933.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Av5w8wPRCKxwxJ/sa8qO1acX2pawT/KuxE5ft9qBm7S5kjvbcsCtQzRlGI9uWHL6pokFJ1NJVjtSc8I3ZfVCsacUaWMfuNLBNjTWvcqRM/L6XgmW2y541U9nQQi+gsd684v7NABvyKHgveU4AIGOLROty2j6Ll8OJvvACEYaQoddNbccKlE+crl6gXzxle75XXg/IoNR01Pmz+CjuhTqak43YQ77ReyuuakwM3t8c8a+ymuhXfCazUeZfnkZ4lWzWTvoWHmEhipNrD6CUknScXQoVDSXlDr/UBC9EibYLCEljIACXEZBA7JZWO8AaOq842+EoNp1jZU4bgWWaxPSGv5nuvl3T+lurF/rPJ+X0UI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6952927-4f33-471f-7f66-08d6386d14c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 22:24:07.4931 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB5135 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-22_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810220188 X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Mary Manohar Subject: [ovs-dev] [PATCH v1 2/3] [2/3] Routing policies, add routing-policies in ovn-nbctl 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 Series: Policy-Based Routing This patch: Add commands to ovn-nbctl to add/delete/list routing policies. Routing-policy commands: lr-policy-add ROUTER PRIORITY MATCH ACTION [NEXTHOP] add a policy to router lr-policy-del ROUTER [PRIORITY [MATCH]] lr-policy-list ROUTER print policies for ROUTER lr-policy-add : A policy is uniquely identified by priority and match. Multiple policies can have the same priority. lr-policy-del : takes priority and match as optional parameters. If priority is not specified, all the rules would be deleted. If priority is specified, all rules with that priority are deleted. If priority and match are specified, the policy with the given priority and match is deleted. lr-policy-list : mandates ROUTER parameter. Sample CLI: ovn-nbctl lr-policy-add lr1 10 "ip4.src == 1.1.1.0/24" drop ovn-nbctl lr-policy-del lr1 10 ovn-nbctl lr-policy-list lr1 --- ovn/utilities/ovn-nbctl.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 798c972..920024b 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -642,6 +642,13 @@ Route commands:\n\ remove routes from ROUTER\n\ lr-route-list ROUTER print routes for ROUTER\n\ \n\ +Policy commands:\n\ + lr-policy-add ROUTER PRIORITY MATCH ACTION [NEXTHOP]\n\ + add a policy to router\n\ + lr-policy-del ROUTER [PRIORITY [MATCH]]\n\ + remove policies from ROUTER\n\ + lr-policy-list ROUTER print policies for ROUTER\n\ +\n\ NAT commands:\n\ lr-nat-add ROUTER TYPE EXTERNAL_IP LOGICAL_IP [LOGICAL_PORT EXTERNAL_MAC]\n\ add a NAT to ROUTER\n\ @@ -3395,6 +3402,187 @@ normalize_prefix_str(const char *orig_prefix) return normalize_ipv6_prefix(ipv6, plen); } } + +static void +nbctl_lr_policy_add(struct ctl_context *ctx) +{ + const struct nbrec_logical_router *lr; + int64_t priority = 0; + char *error = lr_by_name_or_uuid(ctx, ctx->argv[1], true, &lr); + if (error) { + ctx->error = error; + return; + } + error = parse_priority(ctx->argv[2], &priority); + if (error) { + ctx->error = error; + return; + } + const char *action = ctx->argv[4]; + char *next_hop = NULL; + /* Validate action. */ + if (strcmp(action, "allow") && strcmp(action, "drop") + && strcmp(action, "reroute")) { + ctl_error(ctx, "%s: action must be one of \"allow\", \"drop\", " + "and \"reroute\"", action); + } + if (!strcmp(action, "reroute")) { + if (ctx->argc < 6) { + ctl_error(ctx, "Nexthop is not specified when action is reroute."); + } + } + /* Check if same routing policy already exists. + * A policy is uniquely identified by priority and match */ + for (int i = 0; i < lr->n_policies; i++) { + const struct nbrec_logical_router_policy *policy = lr->policies[i]; + if ((policy->priority == priority) && + (!strcmp(policy->match, ctx->argv[3]))) { + ctl_error(ctx, "Same routing policy already existed on the " + "logical router %s.", ctx->argv[1]); + } + } + if (ctx->argc == 6) { + next_hop = normalize_prefix_str(ctx->argv[5]); + if (!next_hop) { + ctl_error(ctx, "bad next hop argument: %s", ctx->argv[5]); + } + } + struct nbrec_logical_router_policy *policy; + policy = nbrec_logical_router_policy_insert(ctx->txn); + nbrec_logical_router_policy_set_priority(policy, priority); + nbrec_logical_router_policy_set_match(policy, ctx->argv[3]); + nbrec_logical_router_policy_set_action(policy, action); + if (ctx->argc == 6) { + nbrec_logical_router_policy_set_nexthop(policy, next_hop); + } + nbrec_logical_router_verify_policies(lr); + struct nbrec_logical_router_policy **new_policies + = xmalloc(sizeof *new_policies * (lr->n_policies + 1)); + memcpy(new_policies, lr->policies, + sizeof *new_policies * lr->n_policies); + new_policies[lr->n_policies] = policy; + nbrec_logical_router_set_policies(lr, new_policies, + lr->n_policies + 1); + free(new_policies); + if (next_hop != NULL) + free(next_hop); +} + +static void +nbctl_lr_policy_del(struct ctl_context *ctx) +{ + const struct nbrec_logical_router *lr; + int64_t priority = 0; + char *error = lr_by_name_or_uuid(ctx, ctx->argv[1], true, &lr); + if (error) { + ctx->error = error; + return; + } + if (ctx->argc == 2) { + /* If a priority is not specified, delete all policies. */ + nbrec_logical_router_set_policies(lr, NULL, 0); + return; + } + error = parse_priority(ctx->argv[2], &priority); + if (error) { + ctx->error = error; + return; + } + /* If match is not specified, delete all routing policies with the + * specified priority. */ + if (ctx->argc == 3) { + struct nbrec_logical_router_policy **new_policies + = xmemdup(lr->policies, + sizeof *new_policies * lr->n_policies); + int n_policies = 0; + for (int i = 0; i < lr->n_policies; i++) { + if (priority != lr->policies[i]->priority) { + new_policies[n_policies++] = lr->policies[i]; + } + } + nbrec_logical_router_verify_policies(lr); + nbrec_logical_router_set_policies(lr, new_policies, n_policies); + free(new_policies); + return; + } + /* Delete policy that has the same priority and match string */ + for (int i = 0; i < lr->n_policies; i++) { + struct nbrec_logical_router_policy *routing_policy = lr->policies[i]; + if (priority == routing_policy->priority && + !strcmp(ctx->argv[3], routing_policy->match)) { + struct nbrec_logical_router_policy **new_policies + = xmemdup(lr->policies, + sizeof *new_policies * lr->n_policies); + new_policies[i] = lr->policies[lr->n_policies - 1]; + nbrec_logical_router_verify_policies(lr); + nbrec_logical_router_set_policies(lr, new_policies, + lr->n_policies - 1); + free(new_policies); + return; + } + } +} + + struct routing_policy { + int priority; + char *match; + const struct nbrec_logical_router_policy *policy; +}; + +static int +routing_policy_cmp(const void *policy1_, const void *policy2_) +{ + const struct routing_policy *policy1p = policy1_; + const struct routing_policy *policy2p = policy2_; + if (policy1p->priority != policy2p->priority) { + return policy1p->priority > policy2p->priority ? -1 : 1; + } else { + return strcmp(policy1p->match, policy2p->match); + } +} + +static void +print_routing_policy(const struct nbrec_logical_router_policy *policy, struct ds *s) +{ + if (policy->nexthop != NULL) { + char *next_hop = normalize_prefix_str(policy->nexthop); + ds_put_format(s, "%10ld %50s %15s %25s", policy->priority, policy->match, + policy->action, next_hop); + free(next_hop); + } else + ds_put_format(s, "%10ld %50s %15s", policy->priority, policy->match, policy->action); + ds_put_char(s, '\n'); +} + +static void +nbctl_lr_policy_list(struct ctl_context *ctx) +{ + const struct nbrec_logical_router *lr; + struct routing_policy *policies; + size_t n_policies = 0; + char *error = lr_by_name_or_uuid(ctx, ctx->argv[1], true, &lr); + if (error) { + ctx->error = error; + return; + } + policies = xmalloc(sizeof *policies * lr->n_policies); + for (int i = 0; i < lr->n_policies; i++) { + const struct nbrec_logical_router_policy *policy + = lr->policies[i]; + policies[n_policies].priority = policy->priority; + policies[n_policies].match = policy->match; + policies[n_policies].policy = policy; + n_policies++; + } + qsort(policies, n_policies, sizeof *policies, routing_policy_cmp); + if (n_policies) { + ds_put_cstr(&ctx->output, "Routing Policies\n"); + } + for (int i = 0; i < n_policies; i++) { + print_routing_policy(policies[i].policy, &ctx->output); + } + free(policies); +} static void nbctl_lr_route_add(struct ctl_context *ctx) @@ -5143,6 +5331,14 @@ static const struct ctl_command_syntax nbctl_commands[] = { { "lr-route-list", 1, 1, "ROUTER", NULL, nbctl_lr_route_list, NULL, "", RO }, + /* Policy commands */ + { "lr-policy-add", 4, 5, "ROUTER PRIORITY MATCH ACTION [NEXTHOP]", NULL, + nbctl_lr_policy_add, NULL, "", RW }, + { "lr-policy-del", 1, 3, "ROUTER [PRIORITY [MATCH]]", NULL, + nbctl_lr_policy_del, NULL, "", RW }, + { "lr-policy-list", 1, 1, "ROUTER", NULL, nbctl_lr_policy_list, NULL, + "", RO }, + /* NAT commands. */ { "lr-nat-add", 4, 6, "ROUTER TYPE EXTERNAL_IP LOGICAL_IP [LOGICAL_PORT EXTERNAL_MAC]", NULL, From patchwork Mon Oct 22 22:24:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mary Manohar X-Patchwork-Id: 987965 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" (1024-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.b="RO75zEC1"; 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 42fB1P0yJWz9sMx for ; Tue, 23 Oct 2018 09:25:45 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 97F06B88; Mon, 22 Oct 2018 22:24:15 +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 1F5C0B4C for ; Mon, 22 Oct 2018 22:24:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4E78582B for ; Mon, 22 Oct 2018 22:24:13 +0000 (UTC) Received: from pps.filterd (m0127842.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.0.23/8.16.0.23) with SMTP id w9MMK4bT027311 for ; Mon, 22 Oct 2018 15:24:12 -0700 Received: from nam05-co1-obe.outbound.protection.outlook.com (mail-co1nam05lp0083.outbound.protection.outlook.com [216.32.181.83]) by mx0b-002c1b01.pphosted.com with ESMTP id 2n83pdm3hr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 22 Oct 2018 15:24:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RvQ8T0B9hUgrSMujcmQG3JXI7Z4QoNJ/VK4/X+q9So4=; b=RO75zEC1WorGj1Tr+I7UKSV9LTOHeo98v8+vpiScA32FkcjhB6Rx/LYhA6sx/FGFvaI3Z/E7g8dqfSU/9N/N/OHVNZVvX627vG64UPVpAjsXk6yBsk4kNwPNSqpXIy8bNgO7X7i0gCbuCy5PXtW4G+NQMtKz6BNxTXYYRtuMbec= Received: from SN6PR02MB3933.namprd02.prod.outlook.com (52.135.69.14) by SN6PR02MB5135.namprd02.prod.outlook.com (52.135.99.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.26; Mon, 22 Oct 2018 22:24:10 +0000 Received: from SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27]) by SN6PR02MB3933.namprd02.prod.outlook.com ([fe80::3cf5:568:99f2:f27%3]) with mapi id 15.20.1250.028; Mon, 22 Oct 2018 22:24:10 +0000 From: Mary Manohar To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v1 3/3] [3/3]: Routing policies, ovn-northd changes to handle routing policy commands. Thread-Index: AQHUalXzGyd/RcKM00qv0kADViMbrw== Date: Mon, 22 Oct 2018 22:24:09 +0000 Message-ID: <1540247132-167477-4-git-send-email-mary.manohar@nutanix.com> References: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> In-Reply-To: <1540247132-167477-1-git-send-email-mary.manohar@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR05CA0104.namprd05.prod.outlook.com (2603:10b6:a03:e0::45) To SN6PR02MB3933.namprd02.prod.outlook.com (2603:10b6:805:2b::14) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [205.209.132.11] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR02MB5135; 6:KtBMNZEDNbpSjnSMChQ14Y9t9vwDJ7oQlfnn8p3cwfGzt6YAO7gSf3seEBtCPMZ10hrVtnh/67ZgYhOGb8vlThZTsLUqDUWtKo3JCXWNxb5vhPDjsLb8P6IKdazLpz6Pk5kBe1aF4rum5T4oN9IO2tpEn+gIEs7GKvGhJbAAA6qr5vEcl2RNSp+FB438zDYzufG1weQzzcuLqeF5P4Rb7YYM7uBzpIE8fKzV00DBeE7zNjQcAzG72n37cjfDTMNlxv2w0cET5Zg7ICAh7Tl/iuQjEi/ajTxRME1UwIqvvF1yGHMorM5kxO0Q0XNe9JhnNt49GM5yqTeZMMQEDjEYqmfIxD7R3kVEFgfhMS0IEDqTox+gbEnZMpnmNPta831ShbCG0Ddv03bS4M8B5ALQkJABHYsMgLLC632KKiYDeXZdWTdIOE+mukLNh/2eM/5hMhOAGGRk3pk/WD4bxK+AlA==; 5:eX7z7oA5u8oHItf4JI/sfFE391aItmArapWqWqi1JvrXGpHCcr9rl6cvuok07nC52rPkTPL3687JxlV/fiD20gLZDbdcMKjCzEOgKLisH7jO2ar6TGR5d7WeD+xfeMKZtA4UzpeKvZZUTxlTlePQEiT4cSUQ6yTcyd+pCKpPVqs=; 7:8wY8amLtEjVBvp51sW9QGqVSOvu+a4vlKrZ4q8aFyg+oBjJ1+gVgj9JTDfbqyirJVX2eKH61mAqGz78O7TDWqW8QlXfNC7j15TSp7zdJCG/YWIH/BgVyb8mii+0/MViqcEzC2Escs9d4NZWYYwSD2z2XiC0zVqMD/HUFOIOC4q70VZiNx/4VlincjAuWgHZft6DJ/xQavgyyHu4aHl7JrU70mnXs8kXg4pkyQm3W9rJTB/Vy+azTNV9Mn4i3QXYI x-ms-office365-filtering-correlation-id: c012a1cd-c9e2-4117-2b06-08d6386d15ac x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7167020)(7153060)(7193020); SRVR:SN6PR02MB5135; x-ms-traffictypediagnostic: SN6PR02MB5135: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:SN6PR02MB5135; BCL:0; PCL:0; RULEID:; SRVR:SN6PR02MB5135; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(44832011)(68736007)(6506007)(55236004)(102836004)(107886003)(186003)(8676002)(386003)(14454004)(86362001)(2906002)(6512007)(478600001)(6916009)(25786009)(36756003)(6116002)(3846002)(316002)(53936002)(2900100001)(5250100002)(5660300001)(11346002)(2501003)(6486002)(446003)(2616005)(476003)(97736004)(486006)(2351001)(256004)(105586002)(81156014)(14444005)(71190400001)(99286004)(305945005)(106356001)(8936002)(81166006)(76176011)(52116002)(26005)(71200400001)(6436002)(66066001)(7736002)(4326008)(5640700003)(64030200001)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR02MB5135; H:SN6PR02MB3933.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 1X2AOBF4Lky7f4xl2DdfAYgu/hJloN+uMaZ9QmDVTkHkXcmPuHTOrWOsa0po6PIJpJGNMYardwiZ770zbZpNDJ8Rfrohe1i4qf45iJlKfYa0LAaEbbk0oI3g6i8gjdX61nIqgmqLHWcr1tjETrfvt6IJJLmjnNAILVqwM7iqzaKToSFUSOuTx/7V+HmriCDF44ZSMMaaj+04tu8TC5cSUlWZLMfUI8e2dK145vQeNNdNs256IoKph7z4tux9muADQ+RNmJunbrf++VwFaMUJj87dj1IIjSQMDdbRxOdKMdCCv+UHTMuTW2+xXNk/FgFlDkGgxnx2sW/sWIyQlpWsWzkBEs1lzcXpC46CSHPdOy4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <7A9C508FA3C30C458F1BC7521D3336BD@namprd02.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: c012a1cd-c9e2-4117-2b06-08d6386d15ac X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 22:24:10.2221 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB5135 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-22_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810220188 X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Mary Manohar Subject: [ovs-dev] [PATCH v1 3/3] [3/3]: Routing policies, ovn-northd changes to handle routing policy commands. 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 Series: Policy-Based Routing. This Patch: Changes in ovn-northd to handle routing policy commands. --- ovn/northd/ovn-northd.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++-- tests/ovn-nbctl.at | 47 ++++++++++++++++ 2 files changed, 185 insertions(+), 6 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 439651f..554ea2a 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -141,9 +141,10 @@ enum ovn_stage { PIPELINE_STAGE(ROUTER, IN, ND_RA_OPTIONS, 5, "lr_in_nd_ra_options") \ PIPELINE_STAGE(ROUTER, IN, ND_RA_RESPONSE, 6, "lr_in_nd_ra_response") \ PIPELINE_STAGE(ROUTER, IN, IP_ROUTING, 7, "lr_in_ip_routing") \ - PIPELINE_STAGE(ROUTER, IN, ARP_RESOLVE, 8, "lr_in_arp_resolve") \ - PIPELINE_STAGE(ROUTER, IN, GW_REDIRECT, 9, "lr_in_gw_redirect") \ - PIPELINE_STAGE(ROUTER, IN, ARP_REQUEST, 10, "lr_in_arp_request") \ + PIPELINE_STAGE(ROUTER, IN, POLICY, 8, "lr_in_policy") \ + PIPELINE_STAGE(ROUTER, IN, ARP_RESOLVE, 9, "lr_in_arp_resolve") \ + PIPELINE_STAGE(ROUTER, IN, GW_REDIRECT, 10, "lr_in_gw_redirect") \ + PIPELINE_STAGE(ROUTER, IN, ARP_REQUEST, 11, "lr_in_arp_request") \ \ /* Logical router egress stages. */ \ PIPELINE_STAGE(ROUTER, OUT, UNDNAT, 0, "lr_out_undnat") \ @@ -4598,6 +4599,111 @@ find_lrp_member_ip(const struct ovn_port *op, const char *ip_s) return NULL; } +static struct ovn_port* +get_outport_for_routing_policy_nexthop(struct ovn_datapath *od, + struct hmap *ports, + int priority, const char *nexthop) +{ + if (nexthop == NULL) + return NULL; + + unsigned int plen = 0; + ovs_be32 nexthop_be32; + /* Verify that the next hop is an IP address with an all-ones mask. */ + char *error = ip_parse_cidr(nexthop, &nexthop_be32, &plen); + if (!error) { + if (plen != 32) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "bad next hop ip %s for routing policy " + "with priority %d, error: %s ", + nexthop, priority, error); + return NULL; + } + } else { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "Failed to parse cidr %s for routing policy " + "with priority %d ", + nexthop, priority); + free(error); + return NULL; + } + + /* find the router port matching the next hop. */ + int i; + struct ovn_port *out_port = NULL; + const char *lrp_addr_s = NULL; + for (i = 0; i < od->nbr->n_ports; i++) { + struct nbrec_logical_router_port *lrp = od->nbr->ports[i]; + out_port = ovn_port_find(ports, lrp->name); + if (!out_port) { + /* This should not happen. */ + continue; + } + lrp_addr_s = find_lrp_member_ip(out_port, nexthop); + if (lrp_addr_s) { + break; + } else { + out_port = NULL; + } + } + if (!out_port) { + /* There is no matched out port. */ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "No path for routing policy priority %d; next hop %s", + priority, nexthop); + return NULL; + } + return out_port; +} + +static void +build_routing_policy_flow(struct hmap *lflows, struct ovn_datapath *od, + struct hmap *ports, + const struct nbrec_logical_router_policy *rule) +{ + struct ds match = DS_EMPTY_INITIALIZER; + struct ds actions = DS_EMPTY_INITIALIZER; + + if (!strcmp(rule->action, "reroute")) { + struct ovn_port *out_port = NULL; + const char *lrp_addr_s = NULL; + out_port = get_outport_for_routing_policy_nexthop( + od, ports, rule->priority, rule->nexthop); + if (out_port == NULL) { + return; + } else { + lrp_addr_s = find_lrp_member_ip(out_port, rule->nexthop); + if (!lrp_addr_s) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "lrp_addr not found for routing policy " + " priority %d nexthop %s", + rule->priority, rule->nexthop); + return; + } else { + ds_put_format(&actions, "reg0 = %s; " + "reg1 = %s; " + "eth.src = %s; " + "outport = %s; " + "flags.loopback = 1; " + "next;", + rule->nexthop, + lrp_addr_s, + out_port->lrp_networks.ea_s, + out_port->json_key); + } + } + } else if (!strcmp(rule->action, "drop")) { + ds_put_cstr(&actions, "drop;"); + } else if (!strcmp(rule->action, "allow")) { + ds_put_cstr(&actions, "next;"); + } + ds_put_format(&match, "%s", rule->match); + ovn_lflow_add(lflows, od, S_ROUTER_IN_POLICY, rule->priority, + ds_cstr(&match), ds_cstr(&actions)); + ds_destroy(&match); + ds_destroy(&actions); +} + static void add_route(struct hmap *lflows, const struct ovn_port *op, const char *lrp_addr_s, const char *network_s, int plen, @@ -6297,9 +6403,35 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, } } + /* Logical router ingress table 8: Policy. + * + * A packet that arrives at this table is an IP packet that should be + * permitted/denied/rerouted to the address in the rule's nexthop. + * This table sets outport to the correct out_port, + * eth.src to the output port's MAC address, + * and '[xx]reg0' to the next-hop IP address (leaving + * 'ip[46].dst', the packet’s final destination, unchanged), and + * advances to the next table for ARP/ND resolution. */ + HMAP_FOR_EACH (od, key_node, datapaths) { + if (!od->nbr) { + continue; + } + /* This is a catch-all rule. It has the lowest priority (0) + * does a match-all("1") and pass-through (next) */ + ovn_lflow_add(lflows, od, S_ROUTER_IN_POLICY, 0, "1", "next;"); + + /* Convert routing policies to flows. */ + for (int i = 0; i < od->nbr->n_policies; i++) { + const struct nbrec_logical_router_policy *rule; + rule = od->nbr->policies[i]; + build_routing_policy_flow(lflows, od, ports, rule); + } + } + + /* XXX destination unreachable */ - /* Local router ingress table 8: ARP Resolution. + /* Local router ingress table 9: ARP Resolution. * * Any packet that reaches this table is an IP packet whose next-hop IP * address is in reg0. (ip4.dst is the final destination.) This table @@ -6498,7 +6630,7 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, "get_nd(outport, xxreg0); next;"); } - /* Logical router ingress table 9: Gateway redirect. + /* Logical router ingress table 10: Gateway redirect. * * For traffic with outport equal to the l3dgw_port * on a distributed router, this table redirects a subset @@ -6538,7 +6670,7 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, ovn_lflow_add(lflows, od, S_ROUTER_IN_GW_REDIRECT, 0, "1", "next;"); } - /* Local router ingress table 10: ARP request. + /* Local router ingress table 11: ARP request. * * In the common case where the Ethernet destination has been resolved, * this table outputs the packet (priority 0). Otherwise, it composes diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 25414b8..2bb1006 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1331,6 +1331,53 @@ IPv6 Routes dnl --------------------------------------------------------------------- +OVN_NBCTL_TEST([ovn_nbctl_policies], [policies], [ +AT_CHECK([ovn-nbctl lr-add lr0]) + +dnl Add policies with allow and drop actions +AT_CHECK([ovn-nbctl lr-policy-add lr0 100 "ip4.src == 1.1.1.0/24" drop]) +AT_CHECK([ovn-nbctl lr-policy-add lr0 100 "ip4.src == 1.1.2.0/24" allow]) +AT_CHECK([ovn-nbctl lr-policy-add lr0 101 "ip4.src == 2.1.1.0/24" allow]) +AT_CHECK([ovn-nbctl lr-policy-add lr0 101 "ip4.src == 2.1.2.0/24" drop]) + +dnl Add duplicated policy +AT_CHECK([ovn-nbctl lr-policy-add lr0 100 "ip4.src == 1.1.1.0/24" drop], [1], [], + [ovn-nbctl: Same routing policy already existed on the logical router lr0. +]) + +dnl Add duplicated policy +AT_CHECK([ovn-nbctl lr-policy-add lr0 103 "ip4.src == 1.1.1.0/24" deny], [1], [], + [ovn-nbctl: deny: action must be one of "allow", "drop", and "reroute" +]) + +dnl Delete by priority and match string +AT_CHECK([ovn-nbctl lr-policy-del lr0 100 "ip4.src == 1.1.1.0/24"]) +AT_CHECK([ovn-nbctl lr-policy-list lr0], [0], [dnl +Routing Policies + 101 ip4.src == 2.1.1.0/24 allow + 101 ip4.src == 2.1.2.0/24 drop + 100 ip4.src == 1.1.2.0/24 allow +]) + +dnl Delete all policies for given priority +AT_CHECK([ovn-nbctl lr-policy-del lr0 101]) +AT_CHECK([ovn-nbctl lr-policy-list lr0], [0], [dnl +Routing Policies + 100 ip4.src == 1.1.2.0/24 allow +]) + +dnl Add policy with reroute action +AT_CHECK([ovn-nbctl lr-policy-add lr0 102 "ip4.src == 3.1.2.0/24" reroute 3.3.3.3]) + +dnl Add policy with invalid reroute ip +AT_CHECK([ovn-nbctl lr-policy-add lr0 103 "ip4.src == 3.1.2.0/24" reroute 3.3.3.x], [1], [], + [ovn-nbctl: bad next hop argument: 3.3.3.x +]) +]) + +dnl --------------------------------------------------------------------- + + OVN_NBCTL_TEST([ovn_nbctl_lsp_types], [lsp types], [ AT_CHECK([ovn-nbctl ls-add ls0]) AT_CHECK([ovn-nbctl lsp-add ls0 lp0])