};
struct nft_ctx {
+ const char *include_paths[INCLUDE_PATHS_MAX];
+ unsigned int num_include_paths;
struct output_ctx output;
bool check;
struct nft_cache cache;
extern unsigned int max_errors;
extern unsigned int debug_level;
-extern const char *include_paths[INCLUDE_PATHS_MAX];
enum nftables_exit_codes {
NFT_EXIT_SUCCESS = 0,
extern void parser_init(struct mnl_socket *nf_sock, struct nft_cache *cache,
struct parser_state *state, struct list_head *msgs);
-extern int nft_parse(void *, struct parser_state *state);
+extern int nft_parse(struct nft_ctx *ctx, void *, struct parser_state *state);
extern void *scanner_init(struct parser_state *state);
extern void scanner_destroy(struct parser_state *state);
extern int scanner_read_file(void *scanner, const char *filename,
const struct location *loc);
-extern int scanner_include_file(void *scanner, const char *filename,
+extern int scanner_include_file(struct nft_ctx *ctx, void *scanner,
+ const char *filename,
const struct location *loc);
extern void scanner_push_buffer(void *scanner,
const struct input_descriptor *indesc,
unsigned int debug_level;
#endif
-const char *include_paths[INCLUDE_PATHS_MAX] = { DEFAULT_INCLUDE_PATH };
-static unsigned int num_include_paths = 1;
-
enum opt_vals {
OPT_HELP = 'h',
OPT_VERSION = 'v',
struct cmd *cmd, *next;
int ret;
- ret = nft_parse(scanner, state);
+ ret = nft_parse(nft, scanner, state);
if (ret != 0 || state->nerrs > 0) {
ret = -1;
goto err1;
mark_table_exit();
}
+static void nft_ctx_init(struct nft_ctx *nft)
+{
+ nft->include_paths[0] = DEFAULT_INCLUDE_PATH;
+ nft->num_include_paths = 1;
+}
+
int main(int argc, char * const *argv)
{
struct parser_state state;
init_list_head(&nft.cache.list);
nft_init();
+ nft_ctx_init(&nft);
+
nf_sock = netlink_open_sock();
while (1) {
val = getopt_long(argc, argv, OPTSTRING, options, NULL);
interactive = true;
break;
case OPT_INCLUDEPATH:
- if (num_include_paths >= INCLUDE_PATHS_MAX) {
+ if (nft.num_include_paths >= INCLUDE_PATHS_MAX) {
fprintf(stderr, "Too many include paths "
"specified, max. %u\n",
INCLUDE_PATHS_MAX - 1);
exit(NFT_EXIT_FAILURE);
}
- include_paths[num_include_paths++] = optarg;
+ nft.include_paths[nft.num_include_paths++] = optarg;
break;
case OPT_NUMERIC:
if (++nft.output.numeric > NUMERIC_ALL) {
state->ectx.nf_sock = nf_sock;
}
-static void yyerror(struct location *loc, void *scanner,
+static void yyerror(struct location *loc, struct nft_ctx *nft, void *scanner,
struct parser_state *state, const char *s)
{
erec_queue(error(loc, "%s", s), state->msgs);
%name-prefix "nft_"
%debug
%pure-parser
+%parse-param { struct nft_ctx *nft }
%parse-param { void *scanner }
%parse-param { struct parser_state *state }
%lex-param { scanner }
common_block : INCLUDE QUOTED_STRING stmt_seperator
{
- if (scanner_include_file(scanner, $2, &@$) < 0) {
+ if (scanner_include_file(nft, scanner, $2, &@$) < 0) {
xfree($2);
YYERROR;
}
filename[0] != '/');
}
-int scanner_include_file(void *scanner, const char *filename,
- const struct location *loc)
+int scanner_include_file(struct nft_ctx *nft, void *scanner,
+ const char *filename, const struct location *loc)
{
struct parser_state *state = yyget_extra(scanner);
struct error_record *erec;
if (search_in_include_path(filename)) {
for (i = 0; i < INCLUDE_PATHS_MAX; i++) {
- if (include_paths[i] == NULL)
+ if (nft->include_paths[i] == NULL)
break;
ret = snprintf(buf, sizeof(buf), "%s/%s",
- include_paths[i], filename);
+ nft->include_paths[i], filename);
if (ret < 0 || ret >= PATH_MAX) {
erec = error(loc, "Too long file path \"%s/%s\"\n",
- include_paths[i], filename);
+ nft->include_paths[i], filename);
erec_queue(erec, state->msgs);
return -1;
}