meta: Reject zero ifindex values
Phil Sutter
reviewerPATCH 1/3 meta: Reject zero ifindex values
Signed-off-by Phil Sutter <[email protected]>
--- src/meta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/meta.c +1 -1
@@ -155,7 +155,7 @@ static struct error_record *ifindex_type_parse(const struct expr *sym, errno =0 ; res =strtol (sym->identifier, &end,10 ); -if (res <0 || res >INT_MAX || *end || errno) +if (res <=0 || res >INT_MAX || *end || errno)return error (&sym->location,"Interface does not exist" ); ifindex = (int )res;
Signature · 1 line
2.22.0
Phil Sutter
reviewerPATCH 2/3 meta: Reject nfproto value 0xffff
Since parsing of arphrd_type happens via sym_tbl, there is no dedicated parser function to perform the check in. So instead make use of maxval in expr_ctx to reject the value.
While being at it, introduce a switch() to check for meta.key value in a single place.
Signed-off-by Phil Sutter <[email protected]>
--- src/evaluate.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
src/evaluate.c +18 -6
@@ -23,6 +23,7 @@#include <netinet/icmp6.h> #include <net/ethernet.h> #include <net/if.h> +#include <net/if_arp.h> #include <errno.h> #include <expression.h>
@@ -1795,14 +1796,25 @@ static int expr_evaluate_fib(struct eval_ctx *ctx, struct expr **exprp)static int expr_evaluate_meta (struct eval_ctx *ctx,struct expr **exprp) {struct expr *meta = *exprp; +unsigned int maxval =0 ; -if (ctx->pctx.family !=NFPROTO_INET && - meta->flags &EXPR_F_PROTOCOL && - meta->meta.key ==NFT_META_NFPROTO ) +switch (meta->meta.key) { +case NFT_META_NFPROTO : +if (ctx->pctx.family ==NFPROTO_INET || + !(meta->flags &EXPR_F_PROTOCOL )) +break ;return expr_error (ctx->msgs, meta, -"meta nfproto is only useful in the inet family" ); - -return expr_evaluate_primary (ctx, exprp); +"meta nfproto is only useful in the inet family" ); +case NFT_META_IIFTYPE : +case NFT_META_OIFTYPE : + maxval =ARPHRD_VOID -1 ; +break ; +default : +break ; + } +__expr_set_context (&ctx->ectx, (*exprp)->dtype, (*exprp)->byteorder, + (*exprp)->len, maxval); +return 0 ; }static int expr_evaluate_socket (struct eval_ctx *ctx,struct expr **expr)
Signature · 1 line
2.22.0
Phil Sutter
reviewerPATCH 3/3 tests/py: Add missing meta tests
In reply to Phil SutterEnsure invalid values are rejected. Also add basic positive tests for {i,o}ifkind.
Signed-off-by Phil Sutter <[email protected]>
--- tests/py/any/meta.t | 10 ++++++++++ tests/py/any/meta.t.json | 30 ++++++++++++++++++++++++++++++ tests/py/any/meta.t.payload | 10 ++++++++++ 3 files changed, 50 insertions(+)
tests/py/any/meta.t +10 -0
@@ -63,6 +63,7 @@ meta mark xor 0x03 != 0x01;ok;meta mark != 0x00000002 meta iif "lo" accept;ok;iif "lo" accept meta iif != "lo" accept;ok;iif != "lo" accept +meta iif 0;fail meta iifname "dummy0";ok;iifname "dummy0" meta iifname != "dummy0";ok;iifname != "dummy0"
@@ -78,9 +79,14 @@ meta iiftype != ether;ok meta iiftype ether;ok meta iiftype != ppp;ok meta iiftype ppp;ok +meta iiftype 0xffff;fail + +meta iifkind "bond";ok +meta iifkind "";fail meta oif "lo" accept;ok;oif "lo" accept meta oif != "lo" accept;ok;oif != "lo" accept +meta oif 0;fail meta oifname "dummy0";ok;oifname "dummy0" meta oifname != "dummy0";ok;oifname != "dummy0"
@@ -93,6 +99,10 @@ meta oiftype {ether, ppp, ipip, ipip6, loopback, sit, ipgre};ok meta oiftype != {ether, ppp, ipip, ipip6, loopback, sit, ipgre};ok meta oiftype != ether;ok meta oiftype ether;ok +meta oiftype 0xffff;fail + +meta oifkind "bond";ok +meta oifkind "";fail meta skuid {"bin", "root", "daemon"} accept;ok;meta skuid { 0, 1, 2} accept meta skuid != {"bin", "root", "daemon"} accept;ok;meta skuid != { 1, 0, 2} accept
tests/py/any/meta.t.json +30 -0
@@ -952,6 +952,21 @@ } ] +# meta iifkind "bond" +[ + { + "match": { + "left": { + "meta": { + "key": "iifkind" + } + }, + "op": "==", + "right": "bond" + } + } +] + # meta oif "lo" accept [ {
@@ -1113,6 +1128,21 @@ } ] +# meta oifkind "bond" +[ + { + "match": { + "left": { + "meta": { + "key": "oifkind" + } + }, + "op": "==", + "right": "bond" + } + } +] + # meta oiftype ether [ {
tests/py/any/meta.t.payload +10 -0
@@ -263,6 +263,11 @@ ip test-ip4 input [ meta load iiftype => reg 1 ] [ cmp eq reg 1 0x00000200 ] +# meta iifkind "bond" +ip test-ip4 input + [ meta load iifkind => reg 1 ] + [ cmp eq reg 1 0x646e6f62 0x00000000 0x00000000 0x00000000 ] + # meta oif "lo" accept ip test-ip4 input [ meta load oif => reg 1 ]
@@ -329,6 +334,11 @@ ip test-ip4 input [ meta load oiftype => reg 1 ] [ cmp eq reg 1 0x00000001 ] +# meta oifkind "bond" +ip test-ip4 input + [ meta load oifkind => reg 1 ] + [ cmp eq reg 1 0x646e6f62 0x00000000 0x00000000 0x00000000 ] + # meta skuid {"bin", "root", "daemon"} accept __set%d test-ip4 3 __set%d test-ip4 0
Signature · 1 line
2.22.0