struct nft_ctx;
-enum debug_level {
- DEBUG_SCANNER = 0x1,
- DEBUG_PARSER = 0x2,
- DEBUG_EVALUATION = 0x4,
- DEBUG_NETLINK = 0x8,
- DEBUG_MNL = 0x10,
- DEBUG_PROTO_CTX = 0x20,
- DEBUG_SEGTREE = 0x40,
+enum nft_debug_level {
+ NFT_DEBUG_SCANNER = 0x1,
+ NFT_DEBUG_PARSER = 0x2,
+ NFT_DEBUG_EVALUATION = 0x4,
+ NFT_DEBUG_NETLINK = 0x8,
+ NFT_DEBUG_MNL = 0x10,
+ NFT_DEBUG_PROTO_CTX = 0x20,
+ NFT_DEBUG_SEGTREE = 0x40,
};
-enum numeric_level {
- NUMERIC_NONE,
- NUMERIC_ADDR,
- NUMERIC_PORT,
- NUMERIC_ALL,
+enum nft_numeric_level {
+ NFT_NUMERIC_NONE,
+ NFT_NUMERIC_ADDR,
+ NFT_NUMERIC_PORT,
+ NFT_NUMERIC_ALL,
};
/**
bool nft_ctx_get_dry_run(struct nft_ctx *ctx);
void nft_ctx_set_dry_run(struct nft_ctx *ctx, bool dry);
-enum numeric_level nft_ctx_output_get_numeric(struct nft_ctx *ctx);
-void nft_ctx_output_set_numeric(struct nft_ctx *ctx, enum numeric_level level);
+enum nft_numeric_level nft_ctx_output_get_numeric(struct nft_ctx *ctx);
+void nft_ctx_output_set_numeric(struct nft_ctx *ctx, enum nft_numeric_level level);
bool nft_ctx_output_get_stateless(struct nft_ctx *ctx);
void nft_ctx_output_set_stateless(struct nft_ctx *ctx, bool val);
bool nft_ctx_output_get_ip2name(struct nft_ctx *ctx);
if (quotes)
nft_print(octx, "\"");
- if (octx->numeric > NUMERIC_ALL)
+ if (octx->numeric > NFT_NUMERIC_ALL)
nft_print(octx, "%" PRIu64 "", val);
else
nft_print(octx, "%s", s->identifier);
{
struct protoent *p;
- if (octx->numeric < NUMERIC_ALL) {
+ if (octx->numeric < NFT_NUMERIC_ALL) {
p = getprotobynumber(mpz_get_uint8(expr->value));
if (p != NULL) {
nft_print(octx, "%s", p->p_name);
static void inet_service_type_print(const struct expr *expr,
struct output_ctx *octx)
{
- if (octx->numeric >= NUMERIC_PORT) {
+ if (octx->numeric >= NFT_NUMERIC_PORT) {
integer_type_print(expr, octx);
return;
}
break;
case SYMBOL_SET:
ret = cache_update(ctx->nf_sock, ctx->cache, ctx->cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
{
- if (ctx->debug_mask & DEBUG_EVALUATION) {
+ if (ctx->debug_mask & NFT_DEBUG_EVALUATION) {
struct error_record *erec;
erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location,
"Evaluate %s", (*expr)->ops->name);
int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
{
- if (ctx->debug_mask & DEBUG_EVALUATION) {
+ if (ctx->debug_mask & NFT_DEBUG_EVALUATION) {
struct error_record *erec;
erec = erec_create(EREC_INFORMATIONAL, &stmt->location,
"Evaluate %s", stmt->ops->name);
switch (cmd->obj) {
case CMD_OBJ_SETELEM:
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
return setelem_evaluate(ctx, &cmd->expr);
case CMD_OBJ_SET:
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
return rule_evaluate(ctx, cmd->rule);
case CMD_OBJ_CHAIN:
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
switch (cmd->obj) {
case CMD_OBJ_SETELEM:
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
int ret;
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
int ret;
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
int ret;
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
switch (cmd->obj) {
case CMD_OBJ_CHAIN:
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op,
- ctx->msgs, ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->msgs, ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
int ret;
ret = cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (ret < 0)
return ret;
static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
{
return cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
}
static const char * const cmd_op_name[] = {
int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
{
- if (ctx->debug_mask & DEBUG_EVALUATION) {
+ if (ctx->debug_mask & NFT_DEBUG_EVALUATION) {
struct error_record *erec;
erec = erec_create(EREC_INFORMATIONAL, &cmd->location,
static void range_expr_print(const struct expr *expr, struct output_ctx *octx)
{
- octx->numeric += NUMERIC_ALL + 1;
+ octx->numeric += NFT_NUMERIC_ALL + 1;
expr_print(expr->left, octx);
nft_print(octx, "-");
expr_print(expr->right, octx);
- octx->numeric -= NUMERIC_ALL + 1;
+ octx->numeric -= NFT_NUMERIC_ALL + 1;
}
static void range_expr_clone(struct expr *new, const struct expr *expr)
ctx->check = dry;
}
-enum numeric_level nft_ctx_output_get_numeric(struct nft_ctx *ctx)
+enum nft_numeric_level nft_ctx_output_get_numeric(struct nft_ctx *ctx)
{
return ctx->output.numeric;
}
-void nft_ctx_output_set_numeric(struct nft_ctx *ctx, enum numeric_level level)
+void nft_ctx_output_set_numeric(struct nft_ctx *ctx,
+ enum nft_numeric_level level)
{
ctx->output.numeric = level;
}
static const struct {
const char *name;
- enum debug_level level;
+ enum nft_debug_level level;
} debug_param[] = {
{
.name = "scanner",
- .level = DEBUG_SCANNER,
+ .level = NFT_DEBUG_SCANNER,
},
{
.name = "parser",
- .level = DEBUG_PARSER,
+ .level = NFT_DEBUG_PARSER,
},
{
.name = "eval",
- .level = DEBUG_EVALUATION,
+ .level = NFT_DEBUG_EVALUATION,
},
{
.name = "netlink",
- .level = DEBUG_NETLINK,
+ .level = NFT_DEBUG_NETLINK,
},
{
.name = "mnl",
- .level = DEBUG_MNL,
+ .level = NFT_DEBUG_MNL,
},
{
.name = "proto-ctx",
- .level = DEBUG_PROTO_CTX,
+ .level = NFT_DEBUG_PROTO_CTX,
},
{
.name = "segtree",
- .level = DEBUG_SEGTREE,
+ .level = NFT_DEBUG_SEGTREE,
},
{
.name = "all",
int main(int argc, char * const *argv)
{
char *buf = NULL, *filename = NULL;
- unsigned int len;
+ enum nft_numeric_level numeric;
bool interactive = false;
- int i, val, rc;
- enum numeric_level numeric;
unsigned int debug_mask;
+ unsigned int len;
+ int i, val, rc;
nft = nft_ctx_new(NFT_CTX_DEFAULT);
nft_ctx_set_output(nft, stdout);
break;
case OPT_NUMERIC:
numeric = nft_ctx_output_get_numeric(nft);
- if (numeric == NUMERIC_ALL) {
+ if (numeric == NFT_NUMERIC_ALL) {
fprintf(stderr, "Too many numeric options "
"used, max. %u\n",
- NUMERIC_ALL);
+ NFT_NUMERIC_ALL);
exit(NFT_EXIT_FAILURE);
}
nft_ctx_output_set_numeric(nft, numeric + 1);
{
struct passwd *pw;
- if (octx->numeric < NUMERIC_ALL) {
+ if (octx->numeric < NFT_NUMERIC_ALL) {
uint32_t uid = mpz_get_uint32(expr->value);
pw = getpwuid(uid);
{
struct group *gr;
- if (octx->numeric < NUMERIC_ALL) {
+ if (octx->numeric < NFT_NUMERIC_ALL) {
uint32_t gid = mpz_get_uint32(expr->value);
gr = getgrgid(gid);
{
uint32_t portid = mnl_socket_get_portid(ctx->nf_sock);
- if (ctx->debug_mask & DEBUG_MNL)
+ if (ctx->debug_mask & NFT_DEBUG_MNL)
mnl_nlmsg_fprintf(stdout, data, len, sizeof(struct nfgenmsg));
if (mnl_socket_sendto(ctx->nf_sock, data, len) < 0)
nftnl_batch_iovec(ctx->batch, iov, iov_len);
for (i = 0; i < iov_len; i++) {
- if (ctx->debug_mask & DEBUG_MNL) {
+ if (ctx->debug_mask & NFT_DEBUG_MNL) {
mnl_nlmsg_fprintf(stdout,
iov[i].iov_base, iov[i].iov_len,
sizeof(struct nfgenmsg));
}
}
- if (ctx->debug_mask & DEBUG_MNL) {
+ if (ctx->debug_mask & NFT_DEBUG_MNL) {
mnl_nlmsg_fprintf(stdout, buf, sizeof(buf),
sizeof(struct nfgenmsg));
}
if (ctx->octx->echo) {
err = cache_update(ctx->nf_sock, ctx->cache,
CMD_INVALID, ctx->msgs,
- ctx->debug_mask & DEBUG_NETLINK, ctx->octx);
+ ctx->debug_mask & NFT_DEBUG_NETLINK, ctx->octx);
if (err < 0)
return err;
{
FILE *fp = ctx->octx->output_fp;
- if (!(ctx->debug_mask & DEBUG_NETLINK) || !fp)
+ if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
return;
nftnl_rule_fprintf(fp, nlr, 0, 0);
void netlink_dump_expr(const struct nftnl_expr *nle,
FILE *fp, unsigned int debug_mask)
{
- if (!(debug_mask & DEBUG_NETLINK))
+ if (!(debug_mask & NFT_DEBUG_NETLINK))
return;
nftnl_expr_fprintf(fp, nle, 0, 0);
{
FILE *fp = ctx->octx->output_fp;
- if (!(ctx->debug_mask & DEBUG_NETLINK) || !fp)
+ if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
return;
nftnl_chain_fprintf(fp, nlc, 0, 0);
{
FILE *fp = ctx->octx->output_fp;
- if (!(ctx->debug_mask & DEBUG_NETLINK) || !fp)
+ if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
return;
nftnl_set_fprintf(fp, nls, 0, 0);
{
FILE *fp = ctx->octx->output_fp;
- if (!(ctx->debug_mask & DEBUG_NETLINK) || !fp)
+ if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
return;
nftnl_obj_fprintf(fp, nln, 0, 0);
static void netlink_events_debug(uint16_t type, unsigned int debug_mask)
{
- if (!(debug_mask & DEBUG_NETLINK))
+ if (!(debug_mask & NFT_DEBUG_NETLINK))
return;
printf("netlink event: %s\n", nftnl_msgtype2str(type));
%initial-action {
location_init(scanner, state, &yylloc);
- if (nft->debug_mask & DEBUG_SCANNER)
+ if (nft->debug_mask & NFT_DEBUG_SCANNER)
nft_set_debug(1, scanner);
- if (nft->debug_mask & DEBUG_PARSER)
+ if (nft->debug_mask & NFT_DEBUG_PARSER)
yydebug = 1;
}
{
unsigned int i;
- if (!(debug_mask & DEBUG_PROTO_CTX))
+ if (!(debug_mask & NFT_DEBUG_PROTO_CTX))
return;
pr_debug("update %s protocol context:\n", proto_base_names[base]);
.cache = cache,
.msgs = msgs,
.seqnum = cache->seqnum++,
- .debug_mask = debug ? DEBUG_NETLINK : 0,
+ .debug_mask = debug ? NFT_DEBUG_NETLINK : 0,
.octx = octx,
};
int ret;
static bool segtree_debug(unsigned int debug_mask)
{
- if (debug_mask & DEBUG_SEGTREE)
+ if (debug_mask & NFT_DEBUG_SEGTREE)
return true;
return false;