Commit Graph

1174 Commits

Author SHA1 Message Date
Lorenzo Colitti
48cd598f81 Add unit tests for race conditions in upstream selection. am: 6748e62ef2 am: afb685e650
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662399

Change-Id: I08b9b57734374ab12634ea8ba20c718c6e7c3280
2021-04-06 04:42:29 +00:00
Lorenzo Colitti
6748e62ef2 Add unit tests for race conditions in upstream selection.
In the current tethering code, upstream selection is only
triggered by CONNECTIVITY_ACTION. But in automatic mode, the
upstream network is selected by listening to a NetworkCallback
that tracks the default network.

This causes a race where if the CONNECTIVITY_ACTION for a network
switch is received and processed before the callbacks for that
network switch, upstream selection just re-selects the upstream
currently in use.

Make it possible to test this by giving TestConnectivityManager
the ability to choose the ordering between NetworkCallbacks and
CONNECTIVITY_ACTION, and to run an arbitrary Runnable between
calling one and calling the other. TetheringTest passes a
Runnable that calls mLooper.dispatchAll(), which ensures that
the tethering code fully processes the first set of information
it receives (either the broadcast (or the callbacks) before
receiving any more information.

Add test coverage to testAutomaticUpstreamSelection that
exercises various orderings, and make the test pass by expecting
the buggy behaviour of the current code.

An upcoming CL will fix the bug and update the tests.

Bug: 173068192
Test: test-only change
Change-Id: I7805444dcf59f6d5f8517fbcf2f2b1641783d50b
2021-04-05 14:51:53 +09:00
Lorenzo Colitti
6ca408f317 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7 am: a16ca88456
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: Ib095466f92872d50cc751b34cc870df31dc8e345
2021-04-02 10:06:09 +00:00
Lorenzo Colitti
e9bc8c9db7 Dump the input destination MAC address for IPv4 flows.
This is needed for forwarding to work, so it should be dumped.

New output:

  Forwarding rules:
    29(29) -> 14(rmnet2) 86dd 00:00:00:00:00:00 00:00:00:00:00:00
    [ap_br_wlan2]: iif(iface) oif(iface) v6addr srcmac dstmac
      14(rmnet2) 29(ap_br_wlan2) 2001:240:2423:13fa:3c21:e35a:6a59:ff8a da:17:fd:70:3d:14 26:5b:b2:ee:bc:ba
    IPv4: [inDstMac] iif(iface) src -> nat -> dst
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:39208 -> 14(rmnet2) 100.102.14.231:39208 -> 172.217.175.3:80
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:47386 -> 14(rmnet2) 100.102.14.231:47386 -> 216.58.197.196:443

Also add a call to getHostAddress() to remove the / on IPv6
forwarding rules.

Test: manual
Change-Id: I347ea5a3fd88c51f1fae0c76c75dfa30c68a55ad
2021-04-02 05:42:22 +00:00
Aaron Huang
b3cc853814 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" am: 5316e1ff18 am: 9c3cfaa9b8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626079

Change-Id: Ic491a32bbc6bb8173f15f491adb31a942eb7e773
2021-04-01 16:45:23 +00:00
Aaron Huang
5316e1ff18 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" 2021-04-01 15:59:39 +00:00
Lorenzo Colitti
cece10d4e0 Rename members in TestConnectivityManager. am: 9bbdac6275 am: a6d9d23180
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1659938

Change-Id: If02ce4eed9804d705a575fe7171459dafba216c9
2021-04-01 08:39:16 +00:00
Lorenzo Colitti
a116b7f370 Add the ability to affect ordering in the tethering unit tests. am: 3e09f80e8a am: bdb012f733
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635021

Change-Id: Iee27da6e7f6972564ee062e789905197e8994aa9
2021-04-01 08:39:15 +00:00
Lorenzo Colitti
bd868cd5d0 Make Tethering file NetworkRequests only if needed. am: 2bcde0fd97 am: cce64f0dd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556199

Change-Id: I66b565a18a850c020f1289566c646bdda1b6bd94
2021-04-01 08:39:15 +00:00
Lorenzo Colitti
9902d8c14f Expose upstream requirements to UpstreamNetworkMonitor. am: 0e7e32ab2c am: 9dcd8587ed
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556198

Change-Id: I47a5bdced72c17ecc5182f57623de1ae21f29036
2021-04-01 08:39:14 +00:00
Lorenzo Colitti
9bbdac6275 Rename members in TestConnectivityManager.
These members are public mutable and their names are confusing.
Make them package-private and final.

Bug: 173068192
Test: test-only change
Change-Id: I87131c48f67b6614c25aa99e1cbc53196f49aa7c
2021-03-31 20:23:20 +09:00
Lorenzo Colitti
3e09f80e8a Add the ability to affect ordering in the tethering unit tests.
Currently, TestConnectivityManager immediately sends all
callbacks and broadcasts to the Tethering code as soon as the
test code makes any change.

This makes it impossible to affect the order in which those
events are delivered to the Tethering code, so it is not possible
to test for races.

Fix some of this as follows:
1. Make TestConnectivityManager post all its callbacks to the
   handlers that Tethering registered them with.
2. In TetheringTest, use the existing TestLooper object to
   advance time manually. Also use setUseRegisteredHandlers to
   ensure that the broadcasts are sent in order. This requires
   calling dispatchAll() after sending the broadcast to preserve
   the existing synchronous behaviour. Take advantage of that to
   remove lots of existing dispatchAll calls.
3. Add a TestLooper to UpstreamNetworkMonitorTest and use it.
   Keep the test passing by adding lots of mLooper.dispatchAll(),
   which is a bit ugly but probably acceptable given the
   additional coverage it provides.

This exposes an existing bug in the code where if upstream
selection is in automatic mode, and all CONNECTIVITY_ACTION
broadcasts are received before all NetworkCallbacks, the code
does not switch upstream.

In order to make the tests pass, re-order the CONNECTIVITY_ACTION
broadcasts with the NetworkCallbacks in TestConnectivityManager
so as not to trigger the bug. A future CL will make the order
configurable.

While I'm at it, switch TestConnectivityManager from HashMap to
ArrayMap, which is generally preferred for maps that do not
contain too many elements.

Bug: 173068192
Test: test-only change
Change-Id: I964f365c691fbc396ab0a87f292bd32b123011fe
2021-03-31 20:17:11 +09:00
Lorenzo Colitti
2bcde0fd97 Make Tethering file NetworkRequests only if needed.
Currently, Tethering files NetworkRequests even when
config_tether_upstream_automatic is enabled. This is incorrect:
when the automatic upstream selection is enabled, the tethering
upstream should always follow the default network and there is
no need to file any requests.

These requests are harmful when tethering is not using cellular
as its upstream, because:

- If the device does not use mobile data always on, the request
  causes the cellular network to be brought up, causing power
  draw.
- Even if the device does use mobile data always on, the request
  causes the cellular network to come to the foreground, which
  allows all apps to access it, causing potential data usage.

Amend the existing testGetCurrentPreferredUpstream to cover these
changes, by making that test case always set automatic upstream
mode. This does not result in any loss of meaningful test
coverage, because getCurrentPreferredUpstream is only ever called
when chooseUpstreamAutomatically is enabled.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I068a5338699a3ed04f24f97f785ea89ff5890e50
2021-03-31 19:27:17 +09:00
Lorenzo Colitti
0e7e32ab2c Expose upstream requirements to UpstreamNetworkMonitor.
UpstreamNetworkMonitor is the part of tethering that files
NetworkRequests for upstream netwoks, but it currently does not
know all the requirements for upstream selection. For example, it
does not know whether automatic upstream selection is in use.
This forces the upstream selection code to be split between
UpstreamNetworkMonitor and Tethering. This makes it difficult to
follow.

This CL ensures that all information about upstream requirements
(DUN required, automatic upstream selection, tryCell) is passed
to UpstreamNetworkMonitor so it can be aware of it.

This CL also removes the ability for UpstreamNetworkMonitor's
callers to call registerMobileNetworkRequest or
releaseMobileNetworkRequest. In a future CL, this will be
automatically done by UpstreamNetworkMonitor depending on the
upstream requirements.

This CL is a no-op refactoring with no behaviour changes.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I174f765c616e0dbe2aa493c12613e6131cff0666
2021-03-31 19:27:17 +09:00
Maciej Żenczykowski
d65201b5a1 bpf_progs - remove unused dependencies am: b1ffd2ce9b am: 2f780deb38
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1646235

Change-Id: I7fbb943db076cf3a70686a9c208bc82798a02cf1
2021-03-19 09:58:37 +00:00
Maciej Żenczykowski
b1ffd2ce9b bpf_progs - remove unused dependencies
Test: builds, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9414bde566bb73b696593587db854de3fb14cdcc
2021-03-19 03:39:42 +00:00
Maciej Żenczykowski
5066bb74a5 Merge changes Ibe325714,I44f3dc9e am: 63be468bf4 am: 3828871130
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1644628

Change-Id: I1636d12476f44d6b1e92ecc6d5335626cc07ea76
2021-03-18 22:41:56 +00:00
Maciej Żenczykowski
3f32a83207 fix whitespace in offload.c macro
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe325714f95a1accce8add16220a31ca15913816
2021-03-18 02:34:01 -07:00
Maciej Żenczykowski
af1f314cbd change PRIO_CLAT into a comment
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I44f3dc9e3a3462f275a04ed5601370f664b985a2
2021-03-18 02:33:56 -07:00
Aaron Huang
e931b159dd Update import class of TAG_SYSTEM_NEIGHBOR
TrafficStatsConstants.TAG_SYSTEM_NEIGHBOR is moved to
NetworkStackConstants so update the import class name for it.

Bug: 182349970
Test: FrameworksNetTests
      NetworkStackTests
      TetheringTests
Change-Id: I8fcd2772ed873d318233d3029184e4352245d4cd
Merged-In: I8fcd2772ed873d318233d3029184e4352245d4cd
2021-03-17 14:03:07 +08:00
Kimberly Kreider
56c0b8c40a Merge "Enable networking tests to be included in partial MTS files as well as full mts." am: 6f4d35119f am: 8266302ee7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1531141

Change-Id: Ida996c15aeed86febda6a44aa3625f53a882fda0
2021-03-17 03:07:45 +00:00
Kimberly Kreider
6f4d35119f Merge "Enable networking tests to be included in partial MTS files as well as full mts." 2021-03-17 02:23:54 +00:00
Maciej Żenczykowski
9788c4a2e6 Merge "Test conntrack event monitor on R" am: d5f07c1243 am: 4c9bfb1fbd
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1639707

Change-Id: Ib3f2e2253fafdf6bd306d065c6d8a8101cfcc6a1
2021-03-16 13:27:03 +00:00
Maciej Żenczykowski
d5f07c1243 Merge "Test conntrack event monitor on R" 2021-03-16 12:29:20 +00:00
Hungming Chen
62afc9809b Test conntrack event monitor on R
Should not {start, stop} conntrack event monitor on R because
it is used by S feature.

Test: atest TetheringCoverageTests
Change-Id: I57a0a84d46e973660b24fc10d314820ada0d45b9
2021-03-16 18:14:38 +08:00
Treehugger Robot
cde05e5133 Merge "Do not start conntrack event monitor when running on R" am: c162fc297f am: de2d7bef3b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1639703

Change-Id: I566869dbb5e14ced269e286597381533d6f92c1b
2021-03-16 09:05:40 +00:00
Treehugger Robot
c162fc297f Merge "Do not start conntrack event monitor when running on R" 2021-03-16 08:03:46 +00:00
Maciej Żenczykowski
d3bc95b1d2 Merge "add test for TetheringUtils::setupNsSocket()" am: d3bb5a544c am: b0c92ad6c8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1638165

Change-Id: If39dd7f5d6d4dbe1a0bbc487b743d6fbc360cd98
2021-03-16 07:07:10 +00:00
Lorenzo Colitti
804a3e1f98 Merge "Add a test for TetheringUtils.setupNaSocket." am: d5edbb9eb4 am: 706d7ffb3e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1639699

Change-Id: I957fc61a12f514de19496dd84d739dd794f040eb
2021-03-16 07:06:55 +00:00
Maciej Żenczykowski
d3bb5a544c Merge "add test for TetheringUtils::setupNsSocket()" 2021-03-16 06:23:06 +00:00
Hungming Chen
23ee901e76 Do not start conntrack event monitor when running on R
Starting conntrack event monitor on R devices is unnecessary because
no code uses them.

Bug: 177884581
Test: atest TetheringCoverageTests
Change-Id: I036cb8e29b32a4e220da9a52849b978a6ab821e4
2021-03-16 14:18:32 +08:00
Lorenzo Colitti
d5edbb9eb4 Merge "Add a test for TetheringUtils.setupNaSocket." 2021-03-16 06:17:37 +00:00
Maciej Żenczykowski
e7c57368f8 add test for TetheringUtils::setupNsSocket()
Bug: 154669942
Test: test-only change
Change-Id: I33fe5a92667a0a6ee38bbcfdee40405cd37cc30f
2021-03-15 21:10:21 -07:00
Lorenzo Colitti
82d4b9956d Add a test for TetheringUtils.setupNaSocket.
Because most of the tethering tests are unprivileged, we cannot
test this code on real sockets. So use an AF_UNIX socketpair.

Bug: 154669942
Bug: 182785371
Test: test-only change
Change-Id: I843fddb3aaeab33628438f3bcd6a4166062de962
2021-03-15 21:01:42 -07:00
Remi NGUYEN VAN
c53077244f Merge changes from topic "conn_resources_cp" am: 016e0b9261 am: 16763614c0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635019

Change-Id: Ib1c92cf86dbdae88ad384d7aa0bf71f84dbb85d4
2021-03-16 03:50:49 +00:00
Remi NGUYEN VAN
51bddeaaec Add ServiceConnectivityResources to tethering am: 60f4c2f425 am: fb1f5458d0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1620872

Change-Id: I9f87e230b74478658c603d83f98b4ede71f45b94
2021-03-16 03:50:47 +00:00
Remi NGUYEN VAN
fb1f5458d0 Add ServiceConnectivityResources to tethering am: 60f4c2f425
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1620872

Change-Id: Ieed8fd3fe6cca6857c8c398f73143df41ac2d743
2021-03-16 03:11:26 +00:00
Remi NGUYEN VAN
016e0b9261 Merge changes from topic "conn_resources_cp"
* changes:
  Add ServiceConnectivityResources to in-process APEX
  Add ServiceConnectivityResources to tethering
2021-03-16 02:29:31 +00:00
Lorenzo Colitti
b5c74b7f55 Merge "Add test for RouterAdvertisementDaemon." am: e8e91c1726 am: 464a83c23f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1485809

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: If012da4b4eb6b4aaf4999702708e63651cc9c249
2021-03-15 14:24:59 +00:00
Lorenzo Colitti
9c1e719174 Merge "Do not open BPF maps when running on R." am: d12f867cb0 am: 9bcb23851b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635300

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I734b4e0ac01f3cb8d0cc3cbdad0cbcc2515d9a47
2021-03-15 14:24:52 +00:00
Lorenzo Colitti
e8e91c1726 Merge "Add test for RouterAdvertisementDaemon." 2021-03-15 13:21:03 +00:00
Lorenzo Colitti
3c228f4923 Do not open BPF maps when running on R.
Opening the maps on R devices is unnecessary (because no code
uses them) and unsafe (because the maps might actually be in a
different format than expected by the module).

Always return null when opening the maps, so the code will safely
fall back to using netd for anything.

This only affects dump(). The production code never opens the
maps except via the shim, and only the S shim opens the maps.
Also check isAtLeastS in dumpCounters, because it opens the map
directly.

Bug: 177884581
Test: builds, boots, "dumpsys tethering" shows expected output
Change-Id: I5884490a5cc40fc529a12100ae5baaeae6a18f30
2021-03-15 10:44:53 +00:00
markchien
2af32e475f Add test for RouterAdvertisementDaemon.
bug: 154669942
Test: atest TetheringPrivilegedTests
Change-Id: I2bbea720c486d6bb47a8d86375847894e2b2f390
2021-03-15 08:20:57 +00:00
Remi NGUYEN VAN
235097b32b Merge "Update sources of Tethering module since it is renamed" am: e2c74e90a9 am: a564d023d0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626083

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ieede28a14ecfca4969eabb8954336ee0e07491c3
2021-03-15 02:48:59 +00:00
Remi NGUYEN VAN
e2c74e90a9 Merge "Update sources of Tethering module since it is renamed" 2021-03-15 01:32:47 +00:00
Remi NGUYEN VAN
2fb22c2a2b Add ServiceConnectivityResources to in-process APEX
The APK was added to the standard APEX, but is missing in the
in-process APEX.

Bug: 182557971
Merged-In: Ic2491f04880ff66abc3b2d3aaee6168e18f6d68a
Merged-In: Ibf982ceb5f0fd61c822399e3eeeb1ef5e500604d

Change-Id: Ibf982ceb5f0fd61c822399e3eeeb1ef5e500604d
Test: m
2021-03-14 12:33:30 +09:00
Lorenzo Colitti
9f8e962d48 Merge "Add a test for upstream selection." am: f427d49541 am: 939d48f96c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1611320

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I1f2430060ba0de9fa4d19fa290b31f114f72b13a
2021-03-12 15:16:49 +00:00
Lorenzo Colitti
f427d49541 Merge "Add a test for upstream selection." 2021-03-12 14:07:01 +00:00
Lorenzo Colitti
473399ceab Add a test for upstream selection.
Currently, upstream selection is split between the Tethering and
UpstreamNetworkMonitor classes. The UpstreamNetworkMonitor bits
are unit tested, but there are no tests for the interaction of
the two. Add a simple test.

In order to do this, remove the code that controls the
UpstreamNetworkMonitor spy from prepareUsbTethering. This is so
that the new test can call prepareUsbTethering but still rely on
the behaviour of the actual UpstreamNetworkMonitor.

Bug: 173068192
Test: atest TetheringTests
Change-Id: If2ef9af82bc0cbff9172e575ad3d7686e5b492da
2021-03-12 17:59:02 +09:00
Remi NGUYEN VAN
60f4c2f425 Add ServiceConnectivityResources to tethering
The resource package is used by service-connectivity to load its own
resources.

Bug: 182125649
Test: atest FrameworksNetTests

Merged-In: I3c7fc6285f10318ecef05a64e1179054bb831d99
Merged-In: Ic2491f04880ff66abc3b2d3aaee6168e18f6d68a

Change-Id: I3c7fc6285f10318ecef05a64e1179054bb831d99
2021-03-12 17:50:41 +09:00