queue: More compact syntax
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 queue: More compact syntax
This patch allows to use a new syntax more compact and break the current syntax. This new syntax is more similar than the nftables syntax that we use usually. We can use range like we have used in other case in nftables. Here, we have some examples:
Before, If we want to declare a queue, we have used a syntax like this:
nft add rule test input queue num 1 total 3 options bypass,fanout
If we want to use the queue number 1 and the two next (total 3), we use a range in the new syntax, for example:
nft add rule test input queue num 1-3 bypass fanout
Also if we want to use only one queue, the new rules are like:
nft add rule test input queue num 1 //queue 1
or
nft add rule test input queue //queue 0
And if we want to add a specific flags we only need to put what flags we want to use:
nft add rule test input queue bypass
we don't need to use options and the comma for indicating the flags.
---
[changes in v2]
* I have moved the range checking (if the range is well-form) from the linealize to the parser.
include/statement.h | 4 ++-- src/netlink_delinearize.c | 9 ++++++--- src/netlink_linearize.c | 12 +++++++----- src/parser.y | 46 +++++++++++++++++++++++++++++---------------- src/scanner.l | 2 -- src/statement.c | 23 ++++++++--------------- 6 files changed, 53 insertions(+), 43 deletions(-)
include/statement.h +2 -2
@@ -60,8 +60,8 @@ struct nat_stmt {extern struct stmt *nat_stmt_alloc (const struct location *loc);struct queue_stmt { -uint16_t queuenum; -uint16_t queues_total; +uint16_t from; +uint16_t to;uint16_t flags; };
src/netlink_delinearize.c +6 -3
@@ -541,11 +541,14 @@ static void netlink_parse_queue(struct netlink_parse_ctx *ctx, const struct nft_rule_expr *nle) {struct stmt *stmt; +uint16_t range_to; stmt =queue_stmt_alloc (loc); - stmt->queue.queuenum =nft_rule_expr_get_u16 (nle,NFT_EXPR_QUEUE_NUM ); - stmt->queue.queues_total = -nft_rule_expr_get_u16 (nle,NFT_EXPR_QUEUE_TOTAL ); + stmt->queue.from =nft_rule_expr_get_u16 (nle,NFT_EXPR_QUEUE_NUM ); + range_to =nft_rule_expr_get_u16 (nle,NFT_EXPR_QUEUE_TOTAL ); + range_to += stmt->queue.from -1 ; + stmt->queue.to = range_to; + stmt->queue.flags =nft_rule_expr_get_u16 (nle,NFT_EXPR_QUEUE_FLAGS );list_add_tail (&stmt->list, &ctx->rule->stmts); }
src/netlink_linearize.c +7 -5
@@ -683,15 +683,17 @@ static void netlink_gen_queue_stmt(struct netlink_linearize_ctx *ctx, const struct stmt *stmt) {struct nft_rule_expr *nle; +uint16_t total_queues; nle =alloc_nft_expr ("queue" );nft_rule_expr_set_u16 (nle,NFT_EXPR_QUEUE_NUM , - stmt->queue.queuenum); -if (stmt->queue.queues_total) { -nft_rule_expr_set_u16 (nle,NFT_EXPR_QUEUE_TOTAL , - stmt->queue.queues_total); - } + stmt->queue.from); + + total_queues = stmt->queue.to - stmt->queue.from; +nft_rule_expr_set_u16 (nle,NFT_EXPR_QUEUE_TOTAL , + total_queues +1 ); +if (stmt->queue.flags) {nft_rule_expr_set_u16 (nle,NFT_EXPR_QUEUE_FLAGS , stmt->queue.flags);
src/parser.y +30 -16
80 lines not on this page · raw message
src/scanner.l +0 -2
@@ -279,10 +279,8 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "queue" { return QUEUE;} "num" { return QUEUENUM;} -"total" { return QUEUETOTAL;} "bypass" { return QUEUEBYPASS;} "fanout" { return QUEUECPUFANOUT;} -"options" { return OPTIONS;} "limit" { return LIMIT; } "rate" { return RATE; }
src/statement.c +8 -15
@@ -174,21 +174,14 @@ struct stmt *limit_stmt_alloc(const struct location *loc)static void queue_stmt_print (const struct stmt *stmt) { -int one =0 ; - -printf ("queue num %u total %u" , - stmt->queue.queuenum, stmt->queue.queues_total); -if (stmt->queue.flags) -printf (" options " ); -if (stmt->queue.flags &NFT_QUEUE_FLAG_BYPASS ) { -printf ("bypass" ); - one =1 ; - } -if (stmt->queue.flags &NFT_QUEUE_FLAG_CPU_FANOUT ) { -if (one) -printf ("," ); -printf ("fanout" ); - } +printf ("queue num %u" , + stmt->queue.from); +if (stmt->queue.to && stmt->queue.to != stmt->queue.from) +printf ("-%u" , stmt->queue.to); +if (stmt->queue.flags &NFT_QUEUE_FLAG_BYPASS ) +printf (" bypass" ); +if (stmt->queue.flags &NFT_QUEUE_FLAG_CPU_FANOUT ) +printf (" fanout" ); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerQuoted 20 lines · Alvaro Neira Ayuso
This patch allows to use a new syntax more compact and break the current syntax. This new syntax is more similar than the nftables syntax that we use usually. We can use range like we have used in other case in nftables. Here, we have some examples:
Before, If we want to declare a queue, we have used a syntax like this:
nft add rule test input queue num 1 total 3 options bypass,fanout
If we want to use the queue number 1 and the two next (total 3), we use a range in the new syntax, for example:
nft add rule test input queue num 1-3 bypass fanout
Also if we want to use only one queue, the new rules are like:
nft add rule test input queue num 1 //queue 1
or
nft add rule test input queue //queue 0
Quoted 7 lines
And if we want to add a specific flags we only need to put what flags we want to use:
nft add rule test input queue bypass
we don't need to use options and the comma for indicating the flags.
Applied, thanks Álvaro.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html