OSDN Git Service

android-x86/system-netd.git
9 years agoRe-add netd support for enabling IPv6 optimistic mode.
Erik Kline [Mon, 8 Dec 2014 07:05:28 +0000 (16:05 +0900)]
Re-add netd support for enabling IPv6 optimistic mode.

Enables optimistic_dad and use_optimistic on all interfaces
by default.

---

This functionality was originally submitted in ag/569594.  Owing
to issues with bind()ing to optimistic addresses (see b/18609055)
this was reverted in ag/598690.

This reverts the revert.  :-)

Bug: 17769720
Change-Id: I156e5636341a846f41fb9a15c84cf06878b239d8

9 years agoRevert "Merge "Add netd support for configuring IPv6 optimistic mode." into lmp-mr1...
Erik Kline [Fri, 5 Dec 2014 11:17:10 +0000 (20:17 +0900)]
Revert "Merge "Add netd support for configuring IPv6 optimistic mode." into lmp-mr1-dev"

This is to undo ag/569594.

This reverts commit 828f8b88c78e7d7c31b098768df403e4596a91d4, reversing
changes made to ac7fefcf3d90cf856b0f1664207d056ed1dd4725.

Bug: 18609055
Bug: 17769720
Change-Id: I120745d9d01d731174f477dff9b463dede8523d7

9 years agoAdd a command to clear a network's DNS servers.
Lorenzo Colitti [Sat, 29 Nov 2014 04:54:25 +0000 (13:54 +0900)]
Add a command to clear a network's DNS servers.

Bug: 18327075
Change-Id: I0df13ff4a17ee65e640be96695a3af31b020963a

9 years agoDon't use framework permission strings for netd permissions.
Sreeram Ramachandran [Tue, 4 Nov 2014 18:18:25 +0000 (10:18 -0800)]
Don't use framework permission strings for netd permissions.

These framework permission strings were being used as arbitrary labels
that mapped to netd permissions that have completely different meaning.
This leads to confusion, so use different strings.

Bug: 18194858
Change-Id: Ib3ec377ab26ce904d3d4678f04edec6cb1260517

9 years agoWrite pid file so we can tell when netd bounces.
Robert Greenwalt [Sat, 1 Nov 2014 01:54:06 +0000 (18:54 -0700)]
Write pid file so we can tell when netd bounces.

We clear the file early so people know it's died and rewrite after all the
setup and flushing of data is done so people know when it's safe to
repopulate the data.

bug:18069270
Change-Id: I954cf43ff02f1d352015f128ef88b659e6d0f95a

9 years agoDon't fail when trying to add routes that already exist.
Sreeram Ramachandran [Thu, 30 Oct 2014 17:01:07 +0000 (10:01 -0700)]
Don't fail when trying to add routes that already exist.

Previously, we suppressed failures for the special case of
requestRouteToHost() being called multiple times. Turns out that other
parts of the system also try to add duplicate routes, so just suppress
EEXIST errors in general (as far as adding routes is concerned). For
example, this happens when the WiFi P2P DHCP client renews its lease
and blindly requests to add a route that it had already added before.

Bug: 17205769
Change-Id: I3de557ddb82c95899623aa31b4b3ec7c955f5609

9 years agoMerge "Add a netd interface command to disable ND offload." into lmp-mr1-dev
Lorenzo Colitti [Thu, 30 Oct 2014 13:24:39 +0000 (13:24 +0000)]
Merge "Add a netd interface command to disable ND offload." into lmp-mr1-dev

9 years agoAdd a netd interface command to disable ND offload.
Lorenzo Colitti [Mon, 27 Oct 2014 15:15:07 +0000 (00:15 +0900)]
Add a netd interface command to disable ND offload.

This will be used to support 464xlat on wifi and IPv6 tethering.

Bug: 12111730
Change-Id: I3b97f4dfb787b2c5d5021811c6da51850bdc70d1

9 years agoMerge "Add netd support for configuring IPv6 optimistic mode." into lmp-mr1-dev
Erik Kline [Thu, 30 Oct 2014 03:42:18 +0000 (03:42 +0000)]
Merge "Add netd support for configuring IPv6 optimistic mode." into lmp-mr1-dev

9 years agoSupport more than one clatd at a time.
Lorenzo Colitti [Mon, 20 Oct 2014 08:14:13 +0000 (17:14 +0900)]
Support more than one clatd at a time.

1. Change from a single PID to a map of interface names to PIDs.
2. Make clatd commands take an interface argument.
3. Give the clatd processes names that depend on their parent
   interface, e.g., clatd-rmnet0.

Bug: 12111730
Change-Id: Ia770952d6511f8598a3356be5911da4ffa01b46a

9 years agoAdd netd support for configuring IPv6 optimistic mode.
Erik Kline [Thu, 9 Oct 2014 06:37:01 +0000 (15:37 +0900)]
Add netd support for configuring IPv6 optimistic mode.

Enables optimistic_dad and use_optimistic on all interfaces
by default.

Bug: 17769720
Change-Id: Ide492e18aa94064b890fef30d31c3a14cfdf4052

9 years agoam a1067c8d: Improve error return values on network selection.
Lorenzo Colitti [Fri, 3 Oct 2014 05:55:27 +0000 (05:55 +0000)]
am a1067c8d: Improve error return values on network selection.

* commit 'a1067c8d2b2165f1058a3a8216bed4efacfa1c80':
  Improve error return values on network selection.

9 years agoam e8164ddc: Fix MSS clamping.
Lorenzo Colitti [Fri, 3 Oct 2014 05:54:55 +0000 (05:54 +0000)]
am e8164ddc: Fix MSS clamping.

* commit 'e8164ddc8204b626c1144a0a504754bf6622c6fd':
  Fix MSS clamping.

9 years agoImprove error return values on network selection.
Lorenzo Colitti [Thu, 2 Oct 2014 13:47:41 +0000 (22:47 +0900)]
Improve error return values on network selection.

It's very confusing to see EPERM when opening or connecting a
socket when the problem is not security-related. In the (common)
case where an app cannot select a network because it does not
exist, return ENONET ("Machine is not on network") instead.

Also, return EREMOTEIO for when we can't figure out who the user
is, and use EPERM for VPN denials and EACCES for permission
bits.

Bug: 17702933
Change-Id: Ia680c485e0ea1efad1ad374231d994e9bfd4cd5a

9 years agoFix MSS clamping.
Lorenzo Colitti [Thu, 2 Oct 2014 11:46:23 +0000 (20:46 +0900)]
Fix MSS clamping.

http://ag/553410 added an iptables chain and rule to do MSS
clamping for tethered clients, but did not add the chain to any
other chains, so the rule had no effect.

Fix this by adding the chain to the proper forwarding chains.
Also rename some of the new variables and constants so they are
more consistent with the previous code.

Bug: 17552732
Bug: 17727533
Change-Id: I9fcae31de5c0283d7d9f1dac989de84f77c5e53c

9 years agosoftap: Ensure entropy file creation
Dmitry Shmidt [Fri, 5 Sep 2014 23:39:29 +0000 (16:39 -0700)]
softap: Ensure entropy file creation

Bug: 17408011

Change-Id: I558270f1ce2603f305d38ad8604379ea533f0a47
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
9 years agoEnable tcp mss clamp for Tethering
Gordon Gao [Thu, 18 Sep 2014 18:50:09 +0000 (11:50 -0700)]
Enable tcp mss clamp for Tethering

With this change, IPv4 tethering clients (such as PC) with default
MTU size 1500 will be configured again in the phone to use MTU
matching the carrier network, then no IP fragemention in the phone
and have higher data throughput for tethering.

bug:17552732
Change-Id: Ia306b1b8454da1b0e2d9c320e770aeff172d5fc4

9 years agoSupport manipulating throw routes.
Lorenzo Colitti [Thu, 18 Sep 2014 07:01:50 +0000 (16:01 +0900)]
Support manipulating throw routes.

We already supported unreachable routes. Throw routes are
necessary so we can exempt the VPN endpoint from being routed
through the VPN in legacy VPN modes that do not pass traffic
through a tun or ppp interface but just directly appply IPsec
transformations to outgoing packets.

Bug: 17462989
Change-Id: I8635472ca3e96ec2866af2de48e6260ab2da13fb

9 years agoMerge "Reset connections whenever an address goes away." into lmp-dev
Sreeram Ramachandran [Tue, 9 Sep 2014 23:24:52 +0000 (23:24 +0000)]
Merge "Reset connections whenever an address goes away." into lmp-dev

9 years agoReset connections whenever an address goes away.
Sreeram Ramachandran [Mon, 8 Sep 2014 23:03:18 +0000 (16:03 -0700)]
Reset connections whenever an address goes away.

Bug: 15414453
Change-Id: Ibf1f052e12b88838a328148e25817a96f10d50f5

9 years agoReserve NetIds 1..50 for OEM use.
Sreeram Ramachandran [Fri, 5 Sep 2014 23:05:03 +0000 (16:05 -0700)]
Reserve NetIds 1..50 for OEM use.

Also reserve 51..100 for our use.

Bug: 17303534
Change-Id: Id082368b493dc3c5b5c479e51d273458d80ec6aa

9 years agoMerge "softap: Add wowlan_triggers=any parameter" into lmp-dev
Dmitry Shmidt [Thu, 4 Sep 2014 17:23:26 +0000 (17:23 +0000)]
Merge "softap: Add wowlan_triggers=any parameter" into lmp-dev

9 years agosoftap: Add wowlan_triggers=any parameter
Dmitry Shmidt [Wed, 3 Sep 2014 22:19:36 +0000 (15:19 -0700)]
softap: Add wowlan_triggers=any parameter

New kernels in wiphy_suspend() will call cfg80211_leave_all()
that will eventually end up in cfg80211_stop_ap() unless
wowlan_triggers were set.

Bug: 17269024

Change-Id: I609d78f5bb573b4c6a9dae25a3b2a345499f6853
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
9 years agoAdd a socket mark parameter to tethering DNS commands.
Lorenzo Colitti [Tue, 26 Aug 2014 21:13:07 +0000 (14:13 -0700)]
Add a socket mark parameter to tethering DNS commands.

This allows the framework to pass down to dnsmasq the socket mark
to use for DNS queries.

Bug: 16357676
Change-Id: I8933b6de198a92c2aaf0291931ace8966ddba275

9 years agoMake destroying networks more robust.
Lorenzo Colitti [Tue, 12 Aug 2014 06:08:00 +0000 (15:08 +0900)]
Make destroying networks more robust.

1. Retry route flushes if they fail.
2. Make destroyNetwork ignore (but return) errors.

Bug: 16944962
Change-Id: I26301613437d7cc373ff64955fd44d716e9982b9

9 years agoRevert DNS cache flush command deletion from "Cleanup: Delete dead code."
Paul Jensen [Wed, 6 Aug 2014 18:42:27 +0000 (18:42 +0000)]
Revert DNS cache flush command deletion from "Cleanup: Delete dead code."

This reverts part of commit 1604e18615f824adb2d54c36320069ba6fcb4796.
The DNS cache flushing code needs to be called when routes change.

Change-Id: I20d39eabfa088deeeeeff0c3292b1910fd948b0d
bug:16549455

9 years agoMerge "Fix initialization of Monitor fields." into lmp-dev
Narayan Kamath [Mon, 4 Aug 2014 15:54:00 +0000 (15:54 +0000)]
Merge "Fix initialization of Monitor fields." into lmp-dev

9 years agoFix initialization of Monitor fields.
Narayan Kamath [Mon, 4 Aug 2014 15:20:47 +0000 (16:20 +0100)]
Fix initialization of Monitor fields.

mLiveCount was never initialized. Also moves
initialization of mPollCount to the constructor, where
it belongs. Also, fields are now initialized in the order
in which they are declared.

bug: 16734745

Change-Id: I9cc668a6fc5649d3ea550bc3a47c0eef210cad07

9 years agoAdd logging of calloc failures.
Robert Greenwalt [Fri, 1 Aug 2014 23:19:02 +0000 (16:19 -0700)]
Add logging of calloc failures.

Re-adding after build-break and revert

bug:16734745
Change-Id: I26f9ff8c43836fd35778db61915ce37fd2025ba7

9 years agoMerge "Revert "Add logging of calloc failures."" into lmp-dev
Ben Murdoch [Sat, 2 Aug 2014 09:47:35 +0000 (09:47 +0000)]
Merge "Revert "Add logging of calloc failures."" into lmp-dev

9 years agoRevert "Add logging of calloc failures."
Ben Murdoch [Sat, 2 Aug 2014 09:43:22 +0000 (09:43 +0000)]
Revert "Add logging of calloc failures."

This reverts commit 96dd5bfec1693fee29ed0c728cf6ab4f0f0ec6e9 as it breaks the
64b build.

Bug: 16734745
Change-Id: Icf83b35ca0f99c2b5d6d919cfc8c2b02ee980e0b

9 years agoAdd logging of calloc failures.
Robert Greenwalt [Fri, 1 Aug 2014 23:19:02 +0000 (16:19 -0700)]
Add logging of calloc failures.

bug:16734745
Change-Id: I30437983e93fc2420e291e3d2e6ffbe4d8a47af4

9 years agoMerge "Add logging of calloc failures." into lmp-dev
Robert Greenwalt [Fri, 1 Aug 2014 23:46:24 +0000 (23:46 +0000)]
Merge "Add logging of calloc failures." into lmp-dev

9 years agoRemove default routing rule & table before we forget table number.
Paul Jensen [Fri, 1 Aug 2014 14:54:03 +0000 (10:54 -0400)]
Remove default routing rule & table before we forget table number.

We clear the interface index cache when we remove an interface from a
network, so we must only do this after we remove the default rule so
we still know the table number (calculated from interface index).

bug:16728065
Change-Id: I538673dcba49820a9e21f60407754fae30de02cf

9 years agoMinor improvements to NetworkController error reporting.
Lorenzo Colitti [Wed, 30 Jul 2014 08:46:08 +0000 (17:46 +0900)]
Minor improvements to NetworkController error reporting.

Currently, when trying to perform an operation on netId that
does not exist, we return EINVAL. This can be confusing
because lots of things can return EINVAL for many different
reasons.

Instead, change this to ENONET ("Machine is not on network"),
which was what Sreeram originally implemented before we changed
it to EINVAL. I also considered ENOENT ("No such file or
directory"), but on reflection that seems less appropriate, and
it's used by other things as well. ENONET appears to have no
uses in our tree. It is also clearly separate from the ESRCH we
return for nonexistent rules.

While I'm at it, also disambiguate some of the
if (foo || bar ) { return EFOO; } to return two different error
codes.

Bug: 16667349
Change-Id: Ief2d720a58679aa746f5ba273d545487d0825e52

9 years agoStop copying directly-connected routes to the main table, #2.
Lorenzo Colitti [Tue, 29 Jul 2014 09:26:21 +0000 (18:26 +0900)]
Stop copying directly-connected routes to the main table, #2.

For a long time we have thought that copying directly-connected
routes to the main table was necessary to add gatewayed routes
to other routing tables. However, this is not necessary when the
directly-connected routes are properly created with "scope link"
as we do in http://ag/513100 .

Delete the copying code, but don't delete the rule that looks up
the main table or the code that dumps it. The main table is used
for things like cell networking, because the RIL emulates cell
networks, which are actually point-to-point, as directly
connected broadcast subnets (e.g., a /30 or a /27) with a fake
default gateway.  The directly-connected route that covers the
fake default gateway is implicitly created by adding the IP
address, but it's in the main table, so we can't add the default
route without looking up the main table.

Change-Id: I93bd4764ac75fdcc98fa4206c601524100d53fc3

9 years agoRevert "Stop copying directly-connected routes to the main table."
Lorenzo Colitti [Tue, 29 Jul 2014 09:25:44 +0000 (09:25 +0000)]
Revert "Stop copying directly-connected routes to the main table."

This reverts commit 2f5ea0e99e9a436cd43901b1772b77a410a62f8d.

Change-Id: I1fe1df0249714cb650a34fae56476236ac0108e3

9 years agoStop copying directly-connected routes to the main table.
Lorenzo Colitti [Tue, 29 Jul 2014 06:46:56 +0000 (15:46 +0900)]
Stop copying directly-connected routes to the main table.

For a long time we have thought that copying directly-connected
routes to the main table was necessary to add gatewayed routes
to other routing tables. However, this is not necessary when the
directly-connected routes are properly created with "scope link"
as we do in http://ag/513100 .

Delete the copying code, but keep dumping the main table in
bugreports, so we can see if third-party code such as RIL
daemons is putting anything in it.

Change-Id: Iddd531daaf9881ffd82f0a4b4f6cc857ce8788fd

9 years agoAdd "scope link" when adding routes without a nexthop.
Sreeram Ramachandran [Fri, 18 Jul 2014 20:03:47 +0000 (13:03 -0700)]
Add "scope link" when adding routes without a nexthop.

This is consistent with what /sbin/ip does, and it makes
recursive lookups on secondary tables work even when the main
table is empty.

This was originally proposed by Sreeram as http://ag/506456 to
fix a VPN issue, but then abandoned because it did not fix that
particular problem.

Bug: 16628572
Change-Id: I85753389c683ae2127b21af722463a35a33b60eb

9 years agoMerge "Prohibit address families by default unless a VPN explicitly allows them....
Sreeram Ramachandran [Mon, 28 Jul 2014 18:53:50 +0000 (18:53 +0000)]
Merge "Prohibit address families by default unless a VPN explicitly allows them." into lmp-dev

9 years agoProhibit address families by default unless a VPN explicitly allows them.
Sreeram Ramachandran [Sun, 27 Jul 2014 01:43:25 +0000 (18:43 -0700)]
Prohibit address families by default unless a VPN explicitly allows them.

Bug: 15972465
Change-Id: I3278d94536fefacc86390c1ba4231680f7be8589

9 years agoImplement support for bypassable VPNs.
Sreeram Ramachandran [Wed, 23 Jul 2014 20:27:31 +0000 (13:27 -0700)]
Implement support for bypassable VPNs.

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

9 years agoMerge "Fix fwmark handling for bypassable VPNs and DNS." into lmp-dev
Sreeram Ramachandran [Mon, 28 Jul 2014 18:52:15 +0000 (18:52 +0000)]
Merge "Fix fwmark handling for bypassable VPNs and DNS." into lmp-dev

9 years agoFix fwmark handling for bypassable VPNs and DNS.
Sreeram Ramachandran [Fri, 25 Jul 2014 02:04:32 +0000 (19:04 -0700)]
Fix fwmark handling for bypassable VPNs and DNS.

This is a significant change to the way fwmarks are handled for two purposes:

1. Bypassable VPN.

   This was introduced in http://ag/510058 and had an issue that if there's a
   default network, it would always be used in connect(), so the bypassable VPN
   wouldn't get any traffic. This CL fixes that issue by using the bypassable
   VPN's NetId in connect(). See the comments in the code for more details.

2. DNS.

   The previous DNS code (specifically, getNetworkForUser()) had two problems:

   + Even if a user asks for a NetId they have permission for, we'd always use
     the user's VPN if they were subject to one. So, for example, a system IMS
     app that brings up the mobile network in the presence of a VPN would still
     have its DNS queries sent over the VPN, instead of mobile as desired.

   + Any user could perform DNS over any valid network, even one they didn't
     have permissions for, as long as they weren't subject to a VPN. So, for
     example, an app could use the DNS servers of a different profile's VPN.

   This CL fixes those problems. See getNetworkForDns() for more details.

The two pieces above are inter-related. Previously, we never set the explicit
bit from the DNS code. But we need to do that if the user asks for a network
explicitly, for two reasons:

o So that the DNS query is really restricted to that network and doesn't
  fallthrough to the default network.

o So that the heuristic described in ON_CONNECT works in all cases. I.e., if the
  DNS proxy's connect() request comes in with the explicit bit NOT set, we know
  that the NetId can only be either the default network or a VPN.

This CL is not intended to be robust against race conditions. In general, very
little of the netd code is resilient. A separate effort needs to be undertaken
to carefully audit all the code and logic to guard against things like:

* A VPN being established between calls to getNetworkForDns() and connect().
* State changes between multiple calls to NetworkController from clients such as
  FwmarkServer and DnsProxyListener.
* Routing rules / iptables rules being set up in a less-than-ideal order.
* ... etc.

Bug: 15347374
Change-Id: I5baad9168c4f4f3ef4129e07234b4bf24b0d8ba2

9 years agoImplement the fallthrough rule to support split tunnel VPNs.
Sreeram Ramachandran [Wed, 23 Jul 2014 05:23:20 +0000 (22:23 -0700)]
Implement the fallthrough rule to support split tunnel VPNs.

Change-Id: Ibc48caedb5954c6b12bfa553d978bab56c4b09aa

9 years agoImplement the rule to forward traffic to local networks via VPNs.
Sreeram Ramachandran [Wed, 23 Jul 2014 01:51:06 +0000 (18:51 -0700)]
Implement the rule to forward traffic to local networks via VPNs.

Change-Id: I4bffb2ce854a6fa7d4c0d35b97f123d91c6a84d6

9 years agoCosmetic: Move some functions around to match rule priority order.
Sreeram Ramachandran [Wed, 23 Jul 2014 01:16:44 +0000 (18:16 -0700)]
Cosmetic: Move some functions around to match rule priority order.

Change-Id: I81af639b66ac66272e0fae2d53119de1bfa12e69

9 years agoRemove the oif=iface clause when tethering.
Sreeram Ramachandran [Tue, 22 Jul 2014 23:44:37 +0000 (16:44 -0700)]
Remove the oif=iface clause when tethering.

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

9 years agoCleanup: Delete dead code.
Sreeram Ramachandran [Sun, 20 Jul 2014 06:22:33 +0000 (23:22 -0700)]
Cleanup: Delete dead code.

Bug: 15413389
Change-Id: I315468832ef18ffc84174e54774ab63b86d284dc

9 years agoTry to undo iptables rules if a command fails.
Sreeram Ramachandran [Tue, 22 Jul 2014 19:40:36 +0000 (12:40 -0700)]
Try to undo iptables rules if a command fails.

As per review comments at:
https://googleplex-android-review.git.corp.google.com/#/c/504240/5/server/NatController.cpp@194

Bug: 15413694
Bug: 15413741
Change-Id: I99e2f83792fa81498447e4c03f5f8be1d2c43b7d

9 years agoFlush routing rules and add an "unreachable" rule on Init().
Sreeram Ramachandran [Sat, 19 Jul 2014 07:22:15 +0000 (00:22 -0700)]
Flush routing rules and add an "unreachable" rule on Init().

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

9 years agoFix WiFi-Direct and Tethering.
Sreeram Ramachandran [Tue, 15 Jul 2014 23:20:28 +0000 (16:20 -0700)]
Fix WiFi-Direct and Tethering.

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

9 years agoDon't reset a VPN's NetId in the connect() shim.
Sreeram Ramachandran [Sat, 12 Jul 2014 00:06:12 +0000 (17:06 -0700)]
Don't reset a VPN's NetId in the connect() shim.

Change-Id: I0cc6c0e221a40c9100c8f4c0c5e761fce3f9b0ae

9 years agoIntroduce a SELECT_FOR_USER fwmarkd command.
Sreeram Ramachandran [Fri, 11 Jul 2014 23:27:02 +0000 (16:27 -0700)]
Introduce a SELECT_FOR_USER fwmarkd command.

This lets SYSTEM apps mark a socket with the network that would apply to an
arbitrary UID. I.e., either the VPN that applies to that user, or the default
network, if there's no such VPN.

This command will be used by system apps that proxy stuff for a user, so that
they can route the same way that user would have. Examples of such system apps
are the DnsProxyListener, MediaServer and DownloadManager.

The "explicit" bit is NOT set, so that if the user's VPN is a split tunnel, the
route lookup will fall-through to the default network as desired.

The "protect" bit is set, so that the socket bypasses any VPN applicable to the
system app itself. Note that even if the uid being proxied for is also subject
to the same VPN, this still works because the relevant rule doesn't care about
the protected bit (see modifyVpnSystemPermissionRule() in RouteController.cpp).

Change-Id: I4d501e5214b127f4ae9eaeb7befb1751cd102308

9 years agoCosmetic: Remove unnecessary constructor.
Sreeram Ramachandran [Fri, 11 Jul 2014 23:01:33 +0000 (16:01 -0700)]
Cosmetic: Remove unnecessary constructor.

Change-Id: Ib1de6e8988c4728e962da8607d0ecd98d6121e0c

9 years agoMerge "Add default routing tables to rt_tables."
Sreeram Ramachandran [Fri, 11 Jul 2014 22:29:49 +0000 (22:29 +0000)]
Merge "Add default routing tables to rt_tables."

9 years agoAdd default routing tables to rt_tables.
Sreeram Ramachandran [Fri, 11 Jul 2014 18:45:14 +0000 (11:45 -0700)]
Add default routing tables to rt_tables.

This is so that these tables also get dumped by bugreport / dumpstate.

Change-Id: Ia5ed8a23911d7b34ba964934dec42849f4a73824

9 years agoFix tethering in the case of a regular upstream connection.
Sreeram Ramachandran [Fri, 11 Jul 2014 16:10:20 +0000 (09:10 -0700)]
Fix tethering in the case of a regular upstream connection.

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

9 years agoCosmetic: Move constants into file scope.
Sreeram Ramachandran [Wed, 9 Jul 2014 14:39:30 +0000 (07:39 -0700)]
Cosmetic: Move constants into file scope.

Change-Id: Ic1398a5867693bb8f1e588e727869ec6a4574432

9 years agoAdd symbolic table names for routing table numbers.
Sreeram Ramachandran [Tue, 8 Jul 2014 05:11:37 +0000 (22:11 -0700)]
Add symbolic table names for routing table numbers.

This makes the output from "ip rule" much more readable.

Companion changes are in AOSP.

Change-Id: I69deb1a64d5d6647470823405bf0cc55b24b22de

9 years agoAdd full support for UIDs in VPNs.
Sreeram Ramachandran [Sun, 6 Jul 2014 00:15:14 +0000 (17:15 -0700)]
Add full support for UIDs in VPNs.

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

9 years agoUpdate routing rules.
Sreeram Ramachandran [Thu, 3 Jul 2014 19:20:48 +0000 (12:20 -0700)]
Update routing rules.

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

9 years agoFix permissions handling.
Sreeram Ramachandran [Sat, 5 Jul 2014 19:31:05 +0000 (12:31 -0700)]
Fix permissions handling.

+ 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

9 years agoOnly add permissions in accept(); do not try to enforce anything.
Sreeram Ramachandran [Sat, 5 Jul 2014 18:00:55 +0000 (11:00 -0700)]
Only add permissions in accept(); do not try to enforce anything.

Previously, we were enforcing that the user has access to the network over which
the socket is accepted. This has two problems:

1. We weren't handling the loopback interface ('lo') correctly. It's not part of
   any network, so the NetId in the fwmark is NETID_UNSET. In
   NetworkController::isUserPermittedOnNetwork(), we would fail to find a valid
   network, and so we would return false.

2. We have decided that in fact, we don't want to enforce this even for other
   interfaces, due to the SYN-ACK problem. See the comments and discussion at:
   http://go/android-multinetwork-routing

Bug: 16079376
Change-Id: I3f07f67d06dd7b48bfdfa5616ee22e098e31f8af

9 years agoFix regressions in flushRoutes().
Sreeram Ramachandran [Thu, 3 Jul 2014 01:06:34 +0000 (18:06 -0700)]
Fix regressions in flushRoutes().

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

9 years agoMinor style change.
Sreeram Ramachandran [Wed, 2 Jul 2014 21:49:33 +0000 (14:49 -0700)]
Minor style change.

Change-Id: Ib1f89bff55506cf3881047dd876adbf97c789423

9 years agoKeep track of users allowed to call protect() explicitly.
Sreeram Ramachandran [Wed, 2 Jul 2014 17:09:49 +0000 (10:09 -0700)]
Keep track of users allowed to call protect() explicitly.

This is an API change between ConnectivityService and Netd.

The ownerUid was meant for this purpose, but it's insufficient, as apps need to
call protect() _before_ they create a VPN.

Bug: 15409918
Change-Id: If804aa106002e96d5ffb623d32db35fd76928367

9 years agoCosmetic: Add a way to query the type of a network.
Sreeram Ramachandran [Wed, 2 Jul 2014 02:01:56 +0000 (19:01 -0700)]
Cosmetic: Add a way to query the type of a network.

This is a cosmetic change, i.e., there's no change in functionality.

This is the poor man's RTTI. It turns out that maintaining separate lists (or
maps) of the different types of networks gets burdensome pretty quickly
(especially in an upcoming CL where we add functions like
canUserSelectNetwork()).

Change-Id: If5250c0fc106045f681d0fd71278b793addbe1e3

9 years agoFix routing rules.
Sreeram Ramachandran [Tue, 1 Jul 2014 21:30:30 +0000 (14:30 -0700)]
Fix routing rules.

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

9 years agoDon't use %zu for uid_t. It's always unsigned int, so %u is correct.
Sreeram Ramachandran [Tue, 1 Jul 2014 22:49:20 +0000 (15:49 -0700)]
Don't use %zu for uid_t. It's always unsigned int, so %u is correct.

Change-Id: I5be1d479b524495037c2aedc8336c794d2698914

9 years agoUse %zu to printf size_t correctly on both 32-bit and 64-bit platforms.
Sreeram Ramachandran [Tue, 1 Jul 2014 22:06:05 +0000 (15:06 -0700)]
Use %zu to printf size_t correctly on both 32-bit and 64-bit platforms.

Change-Id: I5223e574084fca47606b844d74a99a642c7d66be

9 years agoAdd UID range support to VPNs.
Sreeram Ramachandran [Tue, 24 Jun 2014 01:54:27 +0000 (18:54 -0700)]
Add UID range support to VPNs.

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

9 years agoIntroduce VPN support.
Sreeram Ramachandran [Mon, 23 Jun 2014 19:41:37 +0000 (12:41 -0700)]
Introduce VPN support.

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

9 years agoRefactor: Encapsulate permissions and interfaces into a Network class.
Sreeram Ramachandran [Mon, 23 Jun 2014 16:54:06 +0000 (09:54 -0700)]
Refactor: Encapsulate permissions and interfaces into a Network class.

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

9 years agoDon't fail when adding a duplicate legacy route.
Sreeram Ramachandran [Fri, 27 Jun 2014 13:42:11 +0000 (06:42 -0700)]
Don't fail when adding a duplicate legacy route.

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

9 years agoConvert rta_* and fra_* variable names to camelCase.
Lorenzo Colitti [Thu, 26 Jun 2014 04:51:10 +0000 (13:51 +0900)]
Convert rta_* and fra_* variable names to camelCase.

Change-Id: I0ca539ac4c54bb71b033f288fb4229afd71b7989

9 years agoSupport adding and removing UID rules via netlink.
Lorenzo Colitti [Tue, 24 Jun 2014 18:20:29 +0000 (03:20 +0900)]
Support adding and removing UID rules via netlink.

Change-Id: Idae13bceda869261689260759084b8d6ef1ff639

9 years agoPass rule modification errors back to CommandListener.
Lorenzo Colitti [Mon, 23 Jun 2014 06:09:54 +0000 (15:09 +0900)]
Pass rule modification errors back to CommandListener.

Change-Id: If01334dccad8b6230648713a57fd58be180ac66b

9 years agoUse netlink to add/delete rules as well as routes.
Lorenzo Colitti [Fri, 20 Jun 2014 14:03:29 +0000 (23:03 +0900)]
Use netlink to add/delete rules as well as routes.

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

9 years agoUnrevert the 'revert the "talk to netlink directly" change.'
Sreeram Ramachandran [Tue, 24 Jun 2014 23:09:21 +0000 (16:09 -0700)]
Unrevert the 'revert the "talk to netlink directly" change.'

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

9 years agoTemporarily revert the "talk to netlink directly" change.
Sreeram Ramachandran [Tue, 24 Jun 2014 22:03:52 +0000 (15:03 -0700)]
Temporarily revert the "talk to netlink directly" change.

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

9 years agoNetd: Interface controller: Demote a log message severity from warning to verbose.
Sasha Levitskiy [Mon, 23 Jun 2014 17:51:05 +0000 (10:51 -0700)]
Netd: Interface controller: Demote a log message severity from warning to verbose.

Change-Id: Ia8b2e6a0b039c2bda418a5f7138c0aac6b6c643b
Signed-off-by: Sasha Levitskiy <sanek@google.com>
9 years agoMerge "Pass route add/delete errors back to CommandListener."
Lorenzo Colitti [Mon, 23 Jun 2014 16:41:13 +0000 (16:41 +0000)]
Merge "Pass route add/delete errors back to CommandListener."

9 years agoReturn negative errno (instead of positive) on failure.
Sreeram Ramachandran [Sun, 22 Jun 2014 18:02:57 +0000 (11:02 -0700)]
Return negative errno (instead of positive) on failure.

http://ag/489245 changed some return values from bools to errno values. However,
in forthcoming CLs, @lorenzo uses the convention of negative errno to indicate
failure. So, be consistent with that style.

Change-Id: I3eac8f142c36a2e779cda289c07ee374c49e2f6b

9 years agoPass route add/delete errors back to CommandListener.
Lorenzo Colitti [Tue, 17 Jun 2014 15:41:58 +0000 (00:41 +0900)]
Pass route add/delete errors back to CommandListener.

Change-Id: Id1d6d578963080e141f71bc1303801fc53bce40a

9 years agoUse native netlink code instead of /sbin/ip to manipulate routes
Lorenzo Colitti [Tue, 17 Jun 2014 15:22:17 +0000 (00:22 +0900)]
Use native netlink code instead of /sbin/ip to manipulate routes

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

9 years agoNotify network observers of route changes.
Lorenzo Colitti [Thu, 12 Jun 2014 04:51:05 +0000 (13:51 +0900)]
Notify network observers of route changes.

This reverts commit 20d3f5e856a38ef22851e32d7f9b6a7cd02eb459.

Bug: 9180552
Change-Id: I004448e2f0c731f6ca2c6d3535dc4dd51a622293

9 years agoAdd getNetworkForSocket().
Sreeram Ramachandran [Fri, 20 Jun 2014 18:59:40 +0000 (11:59 -0700)]
Add getNetworkForSocket().

This doesn't require a roundtrip to netd, since anybody can read the SO_MARK.

Change-Id: I51dd17725c4534cb0d5dbc8e93e844e6a7847959

9 years agoReturn errors explicitly instead of using errno.
Sreeram Ramachandran [Fri, 20 Jun 2014 18:51:48 +0000 (11:51 -0700)]
Return errors explicitly instead of using errno.

Change-Id: Ia29f500e747a8c72d13a8f38c3b08c319c8c029a

9 years agoMerge "Add a client API to protect a socket from VPNs."
Sreeram Ramachandran [Fri, 20 Jun 2014 17:23:46 +0000 (17:23 +0000)]
Merge "Add a client API to protect a socket from VPNs."

9 years agoMerge "Revert "Notify network observers of route changes.""
Lorenzo Colitti [Fri, 20 Jun 2014 07:03:19 +0000 (07:03 +0000)]
Merge "Revert "Notify network observers of route changes.""

9 years agoRevert "Notify network observers of route changes."
Lorenzo Colitti [Fri, 20 Jun 2014 07:02:36 +0000 (07:02 +0000)]
Revert "Notify network observers of route changes."

This reverts commit d2f23fb6285000831f14cacc16881d96f6046c33.

Change-Id: Ifabbc6848ab33842461465fccb9886863a08aec6

9 years agoNotify network observers of route changes.
Lorenzo Colitti [Thu, 12 Jun 2014 04:51:05 +0000 (13:51 +0900)]
Notify network observers of route changes.

Bug: 9180552
Change-Id: Ic23025e4d7cb4e58ae59017777267ac45f00b434

9 years agoMerge "Flush both IPv4 and IPv6 routes."
Lorenzo Colitti [Fri, 20 Jun 2014 06:02:48 +0000 (06:02 +0000)]
Merge "Flush both IPv4 and IPv6 routes."

9 years agoFlush both IPv4 and IPv6 routes.
Lorenzo Colitti [Tue, 17 Jun 2014 07:14:17 +0000 (16:14 +0900)]
Flush both IPv4 and IPv6 routes.

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

9 years agoMerge "Notify network observers of route changes."
Lorenzo Colitti [Fri, 20 Jun 2014 05:52:15 +0000 (05:52 +0000)]
Merge "Notify network observers of route changes."

9 years agoserver: check interface names in RPC arguments for validity
JP Abgrall [Fri, 20 Jun 2014 01:35:24 +0000 (18:35 -0700)]
server: check interface names in RPC arguments for validity

This patch introduces a method isIfaceName that checks interface
names from various RPCs for validity before e.g. using them as
part of iptables arguments or in filenames.

All of these RPC calls can only be called from applications
with at least the CONNECTIVITY_INTERNAL permission in recent
Android versions, so the impact of the missing checks luckily
isn't very high.

Orig-Author: Jann Horn <jann@thejh.net>

Change-Id: I80df8d745a3de99ad02d6649f0d10562c81f6b98
Signed-off-by: JP Abgrall <jpa@google.com>
9 years agoAdd a client API to protect a socket from VPNs.
Sreeram Ramachandran [Thu, 19 Jun 2014 17:03:07 +0000 (10:03 -0700)]
Add a client API to protect a socket from VPNs.

The server side hasn't been implemented yet (see FwmarkServer.cpp).

A UID can only be in a single VPN at any time, so there's no need
to specify a netId or vpnId.

Change-Id: Ie9c4590a9900e1ebf28418c4b9c4760cc0a5501a

9 years agoCache interface indices in case interfaces go away.
Paul Jensen [Thu, 12 Jun 2014 20:46:37 +0000 (16:46 -0400)]
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

9 years agoMerge "Pass a socket mark to clatd so it can bind to its network."
Lorenzo Colitti [Fri, 13 Jun 2014 02:35:29 +0000 (02:35 +0000)]
Merge "Pass a socket mark to clatd so it can bind to its network."