conntrack: support multiple -l options
Florian Westphal
maintainerPATCH 1/3 conntrack: support multiple -l options
Using -l foo -l bar caused the "foo" label to be lost.
Merge multiple -l options so "-l foo,bar" and "-l foo -l bar" have same effect.
---
Change since v1:
retain old -l "foo,bar" syntax
make of "-l foo -l bar,baz" work
conntrack.8 | 7 ++++--- src/conntrack.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-)
conntrack.8 +4 -3
@@ -144,10 +144,11 @@ 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 "-l, --label " "LABEL,..." -Specify the conntrack labels. +.BI "-l, --label " "LABEL" +Specify a conntrack label. This option is only available in conjunction with "-L, --dump" or "-E, --event". -Match entries whose labels matches at least those specified as arguments. +Match entries whose labels match at least those specified. +Use multiple -l commands to specify multiple labels that need to be set. .TP .BI "-c, --secmark " "SECMARK" Specify the conntrack selinux security mark.
src/conntrack.c +28 -1
@@ -1828,6 +1828,31 @@ static void labelmap_init(void)perror ("nfct_labelmap_new" ); } +static void merge_bitmasks (struct nfct_bitmask **current, +struct nfct_bitmask *src) +{ +unsigned int i; + +if (*current ==NULL ) { + *current = src; +return ; + } + +/* "current" must be the larger bitmask object */ +if (nfct_bitmask_maxbit (src) >nfct_bitmask_maxbit (*current)) { +struct nfct_bitmask *tmp = *current; + *current = src; + src = tmp; + } + +for (i =0 ; i <=nfct_bitmask_maxbit (src); i++) { +if (nfct_bitmask_test_bit (src, i)) +nfct_bitmask_set_bit (*current, i); + } + +nfct_bitmask_destroy (src); +} +int main (int argc,char *argv[]) {int c, cmd;
@@ -2030,7 +2055,9 @@ int main(int argc, char *argv[])struct nfct_bitmask * b =nfct_bitmask_new (max);parse_label (b, optarg2); - tmpl.label = b; + +/* join "-l foo -l bar" into single bitmask object */ +merge_bitmasks (&tmpl.label, b);free (optarg2);break ;case 'a' :
Signature · 1 line
1.7.8.6
Florian Westphal
maintainerPATCH 2/3 conntrack: support add/delete of conntrack labels
From: Clemence Faure <[email protected]>
new options "--label-add" and "--label-delete" to alter connlabels assigned to a connection.
---
Change since v1:
make "--create --add-label foo" work again
conntrack.8 | 10 +++- include/conntrack.h | 2 +- src/conntrack.c | 154 +++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 140 insertions(+), 26 deletions(-)
conntrack.8 +9 -1
@@ -146,9 +146,17 @@ In "--create" mode, the mask is ignored. .TP .BI "-l, --label " "LABEL" Specify a conntrack label. -This option is only available in conjunction with "-L, --dump" or "-E, --event". +This option is only available in conjunction with "-L, --dump", "-E, --event", or "-U --update". Match entries whose labels match at least those specified. Use multiple -l commands to specify multiple labels that need to be set. +Match entries whose labels matches at least those specified as arguments. +.BI "--label-add " "LABEL" +Specify the conntrack label to add to to the selected conntracks. +This option is only available in conjunction with "-I, --create" or "-U, --update". +.BI "--label-del " "[LABEL]" +Specify the conntrack label to delete from the selected conntracks. +If no label is given, all labels are deleted. +This option is only available in conjunction with "-U, --update". .TP .BI "-c, --secmark " "SECMARK" Specify the conntrack selinux security mark.
include/conntrack.h +1 -1
@@ -10,7 +10,7 @@#include <netinet/in.h> #define NUMBER_OF_CMD 19 -#define NUMBER_OF_OPT 25 +#define NUMBER_OF_OPT 27struct ctproto_handler {struct list_head head;
src/conntrack.c +130 -24
265 lines not on this page · raw message
Signature · 1 line
1.7.8.6
Florian Westphal
maintainerPATCH 3/3 conntrack: do not exit when update returns an error
In reply to Florian WestphalIf we fail to update an entry, just try to continue with the next one instead of exiting.
Can happen f.e. when using "conntrack -U --add-label bla", but the conntrack entry in the kernel does not have the label extension set.
--- src/conntrack.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
src/conntrack.c +3 -5
@@ -1492,12 +1492,10 @@ static int update_cb(enum nf_conntrack_msg_type type, } res =nfct_query (ith,NFCT_Q_UPDATE , tmp); -if (res <0 ) { -nfct_destroy (tmp); -exit_error (OTHER_PROBLEM , -"Operation failed: %s" , +if (res <0 ) +fprintf (stderr, +"Operation failed: %s\n" ,err2str (errno,CT_UPDATE )); - }nfct_callback_register (ith,NFCT_T_ALL , print_cb,NULL ); res =nfct_query (ith,NFCT_Q_GET , tmp);
Signature · 1 line
1.7.8.6