extern int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h,
const struct chain *chain);
+extern int netlink_rename_chain(struct netlink_ctx *ctx, const struct handle *h,
+ const char *name);
extern int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h);
extern int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h);
* @CMD_DELETE: delete object
* @CMD_LIST: list container
* @CMD_FLUSH: flush container
+ * @CMD_RENAME: rename object
*/
enum cmd_ops {
CMD_INVALID,
CMD_DELETE,
CMD_LIST,
CMD_FLUSH,
+ CMD_RENAME,
};
/**
* @obj: object type to perform operation on
* @handle: handle for operations working without full objects
* @union: object
+ * @arg: argument data
*/
struct cmd {
struct list_head list;
struct chain *chain;
struct table *table;
};
+ const void *arg;
};
extern struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
return cmd_evaluate_delete(ctx, cmd);
case CMD_LIST:
case CMD_FLUSH:
+ case CMD_RENAME:
return 0;
default:
BUG("invalid command operation %u\n", cmd->op);
/*
- * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2008-2012 Patrick McHardy <kaber@trash.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
memory_allocation_error();
nfnl_nft_chain_set_family(nlc, h->family);
nfnl_nft_chain_set_table(nlc, h->table, strlen(h->table) + 1);
+ if (h->handle != 0)
+ nfnl_nft_chain_set_handle(nlc, h->handle);
if (h->chain != NULL)
nfnl_nft_chain_set_name(nlc, h->chain, strlen(h->chain) + 1);
return nlc;
return err;
}
+int netlink_rename_chain(struct netlink_ctx *ctx, const struct handle *h,
+ const char *name)
+{
+ struct nfnl_nft_chain *nlc;
+ int err;
+
+ nlc = alloc_nft_chain(h);
+ nfnl_nft_chain_set_name(nlc, name, strlen(name) + 1);
+ netlink_dump_object(OBJ_CAST(nlc));
+ err = nfnl_nft_chain_add(nf_sock, nlc, 0);
+ nfnl_nft_chain_put(nlc);
+
+ if (err < 0)
+ netlink_io_error(ctx, NULL, "Could not rename chain: %s",
+ nl_geterror(err));
+ return err;
+}
+
int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h)
{
struct nfnl_nft_chain *nlc;
chain = chain_alloc(nfnl_nft_chain_get_name(nlc));
chain->handle.family = nfnl_nft_chain_get_family(nlc);
chain->handle.table = xstrdup(nfnl_nft_chain_get_table(nlc));
+ chain->handle.handle = nfnl_nft_chain_get_handle(nlc);
chain->hooknum = nfnl_nft_chain_get_hooknum(nlc);
chain->priority = nfnl_nft_chain_get_priority(nlc);
list_add_tail(&chain->list, &ctx->list);
/*
- * Copyright (c) 2007-2008 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2007-2012 Patrick McHardy <kaber@trash.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
%token DELETE "delete"
%token LIST "list"
%token FLUSH "flush"
+%token RENAME "rename"
%token DESCRIBE "describe"
%token ACCEPT "accept"
%type <cmd> line
%destructor { cmd_free($$); } line
-%type <cmd> base_cmd add_cmd delete_cmd list_cmd flush_cmd
-%destructor { cmd_free($$); } base_cmd add_cmd delete_cmd list_cmd flush_cmd
+%type <cmd> base_cmd add_cmd delete_cmd list_cmd flush_cmd rename_cmd
+%destructor { cmd_free($$); } base_cmd add_cmd delete_cmd list_cmd flush_cmd rename_cmd
%type <handle> table_spec chain_spec chain_identifier ruleid_spec
%destructor { handle_free(&$$); } table_spec chain_spec chain_identifier ruleid_spec
| DELETE delete_cmd { $$ = $2; }
| LIST list_cmd { $$ = $2; }
| FLUSH flush_cmd { $$ = $2; }
+ | RENAME rename_cmd { $$ = $2; }
| DESCRIBE primary_expr
{
expr_describe($2);
}
;
+rename_cmd : CHAIN chain_spec identifier
+ {
+ $$ = cmd_alloc(CMD_RENAME, CMD_OBJ_CHAIN, &$2, NULL);
+ $$->arg = $3;
+ }
+ ;
+
table_block_alloc : /* empty */
{
$$ = table_alloc();
/*
- * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2008-2012 Patrick McHardy <kaber@trash.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
BUG("invalid command object type %u\n", cmd->obj);
}
}
+ xfree(cmd->arg);
xfree(cmd);
}
return 0;
}
+static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
+{
+ struct table *table;
+ struct chain *chain;
+ int err;
+
+ table = table_alloc();
+ handle_merge(&table->handle, &cmd->handle);
+ table_add_hash(table);
+
+ switch (cmd->obj) {
+ case CMD_OBJ_CHAIN:
+ err = netlink_get_chain(ctx, &cmd->handle);
+ if (err < 0)
+ return err;
+ list_splice_tail_init(&ctx->list, &table->chains);
+ chain = chain_lookup(table, &cmd->handle);
+
+ return netlink_rename_chain(ctx, &chain->handle, cmd->arg);
+ default:
+ BUG("invalid command object type %u\n", cmd->obj);
+ }
+ return 0;
+}
+
int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
{
switch (cmd->op) {
return do_command_list(ctx, cmd);
case CMD_FLUSH:
return do_command_flush(ctx, cmd);
+ case CMD_RENAME:
+ return do_command_rename(ctx, cmd);
default:
BUG("invalid command object type %u\n", cmd->obj);
}
"delete" { return DELETE; }
"list" { return LIST; }
"flush" { return FLUSH; }
+"rename" { return RENAME; }
"counter" { return COUNTER; }