mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-06 04:55:22 +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 *
|
static virNWFilterRuleDef *
|
||||||
virNWFilterRuleParse(xmlNodePtr node)
|
virNWFilterRuleParse(xmlNodePtr node)
|
||||||
{
|
{
|
||||||
g_autofree char *action = NULL;
|
|
||||||
g_autofree char *direction = NULL;
|
|
||||||
g_autofree char *prio = NULL;
|
g_autofree char *prio = NULL;
|
||||||
g_autofree char *statematch = NULL;
|
g_autofree char *statematch = NULL;
|
||||||
bool found;
|
bool found;
|
||||||
@ -2386,38 +2384,16 @@ virNWFilterRuleParse(xmlNodePtr node)
|
|||||||
|
|
||||||
ret = g_new0(virNWFilterRuleDef, 1);
|
ret = g_new0(virNWFilterRuleDef, 1);
|
||||||
|
|
||||||
action = virXMLPropString(node, "action");
|
|
||||||
direction = virXMLPropString(node, "direction");
|
|
||||||
prio = virXMLPropString(node, "priority");
|
prio = virXMLPropString(node, "priority");
|
||||||
statematch = virXMLPropString(node, "statematch");
|
statematch = virXMLPropString(node, "statematch");
|
||||||
|
|
||||||
if (!action) {
|
if (virXMLPropEnum(node, "action", virNWFilterRuleActionTypeFromString,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
VIR_XML_PROP_REQUIRED, &ret->action) < 0)
|
||||||
"%s",
|
|
||||||
_("rule node requires action attribute"));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if ((ret->action = virNWFilterRuleActionTypeFromString(action)) < 0) {
|
if (virXMLPropEnum(node, "direction", virNWFilterRuleDirectionTypeFromString,
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
VIR_XML_PROP_REQUIRED, &ret->tt) < 0)
|
||||||
"%s",
|
|
||||||
_("unknown rule action attribute value"));
|
|
||||||
return NULL;
|
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;
|
ret->priority = MAX_RULE_PRIORITY / 2;
|
||||||
|
|
||||||
|
@ -446,8 +446,8 @@ typedef struct _virNWFilterRuleDef virNWFilterRuleDef;
|
|||||||
struct _virNWFilterRuleDef {
|
struct _virNWFilterRuleDef {
|
||||||
virNWFilterRulePriority priority;
|
virNWFilterRulePriority priority;
|
||||||
virNWFilterRuleFlags flags;
|
virNWFilterRuleFlags flags;
|
||||||
int action; /* virNWFilterRuleActionType */
|
virNWFilterRuleActionType action;
|
||||||
int tt; /* virNWFilterRuleDirectionType */
|
virNWFilterRuleDirectionType tt;
|
||||||
virNWFilterRuleProtocolType prtclType;
|
virNWFilterRuleProtocolType prtclType;
|
||||||
union {
|
union {
|
||||||
ethHdrFilterDef ethHdrFilter;
|
ethHdrFilterDef ethHdrFilter;
|
||||||
|
@ -2361,6 +2361,11 @@ ebtablesCreateRuleInstance(virFirewall *fw,
|
|||||||
target = virNWFilterJumpTargetTypeToString(
|
target = virNWFilterJumpTargetTypeToString(
|
||||||
VIR_NWFILTER_RULE_ACTION_DROP);
|
VIR_NWFILTER_RULE_ACTION_DROP);
|
||||||
break;
|
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:
|
default:
|
||||||
target = virNWFilterJumpTargetTypeToString(rule->action);
|
target = virNWFilterJumpTargetTypeToString(rule->action);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user