From patchwork Thu Apr 27 21:48:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarno Rajahalme X-Patchwork-Id: 756155 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 3wDVvp4vLdz9sCX for ; Fri, 28 Apr 2017 07:49:10 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 32F38C38; Thu, 27 Apr 2017 21:49:09 +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 0E8C5C13 for ; Thu, 27 Apr 2017 21:49:08 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1A2AB10A for ; Thu, 27 Apr 2017 21:49:07 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id E39EF402F2; Thu, 27 Apr 2017 23:49:05 +0200 (CEST) Received: from mfilter22-d.gandi.net (mfilter22-d.gandi.net [217.70.178.150]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id CB21E41C074; Thu, 27 Apr 2017 23:49:05 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter22-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter22-d.gandi.net (mfilter22-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id SdQu4bmD-VgK; Thu, 27 Apr 2017 23:49:04 +0200 (CEST) X-Originating-IP: 208.91.1.34 Received: from sc9-mailhost3.vmware.com (unknown [208.91.1.34]) (Authenticated sender: jarno@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 8784341C07F; Thu, 27 Apr 2017 23:49:03 +0200 (CEST) From: Jarno Rajahalme To: dev@openvswitch.org Date: Thu, 27 Apr 2017 14:48:54 -0700 Message-Id: <1493329734-57461-1-git-send-email-jarno@ovn.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM 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] xlate: Use OVS_CT_ATTR_EVENTMASK. 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 Specify the event mask with CT commit including bits for CT features exposed at the OVS interface (mark and label changes in addition to basic creation and destruction of conntrack entries). Without this any listener of conntrack update events will typically (depending on system configuration) receive events for each L4 (e.g., TCP) state machine change, which can multiply the number of events received per connection. By including the new, related, and destroy events any listener of new conntrack events gets notified of new related and non-related connections, and any listener of destroy events will get notified of deleted (typically timed out) conntrack entries. By including the flags for mark and labels, any listener of conntrack update events gets notified whenever the connmark or conntrack labels are changed from the values reported within the new events. VMware-BZ: #1837218 Signed-off-by: Jarno Rajahalme Acked-by: Joe Stringer --- v3: Added feature probing to not use the new attribute on datapaths the do not support it. build-aux/extract-odp-netlink-h | 2 ++ ofproto/ofproto-dpif-xlate.c | 6 ++++ ofproto/ofproto-dpif.c | 62 +++++++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif.h | 5 +++- 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/build-aux/extract-odp-netlink-h b/build-aux/extract-odp-netlink-h index 907a70a..7fb6ce8 100755 --- a/build-aux/extract-odp-netlink-h +++ b/build-aux/extract-odp-netlink-h @@ -19,6 +19,8 @@ $i\ #ifdef _WIN32\ #include "OvsDpInterfaceExt.h"\ #include "OvsDpInterfaceCtExt.h"\ +#else\ +#include "linux/netfilter/nf_conntrack_common.h"\ #endif\ # Use OVS's own struct eth_addr instead of a 6-byte char array. diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index d8c6a7c..ab5eef8 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -5351,6 +5351,12 @@ compose_conntrack_action(struct xlate_ctx *ctx, struct ofpact_conntrack *ofc) if (ofc->flags & NX_CT_F_COMMIT) { nl_msg_put_flag(ctx->odp_actions, ofc->flags & NX_CT_F_FORCE ? OVS_CT_ATTR_FORCE_COMMIT : OVS_CT_ATTR_COMMIT); + if (ctx->xbridge->support.ct_eventmask) { + nl_msg_put_u32(ctx->odp_actions, OVS_CT_ATTR_EVENTMASK, + 1 << IPCT_NEW | 1 << IPCT_RELATED | + 1 << IPCT_DESTROY | 1 << IPCT_MARK | + 1 << IPCT_LABEL); + } } nl_msg_put_u16(ctx->odp_actions, OVS_CT_ATTR_ZONE, zone); put_ct_mark(&ctx->xin->flow, ctx->odp_actions, ctx->wc); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index c73c273..b052b04 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1241,6 +1241,67 @@ check_clone(struct dpif_backer *backer) return !error; } +/* Tests whether 'backer''s datapath supports the OVS_CT_ATTR_EVENTMASK + * attribute in OVS_ACTION_ATTR_CT. */ +static bool +check_ct_eventmask(struct dpif_backer *backer) +{ + struct dpif_execute execute; + struct dp_packet packet; + struct ofpbuf actions; + struct flow flow = { + .dl_type = htons(ETH_TYPE_IP), + .nw_ttl = 64, + .nw_proto = IPPROTO_UDP, + .nw_src = 0x0a010101, + .nw_dst = 0x0a010102, + .tp_src = 42387, + .tp_dst = 13264, + }; + size_t ct_start; + int error; + + /* Compose CT action with eventmask attribute and check if datapath can + * decode the message. */ + ofpbuf_init(&actions, 64); + ct_start = nl_msg_start_nested(&actions, OVS_ACTION_ATTR_CT); + /* Eventmask has no effect without the commit flag, but currently the + * datapath will accept an eventmask even without commit. This is useful + * as we do not want to persist the probe connection in the conntrack + * table. */ + nl_msg_put_u32(&actions, OVS_CT_ATTR_EVENTMASK, ~0); + nl_msg_end_nested(&actions, ct_start); + + /* Compose a dummy UDP packet. */ + dp_packet_init(&packet, 0); + flow_compose(&packet, &flow); + + /* Execute the actions. On older datapaths this fails with EINVAL, on + * newer datapaths it succeeds. */ + execute.actions = actions.data; + execute.actions_len = actions.size; + execute.packet = &packet; + execute.flow = &flow; + execute.needs_help = false; + execute.probe = true; + execute.mtu = 0; + + error = dpif_execute(backer->dpif, &execute); + + dp_packet_uninit(&packet); + ofpbuf_uninit(&actions); + + if (error) { + VLOG_INFO("%s: Datapath does not support eventmask in conntrack action", + dpif_name(backer->dpif)); + } else { + VLOG_INFO("%s: Datapath supports eventmask in conntrack action", + dpif_name(backer->dpif)); + } + + return !error; +} + #define CHECK_FEATURE__(NAME, SUPPORT, FIELD, VALUE) \ static bool \ check_##NAME(struct dpif_backer *backer) \ @@ -1300,6 +1361,7 @@ check_support(struct dpif_backer *backer) backer->support.tnl_push_pop = dpif_supports_tnl_push_pop(backer->dpif); backer->support.clone = check_clone(backer); backer->support.sample_nesting = check_max_sample_nesting(backer); + backer->support.ct_eventmask = check_ct_eventmask(backer); /* Flow fields. */ backer->support.odp.ct_state = check_ct_state(backer); diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 81a0bdf..1fe2e25 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -174,7 +174,10 @@ struct group_dpif *group_dpif_lookup(struct ofproto_dpif *, DPIF_SUPPORT_FIELD(bool, clone, "Clone action") \ \ /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */\ - DPIF_SUPPORT_FIELD(size_t, sample_nesting, "Sample nesting") + DPIF_SUPPORT_FIELD(size_t, sample_nesting, "Sample nesting") \ + \ + /* OVS_CT_ATTR_EVENTMASK supported by OVS_ACTION_ATTR_CT action. */ \ + DPIF_SUPPORT_FIELD(bool, ct_eventmask, "Conntrack eventmask") /* Stores the various features which the corresponding backer supports. */ struct dpif_backer_support {