netfilter: nf_tables: include conntrack state in trace messages
Subsystems (2)
Florian Westphal
maintainerv2 cover netfilter: nf_tables: include conntrack state in trace messages
v2:
Address feedback from Pablo: don't reuse nft_ct_keys, but add extra ct_trace attributes. No other changes.
Add the minimal relevant info needed for userspace ("nftables monitor trace") to provide the conntrack view of the packet:
- state (new, related, established)
- direction (original, reply)
- status (e.g., if connection is subject to dnat)
- id (allows to query ctnetlink for remaining conntrack state info)
Example:
trace id a62 inet filter PRE_RAW packet: iif "enp0s3" ether [..]
[..]
trace id a62 inet filter PRE_MANGLE conntrack: ct direction original ct state new ct id 32 trace id a62 inet filter PRE_MANGLE packet: [..]
[..]
trace id a62 inet filter IN conntrack: ct direction original ct state new ct status dnat-done ct id 32
[..]
First patch is a needed prerequisite to avoid a module dependency. Second patch adds the needed info.
Updated patch for libnftnl will follow shortly, the nftables patch doesn't need adjustment: it uses libnftl for all trace accesses.
Florian Westphal (2):
netfilter: conntrack: make nf_conntrack_id callable without a module
dependency
netfilter: nf_tables: add packets conntrack state to debug trace info
include/linux/netfilter.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 8 ++++ net/netfilter/nf_conntrack_core.c | 6 +++ net/netfilter/nf_tables_trace.c | 54 +++++++++++++++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.0
Florian Westphal
maintainerPATCH v2 1/2 netfilter: conntrack: make nf_conntrack_id callable without a module dependency
While nf_conntrack_id() doesn't need any functionaliy from conntrack, it does reside in nf_conntrack_core.c -- callers add a module dependency on conntrack.
Followup patch will need to compute the conntrack id from nf_tables_trace.c to include it in nf_trace messages emitted to userspace via netlink.
I don't want to introduce a module dependency between nf_tables and conntrack for this.
Since trace is slowpath, the added indirection is ok.
One alternative is to move nf_conntrack_id to the netfilter/core.c, but I don't see a compelling reason so far.
---
No changes since v1.
include/linux/netfilter.h | 1 + net/netfilter/nf_conntrack_core.c | 6 ++++++ 2 files changed, 7 insertions(+)
include/linux/netfilter.h +1 -0
@@ -470,6 +470,7 @@ struct nf_ct_hook {void (*attach)(struct sk_buff *nskb,const struct sk_buff *skb);void (*set_closing)(struct nf_conntrack *nfct);int (*confirm)(struct sk_buff *skb); +u32 (*get_id)(const struct nf_conntrack *nfct); };extern const struct nf_ct_hook __rcu *nf_ct_hook;
net/netfilter/nf_conntrack_core.c +6 -0
@@ -505,6 +505,11 @@ u32 nf_ct_get_id(const struct nf_conn *ct) }EXPORT_SYMBOL_GPL (nf_ct_get_id); +static u32 nf_conntrack_get_id (const struct nf_conntrack *nfct) +{ +return nf_ct_get_id (nf_ct_to_nf_conn (nfct)); +} +static void clean_from_lists (struct nf_conn *ct) {
@@ -2710,6 +2715,7 @@ static const struct nf_ct_hook nf_conntrack_hook = { .attach = nf_conntrack_attach, .set_closing = nf_conntrack_set_closing, .confirm = __nf_conntrack_confirm, + .get_id = nf_conntrack_get_id, };void nf_conntrack_init_end (void )
Signature · 1 line
2.49.0
Florian Westphal
maintainerPATCH v2 2/2 netfilter: nf_tables: add packets conntrack state to debug trace info
In reply to Florian WestphalAdd the minimal relevant info needed for userspace ("nftables monitor trace") to provide the conntrack view of the packet:
- state (new, related, established)
- direction (original, reply)
- status (e.g., if connection is subject to dnat)
- id (allows to query ctnetlink for remaining conntrack state info)
Example:
trace id a62 inet filter PRE_RAW packet: iif "enp0s3" ether [..]
[..]
trace id a62 inet filter PRE_MANGLE conntrack: ct direction original ct state new ct id 32 trace id a62 inet filter PRE_MANGLE packet: [..]
[..]
trace id a62 inet filter IN conntrack: ct direction original ct state new ct status dnat-done ct id 32
[..]
In this case one can see that while NAT is active, the new connection isn't subject to a translation.
---
v2: - use flat representation (no NLA_NESTED) and don't use nft_ct_keys.
include/uapi/linux/netfilter/nf_tables.h | 8 ++++ net/netfilter/nf_tables_trace.c | 54 +++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +8 -0
@@ -1841,6 +1841,10 @@ enum nft_xfrm_keys {* @NFTA_TRACE_MARK: nfmark (NLA_U32) * @NFTA_TRACE_NFPROTO: nf protocol processed (NLA_U32) * @NFTA_TRACE_POLICY: policy that decided fate of packet (NLA_U32) +* @NFTA_TRACE_CT_ID: conntrack id (NLA_U32) +* @NFTA_TRACE_CT_DIRECTION: packets direction (NLA_U8) +* @NFTA_TRACE_CT_STATUS: conntrack status (NLA_U32) +* @NFTA_TRACE_CT_STATE: packet state (new, established, ...) (NLA_U32) */ enum nft_trace_attributes {NFTA_TRACE_UNSPEC ,
@@ -1861,6 +1865,10 @@ enum nft_trace_attributes {NFTA_TRACE_NFPROTO ,NFTA_TRACE_POLICY ,NFTA_TRACE_PAD , +NFTA_TRACE_CT_ID , +NFTA_TRACE_CT_DIRECTION , +NFTA_TRACE_CT_STATUS , +NFTA_TRACE_CT_STATE , __NFTA_TRACE_MAX };#define NFTA_TRACE_MAX (__NFTA_TRACE_MAX - 1)
net/netfilter/nf_tables_trace.c +53 -1
78 lines not on this page · raw message
Signature · 1 line
2.49.0