Commit Graph

662 Commits

Author SHA1 Message Date
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
Remi NGUYEN VAN
34d197bc2d Add framework-connectivity to tethering tests
This is necessary for tethering tests to build against hidden
framework-connectivity APIs after it is moved out of
framework-minus-apex.

Bug: 179229316
Test: atest TetheringTests
Ignore-AOSP-First: Need manual cherry-picks
Change-Id: I912fcd19bacb75a5944409b07d8e014032657d4a
2021-03-19 13:16:01 +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
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
c162fc297f Merge "Do not start conntrack event monitor when running on R" 2021-03-16 08:03:46 +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
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
Lorenzo Colitti
e8e91c1726 Merge "Add test for RouterAdvertisementDaemon." 2021-03-15 13:21:03 +00:00
markchien
2af32e475f Add test for RouterAdvertisementDaemon.
bug: 154669942
Test: atest TetheringPrivilegedTests
Change-Id: I2bbea720c486d6bb47a8d86375847894e2b2f390
2021-03-15 08:20:57 +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
Maciej Żenczykowski
3357388742 Merge changes from topic "attach_bpfprog_in_mainline"
* changes:
  [NFCT.TETHER.15] Attach BPF program in the mainline module
  [NFCT.TETHER.14] Clear the BPF maps in BpfCoordinator ctor
2021-03-12 00:21:01 +00:00
Hungming Chen
3dbd4a1cc4 [NFCT.TETHER.15] Attach BPF program in the mainline module
Migrate Maze's BPF program attaching and detaching functions from
system/netd/server/OffloadUtils.{c, h} to tethering module.

Test: atest TetheringCoverageTests
Test case #1:
Enable WiFi hotspot and check tc filters are added or removed on both
wlan1 and rmnet_data#.

$ adb shell tc filter show dev wlan1 ingress
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream6_ether:[*fsobj] direct-action
not_in_hw id 2 tag 7cf020cc09a7c982
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream4_ether:[*fsobj] direct-action
not_in_hw id 7 tag 2f87d55b636c082c

$ adb shell tc filter show dev rmnet_data2 ingress;
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream6_rawip:[*fsobj] direct-action
not_in_hw id 3 tag 8b3885b75bd261de
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream4_rawip:[*fsobj] direct-action
not_in_hw id 6 tag b1c9478c91f8df9a

Test case #2:
Enable USB tethering and check tc filters are added or removed on both
rndis0 and rmnet_data#.

Test case #3:
Enable WiFi and USB tethering and check tc filter are added or removed
on rndis0, wlan1 and rmnet_data#.

Change-Id: I3f9a65043271bc8f5bf1b82ae505c471625ca9de
2021-03-11 17:49:42 +08:00
Hungming Chen
499d3cac73 [NFCT.TETHER.14] Clear the BPF maps in BpfCoordinator ctor
Needed while the system server has recovered from crash.

Test: atest TetheringCoverageTests
Change-Id: Idbed4887f5396537f0d0df97de8b482266dffbb7
2021-03-09 16:11:22 +08:00
Lorenzo Colitti
57957fe8a1 Make TestConnectivityManager send CONNECTIVITY_ACTION.
The tethering code still depends on CONNECTIVITY_ACTION for
upstream selection. Make TestConnectivityManager send these
broadcasts.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I6a32e99fafef9d6d2abec438ffc68164ab4c5bdf
2021-03-09 01:16:35 +09:00
Lorenzo Colitti
66287d3551 Use TestConnectivityManager in TetheringTest.
The changes required are:
- Change all usages of when(mCm.method()).thenReturn(...) to
  doReturn(...).when(mCm).method() because spies must use the
  latter syntax.
- In setDataSaverEnabled, set the mocked return value before
  sending the broadcast. Otherwise, the first time the method is
  called, the spy will attempt to send the broadcast, and will
  crash because it does not have permission to do so.

This does not do anything useful yet, but it will be used in
future CLs.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I968bfa76ead25b2d45ed1c0e8ede32df81401579
2021-03-04 23:06:52 +09:00
Lorenzo Colitti
b424a2794e Support building different UpstreamNetworkState test objects.
TetheringTest is only able to build UpstreamNetworkState objects
for mobile Internet networks. Support building wifi and dun
versions as well.

Bug: 173068192
Test: atest TetheringTests
Change-Id: Id46f1e5b65dbe04e84a5f56343821af260e2539e
2021-03-04 23:02:40 +09:00
Lorenzo Colitti
bf69824479 Change TetheringTest's UpstreamNetworkMonitor from mock to spy.
This allows future tests that want to exercise the interactions
between Tethering and UNM to do so.

Also verify what happens when UNM is initialized, and in setUp,
capture the NetworkCallback it files to track the default
network, so tests can send it NetworkCallbacks. (This callback
is only ever filed once.)

Test: test-only change
Change-Id: Iff9b62120cced41cc61263bfd4fa34f575d0ac00
2021-03-04 23:02:40 +09:00
Lorenzo Colitti
d025c562f0 Make TestConnectivityManager usable by other tethering tests.
Currently, this class is a static inner class of
UpstreamNetworkMonitorTest. Extract it to its own top-level class
so it can be used by other tests.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I6bdb090a99781ac2530b3924ac5c4cf78de315b0
2021-03-04 23:02:40 +09:00
Remi NGUYEN VAN
e43c960d50 Merge "Add flag to force choosing upstreams automatically" 2021-02-26 06:42:00 +00:00
Lorenzo Colitti
ffb0ccd04b Add a BpfMap#clear method.
A caller can mostly already do this via forEach(), but having a
specific method is faster (since the code does not need to read
the value) and easier to use.

The semantics of this method (e.g., ignore ENOENT while deleting
a key, but throw on any other error) match those of the native
BpfMap::clear method.

Test: new unit tests
Change-Id: I5cd32efd0f87c823cd2d0a2fa3a95a83093fb6f9
2021-02-24 06:09:46 +00:00
Kimberly Kreider
6413dd84cf Enable networking tests to be included in partial MTS files as well as
full mts.

Test: built locally and verified contents.
Bug: 170318013
Change-Id: Idea798841c067002d7b1f47da73a34052a8ab32c
2021-02-22 14:59:54 -08:00
Remi NGUYEN VAN
b4859198f5 Add flag to force choosing upstreams automatically
The flag allows overriding the value of config_tether_upstream_automatic
on released R devices, as issues have been found on devices where an
overlay was used to set it to false.

The flag is only usable on R devices, as S devices can either not set
the setting to false, or fix the underlying issues.

Bug: 173068192
Test: atest TetheringCoverageTests

Change-Id: Id99638916e08e596fab21cedd7bfe39906ce2fe5
2021-02-22 05:30:04 +00:00
Bob Badour
f5b346ed1d Merge "[LSC] Add LOCAL_LICENSE_KINDS to packages/modules/Connectivity" 2021-02-19 06:23:22 +00:00
Tomasz Wasilczyk
3cbccdb6c3 Don't crash Tethering service when WiFi feature is missing
Bug: 175430552
Test: disable WiFi feature on device with wlan0

Change-Id: Ie8b422ed6e0a0a98eb1c7e6072464859d9083ba5
2021-02-17 15:36:05 -08:00
Bob Badour
97e6be27f6 [LSC] Add LOCAL_LICENSE_KINDS to packages/modules/Connectivity
Added SPDX-license-identifier-Apache-2.0 to:
  Tethering/Android.bp
  Tethering/apex/Android.bp
  Tethering/bpf_progs/Android.bp
  Tethering/common/TetheringLib/Android.bp
  Tethering/tests/Android.bp
  Tethering/tests/integration/Android.bp
  Tethering/tests/mts/Android.bp
  Tethering/tests/privileged/Android.bp
  Tethering/tests/unit/Android.bp
  tests/cts/hostside/Android.bp
  tests/cts/hostside/aidl/Android.bp
  tests/cts/hostside/app/Android.bp
  tests/cts/hostside/app2/Android.bp
  tests/cts/hostside/certs/Android.bp
  tests/cts/net/Android.bp
  tests/cts/net/api23Test/Android.bp
  tests/cts/net/appForApi23/Android.bp
  tests/cts/net/jni/Android.bp
  tests/cts/net/native/dns/Android.bp
  tests/cts/net/native/qtaguid/Android.bp
  tests/cts/net/util/Android.bp
  tests/cts/tethering/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: I8534c580f0e2a17be146300b67b3604817b64507
2021-02-16 04:09:58 -08:00
Maciej Żenczykowski
c92e8ce636 fix TetheringCoverageTests
Test: atest TetheringCoverageTests now passes, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0d83de14784f323400a83ce282cae1a3e7b4b396
2021-02-11 16:06:46 -08:00
Lorenzo Colitti
4e92da06fa Dump counters in "dumpsys tethering bpf".
This CL adds the counters collected by the tethering programs to
the output of "dumpsys tethering bpf". The counter names are
fetched by JNI code at startup and then read by the debugging
code on demand.

Example from my device:

  Forwarding errors:
    TCP_CONTROL_PACKET: 67
    NON_GLOBAL_SRC: 13
    NON_GLOBAL_DST: 17
    LOCAL_SRC_DST: 7

Test: manual (debug-only code)
Change-Id: I7ec7992612556a4bca5f1b6bb52c655d6d870201
2021-02-10 04:43:03 +00:00
Lucas Lin
c0bae3c8c5 Merge "Add NetdStaticLibTestsLib into TetheringCoverageTests" 2021-02-02 03:38:37 +00:00
lucaslin
5dc7de221a Add NetdStaticLibTestsLib into TetheringCoverageTests
Add NetdStaticLibTestsLib into Tethering MTS , so that the tests
under client-libs can also be run when running tethering MTS.

Bug: 170598012
Test: atest TetheringCoverageTests
Change-Id: Idd47becaa4254ab80b74ad5f3ddcdd4b017a5e69
2021-01-27 17:54:56 +00:00
Lorenzo Colitti
f3b201f819 Remove IpServer.Dependencies#getIfIndex.
This code is unused.

Test: atest TetheringTests
Change-Id: Iaac422d72e8538b67798cb3ae3737deb7b426401
2021-01-27 00:53:59 +09:00
Lorenzo Colitti
51c1a95c82 Address comments on aosp/1559686.
Also remove some unnecessary line wrapping.

Test: atest TetheringTests
Change-Id: Ia7638b3198d7811cdbb34e959c50608cf1a656bf
2021-01-27 00:53:59 +09:00
Lorenzo Colitti
77262cea76 Add an isEmpty convenience method to BpfMap.
Test: new unit test
Change-Id: Ibec09f328e24111aee4760af2f75ea5a80ba84c3
2021-01-27 00:53:56 +09:00
Lorenzo Colitti
7bf39e56e1 Address a TODO in BpfMapTest.
Test: test-only change
Change-Id: I9a47234979cbb161dfcd0c97c54c0476aa753c5e
2021-01-27 00:53:02 +09:00
Lorenzo Colitti
5b1ed508cf Program the upstream IPv6 map in BpfCoordinator.
- Add methods to start and stop IPv6 forwarding upstream
- Populate the upstream IPv6 map when the first rule for any
  upstream/downstream pair is created.
- Clear the upstream IPv6 map when the last rule for any
  upstream/downstream pair is deleted.

Test: Added coverage to IpServerTest and BpfCoordinatorTest
Change-Id: Ib041081e95f5f449489ab63138de034222ffac8f
2021-01-27 00:52:09 +09:00
Lorenzo Colitti
d69a886235 Rename TetherDownstream6Value to Tether6Value.
The two value types are identical so there is no need to have
separate classes for them.

Test: atest TetheringTests
Change-Id: Ia622b082d0a44373d21f51222f5e675e5bde08e0
2021-01-27 00:52:09 +09:00
Lorenzo Colitti
3c35666892 Merge changes from topic "bpf_tether4_rename"
* changes:
  merge Tether{Down,Up}stream4{Key,Value} - part 3 - fixups
  merge Tether{Down,Up}stream4{Key,Value} - part 2 - java
  merge Tether{Down,Up}stream4{Key,Value} - part 1 - C portion
2021-01-26 13:01:22 +00:00
Lorenzo Colitti
ae27ecf5ad Fix a WTF in IpServerTest.
Bug: 178324405
Test: atest TetheringTests
Change-Id: I2069ea79f982e6bb197388edd7820a05d1e651f1
2021-01-26 15:14:26 +09:00
Maciej Żenczykowski
32874eb6bc merge Tether{Down,Up}stream4{Key,Value} - part 2 - java
Generated via:
  git grep 'Tether(Down|Up)stream4(Key|Value)' | cut -d: -f1 | sort -u | while read i; do
    sed -r -i 's@TetherUpstream4Value@Tether4Value@g' "$i"
    sed -r -i 's@TetherDownstream4Value@Tether4Value@g' "$i"
    sed -r -i 's@TetherDownstream4Key@Tether4Key@g' "$i"
    sed -r -i 's@TetherUpstream4Key@Tether4Key@g' "$i"
  done

  cd Tethering/src/com/android/networkstack/tethering
  git mv TetherUpstream4Key.java Tether4Key.java
  git mv TetherUpstream4Value.java Tether4Value.java

  git diff TetherDownstream4Key.java Tether4Key.java
  git diff TetherDownstream4Value.java Tether4Value.java
  git rm TetherDownstream4Key.java
  git rm TetherDownstream4Value.java

Fixup resulting 'import' duplication
  mcedit Tethering/apishim/31/com/android/networkstack/tethering/apishim/api31/BpfCoordinatorShimImpl.java
  mcedit Tethering/apishim/30/com/android/networkstack/tethering/apishim/api30/BpfCoordinatorShimImpl.java
  mcedit Tethering/apishim/common/com/android/networkstack/tethering/apishim/common/BpfCoordinatorShim.java
  mcedit Tethering/tests/unit/src/android/net/ip/IpServerTest.java

Test: N/A, requires follow up commit
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1dfc3108ca4bbd0cefc3420bc7e421594b62619c
2021-01-25 20:32:05 -08:00
Hungming Chen
dd833dee31 [NFCT.TETHER.10] Add/delete IPv4 offload BPF rules to/from BPF map
Access the IPv4 downstream and upstream BPF map with the built rules.

Test: atest TetheringCoverageTests
Change-Id: I8cd6e49b377c72250988019eea57f93cccd78309
2021-01-25 20:13:47 +08:00
Hungming Chen
46c30b1fd4 [NFCT.TETHER.1] Add conntrack monitor to BpfCoordinator
A preparation for starting monitoring conntrack event which is required
by IPv4 tethering offload.

Test: atest TetheringCoverageTests
Change-Id: Ied46aeca193554f52a90889dfdf92827e94845d6
2021-01-21 21:25:18 +08:00
Maciej Żenczykowski
a0e2c0445d refactor: continued
Test: builds, atest, TreeHugger
  git grep 'makeIngressKey|makeIngressValue|BpfIngressMap|TETHER_INGRESS_FS_PATH'
  no longer finds anything
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I27200d33cbc4ea2094b18e05bf93ab54c564da0b
2021-01-20 11:34:48 +00:00
Maciej Żenczykowski
770e0a7a8f refactor: TetherIngress becomes TetherDownstream6 (and friends)
Generated via:
  #!/bin/bash

  do_replace() {
    pushd "$1" >/dev/null
    shift
    git grep "$1" | cut -d: -f1 | sort -u | while read f; do
      sed -i -r "s@$1@$2@g" "${f}"
      git add "${f}"
    done
    popd >/dev/null
  }

  replace() {
    do_replace packages/modules/Connectivity/Tethering "$@"
    do_replace system/netd "$@"
  }

  do_reset() {
    pushd "$1" >/dev/null
    git rhh
    popd >/dev/null
  }

  main() {
    do_reset packages/modules/Connectivity/Tethering
    do_reset system/netd

    replace TetherIngressKey TetherDownstream6Key
    replace TetherIngressValue TetherDownstream6Value

    pushd packages/modules/Connectivity/Tethering/src/com/android/networkstack/tethering >/dev/null
    git mv TetherIngressKey.java TetherDownstream6Key.java
    git mv TetherIngressValue.java TetherDownstream6Value.java
    popd >/dev/null

    replace TETHER_INGRESS_PROG TETHER_DOWNSTREAM6_TC_PROG
    replace ingress_tether tether_downstream6
    replace ingress/tether_ tether_downstream6_
    replace TETHER_INGRESS_MAP TETHER_DOWNSTREAM6_MAP
    replace tether_ingress_map tether_downstream6_map

    replace getTetherIngressMapFd getTetherDownstream6MapFd
    replace getTetherIngressProgFd getTetherDownstream6TcProgFd

    replace mBpfIngressMap mBpfDownstream6Map
    replace bpfIngressMap bpfDownstream6Map
    replace printIngressMap printDownstream6Map
    replace 'BPF ingress map' 'BPF downstream ipv6 map'
  }

  main "$@"; exit

Followed by:
  cd system/netd
  # change regexp in tests/binder_test.cpp:3374
  git add tests/binder_test.cpp

(and whitespace adjustments to prevent lines from going over 100 characters)

Afterwards we have:
  $ adbz shell ls /sys/fs/bpf/tethering
  map_offload_tether_downstream6_map
  map_offload_tether_limit_map
  map_offload_tether_stats_map
  map_test_tether_downstream6_map
  prog_offload_schedcls_tether_downstream6_ether
  prog_offload_schedcls_tether_downstream6_rawip
  prog_test_xdp_drop_ipv4_udp_ether

Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib04dc0c6e3d034461f3f84e09f6fa93a862e1bb2
2021-01-19 23:18:46 -08:00
Maciej Żenczykowski
7928fde758 BpfMapTest - adjust paths for bpfloader change
that puts tethering mainline module maps and programs
under /sys/fs/bpf/tethering

Test: builds, boots, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If57e737168cefe9fe0fe180114c1d61918d20d21
2021-01-20 05:13:08 +00:00
Lorenzo Colitti
fab97c22b2 Merge changes Id87b88f6,I67dfba75
* changes:
  [NFCT.TETHER.6] Migrate tetherOffloadGetAndClearStats from netd to mainline
  [NFCT.TETHER.5] Migrate tetherOffloadSetInterfaceQuota from netd to mainline
2021-01-20 02:19:14 +00:00
Nucca Chen
2668d4a0e2 Merge changes I969d6182,Ie73f7b4d
* changes:
  [NFCT.TETHER.4] Migrate tetherOffloadRuleRemove from netd to mainline
  [NFCT.TETHER.3] Migrate tetherOffloadGetStats from netd to mainline
2021-01-19 11:29:22 +00:00
Maciej Żenczykowski
e9810ffef1 move bpf test map into a separate file
This allows for better separation of test vs production code:
we will add more test maps and programs here later.

Test: builds
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7b22e3e148ebf43fdf43dc68d0dea354f7627688
2021-01-18 18:36:00 -08:00