Esempio n. 1
0
/**
 * ebtablesContextNew:
 *
 * Create a new ebtable context
 *
 * Returns a pointer to the new structure or NULL in case of error
 */
ebtablesContext *
ebtablesContextNew(const char *driver)
{
    ebtablesContext *ctx;
    char chain[PATH_MAX];

    if (VIR_ALLOC(ctx) < 0)
        return NULL;

    snprintf(chain, sizeof(chain), "libvirt_%s_INPUT", driver);
    if (!(ctx->input_filter = ebtRulesNew("filter", chain)))
        goto error;

    snprintf(chain, sizeof(chain), "libvirt_%s_FORWARD", driver);
    if (!(ctx->forward_filter = ebtRulesNew("filter", chain)))
        goto error;

    snprintf(chain, sizeof(chain), "libvirt_%s_POSTROUTING", driver);
    if (!(ctx->nat_postrouting = ebtRulesNew("nat", chain)))
        goto error;

    return ctx;

 error:
    ebtablesContextFree(ctx);
    return NULL;
}
Esempio n. 2
0
/**
 * ebtablesContextNew:
 *
 * Create a new ebtable context
 *
 * Returns a pointer to the new structure or NULL in case of error
 */
ebtablesContext *
ebtablesContextNew(const char *driver)
{
    bool success = false;
    ebtablesContext *ctx = NULL;
    char *input_chain = NULL;
    char *forward_chain = NULL;
    char *nat_chain = NULL;

    if (VIR_ALLOC(ctx) < 0)
        return NULL;

    if (virAsprintf(&input_chain, "libvirt_%s_INPUT", driver) < 0 ||
        virAsprintf(&forward_chain, "libvirt_%s_FORWARD", driver) < 0 ||
        virAsprintf(&nat_chain, "libvirt_%s_POSTROUTING", driver) < 0) {
        goto cleanup;
    }

    if (!(ctx->input_filter = ebtRulesNew("filter", input_chain)))
        goto cleanup;

    if (!(ctx->forward_filter = ebtRulesNew("filter", forward_chain)))
        goto cleanup;

    if (!(ctx->nat_postrouting = ebtRulesNew("nat", nat_chain)))
        goto cleanup;

    success = true;

cleanup:
    VIR_FREE(input_chain);
    VIR_FREE(forward_chain);
    VIR_FREE(nat_chain);

    if (!success) {
        ebtablesContextFree(ctx);
        ctx = NULL;
    }

    return ctx;
}