Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-netd: Commit

system/netd


Commit MetaInfo

Revisionc5e8402bac2b973667b8c9d94acc4cc51cc1e7d5 (tree)
Zeit2017-11-16 05:44:30
AutorLorenzo Colitti <lorenzo@goog...>
CommiterDan Pasanen

Log Message

Invalidate dst caches when changing network permissions.

Bug: 64103722
Test: builds
Test: connected socket UDP traffic switches to wifi when cell goes into background
Change-Id: I22e618be40d61be6d5f56a6fc4e5a71e1606c2f8
Merged-In: I22e618be40d61be6d5f56a6fc4e5a71e1606c2f8
(cherry picked from commit 639696d77d19edb8298a21500b9fe1d101ec0b62)

Ändern Zusammenfassung

Diff

--- a/server/PhysicalNetwork.cpp
+++ b/server/PhysicalNetwork.cpp
@@ -83,6 +83,18 @@ int PhysicalNetwork::destroySocketsLackingPermission(Permission permission) {
8383 return 0;
8484 }
8585
86+void PhysicalNetwork::invalidateRouteCache(const std::string& interface) {
87+ for (const auto& dst : { "0.0.0.0/0", "::/0" }) {
88+ // If any of these operations fail, there's no point in logging because RouteController will
89+ // have already logged a message. There's also no point returning an error since there's
90+ // nothing we can do.
91+ (void) RouteController::addRoute(interface.c_str(), dst, "throw",
92+ RouteController::INTERFACE);
93+ (void) RouteController::removeRoute(interface.c_str(), dst, "throw",
94+ RouteController::INTERFACE);
95+ }
96+}
97+
8698 int PhysicalNetwork::setPermission(Permission permission) {
8799 if (permission == mPermission) {
88100 return 0;
@@ -100,6 +112,7 @@ int PhysicalNetwork::setPermission(Permission permission) {
100112 interface.c_str(), mNetId, mPermission, permission);
101113 return ret;
102114 }
115+ invalidateRouteCache(interface);
103116 }
104117 if (mIsDefault) {
105118 for (const std::string& interface : mInterfaces) {
--- a/server/PhysicalNetwork.h
+++ b/server/PhysicalNetwork.h
@@ -47,6 +47,7 @@ private:
4747 int addInterface(const std::string& interface) override WARN_UNUSED_RESULT;
4848 int removeInterface(const std::string& interface) override WARN_UNUSED_RESULT;
4949 int destroySocketsLackingPermission(Permission permission);
50+ void invalidateRouteCache(const std::string& interface);
5051
5152 Delegate* const mDelegate;
5253 Permission mPermission;
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -88,6 +88,14 @@ const uint16_t NETLINK_CREATE_REQUEST_FLAGS = NETLINK_REQUEST_FLAGS | NLM_F_CREA
8888
8989 const sockaddr_nl NETLINK_ADDRESS = {AF_NETLINK, 0, 0, 0};
9090
91+// None of our routes specify priority, which causes them to have the default
92+// priority. For throw routes, we use a fixed priority of 100000. This is
93+// because we use throw routes either for maximum-length routes (/32 for IPv4,
94+// /128 for IPv6), which we never create with any other priority, or for
95+// purposely-low-priority default routes that should never match if there is
96+// any other route in the table.
97+uint32_t PRIO_THROW = 100000;
98+
9199 const uint8_t AF_FAMILIES[] = {AF_INET, AF_INET6};
92100
93101 const char* const IP_VERSIONS[] = {"-4", "-6"};
@@ -122,6 +130,7 @@ rtattr FRATTR_UID_END = { U16_RTA_LENGTH(sizeof(uid_t)), FRA_UID_END };
122130
123131 rtattr RTATTR_TABLE = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_TABLE };
124132 rtattr RTATTR_OIF = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_OIF };
133+rtattr RTATTR_PRIO = { U16_RTA_LENGTH(sizeof(uint32_t)), RTA_PRIORITY };
125134
126135 uint8_t PADDING_BUFFER[RTA_ALIGNTO] = {0, 0, 0, 0};
127136
@@ -414,6 +423,8 @@ WARN_UNUSED_RESULT int modifyIpRoute(uint16_t action, uint32_t table, const char
414423 }
415424 }
416425
426+ bool isDefaultThrowRoute = (type == RTN_THROW && prefixLength == 0);
427+
417428 // Assemble a rtmsg and put it in an array of iovec structures.
418429 rtmsg route = {
419430 .rtm_protocol = RTPROT_STATIC,
@@ -437,6 +448,8 @@ WARN_UNUSED_RESULT int modifyIpRoute(uint16_t action, uint32_t table, const char
437448 { &ifindex, interface != OIF_NONE ? sizeof(ifindex) : 0 },
438449 { &rtaGateway, nexthop ? sizeof(rtaGateway) : 0 },
439450 { rawNexthop, nexthop ? static_cast<size_t>(rawLength) : 0 },
451+ { &RTATTR_PRIO, isDefaultThrowRoute ? sizeof(RTATTR_PRIO) : 0 },
452+ { &PRIO_THROW, isDefaultThrowRoute ? sizeof(PRIO_THROW) : 0 },
440453 };
441454
442455 uint16_t flags = (action == RTM_NEWROUTE) ? NETLINK_CREATE_REQUEST_FLAGS :
Show on old repository browser