On Mon, 2012-01-30 at 21:57 -0200, Eduardo Lima (Etrunko) wrote:
> 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'?
The problem is that this value can be either a pre-define string (ipv4,
ipv6, arp, rarp)or an hexadecimal value in string form.
The idea here is first try to match the value with one of those pre
defined values calling convert_protocol_id() and if it fails, we try
converting the string to hexadecimal value. In case it fails it will
return 0.
Makes sense?
--
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima(a)br.ibm.com