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;