kernel: add minimal TCP state tracking to flow offload support
[openwrt/staging/mkresin.git] / target / linux / generic / backport-4.14 / 363-netfilter-nf_flow_table-add-support-for-sending-flow.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sun, 25 Feb 2018 15:41:11 +0100
3 Subject: [PATCH] netfilter: nf_flow_table: add support for sending flows
4 back to the slow path
5
6 Reset the timeout. For TCP, also set the state to indicate to use the
7 next incoming packets to reset window tracking.
8 This allows the slow path to take over again once the offload state has
9 been torn down
10
11 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 ---
13
14 --- a/net/netfilter/nf_flow_table_core.c
15 +++ b/net/netfilter/nf_flow_table_core.c
16 @@ -100,6 +100,36 @@ err_ct_refcnt:
17 }
18 EXPORT_SYMBOL_GPL(flow_offload_alloc);
19
20 +static void flow_offload_fixup_ct_state(struct nf_conn *ct)
21 +{
22 + const struct nf_conntrack_l4proto *l4proto;
23 + struct net *net = nf_ct_net(ct);
24 + unsigned int *timeouts;
25 + unsigned int timeout;
26 + int l4num;
27 +
28 + l4num = nf_ct_protonum(ct);
29 + l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), l4num);
30 + if (!l4proto)
31 + return;
32 +
33 + timeouts = l4proto->get_timeouts(net);
34 + if (!timeouts)
35 + return;
36 +
37 + if (l4num == IPPROTO_TCP) {
38 + timeout = timeouts[TCP_CONNTRACK_ESTABLISHED];
39 + ct->proto.tcp.state = TCP_CONNTRACK_IGNORE;
40 + } else if (l4num == IPPROTO_UDP) {
41 + timeout = timeouts[UDP_CT_REPLIED];
42 + } else {
43 + return;
44 + }
45 +
46 + ct->timeout = nfct_time_stamp + timeout;
47 + clear_bit(IPS_OFFLOAD_BIT, &ct->status);
48 +}
49 +
50 void flow_offload_free(struct flow_offload *flow)
51 {
52 struct flow_offload_entry *e;
53 @@ -107,7 +137,10 @@ void flow_offload_free(struct flow_offlo
54 dst_release(flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.dst_cache);
55 dst_release(flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_cache);
56 e = container_of(flow, struct flow_offload_entry, flow);
57 - nf_ct_delete(e->ct, 0, 0);
58 + if (flow->flags & FLOW_OFFLOAD_DYING)
59 + nf_ct_delete(e->ct, 0, 0);
60 + else
61 + flow_offload_fixup_ct_state(e->ct);
62 nf_ct_put(e->ct);
63 kfree_rcu(e, rcu_head);
64 }