From patchwork Fri Jun 1 17:03:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 924239 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=redhat.com 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 40y9jm2VsFz9s1p for ; Sat, 2 Jun 2018 03:07:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 0F4AFD3C; Fri, 1 Jun 2018 17:04:06 +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 EB4E3D18 for ; Fri, 1 Jun 2018 17:04:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9A025CF for ; Fri, 1 Jun 2018 17:04:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1D8B818BAEE; Fri, 1 Jun 2018 17:04:01 +0000 (UTC) Received: from rhvm.com (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EF35210C6CF; Fri, 1 Jun 2018 17:04:01 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Fri, 1 Jun 2018 19:03:55 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 01 Jun 2018 17:04:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 01 Jun 2018 17:04:01 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'echaudro@redhat.com' RCPT:'' X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, 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 Subject: [ovs-dev] [PATCH v3 1/1] netdev-vport: reject concomitant incompatible tunnels X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This patch will make sure VXLAN tunnels with and without the group based policy (GBP) option enabled can not coexist on the same destination UDP port. In theory, VXLAN tunnel with and without GBP enables can be multiplexed on the same UDP port as long as different VNI's are used. However currently OVS does not support this, hence this patch to check for this condition. Signed-off-by: Eelco Chaudron --- lib/netdev-vport.c | 147 +++++++++++++++++++++++++++++++++++++++++++-- tests/tunnel.at | 29 +++++++++ 2 files changed, 171 insertions(+), 5 deletions(-) * V2 Updated commit message as its now clear that the OVS implementation does not support VNI multiplexing on the same UDP port. * V3 Back to Cascardo's original approach, i.e. storing some global port information in the class. This avoids checking all available tunnels on every tunnel add/delete/update. diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index 1dae7e031..2be86cf19 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -41,6 +41,7 @@ #include "packets.h" #include "openvswitch/poll-loop.h" #include "route-table.h" +#include "simap.h" #include "smap.h" #include "socket-util.h" #include "unaligned.h" @@ -66,10 +67,14 @@ static uint64_t rt_change_seqno; static int get_patch_config(const struct netdev *netdev, struct smap *args); static int get_tunnel_config(const struct netdev *, struct smap *args); static bool tunnel_check_status_change__(struct netdev_vport *); +static void update_vxlan_global_cfg(struct netdev *, + struct netdev_tunnel_config *, + struct netdev_tunnel_config *); struct vport_class { const char *dpif_port; struct netdev_class netdev_class; + struct simap global_cfg_tracker; }; bool @@ -78,7 +83,7 @@ netdev_vport_is_vport_class(const struct netdev_class *class) return is_vport_class(class); } -static const struct vport_class * +static struct vport_class * vport_class_cast(const struct netdev_class *class) { ovs_assert(is_vport_class(class)); @@ -195,6 +200,7 @@ netdev_vport_construct(struct netdev *netdev_) dev->tnl_cfg.dst_port = htons(GENEVE_DST_PORT); } else if (!strcmp(type, "vxlan")) { dev->tnl_cfg.dst_port = htons(VXLAN_DST_PORT); + update_vxlan_global_cfg(netdev_, NULL, &dev->tnl_cfg); } else if (!strcmp(type, "lisp")) { dev->tnl_cfg.dst_port = htons(LISP_DST_PORT); } else if (!strcmp(type, "stt")) { @@ -210,6 +216,11 @@ static void netdev_vport_destruct(struct netdev *netdev_) { struct netdev_vport *netdev = netdev_vport_cast(netdev_); + const char *type = netdev_get_type(netdev_); + + if (!strcmp(type, "vxlan")) { + update_vxlan_global_cfg(netdev_, &netdev->tnl_cfg, NULL); + } free(netdev->peer); ovs_mutex_destroy(&netdev->mutex); @@ -421,6 +432,117 @@ default_pt_mode(enum tunnel_layers layers) return layers == TNL_L3 ? NETDEV_PT_LEGACY_L3 : NETDEV_PT_LEGACY_L2; } +static char * +vxlan_get_port_ext_gbp_str(uint16_t port, bool gbp, + char namebuf[], size_t bufsize) +{ + snprintf(namebuf, bufsize, "dst_port_%d%s", + port, gbp ? "_gbp" : ""); + + return namebuf; +} + +static void +update_vxlan_global_cfg(struct netdev *netdev, + struct netdev_tunnel_config *old_cfg, + struct netdev_tunnel_config *new_cfg) +{ + unsigned int count; + char namebuf[20]; + const char *type = netdev_get_type(netdev); + struct vport_class *vclass = vport_class_cast(netdev_get_class(netdev)); + + if (strcmp(type, "vxlan") || + (old_cfg != NULL && new_cfg != NULL && + old_cfg->dst_port == new_cfg->dst_port && + old_cfg->exts == new_cfg->exts)) { + return; + } + + if (old_cfg != NULL) { + vxlan_get_port_ext_gbp_str(ntohs(old_cfg->dst_port), + old_cfg->exts & + (1 << OVS_VXLAN_EXT_GBP), + namebuf, sizeof(namebuf)); + + count = simap_get(&vclass->global_cfg_tracker, namebuf); + if (count != 0) { + if (--count) { + simap_put(&vclass->global_cfg_tracker, namebuf, count); + } else { + simap_find_and_delete(&vclass->global_cfg_tracker, namebuf); + } + } + } + + if (new_cfg != NULL) { + vxlan_get_port_ext_gbp_str(ntohs(new_cfg->dst_port), + new_cfg->exts & + (1 << OVS_VXLAN_EXT_GBP), + namebuf, sizeof(namebuf)); + + simap_increase(&vclass->global_cfg_tracker, namebuf, 1); + } +} + +static bool +is_concomitant_vxlan_tunnel_present(struct netdev_vport *dev, + const struct netdev_tunnel_config *tnl_cfg) +{ + char namebuf[20]; + const char *type = netdev_get_type(&dev->up); + struct vport_class *vclass = vport_class_cast(netdev_get_class(&dev->up)); + + if (strcmp(type, "vxlan")) { + return false; + } + + if (dev->tnl_cfg.dst_port == tnl_cfg->dst_port && + (dev->tnl_cfg.exts & (1 << OVS_VXLAN_EXT_GBP)) == + (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP))) { + + if (ntohs(dev->tnl_cfg.dst_port) == VXLAN_DST_PORT) { + /* Special case where we kept the default port/gbp, only ok if + the opposite of the default does not exits */ + vxlan_get_port_ext_gbp_str(ntohs(tnl_cfg->dst_port), + !(tnl_cfg->exts & + (1 << OVS_VXLAN_EXT_GBP)), + namebuf, sizeof(namebuf)); + + if (simap_get(&vclass->global_cfg_tracker, namebuf) > 0) { + return true; + } + } + return false; + } + + /* Same port: ok if no one is left with the previous configuration */ + if (dev->tnl_cfg.dst_port == tnl_cfg->dst_port) { + vxlan_get_port_ext_gbp_str(ntohs(dev->tnl_cfg.dst_port), + dev->tnl_cfg.exts & + (1 << OVS_VXLAN_EXT_GBP), + namebuf, sizeof(namebuf)); + + if (simap_get(&vclass->global_cfg_tracker, namebuf) > 1) { + return true; + } + + return false; + } + + /* Different port: ok if the opposite gbp option does not yet exists */ + vxlan_get_port_ext_gbp_str(ntohs(tnl_cfg->dst_port), + !(tnl_cfg->exts & + (1 << OVS_VXLAN_EXT_GBP)), + namebuf, sizeof(namebuf)); + + if (simap_get(&vclass->global_cfg_tracker, namebuf) > 0) { + return true; + } + + return false; +} + static int set_tunnel_config(struct netdev *dev_, const struct smap *args, char **errp) { @@ -678,6 +800,16 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args, char **errp) &tnl_cfg.out_key_present, &tnl_cfg.out_key_flow); + if (is_concomitant_vxlan_tunnel_present(dev, &tnl_cfg)) { + ds_put_format(&errors, "%s: VXLAN-GBP, and non-VXLAN-GBP " + "tunnels can't be configured on the same " + "dst_port\n", + name); + err = EEXIST; + goto out; + } + update_vxlan_global_cfg(dev_, &dev->tnl_cfg, &tnl_cfg); + ovs_mutex_lock(&dev->mutex); if (memcmp(&dev->tnl_cfg, &tnl_cfg, sizeof tnl_cfg)) { dev->tnl_cfg = tnl_cfg; @@ -1062,14 +1194,15 @@ netdev_vport_get_ifindex(const struct netdev *netdev_) get_netdev_tunnel_config, \ tunnel_get_status, \ BUILD_HEADER, PUSH_HEADER, POP_HEADER, \ - GET_IFINDEX) }} + GET_IFINDEX) }, \ + {{0}} } void netdev_vport_tunnel_register(void) { /* The name of the dpif_port should be short enough to accomodate adding * a port number to the end if one is necessary. */ - static const struct vport_class vport_classes[] = { + static struct vport_class vport_classes[] = { TUNNEL_CLASS("geneve", "genev_sys", netdev_geneve_build_header, netdev_tnl_push_udp_header, netdev_geneve_pop_header, @@ -1103,6 +1236,7 @@ netdev_vport_tunnel_register(void) int i; for (i = 0; i < ARRAY_SIZE(vport_classes); i++) { + simap_init(&vport_classes[i].global_cfg_tracker); netdev_register_provider(&vport_classes[i].netdev_class); } @@ -1116,12 +1250,15 @@ netdev_vport_tunnel_register(void) void netdev_vport_patch_register(void) { - static const struct vport_class patch_class = + static struct vport_class patch_class = { NULL, { "patch", false, VPORT_FUNCTIONS(get_patch_config, set_patch_config, NULL, - NULL, NULL, NULL, NULL, NULL) }}; + NULL, NULL, NULL, NULL, NULL)}, + {{0}} }; + + simap_init(&patch_class.global_cfg_tracker); netdev_register_provider(&patch_class.netdev_class); } diff --git a/tests/tunnel.at b/tests/tunnel.at index 2bc004cd8..3ac9cd83f 100644 --- a/tests/tunnel.at +++ b/tests/tunnel.at @@ -831,6 +831,35 @@ AT_CHECK([tail -1 stdout], [0], [Datapath actions: set(tunnel(dst=1.1.1.1,ttl=64,tp_dst=4789,flags(df))),4789 ]) +OVS_VSWITCHD_STOP +AT_CLEANUP + +AT_SETUP([tunnel - concomitant incompatible tunnels on the same port]) +OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \ + options:remote_ip=flow ofport_request=1]) + +AT_CHECK([ovs-vsctl add-port br0 p2 -- set Interface p2 type=vxlan \ + options:remote_ip=flow options:exts=gbp options:key=1 ofport_request=2], [0], + [], [ignore]) + +AT_CHECK([grep 'p2: could not set configuration (File exists)' ovs-vswitchd.log | sed "s/^.*\(p2:.*\)$/\1/"], [0], + [p2: could not set configuration (File exists) +]) + +OVS_VSWITCHD_STOP(["/p2: VXLAN-GBP, and non-VXLAN-GBP tunnels can't be configured on the same dst_port/d +/p2: could not set configuration (File exists)/d"]) +AT_CLEANUP + +AT_SETUP([tunnel - concomitant incompatible tunnels on different ports]) +OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=vxlan \ + options:remote_ip=flow ofport_request=1]) + +AT_CHECK([ovs-vsctl add-port br0 p2 -- set Interface p2 type=vxlan options:dst_port=9000 \ + options:remote_ip=flow options:exts=gbp ofport_request=2]) + +AT_CHECK([grep p2 ovs-vswitchd.log | sed "s/^.*\(bridge br0:.*\)$/\1/"], [0], + [bridge br0: added interface p2 on port 2 +]) OVS_VSWITCHD_STOP AT_CLEANUP