]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: add/move size and byte order information into data types
authorPatrick McHardy <kaber@trash.net>
Tue, 31 Mar 2009 02:57:48 +0000 (04:57 +0200)
committerPatrick McHardy <kaber@trash.net>
Tue, 31 Mar 2009 02:57:48 +0000 (04:57 +0200)
Add size and type information to non-basetype types and remove the now
redundant information from the symbol tables.

This will be used to determine size and byteorder of set members without
analyzing the ruleset for incremental update operations.

Signed-off-by: Patrick McHardy <kaber@trash.net>
include/datatype.h
src/ct.c
src/datatype.c
src/expression.c
src/exthdr.c
src/meta.c
src/payload.c

index 9131d72a833eaf6121602acb3509de7d9bdf1431..ea18f7190cb9649b664bdf321537169628110b69 100644 (file)
@@ -81,6 +81,8 @@ struct expr;
  * struct datatype
  *
  * @type:      numeric identifier
+ * @byteorder: byteorder of type (non-basetypes only)
+ * @size:      type size (fixed sized non-basetypes only)
  * @name:      type name
  * @desc:      type description
  * @basetype:  basetype for subtypes, determines type compatibilty
@@ -91,6 +93,8 @@ struct expr;
  */
 struct datatype {
        enum datatypes                  type;
+       enum byteorder                  byteorder;
+       unsigned int                    size;
        const char                      *name;
        const char                      *desc;
        const struct datatype           *basetype;
@@ -126,13 +130,10 @@ struct symbolic_constant {
 /**
  * struct symbol_table - type construction from symbolic values
  *
- * @byteorder: byteorder of symbol values
- * @size:      size of symbol values
  * @symbols:   the symbols
  */
 struct symbol_table {
-       enum byteorder                  byteorder;
-       unsigned int                    size;
+       int                             gcc_workaround;
        struct symbolic_constant        symbols[];
 };
 
@@ -141,7 +142,8 @@ extern struct error_record *symbolic_constant_parse(const struct expr *sym,
                                                    struct expr **res);
 extern void symbolic_constant_print(const struct symbol_table *tbl,
                                    const struct expr *expr);
-extern void symbol_table_print(const struct symbol_table *tbl);
+extern void symbol_table_print(const struct symbol_table *tbl,
+                              const struct datatype *dtype);
 
 extern struct symbol_table *rt_symbol_table_init(const char *filename);
 extern void rt_symbol_table_free(struct symbol_table *tbl);
index b077a5f9d0745c59a704d2fc357313888c51c3fb..1baefed877ad56627c4578a2ac895c22b7226e59 100644 (file)
--- a/src/ct.c
+++ b/src/ct.c
@@ -26,8 +26,6 @@
 #include <utils.h>
 
 static const struct symbol_table ct_state_tbl = {
-       .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 4 * BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("invalid",       NF_CT_STATE_INVALID_BIT),
                SYMBOL("new",           NF_CT_STATE_BIT(IP_CT_NEW)),
@@ -42,13 +40,13 @@ static const struct datatype ct_state_type = {
        .type           = TYPE_CT_STATE,
        .name           = "ct_state",
        .desc           = "conntrack state",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &bitmask_type,
        .sym_tbl        = &ct_state_tbl,
 };
 
 static const struct symbol_table ct_dir_tbl = {
-       .byteorder      = BYTEORDER_INVALID,
-       .size           = BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("original",      IP_CT_DIR_ORIGINAL),
                SYMBOL("reply",         IP_CT_DIR_REPLY),
@@ -60,13 +58,13 @@ static const struct datatype ct_dir_type = {
        .type           = TYPE_CT_DIR,
        .name           = "ct_dir",
        .desc           = "conntrack direction",
+       .byteorder      = BYTEORDER_INVALID,
+       .size           = BITS_PER_BYTE,
        .basetype       = &bitmask_type,
        .sym_tbl        = &ct_dir_tbl,
 };
 
 static const struct symbol_table ct_status_tbl = {
-       .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 4 * BITS_PER_BYTE,
        /*
         * There are more, but most of them don't make sense for filtering.
         */
@@ -86,6 +84,8 @@ static const struct datatype ct_status_type = {
        .type           = TYPE_CT_STATUS,
        .name           = "ct_status",
        .desc           = "conntrack status",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &bitmask_type,
        .sym_tbl        = &ct_status_tbl,
 };
index 256bcbe4e2acf7f2cf324f2af90f7af2eb8b3002..fece6049cd33d2303cd9a9cd2b337921b2258aab 100644 (file)
@@ -100,18 +100,20 @@ struct error_record *symbolic_constant_parse(const struct expr *sym,
                                             struct expr **res)
 {
        const struct symbolic_constant *s;
+       const struct datatype *dtype;
 
        for (s = tbl->symbols; s->identifier != NULL; s++) {
                if (!strcmp(sym->identifier, s->identifier))
                        break;
        }
 
+       dtype = sym->sym_type;
        if (s->identifier == NULL)
-               return error(&sym->location, "Could not parse %s",
-                            sym->sym_type->desc);
+               return error(&sym->location, "Could not parse %s", dtype->desc);
 
-       *res = constant_expr_alloc(&sym->location, sym->sym_type,
-                                  tbl->byteorder, tbl->size, &s->value);
+       *res = constant_expr_alloc(&sym->location, dtype,
+                                  dtype->byteorder, dtype->size,
+                                  &s->value);
        return NULL;
 }
 
@@ -131,10 +133,11 @@ void symbolic_constant_print(const struct symbol_table *tbl,
        printf("%s", s->identifier);
 }
 
-void symbol_table_print(const struct symbol_table *tbl)
+void symbol_table_print(const struct symbol_table *tbl,
+                       const struct datatype *dtype)
 {
        const struct symbolic_constant *s;
-       unsigned int size = 2 * tbl->size / BITS_PER_BYTE;
+       unsigned int size = 2 * dtype->size / BITS_PER_BYTE;
 
        for (s = tbl->symbols; s->identifier != NULL; s++)
                printf("\t%-30s\t0x%.*" PRIx64 "\n",
@@ -353,6 +356,8 @@ const struct datatype ipaddr_type = {
        .type           = TYPE_IPADDR,
        .name           = "ipv4_address",
        .desc           = "IPv4 address",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = ipaddr_type_print,
        .parse          = ipaddr_type_parse,
@@ -402,6 +407,8 @@ const struct datatype ip6addr_type = {
        .type           = TYPE_IP6ADDR,
        .name           = "ipv6_address",
        .desc           = "IPv6 address",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = 16 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = ip6addr_type_print,
        .parse          = ip6addr_type_parse,
@@ -440,6 +447,7 @@ const struct datatype inet_protocol_type = {
        .type           = TYPE_INET_PROTOCOL,
        .name           = "inet_protocol",
        .desc           = "Internet protocol",
+       .size           = BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = inet_protocol_type_print,
        .parse          = inet_protocol_type_parse,
@@ -481,6 +489,8 @@ const struct datatype inet_service_type = {
        .type           = TYPE_INET_SERVICE,
        .name           = "inet_service",
        .desc           = "internet network service",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = 2 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = inet_service_type_print,
        .parse          = inet_service_type_parse,
@@ -500,9 +510,6 @@ struct symbol_table *rt_symbol_table_init(const char *filename)
        tbl = xmalloc(sizeof(*tbl) + size * sizeof(s));
        nelems = 0;
 
-       tbl->size      = 4 * BITS_PER_BYTE;
-       tbl->byteorder = BYTEORDER_HOST_ENDIAN;
-
        f = fopen(filename, "r");
        if (f == NULL)
                goto out;
@@ -574,6 +581,8 @@ const struct datatype mark_type = {
        .type           = TYPE_MARK,
        .name           = "mark",
        .desc           = "packet mark",
+       .size           = 4 * BITS_PER_BYTE,
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
        .basetype       = &integer_type,
        .basefmt        = "0x%.8Zx",
        .print          = mark_type_print,
@@ -618,6 +627,8 @@ const struct datatype time_type = {
        .type           = TYPE_TIME,
        .name           = "time",
        .desc           = "relative time",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 8 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = time_type_print,
 };
index ba4bda172cee501d1877fc4016d304fdc1c20844..74579dd2ddf2554283a7b5a1eb0f60f20eeb8f5b 100644 (file)
@@ -102,7 +102,7 @@ void expr_describe(const struct expr *expr)
 
        if (expr->dtype->sym_tbl != NULL) {
                printf("\npre-defined symbolic constants:\n");
-               symbol_table_print(expr->dtype->sym_tbl);
+               symbol_table_print(expr->dtype->sym_tbl, expr->dtype);
        }
 }
 
index ee02cd53cfcce04a33593a2120a165f8c3fdbea0..3d01c3ab88dc281245b92433ef176215e2c9c421 100644 (file)
@@ -205,8 +205,6 @@ const struct exthdr_desc exthdr_dst = {
        HDR_TEMPLATE(__name, __dtype, struct ip6_mh, __member)
 
 static const struct symbol_table mh_type_tbl = {
-       .byteorder      = BYTEORDER_BIG_ENDIAN,
-       .size           = BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("binding-refresh-request",       IP6_MH_TYPE_BRR),
                SYMBOL("home-test-init",                IP6_MH_TYPE_HOTI),
@@ -229,6 +227,8 @@ static const struct datatype mh_type_type = {
        .type           = TYPE_MH_TYPE,
        .name           = "mh_type",
        .desc           = "Mobility Header Type",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = BITS_PER_BYTE,
        .basetype       = &integer_type,
        .sym_tbl        = &mh_type_tbl,
 };
index a8f728af3c61a10777330e6f08c94304a36f9acf..c5168248cd19ecb33ba79f4d71d4b777494f8c86 100644 (file)
@@ -55,6 +55,8 @@ static const struct datatype realm_type = {
        .type           = TYPE_REALM,
        .name           = "realm",
        .desc           = "routing realm",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = realm_type_print,
        .parse          = realm_type_parse,
@@ -87,6 +89,8 @@ static const struct datatype tchandle_type = {
        .type           = TYPE_TC_HANDLE,
        .name           = "tc_handle",
        .desc           = "TC handle",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = tchandle_type_print,
        .parse          = tchandle_type_parse,
@@ -164,14 +168,14 @@ static const struct datatype ifindex_type = {
        .type           = TYPE_IFINDEX,
        .name           = "ifindex",
        .desc           = "interface index",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = ifindex_type_print,
        .parse          = ifindex_type_parse,
 };
 
 static const struct symbol_table arphrd_tbl = {
-       .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 2 * BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("ether",         ARPHRD_ETHER),
                SYMBOL("ppp",           ARPHRD_PPP),
@@ -189,6 +193,8 @@ const struct datatype arphrd_type = {
        .type           = TYPE_ARPHRD,
        .name           = "arphrd",
        .desc           = "hardware type",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 2 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .sym_tbl        = &arphrd_tbl,
 };
@@ -227,6 +233,8 @@ static const struct datatype uid_type = {
        .type           = TYPE_UID,
        .name           = "uid",
        .desc           = "user ID",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = sizeof(uid_t) * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = uid_type_print,
        .parse          = uid_type_parse,
@@ -266,6 +274,8 @@ static const struct datatype gid_type = {
        .type           = TYPE_GID,
        .name           = "gid",
        .desc           = "group ID",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = sizeof(gid_t) * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = gid_type_print,
        .parse          = gid_type_parse,
index feb6c55140c9f6bc3ef80d43fcec612f382591f6..f41d4c17e22f4426a92a64d8be0277d78b0edd91 100644 (file)
@@ -558,8 +558,6 @@ const struct payload_desc payload_comp = {
 #include <netinet/ip_icmp.h>
 
 static const struct symbol_table icmp_type_tbl = {
-       .byteorder      = BYTEORDER_BIG_ENDIAN,
-       .size           = BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("echo-reply",                    ICMP_ECHOREPLY),
                SYMBOL("destination-unreachable",       ICMP_DEST_UNREACH),
@@ -582,6 +580,8 @@ static const struct datatype icmp_type_type = {
        .type           = TYPE_ICMP_TYPE,
        .name           = "icmp_type",
        .desc           = "ICMP type",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = BITS_PER_BYTE,
        .basetype       = &integer_type,
        .sym_tbl        = &icmp_type_tbl,
 };
@@ -642,8 +642,6 @@ const struct payload_desc payload_udplite = {
 #include <netinet/tcp.h>
 
 static const struct symbol_table tcp_flag_tbl = {
-       .byteorder      = BYTEORDER_BIG_ENDIAN,
-       .size           = BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("fin",   TCP_FLAG_FIN),
                SYMBOL("syn",   TCP_FLAG_SYN),
@@ -661,6 +659,8 @@ static const struct datatype tcp_flag_type = {
        .type           = TYPE_TCP_FLAG,
        .name           = "tcp_flag",
        .desc           = "TCP flag",
+       .byteorder      = BYTEORDER_BIG_ENDIAN,
+       .size           = BITS_PER_BYTE,
        .basetype       = &bitmask_type,
        .sym_tbl        = &tcp_flag_tbl,
 };
@@ -805,8 +805,6 @@ const struct payload_desc payload_ip6 = {
 #include <net/if_arp.h>
 
 static const struct symbol_table arpop_tbl = {
-       .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 2 * BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("request",       ARPOP_REQUEST),
                SYMBOL("reply",         ARPOP_REPLY),
@@ -822,6 +820,8 @@ static const struct datatype arpop_type = {
        .type           = TYPE_ARPOP,
        .name           = "arp_op",
        .desc           = "ARP operation",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 2 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .sym_tbl        = &arpop_tbl,
 };
@@ -878,8 +878,6 @@ const struct payload_desc payload_vlan = {
  */
 
 static const struct symbol_table ethertype_tbl = {
-       .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 2 * BITS_PER_BYTE,
        .symbols        = {
                SYMBOL("ip",            ETH_P_IP),
                SYMBOL("arp",           ETH_P_ARP),
@@ -893,6 +891,8 @@ const struct datatype ethertype_type = {
        .type           = TYPE_ETHERTYPE,
        .name           = "ethertype",
        .desc           = "Ethernet protocol",
+       .byteorder      = BYTEORDER_HOST_ENDIAN,
+       .size           = 2 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .sym_tbl        = &ethertype_tbl,
 };