Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2695063ybl; Thu, 29 Aug 2019 11:35:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1yXX+hGvcU2QzqoWp9NwFUzx9HrQqwKBKQO2mFGtjKsGhrHbtgtxGleDHS36AiaewlC9n X-Received: by 2002:a17:90a:26ac:: with SMTP id m41mr11481421pje.59.1567103707831; Thu, 29 Aug 2019 11:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103707; cv=none; d=google.com; s=arc-20160816; b=svRlgi63779ilFL53CnlPJO3Qt2dcWlRQUwmOd9AKPRAn40vYPNeV2p5UBkOIiPvD4 IN/biXyBAcyIrsMuUYnOwk4bz6bJ0p1dK8cwmM8HiVtUk87WKWYGw2XBEzjTnsWdoqup +vG7T/OPaETrOjk6j2MU4RxjURkfY+U6bLVvz6d9cd/0qihuYDRG1e9rgeUz1/1IN1Qx zlQ7mn3H4KUd2JY8N+/4zwnwUCtoqszntMswrah8NYjbhMNGcXjZnL6mp10gu4WLfAN2 v4cjCcc5Ir8lVF1km1FmVmCn14h0PXnAzxzOi0U8gvVJfT5QwYbrGU4hjXR7uOwAhKGE cgjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6812fHPVamtRlRIOsFR9iLGiKJNHAELlcoqhDgM/5m4=; b=i+FMbpWNpmRH68LZW7gOf8wIGbgJVe7j5V4jKwViFM/vt5M9Vpl3sPoI7v+0Lymd6m nu+LD4siioKuvSsjGIQJJdeWnriNK6izgS7D3M4/awBtiqrVXz1tuM+azgCoN+mlJ/iY Qm79EGfUlvEJ82kTZmpH2PIhz2aqRsbcp+ViZOhUZaZvDM14Jb3aY2WlRMUOGrWefKgF /7Iqia6ooqCzqecMLzqgy66ISBoUC1pF20UVv260hVT0xSMXut9e5b0rEaWiFI1+KcFs pnzVGYYVNuLJJ+pWaHSUV3FswKEPvdeYOjvgSLVGyoYsba4gN1IiH9L0BwgBbc1Ap/xR rOIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RYFFzKXc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o9si3594213pfp.158.2019.08.29.11.34.52; Thu, 29 Aug 2019 11:35:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RYFFzKXc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729539AbfH2SeA (ORCPT + 99 others); Thu, 29 Aug 2019 14:34:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:55342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728330AbfH2SNi (ORCPT ); Thu, 29 Aug 2019 14:13:38 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E7B102339E; Thu, 29 Aug 2019 18:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102416; bh=vm7PlOFMrhdiuuOeVzjw28rou+yhF1NIk/jyUsin+3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYFFzKXc19SD4IH1cfJCE/ozlcj/nuKaYQHjk3aO/e0+5lRjLFOQvy/Qd/M1iRH9I hfr8e66JGWgSiVTzaz2TmgwkZ4yFmJh5OApGORUH31194UOTsuay4bLXGlQ8jNBTHE 66C6dJmbzkTfYfQ7d72bugbXInAMkIlu/WATc/EM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pablo Neira Ayuso , Sasha Levin , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 11/76] netfilter: nf_flow_table: conntrack picks up expired flows Date: Thu, 29 Aug 2019 14:12:06 -0400 Message-Id: <20190829181311.7562-11-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit 3e68db2f6422d711550a32cbc87abd97bb6efab3 ] Update conntrack entry to pick up expired flows, otherwise the conntrack entry gets stuck with the internal offload timeout (one day). The TCP state also needs to be adjusted to ESTABLISHED state and tracking is set to liberal mode in order to give conntrack a chance to pick up the expired flow. Fixes: ac2a66665e23 ("netfilter: add generic flow table infrastructure") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_flow_table_core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 948b4ebbe3fbd..4254e42605135 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -112,7 +112,7 @@ static void flow_offload_fixup_tcp(struct ip_ct_tcp *tcp) #define NF_FLOWTABLE_TCP_PICKUP_TIMEOUT (120 * HZ) #define NF_FLOWTABLE_UDP_PICKUP_TIMEOUT (30 * HZ) -static void flow_offload_fixup_ct_state(struct nf_conn *ct) +static void flow_offload_fixup_ct(struct nf_conn *ct) { const struct nf_conntrack_l4proto *l4proto; unsigned int timeout; @@ -209,6 +209,11 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow) } EXPORT_SYMBOL_GPL(flow_offload_add); +static inline bool nf_flow_has_expired(const struct flow_offload *flow) +{ + return (__s32)(flow->timeout - (u32)jiffies) <= 0; +} + static void flow_offload_del(struct nf_flowtable *flow_table, struct flow_offload *flow) { @@ -224,6 +229,9 @@ static void flow_offload_del(struct nf_flowtable *flow_table, e = container_of(flow, struct flow_offload_entry, flow); clear_bit(IPS_OFFLOAD_BIT, &e->ct->status); + if (nf_flow_has_expired(flow)) + flow_offload_fixup_ct(e->ct); + flow_offload_free(flow); } @@ -234,7 +242,7 @@ void flow_offload_teardown(struct flow_offload *flow) flow->flags |= FLOW_OFFLOAD_TEARDOWN; e = container_of(flow, struct flow_offload_entry, flow); - flow_offload_fixup_ct_state(e->ct); + flow_offload_fixup_ct(e->ct); } EXPORT_SYMBOL_GPL(flow_offload_teardown); @@ -299,11 +307,6 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table, return err; } -static inline bool nf_flow_has_expired(const struct flow_offload *flow) -{ - return (__s32)(flow->timeout - (u32)jiffies) <= 0; -} - static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data) { struct nf_flowtable *flow_table = data; -- 2.20.1