From patchwork Tue Sep 28 18:28:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1534017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hMf89rmk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJp1f5lxRz9t0p for ; Wed, 29 Sep 2021 04:29:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id EB0D080CBF; Tue, 28 Sep 2021 18:29:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u6ZKSFthOMCJ; Tue, 28 Sep 2021 18:29:05 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1B33280C2C; Tue, 28 Sep 2021 18:29:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E4C5FC0011; Tue, 28 Sep 2021 18:29:03 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id CEA88C000D for ; Tue, 28 Sep 2021 18:29:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A33668299E for ; Tue, 28 Sep 2021 18:29:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FZRLAxLujxNj for ; Tue, 28 Sep 2021 18:29:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9864C8299D for ; Tue, 28 Sep 2021 18:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632853740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xBc1r99kMzjMehY1FI5WA1r+JJ2ugzYjWwozoKTEDKk=; b=hMf89rmkw0OYvjXvc1Pp7I/8smr5GpeOCDZGyfCxVSdAJEG/oMIIp4vArH0KK9ZVNFkXUW abDUzfuYMmJOgt2TIL+Sv4PY54nHmhNx3UIcCW9PtzksZmArPerD43FjXPiieM3trBwlWr 2a/wWgk+hoUU9jgMgStKeqVFGJf01rY= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-AikAJO5pOPqh_0vIPYRkOA-1; Tue, 28 Sep 2021 14:28:59 -0400 X-MC-Unique: AikAJO5pOPqh_0vIPYRkOA-1 Received: by mail-ed1-f69.google.com with SMTP id e21-20020a50a695000000b003daa0f84db2so297328edc.23 for ; Tue, 28 Sep 2021 11:28:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xBc1r99kMzjMehY1FI5WA1r+JJ2ugzYjWwozoKTEDKk=; b=O9PHbHfT2SGOLZGcbXI6/IWG1OeU7F3AWi3Xe1yAeOl1StngIh0x7G7wkIUKCBqh4+ 8E8kdIP8+Xo2+yaq+0hqZUkseG3nbJfwbZbgzDmBi0IxpfmUDJXBBQvH8AwVv683OYOu yj9fzMkXvSTu8/rnO067qcDTMyv7Nm9/v9vsUMDu14pbjr/d0mFE+QTtXCM/TeagRjZp DFLIzKhljdt658L9CMoNUb0BaoRuuZfyof921/qVpEmfQFjUxiwpYABuoYLkO8yeRpHs B8AbyhEDZ34hveqxE/7CBo4UofrnwSASYr9gaiZPNhoG4v8P6ZFoHpHnStRj0YlE6r3a bmHw== X-Gm-Message-State: AOAM532Pon5JPhNIlN333jaA19aU19yxoYhthvD2O3qhw+0Qb01BYO48 guKHYjYIzuSNeVymJIe0ughrp0OX9znpKms9sOQid1LdKuLw/W8fpnZhUjHUJgnebPK3scGov1k 2cn/D/Ach9W6QtmClZiknQE9WZtbPQ8IN7uI7pHdR/4EbdjlnHpumaFpqjGsn07+MKHi5anVr09 3wu1rF X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr8757962ejc.504.1632853737427; Tue, 28 Sep 2021 11:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtKPPMcCKazzsYBLpetIPWogOnBBezZvx32YBBJeTj3V6LfDd4jaC/9xsc97UTBY9yJ3NUbA== X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr8757937ejc.504.1632853737136; Tue, 28 Sep 2021 11:28:57 -0700 (PDT) Received: from lore-desk.redhat.com (net-130-25-199-50.cust.vodafonedsl.it. [130.25.199.50]) by smtp.gmail.com with ESMTPSA id r22sm10832946ejj.91.2021.09.28.11.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 11:28:56 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Tue, 28 Sep 2021 20:28:50 +0200 Message-Id: <257bf842bac8d1e3eb2ec40ac11cd31a98c556e1.1632853104.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: trozet@redhat.com Subject: [ovs-dev] [PATCH ovn] sbctl: add the capability to configure static mac_bindings entries X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Introduce the two following commands to configure and dump static L2 address bindings: $ovn-sbctl set-mac-binding 192.168.1.100 00:11:22:33:44:55 vif0 $ovn-sbctl list-mac-binding [ 192.168.1.100 00:11:22:33:44:55 S ] https://bugzilla.redhat.com/show_bug.cgi?id=1845111 Signed-off-by: Lorenzo Bianconi --- controller/pinctrl.c | 3 +- ovn-sb.ovsschema | 7 +++-- ovn-sb.xml | 3 ++ tests/ovn-sbctl.at | 39 +++++++++++++++++++++++++ utilities/ovn-sbctl.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index cc3edaaf4..c56e800cf 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -4135,7 +4135,8 @@ mac_binding_add_to_sb(struct ovsdb_idl_txn *ovnsb_idl_txn, sbrec_mac_binding_set_ip(b, ip); sbrec_mac_binding_set_mac(b, mac_string); sbrec_mac_binding_set_datapath(b, dp); - } else if (strcmp(b->mac, mac_string)) { + sbrec_mac_binding_set_static_(b, false); + } else if (strcmp(b->mac, mac_string) && !b->static_) { sbrec_mac_binding_set_mac(b, mac_string); } } diff --git a/ovn-sb.ovsschema b/ovn-sb.ovsschema index e5ab41db9..0eb9df19c 100644 --- a/ovn-sb.ovsschema +++ b/ovn-sb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Southbound", - "version": "20.20.0", - "cksum": "605270161 26670", + "version": "20.21.0", + "cksum": "4055366137 26717", "tables": { "SB_Global": { "columns": { @@ -241,7 +241,8 @@ "ip": {"type": "string"}, "mac": {"type": "string"}, "datapath": {"type": {"key": {"type": "uuid", - "refTable": "Datapath_Binding"}}}}, + "refTable": "Datapath_Binding"}}}, + "static": {"type": "boolean"}}, "indexes": [["logical_port", "ip"]], "isRoot": true}, "DHCP_Options": { diff --git a/ovn-sb.xml b/ovn-sb.xml index 2d4d47d10..e6c74a328 100644 --- a/ovn-sb.xml +++ b/ovn-sb.xml @@ -3378,6 +3378,9 @@ tcp.flags = RST; The logical datapath to which the logical port belongs. + + The entry has been manually created by the CMS and not discovered by OVN. + diff --git a/tests/ovn-sbctl.at b/tests/ovn-sbctl.at index 1d1eee23e..ea343ff84 100644 --- a/tests/ovn-sbctl.at +++ b/tests/ovn-sbctl.at @@ -243,3 +243,42 @@ Total number of logical flows = 0 ]) ]) +dnl --------------------------------------------------------------------- + +OVN_SBCTL_TEST([ovn_sbctl_mac_bindings], [ovn-sbctl - mac-bindings], [ +AT_CHECK([ovn-nbctl ls-add sw0]) +AT_CHECK([ovn-nbctl lsp-add sw0 vif0]) +AT_CHECK([ovn-nbctl lsp-set-addresses vif0 "f0:ab:cd:ef:01:02 192.168.1.2"]) +AT_CHECK([ovn-nbctl --wait=sb sync]) + +AT_CHECK([ovn-sbctl set-mac-binding 192.168.1.100 00:11:22:33:44:55 vif0]) +AT_CHECK([ovn-sbctl list-mac-binding], [0], [dnl +[[ 192.168.1.100 00:11:22:33:44:55 S ]] +]) + +AT_CHECK([ovn-sbctl set-mac-binding 192.168.1.101 00:11:22:33:44:66 vif0]) +AT_CHECK([ovn-sbctl list-mac-binding |sort], [0], [dnl +[[ 192.168.1.100 00:11:22:33:44:55 S ]] +[[ 192.168.1.101 00:11:22:33:44:66 S ]] +]) + +# sanity checks +AT_CHECK([ovn-sbctl set-mac-binding 192.168.1.101 00:11:22:33:44:66 vif1]) +AT_CHECK([ovn-sbctl list-mac-binding |sort], [0], [dnl +[[ 192.168.1.100 00:11:22:33:44:55 S ]] +[[ 192.168.1.101 00:11:22:33:44:66 S ]] +]) + +AT_CHECK([ovn-sbctl set-mac-binding 192.168.1.101.2 00:11:22:33:44:66 vif0]) +AT_CHECK([ovn-sbctl list-mac-binding |sort], [0], [dnl +[[ 192.168.1.100 00:11:22:33:44:55 S ]] +[[ 192.168.1.101 00:11:22:33:44:66 S ]] +]) + +AT_CHECK([ovn-sbctl set-mac-binding 192.168.1.102 00:11:22:33:44:66:77 vif0]) +AT_CHECK([ovn-sbctl list-mac-binding |sort], [0], [dnl +[[ 192.168.1.100 00:11:22:33:44:55 S ]] +[[ 192.168.1.101 00:11:22:33:44:66 S ]] +]) +]) + diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c index 4d7e7d670..6d581887b 100644 --- a/utilities/ovn-sbctl.c +++ b/utilities/ovn-sbctl.c @@ -333,6 +333,7 @@ pre_get_info(struct ctl_context *ctx) ovsdb_idl_add_column(ctx->idl, &sbrec_mac_binding_col_logical_port); ovsdb_idl_add_column(ctx->idl, &sbrec_mac_binding_col_ip); ovsdb_idl_add_column(ctx->idl, &sbrec_mac_binding_col_mac); + ovsdb_idl_add_column(ctx->idl, &sbrec_mac_binding_col_static_); ovsdb_idl_add_column(ctx->idl, &sbrec_load_balancer_col_datapaths); ovsdb_idl_add_column(ctx->idl, &sbrec_load_balancer_col_vips); @@ -1176,6 +1177,67 @@ sbctl_ip_mcast_flush(struct ctl_context *ctx) } } +static void +sbctl_list_mac_binding(struct ctl_context *ctx) +{ + const struct sbrec_mac_binding *iter; + SBREC_MAC_BINDING_FOR_EACH (iter, ctx->idl) { + ds_put_format(&ctx->output, "[ %s %s %s ]\n", + iter->ip, iter->mac, + iter->static_ ? "S" : "R"); + } +} + +static void +sbctl_set_mac_binding(struct ctl_context *ctx) +{ + if (ctx->argc != 4) { + return; + } + + /* sanity checks. */ + struct in6_addr ipv6; + ovs_be32 ip; + if (!ip_parse(ctx->argv[1], &ip) && !ipv6_parse(ctx->argv[1], &ipv6)) { + return; + } + + struct eth_addr ea; + int index = 0; + if (!ovs_scan_len(ctx->argv[2], &index, ETH_ADDR_SCAN_FMT, + ETH_ADDR_SCAN_ARGS(ea)) || + index != strlen(ctx->argv[2])) { + return; + } + + const struct sbrec_port_binding *pb_iter, *pb = NULL; + SBREC_PORT_BINDING_FOR_EACH (pb_iter, ctx->idl) { + if (!strcmp(pb_iter->logical_port, ctx->argv[3])) { + pb = pb_iter; + break; + } + } + if (!pb) { + return; + } + + const struct sbrec_mac_binding *mb_iter, *mb = NULL; + SBREC_MAC_BINDING_FOR_EACH (mb_iter, ctx->idl) { + if (!strcmp(mb_iter->ip, ctx->argv[1])) { + mb = mb_iter; + break; + } + } + if (!mb) { + mb = sbrec_mac_binding_insert(ctx->txn); + sbrec_mac_binding_set_ip(mb, ctx->argv[1]); + } + sbrec_mac_binding_set_mac(mb, ctx->argv[2]); + sbrec_mac_binding_set_logical_port(mb, ctx->argv[3]); + sbrec_mac_binding_set_datapath(mb, pb->datapath); + sbrec_mac_binding_set_static_(mb, true); +} + static void verify_connections(struct ctl_context *ctx) { @@ -1482,6 +1544,12 @@ static const struct ctl_command_syntax sbctl_commands[] = { {"ip-multicast-flush", 0, 1, "SWITCH", pre_get_info, sbctl_ip_mcast_flush, NULL, "", RW }, + /* Mac bindings commands. */ + {"list-mac-binding", 0, 0, "", pre_get_info, sbctl_list_mac_binding, + NULL, "", RO}, + {"set-mac-binding", 3, 3, "IP MAC PORT", pre_get_info, + sbctl_set_mac_binding, NULL, "", RW}, + /* Connection commands. */ {"get-connection", 0, 0, "", pre_connection, cmd_get_connection, NULL, "", RO}, {"del-connection", 0, 0, "", pre_connection, cmd_del_connection, NULL, "", RW},