From patchwork Tue Apr 25 02:09:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarno Rajahalme X-Patchwork-Id: 754555 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 3wBmrb0wSbz9s2G for ; Tue, 25 Apr 2017 12:10:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C3FD6B63; Tue, 25 Apr 2017 02:09:58 +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 AB442B64 for ; Tue, 25 Apr 2017 02:09:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 85FFA10A for ; Tue, 25 Apr 2017 02:09:55 +0000 (UTC) Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id 66C96C5A43; Tue, 25 Apr 2017 04:09:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id tC-WEjtp5flT; Tue, 25 Apr 2017 04:09:53 +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 relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 624E1C5A4E; Tue, 25 Apr 2017 04:09:52 +0200 (CEST) From: Jarno Rajahalme To: dev@openvswitch.org Date: Mon, 24 Apr 2017 19:09:43 -0700 Message-Id: <1493086183-114264-2-git-send-email-jarno@ovn.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1493086183-114264-1-git-send-email-jarno@ovn.org> References: <1493086183-114264-1-git-send-email-jarno@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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 v2 2/2] datapath: nf_connlabels_replace() backport. 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 Linux 4.7 changed nf_connlabels_replace() to trigger conntrack event for a label change only when the labels actually changed. Without this change an update event is triggered even if the labels already have the values they are being set to. There is no way we can detect this functional change from Linux headers, so provide replacements that work the same for older Linux releases regardless if a distribution provides backports or not. VMware-BZ: #1837218 Signed-off-by: Jarno Rajahalme Acked-by: Joe Stringer --- v2: New for v2. .../include/net/netfilter/nf_conntrack_labels.h | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h b/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h index 5af5a9a..61cf19e 100644 --- a/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h +++ b/datapath/linux/compat/include/net/netfilter/nf_conntrack_labels.h @@ -57,4 +57,49 @@ static inline int nf_connlabels_get(struct net *net, unsigned int bits) static inline void nf_connlabels_put(struct net *net) { } #endif /* CONFIG_NF_CONNTRACK_LABELS */ #endif /* HAVE_NF_CONNLABELS_GET_TAKES_BIT */ + +/* Linux 4.7 introduced a functional change to trigger conntrack event for a + * label change only when the labels actually changed. There is no way we can + * detect this from the headers, so provide replacements that work the same for + * OVS (where labels size is 128 bits == 16 bytes == 4 4-byte words). */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0) +static int replace_u32(u32 *address, u32 mask, u32 new) +{ + u32 old, tmp; + + do { + old = *address; + tmp = (old & mask) ^ new; + if (old == tmp) + return 0; + } while (cmpxchg(address, old, tmp) != old); + + return 1; +} + +static int rpl_nf_connlabels_replace(struct nf_conn *ct, + const u32 *data, + const u32 *mask, unsigned int words32) +{ + struct nf_conn_labels *labels; + unsigned int i; + int changed = 0; + u32 *dst; + + labels = nf_ct_labels_find(ct); + if (!labels) + return -ENOSPC; + + dst = (u32 *) labels->bits; + for (i = 0; i < words32; i++) + changed |= replace_u32(&dst[i], mask ? ~mask[i] : 0, data[i]); + + if (changed) + nf_conntrack_event_cache(IPCT_LABEL, ct); + + return 0; +} +#define nf_connlabels_replace rpl_nf_connlabels_replace +#endif + #endif /* _NF_CONNTRACK_LABELS_WRAPPER_H */