From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
According to libvirt network filter specification, since verstion 0.9.8,
filter lists can be assigned priorities.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
libxkutil/acl_parsing.c | 2 ++
libxkutil/acl_parsing.h | 1 +
schema/FilterList.mof | 9 +++++++++
src/Makefile.am | 4 ++--
src/Virt_FilterEntry.c | 11 ++++-------
src/Virt_FilterEntry.h | 6 ++++++
src/Virt_FilterList.c | 5 ++++-
7 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c
index 9c4b4b2..2930928 100644
--- a/libxkutil/acl_parsing.c
+++ b/libxkutil/acl_parsing.c
@@ -134,6 +134,7 @@ void cleanup_filter(struct acl_filter *filter)
free(filter->uuid);
free(filter->name);
free(filter->chain);
+ free(filter->priority);
for (i = 0; i < filter->rule_ct; i++)
cleanup_rule(filter->rules[i]);
@@ -345,6 +346,7 @@ static int parse_acl_filter(xmlNode *fnode, struct acl_filter
*filter)
goto err;
filter->chain = get_attr_value(fnode, "chain");
+ filter->priority = get_attr_value(fnode, "priority");
for (child = fnode->children; child != NULL; child = child->next) {
if (XSTREQ(child->name, "uuid")) {
diff --git a/libxkutil/acl_parsing.h b/libxkutil/acl_parsing.h
index 5b99175..5abcb02 100644
--- a/libxkutil/acl_parsing.h
+++ b/libxkutil/acl_parsing.h
@@ -148,6 +148,7 @@ struct acl_filter {
char *uuid;
char *name;
char *chain;
+ char *priority;
struct acl_rule **rules;
int rule_ct;
diff --git a/schema/FilterList.mof b/schema/FilterList.mof
index a98c14d..7339db6 100644
--- a/schema/FilterList.mof
+++ b/schema/FilterList.mof
@@ -1,4 +1,13 @@
// Copyright IBM Corp. 2011
class KVM_FilterList : CIM_FilterList
{
+ [Description("The priority of the filter controls the order in which "
+ "the filter will be, instantiated relative to other filters. "
+ "Filters with lower value will be instantiated and therefore "
+ "evaluated before rules with higher value. Valid values are "
+ "in the range of -1000 to 1000. If this attribute is not "
+ "provided, the value 500 will automatically be assigned."),
+ MinValue(-1000),
+ MaxValue(1000)]
+ sint16 Priority = 500;
};
diff --git a/src/Makefile.am b/src/Makefile.am
index c28dc9a..3f90926 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -255,9 +255,9 @@ libVirt_FilterEntry_la_DEPENDENCIES = libVirt_HostSystem.la
libVirt_FilterEntry_la_SOURCES = Virt_FilterEntry.c
libVirt_FilterEntry_la_LIBADD = -lVirt_HostSystem
-libVirt_FilterList_la_DEPENDENCIES = libVirt_HostSystem.la
+libVirt_FilterList_la_DEPENDENCIES = libVirt_HostSystem.la libVirt_FilterEntry.la
libVirt_FilterList_la_SOURCES = Virt_FilterList.c
-libVirt_FilterList_la_LIBADD = -lVirt_HostSystem
+libVirt_FilterList_la_LIBADD = -lVirt_HostSystem -lVirt_FilterEntry
libVirt_EntriesInFilterList_la_DEPENDENCIES = libVirt_FilterEntry.la
libVirt_FilterList.la
libVirt_EntriesInFilterList_la_SOURCES = Virt_EntriesInFilterList.c
diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
index a4fa4cd..c058b5e 100644
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -192,15 +192,12 @@ static int convert_direction(const char *s)
return direction;
}
-static int convert_priority(const char *s)
+int convert_priority(const char *s)
{
- int priority = 0;
-
- if (s != NULL) {
- priority = atoi(s);
- }
+ if (s == NULL)
+ return 0;
- return priority;
+ return atoi(s);
}
static int convert_action(const char *s)
diff --git a/src/Virt_FilterEntry.h b/src/Virt_FilterEntry.h
index 2fe17c4..a30f46d 100644
--- a/src/Virt_FilterEntry.h
+++ b/src/Virt_FilterEntry.h
@@ -72,6 +72,12 @@ CMPIStatus instance_from_rule(
struct acl_rule *rule,
CMPIInstance **instance);
+/**
+ * Convert a string representing the priority to corresponding integer value
+ *
+ * @param s A pointer to a string representing the priority
+ */
+int convert_priority(const char *s);
#endif
/*
diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c
index 5b1b6e8..9b5dbae 100644
--- a/src/Virt_FilterList.c
+++ b/src/Virt_FilterList.c
@@ -31,6 +31,7 @@
#include "Virt_FilterList.h"
#include "Virt_HostSystem.h"
+#include "Virt_FilterEntry.h"
const static CMPIBroker *_BROKER;
@@ -44,7 +45,7 @@ static CMPIInstance *convert_filter_to_instance(
CMPIInstance *inst = NULL;
const char *sys_name = NULL;
const char *sys_ccname = NULL;
- int direction = 0;
+ int direction = 0, priority;
inst = get_typed_instance(broker,
CLASSNAME(reference),
@@ -77,6 +78,8 @@ static CMPIInstance *convert_filter_to_instance(
CMPI_chars);
CMSetProperty(inst, "Direction", (CMPIValue *)&direction,
CMPI_uint16);
+ priority = convert_priority(filter->priority);
+ CMSetProperty(inst, "Priority", (CMPIValue *)&priority,
CMPI_sint16);
out:
return inst;
}
--
1.7.7.6