Commit Graph

404 Commits

Author SHA1 Message Date
Treehugger Robot
2a520365da Merge "Remove unused imports of libcore.io.Libcore." 2018-10-13 00:47:45 +00:00
Neil Fuller
031dfa6f33 Remove unused import
StructGroupReq is imported but not used.
The import can be removed.

Bug: 113148576
Test: build only
Change-Id: I6b2ec5eb3f6c6e298fcde8e47dfd0979f889ca1d
2018-10-10 17:17:56 +01:00
Tobias Thierer
30ff7a093e Remove unused imports of libcore.io.Libcore.
Test: Treehugger
Bug: 115503977
Bug: 117548625
Change-Id: I122fa68ddc2bd531f627dcac00834b47249bd56e
2018-10-10 15:49:51 +00:00
Remi NGUYEN VAN
3b12359e4c Merge "Send hostname and MTU options in DHCP ACK/OFFER" 2018-10-04 01:08:19 +00:00
Remi NGUYEN VAN
f90a92bb7b Send hostname and MTU options in DHCP ACK/OFFER
The hostname option is only sent when requested in the requested
parameters option. This matches current behavior.

Test: with aosp/763982, regression tests now all pass
      atest FrameworksNetTest
Bug: b/109584964
Change-Id: I793173fa893750ddbe72be09f4c2d70e5b285837
2018-10-01 11:01:39 +09:00
Remi NGUYEN VAN
f5d65c521c Don't throw a NPE in SharedLog#e
Some DhcpServer error code paths could cause a NPE, when the logError
callback was called without an exception. Allowing SharedLog#e to be
called with a null Throwable is less error-prone.

Bug: b/109584964
Test: atest FrameworksNetTests
Change-Id: Idbcdd330a9d1951b27aaf525aaf12e52e102872c
2018-09-27 12:20:15 +09:00
Jeffrey Vander Stoep
f8529dc891 Merge "Add ConnectivityManager.getConnectionOwnerUid()" 2018-09-21 21:04:20 +00:00
Jeff Vander Stoep
0ac2c0945b Add ConnectivityManager.getConnectionOwnerUid()
Allow VPN apps to lookup the UID owner of a network connection.

Requires specifying the:
 - IP address and port for both the source and destination of a TCP
   connection.
 - IP address and port for either source and destination or just
   source for a UDP connection.
Only TCP and UDP protocols are supported. Only connections for UIDs
that apply to the calling VPN app will be resolved. This is intended
to replace direct app access to /proc/net/{tcp,tcp6,udp,udp6}.

The implementation uses netlink inet_diag sockets[1] to perform
the lookup on TCP sockets as well as UDP sockets when supported
(kernel has CONFIG_INET_UDP_DIAG=y).

[1] http://man7.org/linux/man-pages/man7/sock_diag.7.html

Bug: 9496886
Bug: 109758967
Test: atest HostsideVpnTests
Test: atest InetDiagSocketTest on Taimen with CONFIG_INET_UDP_DIAG
    and on Sailfish without CONFIG_INET_UDP_DIAG.
Change-Id: I2bbc7072dd091e2e653dadf6dc05024c04180f34
2018-09-21 06:16:09 +00:00
Erik Kline
8e492f8de4 Use IPv6 hop limit from upstream interface.
Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - manually setting /proc/sys/net/ipv6/<upiface>/conf/hop_limit
      to various value yields RAs with expected hop limit settings
      in downstream RAs
Bug: 32163131
Change-Id: I248154ca9d836318bf21a2971d0884040525d9fc
2018-09-14 18:46:25 +09:00
Erik Kline
7a4ccc69d0 Initial rename to IpServer
Rename TetherInterfaceStateMachine to IpServer. IControlsTethering
is folded into IpServer.Callback and some of the dependencies in
TetheringDependencies are moved into IpServer.Dependencies.

Several things still need fixing, including:
    - convert message passing into method calls
    - the calls that enable forwarding should be moved up out of
      IpServer into the Tethering layer above it

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
Change-Id: I015f800ed23c8aa5c8c81a74d7b508abfcaab659
2018-09-13 15:46:01 +09:00
Erik Kline
95999bda8d Remove the last of the ResolvUtil uses
This is the completion of cleanup work started in aosp/674269.
Consequently, also remove ResolvUtil.

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - presubmit
Bug: 64133961
Bug: 72345192
Bug: 73872000
Bug: 78548486
Change-Id: I980f8a9b67f3f06f2d97a60f8e58e92c36316d40
2018-09-12 14:58:58 +09:00
Jacob Abrams
56fbfc0460 Fix ConcurrentModificationException crash due to race in IpClient
Bug: https://issuetracker.google.com/issues/114838819

Test: manual
Change-Id: Ifd1522ccaca10c0416fc2d00641c4effee37fc6c
2018-09-12 00:23:26 +00:00
Treehugger Robot
666bb5cf28 Merge "Try to set the hop limit to something suitable for 64share" 2018-09-11 05:55:37 +00:00
Erik Kline
5b43cea3c8 Tighten up neighbor timers if IpReachabilityMonitor is in use
Currently the kernel sends 3 probes, 1000ms apart when a neighbor is
in NUD_PROBE state (either naturally or artificially moved to that
state when, for example, confirming network configuration following
an AP association/roam).

With this change the device sends 5 probes at 750ms apart.  This
gives the network infrastructure a chance to respond to any of
5 probes instead of any of only 3, at a cost of increasing the total
probe time from 3s to 3.75s.

Future changes may read these values from settings (or from somewhere
else) so that experiments may be conducted or values adjusted based on
other information.

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - examinaton of /proc settings on wifi shows updated values
    - connected to a test network, disconnected the backhaul, ran
      "adb shell dumpsys wifi ipclient confirm" while watching
      "adb shell tcpdump -n -i wlan0 -l -vv arp", and observed
      5 ARP who-has ("solicits") ~750ms apart.
Bug: 62476366
Bug: 62845299
Change-Id: Ib805531b08624805bb63703a5b338b9ff48171d4
2018-09-06 11:41:39 +09:00
Erik Kline
abb70339ea Try to set the hop limit to something suitable for 64share
Introduce hopLimit into RaParams so in future the value can be passed
in from the control plane up in Tethering.

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
Bug: 32163131
Change-Id: I8d2f056dcd55d76e89199db1196754fb690250e8
2018-09-05 17:08:07 +09:00
Remi NGUYEN VAN
e1a1dcc994 Ignore DHCP discover and request w/ invalid giaddr
This matches previous behavior, and there could be situations where
another server on the network would be configured to reply to such
requests, so not replying is better than sending NAKs as done now.

Also refactoring requests in DhcpLeaseRepositoryTest and replacing some
INETADDR_UNSPEC usages for giaddr with INET4_ANY (giaddr is a BOOTP
field and can't be unspecified, only empty).

Test: Following DhcpServerTest.py regression tests pass:
      test_request_selecting_giaddr_outside_subnet
      test_discover_requestaddress_giaddr_outside_subnet
      test_discover_knownaddress_giaddr_outside_subnet
      test_discover_giaddr_outside_subnet
      Also: atest FrameworksNetTests passes
Change-Id: I4decffccfc64d5e0e29c9ce1cf1446644fcf8190
2018-08-31 13:23:39 +09:00
Remi NGUYEN VAN
8975ab6322 Send ciaddr in DHCP server ACK if set by client
RFC2131#4.3.1 specifies that ciaddr should be set to the "'ciaddr' from
DHCPREQUEST or 0". Previous behavior sets ciaddr if provided by the
client in DHCPREQUEST, so keeping this behavior.

Bug: b/109584964
Test: DhcpServerTest.py debian/macos/win10 renewing test pass
Change-Id: I283e88b1f66f39d24589c5af4518cf9a2e77b95d
2018-08-30 18:23:23 +09:00
Remi NGUYEN VAN
9865cc1bd2 Minor logging fixes for new DHCP server
- Do not use Inet4Address#toString(), but Inet4Address#getHostAddress()
 - Dump enableLegacyDhcpServer in TetheringConfiguration

Bug: b/109584964
Test: manual: flashed, observed logs
Change-Id: I1f4d008b8bb1818e05a68ac0b5da4ce856cc1588
2018-08-30 17:30:56 +09:00
Remi NGUYEN VAN
6557a2464e Fix DHCP options sent by DHCP server
Add Android metered option, rebinding time option (T2), and match
current order of options.  Current DHCP server uses subnet_mask,
broadcast_address, router, name_server in this order.

Test: DhcpServerTest.py:test_discover_paramrequestlist passes
      atest FrameworksNetTests passes

Bug: b/109584964
Change-Id: I58f904d5fac306f704c16234fd69c2440fe0803d
2018-08-30 16:13:20 +09:00
Remi NGUYEN VAN
e59d031fb9 Fix BOOTP fields for server-generated DHCP packets
Set siaddr to the server address instead of zero in DHCPOFFER
Set siaddr to zero instead of the server address in DHCPNAK
Set giaddr to the relay address instead of the server address in
DHCPNAK
Set giaddr to the relay address instead of zero on DHCPACK and
DHCPOFFER
Set server identifier option in DHCPNAK

Current code is not compliant with RFC2131 and does not match dnsmasq
behavior. It was not an issue until now since the packets were only used
by the DHCP client, which does not send DHCPOFFER or DHCPNAK.

Bug: b/109584964
Test: following DhcpServerTest.py regression tests pass:
      test_discover_bootpfields
      test_request_selecting_inuse
      test_request_rebinding_relayed
      test_discover_relayed_broadcastbit
      test_request_rebinding_wrongaddr_relayed
      Also: atest FrameworksNetTests

Change-Id: Ie0bf780498e38945444bff66ca499cff5983a97f
2018-08-30 15:54:02 +09:00
Erik Kline
397f8110b5 Also copy-construct multinetwork policy preference
Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - manual bluetooth tethering testing doesn't seem to trigger any
      actual tethering, since bt-pan interface keeps going down on
      test device (IpClient never really starts up fully)
Bug: 62476366
Bug: 113136023
Change-Id: I3265f60f8ae125eba4545cb652c95a2f70049058
2018-08-29 16:55:47 +09:00
Remi NGUYEN VAN
ef7432f245 Merge "Ignore DHCP packet sent from non-68 client port" 2018-08-29 06:25:06 +00:00
Remi NGUYEN VAN
e3a0f42e8e Merge "Add DhcpServer" 2018-08-29 03:19:27 +00:00
Remi NGUYEN VAN
80f3ddca8a Merge "Add varargs methods to build DhcpServingParams" 2018-08-28 08:08:07 +00:00
Remi NGUYEN VAN
b0762eb3db Ignore DHCP packet sent from non-68 client port
This differs from previous behavior where dnsmasq would reply to port 68
if the client had no configured address (ciaddr empty in request), or
send replies to the client port if the request ciaddr matched the
assigned lease.
Not all DHCP servers preserve this behavior, and there is no good known
use-case for it. Not replying to such packets is less error-prone and
closer to the standard.

Bug: b/109584964
Test: Added test in DhcpServerTest.py passes
Change-Id: I88d467336cc4f4e4c9498c3787ec22fdef5e1cdd
2018-08-28 13:57:40 +09:00
Remi NGUYEN VAN
a13007ad0f Add DhcpServer
This first version can serve discover/request/release, although there
are some small behavior changes with current implementation which will
be addressed later.

Also removes final modifiers on start() and stop() in FdEventsReader, to
allow mocking the methods in tests with the current mockito lib.

Test: Added tests pass, manual: flashed a device using the server
Change-Id: I025366ff7d51c4ba31152af50f3dd2b5e280a54d
2018-08-28 12:50:47 +09:00
Remi NGUYEN VAN
a758720394 Add varargs methods to build DhcpServingParams
In common use-cases, only one gateway or DNS server may be set, so the
added methods make it easier for clients to build the parameters.

Bug: b/109584964
Test: runtest --no-hidden-api-checks frameworks-net
Change-Id: Ib54bc60a54ad4ef0605baea62d87b9f14caf8aa7
2018-08-27 10:57:14 +09:00
Treehugger Robot
18c144cf62 Merge "IpClient: fix in InitialConfiguration validation." 2018-08-24 09:18:38 +00:00
Remi NGUYEN VAN
bd0cc31c12 Add a SharedLog method to log errors w/ stacktrace
Test: manual: ran code using this method and checked log.
Change-Id: I2cea553ae0dd8a8f2f629718e92aa642c62eb120
2018-08-23 17:29:51 +09:00
Remi NGUYEN VAN
a420b57a6b Add DhcpServingParams
Those parameters will be used to start DhcpServer or update its
configuration.

Test: runtest DhcpServingParamsTest.java
Bug: b/109584964
Change-Id: Id8d3dcf62d66dcb02accffa8d8500e30f07af452
2018-08-23 17:29:48 +09:00
Remi NGUYEN VAN
1885805aac Add fields to DHCP packets for server use-case
Also add DhcpReleasePacket

Test: runtest -x DhcpPacketTest.java, manual: still obtains IP
Bug: b/109584964
Change-Id: I19e68e8857646555ea56995880979a8a722757d7
2018-08-23 16:03:12 +09:00
Remi NGUYEN VAN
c1413d0a27 Add DHCP utils extracted from DhcpClient
DhcpClient can then be migrated to at least DhcpSocketFactory, and
eventually DhcpPacketListener.
These classes will be used to implement the new DhcpServer.

FdEventsReader is PacketReader with generic T instead of byte[], to
allow reading both received payload and source IP from a UDP socket with
Os.recvfrom().

Bug: 109584964
Test: runtest --no-hidden-api-checks frameworks-net
Change-Id: Idd7dc36938748af701b45f50bde76a2592c9bfdd
2018-08-23 16:01:44 +09:00
Remi NGUYEN VAN
eca5b4e753 Add DhcpLeaseRepository
This is a first component to build the new DHCP server.

Test: added tests pass
Bug: b/109584964
Change-Id: I5657d89c3010a23e9289ac827bf78381477d1355
2018-08-23 15:55:39 +09:00
Hugo Benichi
509c0615fe IpClient: fix in InitialConfiguration validation.
This patch correctly invalidates InitialConfiguration objects with more
than one IPv4 address specified.

Bug: 111639419
Test: none
Change-Id: Ifda174636544311bee456f17946779bac7d4a49e
2018-07-24 09:13:58 +09:00
Erik Kline
de8eac9ae1 Merge "Always close file descriptors"
am: 26025a06ec

Change-Id: Ib1d8f74832b8b649dc83de39f8f16651a9924e69
2018-07-05 05:20:25 -07:00
Erik Kline
725e8f6856 Always close file descriptors
Every error thrown leaked a netlink NETFILTER socket.

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - enabled tethering and tried to cause conntrack updates to sessions
      that had expired (which causes ErrnoExceptions to be thrown)
      while monitoring lsof for system_server's NETFILTER sockets

Bug: 32163131
Bug: 64976634
Bug: 110122306

Change-Id: Ib52b812e8434c27ad9f2596666400c13e03c2216
2018-07-05 15:23:40 +09:00
Erik Kline
f415a67fc0 Merge "Randomize the local Wifi IPv4 address" am: 13cb6084e2
am: 9c69afc86f

Change-Id: I47d75c32ccd4bcbbb2f05637fcbae216d7e15015
2018-06-05 03:16:47 -07:00
Erik Kline
0f27eed8f6 Randomize the local Wifi IPv4 address
Also: address a few "error prone" warnings, adding @Override where missing

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes (with --no-hidden-api-checks)
    - wifi tethering uses a randomized address, in as much as it can work
Bug: 32163131
Bug: 70673901

Change-Id: Icfabc48f2cf97b362ce292747f47021e84b900da
2018-06-05 15:56:55 +09:00
Erik Kline
a5b35c7850 Merge "Send empty LinkProperties when entering StoppedState." am: 59ccf1041f
am: 48b64fd9f2

Change-Id: Ib946351005140d59e6a559610aa7448ab19c2630
2018-06-04 11:49:28 -07:00
Erik Kline
c8cb0f71d2 Send empty LinkProperties when entering StoppedState.
Additionally, no longer try to transition from within a State's
enter() method (this can encounter Log.wtf()s). Introduce some
CMD_JUMP_* commands and use deferMessage().

Test: as follows
    - built, flashed, booted
    - runtest -x IpClientTest passes
    - basic DHCP wifi association works
Bug: 69800563
Bug: 70394432
Bug: 80284937
Change-Id: I7ed6e1a994a3556af345e8a4dfb51c383f6d5478
(cherry picked from commit ffacb517d40df8ebb52d5906fa844b20c6520cd8)
2018-05-28 17:51:24 +09:00
Remi NGUYEN VAN
b19a838f47 Merge "Use AI_ADDRCONFIG for most DNS requests" 2018-05-25 03:28:05 +00:00
Remi NGUYEN VAN
a6085d17ca Use AI_ADDRCONFIG for most DNS requests
Not using it doubles the number of DNS lookups for single-stack
networks.
Private DNS hostname resolution still does not use this flag so that we
get all address families in advance, in case of LinkProperties changes.
Bug: b/79811321
Test: manual: Captive portal, 464xlat, networking in apps working
Merged-In: I7037342a93dc48b8e0988e719b9a9a2d5055bcf2
Merged-In: I8ca15fa079cd5ff94e4d9f7e0476504769f9708f
(Clean cherry-pick of pi-dev Ib46756e5e5f8d8d2698c90c5183c368d2d44be7a)

Change-Id: Iedb7a9c5f9caeb66de4505189fca8db91013d844
2018-05-24 11:42:05 +09:00
Remi NGUYEN VAN
37bef2a4e3 Use AI_ADDRCONFIG for most DNS requests
Not using it doubles the number of DNS lookups for single-stack
networks.
Private DNS hostname resolution still does not use this flag so that we
get all address families in advance, in case of LinkProperties changes.
Bug: b/79811321
Test: manual: Captive portal, 464xlat, networking in apps working

Change-Id: Ib46756e5e5f8d8d2698c90c5183c368d2d44be7a
2018-05-23 12:49:06 +09:00
Bernie Innocenti
ab30db7072 apf: Add counters for dropped / passed packets
ApfFilter maintains separate counters for each reason why a packet was
passed or dropped by the filter logic.

There's also a total which should match the individual counters,
*unless* the APF interpreter aborted execution early due to an illegal
instruction or an out-of-bounds access.

Test: both on APFv2 and APFv4-capable device:
	runtest -x tests/net/java/android/net/ip/IpClientTest.java
	runtest -x tests/net/java/android/net/apf/ApfTest.java
	manual tests connected to an AP
Bug: 73804303
Change-Id: I54b17fcbb95dfaea5db975d282314ce73d79d6ec
Merged-In: I54b17fcbb95dfaea5db975d282314ce73d79d6ec
(cherry picked from commit 3cc40ea6c5)
2018-05-15 14:21:54 +09:00
Bernie Innocenti
40b43542c1 Add support for reading a snapshot of the APF data
No functional change yet, since startReadPacketFilter() has no callers
at this time.  In the future, this new hook will be used to take
periodic snapshots of the APF memory (for instance, when the device
wakes up).

Design note: WifiStateMachine grabs the APF data synchronously
from another thread, but then the data snapshot is delivered to IpClient
via an asynchronous reply, following the same pattern used by other
commands. This means that there's no (practical) way for IpClient to
read the APF data just before replacing the APF program.

Even with this limitation, it's still possible to reliably decode packet
counters and compute deltas relative to the last snapshot, provided that
the address range isn't cleared when installing a new APF filter.

Bug: 73804303
Test: Manual - called the new code and inspected 'dumpsys wifi' output.
Change-Id: Ia0923d71cf3ee4128fb1c381557316300adac1a3
Merged-In: Ia0923d71cf3ee4128fb1c381557316300adac1a3
Merged-In: I3b940f5a3b795f85d244882eaa7eca56bd9e167d
Merged-In: I283fd5fb71f8a679911e58c487a4ac12a5190049
(cherry picked from commit bb2193bf58)
2018-05-15 14:21:30 +09:00
Bernie Innocenti
8d65db32eb Disable APF memory clear on pre-APFv4 devices
Fixes a system crash on HU when connecting to a wifi AP.

Change-Id: I8b71323985b6c5fc8a75f99470c9f86343d57f90
Bug: 78905546
Test: manually on android auto device
2018-05-10 22:59:22 +09:00
Erik Kline
c172c7d815 Add static IpClient logging
Support keeping IpClient logs around and dumping them
during dumpsys.  Previously we got this benefit for
wifi by virtue of WifiStateMachine's long-lived nature.
Now that this is changing we need to be sure we have
logs, and this method gets us Ethernet logs as well.

Bug: 62476366
Bug: 77999594
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
    - dumpsys connmetrics [ipclient] works
Merged-In: Ib4daf0902cae91acadbe9965de1fb73c96a47bec
Merged-In: Ie947394fabcaca7fc1d067f095c2442ee2704593
Change-Id: I1136a83de8097fdb4130debe1eaf689be7132fe5
(cherry picked from commit 3f8306b8c5)
2018-05-03 18:00:09 +09:00
Erik Kline
3f8306b8c5 Add static IpClient logging
Support keeping IpClient logs around and dumping them
during dumpsys.  Previously we got this benefit for
wifi by virtue of WifiStateMachine's long-lived nature.
Now that this is changing we need to be sure we have
logs, and this method gets us Ethernet logs as well.

Bug: 62476366
Bug: 77999594
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
    - dumpsys connmetrics [ipclient] works
Change-Id: I1136a83de8097fdb4130debe1eaf689be7132fe5
2018-05-02 21:53:17 +09:00
Bernie Innocenti
3cc40ea6c5 apf: Add counters for dropped / passed packets
ApfFilter maintains separate counters for each reason why a packet was
passed or dropped by the filter logic.

There's also a total which should match the individual counters,
*unless* the APF interpreter aborted execution early due to an illegal
instruction or an out-of-bounds access.

Test: both on APFv2 and APFv4-capable device:
	runtest -x tests/net/java/android/net/ip/IpClientTest.java
	runtest -x tests/net/java/android/net/apf/ApfTest.java
	manual tests connected to an AP
Bug: 73804303
Change-Id: I54b17fcbb95dfaea5db975d282314ce73d79d6ec
2018-04-27 23:30:23 +09:00
Erik Kline
d324dcecef Fix CaptivePortalLoginActivity probes to bypass Private DNS
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
    - manual testing on captive portal networks
Bug: 64133961
Bug: 77140445
Bug: 78548486

Merged-In: I749e8b5dba3b4af9ecb82bfb558c6f0e664531a4
Merged-In: Ic76d55861f385d1aecd360adda7f10142d083a47
Change-Id: Idbc4d90eeec257b36c5f374d61dea4600a0f8ebb
(cherry picked from commit 848d842a3a)
2018-04-26 14:54:48 +09:00