int SecondaryTableController::removeRoute(SocketClient *cli, char *iface, char *dest, int prefix, char *gateway) { int tableIndex = findTableNumber(iface); if (tableIndex == -1) { ALOGE("Interface not found"); errno = ENODEV; cli->sendMsg(ResponseCode::OperationFailed, "Interface not found", true); return -1; } return modifyRoute(cli, DEL, iface, dest, prefix, gateway, tableIndex); }
int SecondaryTableController::addRoute(SocketClient *cli, char *iface, char *dest, int prefix, char *gateway) { char *cmd; int tableIndex = findTableNumber(iface); int fd; struct ifreq ifreqs[20]; struct ifconf ic; unsigned int i; if (tableIndex == -1) { tableIndex = findTableNumber(""); // look for an empty slot if (tableIndex == -1) { ALOGE("Max number of NATed interfaces reached"); errno = ENODEV; cli->sendMsg(ResponseCode::OperationFailed, "Max number NATed", true); return -1; } strncpy(mInterfaceTable[tableIndex], iface, IFNAMSIZ); // Ensure null termination even if truncation happened mInterfaceTable[tableIndex][IFNAMSIZ] = 0; } if ((fd = open("/proc/net/mptcp", O_RDONLY)) != -1) { close(fd); fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { ALOGE("socket error"); return -1; } ic.ifc_len = sizeof(ifreqs); ic.ifc_buf = (char *) ifreqs; if (ioctl(fd, SIOCGIFCONF, &ic) < 0) { ALOGE("ioctl error"); return -1; } for (i = 0; i < ic.ifc_len / sizeof(struct ifreq); i++) { if (!strcmp(ifreqs[i].ifr_name, iface)) { asprintf(&cmd, "%s rule add from %s table %d", IP_PATH, inet_ntoa(((struct sockaddr_in *)&ifreqs[i].ifr_addr)->sin_addr), tableIndex+BASE_TABLE_NUMBER); system_nosh(cmd); } } } return modifyRoute(cli, ADD, iface, dest, prefix, gateway, tableIndex); }
int SecondaryTableController::addRoute(SocketClient *cli, char *iface, char *dest, int prefix, char *gateway) { int tableIndex = findTableNumber(iface); if (tableIndex == -1) { tableIndex = findTableNumber(""); // look for an empty slot if (tableIndex == -1) { ALOGE("Max number of NATed interfaces reached"); errno = ENODEV; cli->sendMsg(ResponseCode::OperationFailed, "Max number NATed", true); return -1; } strncpy(mInterfaceTable[tableIndex], iface, IFNAMSIZ); // Ensure null termination even if truncation happened mInterfaceTable[tableIndex][IFNAMSIZ] = 0; } return modifyRoute(cli, ADD, iface, dest, prefix, gateway, tableIndex); }
int SecondaryTableController::removeRoute(SocketClient *cli, char *iface, char *dest, int prefix, char *gateway) { char *cmd; int tableIndex = findTableNumber(iface); int fd; struct ifreq ifreqs[20]; struct ifconf ic; unsigned int i; if (tableIndex == -1) { ALOGE("Interface not found"); errno = ENODEV; cli->sendMsg(ResponseCode::OperationFailed, "Interface not found", true); return -1; } if ((fd = open("/proc/net/mptcp", O_RDONLY)) != -1) { close(fd); fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { ALOGE("socket error"); return -1; } ic.ifc_len = sizeof(ifreqs); ic.ifc_buf = (char *) ifreqs; if (ioctl(fd, SIOCGIFCONF, &ic) < 0) { ALOGE("ioctl error"); return -1; } for (i = 0; i < ic.ifc_len / sizeof(struct ifreq); i++) { if (!strcmp(ifreqs[i].ifr_name, iface)) { asprintf(&cmd, "%s rule del from %s table %d", IP_PATH, inet_ntoa(((struct sockaddr_in *)&ifreqs[i].ifr_addr)->sin_addr), tableIndex+BASE_TABLE_NUMBER); system_nosh(cmd); } } } return modifyRoute(cli, DEL, iface, dest, prefix, gateway, tableIndex); }
int SecondaryTableController::addRoute(SocketClient *cli, char *iface, char *dest, int prefix, char *gateway) { return modifyRoute(cli, ADD, iface, dest, prefix, gateway, mNetCtrl->getNetworkId(iface)); }