mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
nwfilter: utility function virNWFilterVarValueEqual
To detect if an interface's nwfilter has changed, we need to also compare the filterparams, which is a hashtable of virNWFilterVarValue. virHashEqual can do this nicely, but requires a pointer to a function that will compare two of the items being stored in the hashes.
This commit is contained in:
parent
3738cf41f1
commit
ab4139a493
@ -189,6 +189,37 @@ virNWFilterVarValueGetCardinality(const virNWFilterVarValuePtr val)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
virNWFilterVarValueEqual(const virNWFilterVarValuePtr a,
|
||||||
|
const virNWFilterVarValuePtr b)
|
||||||
|
{
|
||||||
|
unsigned int card, i, j;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
if (!a || !b)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
card = virNWFilterVarValueGetCardinality(a);
|
||||||
|
if (card != virNWFilterVarValueGetCardinality(b))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* brute force O(n^2) comparison */
|
||||||
|
for (i = 0; i < card; i++) {
|
||||||
|
bool eq = false;
|
||||||
|
|
||||||
|
s = virNWFilterVarValueGetNthValue(a, i);
|
||||||
|
for (j = 0; j < card; j++) {
|
||||||
|
if (STREQ_NULLABLE(s, virNWFilterVarValueGetNthValue(b, j))) {
|
||||||
|
eq = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!eq)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
|
virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,8 @@ const char *virNWFilterVarValueGetSimple(const virNWFilterVarValuePtr val);
|
|||||||
const char *virNWFilterVarValueGetNthValue(virNWFilterVarValuePtr val,
|
const char *virNWFilterVarValueGetNthValue(virNWFilterVarValuePtr val,
|
||||||
unsigned int idx);
|
unsigned int idx);
|
||||||
unsigned int virNWFilterVarValueGetCardinality(const virNWFilterVarValuePtr);
|
unsigned int virNWFilterVarValueGetCardinality(const virNWFilterVarValuePtr);
|
||||||
|
bool virNWFilterVarValueEqual(const virNWFilterVarValuePtr a,
|
||||||
|
const virNWFilterVarValuePtr b);
|
||||||
int virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value);
|
int virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value);
|
||||||
int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value);
|
int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value);
|
||||||
|
|
||||||
|
@ -975,6 +975,7 @@ virNWFilterVarValueCopy;
|
|||||||
virNWFilterVarValueCreateSimple;
|
virNWFilterVarValueCreateSimple;
|
||||||
virNWFilterVarValueCreateSimpleCopyValue;
|
virNWFilterVarValueCreateSimpleCopyValue;
|
||||||
virNWFilterVarValueDelValue;
|
virNWFilterVarValueDelValue;
|
||||||
|
virNWFilterVarValueEqual;
|
||||||
virNWFilterVarValueFree;
|
virNWFilterVarValueFree;
|
||||||
virNWFilterVarValueGetCardinality;
|
virNWFilterVarValueGetCardinality;
|
||||||
virNWFilterVarValueGetNthValue;
|
virNWFilterVarValueGetNthValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user