]> xenbits.xensource.com Git - libvirt.git/commitdiff
virNWFilterRuleDef: Turn 'action' and 'tt' into proper enum types
authorPeter Krempa <pkrempa@redhat.com>
Thu, 16 Feb 2023 12:14:45 +0000 (13:14 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Jun 2023 11:23:06 +0000 (13:23 +0200)
Convert the fields to the proper types and use virXMLPropEnum for
parsing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/nwfilter_conf.c
src/conf/nwfilter_conf.h
src/nwfilter/nwfilter_ebiptables_driver.c

index 98a19f9e4b1870186e67edbb1fc6e5ea95251d74..13c6096fcdd7e8d1d5cb90a2b3d549c27676d67c 100644 (file)
@@ -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;
 
index 7c09b3bcb9f6e67ecf378d5272a7441027caca55..22c2fb51f01b6ee3b4c5725299ff45da0421befc 100644 (file)
@@ -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;
index 99a74a60e5ff0a15658f5562675760f6b99b799a..1c5da2ae058b01e79c1ee2002d218f934995ff07 100644 (file)
@@ -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);
     }