]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
payload: accept ethertype in hexadecimal
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 20 Apr 2013 09:51:40 +0000 (11:51 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 20 Apr 2013 09:52:19 +0000 (11:52 +0200)
You can use the symbols ip, ip6, arp and vlan, or alternatively
the ethertype protocol number.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/payload.c

index bcbc0d4352784e4a7b66db553d08e12c5ac43b24..942bc8574aa16f3730a1d9ec1824572ad4a2a6c6 100644 (file)
@@ -930,6 +930,24 @@ static const struct symbol_table ethertype_tbl = {
        },
 };
 
+static struct error_record *ethertype_parse(const struct expr *sym,
+                                           struct expr **res)
+{
+       struct error_record *erec;
+
+       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);
+}
+
 const struct datatype ethertype_type = {
        .type           = TYPE_ETHERTYPE,
        .name           = "ethertype",
@@ -937,7 +955,9 @@ const struct datatype ethertype_type = {
        .byteorder      = BYTEORDER_HOST_ENDIAN,
        .size           = 2 * BITS_PER_BYTE,
        .basetype       = &integer_type,
-       .sym_tbl        = &ethertype_tbl,
+       .basefmt        = "0x%.4Zx",
+       .print          = ethertype_print,
+       .parse          = ethertype_parse,
 };
 
 #define ETHHDR_TEMPLATE(__name, __dtype, __member) \