Lines Matching refs:interface
133 uint32_t getRouteTableForInterface(const char* interface) {
134 uint32_t index = if_nametoindex(interface);
137 interfaceToTable[interface] = index;
140 // If the interface goes away if_nametoindex() will return 0 but we still need to know
142 auto iter = interfaceToTable.find(interface);
144 ALOGE("cannot find interface %s", interface);
246 ALOGE("interface name too long (%zu > %u)", *length, IFNAMSIZ);
259 // + If |iif| is non-NULL, the rule matches the specified incoming interface.
260 // + If |oif| is non-NULL, the rule matches the specified outgoing interface.
274 // Interface names must include exactly one terminating NULL and be properly padded, or older
361 WARN_UNUSED_RESULT int modifyIpRoute(uint16_t action, uint32_t table, const char* interface,
391 // 'interface' is likely non-NULL, as the caller (modifyRoute()) likely used it to lookup
392 // the table number. But it's an error to specify an interface ("dev ...") or a nexthop for
394 interface = OIF_NONE;
398 interface = OIF_NONE;
401 // If an interface was specified, find the ifindex.
402 if (interface != OIF_NONE) {
403 ifindex = if_nametoindex(interface);
405 ALOGE("cannot find interface %s", interface);
436 { &RTATTR_OIF, interface != OIF_NONE ? sizeof(RTATTR_OIF) : 0 },
437 { &ifindex, interface != OIF_NONE ? sizeof(ifindex) : 0 },
452 // + Mark sockets that accept connections from this interface so that the connection stays on the
453 // same interface.
454 WARN_UNUSED_RESULT int modifyIncomingPacketMark(unsigned netId, const char* interface,
466 if (execIptables(V4V6, "-t", "mangle", add ? "-A" : "-D", "INPUT", "-i", interface, "-j",
478 // the VPN's tunnel interface. When the VPN forwards the responses, they emerge out of the tunnel.
561 // A rule to route traffic based on a chosen outgoing interface.
564 // the outgoing interface (typically for link-local communications).
565 WARN_UNUSED_RESULT int modifyOutputInterfaceRules(const char* interface, uint32_t table,
578 table, fwmark.intValue, mask.intValue, IIF_NONE, interface,
585 fwmark.intValue, mask.intValue, IIF_NONE, interface, uidStart, uidEnd);
684 const char *interface = DummyNetwork::INTERFACE_NAME;
685 uint32_t table = getRouteTableForInterface(interface);
692 int ret = ifc_up(interface);
695 ALOGE("Can't bring up %s: %s", interface, strerror(errno));
699 if ((ret = modifyOutputInterfaceRules(interface, table, PERMISSION_NONE,
701 ALOGE("Can't create oif rules for %s: %s", interface, strerror(-ret));
705 if ((ret = modifyIpRoute(RTM_NEWROUTE, table, interface, "0.0.0.0/0", NULL))) {
706 ALOGE("Can't add IPv4 default route to %s: %s", interface, strerror(-ret));
710 if ((ret = modifyIpRoute(RTM_NEWROUTE, table, interface, "::/0", NULL))) {
711 ALOGE("Can't add IPv6 default route to %s: %s", interface, strerror(-ret));
743 WARN_UNUSED_RESULT int modifyLocalNetwork(unsigned netId, const char* interface, bool add) {
744 if (int ret = modifyIncomingPacketMark(netId, interface, PERMISSION_NONE, add)) {
747 return modifyOutputInterfaceRules(interface, ROUTE_TABLE_LOCAL_NETWORK, PERMISSION_NONE,
751 WARN_UNUSED_RESULT int modifyPhysicalNetwork(unsigned netId, const char* interface,
753 uint32_t table = getRouteTableForInterface(interface);
758 if (int ret = modifyIncomingPacketMark(netId, interface, permission, add)) {
765 if (int ret = modifyOutputInterfaceRules(interface, table, permission, INVALID_UID, INVALID_UID,
790 WARN_UNUSED_RESULT int modifyVirtualNetwork(unsigned netId, const char* interface,
793 uint32_t table = getRouteTableForInterface(interface);
806 if (int ret = modifyOutputInterfaceRules(interface, table, PERMISSION_NONE, range.first,
813 if (int ret = modifyIncomingPacketMark(netId, interface, PERMISSION_NONE, add)) {
816 if (int ret = modifyVpnOutputToLocalRule(interface, add)) {
828 WARN_UNUSED_RESULT int modifyDefaultNetwork(uint16_t action, const char* interface,
830 uint32_t table = getRouteTableForInterface(interface);
879 WARN_UNUSED_RESULT int modifyRoute(uint16_t action, const char* interface, const char* destination,
883 case RouteController::INTERFACE: {
884 table = getRouteTableForInterface(interface);
904 int ret = modifyIpRoute(action, table, interface, destination, nexthop);
914 WARN_UNUSED_RESULT int flushRoutes(const char* interface) {
915 uint32_t table = getRouteTableForInterface(interface);
936 // happen, for example, if an interface goes down while we're trying to flush its routes.
954 // If we failed to flush routes, the caller may elect to keep this interface around, so keep
957 interfaceToTable.erase(interface);
1002 int RouteController::addInterfaceToLocalNetwork(unsigned netId, const char* interface) {
1003 return modifyLocalNetwork(netId, interface, ACTION_ADD);
1006 int RouteController::removeInterfaceFromLocalNetwork(unsigned netId, const char* interface) {
1007 return modifyLocalNetwork(netId, interface, ACTION_DEL);
1010 int RouteController::addInterfaceToPhysicalNetwork(unsigned netId, const char* interface,
1012 if (int ret = modifyPhysicalNetwork(netId, interface, permission, ACTION_ADD)) {
1019 int RouteController::removeInterfaceFromPhysicalNetwork(unsigned netId, const char* interface,
1021 if (int ret = modifyPhysicalNetwork(netId, interface, permission, ACTION_DEL)) {
1024 if (int ret = flushRoutes(interface)) {
1027 if (int ret = clearTetheringRules(interface)) {
1034 int RouteController::addInterfaceToVirtualNetwork(unsigned netId, const char* interface,
1036 if (int ret = modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_ADD,
1044 int RouteController::removeInterfaceFromVirtualNetwork(unsigned netId, const char* interface,
1046 if (int ret = modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_DEL,
1050 if (int ret = flushRoutes(interface)) {
1057 int RouteController::modifyPhysicalNetworkPermission(unsigned netId, const char* interface,
1061 if (int ret = modifyPhysicalNetwork(netId, interface, newPermission, ACTION_ADD)) {
1064 return modifyPhysicalNetwork(netId, interface, oldPermission, ACTION_DEL);
1075 int RouteController::addUsersToVirtualNetwork(unsigned netId, const char* interface, bool secure,
1077 return modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_ADD,
1081 int RouteController::removeUsersFromVirtualNetwork(unsigned netId, const char* interface,
1083 return modifyVirtualNetwork(netId, interface, uidRanges, secure, ACTION_DEL,
1087 int RouteController::addInterfaceToDefaultNetwork(const char* interface, Permission permission) {
1088 return modifyDefaultNetwork(RTM_NEWRULE, interface, permission);
1091 int RouteController::removeInterfaceFromDefaultNetwork(const char* interface,
1093 return modifyDefaultNetwork(RTM_DELRULE, interface, permission);
1096 int RouteController::addRoute(const char* interface, const char* destination, const char* nexthop,
1098 return modifyRoute(RTM_NEWROUTE, interface, destination, nexthop, tableType);
1101 int RouteController::removeRoute(const char* interface, const char* destination,
1103 return modifyRoute(RTM_DELROUTE, interface, destination, nexthop, tableType);