int SecondaryTableController::modifyRoute(SocketClient *cli, const char *action, char *iface,
        char *dest, int prefix, char *gateway, int tableIndex) {
    char *cmd;

    if (strcmp("::", gateway) == 0) {
        //  IP tool doesn't like "::" - the equiv of 0.0.0.0 that it accepts for ipv4
        asprintf(&cmd, "%s route %s %s/%d dev %s table %d",
                IP_PATH, action, dest, prefix, iface, tableIndex+BASE_TABLE_NUMBER);
    } else {
        asprintf(&cmd, "%s route %s %s/%d via %s dev %s table %d",
                IP_PATH, action, dest, prefix, gateway, iface, tableIndex+BASE_TABLE_NUMBER);
    }
    ALOGD("modifyRoute RUN: %s ",cmd);
    if (runAndFree(cli, cmd)) {
        ALOGE("ip route %s failed: %s route %s %s/%d via %s dev %s table %d", action,
                IP_PATH, action, dest, prefix, gateway, iface, tableIndex+BASE_TABLE_NUMBER);
        errno = ENODEV;
        cli->sendMsg(ResponseCode::OperationFailed, "ip route modification failed", true);
        return -1;
    }

    if (strcmp(action, ADD) == 0) {
        mInterfaceRuleCount[tableIndex]++;
    } else {
        if (--mInterfaceRuleCount[tableIndex] < 1) {
            mInterfaceRuleCount[tableIndex] = 0;
            mInterfaceTable[tableIndex][0] = 0;
        }
    }
    modifyRuleCount(tableIndex, action);
    cli->sendMsg(ResponseCode::CommandOkay, "Route modified", false);
    return 0;
}
Exemplo n.º 2
0
int SecondaryTableController::modifyRoute(SocketClient *cli, const char *action, char *iface,
        char *dest, int prefix, char *gateway, unsigned netId) {
    char dest_str[44]; // enough to store an IPv6 address + 3 character bitmask
    char tableIndex_str[11];
    int ret;

    //  IP tool doesn't like "::" - the equiv of 0.0.0.0 that it accepts for ipv4
    snprintf(dest_str, sizeof(dest_str), "%s/%d", dest, prefix);
    snprintf(tableIndex_str, sizeof(tableIndex_str), "%u", netId + BASE_TABLE_NUMBER);

    if (strcmp("::", gateway) == 0) {
        const char *cmd[] = {
                IP_PATH,
                "route",
                action,
                dest_str,
                "dev",
                iface,
                "table",
                tableIndex_str
        };
        ret = runCmd(ARRAY_SIZE(cmd), cmd);
    } else {
        const char *cmd[] = {
                IP_PATH,
                "route",
                action,
                dest_str,
                "via",
                gateway,
                "dev",
                iface,
                "table",
                tableIndex_str
        };
        ret = runCmd(ARRAY_SIZE(cmd), cmd);
    }

    if (ret) {
        ALOGE("ip route %s failed: %s route %s %s/%d via %s dev %s table %u", action,
                IP_PATH, action, dest, prefix, gateway, iface, netId + BASE_TABLE_NUMBER);
        errno = ENODEV;
        cli->sendMsg(ResponseCode::OperationFailed, "ip route modification failed", true);
        return -1;
    }

    modifyRuleCount(netId, action);
    cli->sendMsg(ResponseCode::CommandOkay, "Route modified", false);
    return 0;
}
int SecondaryTableController::modifyLocalRoute(int tableIndex, const char *action,
        const char *iface, const char *addr) {
    char *cmd;

    if (verifyTableIndex(tableIndex)) {
        return -1;
    }

    modifyRuleCount(tableIndex, action); // some del's will fail as the iface is already gone.

    asprintf(&cmd, "%s route %s %s dev %s table %d", IP_PATH, action, addr, iface,
            tableIndex+BASE_TABLE_NUMBER);
    return runAndFree(NULL, cmd);
}
int SecondaryTableController::modifyFromRule(int tableIndex, const char *action,
        const char *addr) {
    char *cmd;

    if (verifyTableIndex(tableIndex)) {
        return -1;
    }
    asprintf(&cmd, "%s %s rule %s from %s table %d", IP_PATH, getVersion(addr),
            action, addr, tableIndex + BASE_TABLE_NUMBER);
    if (runAndFree(NULL, cmd)) {
        return -1;
    }

    modifyRuleCount(tableIndex, action);
    return 0;
}
Exemplo n.º 5
0
int SecondaryTableController::modifyLocalRoute(unsigned netId, const char *action,
        const char *iface, const char *addr) {
    char tableIndex_str[11];

    modifyRuleCount(netId, action); // some del's will fail as the iface is already gone.
    snprintf(tableIndex_str, sizeof(tableIndex_str), "%u", netId + BASE_TABLE_NUMBER);
    const char *cmd[] = {
            IP_PATH,
            "route",
            action,
            addr,
            "dev",
            iface,
            "table",
            tableIndex_str
    };

    return runCmd(ARRAY_SIZE(cmd), cmd);
}
Exemplo n.º 6
0
int SecondaryTableController::modifyFromRule(unsigned netId, const char *action,
        const char *addr) {
    char tableIndex_str[11];

    snprintf(tableIndex_str, sizeof(tableIndex_str), "%u", netId + BASE_TABLE_NUMBER);
    const char *cmd[] = {
            IP_PATH,
            getVersion(addr),
            "rule",
            action,
            "from",
            addr,
            "table",
            tableIndex_str
    };
    if (runCmd(ARRAY_SIZE(cmd), cmd)) {
        return -1;
    }

    modifyRuleCount(netId, action);
    return 0;
}