From patchwork Thu Oct 8 13:53:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Benc X-Patchwork-Id: 527712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 5F7DD140D6E for ; Fri, 9 Oct 2015 00:53:36 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 17654109DD; Thu, 8 Oct 2015 06:53:35 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 1909B109D4 for ; Thu, 8 Oct 2015 06:53:34 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 6F432420102 for ; Thu, 8 Oct 2015 07:53:33 -0600 (MDT) X-ASG-Debug-ID: 1444312411-09eadd14184742d0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id obQ8fxUssomPGOAK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 08 Oct 2015 07:53:31 -0600 (MDT) X-Barracuda-Envelope-From: jbenc@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 8 Oct 2015 13:53:31 -0000 Received-SPF: pass (mx1-pf2.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-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id EC922C18F727; Thu, 8 Oct 2015 13:53:28 +0000 (UTC) Received: from griffin.upir.cz (ovpn-204-20.brq.redhat.com [10.40.204.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t98DrQXv016031; Thu, 8 Oct 2015 09:53:27 -0400 X-CudaMail-Envelope-Sender: jbenc@redhat.com From: Jiri Benc To: netdev@vger.kernel.org X-CudaMail-MID: CM-E2-1007022883 X-CudaMail-DTE: 100815 X-CudaMail-Originating-IP: 209.132.183.28 Date: Thu, 8 Oct 2015 15:53:04 +0200 X-ASG-Orig-Subj: [##CM-E2-1007022883##][PATCH net-next] openvswitch: report features supported by the kernel datapath Message-Id: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0.343385 p=-0.142857 Source Normal X-MessageSniffer-Rules: 0-0-0-10414-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1444312411 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=3.0 tests=BSF_SC0_MISMATCH_TO, BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.23304 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH net-next] openvswitch: report features supported by the kernel datapath 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" Allow the user space to query what features are supported by the openvswitch module. This will be used to allow or disallow certain configurations and/or switch between newer and older APIs depending on what the kernel supports. Two features are reported as supported by this patch: lwtunnel and IPv6 tunneling support. Theoretically, we could merge these two, as any of them implies the other with this patch applied, but it's better to keep them separate: kernel 4.3 supports lwtunnels but not IPv6 for ovs, and the separation of the two flags allows us to backport a version of this patch to 4.3 should the need arise. Signed-off-by: Jiri Benc --- This is intentionally submitted to net-next. Kernel 4.3 will be fine without this feature (but despite that, I'd like to keep the two flags separate). --- include/uapi/linux/openvswitch.h | 12 ++++++++++++ net/openvswitch/datapath.c | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index 32e07d8cbaf4..3d8d00b6e55d 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -73,6 +73,10 @@ enum ovs_datapath_cmd { * datapath. Always present in notifications. * @OVS_DP_ATTR_MEGAFLOW_STATS: Statistics about mega flow masks usage for the * datapath. Always present in notifications. + * @OVS_DP_ATTR_KERNEL_FEATURES: Bitmask of features that the datapath + * supports. When creating a datapath, this is a minimal feature set + * requested, the request will fail if it cannot be honored. On get + * operations, this contains all features supported by the datapath. * * These attributes follow the &struct ovs_header within the Generic Netlink * payload for %OVS_DP_* commands. @@ -84,6 +88,7 @@ enum ovs_datapath_attr { OVS_DP_ATTR_STATS, /* struct ovs_dp_stats */ OVS_DP_ATTR_MEGAFLOW_STATS, /* struct ovs_dp_megaflow_stats */ OVS_DP_ATTR_USER_FEATURES, /* OVS_DP_F_* */ + OVS_DP_ATTR_KERNEL_FEATURES, /* OVS_DP_KF_* */ __OVS_DP_ATTR_MAX }; @@ -121,6 +126,13 @@ struct ovs_vport_stats { /* Allow datapath to associate multiple Netlink PIDs to each vport */ #define OVS_DP_F_VPORT_PIDS (1 << 1) +/* Datapath features */ +#define OVS_DP_KF_LWTUNNEL (1ULL << 0) /* lwtunnel interface supported */ +#define OVS_DP_KF_IPV6_TUNNEL (1ULL << 1) /* IPv6 tunneling supported */ + +#define OVS_DP_KF_ALL (OVS_DP_KF_LWTUNNEL | \ + OVS_DP_KF_IPV6_TUNNEL) + /* Fixed logical ports. */ #define OVSP_LOCAL ((__u32)0) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index a75828091e21..896435779fc8 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -1439,6 +1439,7 @@ static size_t ovs_dp_cmd_msg_size(void) msgsize += nla_total_size(sizeof(struct ovs_dp_stats)); msgsize += nla_total_size(sizeof(struct ovs_dp_megaflow_stats)); msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */ + msgsize += nla_total_size(sizeof(u64)); /* OVS_DP_ATTR_KERNEL_FEATURES */ return msgsize; } @@ -1476,6 +1477,9 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features)) goto nla_put_failure; + if (nla_put_u64(skb, OVS_DP_ATTR_KERNEL_FEATURES, OVS_DP_KF_ALL)) + goto nla_put_failure; + genlmsg_end(skb, ovs_header); return 0; @@ -1526,6 +1530,13 @@ static void ovs_dp_change(struct datapath *dp, struct nlattr *a[]) dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); } +static bool ovs_dp_kernel_features_ok(struct nlattr *a[]) +{ + if (!a[OVS_DP_ATTR_KERNEL_FEATURES]) + return true; + return !(nla_get_u64(a[OVS_DP_ATTR_KERNEL_FEATURES]) & ~OVS_DP_KF_ALL); +} + static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) { struct nlattr **a = info->attrs; @@ -1536,9 +1547,10 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) struct ovs_net *ovs_net; int err, i; - err = -EINVAL; if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID]) - goto err; + return -EINVAL; + if (!ovs_dp_kernel_features_ok(a)) + return -EOPNOTSUPP; reply = ovs_dp_cmd_alloc_info(info); if (!reply) @@ -1626,7 +1638,6 @@ err_free_dp: kfree(dp); err_free_reply: kfree_skb(reply); -err: return err; } @@ -1694,6 +1705,9 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info) struct datapath *dp; int err; + if (!ovs_dp_kernel_features_ok(info->attrs)) + return -EOPNOTSUPP; + reply = ovs_dp_cmd_alloc_info(info); if (!reply) return -ENOMEM; @@ -1777,6 +1791,7 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, + [OVS_DP_ATTR_KERNEL_FEATURES] = { .type = NLA_U64 }, }; static const struct genl_ops dp_datapath_genl_ops[] = {