src: add datatype->describe()
Pablo Neira Ayuso
maintainerPATCH 1/1 src: add datatype->describe()
As an alternative to print the datatype values when no symbol table is available. Use it to print protocols available via getprotobynumber() which actually refers to /etc/protocols.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/datatype.h | 1 + src/datatype.c | 15 +++++++++++++++ src/expression.c | 2 ++ 3 files changed, 18 insertions(+)
include/datatype.h +1 -0
@@ -164,6 +164,7 @@ struct datatype {struct error_record *(*parse)(struct parse_ctx *ctx,const struct expr *sym,struct expr **res); +void (*describe)(struct output_ctx *octx);const struct symbol_table *sym_tbl;unsigned int refcnt; };
src/datatype.c +15 -0
@@ -619,6 +619,20 @@ static void inet_protocol_type_print(const struct expr *expr,integer_type_print (expr, octx); } +static void inet_protocol_type_describe (struct output_ctx *octx) +{ +struct protoent *p; +uint8_t protonum; + +for (protonum =0 ; protonum <255 ; protonum++) { + p =getprotobynumber (protonum); +if (!p) +continue ; + +nft_print (octx,"\t%-30s\t%u\n" , p->p_name, protonum); + } +} +static struct error_record *inet_protocol_type_parse (struct parse_ctx *ctx,const struct expr *sym,struct expr **res)
@@ -658,6 +672,7 @@ const struct datatype inet_protocol_type = { .print = inet_protocol_type_print, .json = inet_protocol_type_json, .parse = inet_protocol_type_parse, + .describe = inet_protocol_type_describe, };static void inet_service_print (const struct expr *expr,struct output_ctx *octx)
src/expression.c +2 -0
@@ -172,6 +172,8 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx)nft_print (octx,"(in hexadecimal):\n" );symbol_table_print (edtype->sym_tbl, edtype, expr->byteorder, octx); + }else if (edtype->describe) { + edtype->describe (octx); } }
Signature · 1 line
2.30.2