Skip to content

Commit f87fb66

Browse files
Yenyakaber
authored andcommitted
netfilter: nf_ct_icmp: keep the ICMP ct entries longer
Current conntrack code kills the ICMP conntrack entry as soon as the first reply is received. This is incorrect, as we then see only the first ICMP echo reply out of several possible duplicates as ESTABLISHED, while the rest will be INVALID. Also this unnecessarily increases the conntrackd traffic on H-A firewalls. Make all the ICMP conntrack entries (including the replied ones) last for the default of nf_conntrack_icmp{,v6}_timeout seconds. Signed-off-by: Jan "Yenya" Kasprzak <[email protected]> Signed-off-by: Patrick McHardy <[email protected]>
1 parent 17f2f52 commit f87fb66

File tree

5 files changed

+8
-45
lines changed

5 files changed

+8
-45
lines changed

include/net/netfilter/ipv4/nf_conntrack_icmp.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

include/net/netfilter/ipv6/nf_conntrack_icmpv6.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#ifndef _NF_CONNTRACK_ICMPV6_H
1111
#define _NF_CONNTRACK_ICMPV6_H
12-
#include <asm/atomic.h>
1312

1413
#ifndef ICMPV6_NI_QUERY
1514
#define ICMPV6_NI_QUERY 139
@@ -18,10 +17,4 @@
1817
#define ICMPV6_NI_REPLY 140
1918
#endif
2019

21-
struct nf_ct_icmpv6
22-
{
23-
/* Optimization: when number in == number out, forget immediately. */
24-
atomic_t count;
25-
};
26-
2720
#endif /* _NF_CONNTRACK_ICMPV6_H */

include/net/netfilter/nf_conntrack.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/netfilter/nf_conntrack_dccp.h>
2424
#include <linux/netfilter/nf_conntrack_sctp.h>
2525
#include <linux/netfilter/nf_conntrack_proto_gre.h>
26-
#include <net/netfilter/ipv4/nf_conntrack_icmp.h>
2726
#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
2827

2928
#include <net/netfilter/nf_conntrack_tuple.h>
@@ -34,8 +33,6 @@ union nf_conntrack_proto {
3433
struct nf_ct_dccp dccp;
3534
struct ip_ct_sctp sctp;
3635
struct ip_ct_tcp tcp;
37-
struct ip_ct_icmp icmp;
38-
struct nf_ct_icmpv6 icmpv6;
3936
struct nf_ct_gre gre;
4037
};
4138

net/ipv4/netfilter/nf_conntrack_proto_icmp.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,10 @@ static int icmp_packet(struct nf_conn *ct,
8282
u_int8_t pf,
8383
unsigned int hooknum)
8484
{
85-
/* Try to delete connection immediately after all replies:
86-
won't actually vanish as we still have skb, and del_timer
87-
means this will only run once even if count hits zero twice
88-
(theoretically possible with SMP) */
89-
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
90-
if (atomic_dec_and_test(&ct->proto.icmp.count))
91-
nf_ct_kill_acct(ct, ctinfo, skb);
92-
} else {
93-
atomic_inc(&ct->proto.icmp.count);
94-
nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_icmp_timeout);
95-
}
85+
/* Do not immediately delete the connection after the first
86+
successful reply to avoid excessive conntrackd traffic
87+
and also to handle correctly ICMP echo reply duplicates. */
88+
nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_icmp_timeout);
9689

9790
return NF_ACCEPT;
9891
}
@@ -116,7 +109,6 @@ static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,
116109
nf_ct_dump_tuple_ip(&ct->tuplehash[0].tuple);
117110
return false;
118111
}
119-
atomic_set(&ct->proto.icmp.count, 0);
120112
return true;
121113
}
122114

net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,10 @@ static int icmpv6_packet(struct nf_conn *ct,
9595
u_int8_t pf,
9696
unsigned int hooknum)
9797
{
98-
/* Try to delete connection immediately after all replies:
99-
won't actually vanish as we still have skb, and del_timer
100-
means this will only run once even if count hits zero twice
101-
(theoretically possible with SMP) */
102-
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
103-
if (atomic_dec_and_test(&ct->proto.icmp.count))
104-
nf_ct_kill_acct(ct, ctinfo, skb);
105-
} else {
106-
atomic_inc(&ct->proto.icmp.count);
107-
nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_icmpv6_timeout);
108-
}
98+
/* Do not immediately delete the connection after the first
99+
successful reply to avoid excessive conntrackd traffic
100+
and also to handle correctly ICMP echo reply duplicates. */
101+
nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_icmpv6_timeout);
109102

110103
return NF_ACCEPT;
111104
}
@@ -131,7 +124,6 @@ static bool icmpv6_new(struct nf_conn *ct, const struct sk_buff *skb,
131124
type + 128);
132125
return false;
133126
}
134-
atomic_set(&ct->proto.icmp.count, 0);
135127
return true;
136128
}
137129

0 commit comments

Comments
 (0)