Commit Graph

280 Commits

Author SHA1 Message Date
junyulai
c33ac0d43b Fix negative uid stats caused by 464xlat adjust when eBPF is on.
When using xt_qtaguid to count per uid stats,
NetworkStatsService needs to adjust the 464xlat traffic since
iptables module would double count for ipv4 and ipv6 packet.
But for eBPF, the per uid stats is collected in a different
hook, so the adjustment on root uid would only be needed in tx
direction.

Bug: 112226716
Test: 1. Make ipv4 traffic in ipv6-only network and check data
         usage.
      2. Make ipv4 traffic in a client which connect to
         ipv6-only hotspot.
      3. runtest frameworks-net
      4. cts-tradefed run cts -m CtsNetTestCases -t \
                 android.net.cts.TrafficStatsTest
      5. cts-tradefed run cts -m CtsUsageStatsTestCases

Change-Id: Ic9a84f5446eddc943c255d5f3b89dad171f53cac
2018-10-30 21:23:38 +08:00
Luke Huang
77017913a4 Refactor UidRange by using stable aidl structure
Use stable aidl generated structure instead of UidRange

Test: runtest frameworks-net passes
Test: manual testing of UidRange related function works
Change-Id: Iaf1c10777dc1e71df2be2a57533a10257b12626b
2018-10-24 19:45:09 +09:00
Mike Yu
f9729757f9 Add tests for the network blocked status change
onBlockedStatusChanged is intruduced for network blocked status.
The changes in this patch are:
  - Test onBlockedStatusChanged which tells apps whether the
    network is blocked.
  - Fixed the tests which is affected by the order changed in
    onAvailable.

Test: as follows
    - runtest frameworks-net
    - runtest -x NetworkPolicyManagerServiceTest.java
Bug: 74575553
Change-Id: I383c037ed895ef69c478dc3cff69fb1e27c42845
2018-10-19 19:52:50 +08: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
Treehugger Robot
23a73be430 Merge "InetDiagSocketTest: enable UDP unit tests on all devices" 2018-09-29 00:16:11 +00:00
Jeff Vander Stoep
f5dfad4b88 InetDiagSocketTest: enable UDP unit tests on all devices
Bug: 116849885
Test: atest InetDiagSocketTest
Change-Id: I3b036818cccd0959feb3a93bc722d70e3ef2c4d7
2018-09-28 08:49:41 -07: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
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
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
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
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
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
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
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
Remi NGUYEN VAN
2595e68176 Merge "Add utils to convert Inet4Address <-> int"
am: 5caebe3415

Change-Id: I347d23f4682eca623e3b10f72bc9000b1c5954a3
2018-08-06 09:34:55 -07:00
Remi NGUYEN VAN
5caebe3415 Merge "Add utils to convert Inet4Address <-> int" 2018-08-06 05:49:52 +00:00
Remi NGUYEN VAN
0066bda4cf Add utils to convert Inet4Address <-> int
The current utilities map the higher-order bytes of ints to the
lower-order bytes of IPv4 addresses, which makes applying masks and
generating series of addresses confusing.

For example, the current utilities would convert 1.2.3.4 to 0x04030201,
or generate 0x0080ffff for a /17 subnet mask. The utilities in this CL
convert 1.2.3.4 to 0x01020304, and a /17 subnet mask is represented as
0xffff8000.

Includes tests for all the above methods and migration of
NetworkUtilsTest to JUnit4.

Test: added tests pass
Change-Id: I5f5aa2e6e3b054b66b9dc507dab64f41be9139b1
2018-08-03 15:55:24 +09:00
Remi NGUYEN VAN
98e2f04ec0 Merge "Increase IpClientTest verification timeout"
am: 0cbdca3e20

Change-Id: I214df25ed178d859ae60d765c94fc9d6a25408ee
2018-07-27 02:11:47 -07:00
Remi NGUYEN VAN
01a34ac642 Increase IpClientTest verification timeout
apct runs have become significantly slower, which makes some of these
tests flaky. Increase the timeout as a first measure to avoid flakes.

Bug: b/111819270
Test: runtest -x IpClientTest.java
Change-Id: Ifb0091377f311b67ba3a4f9324ce1e8cfb421ea3
2018-07-27 12:52:28 +09:00
Andreas Gampe
4afe1f957b Merge "Apf: Avoid constant overflow"
am: 5b99659943

Change-Id: Iacf849e3739f24cd430e6210a2e6a1c67ae0614f
2018-06-18 01:20:28 -07:00
Andreas Gampe
5b003117b2 Apf: Avoid constant overflow
The used constant overflows. This is irrelevant to the test, so
decrease test constant.

Bug: 110155920
Test: m javac-check RUN_ERROR_PRONE=true
Change-Id: Idfc7e987ba9c36389a20c7fc01b1161ef89483d8
2018-06-14 08:43:07 -07:00
nharold
b2749539c0 Merge changes from topic "ipsec-sync-with-pi"
* changes:
  Disable the AppOp Restriction for IpSec Tunnels
  Rework Exception Handling for IpSecManager
  Update IpSecManager to use InetAddress and prefixLen
  Add AppOps Checks for MANAGE_IPSEC_TUNNELS
  Add MANAGE_IPSEC_TUNNELS Permission
2018-06-08 17:07:11 +00:00
Benedict Wong
fdda5697d7 Update IpSecManager to use InetAddress and prefixLen
LinkAddress constructors are currently @hide; this change updates
IpSecManager to use InetAddress and prefixLen, and then construct a
LinkAddress internally. LinkAddress is used over the binder interface to
IpSecService to ensure validity.

Bug: 77528639
Test: CTS, Java unit tests ran on walleye
Merged-In: I19e124adef6d9f4992d8293db3190bcf74c95848
Change-Id: I19e124adef6d9f4992d8293db3190bcf74c95848
(cherry picked from commit 3f2c54b782)
2018-06-07 18:42:52 -07:00
Nathan Harold
21208eeccc Add AppOps Checks for MANAGE_IPSEC_TUNNELS
Adds support for a new AppOp to permit services to
use IpSec tunnel mode. The IpSecService now needs
a context so change the service mode to a cached
service rather than a static service.

Bug: 66955045
Test: runtest frameworks-net
Merged-In: I17a4a286225b432c3e15ea1587d946189931b4f4
Change-Id: I17a4a286225b432c3e15ea1587d946189931b4f4
(cherry picked from commit 592dadbd43)
2018-06-07 18:42:52 -07:00
Chalard Jean
b044b885cf Merge changes Ia764b341,I4e4b41bb,I61b262d8,Ie6ace6bd,I21e866c7, ...
* changes:
  Let tests enumerate all transports/capabilities.
  Destroy networks as soon as they are disconnected.
  Fix a ConcurrentModificationException crash.
  Unify behavior of various cases of "no underlying networks"
  Fix: VPNs update caps upon underlying network disconnect.
  Add tests for setUnderlyingNetworks.
  Fix setCapabilities.
  Fix SSID not being logged by the validation logs
  Make sure getActiveNetwork is consistent with default callbacks
  Add tests for getActiveNetwork.
  Guard the SSID with NETWORK_SETTINGS
  Add a new ssid field in NetworkCapabilities.
  Notif manager and captive portal app to read SSID again
  Remove unwanted capability from the java-doc
  Actually @hide unwanted capability methods.
  API council requested tweaks to NetworkRequest.
  Add OEM_PAID capability to system api
  add airplane mode shell commands to connectivity
  Enable cleartext for captive portal apps
  Expose CONNECTIVITY_ACTION to Instant Apps
  fix isActiveNetworkMetered with VPNs
2018-06-06 08:25:45 +00:00
Chalard Jean
d1d8b627dd Fix setCapabilities.
P introduced setSSID, UIDs and unwanted capabilities.
None of these exhibit commutative behavior through combineCapabilities
because their semantics don't allow it. Therefore
NetworkRequest.setCapabilities() is badly broken around any of
these. Look at the comments in the new tests to realize the
extent of the damage.

Clean cherry-pick of ag/4083952

Bug: 79748782
Test: new tests written, old tests pass
Change-Id: Iafe074126132a82af37f4bf056c4a7b8d56bdc83
Merged-In: Ia5bebf8a233775367bbf1b788870528934ecbcfb
Merged-In: I13d7782a6c0c7b1f94137995bbb0d257a58d89c1
2018-06-06 08:24:43 +00:00
Chalard Jean
6bc18fbb5d Add a new ssid field in NetworkCapabilities.
Clean cherry-pick of ag/3887737

Bug: 77891227
Test: frameworks-net
Change-Id: Icefe1657bca52b913a72b56705342a7285769658
Merged-In: Ia1f4e51b7c2e9118789242cf6d9e7576c4167cda
Merged-In: I6dd1aba6fde5a502b4a9145cf16393d8ce623c89
2018-06-06 08:23:52 +00: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
59ccf1041f Merge "Send empty LinkProperties when entering StoppedState." 2018-06-04 07:41:51 +00:00
Bernie Innocenti
b1883f9abb Merge "apf: Increase test coverage of LDDW / STDW" am: e03b8ee7e0
am: 0bf54f4a2e

Change-Id: Ifa016ce8a4fcb3a43a03d0f1126c01638cbf21ef
2018-05-28 21:29:32 -07:00
Treehugger Robot
e03b8ee7e0 Merge "apf: Increase test coverage of LDDW / STDW" 2018-05-29 02:33:22 +00: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
96dbac0c5c Merge "Migrating remaining core networking tests to Junit4" 2018-05-25 03:27:39 +00:00
Hugo Benichi
fe530062ff Migrating remaining core networking tests to Junit4
Bug: 62918393
Test: runtest frameworks-net
Merged-In: I30f7eaa0307b8fad5a8de7a0da235a4f76c18677
(clean cherry-pick of I30f7eaa0307b8fad5a8de7a0da235a4f76c18677)

Change-Id: I272fea0bb4a9e7f6252bb3bd14a6b769a082039e
2018-05-24 16:24:47 +09:00
Remi NGUYEN VAN
13e6e21db9 Add configurable captive portal probes
The probes allow testing for a configurable status code and location
header (regexes). They are disabled by default, so this CL is a
no-op unless the probe configurations are pushed.

Bug: b/79499239
Test: tests in CL pass, manual: captive portal login works
Merged-In: Iec7a74bbf2569a91e958c497200d77e8451cbf7b
Merged-In: Ia958815325d1466345e9626efc8f62fc9d08d774
(clean cherry-pick of pi-dev I785723aaed06054b9aa8ebff77803f23d7836db9)

Change-Id: I18b3f263fed08fa4fee20d5e88f3ec8647d7f835
2018-05-24 12:08:36 +09:00
Remi NGUYEN VAN
23d3487caa Merge "Add configurable captive portal probes" into pi-dev
am: 1f8f21af60

Change-Id: Iec7a74bbf2569a91e958c497200d77e8451cbf7b
2018-05-23 15:22:24 -07:00
Remi NGUYEN VAN
1f8f21af60 Merge "Add configurable captive portal probes" into pi-dev 2018-05-23 14:26:39 +00:00
Remi NGUYEN VAN
8255c2d6c2 Add configurable captive portal probes
The probes allow testing for a configurable status code and location
header (regexes). They are disabled by default, so this CL is a
no-op unless the probe configurations are pushed.

Bug: b/79499239
Test: tests in CL pass, manual: captive portal login works
Change-Id: I785723aaed06054b9aa8ebff77803f23d7836db9
2018-05-23 20:48:46 +09:00
Chalard Jean
c60a252b87 Merge "Fix setCapabilities." into pi-dev
am: d1d4cc94ba

Change-Id: I13d7782a6c0c7b1f94137995bbb0d257a58d89c1
2018-05-22 01:01:39 -07:00
Chalard Jean
4c4bc93b5e Fix setCapabilities.
P introduced setSSID, UIDs and unwanted capabilities.
None of these exhibit commutative behavior through combineCapabilities
because their semantics don't allow it. Therefore
NetworkRequest.setCapabilities() is badly broken around any of
these. Look at the comments in the new tests to realize the
extent of the damage.

Bug: 79748782
Test: new tests written, old tests pass
Change-Id: Ie46581bdaf9ecc2f14aab44788bbdb27a3fec8c1
2018-05-21 14:46:40 +09:00
Bernie Innocenti
3d479d9ad8 apf: Increase test coverage of LDDW / STDW
Add testcases covering interesting combinations of offset size and sign.
Also adjust a few existing testcases to increase interpreter coverage.

Bug: 73804303
Test: runtest -x tests/net/java/android/net/apf/ApfTest.java
Change-Id: I7f1a9166e81656711c57af7c72608e53666aae6f
2018-05-11 18:27:01 +09:00
Chalard Jean
03dbf6bd5e Add the list of private DNS addresses to LinkProperties
(clean cherry-pick from ag/3874803)

Test: atest android.net.LinkPropertiesTest, also new tests pass
Bug: 73641539
Change-Id: If33a35b1354a67db09411ff098f20064797296ad
Merged-In: I4b739c56e658690532ae9deb0b9a3bc9b2adf8b0
Merged-In: I6bdbef78d078d68534c8e07e9af031ce374560ef
2018-04-27 13:32:10 +09:00
Bernie Innocenti
825c739486 apf: Add immediate encoding tests for LI
This tests that ApfGenerator knows how to optimally encode positive and
negative immediates of various sizes.

Equivalent tests will follow for LDDW and STDW.

Change-Id: Ia904aecb155c78569e3cf32a2431570281570481
Bug: 73804303
Test: runtest tests/net/java/android/net/apf/ApfTest.java
(cherry picked from commit 18050000d7)
2018-04-24 21:28:49 +09:00
Chalard Jean
1bb54ae872 Merge "Add the list of private DNS addresses to LinkProperties" into pi-dev
am: f12a2130a4

Change-Id: I4b739c56e658690532ae9deb0b9a3bc9b2adf8b0
2018-04-20 04:49:43 -07:00
TreeHugger Robot
580a1ed904 Merge "Adjust APF interpreter tests to match APFv4" into pi-dev 2018-04-20 11:41:52 +00:00
Bernie Innocenti
deb145d233 Adjust APF interpreter tests to match APFv4
Change-Id: I4311c754f1cb79633d49c5c1c0b4e27c8dde727e
Bug: 73804303
Test: runtest -x tests/net/java/android/net/apf/ApfTest.java
(cherry picked from commit 545d9367e2)
2018-04-20 17:37:09 +09:00
Chalard Jean
9419b11458 Add the list of private DNS addresses to LinkProperties
Test: atest android.net.LinkPropertiesTest, also new tests pass
Bug: 73641539
Change-Id: If33a35b1354a67db09411ff098f20064797296ad
2018-04-20 16:48:43 +09:00