History

netfilter: kill the fake untracked conntrack objects

resurrect an old patch from Pablo Neira to remove the untracked objects. Currently, there are four possible states of an skb wrt. conntrack. 1. No conntrack attached, ct is NULL. 2. Normal (kmem cache allocated) ct attached. 3. a template (kmalloc'd), not in any hash tables at any point in time 4. the 'untracked' conntrack, a percpu nf_conn object, tagged via IPS_UNTRACKED_BIT in ct->status. Untracked is supposed to be identical to case 1. It exists only so users can check -m conntrack --ctstate UNTRACKED vs. -m conntrack --ctstate INVALID e.g. attempts to set connmark on INVALID or UNTRACKED conntracks is supposed to be a no-op. Thus currently we need to check ct == NULL || nf_ct_is_untracked(ct) in a lot of places in order to avoid altering untracked objects. The other consequence of the percpu untracked object is that all -j NOTRACK (and, later, kfree_skb of such skbs) result in an atomic op (inc/dec the untracked conntracks refcount). This adds a new kernel-private ctinfo state, IP_CT_UNTRACKED, to make the distinction instead. The (few) places that care about packet invalid (ct is NULL) vs. packet untracked now need to test ct == NULL vs. ctinfo == IP_CT_UNTRACKED, but all other places can omit the nf_ct_is_untracked() check.

Florian Westphal committed 9 years ago

Commit cc41c841 parent 6e354a512 files · +39 −97Browse files

Showing the changes to include/uapi/linux (1 of 12 files). Show all

Unified · Split

include/uapi/linux/netfilter/nf_conntrack_common.h+4−2
@@ -28,12 +28,14 @@ enum ip_conntrack_info { · 27 unmodified lines
2828 /* only for userspace compatibility */
2929 #ifndef __KERNEL__
3030 IP_CT_NEW_REPLY = IP_CT_NUMBER,
31+#else
32+ IP_CT_UNTRACKED = 7,
3133 #endif
3234 };
3335
3436 #define NF_CT_STATE_INVALID_BIT (1 << 0)
3537 #define NF_CT_STATE_BIT(ctinfo) (1 << ((ctinfo) % IP_CT_IS_REPLY + 1))
36−#define NF_CT_STATE_UNTRACKED_BIT (1 << (IP_CT_NUMBER + 1))
38+#define NF_CT_STATE_UNTRACKED_BIT (1 << (IP_CT_UNTRACKED + 1))
3739
3840 /* Bitset representing status of connection. */
3941 enum ip_conntrack_status {
@@ -94,7 +96,7 @@ enum ip_conntrack_status { · 54 unmodified lines
9496 IPS_TEMPLATE_BIT = 11,
9597 IPS_TEMPLATE = (1 << IPS_TEMPLATE_BIT),
9698
97− /* Conntrack is a fake untracked entry */
99+ /* Conntrack is a fake untracked entry. Obsolete and not used anymore */
98100 IPS_UNTRACKED_BIT = 12,
99101 IPS_UNTRACKED = (1 << IPS_UNTRACKED_BIT),
100102