summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 104eeb9)
raw | patch | inline | side by side (parent: 104eeb9)
author | Marc Falzon <marc@falzon.me> | |
Tue, 1 Oct 2013 16:53:39 +0000 (18:53 +0200) | ||
committer | Marc Falzon <marc@falzon.me> | |
Tue, 1 Oct 2013 16:53:39 +0000 (18:53 +0200) |
This patch allows appending rules/targets to an existing chain instead
of overwriting it. This way, it is possible to split filter chains
definition among several files.
of overwriting it. This way, it is possible to split filter chains
definition among several files.
src/filter_chain.c | patch | blob | history |
diff --git a/src/filter_chain.c b/src/filter_chain.c
index 7d8369b901def7d9633e78e6c73de5b14cc26f92..57bcc9bcba5dc865c5d9bafd82892a6f4a7b7ed6 100644 (file)
--- a/src/filter_chain.c
+++ b/src/filter_chain.c
static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
{
- fc_chain_t *chain;
+ fc_chain_t *chain = NULL;
int status = 0;
int i;
+ int new_chain = 1;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
return (-1);
}
- chain = (fc_chain_t *) malloc (sizeof (*chain));
+ if (chain_list_head != NULL)
+ {
+ if ((chain = fc_chain_get_by_name (ci->values[0].value.string)))
+ new_chain = 0;
+ }
+
if (chain == NULL)
{
- ERROR ("fc_config_add_chain: malloc failed.");
- return (-1);
+ chain = (fc_chain_t *) malloc (sizeof (*chain));
+ if (chain == NULL)
+ {
+ ERROR ("fc_config_add_chain: malloc failed.");
+ return (-1);
+ }
+ memset (chain, 0, sizeof (*chain));
+ sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
+ chain->rules = NULL;
+ chain->targets = NULL;
+ chain->next = NULL;
}
- memset (chain, 0, sizeof (*chain));
- sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
- chain->rules = NULL;
- chain->targets = NULL;
- chain->next = NULL;
for (i = 0; i < ci->children_num; i++)
{
if (chain_list_head != NULL)
{
+ if (!new_chain)
+ return (0);
+
fc_chain_t *ptr;
ptr = chain_list_head;