From 78629cf5310874fe02f1fd76c9ad6016724358f7 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 7 Mar 2014 16:56:56 +0000 Subject: [PATCH] Remove data structure holding list of ebtables rules When adding/removing ebtables rules, the code would keep an array of all rules in memory. This list of rules was never used for any purpose and would be lost if libvirtd restarted. Delete all the unused code. Signed-off-by: Daniel P. Berrange --- src/util/virebtables.c | 88 ------------------------------------------ src/util/virebtables.h | 11 ------ 2 files changed, 99 deletions(-) diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 6f28b4b9c2..13ab51eb99 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -97,83 +97,13 @@ enum { INSERT }; -static void -ebtRuleFree(ebtRule *rule) -{ - VIR_FREE(rule->rule); - - if (rule->argv) { - size_t i = 0; - while (rule->argv[i]) - VIR_FREE(rule->argv[i++]); - VIR_FREE(rule->argv); - } -} - -static int -ebtRulesAppend(ebtRules *rules, - char *rule, - char **argv, - int command_idx) -{ - if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) { - size_t i = 0; - while (argv[i]) - VIR_FREE(argv[i++]); - VIR_FREE(argv); - return ENOMEM; - } - - rules->rules[rules->nrules].rule = rule; - rules->rules[rules->nrules].argv = argv; - rules->rules[rules->nrules].command_idx = command_idx; - - rules->nrules++; - - return 0; -} - -static int -ebtRulesRemove(ebtRules *rules, - char *rule) -{ - size_t i; - - for (i = 0; i < rules->nrules; i++) - if (STREQ(rules->rules[i].rule, rule)) - break; - - if (i >= rules->nrules) - return EINVAL; - - ebtRuleFree(&rules->rules[i]); - - memmove(&rules->rules[i], - &rules->rules[i+1], - (rules->nrules - i - 1) * sizeof(ebtRule)); - - rules->nrules--; - - return 0; -} static void ebtRulesFree(ebtRules *rules) { - size_t i; - VIR_FREE(rules->table); VIR_FREE(rules->chain); - if (rules->rules) { - for (i = 0; i < rules->nrules; i++) - ebtRuleFree(&rules->rules[i]); - - VIR_FREE(rules->rules); - - rules->nrules = 0; - } - VIR_FREE(rules); } @@ -192,9 +122,6 @@ ebtRulesNew(const char *table, if (VIR_STRDUP(rules->chain, chain) < 0) goto error; - rules->rules = NULL; - rules->nrules = 0; - return rules; error: @@ -208,7 +135,6 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) va_list args; int retval = ENOMEM; char **argv; - char *rule = NULL; const char *s; int n, command_idx; @@ -273,9 +199,6 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) va_end(args); - if (!(rule = virArgvToString((const char **) &argv[command_idx]))) - goto error; - if (action == REMOVE) { VIR_FREE(argv[command_idx]); if (VIR_STRDUP(argv[command_idx], "--delete") < 0) @@ -287,18 +210,7 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) goto error; } - if (action == ADD || action == CREATE || action == POLICY || - action == INSERT) { - retval = ebtRulesAppend(rules, rule, argv, command_idx); - rule = NULL; - argv = NULL; - } else { - retval = ebtRulesRemove(rules, rule); - } - error: - VIR_FREE(rule); - if (argv) { n = 0; while (argv[n]) diff --git a/src/util/virebtables.h b/src/util/virebtables.h index 330b441a48..f9bd6e6635 100644 --- a/src/util/virebtables.h +++ b/src/util/virebtables.h @@ -28,21 +28,10 @@ # include "virmacaddr.h" -typedef struct -{ - char *rule; - char **argv; - int command_idx; -} ebtRule; - typedef struct { char *table; char *chain; - - int nrules; - ebtRule *rules; - } ebtRules; typedef struct _ebtablesContext ebtablesContext; -- 2.47.2