You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

207 lines
7.0 KiB

From 2e9c18d6dc04f79fab9ce46e16d69635d2ace48f Mon Sep 17 00:00:00 2001
From: Thilo Boehm <tboehm@linux.vnet.ibm.com>
Date: Wed, 13 Nov 2013 19:07:10 +0100
Subject: [PATCH 37/60] FilterEntry: Fix endianness issues
A number of CIM properties was set in an endianness-unsafe manner
leading to failures on big endian systems.
Signed-off-by: Thilo Boehm <tboehm@linux.vnet.ibm.com>
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
---
src/Virt_FilterEntry.c | 53 ++++++++++++++++++++++++++------------------------
src/Virt_FilterEntry.h | 2 +-
src/Virt_FilterList.c | 3 ++-
3 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
index b7042da..ab4a512 100644
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -59,8 +59,8 @@ struct rule_data_t {
const char *dstportend;
};
-static int octets_from_mac(const char * s, unsigned int *buffer,
- unsigned int size)
+static int octets_from_mac(const char * s, uint8_t *buffer,
+ unsigned int size)
{
unsigned int _buffer[6];
unsigned int i, n = 0;
@@ -86,8 +86,8 @@ static int octets_from_mac(const char * s, unsigned int *buffer,
return n;
}
-static int octets_from_ip(const char * s, unsigned int *buffer,
- unsigned int size)
+static int octets_from_ip(const char * s, uint8_t *buffer,
+ unsigned int size)
{
struct in6_addr addr;
unsigned int family = 0;
@@ -116,7 +116,8 @@ static int octets_from_ip(const char * s, unsigned int *buffer,
return n;
}
-static CMPIArray *octets_to_cmpi(const CMPIBroker *broker, unsigned int *bytes, int size)
+static CMPIArray *octets_to_cmpi(const CMPIBroker *broker, uint8_t *bytes,
+ int size)
{
CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIArray *array = NULL;
@@ -173,7 +174,7 @@ static char *cidr_to_str(const char *cidr)
return ret;
}
-static int convert_direction(const char *s)
+static uint16_t convert_direction(const char *s)
{
enum {NOT_APPLICABLE, INPUT, OUTPUT, BOTH} direction = NOT_APPLICABLE;
@@ -189,7 +190,7 @@ static int convert_direction(const char *s)
return direction;
}
-int convert_priority(const char *s)
+int16_t convert_priority(const char *s)
{
if (s == NULL)
return 0;
@@ -197,7 +198,7 @@ int convert_priority(const char *s)
return atoi(s);
}
-static int convert_action(const char *s)
+static uint16_t convert_action(const char *s)
{
enum {NONE=0, ACCEPT, DENY, REJECT, RETURN, CONTINUE} action = NONE;
@@ -216,7 +217,7 @@ static int convert_action(const char *s)
return action;
}
-static unsigned long convert_protocol_id(const char *s)
+static uint16_t convert_protocol_id(const char *s)
{
enum {NONE = 0, IPV4 = 2048, ARP = 2054, RARP = 32821, IPV6 = 34525} id = NONE;
@@ -239,7 +240,7 @@ static void convert_mac_rule_to_instance(
CMPIInstance *inst,
const CMPIBroker *broker)
{
- unsigned int bytes[48];
+ uint8_t bytes[48];
unsigned int size = 0;
CMPIArray *array = NULL;
@@ -280,7 +281,7 @@ static void convert_mac_rule_to_instance(
(CMPIValue *)&array, CMPI_uint8A);
if (rule->var.mac.protocol_id != NULL) {
- unsigned long n = convert_protocol_id(rule->var.mac.protocol_id);
+ uint16_t n = convert_protocol_id(rule->var.mac.protocol_id);
/* Unknown protocolid string. Try converting from hexadecimal value */
if (n == 0)
@@ -366,18 +367,19 @@ static void convert_ip_rule_to_instance(
CMPIInstance *inst,
const CMPIBroker *broker)
{
- unsigned int bytes[48];
+ uint8_t bytes[48];
unsigned int size = 0;
- unsigned int n = 0;
+ uint8_t ipver_num = 0;
+ uint16_t port_num = 0;
CMPIArray *array = NULL;
struct rule_data_t rule_data;
if (strstr(rule->protocol_id, "v6"))
- n = 6;
+ ipver_num = 6;
else
- n = 4;
+ ipver_num = 4;
- CMSetProperty(inst, "HdrIPVersion",(CMPIValue *)&n, CMPI_uint8);
+ CMSetProperty(inst, "HdrIPVersion",(CMPIValue *)&ipver_num, CMPI_uint8);
fill_rule_data(rule, &rule_data);
@@ -480,27 +482,27 @@ static void convert_ip_rule_to_instance(
}
if (rule_data.srcportstart) {
- n = atoi(rule_data.srcportstart);
+ port_num = atoi(rule_data.srcportstart);
CMSetProperty(inst, "HdrSrcPortStart",
- (CMPIValue *)&n, CMPI_uint16);
+ (CMPIValue *)&port_num, CMPI_uint16);
}
if (rule_data.srcportend) {
- n = atoi(rule_data.srcportend);
+ port_num = atoi(rule_data.srcportend);
CMSetProperty(inst, "HdrSrcPortEnd",
- (CMPIValue *)&n, CMPI_uint16);
+ (CMPIValue *)&port_num, CMPI_uint16);
}
if (rule_data.dstportstart) {
- n = atoi(rule_data.dstportstart);
+ port_num = atoi(rule_data.dstportstart);
CMSetProperty(inst, "HdrDestPortStart",
- (CMPIValue *)&n, CMPI_uint16);
+ (CMPIValue *)&port_num, CMPI_uint16);
}
if (rule_data.dstportend) {
- n = atoi(rule_data.dstportend);
+ port_num = atoi(rule_data.dstportend);
CMSetProperty(inst, "HdrDestPortEnd",
- (CMPIValue *)&n, CMPI_uint16);
+ (CMPIValue *)&port_num, CMPI_uint16);
}
}
@@ -515,7 +517,8 @@ static CMPIInstance *convert_rule_to_instance(
const char *sys_name = NULL;
const char *sys_ccname = NULL;
const char *basename = NULL;
- int action, direction, priority = 0;
+ uint16_t action, direction;
+ int16_t priority;
void (*convert_f)(struct acl_rule*, CMPIInstance*, const CMPIBroker*);
diff --git a/src/Virt_FilterEntry.h b/src/Virt_FilterEntry.h
index 5057fb0..0589aa0 100644
--- a/src/Virt_FilterEntry.h
+++ b/src/Virt_FilterEntry.h
@@ -77,7 +77,7 @@ CMPIStatus instance_from_rule(
*
* @param s A pointer to a string representing the priority
*/
-int convert_priority(const char *s);
+int16_t convert_priority(const char *s);
#endif
/*
diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c
index 7026d8b..b248004 100644
--- a/src/Virt_FilterList.c
+++ b/src/Virt_FilterList.c
@@ -45,7 +45,8 @@ static CMPIInstance *convert_filter_to_instance(
CMPIInstance *inst = NULL;
const char *sys_name = NULL;
const char *sys_ccname = NULL;
- int direction = 0, priority;
+ uint16_t direction = 0;
+ int16_t priority;
inst = get_typed_instance(broker,
CLASSNAME(reference),
--
2.1.0