From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
The HdrProtocolID8021 property expects an unsigned int value, while libvirt
network filters specification allows the corresponding value for this property
(protocolid) to be written as a string (ipv4, ipv6, arp, rarp).
The corresponding values for the protocolid strings can be found in:
http://www.iana.org/assignments/ethernet-numbers
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
src/Virt_FilterEntry.c | 26 ++++++++++++++++++++++++--
1 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
index 2ff354a..126615b 100644
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -219,6 +219,24 @@ static int convert_action(const char *s)
return action;
}
+static unsigned long convert_protocol_id(const char *s)
+{
+ enum {NONE = 0, IPV4 = 2048, ARP = 2054, RARP = 32821, IPV6 = 34525} id = NONE;
+
+ if (s != NULL) {
+ if (STREQC(s, "ipv4"))
+ id = IPV4;
+ else if (STREQC(s, "arp"))
+ id = ARP;
+ else if (STREQC(s, "rarp"))
+ id = RARP;
+ else if (STREQC(s, "ipv6"))
+ id = IPV6;
+ }
+
+ return id;
+}
+
static void convert_mac_rule_to_instance(
struct acl_rule *rule,
CMPIInstance *inst,
@@ -265,8 +283,12 @@ static void convert_mac_rule_to_instance(
(CMPIValue *)&array, CMPI_uint8A);
if (rule->var.mac.protocol_id != NULL) {
- unsigned long n = strtoul(rule->var.mac.protocol_id,
- NULL, 16);
+ unsigned long n = convert_protocol_id(rule->var.mac.protocol_id);
+
+ /* Unknown protocolid string. Try converting from hexadecimal value */
+ if (n == 0)
+ n = strtoul(rule->var.mac.protocol_id, NULL, 16);
+
CMSetProperty(inst, "HdrProtocolID8021",
(CMPIValue *)&n, CMPI_uint16);
Why are we converting to hex if unknown protocol? Can we just use "0"
to indicate that its 'unknown'?
-Sharad