From f0c5da0f241fb218f97776b87c3aed41dfa82f0d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 16 Feb 2023 13:14:45 +0100 Subject: [PATCH] virNWFilterRuleDef: Turn 'action' and 'tt' into proper enum types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert the fields to the proper types and use virXMLPropEnum for parsing. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/nwfilter_conf.c | 32 +++-------------------- src/conf/nwfilter_conf.h | 4 +-- src/nwfilter/nwfilter_ebiptables_driver.c | 5 ++++ 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 98a19f9e4b..13c6096fcd 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2373,8 +2373,6 @@ virNWFilterRuleDefFixup(virNWFilterRuleDef *rule) static virNWFilterRuleDef * virNWFilterRuleParse(xmlNodePtr node) { - g_autofree char *action = NULL; - g_autofree char *direction = NULL; g_autofree char *prio = NULL; g_autofree char *statematch = NULL; bool found; @@ -2386,38 +2384,16 @@ virNWFilterRuleParse(xmlNodePtr node) ret = g_new0(virNWFilterRuleDef, 1); - action = virXMLPropString(node, "action"); - direction = virXMLPropString(node, "direction"); prio = virXMLPropString(node, "priority"); statematch = virXMLPropString(node, "statematch"); - if (!action) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", - _("rule node requires action attribute")); + if (virXMLPropEnum(node, "action", virNWFilterRuleActionTypeFromString, + VIR_XML_PROP_REQUIRED, &ret->action) < 0) return NULL; - } - if ((ret->action = virNWFilterRuleActionTypeFromString(action)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", - _("unknown rule action attribute value")); + if (virXMLPropEnum(node, "direction", virNWFilterRuleDirectionTypeFromString, + VIR_XML_PROP_REQUIRED, &ret->tt) < 0) return NULL; - } - - if (!direction) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", - _("rule node requires direction attribute")); - return NULL; - } - - if ((ret->tt = virNWFilterRuleDirectionTypeFromString(direction)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", - _("unknown rule direction attribute value")); - return NULL; - } ret->priority = MAX_RULE_PRIORITY / 2; diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 7c09b3bcb9..22c2fb51f0 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -446,8 +446,8 @@ typedef struct _virNWFilterRuleDef virNWFilterRuleDef; struct _virNWFilterRuleDef { virNWFilterRulePriority priority; virNWFilterRuleFlags flags; - int action; /* virNWFilterRuleActionType */ - int tt; /* virNWFilterRuleDirectionType */ + virNWFilterRuleActionType action; + virNWFilterRuleDirectionType tt; virNWFilterRuleProtocolType prtclType; union { ethHdrFilterDef ethHdrFilter; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 99a74a60e5..1c5da2ae05 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2361,6 +2361,11 @@ ebtablesCreateRuleInstance(virFirewall *fw, target = virNWFilterJumpTargetTypeToString( VIR_NWFILTER_RULE_ACTION_DROP); break; + case VIR_NWFILTER_RULE_ACTION_DROP: + case VIR_NWFILTER_RULE_ACTION_ACCEPT: + case VIR_NWFILTER_RULE_ACTION_RETURN: + case VIR_NWFILTER_RULE_ACTION_CONTINUE: + case VIR_NWFILTER_RULE_ACTION_LAST: default: target = virNWFilterJumpTargetTypeToString(rule->action); }