summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2012-12-14 17:39:22 +0100
committerPatrick McHardy <kaber@trash.net>2012-12-14 17:39:22 +0100
commita5dadd72bef79d92c14271fb8718a13f0e7f3814 (patch)
tree7ca8daa07c624e51f59de8962e9a7b2467c3b3b2 /src/rule.c
parent1c494b5302b285d6674478a3555b63403bebdcb0 (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.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/rule.c b/src/rule.c
index 61e16e75..f671117d 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -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);
}