]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: relax datatype check in integer_type_parse()
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 28 Nov 2014 20:20:59 +0000 (21:20 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 30 Nov 2014 22:20:32 +0000 (23:20 +0100)
Otherwise parsing with basetypes doesn't work. Now nft displays
an error when the symbolic constant is not correct:

 <cmdline>:1:29-31: Error: Could not parse conntrack state
 add rule test test ct state xxx accept
                             ^^^

Use .sym_tbl instead and default on the symbol_constant_parse()
function from the ethertype and pkttype, this simplifies the code and
(more importantly) it avoids a breakage after the change in
integer_type_parse().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/datatype.c
src/meta.c
src/proto.c
tests/regression/any/ct.t

index 7c9c3d488dbeefdb906d62de9943dd4bfc39034a..1ace3fa7a0492ef6a8555551a8a668045c897f63 100644 (file)
@@ -280,8 +280,6 @@ static struct error_record *integer_type_parse(const struct expr *sym,
        if (gmp_sscanf(sym->identifier, "%Zu%n", v, &len) != 1 ||
            (int)strlen(sym->identifier) != len) {
                mpz_clear(v);
-               if (sym->dtype != &integer_type)
-                       return NULL;
                return error(&sym->location, "Could not parse %s",
                             sym->dtype->desc);
        }
index 61dc5cf083084bd1f72538264bfcf35c4a1fec24..9c1ea582f2b0aad99c1a948d043b1c462267f028 100644 (file)
@@ -312,32 +312,6 @@ static void pkttype_type_print(const struct expr *expr)
        return symbolic_constant_print(&pkttype_type_tbl, expr);
 }
 
-static struct error_record *pkttype_type_parse(const struct expr *sym,
-                                              struct expr **res)
-{
-       struct error_record *erec;
-       const struct symbolic_constant *s;
-
-       for (s = pkttype_type_tbl.symbols; s->identifier != NULL; s++) {
-               if (!strcmp(sym->identifier, s->identifier)) {
-                       *res = constant_expr_alloc(&sym->location, sym->dtype,
-                                                  sym->dtype->byteorder,
-                                                  sym->dtype->size,
-                                                  &s->value);
-                       return NULL;
-               }
-       }
-
-       *res = NULL;
-       erec = sym->dtype->basetype->parse(sym, res);
-       if (erec != NULL)
-               return erec;
-       if (*res)
-               return NULL;
-
-       return symbolic_constant_parse(sym, &pkttype_type_tbl, res);
-}
-
 static const struct datatype pkttype_type = {
        .type           = TYPE_PKTTYPE,
        .name           = "pkt_type",
@@ -346,7 +320,7 @@ static const struct datatype pkttype_type = {
        .size           = BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = pkttype_type_print,
-       .parse          = pkttype_type_parse,
+       .sym_tbl        = &pkttype_type_tbl,
 };
 
 static struct symbol_table *devgroup_tbl;
index 6eb4bb24f3da3d8876799b758a27faf9e135c696..7dc7b3e247f622588795ad4a00008a0ae26c1a2f 100644 (file)
@@ -751,20 +751,6 @@ static const struct symbol_table ethertype_tbl = {
        },
 };
 
-static struct error_record *ethertype_parse(const struct expr *sym,
-                                           struct expr **res)
-{
-       struct error_record *erec;
-
-       *res = NULL;
-       erec = sym->dtype->basetype->parse(sym, res);
-       if (erec != NULL)
-               return erec;
-       if (*res)
-               return NULL;
-       return symbolic_constant_parse(sym, &ethertype_tbl, res);
-}
-
 static void ethertype_print(const struct expr *expr)
 {
        return symbolic_constant_print(&ethertype_tbl, expr);
@@ -779,7 +765,7 @@ const struct datatype ethertype_type = {
        .basetype       = &integer_type,
        .basefmt        = "0x%.4Zx",
        .print          = ethertype_print,
-       .parse          = ethertype_parse,
+       .sym_tbl        = &ethertype_tbl,
 };
 
 #define ETHHDR_TEMPLATE(__name, __dtype, __member) \
index 79674ee74b2cffccc32f31729270d6ea8a924507..09f72ed090b411bf6b1e0c3b19f422f6a72d3e60 100644 (file)
@@ -14,6 +14,7 @@ ct state {new,established, related, untracked};ok
 ct state invalid drop;ok
 ct state established accept;ok
 ct state 8;ok;ct state new
+ct state xxx;fail
 
 ct direction original;ok
 ct direction != original;ok
@@ -21,12 +22,14 @@ ct direction reply;ok
 ct direction != reply;ok
 ct direction {reply, original};ok
 - ct direction != {reply, original};ok
+ct direction xxx;fail
 
 ct status expected;ok
 ct status != expected;ok
 ct status seen-reply;ok
 ct status != seen-reply;ok
 ct status {expected, seen-reply, assured, confirmed, dying};ok
+ct status xxx;fail
 
 # SYMBOL("snat", IPS_SRC_NAT)
 # SYMBOL("dnat", IPS_DST_NAT)