Commit Graph

540 Commits

Author SHA1 Message Date
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
Hungming Chen
6971e91d62 [NFCT.TETHER.6] Migrate tetherOffloadGetAndClearStats from netd to mainline
A preparation for updating BPF map in mainline module.

Test: atest TetheringCoverageTests
Change-Id: Id87b88f6dfcdfe5765756442ed880933cd1c6baf
2021-01-15 18:40:55 +08:00
Hungming Chen
67c14b549f [NFCT.TETHER.5] Migrate tetherOffloadSetInterfaceQuota from netd to mainline
A preparation for updating BPF map in mainline module.

Test: atest TetheringCoverageTests
Change-Id: I67dfba750c7303e4aeaf65f5086db1290d176b4d
2021-01-15 18:40:48 +08:00
Hungming Chen
5ea9c4b64a [NFCT.TETHER.4] Migrate tetherOffloadRuleRemove from netd to mainline
A preparation for updating BPF map in mainline module.

Test: atest TetheringCoverageTests
Change-Id: I969d6182a307f46c8ed0a30960deb460ecedd8ea
2021-01-15 18:40:40 +08:00
Hungming Chen
b350d7589f [NFCT.TETHER.3] Migrate tetherOffloadGetStats from netd to mainline
A preparation for updating BPF map in mainline module.

Test: TetheringCoverageTests
Change-Id: Ie73f7b4d9b191e62cfdfe2cfa3360cc7210f17e8
2021-01-15 17:11:12 +08:00
Hungming Chen
dd55b91228 [NFCT.TETHER.2] Migrate tetherOffloadRuleAdd from netd to mainline
A preparation for updating BPF map in mainline module.

Test: atest TetheringCoverageTests
Change-Id: I6f8667bf110dae3e2805c2752ff59e7284a7bce0
2021-01-15 17:10:58 +08:00
Hungming Chen
7d05e6fddd Follow-up CL to the change at aosp/1498277
1. Correct the API annotation.
2. The entry deletion failure causes the exception in cleanTestMap().
3. Use AtomicInteger to be the counter in the lambda.

Test: atest BpfMapTest
Change-Id: I4a56038881a38bda993ef5303b71f0e2a99f03d1
2021-01-12 19:08:15 +08:00
markchien
7052688dde Provide a easy way to access bpf maps from java
A wrapper for bpf map opening, reading/writing, and iteration.

Bug: 173167302
Test: atest BpfMapTest

Change-Id: I792b41978b322c9e4969cd7b6c35d6978ab86bc4
2021-01-11 17:43:27 +08:00
markchien
c233b1807e Put tether/untether calls into handler queue
BT tethering is the only user of #tether and #untether API.
Enable BT tethering may fail by race between interface status change
and #tether call. In starting BT tethering flow, tethering may receive
pan interface DOWN and UP then PanService call #tether to request for
processing its pan interface. Tethering put interface status change
event into handler queue but it process #tether and #unether calls
right away without order them by queue. It makes tethering handle
binder call #tether before pan interface DOWN even DOWN event arrived
eailer. This cause BT tethering bring down by interface DOWN event
unexpectedly. Although this still can't fix all the race cases of
tethering, but at lesat this could fix the race mentioned above.

Bug: 173310882
Test: manual ON/OFF bt tethering
      atest TetheringTests

Change-Id: I2411378aa36ad4371cca12423bb65542cb8df7a1
2020-12-29 01:04:17 +08:00
markchien
f50f05ebcb Also update connected clients for local only tethering
mForwardedDownstreams is the set of downstreams who wanted upstream.
In other word, it don't contains localOnly tethering(e.g. local only
hotspot, wifi p2p tethering). Changing the list from mForwardedDownstreams
to mNotifyList make both tethered and localOnly tethering have connected
clients callback.

Bug: 172290164
Test: atest TetheringTests
Change-Id: I58fdb28efc616b00d63a1c237ea93aee4d8f2dcd
2020-12-22 23:23:09 +08:00
paulhu
862c8a1ea0 Fix tethering doesn't turn off issue
When user restriction turns on, all tethering functions should
be disabled. But tethering functions still work after
restrication is on. Because tethering request would be removed
from mActiveTetheringRequests after starting tethering that
will result in Tethering#isTetheringActive() always returns
false. Thus, update the design to check tethered interface to
ensure that any of tethering function is working.

Bug: 169596583
Test: atest TetheringTests
Test: Manually test that tethering function would be disabled
      and notification would show to user after restriction
      was on.
Change-Id: Icb9649a5ecdec2d029ac763b5b9b80042ad50eb9
2020-11-10 16:47:52 +08:00
Mark Chien
220e7854bd Merge "Fix null DadProxy failure in R Tethering unit test" 2020-11-06 11:00:19 +00:00
markchien
290e7c452b Fix null DadProxy failure in R Tethering unit test
Tethering unit test would verify the interfaction between DadProxy and
IpServer. Since DadProxy only available in S+, the test would fail if it
build with R sdk.

Bug: 171936270
Test: atest TetheringTests in both R and S
Change-Id: Ia73d4aa59d01400d1ccfd3fdc1b721e269cae952
2020-11-05 15:28:56 +08:00
Baligh Uddin
ebff93159e Adjust visibility for tests
BUG: 167962976
Test: TH
Merged-In: Ic89c084604788b4d41cf854e5015c8ce7791c64d
Change-Id: I12e326167c6fb61a59a919cdd0198ac8f8c84772
2020-11-04 05:06:58 +00:00
Baligh Uddin
f814b9b1ce Add visibility rules for packages/modules/Connectivity/Tethering
BUG: 167962976
Test: TH
Change-Id: Id28881b35cf24fc9517fa11af6d8e539ab244fa6
2020-10-29 02:11:55 +00:00
markchien
e3126480ba Add shared jarjar rule for tethering tests
Also jarjar com.android.net.module.util* to
com.android.networkstack.tethering.util*.

Bug: 171670016
Test: atest TetheringCoverageTests
Change-Id: I3bde9ad3c41adf36da99bd944303d88ce992201c
2020-10-26 18:20:25 +08:00
markchien
4607c5535b Add the flag and default enable selectAllPrefixRange
Also add MtsTetheringTest which only run if tethering mainline
module is installed.

Bug: 166057846
Bug: 170265597
Test: atest TetheringTests
Change-Id: I434dda81eb5fab700d873a8ff3429b4222f0c7e6
2020-10-19 16:50:29 +08:00
Mark Chien
8565b0244a Merge "Fix miss tracking downstream problem in PrivateAddressCoordinator" 2020-10-15 12:07:19 +00:00
markchien
634f0a8ec1 Fix miss tracking downstream problem in PrivateAddressCoordinator
The downstream do not be tracked if PrivateAddressCoordinator just
return cached address. Then, PrivateAddressCoordinator would not notify
that downstream if conflict happen.

Also remove the null check in getDownstreamPrefix because:
- An IpServer is only added to mDownstreams by requestDownstreamAddress.
- That method will only add the IpServer to mDownstreams if it has an
IPv4 address.
- As soon as that method returns, the IpServer sets mIpv4Address to the
address that was returned.
- When an IpServer is torn down, mIpv4Address is set to null after
releaseDownstream is called.

So it should never be possible for this to return null.

Bug: 168169687
Test: atest CtsTetheringTest
      atest TetheringTests
Change-Id: Ide5206b013acdc499344e1c839a830c5b245af41
2020-10-15 16:21:12 +08:00
Treehugger Robot
32456142c0 Merge "Test conflict notification work when using cached address" 2020-10-14 13:18:58 +00:00
markchien
ccf07b1dd6 Test conflict notification work when using cached address
This test catch the regression introduced in r.android.com/1432958.

Bug: 1432958
Test: atest TetheringTest

Change-Id: Id0c1afb5563954ffee1f598a3a5de6a245d77a0e
2020-10-14 17:02:29 +08:00
Mark Chien
8c9a2645d8 Merge "Allow tethering pick prefix from all of private address range" 2020-10-13 13:12:58 +00:00
markchien
d9acdccbd3 Allow tethering pick prefix from all of private address range
Currently tethering only pick prefix from 192.168.0.0/16. There is no
aviable tethering address if the upstream address is 192.168.x.y/16.
This change allow tethering to pick prefix from any private address
rnages. Now it still pick from 192.168.0.0/16 only to avoid behavior
change. Will have follow up commit to change the configuration.

Bug: 166057846
Bug: 170265597
Test: atest TetheringTests
      atest CtsTetheringTest

Change-Id: Ib6304eb8b4788e9196d0af48e72f00a6bda73a5f
2020-10-13 16:45:09 +08:00