diff options
author | Patrick McHardy <kaber@trash.net> | 2012-12-14 17:39:22 +0100 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2012-12-14 17:39:22 +0100 |
commit | a5dadd72bef79d92c14271fb8718a13f0e7f3814 (patch) | |
tree | 7ca8daa07c624e51f59de8962e9a7b2467c3b3b2 /src/rule.c | |
parent | 1c494b5302b285d6674478a3555b63403bebdcb0 (diff) |
chains: add chain rename support
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/rule.c')
-rw-r--r-- | src/rule.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -1,5 +1,5 @@ /* - * 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 @@ -332,6 +332,7 @@ void cmd_free(struct cmd *cmd) BUG("invalid command object type %u\n", cmd->obj); } } + xfree(cmd->arg); xfree(cmd); } @@ -524,6 +525,31 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *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) { @@ -535,6 +561,8 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd) 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); } |