src: add conntrack information to trace monitor mode
Florian Westphal
maintainerPATCH 1/1 src: add conntrack information to trace monitor mode
Upcoming kernel change provides the packets conntrack state in the trace message data.
This allows to see if packet is seen as original or reply, the conntrack state (new, establieshed, related) and the status bits which show if e.g. NAT was applied. Alsoi include conntrack ID so users can use conntrack tool to query the kernel for more information via ctnetlink.
This improves debugging when e.g. packets do not pick up the expected NAT mapping, which could e.g. also happen because of expectations following the NAT binding of the owning conntrack entry.
Example output ("conntrack: " lines are new):
trace id 32 t PRE_RAW packet: iif "enp0s3" ether saddr [..]
trace id 32 t PRE_RAW rule tcp flags syn meta nftrace set 1 (verdict continue)
trace id 32 t PRE_RAW policy accept
trace id 32 t PRE_MANGLE conntrack: ct direction original ct state new ct id 2641368242 trace id 32 t PRE_MANGLE packet: iif "enp0s3" ether saddr [..]
trace id 32 t ct_new_pre rule jump rpfilter (verdict jump rpfilter)
trace id 32 t PRE_MANGLE policy accept
trace id 32 t INPUT conntrack: ct direction original ct state new ct status dnat-done ct id 2641368242 trace id 32 t INPUT packet: iif "enp0s3" [..]
trace id 32 t public_in rule tcp dport 443 accept (verdict accept)
--- src/ct.c | 4 ++ src/netlink.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+)
src/ct.c +4 -0
@@ -98,7 +98,11 @@ static const struct symbol_table ct_status_tbl = { SYMBOL("confirmed", IPS_CONFIRMED), SYMBOL("snat", IPS_SRC_NAT), SYMBOL("dnat", IPS_DST_NAT), + SYMBOL("seq-adjust", IPS_SEQ_ADJUST), + SYMBOL("snat-done", IPS_SRC_NAT_DONE), + SYMBOL("dnat-done", IPS_DST_NAT_DONE), SYMBOL("dying", IPS_DYING), + SYMBOL("fixed-timeout", IPS_FIXED_TIMEOUT),SYMBOL_LIST_END }, };
src/netlink.c +110 -0
122 lines not on this page · raw message
Signature · 1 line
2.49.0
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 11 lines · Florian Westphal
Upcoming kernel change provides the packets conntrack state in the trace message data.
This allows to see if packet is seen as original or reply, the conntrack state (new, establieshed, related) and the status bits which show if e.g. NAT was applied. Alsoi include conntrack ID so users can use conntrack tool to query the kernel for more information via ctnetlink.
This improves debugging when e.g. packets do not pick up the expected NAT mapping, which could e.g. also happen because of expectations following the NAT binding of the owning conntrack entry.
This feature will be present in the next kernel.
Quoted 13 lines
Example output ("conntrack: " lines are new):
trace id 32 t
PRE_RAWpacket: iif "enp0s3" ether saddr [..]
trace id 32 tPRE_RAWrule tcp flags syn meta nftrace set 1 (verdict continue)
trace id 32 tPRE_RAWpolicy accept
trace id 32 tPRE_MANGLEconntrack: ct direction original ct state new ct id 2641368242 trace id 32 tPRE_MANGLEpacket: iif "enp0s3" ether saddr [..]
trace id 32 tct_new_prerule jump rpfilter (verdict jump rpfilter)
trace id 32 tPRE_MANGLEpolicy accept
trace id 32 t INPUT conntrack: ct direction original ct state new ct status dnat-done ct id 2641368242 trace id 32 t INPUT packet: iif "enp0s3" [..]
trace id 32 tpublic_inrule tcp dport 443 accept (verdict accept)
Quoted 1 line
Signed-off-by Florian Westphal <[email protected]>
Comment below.
Quoted 10 lines
--- src/ct.c | 4 ++ src/netlink.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+)src/ct.c +0
-0
src/ct.c static const struct symbol_table ct_status_tbl = { · line 103
Quoted 6 lines
src/ct.c +3
-0@@ -98,7 +98,11 @@ static const struct symbol_table ct_status_tbl = {SYMBOL ("confirmed" ,IPS_CONFIRMED ),SYMBOL ("snat" ,IPS_SRC_NAT ),SYMBOL ("dnat" ,IPS_DST_NAT ), +SYMBOL ("seq-adjust" ,IPS_SEQ_ADJUST ), +SYMBOL ("snat-done" ,IPS_SRC_NAT_DONE ), + SYMBOL("dnat-done", IPS_DST_NAT_DONE),
These will be now exposed through 'ct status' forever, not sure we have a usecase to allow users to match on this.
I know these are exposed through uapi, but I don't have a usecase for them to allow users to match on them.
Maybe it is _not_ worth, those flags have been there since the beginning.
If we go for exposing these flags through ct status, do you think it is possible to provide terse description of these "new flags" in the manpage?
Quoted 10 lines
src/ct.c +1
-0SYMBOL("dying", IPS_DYING), + SYMBOL("fixed-timeout", IPS_FIXED_TIMEOUT),SYMBOL_LIST_END }, };src/netlink.c +0
-0
src/netlink.c next: · line 2121
Quoted 6 lines
src/netlink.c +3
-0@@ -2116,6 +2116,114 @@ next: } } +static struct expr *trace_alloc_list (const struct datatype *dtype, +enum byteorder byteorder, +unsigned int len,const void *data)
Suggestion, not deal breaker: It would be good to start a new src/trace.c file to add this and move tracing infrastructure?
Florian Westphal
maintainerQuoted 10 lines · Pablo Neira Ayuso
src/ct.c static const struct symbol_table ct_status_tbl = { · line 103
Quoted 7 lines
src/ct.c +3
-0@@ -98,7 +98,11 @@ static const struct symbol_table ct_status_tbl = {SYMBOL ("confirmed" ,IPS_CONFIRMED ),SYMBOL ("snat" ,IPS_SRC_NAT ),SYMBOL ("dnat" ,IPS_DST_NAT ), +SYMBOL ("seq-adjust" ,IPS_SEQ_ADJUST ), +SYMBOL ("snat-done" ,IPS_SRC_NAT_DONE ), + SYMBOL("dnat-done", IPS_DST_NAT_DONE),These will be now exposed through 'ct status' forever, not sure we have a usecase to allow users to match on this.
I don't. Its so ct status is pretty printed here:
trace id 32 t INPUT conntrack: ct ... ct status dnat-done ...
I can see if I can somehow restrict this to the trace display side. OTOH I don't see a reason to artificially limit this.
Quoted 2 lines
I know these are exposed through uapi, but I don't have a usecase for them to allow users to match on them.
I don't have that either. But I don't see why we should prevent it.
Quoted 3 lines
If we go for exposing these flags through ct status, do you think it is possible to provide terse description of these "new flags" in the manpage?
Sure, will add.
Quoted 6 lines
Quoted 6 lines
src/netlink.c +0
-0@@ -2116,6 +2116,114 @@ next: } }
Quoted 6 lines
src/netlink.c next: · line 2121
Quoted 3 lines
src/netlink.c +3
-0+static struct expr *trace_alloc_list (const struct datatype *dtype, +enum byteorder byteorder, +unsigned int len,const void *data)Suggestion, not deal breaker: It would be good to start a new
src/trace.cfile to add this and move tracing infrastructure?
OK, let me respin this after splitting the existing stuff to trace.c.
Thanks for reviewing!