Ejemplo n.º 1
0
/* Add an IP address to the list of IP addresses an interface is
 * known to use. This function feeds the per-interface cache that
 * is used to instantiate filters with variable '$IP'.
 *
 * @ifname: The name of the (tap) interface
 * @addr: An IPv4 address in dotted decimal format that the (tap)
 *        interface is known to use.
 *
 * This function returns 0 on success, -1 otherwise
 */
int
virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
{
    int ret = -1;
    virNWFilterVarValuePtr val;

    virMutexLock(&ipAddressMapLock);

    val = virHashLookup(ipAddressMap->hashTable, ifname);
    if (!val) {
        val = virNWFilterVarValueCreateSimple(addr);
        if (!val) {
            virReportOOMError();
            goto cleanup;
        }
        ret = virNWFilterHashTablePut(ipAddressMap, ifname, val, 1);
        goto cleanup;
    } else {
        if (virNWFilterVarValueAddValue(val, addr) < 0)
            goto cleanup;
    }

    ret = 0;

cleanup:
    virMutexUnlock(&ipAddressMapLock);

    return ret;
}
Ejemplo n.º 2
0
int
virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char *value)
{
    char *valdup;
    if (VIR_STRDUP(valdup, value) < 0)
        return -1;
    if (virNWFilterVarValueAddValue(val, valdup) < 0) {
        VIR_FREE(valdup);
        return -1;
    }
    return 0;
}