summaryrefslogtreecommitdiff
path: root/server/RouteController.cpp
diff options
context:
space:
mode:
authorPaul Jensen <pauljensen@google.com>2014-06-12 16:46:37 -0400
committerPaul Jensen <pauljensen@google.com>2014-06-17 16:30:30 +0000
commita561e121c724e9163b2e256e15eef660e3a326da (patch)
tree8490eb9cf8c9f54de243dc1d7787f192bb282f2b /server/RouteController.cpp
parent5ad1c281da21ebe1863fbad50f7c20dce4f08512 (diff)
Cache interface indices in case interfaces go away.
Without caching them netd will fail to remove rules and routes, for example, when the Bluetooth reverse-tether interface ("bt-pan") goes away. bug:15407087 Change-Id: I99fcf00f9645a0b029455516a705b70110f62ff6
Diffstat (limited to 'server/RouteController.cpp')
-rw-r--r--server/RouteController.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/RouteController.cpp b/server/RouteController.cpp
index 592dc351..a4086d9a 100644
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -21,6 +21,7 @@
#include <linux/rtnetlink.h>
#include <logwrap/logwrap.h>
+#include <map>
#include <net/if.h>
namespace {
@@ -41,8 +42,19 @@ const uint32_t RULE_PRIORITY_UNREACHABLE = 21000;
const int ROUTE_TABLE_PRIVILEGED_LEGACY = RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX - 901;
const int ROUTE_TABLE_LEGACY = RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX - 902;
+std::map<std::string, uint32_t> interfaceToIndex;
+
uint32_t getRouteTableForInterface(const char* interface) {
uint32_t index = if_nametoindex(interface);
+ if (index) {
+ interfaceToIndex[interface] = index;
+ } else {
+ // 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.
+ std::map<std::string, uint32_t>::iterator it = interfaceToIndex.find(interface);
+ if (it != interfaceToIndex.end())
+ index = it->second;
+ }
return index ? index + RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX : 0;
}
@@ -257,6 +269,7 @@ bool flushRoutes(const char* interface) {
if (!table) {
return false;
}
+ interfaceToIndex.erase(interface);
return runIpRouteCommand("flush", table, NULL, NULL, NULL);
}