From patchwork Thu Apr 13 20:47:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 750610 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 3w3tFS6W5Kz9sNQ for ; Fri, 14 Apr 2017 06:49:32 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 330CAC86; Thu, 13 Apr 2017 20:47:42 +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 E8D3EC5F for ; Thu, 13 Apr 2017 20:47:36 +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 6D4851D3 for ; Thu, 13 Apr 2017 20:47:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2EA79C0B4 for ; Thu, 13 Apr 2017 20:47:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2EA79C0B4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=erig.me Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=e@erig.me DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E2EA79C0B4 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 9DC7817481 for ; Thu, 13 Apr 2017 20:47:35 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Thu, 13 Apr 2017 16:47:31 -0400 Message-Id: <20170413204732.16707-7-e@erig.me> In-Reply-To: <20170413204732.16707-1-e@erig.me> References: <20170413204732.16707-1-e@erig.me> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 13 Apr 2017 20:47:36 +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 v3 6/7] dpif-netlink-rtnl: add GENEVE 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 GENEVE 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 | 115 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netlink-rtnl.c b/lib/dpif-netlink-rtnl.c index 73022b5d86d0..5a3326ea1f63 100644 --- a/lib/dpif-netlink-rtnl.c +++ b/lib/dpif-netlink-rtnl.c @@ -47,6 +47,15 @@ #define IFLA_GRE_COLLECT_METADATA 18 #endif +#ifndef IFLA_GENEVE_MAX +#define IFLA_GENEVE_MAX 0 +#endif +#if IFLA_GENEVE_MAX < 10 +#define IFLA_GENEVE_PORT 5 +#define IFLA_GENEVE_COLLECT_METADATA 6 +#define IFLA_GENEVE_UDP_ZERO_CSUM6_RX 10 +#endif + static const struct nl_policy rtlink_policy[] = { [IFLA_LINKINFO] = { .type = NL_A_NESTED }, }; @@ -295,6 +304,109 @@ dpif_netlink_rtnl_gre_create(struct netdev *netdev) return dpif_netlink_rtnl_gre_create_kind(netdev, "gretap"); } +static int +dpif_netlink_rtnl_geneve_verify(struct netdev *netdev, const char *name, + const char *kind) +{ + const struct netdev_tunnel_config *tnl_cfg; + struct ifinfomsg *ifmsg; + struct ofpbuf *reply; + int err; + + static const struct nl_policy geneve_policy[] = { + [IFLA_GENEVE_COLLECT_METADATA] = { .type = NL_A_FLAG }, + [IFLA_GENEVE_UDP_ZERO_CSUM6_RX] = { .type = NL_A_U8 }, + [IFLA_GENEVE_PORT] = { .type = NL_A_U16 }, + }; + + tnl_cfg = netdev_get_tunnel_config(netdev); + if (!tnl_cfg) { + return EINVAL; + } + + err = dpif_netlink_rtnl_getlink(name, &reply); + + if (!err) { + struct nlattr *rtlink[ARRAY_SIZE(rtlink_policy)]; + struct nlattr *linkinfo[ARRAY_SIZE(linkinfo_policy)]; + struct nlattr *geneve[ARRAY_SIZE(geneve_policy)]; + + ifmsg = ofpbuf_at(reply, NLMSG_HDRLEN, sizeof *ifmsg); + if (!nl_policy_parse(reply, NLMSG_HDRLEN + sizeof *ifmsg, + rtlink_policy, rtlink, ARRAY_SIZE(rtlink_policy)) + || !nl_parse_nested(rtlink[IFLA_LINKINFO], linkinfo_policy, + linkinfo, ARRAY_SIZE(linkinfo_policy)) + || strcmp(nl_attr_get_string(linkinfo[IFLA_INFO_KIND]), kind) + || !nl_parse_nested(linkinfo[IFLA_INFO_DATA], geneve_policy, + geneve, ARRAY_SIZE(geneve_policy))) { + err = EINVAL; + } + if (!err) { + if (!nl_attr_get_flag(geneve[IFLA_GENEVE_COLLECT_METADATA]) + || 1 != nl_attr_get_u8(geneve[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]) + || (tnl_cfg->dst_port != + nl_attr_get_be16(geneve[IFLA_GENEVE_PORT]))) { + err = EINVAL; + } + } + ofpbuf_delete(reply); + } + + return err; +} + +static int +dpif_netlink_rtnl_geneve_create_kind(struct netdev *netdev, const char *kind) +{ + const struct netdev_tunnel_config *tnl_cfg; + char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; + size_t linkinfo_off, infodata_off; + struct ifinfomsg *ifinfo; + struct ofpbuf request; + const char *name; + int err; + + tnl_cfg = netdev_get_tunnel_config(netdev); + if (!tnl_cfg) { + return EINVAL; + } + + name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); + + 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, kind); + infodata_off = nl_msg_start_nested(&request, IFLA_INFO_DATA); + + nl_msg_put_flag(&request, IFLA_GENEVE_COLLECT_METADATA); + nl_msg_put_u8(&request, IFLA_GENEVE_UDP_ZERO_CSUM6_RX, 1); + nl_msg_put_be16(&request, IFLA_GENEVE_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, NULL); + ofpbuf_uninit(&request); + + if (!err && (err = dpif_netlink_rtnl_geneve_verify(netdev, name, kind))) { + dpif_netlink_rtnl_destroy(name); + } + + return err; +} + +static int +dpif_netlink_rtnl_geneve_create(struct netdev *netdev) +{ + return dpif_netlink_rtnl_geneve_create_kind(netdev, "geneve"); +} + int dpif_netlink_rtnl_port_create(struct netdev *netdev) { @@ -304,6 +416,7 @@ dpif_netlink_rtnl_port_create(struct netdev *netdev) case OVS_VPORT_TYPE_GRE: return dpif_netlink_rtnl_gre_create(netdev); case OVS_VPORT_TYPE_GENEVE: + return dpif_netlink_rtnl_geneve_create(netdev); case OVS_VPORT_TYPE_NETDEV: case OVS_VPORT_TYPE_INTERNAL: case OVS_VPORT_TYPE_LISP: @@ -322,8 +435,8 @@ dpif_netlink_rtnl_port_destroy(const char *name, const char *type) switch (netdev_to_ovs_vport_type(type)) { case OVS_VPORT_TYPE_VXLAN: case OVS_VPORT_TYPE_GRE: - return dpif_netlink_rtnl_destroy(name); case OVS_VPORT_TYPE_GENEVE: + return dpif_netlink_rtnl_destroy(name); case OVS_VPORT_TYPE_NETDEV: case OVS_VPORT_TYPE_INTERNAL: case OVS_VPORT_TYPE_LISP: