diff options
-rw-r--r-- | include/datatype.h | 12 | ||||
-rw-r--r-- | src/ct.c | 12 | ||||
-rw-r--r-- | src/datatype.c | 29 | ||||
-rw-r--r-- | src/expression.c | 2 | ||||
-rw-r--r-- | src/exthdr.c | 4 | ||||
-rw-r--r-- | src/meta.c | 14 | ||||
-rw-r--r-- | src/payload.c | 16 |
7 files changed, 56 insertions, 33 deletions
diff --git a/include/datatype.h b/include/datatype.h index 9131d72a..ea18f719 100644 --- a/include/datatype.h +++ b/include/datatype.h @@ -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); @@ -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, }; diff --git a/src/datatype.c b/src/datatype.c index 256bcbe4..fece6049 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -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, }; diff --git a/src/expression.c b/src/expression.c index ba4bda17..74579dd2 100644 --- a/src/expression.c +++ b/src/expression.c @@ -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); } } diff --git a/src/exthdr.c b/src/exthdr.c index ee02cd53..3d01c3ab 100644 --- a/src/exthdr.c +++ b/src/exthdr.c @@ -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, }; @@ -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, diff --git a/src/payload.c b/src/payload.c index feb6c551..f41d4c17 100644 --- a/src/payload.c +++ b/src/payload.c @@ -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 = ðertype_tbl, }; |