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;
}
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;
}