mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-31 18:15:25 +00:00
virNWFilterRuleDef: Turn 'action' and 'tt' into proper enum types
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>
This commit is contained in:
parent
43f280cc65
commit
f0c5da0f24
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user