From patchwork Sun May 7 13:43:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 759439 X-Patchwork-Delegate: joestringer@nicira.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wLRk15chrz9s84 for ; Sun, 7 May 2017 23:46:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 57E31B5F; Sun, 7 May 2017 13:43:53 +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 C80B2B4A for ; Sun, 7 May 2017 13:43:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3FF37D3 for ; Sun, 7 May 2017 13:43:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A421EC05683F for ; Sun, 7 May 2017 13:43:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A421EC05683F Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=erig.me Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=e@erig.me DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A421EC05683F Received: from wsfd-netdev-buildsys.ntdv.lab.eng.bos.redhat.com (wsfd-netdev-buildsys.ntdv.lab.eng.bos.redhat.com [10.19.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 601A05C542 for ; Sun, 7 May 2017 13:43:46 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Sun, 7 May 2017 09:43:40 -0400 Message-Id: <20170507134343.2709-5-e@erig.me> In-Reply-To: <20170507134343.2709-1-e@erig.me> References: <20170507134343.2709-1-e@erig.me> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 07 May 2017 13:43:46 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 v4 4/7] dpif-netlink-rtnl: add VXLAN creation support 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 Creates VXLAN devices using rtnetlink and tunnel metadata. Co-Authored-by: Thadeu Lima de Souza Cascardo Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Eric Garver --- lib/dpif-netlink-rtnl.c | 80 ++++++++++++++++++++++++++++++++++++++++++++----- lib/dpif-netlink-rtnl.h | 3 +- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/lib/dpif-netlink-rtnl.c b/lib/dpif-netlink-rtnl.c index 906e05145190..6ab882c73756 100644 --- a/lib/dpif-netlink-rtnl.c +++ b/lib/dpif-netlink-rtnl.c @@ -26,6 +26,18 @@ #include "netdev-vport.h" #include "netlink-socket.h" +/* On some older systems, these enums are not defined. */ +#ifndef IFLA_VXLAN_MAX +#define IFLA_VXLAN_MAX 0 +#endif +#if IFLA_VXLAN_MAX < 25 +#define IFLA_VXLAN_LEARNING 7 +#define IFLA_VXLAN_PORT 15 +#define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20 +#define IFLA_VXLAN_GBP 23 +#define IFLA_VXLAN_COLLECT_METADATA 25 +#endif + static const struct nl_policy rtlink_policy[] = { [IFLA_LINKINFO] = { .type = NL_A_NESTED }, }; @@ -33,6 +45,12 @@ static const struct nl_policy linkinfo_policy[] = { [IFLA_INFO_KIND] = { .type = NL_A_STRING }, [IFLA_INFO_DATA] = { .type = NL_A_NESTED }, }; +static const struct nl_policy vxlan_policy[] = { + [IFLA_VXLAN_COLLECT_METADATA] = { .type = NL_A_U8 }, + [IFLA_VXLAN_LEARNING] = { .type = NL_A_U8 }, + [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NL_A_U8 }, + [IFLA_VXLAN_PORT] = { .type = NL_A_U16 }, +}; static int rtnl_transact(uint32_t type, uint32_t flags, const char *name, @@ -58,13 +76,13 @@ dpif_netlink_rtnl_destroy(const char *name) return rtnl_transact(RTM_DELLINK, NLM_F_REQUEST | NLM_F_ACK, name, NULL); } -static int OVS_UNUSED +static int dpif_netlink_rtnl_getlink(const char *name, struct ofpbuf **reply) { return rtnl_transact(RTM_GETLINK, NLM_F_REQUEST, name, reply); } -static int OVS_UNUSED +static int rtnl_policy_parse(const char *kind, struct ofpbuf *reply, const struct nl_policy *policy, struct nlattr *tnl_info[], @@ -90,11 +108,48 @@ rtnl_policy_parse(const char *kind, struct ofpbuf *reply, } static int -dpif_netlink_rtnl_verify(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, - enum ovs_vport_type type, const char OVS_UNUSED *name) +dpif_netlink_rtnl_vxlan_verify(const struct netdev_tunnel_config *tnl_cfg, + const char *name, const char *kind) +{ + struct ofpbuf *reply; + int err; + + err = dpif_netlink_rtnl_getlink(name, &reply); + + if (!err) { + struct nlattr *vxlan[ARRAY_SIZE(vxlan_policy)]; + + err = rtnl_policy_parse(kind, reply, vxlan_policy, vxlan, + ARRAY_SIZE(vxlan_policy)); + if (!err) { + if (0 != nl_attr_get_u8(vxlan[IFLA_VXLAN_LEARNING]) + || 1 != nl_attr_get_u8(vxlan[IFLA_VXLAN_COLLECT_METADATA]) + || 1 != nl_attr_get_u8(vxlan[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) + || (tnl_cfg->dst_port + != nl_attr_get_be16(vxlan[IFLA_VXLAN_PORT]))) { + err = EINVAL; + } + } + if (!err) { + if (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP) + && !nl_attr_get_flag(vxlan[IFLA_VXLAN_GBP])) { + err = EINVAL; + } + } + ofpbuf_delete(reply); + } + + return err; +} + + +static int +dpif_netlink_rtnl_verify(const struct netdev_tunnel_config *tnl_cfg, + enum ovs_vport_type type, const char *name) { switch (type) { case OVS_VPORT_TYPE_VXLAN: + return dpif_netlink_rtnl_vxlan_verify(tnl_cfg, name, "vxlan"); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -110,8 +165,8 @@ dpif_netlink_rtnl_verify(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, return 0; } -static int OVS_UNUSED -dpif_netlink_rtnl_create(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, +static int +dpif_netlink_rtnl_create(const struct netdev_tunnel_config *tnl_cfg, const char *name, enum ovs_vport_type type, const char *kind, uint32_t flags) { @@ -133,6 +188,14 @@ dpif_netlink_rtnl_create(const struct netdev_tunnel_config OVS_UNUSED *tnl_cfg, /* tunnel unique info */ switch (type) { case OVS_VPORT_TYPE_VXLAN: + nl_msg_put_u8(&request, IFLA_VXLAN_LEARNING, 0); + 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); + break; case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -180,6 +243,8 @@ dpif_netlink_rtnl_port_create(struct netdev *netdev) try_again: switch (type) { case OVS_VPORT_TYPE_VXLAN: + err = dpif_netlink_rtnl_create(tnl_cfg, name, type, "vxlan", flags); + break; case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: @@ -208,10 +273,11 @@ try_again: } int -dpif_netlink_rtnl_port_destroy(const char *name OVS_UNUSED, const char *type) +dpif_netlink_rtnl_port_destroy(const char *name, const char *type) { switch (netdev_to_ovs_vport_type(type)) { case OVS_VPORT_TYPE_VXLAN: + return dpif_netlink_rtnl_destroy(name); case OVS_VPORT_TYPE_GRE: case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: diff --git a/lib/dpif-netlink-rtnl.h b/lib/dpif-netlink-rtnl.h index 5fef314a20f6..952c0d4187e5 100644 --- a/lib/dpif-netlink-rtnl.h +++ b/lib/dpif-netlink-rtnl.h @@ -23,8 +23,7 @@ /* Declare these to keep sparse happy. */ int dpif_netlink_rtnl_port_create(struct netdev *netdev); -int dpif_netlink_rtnl_port_destroy(const char *name OVS_UNUSED, - const char *type); +int dpif_netlink_rtnl_port_destroy(const char *name, const char *type); #ifndef __linux__ /* Dummy implementations for non Linux builds. */