src: complete meta priority support
Pablo Neira Ayuso
maintainerPATCH 1/2 src: complete meta priority support
This patch adds the missing bits to scan and parse the meta priority string. The output code to list it has been also reworked.
To match the skbuff priority you can use:
nft add rule filter forward meta priority :ffff nft add rule filter forward meta priority ffff:
nft add rule filter forward meta priority abcd:1234
and to set it, you can use:
nft add rule filter forward meta priority set abcd:1234
flex performs longest prefix matching when scanning patterns so there is not conflict with IPv6 addresses.
There's still a possible clash with:
nft add rule filter input tcp dport vmap { 25:accept, 28:drop }where "25:acce" and "28:d" are interpreted as a meta priority.
I think it's reasonable to tell people that they have to separate the key and the data that represent the element tuple with a whitespace separator between the colon, at least until we find a better way to handle this.
---
@Patrick: You proposed an alternative to this time ago:
http://patchwork.ozlabs.org/patch/320066/
but after applying a similar patch here, that seem to break many other stuff according to the nft-test.py regression tests.
src/meta.c | 33 +++++++++++++------------------- src/scanner.l | 44 +++++++++++++++++++++++++++++++++++++++++++ tests/regression/any/meta.t | 21 ++++++++++++--------- tests/regression/inet/tcp.t | 3 +-- 4 files changed, 70 insertions(+), 31 deletions(-)
src/meta.c +13 -20
@@ -10,6 +10,7 @@* Development of this code funded by Astaro AG (http://www.astaro.com/) */ +#include <errno.h> #include <stddef.h> #include <stdlib.h> #include <stdio.h>
@@ -71,9 +72,11 @@ static void tchandle_type_print(const struct expr *expr)switch (handle) {case TC_H_ROOT : -printf ("root\n" ); +printf ("root" ); +break ;case TC_H_UNSPEC : -printf ("none\n" ); +printf ("none" ); +break ;default :if (TC_H_MAJ (handle) ==0 )printf (":%04x" ,TC_H_MIN (handle));
@@ -92,40 +95,30 @@ static struct error_record *tchandle_type_parse(const struct expr *sym, {uint32_t handle; -if (strcmp (sym->identifier,"root" ) ==0 ) +if (strcmp (sym->identifier,"root" ) ==0 ) { handle =TC_H_ROOT ; -else if (strcmp (sym->identifier,"none" ) ==0 ) + }else if (strcmp (sym->identifier,"none" ) ==0 ) { handle =TC_H_UNSPEC ; -else if (sym->identifier[0 ] ==':' ) { -if (sscanf (sym->identifier,":%04x" , &handle) <0 ) - goto err; - }else if (sym->identifier[strlen (sym->identifier)-1 ] ==':' ) { -if (sscanf (sym->identifier,"%04x:" , &handle) <0 ) - goto err; - - handle <<=16 ; }else { -uint32_t min, max; - -if (sscanf (sym->identifier,"%04x:%04x" , &min, &max) <0 ) + errno =0 ; + handle =strtoul (sym->identifier,NULL ,0 ); +if (errno !=0 ) goto err; - - handle = max <<16 | min; } + *res =constant_expr_alloc (&sym->location, sym->dtype,BYTEORDER_HOST_ENDIAN ,sizeof (handle) *BITS_PER_BYTE , &handle);return NULL ; err: -return error (&sym->location,"Could not parse %s" , - sym->dtype->desc); +return error (&sym->location,"Could not parse %s" , sym->dtype->desc); }static const struct datatype tchandle_type = { .type =TYPE_TC_HANDLE , .name ="tc_handle" , .desc ="TC handle" , - .byteorder =BYTEORDER_BIG_ENDIAN , + .byteorder =BYTEORDER_HOST_ENDIAN , .size =4 *BITS_PER_BYTE , .basetype = &integer_type, .print = tchandle_type_print,
src/scanner.l +44 -0
56 lines not on this page · raw message
tests/regression/any/meta.t +12 -9
@@ -34,15 +34,18 @@ meta l4proto { 33, 55, 67, 88};ok;meta l4proto { 33, 55, 67, 88} meta l4proto { 33-55};ok - meta l4proto != { 33-55};ok -- meta priority :aabb;ok -- meta priority bcad:dadc;ok -- meta priority aabb:;ok -- meta priority != :aabb;ok -- meta priority != bcad:dadc;ok -- meta priority != aabb:;ok -- meta priority bcad:dada-bcad:dadc;ok -- meta priority != bcad:dada-bcad:dadc;ok -- meta priority {bcad:dada, bcad:dadc, aaaa:bbbb};ok +meta priority root;ok +meta priority none;ok +meta priority :aabb;ok +meta priority bcad:dadc;ok +meta priority aabb:;ok +meta priority != :aabb;ok +meta priority != bcad:dadc;ok +meta priority != aabb:;ok +meta priority bcad:dada-bcad:dadc;ok +meta priority != bcad:dada-bcad:dadc;ok +meta priority {bcad:dada, bcad:dadc, aaaa:bbbb};ok +meta priority set cafe:beef;ok - meta priority != {bcad:dada, bcad:dadc, aaaa:bbbb};ok meta mark 0x4;ok;mark 0x00000004
tests/regression/inet/tcp.t +1 -2
@@ -13,7 +13,6 @@ tcp dport { 33-55};ok - tcp dport != { 33-55};ok tcp dport {telnet, http, https} accept;ok;tcp dport { 443, 23, 80} accept tcp dport vmap { 22 : accept, 23 : drop };ok -tcp dport vmap { 25:accept, 28:drop };ok tcp dport { 22, 53, 80, 110 };ok - tcp dport != { 22, 53, 80, 110 };ok # BUG: invalid expression type set
@@ -27,7 +26,7 @@ tcp sport { 33, 55, 67, 88};ok - tcp sport != { 33, 55, 67, 88};ok tcp sport { 33-55};ok - tcp sport != { 33-55};ok -tcp sport vmap { 25:accept, 28:drop };ok +tcp sport vmap { 25 : accept, 28 : drop };ok tcp sport 8080 drop;ok tcp sport 1024 tcp dport 22;ok
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/2 main: display errors and debugging through stderr
--- src/evaluate.c | 6 +++--- src/main.c | 2 +- src/mnl.c | 4 ++-- src/netlink.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-)
src/evaluate.c +3 -3
@@ -1067,7 +1067,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &(*expr)->location,"Evaluate" ); -erec_print (stdout, erec);expr_print (*expr);printf ("\n\n" ); +erec_print (stderr, erec);expr_print (*expr);printf ("\n\n" ); }#endif
@@ -1652,7 +1652,7 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &stmt->location,"Evaluate" ); -erec_print (stdout, erec);stmt_print (stmt);printf ("\n\n" ); +erec_print (stderr, erec);stmt_print (stmt);printf ("\n\n" ); }#endif
@@ -1951,7 +1951,7 @@ int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &cmd->location,"Evaluate" ); -erec_print (stdout, erec);printf ("\n\n" ); +erec_print (stderr, erec);printf ("\n\n" ); }#endif
src/main.c +1 -1
@@ -361,7 +361,7 @@ int main(int argc, char * const *argv) rc =NFT_EXIT_FAILURE ; out:scanner_destroy (scanner); -erec_print_list (stdout, &msgs); +erec_print_list (stderr, &msgs);xfree (buf);return rc;
src/mnl.c +2 -2
@@ -72,7 +72,7 @@ nft_mnl_talk(struct mnl_socket *nf_sock, const void *data, unsigned int len,#ifdef DEBUG if (debug_level &DEBUG_MNL ) -mnl_nlmsg_fprintf (stdout, data, len,sizeof (struct nfgenmsg )); +mnl_nlmsg_fprintf (stderr, data, len,sizeof (struct nfgenmsg ));#endif if (mnl_socket_sendto (nf_sock, data, len) <0 )
@@ -283,7 +283,7 @@ static ssize_t mnl_nft_socket_sendmsg(const struct mnl_socket *nl) i++;#ifdef DEBUG if (debug_level &DEBUG_MNL ) { -mnl_nlmsg_fprintf (stdout, +mnl_nlmsg_fprintf (stderr,mnl_nlmsg_batch_head (batch_page->batch),mnl_nlmsg_batch_size (batch_page->batch),sizeof (struct nfgenmsg ));
src/netlink.c +5 -5
@@ -410,7 +410,7 @@ void netlink_dump_rule(struct nft_rule *nlr)return ;nft_rule_snprintf (buf,sizeof (buf), nlr,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }
@@ -423,7 +423,7 @@ void netlink_dump_expr(struct nft_rule_expr *nle)return ;nft_rule_expr_snprintf (buf,sizeof (buf), nle,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }
@@ -487,7 +487,7 @@ void netlink_dump_chain(struct nft_chain *nlc)return ;nft_chain_snprintf (buf,sizeof (buf), nlc,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }
@@ -872,7 +872,7 @@ void netlink_dump_table(struct nft_table *nlt)return ;nft_table_snprintf (buf,sizeof (buf), nlt,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }
@@ -983,7 +983,7 @@ void netlink_dump_set(struct nft_set *nls)return ;nft_set_snprintf (buf,sizeof (buf), nls,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }
Signature · 1 line
1.7.10.4
Re: [PATCH nft 2/2] main: display errors and debugging through stderr
Quoted 1 line · Pablo Neira Ayuso
I agree for errors, but actually not for debugging. It can be considered regular output since it was explicitly requested.
Quoted 126 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>--- src/evaluate.c | 6 +++--- src/main.c | 2 +- src/mnl.c | 4 ++-- src/netlink.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-)src/evaluate.c +3
-3@@ -1067,7 +1067,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &(*expr)->location,"Evaluate" ); -erec_print (stdout, erec);expr_print (*expr);printf ("\n\n" ); +erec_print (stderr, erec);expr_print (*expr);printf ("\n\n" ); }#endif @@ -1652,7 +1652,7 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &stmt->location,"Evaluate" ); -erec_print (stdout, erec);stmt_print (stmt);printf ("\n\n" ); +erec_print (stderr, erec);stmt_print (stmt);printf ("\n\n" ); }#endif @@ -1951,7 +1951,7 @@ int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)if (debug_level &DEBUG_EVALUATION ) {struct error_record *erec; erec =erec_create (EREC_INFORMATIONAL , &cmd->location,"Evaluate" ); -erec_print (stdout, erec);printf ("\n\n" ); +erec_print (stderr, erec);printf ("\n\n" ); }#endif src/main.c +1
-1@@ -361,7 +361,7 @@ int main(int argc, char * const *argv) rc =NFT_EXIT_FAILURE ; out:scanner_destroy (scanner); -erec_print_list (stdout, &msgs); +erec_print_list (stderr, &msgs);xfree (buf);return rc;src/mnl.c +2
-2@@ -72,7 +72,7 @@ nft_mnl_talk(struct mnl_socket *nf_sock, const void *data, unsigned int len,#ifdef DEBUG if (debug_level &DEBUG_MNL ) -mnl_nlmsg_fprintf (stdout, data, len,sizeof (struct nfgenmsg )); +mnl_nlmsg_fprintf (stderr, data, len,sizeof (struct nfgenmsg ));#endif if (mnl_socket_sendto (nf_sock, data, len) <0 )@@ -283,7 +283,7 @@ static ssize_t mnl_nft_socket_sendmsg(const struct mnl_socket *nl) i++;#ifdef DEBUG if (debug_level &DEBUG_MNL ) { -mnl_nlmsg_fprintf (stdout, +mnl_nlmsg_fprintf (stderr,mnl_nlmsg_batch_head (batch_page->batch),mnl_nlmsg_batch_size (batch_page->batch),sizeof (struct nfgenmsg ));src/netlink.c +5
-5@@ -410,7 +410,7 @@ void netlink_dump_rule(struct nft_rule *nlr)return ;nft_rule_snprintf (buf,sizeof (buf), nlr,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }@@ -423,7 +423,7 @@ void netlink_dump_expr(struct nft_rule_expr *nle)return ;nft_rule_expr_snprintf (buf,sizeof (buf), nle,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }@@ -487,7 +487,7 @@ void netlink_dump_chain(struct nft_chain *nlc)return ;nft_chain_snprintf (buf,sizeof (buf), nlc,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }@@ -872,7 +872,7 @@ void netlink_dump_table(struct nft_table *nlt)return ;nft_table_snprintf (buf,sizeof (buf), nlt,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }@@ -983,7 +983,7 @@ void netlink_dump_set(struct nft_set *nls)return ;nft_set_snprintf (buf,sizeof (buf), nls,0 ,0 ); -fprintf (stdout,"%s\n" , buf); +fprintf (stderr,"%s\n" , buf);#endif }Signature · 1 line
1.7.10.4
Quoted 18 lines · Pablo Neira Ayuso
This patch adds the missing bits to scan and parse the meta priority string. The output code to list it has been also reworked.
To match the skbuff priority you can use:
nft add rule filter forward meta priority :ffff nft add rule filter forward meta priority ffff:
nft add rule filter forward meta priority abcd:1234and to set it, you can use:
nft add rule filter forward meta priority set abcd:1234
flex performs longest prefix matching when scanning patterns so there is not conflict with IPv6 addresses.
There's still a possible clash with:
Quoted 8 lines
nft add rule filter input tcp dport vmap { 25:accept, 28:drop }where "25:acce" and "28:d" are interpreted as a meta priority.
I think it's reasonable to tell people that they have to separate the key and the data that represent the element tuple with a whitespace separator between the colon, at least until we find a better way to handle this.
I agree that it's not too bad, but still would be preferable to avoid this.
Quoted 8 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>---
@Patrick: You proposed an alternative to this time ago:http://patchwork.ozlabs.org/patch/320066/
but after applying a similar patch here, that seem to break many other stuff according to the
nft-test.pyregression tests.
Out of interest, what does it break?