mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
Remove pointless nwIPAddress struct & void *casts
The nwIPAddress was simply a wrapper about virSocketAddr. Just use the latter directly, removing all the extra field de-references from code & helper APIs for parsing/formatting. Also remove all the redundant casts from strong types to void * and then immediately back to strong types. * src/conf/nwfilter_conf.h: Remove nwIPAddress * src/conf/nwfilter_conf.c, src/nwfilter/nwfilter_ebiptables_driver.c: Update to use virSocketAddr and remove void * casts.
This commit is contained in:
parent
f4b54aa027
commit
7ab7d17bfb
@ -1325,26 +1325,6 @@ virNWMACAddressParser(const char *input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
|
||||||
virNWIPv4AddressParser(const char *input,
|
|
||||||
nwIPAddressPtr output)
|
|
||||||
{
|
|
||||||
if (virSocketParseIpv4Addr(input, &output->addr) == -1)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool
|
|
||||||
virNWIPv6AddressParser(const char *input,
|
|
||||||
nwIPAddressPtr output)
|
|
||||||
{
|
|
||||||
if (virSocketParseIpv6Addr(input, &output->addr) == -1)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virNWFilterRuleDetailsParse(xmlNodePtr node,
|
virNWFilterRuleDetailsParse(xmlNodePtr node,
|
||||||
virNWFilterRuleDefPtr nwf,
|
virNWFilterRuleDefPtr nwf,
|
||||||
@ -1359,11 +1339,10 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
nwItemDesc *item;
|
nwItemDesc *item;
|
||||||
int int_val;
|
int int_val;
|
||||||
unsigned int uint_val;
|
unsigned int uint_val;
|
||||||
void *storage_ptr;
|
|
||||||
union data data;
|
union data data;
|
||||||
valueValidator validator;
|
valueValidator validator;
|
||||||
char *match = virXMLPropString(node, "match");
|
char *match = virXMLPropString(node, "match");
|
||||||
nwIPAddress ipaddr;
|
virSocketAddr ipaddr;
|
||||||
int base;
|
int base;
|
||||||
|
|
||||||
if (match && STREQ(match, "no"))
|
if (match && STREQ(match, "no"))
|
||||||
@ -1385,8 +1364,6 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
|
|
||||||
if (STRPREFIX(prop, "$")) {
|
if (STRPREFIX(prop, "$")) {
|
||||||
flags_set |= NWFILTER_ENTRY_ITEM_FLAG_HAS_VAR;
|
flags_set |= NWFILTER_ENTRY_ITEM_FLAG_HAS_VAR;
|
||||||
storage_ptr = NULL;
|
|
||||||
|
|
||||||
if (virNWFilterRuleDefAddVar(nwf,
|
if (virNWFilterRuleDefAddVar(nwf,
|
||||||
item,
|
item,
|
||||||
&prop[1]))
|
&prop[1]))
|
||||||
@ -1411,10 +1388,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
case DATATYPE_UINT8_HEX:
|
case DATATYPE_UINT8_HEX:
|
||||||
base = 16;
|
base = 16;
|
||||||
case DATATYPE_UINT8:
|
case DATATYPE_UINT8:
|
||||||
storage_ptr = &item->u.u8;
|
|
||||||
if (virStrToLong_ui(prop, NULL, base, &uint_val) >= 0) {
|
if (virStrToLong_ui(prop, NULL, base, &uint_val) >= 0) {
|
||||||
if (uint_val <= 0xff) {
|
if (uint_val <= 0xff) {
|
||||||
*(uint8_t *)storage_ptr = uint_val;
|
item->u.u8 = uint_val;
|
||||||
found = 1;
|
found = 1;
|
||||||
data.ui = uint_val;
|
data.ui = uint_val;
|
||||||
} else
|
} else
|
||||||
@ -1426,10 +1402,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
case DATATYPE_UINT16_HEX:
|
case DATATYPE_UINT16_HEX:
|
||||||
base = 16;
|
base = 16;
|
||||||
case DATATYPE_UINT16:
|
case DATATYPE_UINT16:
|
||||||
storage_ptr = &item->u.u16;
|
|
||||||
if (virStrToLong_ui(prop, NULL, base, &uint_val) >= 0) {
|
if (virStrToLong_ui(prop, NULL, base, &uint_val) >= 0) {
|
||||||
if (uint_val <= 0xffff) {
|
if (uint_val <= 0xffff) {
|
||||||
*(uint16_t *)storage_ptr = uint_val;
|
item->u.u16 = uint_val;
|
||||||
found = 1;
|
found = 1;
|
||||||
data.ui = uint_val;
|
data.ui = uint_val;
|
||||||
} else
|
} else
|
||||||
@ -1439,43 +1414,38 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPADDR:
|
case DATATYPE_IPADDR:
|
||||||
storage_ptr = &item->u.ipaddr;
|
if (virSocketParseIpv4Addr(prop,
|
||||||
if (!virNWIPv4AddressParser(prop,
|
&item->u.ipaddr) < 0)
|
||||||
(nwIPAddressPtr)storage_ptr)) {
|
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPMASK:
|
case DATATYPE_IPMASK:
|
||||||
storage_ptr = &item->u.u8;
|
|
||||||
if (virStrToLong_ui(prop, NULL, 10, &uint_val) == 0) {
|
if (virStrToLong_ui(prop, NULL, 10, &uint_val) == 0) {
|
||||||
if (uint_val <= 32) {
|
if (uint_val <= 32) {
|
||||||
if (!validator)
|
if (!validator)
|
||||||
*(uint8_t *)storage_ptr =
|
item->u.u8 = (uint8_t)uint_val;
|
||||||
(uint8_t)uint_val;
|
|
||||||
found = 1;
|
found = 1;
|
||||||
data.ui = uint_val;
|
data.ui = uint_val;
|
||||||
} else
|
} else
|
||||||
rc = -1;
|
rc = -1;
|
||||||
} else {
|
} else {
|
||||||
if (virNWIPv4AddressParser(prop, &ipaddr)) {
|
if (virSocketParseIpv4Addr(prop, &ipaddr) < 0) {
|
||||||
int_val = virSocketGetNumNetmaskBits(
|
rc = -1;
|
||||||
&ipaddr.addr);
|
} else {
|
||||||
|
int_val = virSocketGetNumNetmaskBits(&ipaddr);
|
||||||
if (int_val >= 0)
|
if (int_val >= 0)
|
||||||
*(uint8_t *)storage_ptr = int_val;
|
item->u.u8 = int_val;
|
||||||
else
|
else
|
||||||
rc = -1;
|
rc = -1;
|
||||||
found = 1;
|
found = 1;
|
||||||
} else
|
}
|
||||||
rc = -1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_MACADDR:
|
case DATATYPE_MACADDR:
|
||||||
storage_ptr = &item->u.macaddr;
|
|
||||||
if (!virNWMACAddressParser(prop,
|
if (!virNWMACAddressParser(prop,
|
||||||
(nwMACAddressPtr)storage_ptr)) {
|
&item->u.macaddr)) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
}
|
||||||
found = 1;
|
found = 1;
|
||||||
@ -1483,46 +1453,41 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
|||||||
|
|
||||||
case DATATYPE_MACMASK:
|
case DATATYPE_MACMASK:
|
||||||
validator = checkMACMask;
|
validator = checkMACMask;
|
||||||
storage_ptr = &item->u.macaddr;
|
|
||||||
if (!virNWMACAddressParser(prop,
|
if (!virNWMACAddressParser(prop,
|
||||||
(nwMACAddressPtr)storage_ptr)) {
|
&item->u.macaddr)) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
}
|
||||||
data.v = storage_ptr;
|
data.v = &item->u.macaddr;
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPV6ADDR:
|
case DATATYPE_IPV6ADDR:
|
||||||
storage_ptr = &item->u.ipaddr;
|
if (virSocketParseIpv6Addr(prop,
|
||||||
if (!virNWIPv6AddressParser(prop,
|
&item->u.ipaddr) < 0)
|
||||||
(nwIPAddressPtr)storage_ptr)) {
|
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPV6MASK:
|
case DATATYPE_IPV6MASK:
|
||||||
storage_ptr = &item->u.u8;
|
|
||||||
if (virStrToLong_ui(prop, NULL, 10, &uint_val) == 0) {
|
if (virStrToLong_ui(prop, NULL, 10, &uint_val) == 0) {
|
||||||
if (uint_val <= 128) {
|
if (uint_val <= 128) {
|
||||||
if (!validator)
|
if (!validator)
|
||||||
*(uint8_t *)storage_ptr =
|
item->u.u8 = (uint8_t)uint_val;
|
||||||
(uint8_t)uint_val;
|
|
||||||
found = 1;
|
found = 1;
|
||||||
data.ui = uint_val;
|
data.ui = uint_val;
|
||||||
} else
|
} else
|
||||||
rc = -1;
|
rc = -1;
|
||||||
} else {
|
} else {
|
||||||
if (virNWIPv6AddressParser(prop, &ipaddr)) {
|
if (virSocketParseIpv6Addr(prop, &ipaddr) < 0) {
|
||||||
int_val = virSocketGetNumNetmaskBits(
|
rc = -1;
|
||||||
&ipaddr.addr);
|
} else {
|
||||||
|
int_val = virSocketGetNumNetmaskBits(&ipaddr);
|
||||||
if (int_val >= 0)
|
if (int_val >= 0)
|
||||||
*(uint8_t *)storage_ptr = int_val;
|
item->u.u8 = int_val;
|
||||||
else
|
else
|
||||||
rc = -1;
|
rc = -1;
|
||||||
found = 1;
|
found = 1;
|
||||||
} else
|
}
|
||||||
rc = -1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2642,10 +2607,9 @@ virNWFilterPoolObjDeleteDef(virNWFilterPoolObjPtr pool)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virNWIPAddressFormat(virBufferPtr buf, nwIPAddressPtr ipaddr)
|
virNWIPAddressFormat(virBufferPtr buf, virSocketAddrPtr ipaddr)
|
||||||
{
|
{
|
||||||
virSocketAddrPtr addr = &ipaddr->addr;
|
char *output = virSocketFormatAddr(ipaddr);
|
||||||
char *output = virSocketFormatAddr(addr);
|
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
virBufferVSprintf(buf, "%s", output);
|
virBufferVSprintf(buf, "%s", output);
|
||||||
@ -2674,7 +2638,6 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf,
|
|||||||
while (att[i].name) {
|
while (att[i].name) {
|
||||||
item = (nwItemDesc *)((char *)def + att[i].dataIdx);
|
item = (nwItemDesc *)((char *)def + att[i].dataIdx);
|
||||||
enum virNWFilterEntryItemFlags flags = item->flags;
|
enum virNWFilterEntryItemFlags flags = item->flags;
|
||||||
void *storage_ptr;
|
|
||||||
if ((flags & NWFILTER_ENTRY_ITEM_FLAG_EXISTS)) {
|
if ((flags & NWFILTER_ENTRY_ITEM_FLAG_EXISTS)) {
|
||||||
if (!typeShown) {
|
if (!typeShown) {
|
||||||
virBufferVSprintf(buf, " <%s", type);
|
virBufferVSprintf(buf, " <%s", type);
|
||||||
@ -2725,32 +2688,28 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf,
|
|||||||
case DATATYPE_IPV6MASK:
|
case DATATYPE_IPV6MASK:
|
||||||
// display all masks in CIDR format
|
// display all masks in CIDR format
|
||||||
case DATATYPE_UINT8:
|
case DATATYPE_UINT8:
|
||||||
storage_ptr = &item->u.u8;
|
|
||||||
virBufferVSprintf(buf, asHex ? "0x%x" : "%d",
|
virBufferVSprintf(buf, asHex ? "0x%x" : "%d",
|
||||||
*(uint8_t *)storage_ptr);
|
item->u.u8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_UINT16_HEX:
|
case DATATYPE_UINT16_HEX:
|
||||||
asHex = true;
|
asHex = true;
|
||||||
case DATATYPE_UINT16:
|
case DATATYPE_UINT16:
|
||||||
storage_ptr = &item->u.u16;
|
|
||||||
virBufferVSprintf(buf, asHex ? "0x%x" : "%d",
|
virBufferVSprintf(buf, asHex ? "0x%x" : "%d",
|
||||||
*(uint16_t *)storage_ptr);
|
item->u.u16);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPADDR:
|
case DATATYPE_IPADDR:
|
||||||
case DATATYPE_IPV6ADDR:
|
case DATATYPE_IPV6ADDR:
|
||||||
storage_ptr = &item->u.ipaddr;
|
|
||||||
virNWIPAddressFormat(buf,
|
virNWIPAddressFormat(buf,
|
||||||
(nwIPAddressPtr)storage_ptr);
|
&item->u.ipaddr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_MACMASK:
|
case DATATYPE_MACMASK:
|
||||||
case DATATYPE_MACADDR:
|
case DATATYPE_MACADDR:
|
||||||
storage_ptr = &item->u.macaddr;
|
|
||||||
for (j = 0; j < 6; j++)
|
for (j = 0; j < 6; j++)
|
||||||
virBufferVSprintf(buf, "%02x%s",
|
virBufferVSprintf(buf, "%02x%s",
|
||||||
((nwMACAddressPtr)storage_ptr)->addr[j],
|
item->u.macaddr.addr[j],
|
||||||
(j < 5) ? ":" : "");
|
(j < 5) ? ":" : "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -110,13 +110,6 @@ struct _nwMACAddress {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef struct _nwIPAddress nwIPAddress;
|
|
||||||
typedef nwIPAddress *nwIPAddressPtr;
|
|
||||||
struct _nwIPAddress {
|
|
||||||
virSocketAddr addr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _nwItemDesc nwItemDesc;
|
typedef struct _nwItemDesc nwItemDesc;
|
||||||
typedef nwItemDesc *nwItemDescPtr;
|
typedef nwItemDesc *nwItemDescPtr;
|
||||||
struct _nwItemDesc {
|
struct _nwItemDesc {
|
||||||
@ -125,7 +118,7 @@ struct _nwItemDesc {
|
|||||||
enum attrDatatype datatype;
|
enum attrDatatype datatype;
|
||||||
union {
|
union {
|
||||||
nwMACAddress macaddr;
|
nwMACAddress macaddr;
|
||||||
nwIPAddress ipaddr;
|
virSocketAddr ipaddr;
|
||||||
uint8_t u8;
|
uint8_t u8;
|
||||||
uint16_t u16;
|
uint16_t u16;
|
||||||
char protocolID[10];
|
char protocolID[10];
|
||||||
|
@ -189,7 +189,7 @@ _printDataType(virNWFilterHashTablePtr vars,
|
|||||||
|
|
||||||
switch (item->datatype) {
|
switch (item->datatype) {
|
||||||
case DATATYPE_IPADDR:
|
case DATATYPE_IPADDR:
|
||||||
data = virSocketFormatAddr(&item->u.ipaddr.addr);
|
data = virSocketFormatAddr(&item->u.ipaddr);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("internal IPv4 address representation "
|
_("internal IPv4 address representation "
|
||||||
@ -206,7 +206,7 @@ _printDataType(virNWFilterHashTablePtr vars,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DATATYPE_IPV6ADDR:
|
case DATATYPE_IPV6ADDR:
|
||||||
data = virSocketFormatAddr(&item->u.ipaddr.addr);
|
data = virSocketFormatAddr(&item->u.ipaddr);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("internal IPv6 address representation "
|
_("internal IPv6 address representation "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user