uint32_t flags;
};
+enum nftables_exit_codes {
+ NFT_EXIT_SUCCESS = 0,
+ NFT_EXIT_FAILURE = 1,
+ NFT_EXIT_NOMEM = 2,
+ NFT_EXIT_NONL = 3,
+};
+
struct input_descriptor;
struct location {
const struct input_descriptor *indesc;
*/
#define NFT_CTX_DEFAULT 0
-/**
- * Exit codes returned by nft_run_cmd_from_*()
- */
-enum nftables_exit_codes {
- NFT_EXIT_SUCCESS = 0,
- NFT_EXIT_FAILURE = 1,
- NFT_EXIT_NOMEM = 2,
- NFT_EXIT_NONL = 3,
-};
-
struct nft_ctx *nft_ctx_new(uint32_t flags);
void nft_ctx_free(struct nft_ctx *ctx);
int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen)
{
- int rc = NFT_EXIT_SUCCESS;
+ int rc = 0;
struct parser_state state;
LIST_HEAD(msgs);
void *scanner;
scanner_push_buffer(scanner, &indesc_cmdline, buf);
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
- rc = NFT_EXIT_FAILURE;
+ rc = -1;
fp = nft_ctx_set_output(nft, stderr);
erec_print_list(&nft->output, &msgs, nft->debug_mask);
rc = cache_update(nft->nf_sock, &nft->cache, CMD_INVALID, &msgs,
nft->debug_mask, &nft->output);
if (rc < 0)
- return NFT_EXIT_FAILURE;
+ return -1;
parser_init(nft->nf_sock, &nft->cache, &state,
&msgs, nft->debug_mask, &nft->output);
scanner = scanner_init(&state);
if (scanner_read_file(scanner, filename, &internal_location) < 0) {
- rc = NFT_EXIT_FAILURE;
+ rc = -1;
goto err;
}
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
- rc = NFT_EXIT_FAILURE;
+ rc = -1;
err:
fp = nft_ctx_set_output(nft, stderr);
erec_print_list(&nft->output, &msgs, nft->debug_mask);
switch (val) {
case OPT_HELP:
show_help(argv[0]);
- exit(NFT_EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
case OPT_VERSION:
printf("%s v%s (%s)\n",
PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
- exit(NFT_EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
case OPT_CHECK:
nft_ctx_set_dry_run(nft, true);
break;
fprintf(stderr,
"Failed to add include path '%s'\n",
optarg);
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
break;
case OPT_NUMERIC:
fprintf(stderr, "Too many numeric options "
"used, max. %u\n",
NFT_NUMERIC_ALL);
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
nft_ctx_output_set_numeric(nft, numeric + 1);
break;
if (i == array_size(debug_param)) {
fprintf(stderr, "invalid debug parameter `%s'\n",
optarg);
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
if (end == NULL)
nft_ctx_output_set_echo(nft, true);
break;
case OPT_INVALID:
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
}
strcat(buf, " ");
}
strcat(buf, "\n");
- rc = nft_run_cmd_from_buffer(nft, buf, len + 2);
+ rc = !!nft_run_cmd_from_buffer(nft, buf, len + 2);
} else if (filename != NULL) {
- rc = nft_run_cmd_from_filename(nft, filename);
+ rc = !!nft_run_cmd_from_filename(nft, filename);
} else if (interactive) {
if (cli_init(nft) < 0) {
fprintf(stderr, "%s: interactive CLI not supported in this build\n",
argv[0]);
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
- return 0;
+ return EXIT_SUCCESS;
} else {
fprintf(stderr, "%s: no command specified\n", argv[0]);
- exit(NFT_EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
xfree(buf);