conntrack: permit updating only a part of the ctmark
Florian Westphal
maintainercover conntrack: permit updating only a part of the ctmark
Hello Pablo,
here are two patches for conntrack(8).
I want to alter the upper 8 bits of the conntrack mark while keeping the rest intact. At the moment it is only possible to specifiy an absolute value, so i've extended --mark to optionally handle a mask argument. Its possible to either filter by mark (e.g. list conntracks with a particular mark bit set) or to update parts of the mark.
The 2nd patch is not absolutely needed, but it speeds up operation when only a couple of conntracks are affected by the modification.
Thanks,
Florian
Florian Westphal
maintainerPATCH 1/2 conntrack: add support for mark mask
Extend --mark option to optionally take a mask, seperated by '/', e.g. --mark 0x80/0xf0.
When used with -L, only test those bits of the mark that are in the mask range (behaves like iptables like -m mark).
When used with -U, zero out those bits indicated by the mask and XOR the new mark into the result (behaves like iptables -j MARK --set-xmark).
--- conntrack.8 | 8 +++++- src/conntrack.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-)
conntrack.8 +6 -2
@@ -135,8 +135,12 @@ This option is only required in conjunction with "-L, --dump". If this option is .BI "-t, --timeout " "TIMEOUT" Specify the timeout. .TP -.BI "-m, --mark " "MARK" -Specify the conntrack mark. +.BI "-m, --mark " "MARK[/MASK]" +Specify the conntrack mark. Optionally, a mask value can be specified. +In "--update" mode, this mask specifies the bits that should be zeroed before XORing +the MARK value into the ctmark. +Otherwise, the mask is logically ANDed with the existing mark before the comparision. +In "--create" mode, the mask is ignored. .TP .BI "-c, --secmark " "SECMARK" Specify the conntrack selinux security mark.
src/conntrack.c +67 -1
151 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Florian Westphal
maintainerPATCH 2/2 conntrack: -U: skip sending conntrack update message if conntrack is unchanged
In reply to Florian WestphalThis speeds up operation when a lot of conntracks exist, but only a few of them have to be altered.
This change is user-visible because the exit message
("%d flow entries have been updated") will now print the number of entries that have been altered instead of the total number of conntracks seen.
--- src/conntrack.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
src/conntrack.c +6 -0
@@ -1258,6 +1258,12 @@ static int update_cb(enum nf_conntrack_msg_type type,nfct_copy (tmp, obj,NFCT_CP_META );copy_mark (tmp, ct, &tmpl.mark); +/* do not send NFCT_Q_UPDATE if ct appears unchanged */ +if (nfct_cmp (tmp, ct,NFCT_CMP_ALL |NFCT_CMP_MASK )) { +nfct_destroy (tmp); +return NFCT_CB_CONTINUE ; + } + res =nfct_query (ith,NFCT_Q_UPDATE , tmp);if (res <0 ) {nfct_destroy (tmp);
Signature · 1 line
1.7.3.4
Pablo Neira Ayuso
maintainerQuoted 11 lines · Florian Westphal
Hello Pablo,
here are two patches for conntrack(8).
I want to alter the upper 8 bits of the conntrack mark while keeping the rest intact. At the moment it is only possible to specifiy an absolute value, so i've extended --mark to optionally handle a mask argument. Its possible to either filter by mark (e.g. list conntracks with a particular mark bit set) or to update parts of the mark.
Quoted 2 lines
The 2nd patch is not absolutely needed, but it speeds up operation when only a couple of conntracks are affected by the modification.
I like them both, I've applied them.
Would you send me another patch for the qa/testsuite/ to include some test to check that --mark works with absolute value and masks?
Thank you.
Florian Westphal
maintainerQuoted 4 lines · Pablo Neira Ayuso
I like them both, I've applied them.
Would you send me another patch for the qa/testsuite/ to include some test to check that --mark works with absolute value and masks?
Sure, I'll get to this later tonight.
Thanks,
Florian