From patchwork Wed Jun 8 18:22:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 632439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rPxcj6ztHz9t0r for ; Thu, 9 Jun 2016 04:22:45 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 08E5410A29; Wed, 8 Jun 2016 11:22:24 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 1485B10A22 for ; Wed, 8 Jun 2016 11:22:23 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 8D2831622BE for ; Wed, 8 Jun 2016 12:22:22 -0600 (MDT) X-ASG-Debug-ID: 1465410141-0b3237415a00e60001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar6.cudamail.com with ESMTP id AKE4jilLM1kAN7lV (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 08 Jun 2016 12:22:21 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 8 Jun 2016 18:22:20 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47FBEC049D60 for ; Wed, 8 Jun 2016 18:22:20 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-116-43.phx2.redhat.com [10.3.116.43]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u58IMD8Q005520 for ; Wed, 8 Jun 2016 14:22:19 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V1-607039159 X-CudaMail-DTE: 060816 X-CudaMail-Originating-IP: 209.132.183.28 Date: Wed, 8 Jun 2016 15:22:01 -0300 X-ASG-Orig-Subj: [##CM-V1-607039159##][PATCH v2 3/5] dpif-netlink: add VXLAN creation support Message-Id: <1465410123-1879-4-git-send-email-cascardo@redhat.com> In-Reply-To: <1465410123-1879-1-git-send-email-cascardo@redhat.com> References: <1465410123-1879-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Jun 2016 18:22:20 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1465410141 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH v2 3/5] dpif-netlink: add VXLAN creation support X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Creates VXLAN devices using rtnetlink and tunnel metadata. If the kernel does not support tunnel metadata, it will return EINVAL because of the missing VNI attribute. This was tested on kernels 4.2.3, 4.3.6, 4.4.9, 4.5.5 and RHEL-based 3.10. All of them worked with the system traffic test "datapath - ping over vxlan tunnel". Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/dpif-netlink.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index b624118..2845268 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -931,6 +933,119 @@ dpif_netlink_port_add_compat(struct dpif_netlink *dpif, struct netdev *netdev, } +#ifdef __linux__ + +static int +netdev_linux_destroy(const char *name) +{ + int err; + struct ofpbuf request, *reply; + + ofpbuf_init(&request, 0); + nl_msg_put_nlmsghdr(&request, 0, RTM_DELLINK, + NLM_F_REQUEST | NLM_F_ACK); + ofpbuf_put_zeros(&request, sizeof(struct ifinfomsg)); + nl_msg_put_string(&request, IFLA_IFNAME, name); + + err = nl_transact(NETLINK_ROUTE, &request, &reply); + + if (!err) { + ofpbuf_uninit(reply); + } + + ofpbuf_uninit(&request); + return err; +} + +static int +netdev_vxlan_destroy(const char *name) +{ + return netdev_linux_destroy(name); +} + +/* + * On some older systems, these enums are not defined. + */ + +#ifndef IFLA_VXLAN_MAX +#define IFLA_VXLAN_MAX 0 +#define IFLA_VXLAN_PORT 15 +#endif +#if IFLA_VXLAN_MAX < 20 +#define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20 +#define IFLA_VXLAN_GBP 23 +#define IFLA_VXLAN_COLLECT_METADATA 25 +#endif + +static int +netdev_vxlan_create(struct netdev *netdev) +{ + int err; + struct ofpbuf request, *reply; + size_t linkinfo_off, infodata_off; + char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; + const char *name = netdev_vport_get_dpif_port(netdev, + namebuf, sizeof namebuf); + struct ifinfomsg *ifinfo; + const struct netdev_tunnel_config *tnl_cfg; + tnl_cfg = netdev_get_tunnel_config(netdev); + if (!tnl_cfg) { /* or assert? */ + return EINVAL; + } + + ofpbuf_init(&request, 0); + nl_msg_put_nlmsghdr(&request, 0, RTM_NEWLINK, + NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE); + ifinfo = ofpbuf_put_zeros(&request, sizeof(struct ifinfomsg)); + ifinfo->ifi_change = ifinfo->ifi_flags = IFF_UP; + nl_msg_put_string(&request, IFLA_IFNAME, name); + nl_msg_put_u32(&request, IFLA_MTU, UINT16_MAX); + linkinfo_off = nl_msg_start_nested(&request, IFLA_LINKINFO); + nl_msg_put_string(&request, IFLA_INFO_KIND, "vxlan"); + infodata_off = nl_msg_start_nested(&request, IFLA_INFO_DATA); + nl_msg_put_u8(&request, IFLA_VXLAN_COLLECT_METADATA, 1); + nl_msg_put_u8(&request, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 1); + if (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP)) { + nl_msg_put_flag(&request, IFLA_VXLAN_GBP); + } + nl_msg_put_be16(&request, IFLA_VXLAN_PORT, tnl_cfg->dst_port); + nl_msg_end_nested(&request, infodata_off); + nl_msg_end_nested(&request, linkinfo_off); + + err = nl_transact(NETLINK_ROUTE, &request, &reply); + + if (!err) { + ofpbuf_uninit(reply); + } + + /* + * Linux versions older than 4.3 will return EINVAL in case the VID is not + * set, which is sufficient to verify COLLECT_METADATA is supported. + */ + if (err == EINVAL) { + err = EOPNOTSUPP; + } + + ofpbuf_uninit(&request); + return err; +} + +#else + +static int +netdev_vxlan_create(struct netdev *netdev OVS_UNUSED) +{ + return EOPNOTSUPP; +} + +static int +netdev_vxlan_destroy(const char *name OVS_UNUSED) +{ + return EOPNOTSUPP; +} + +#endif + static int dpif_netlink_port_query__(const struct dpif_netlink *dpif, odp_port_t port_no, const char *port_name, struct dpif_port *dpif_port); @@ -940,6 +1055,7 @@ dpif_netlink_port_create(struct netdev *netdev) { switch (netdev_to_ovs_vport_type(netdev_get_type(netdev))) { case OVS_VPORT_TYPE_VXLAN: + return netdev_vxlan_create(netdev); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -955,10 +1071,11 @@ dpif_netlink_port_create(struct netdev *netdev) } static int -dpif_netlink_port_destroy(const char *name OVS_UNUSED, const char *type) +dpif_netlink_port_destroy(const char *name, const char *type) { switch (netdev_to_ovs_vport_type(type)) { case OVS_VPORT_TYPE_VXLAN: + return netdev_vxlan_destroy(name); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: