From patchwork Thu Apr 13 20:47:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 750613 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 3w3tHB2HD0z9sNQ for ; Fri, 14 Apr 2017 06:51:02 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EC368C97; Thu, 13 Apr 2017 20:47:44 +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 DC483C5F for ; Thu, 13 Apr 2017 20:47:37 +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 189EB1BB 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 7BEFB9C0AC for ; Thu, 13 Apr 2017 20:47:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7BEFB9C0AC 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 7BEFB9C0AC 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 38D8E17146 for ; Thu, 13 Apr 2017 20:47:35 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Thu, 13 Apr 2017 16:47:30 -0400 Message-Id: <20170413204732.16707-6-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:35 +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 5/7] dpif-netlink-rtnl: add GRE 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 GRE 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 | 100 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netlink-rtnl.c b/lib/dpif-netlink-rtnl.c index be40cfab393f..73022b5d86d0 100644 --- a/lib/dpif-netlink-rtnl.c +++ b/lib/dpif-netlink-rtnl.c @@ -40,6 +40,13 @@ #define IFLA_VXLAN_COLLECT_METADATA 25 #endif +#ifndef IFLA_GRE_MAX +#define IFLA_GRE_MAX 0 +#endif +#if IFLA_GRE_MAX < 18 +#define IFLA_GRE_COLLECT_METADATA 18 +#endif + static const struct nl_policy rtlink_policy[] = { [IFLA_LINKINFO] = { .type = NL_A_NESTED }, }; @@ -198,6 +205,96 @@ dpif_netlink_rtnl_vxlan_create(struct netdev *netdev) return dpif_netlink_rtnl_vxlan_create_kind(netdev, "vxlan"); } +static int +dpif_netlink_rtnl_gre_verify(struct netdev *netdev OVS_UNUSED, + const char *name, const char *kind) +{ + struct ifinfomsg *ifmsg; + struct ofpbuf *reply; + int err; + + static const struct nl_policy gre_policy[] = { + [IFLA_GRE_COLLECT_METADATA] = { .type = NL_A_FLAG }, + }; + + 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 *gre[ARRAY_SIZE(gre_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], gre_policy, gre, + ARRAY_SIZE(gre_policy))) { + err = EINVAL; + } + if (!err) { + if (!nl_attr_get_flag(gre[IFLA_GRE_COLLECT_METADATA])) { + err = EINVAL; + } + } + ofpbuf_delete(reply); + } + + return err; +} + +static int +dpif_netlink_rtnl_gre_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_GRE_COLLECT_METADATA); + + 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_gre_verify(netdev, name, kind))) { + dpif_netlink_rtnl_destroy(name); + } + + return err; +} + +static int +dpif_netlink_rtnl_gre_create(struct netdev *netdev) +{ + return dpif_netlink_rtnl_gre_create_kind(netdev, "gretap"); +} + int dpif_netlink_rtnl_port_create(struct netdev *netdev) { @@ -205,6 +302,7 @@ dpif_netlink_rtnl_port_create(struct netdev *netdev) case OVS_VPORT_TYPE_VXLAN: return dpif_netlink_rtnl_vxlan_create(netdev); case OVS_VPORT_TYPE_GRE: + return dpif_netlink_rtnl_gre_create(netdev); case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: case OVS_VPORT_TYPE_INTERNAL: @@ -223,8 +321,8 @@ 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: + return dpif_netlink_rtnl_destroy(name); case OVS_VPORT_TYPE_GENEVE: case OVS_VPORT_TYPE_NETDEV: case OVS_VPORT_TYPE_INTERNAL: