summaryrefslogtreecommitdiff
path: root/server/RouteController.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* | Implement the fallthrough rule to support split tunnel VPNs.Sreeram Ramachandran2014-07-251-1/+41
|/ | | | Change-Id: Ibc48caedb5954c6b12bfa553d978bab56c4b09aa
* Implement support for bypassable VPNs.Sreeram Ramachandran2014-07-251-18/+32
| | | | | | | | | | | | Bypassable VPNs grab all traffic by default (just like secure VPNs), but: + They allow all apps to choose other networks using the multinetwork APIs. If these other networks are insecure ("untrusted"), they will enforce that the app holds the necessary permissions, such as CHANGE_NETWORK_STATE. + They support consistent routing. If an app has an existing connection over some other network when the bypassable VPN comes up, it's not interrupted. Bug: 15347374 Change-Id: Iaee9c6f6fa8103215738570d2b65d3fcf10343f3
* Implement the rule to forward traffic to local networks via VPNs.Sreeram Ramachandran2014-07-231-1/+14
| | | | Change-Id: I4bffb2ce854a6fa7d4c0d35b97f123d91c6a84d6
* Cosmetic: Move some functions around to match rule priority order.Sreeram Ramachandran2014-07-221-109/+107
| | | | Change-Id: I81af639b66ac66272e0fae2d53119de1bfa12e69
* Remove the oif=iface clause when tethering.Sreeram Ramachandran2014-07-221-1/+1
| | | | | | | | | | The rule is meant to be "iif=inputIface => lookup <table_for_outputIface>", not "iif=foo oif=bar => lookup <table_for_bar>" (the latter would never match because packets coming in on the input interface will not have any output interface binding). Bug: 16242255 Change-Id: I98a2a8ab90765aee833134297b58d4f7a212036f
* Flush routing rules and add an "unreachable" rule on Init().Sreeram Ramachandran2014-07-221-6/+24
| | | | | | | | | | | | | Without the flush, rules accumulate duplicates when netd is restarted due to a runtime restart. Nothing functionally wrong with having duplicates; it just makes the output of "ip rule" look as though something went wrong in the system. Time to add the unreachable rule, to suss out issues with corner cases. With the flush, there's no more a naked "from main" rule that we need to protect by adding the unreachable rule. But it's a good idea to add the unreachable rule anyway, in case somebody comes along and adds a rule below it later. Change-Id: I975b2221868b7f5366bd7cf60937a82fb4b75913
* Fix WiFi-Direct and Tethering.Sreeram Ramachandran2014-07-221-76/+114
| | | | | | | | | | | | | | | A LocalNetwork object now always exists in the NetworkController, with a fixed NetId that's guaranteed not to collide with NetIds created by the framework. When routes are added on an interface tracked by the LocalNetwork, they are added to a fixed "local_network" table. When NAT is enabled, we add a special "iif -> oif" tethering rule. Bug: 15413694 Bug: 15413741 Change-Id: I36effc438d5ac193a77174493bf196cb68a5b97a
* Merge "Add default routing tables to rt_tables."Sreeram Ramachandran2014-07-101-0/+8
|\
| * Add default routing tables to rt_tables.Sreeram Ramachandran2014-07-111-0/+8
| | | | | | | | | | | | This is so that these tables also get dumped by bugreport / dumpstate. Change-Id: Ia5ed8a23911d7b34ba964934dec42849f4a73824
* | Fix tethering in the case of a regular upstream connection.Sreeram Ramachandran2014-07-111-1/+52
|/ | | | | | | | | | | | | | Fixes tethering via Ethernet, Bluetooth and WiFi (hotspot). Tethering when the upstream has a DUN-specific APN is likely still broken (untested). For now, assign a fixed NetId (a hack) until we can change the framework to create a valid NetworkAgent and all that jazz. Bug: 15968336 Bug: 14988803 Change-Id: Idcf4d492d9329a9c87913e27be6dd835a792bea2
* Cosmetic: Move constants into file scope.Sreeram Ramachandran2014-07-091-4/+5
| | | | Change-Id: Ic1398a5867693bb8f1e588e727869ec6a4574432
* Add symbolic table names for routing table numbers.Sreeram Ramachandran2014-07-081-29/+93
| | | | | | | | This makes the output from "ip rule" much more readable. Companion changes are in AOSP. Change-Id: I69deb1a64d5d6647470823405bf0cc55b24b22de
* Add full support for UIDs in VPNs.Sreeram Ramachandran2014-07-071-1/+1
| | | | | | | | | | | | | | | | Major: + Implement the functions mentioned in http://go/android-multinetwork-routing correctly, including handling accept(), connect(), setNetworkForSocket() and protect() and supporting functions like canUserSelectNetwork(). + Eliminate the old code path of getting/setting UID ranges through SecondaryTableController (which is currently unused) and mUidMap. Minor: + Rename some methods/variables for clarity and consistency. + Moved some methods in .cpp files to match declaration order in the .h files. Bug: 15409918 Change-Id: Ic6ce3646c58cf645db0d9a53cbeefdd7ffafff93
* Update routing rules.Sreeram Ramachandran2014-07-071-242/+275
| | | | | | | | | | | | | | | | | | | | | As per the latest changes to: http://go/android-multinetwork-routing Functional changes: + Add explicit=NO to the implicit network rules, though it's a no-op. + Remove most of the UID=0 (kernel access) rules since they are no longer needed, except in one case to allow access to a VPN. + Add the explicit, protect and permissions bits to the incoming packet mark. + VPNs now don't need an implicit network rule. + Modifying network permissions now modifies the incoming packet mark as well. Cosmetic changes: + Renamed the legacy tables to match their permissions (SYSTEM and NETWORK). + Renamed most functions and methods for clarity and consistency. + Renamed and adjusted some ule priorities. + Move most rule modifications into their own functions, to prevent brittle reliance on the previous state of the fwmark/mask variables. Change-Id: I958a7e158ee918d5254de606fcfa55fe23327438
* Fix permissions handling.Sreeram Ramachandran2014-07-071-5/+5
| | | | | | | | | | | | | + Rename the permissions as per: http://go/android-multinetwork-routing + Make the SYSTEM permission explicitly include NETWORK. + Grant the SYSTEM permission to system UIDs by default, but allow the framework to override them if necessary. + Move the "string to permission" parsing to CommandListener.cpp, thus allowing us to get rid of Permission.cpp. + There's no need to support multiple permissions string arguments, so tighten that up. Change-Id: I73d51b5e2f44a97e6d5ab5943ff198cebfbcc0c4
* Fix regressions in flushRoutes().Sreeram Ramachandran2014-07-021-6/+6
| | | | | | | | | | http://ag/486276 left out a comma, causing the command to be "routeflush" (which is invalid), instead of the correct "route flush". http://ag/495068 changed the order, causing the interface to be removed from the interfaceToIndex map before we are done using it in modifyPerNetworkRules(). Change-Id: I65af0b5763b13e47b48e7e2b81d243dc19e1a03b
* Fix routing rules.Sreeram Ramachandran2014-07-011-66/+90
| | | | | | | | | | | | | | | | | | | | | | | | Fix the rules in RouteController as per the latest iteration of the routing design: http://go/android-multinetwork-routing. Changes include: + The legacy tables have to be global. So remove the UID being passed in to modifyRoute() and remove the associated TODOs. + Add UID=0 rules to let the kernel access routes on privileged networks. + Add a UID=0 clause to the directly-connected hack, thus fixing the TODO. + Add the privileged_legacy table just above the legacy table, when overriding the default network. (The same table remains added at the top of the rule chain, to override VPNs, but only for CONNECTIVITY_INTERNAL-privileged apps). Other cosmetic changes: + Update the names and values of the rule priorities. + Move the legacy table IDs to the .h file in anticipation of using them from bugreport / dump commands. + Make 'action' the first parameter consistently. Change-Id: I6634a19ddc8062b2ef55d926c7892fff8c586106
* Don't use %zu for uid_t. It's always unsigned int, so %u is correct.Sreeram Ramachandran2014-07-011-2/+2
| | | | Change-Id: I5be1d479b524495037c2aedc8336c794d2698914
* Use %zu to printf size_t correctly on both 32-bit and 64-bit platforms.Sreeram Ramachandran2014-07-011-4/+4
| | | | Change-Id: I5223e574084fca47606b844d74a99a642c7d66be
* Add UID range support to VPNs.Sreeram Ramachandran2014-07-011-61/+104
| | | | | | | | | | This adds the necessary routing rules. Future CLs will add the ability to select the right netId for connect(), setNetworkForSocket(), DNS resolutions, etc. Bug: 15409918 Change-Id: I88a67660d49cecda834dd72ab947fbfed250f09d
* Introduce VPN support.Sreeram Ramachandran2014-07-011-0/+60
| | | | | | | | | This change sets up the basic routing rules for VPNs. It doesn't yet handle UID ranges (that are meant to apply to the VPN) correctly. That's forthcoming in other CLs. Bug: 15409918 Change-Id: I284de04f176dcf6ba702361de6a614266256d04e
* Refactor: Encapsulate permissions and interfaces into a Network class.Sreeram Ramachandran2014-07-011-132/+181
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, there's a lot of logic in NetworkController surrounding events such as interface addition/removal, network creation/destruction and default network change, because these events are interwined. For example, adding an interface means also adding a corresponding default network rule if the interface is being added to the current default network. When we introduce VPNs into this mix, things will get hairy real quick for all this logic in NetworkController. In this refactor, we introduce an abstract base class Network which supports adding and removing interfaces. The main concrete implementation of this is PhysicalNetwork, which allows setting permissions and "default network" state. Since we've moved network permissions into the above class, and user permissions into NetworkController, PermissionsController is unused and has been removed. Also fix a few bugs in RouteController: + Use uidEnd correctly. + Check for all error cases in inet_pton. + Check the return value of android_fork_execvp() correctly. + The "return cmd1() && cmd2()" pattern is wrong. Rewrite that code. Also (non-functional changes): + Remove instantiations of RouteController. It has static methods only. + Reorder some blocks in CommandListener so that the most frequent commands are checked first. + Remove unused paramError() and clearNetworkPreference(). + Change all return codes to int (negative errno) wherever applicable. + Add WARN_UNUSED_RESULT everywhere. + Cleanup some style in RouteController and NetworkController. + Use uid_t instead of unsigned for user IDs. + Add clearer log messages at the source of failures. + Add a check for when fwmark bits are set without corresponding mask bits. Bug: 15409918 Change-Id: Ibba78b0850160f9f3d17d476f16331a6db0025d1
* Don't fail when adding a duplicate legacy route.Sreeram Ramachandran2014-06-271-1/+5
| | | | | | | | | This only affects calls to requestRouteToHost() by apps. We still fail if the framework itself tries to add a non-legacy duplicate route, since the framework should know better (we can consider relaxing that too in the future). Bug: 15925532 Change-Id: I9ee434277e462d570f88e6fe63a096e5ae41eee9
* Convert rta_* and fra_* variable names to camelCase.Lorenzo Colitti2014-06-261-46/+46
| | | | Change-Id: I0ca539ac4c54bb71b033f288fb4229afd71b7989
* Support adding and removing UID rules via netlink.Lorenzo Colitti2014-06-261-19/+48
| | | | Change-Id: Idae13bceda869261689260759084b8d6ef1ff639
* Pass rule modification errors back to CommandListener.Lorenzo Colitti2014-06-261-29/+31
| | | | Change-Id: If01334dccad8b6230648713a57fd58be180ac66b
* Use netlink to add/delete rules as well as routes.Lorenzo Colitti2014-06-261-100/+126
| | | | | | | | | | | Also change the indentation of the rtattrs used in modifyIpRoute to make it easier to see what attributes are being used and in what sequence. This change does not yet pass the errors back to CommandListener; that is done in the next change in the series. Change-Id: Ib2e174386c63cb0647d838d9c7d731cd6df39c4f
* Unrevert the 'revert the "talk to netlink directly" change.'Sreeram Ramachandran2014-06-241-32/+1
| | | | | | | | | http://ag/486277 was reverted in http://ag/491263 and is being unreverted in this change. The bug in the original CL was a typo ("interface" instead of the desired "ifindex"), which is now fixed. Bug: 15840054 Change-Id: If66987c74cc86e9ba4f7a35d36f0a39afe939a68
* Temporarily revert the "talk to netlink directly" change.Sreeram Ramachandran2014-06-241-1/+32
| | | | | | | | | | | | | | | | | | The change being reverted is http://ag/486277. Instead, use /sbin/ip again. The code to talk to netlink fails on volantis. I.e., instead of this: $ ip route show table 1006 default via 100.110.191.254 dev wlan0 100.110.128.0/18 dev wlan0 scope link we end up with this: $ ip route show table 1006 default dev wlan0 proto static 100.110.128.0/18 dev wlan0 proto static Notice the lack of the nexthop and the addition of "proto static". I think the netlink message is somehow not properly aligned on volantis, causing the kernel to misinterpret it. Bug: 15840054 Change-Id: Ief60473e337410f7cb35890de0a5a74a21723a41
* Pass route add/delete errors back to CommandListener.Lorenzo Colitti2014-06-241-18/+22
| | | | Change-Id: Id1d6d578963080e141f71bc1303801fc53bce40a
* Use native netlink code instead of /sbin/ip to manipulate routesLorenzo Colitti2014-06-231-25/+112
| | | | | | | | | | | Shelling out to /sbin/ip is slow, and more importantly it does not preserve the error messages returned by the kernel when adding or deleting a route fails. Instead, use netlink directly. This change does not yet pass the errors back to CommandListener; that is done in the next change in the series. Change-Id: I5ad3c8583580857be6386a620ff5c4f3872d685b
* Flush both IPv4 and IPv6 routes.Lorenzo Colitti2014-06-201-1/+21
| | | | | | | | | | | | | The current code unintentionally flushes only IPv4 routes because it reuses a function that is normally used to add and remove routes (where the IP version is implicitly specified by the route to add or remove). Instead of fixing the runIpRouteCommand function, add a new flushIpRoutes function because runIpRouteCommand will be replaced by a netlink implementation in an upcoming CL. Change-Id: Ie96ae4124baca3edb8e0d0841e7abadb6b3ee9ab
* Cache interface indices in case interfaces go away.Paul Jensen2014-06-171-0/+13
| | | | | | | | | 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
* Fix build.Sreeram Ramachandran2014-05-301-4/+0
| | | | Change-Id: If170e46ff92c6a972bc1c2d838b1ac0eea6e23de
* am 82eab785: Support legacy routes added by apps via ensureRouteToHost().Sreeram Ramachandran2014-05-301-0/+4
|\ | | | | | | | | * commit '82eab785bd5cb2eff0a263f5b0dcde13e9139588': Support legacy routes added by apps via ensureRouteToHost().
| * Support legacy routes added by apps via ensureRouteToHost().Sreeram Ramachandran2014-05-301-6/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the routes to two fixed tables: + LEGACY, which has higher priority than other non-explicit lookup tables (per-network and default network). + PRIVILEGED_LEGACY, available only to system apps and has higher priority than VPNs (system apps are those with the CONNECTIVITY_INTERNAL permission). This will be changed to per-UID tables once the kernel supports UID-based routing, so that these legacy routes are scoped to each app and not global. Also, fix a TODO: The framework (as of http://ag/471599) will not set the gateway argument if it's actually a direct-connected route. Change-Id: I0ee1ca89fdc859d75a89021ca8c1902811b1e4a9 (cherry picked from commit 38b7af1f2cb9579895465fabc37865f5dadcac25)
* | Turn on C++11 and make all warnings into errors.Sreeram Ramachandran2014-05-291-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As a consequence: + Comment out the names of all unused parameters. + Remove all unused variables and functions. In server/Android.mk, there are a couple of non-trivial changes: + Use libcxx instead of stlport. This is needed to fix a bunch of errors due to specifying -std=c++11. + LOCAL_SHARED_LIBRARIES is sorted. Technically, the order in which libraries are listed has an effect on linking, but nobody should be doing such brittle things anyway. Change-Id: I0aff5b745e04609da23144d0e8be4c5694321b8b
* | Support legacy routes added by apps via ensureRouteToHost().Sreeram Ramachandran2014-05-291-6/+47
|/ | | | | | | | | | | | | | | | This adds the routes to two fixed tables: + LEGACY, which has higher priority than other non-explicit lookup tables (per-network and default network). + PRIVILEGED_LEGACY, available only to system apps and has higher priority than VPNs (system apps are those with the CONNECTIVITY_INTERNAL permission). This will be changed to per-UID tables once the kernel supports UID-based routing, so that these legacy routes are scoped to each app and not global. Also, fix a TODO: The framework (as of http://ag/471599) will not set the gateway argument if it's actually a direct-connected route. Change-Id: I0ee1ca89fdc859d75a89021ca8c1902811b1e4a9
* Rework the determination of a "valid network".Sreeram Ramachandran2014-05-211-2/+2
| | | | | | | | | | | | | + isNetIdValid() doesn't make much sense. What we want is whether the netId has actually been created (via createNetwork()). + It isn't an error to call deleteNetwork() or setDefaultNetwork() even when there are no interfaces assigned to the network. + Secure all accesses to the maps in PermissionsController with locks; they are called from many threads (CommandListener, DnsProxyListener and FwmarkServer). + Remove the redundant mIfaceNetidMap. + Minor cosmetic changes to things such as #includes and log messages. Change-Id: Ieb154589b24f00ba8067eaaec4def3534aec4923
* Move netd_client into netd.Sreeram Ramachandran2014-05-211-0/+297
Change-Id: Ie4b6b303225c93f2448a503d6ea9cebb552cbad5