DESCRIBE COMMAND
~~~~~~~~~~~~~~~~
[verse]
-*describe* 'expression'
+*describe* 'expression' | 'data type'
The *describe* command shows information about the type of an expression and its data type.
+A data type may also be given, in which nft will display more information
+about the type.
.The describe command
---------------------
addition some expression types define further data types specific to the
expression type. Most data types have a fixed size, some however may have a
dynamic size, f.i. the string type. +
+Some types also have predefined symbolic constants. Those can be listed
+using the nft *describe* command:
+
+---------------------
+$ nft describe ct_state
+datatype ct_state (conntrack state) (basetype bitmask, integer), 32 bits
+
+pre-defined symbolic constants (in hexadecimal):
+invalid 0x00000001
+new ...
+---------------------
Types may be derived from lower order types, f.i. the IPv4 address type is
derived from the integer type, meaning an IPv4 address can also be specified as
void expr_describe(const struct expr *expr, struct output_ctx *octx)
{
- const struct datatype *dtype = expr->dtype;
+ const struct datatype *dtype = expr->dtype, *edtype = NULL;
+ unsigned int len = expr->len;
const char *delim = "";
- nft_print(octx, "%s expression, datatype %s (%s)",
- expr_name(expr), dtype->name, dtype->desc);
+ if (dtype == &invalid_type &&
+ expr->etype == EXPR_SYMBOL)
+ edtype = datatype_lookup_byname(expr->identifier);
+
+ if (edtype) {
+ dtype = edtype;
+ nft_print(octx, "datatype %s (%s)",
+ dtype->name, dtype->desc);
+ len = dtype->size;
+ } else {
+ nft_print(octx, "%s expression, datatype %s (%s)",
+ expr_name(expr), dtype->name, dtype->desc);
+ }
+
if (dtype->basetype != NULL) {
nft_print(octx, " (basetype ");
for (dtype = dtype->basetype; dtype != NULL;
}
if (expr_basetype(expr)->type == TYPE_STRING) {
- if (expr->len)
+ if (len)
nft_print(octx, ", %u characters",
- expr->len / BITS_PER_BYTE);
+ len / BITS_PER_BYTE);
else
nft_print(octx, ", dynamic length");
} else
- nft_print(octx, ", %u bits", expr->len);
+ nft_print(octx, ", %u bits", len);
+
+ if (!edtype)
+ edtype = expr->dtype;
nft_print(octx, "\n");
- if (expr->dtype->sym_tbl != NULL) {
+ if (edtype->sym_tbl != NULL) {
nft_print(octx, "\npre-defined symbolic constants ");
- if (expr->dtype->sym_tbl->base == BASE_DECIMAL)
+ if (edtype->sym_tbl->base == BASE_DECIMAL)
nft_print(octx, "(in decimal):\n");
else
nft_print(octx, "(in hexadecimal):\n");
- symbol_table_print(expr->dtype->sym_tbl, expr->dtype,
+ symbol_table_print(edtype->sym_tbl, edtype,
expr->byteorder, octx);
}
}