More extensive error checking on base chain
PATCH 1/1 More extensive error checking on base chain
The evaluation of base chain isn't extensive enough. It cannot detect whether a chain type is supported or not in certain families. It also cannot deletect whether a hook is supported or not in certain chains. The evaluation is done by kernel, and the information is unclear.
nft> add chain arp arptable chain1 {type nat hook input priority 0 ;} <cli>:1:1-64: Error: Could not add chain: No such file or directory add chain arp arptable chain1 {type nat hook input priority 0 ;} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nft> add chain ip iptable chain1 {type nat hook forward priority 0 ;} <cli>:1:1-64: Error: Could not add chain: Operation not supported add chain ip iptable chain1 {type nat hook forward priority 0 ;} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This patch performs more extensive error checking, so the information is more clear.
nft> add chain arp arptable chain1 {type nat hook input priority 0 ;} <cli>:1:31-63: Error: invalid type name nat
add chain arp arptable chain1 {type nat hook input priority 0 ;}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add chain ip iptable chain1 {type nat hook forward priority 0 ;}
<cli>:1:29-63: Error: invalid hook name forward
add chain ip iptable chain1 {type nat hook forward priority 0 ;}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- include/rule.h | 2 - src/evaluate.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++---------- src/parser.y | 28 ++------- src/rule.c | 40 ------------ 4 files changed, 168 insertions(+), 98 deletions(-)
include/rule.h +0 -2
@@ -121,8 +121,6 @@ struct chain {struct list_head rules; }; -extern const char *chain_type_name_lookup (const char *name); -extern const char *chain_hookname_lookup (const char *name);extern struct chain *chain_alloc (const char *name);extern void chain_free (struct chain *chain);extern void chain_add_hash (struct chain *chain,struct table *table);
src/evaluate.c +164 -32
219 lines not on this page · raw message
src/parser.y +4 -24
@@ -1119,35 +1119,15 @@ map_block : /* empty */ { $$ = $<set>-1; } hook_spec : TYPE STRING HOOK STRING PRIORITY NUM { - $<chain>0->type = chain_type_name_lookup($2); - if ($<chain>0->type == NULL) { - erec_queue(error(&@2, "unknown chain type %s", $2), - state->msgs); - YYERROR; - } - $<chain>0->hookstr = chain_hookname_lookup($4); - if ($<chain>0->hookstr == NULL) { - erec_queue(error(&@4, "unknown chain type %s", $4), - state->msgs); - YYERROR; - } + $<chain>0->type = $2; + $<chain>0->hookstr = $4; $<chain>0->priority = $6; $<chain>0->flags |= CHAIN_F_BASECHAIN; } | TYPE STRING HOOK STRING PRIORITY DASH NUM { - $<chain>0->type = chain_type_name_lookup($2); - if ($<chain>0->type == NULL) { - erec_queue(error(&@2, "unknown type name %s", $2), - state->msgs); - YYERROR; - } - $<chain>0->hookstr = chain_hookname_lookup($4); - if ($<chain>0->hookstr == NULL) { - erec_queue(error(&@4, "unknown hook name %s", $4), - state->msgs); - YYERROR; - } + $<chain>0->type = $2; + $<chain>0->hookstr = $4; $<chain>0->priority = -$7; $<chain>0->flags |= CHAIN_F_BASECHAIN; }
src/rule.c +0 -40
@@ -275,46 +275,6 @@ struct symbol *symbol_lookup(const struct scope *scope, const char *identifier)return NULL ; } -static const char *chain_type_str_array[] = { -"filter" , -"nat" , -"route" , -NULL , -}; - -const char *chain_type_name_lookup (const char *name) -{ -int i; - -for (i =0 ; chain_type_str_array[i]; i++) { -if (!strcmp (name, chain_type_str_array[i])) -return chain_type_str_array[i]; - } - -return NULL ; -} - -static const char *chain_hookname_str_array[] = { -"prerouting" , -"input" , -"forward" , -"postrouting" , -"output" , -NULL , -}; - -const char *chain_hookname_lookup (const char *name) -{ -int i; - -for (i =0 ; chain_hookname_str_array[i]; i++) { -if (!strcmp (name, chain_hookname_str_array[i])) -return chain_hookname_str_array[i]; - } - -return NULL ; -} -struct chain *chain_alloc (const char *name) {struct chain *chain;
Signature · 1 line
1.9.3
Pablo Neira Ayuso
maintainerQuoted 17 lines · Yanchuan Nian
The evaluation of base chain isn't extensive enough. It cannot detect whether a chain type is supported or not in certain families. It also cannot deletect whether a hook is supported or not in certain chains. The evaluation is done by kernel, and the information is unclear.
nft> add chain arp arptable chain1 {type nat hook input priority 0 ;} <cli>:1:1-64: Error: Could not add chain: No such file or directory add chain arp arptable chain1 {type nat hook input priority 0 ;} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nft> add chain ip iptable chain1 {type nat hook forward priority 0 ;} <cli>:1:1-64: Error: Could not add chain: Operation not supported add chain ip iptable chain1 {type nat hook forward priority 0 ;} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This patch performs more extensive error checking, so the information is more clear.
Quoted 8 lines
nft> add chain arp arptable chain1 {type nat hook input priority 0 ;} <cli>:1:31-63: Error: invalid type name nat
add chain arp arptable chain1 {type nat hook input priority 0 ;}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nft> add chain ip iptable chain1 {type nat hook forward priority 0 ;} <cli>:1:29-63: Error: invalid hook name forward add chain ip iptable chain1 {type nat hook forward priority 0 ;} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I don't think this belongs to userspace. Patrick and I have been discussing some extension for netlink to provide better error reporting to userspace, such as the offset to the attribute that has caused the problem. This should provide enough context to userspace to display more accurate error reporting.
On top of that, this is not going to help to catch the chain type module is missing case.
Meanwhile, I have documented this here:
http://wiki.nftables.org/wiki-nftables/index.php/Troubleshooting