#include <string.h>
static int nft_netlink(struct nft_ctx *nft,
- struct parser_state *state, struct list_head *msgs,
+ struct list_head *cmds, struct list_head *msgs,
struct mnl_socket *nf_sock)
{
uint32_t batch_seqnum, seqnum = 0;
LIST_HEAD(err_list);
int ret = 0;
- if (list_empty(&state->cmds))
+ if (list_empty(cmds))
return 0;
batch = mnl_batch_init();
batch_seqnum = mnl_batch_begin(batch, mnl_seqnum_alloc(&seqnum));
- list_for_each_entry(cmd, &state->cmds, list) {
+ list_for_each_entry(cmd, cmds, list) {
memset(&ctx, 0, sizeof(ctx));
ctx.msgs = msgs;
ctx.seqnum = cmd->seqnum = mnl_seqnum_alloc(&seqnum);
ret = netlink_batch_send(&ctx, &err_list);
list_for_each_entry_safe(err, tmp, &err_list, head) {
- list_for_each_entry(cmd, &state->cmds, list) {
+ list_for_each_entry(cmd, cmds, list) {
if (err->seqnum == cmd->seqnum ||
err->seqnum == batch_seqnum) {
netlink_io_error(&ctx, &cmd->location,
void *scanner, struct parser_state *state,
struct list_head *msgs)
{
- struct cmd *cmd, *next;
+ struct cmd *cmd;
int ret;
ret = nft_parse(nft, scanner, state);
goto err1;
}
- list_for_each_entry(cmd, &state->cmds, list)
+ list_for_each_entry(cmd, state->cmds, list)
nft_cmd_expand(cmd);
- ret = nft_netlink(nft, state, msgs, nf_sock);
+ ret = nft_netlink(nft, state->cmds, msgs, nf_sock);
err1:
- list_for_each_entry_safe(cmd, next, &state->cmds, list) {
- list_del(&cmd->list);
- cmd_free(cmd);
- }
-
return ret;
}
{
int rc = 0;
struct parser_state state;
+ struct cmd *cmd, *next;
LIST_HEAD(msgs);
+ LIST_HEAD(cmds);
size_t nlbuflen;
void *scanner;
char *nlbuf;
snprintf(nlbuf, nlbuflen, "%s\n", buf);
parser_init(nft->nf_sock, &nft->cache, &state,
- &msgs, nft->debug_mask, &nft->output);
+ &msgs, &cmds, nft->debug_mask, &nft->output);
scanner = scanner_init(&state);
scanner_push_buffer(scanner, &indesc_cmdline, nlbuf);
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
rc = -1;
+ list_for_each_entry_safe(cmd, next, &cmds, list) {
+ list_del(&cmd->list);
+ cmd_free(cmd);
+ }
erec_print_list(&nft->output, &msgs, nft->debug_mask);
scanner_destroy(scanner);
iface_cache_release();
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
{
struct parser_state state;
+ struct cmd *cmd, *next;
LIST_HEAD(msgs);
+ LIST_HEAD(cmds);
void *scanner;
int rc;
filename = "/dev/stdin";
parser_init(nft->nf_sock, &nft->cache, &state,
- &msgs, nft->debug_mask, &nft->output);
+ &msgs, &cmds, nft->debug_mask, &nft->output);
scanner = scanner_init(&state);
if (scanner_read_file(scanner, filename, &internal_location) < 0) {
rc = -1;
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
rc = -1;
err:
+ list_for_each_entry_safe(cmd, next, &cmds, list) {
+ list_del(&cmd->list);
+ cmd_free(cmd);
+ }
erec_print_list(&nft->output, &msgs, nft->debug_mask);
scanner_destroy(scanner);
iface_cache_release();
void parser_init(struct mnl_socket *nf_sock, struct nft_cache *cache,
struct parser_state *state, struct list_head *msgs,
- unsigned int debug_mask, struct output_ctx *octx)
+ struct list_head *cmds, unsigned int debug_mask,
+ struct output_ctx *octx)
{
memset(state, 0, sizeof(*state));
- init_list_head(&state->cmds);
init_list_head(&state->top_scope.symbols);
state->msgs = msgs;
+ state->cmds = cmds;
state->scopes[0] = scope_init(&state->top_scope, NULL);
state->ectx.cache = cache;
state->ectx.msgs = msgs;
if (++state->nerrs == nft->parser_max_errors)
YYABORT;
} else
- list_splice_tail(&list, &state->cmds);
+ list_splice_tail(&list, state->cmds);
}
}
;
if (++state->nerrs == nft->parser_max_errors)
YYABORT;
} else
- list_splice_tail(&list, &state->cmds);
+ list_splice_tail(&list, state->cmds);
}
if (state->nerrs)
YYABORT;