summaryrefslogtreecommitdiff
path: root/server/RouteController.cpp
diff options
context:
space:
mode:
authormtk13799 <xin.huang@mediatek.com>2019-02-25 19:39:36 +0800
committerJeiFeng Lee <linger.lee@mediatek.com>2019-04-02 03:02:21 +0000
commit9f2913e261bcabf662ff69ba952e5d086bf74c63 (patch)
tree8d2dd8f2db07e8af0f23a75a04e7c7c123dcf5f3 /server/RouteController.cpp
parent0255437c370aa8bee3d2cbd8d52516c12b2ca9be (diff)
netd: reorder the operations in getRouteTableForInterfaceLocked.
when network was switched quickly between wifi and cellular, netd should always use old ifindex to delete ip rule/route, and new ifindex to add ip rule/route. BUG: 128805131 Test: built, booted, datausage, Phone call, Internet under wifi and cellular data Change-Id: I2d88709a00d50e318b02362ffac543a1e7e40a81
Diffstat (limited to 'server/RouteController.cpp')
-rw-r--r--server/RouteController.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/server/RouteController.cpp b/server/RouteController.cpp
index d0ceefa2..d993c85c 100644
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -139,20 +139,28 @@ const char *familyName(uint8_t family) {
// Caller must hold sInterfaceToTableLock.
uint32_t RouteController::getRouteTableForInterfaceLocked(const char* interface) {
- uint32_t index = if_nametoindex(interface);
- if (index) {
- index += RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX;
- sInterfaceToTable[interface] = index;
- return index;
- }
- // If the interface goes away if_nametoindex() will return 0 but we still need to know
- // the index so we can remove the rules and routes.
+ // If we already know the routing table for this interface name, use it.
+ // This ensures we can remove rules and routes for an interface that has been removed,
+ // or has been removed and re-added with a different interface index.
+ //
+ // The caller is responsible for ensuring that an interface is never added to a network
+ // until it has been removed from any network it was previously in. This ensures that
+ // if the same interface disconnects and then reconnects with a different interface ID
+ // when the reconnect happens the interface will not be in the map, and the code will
+ // determine the new routing table from the interface ID, below.
auto iter = sInterfaceToTable.find(interface);
- if (iter == sInterfaceToTable.end()) {
+ if (iter != sInterfaceToTable.end()) {
+ return iter->second;
+ }
+
+ uint32_t index = if_nametoindex(interface);
+ if (index == 0) {
ALOGE("cannot find interface %s", interface);
return RT_TABLE_UNSPEC;
}
- return iter->second;
+ index += RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX;
+ sInterfaceToTable[interface] = index;
+ return index;
}
uint32_t RouteController::getIfIndex(const char* interface) {