Commit Graph

573 Commits

Author SHA1 Message Date
Hungming Chen
7c1973c98d [NFCT.TETHER.14] Clear the BPF maps in BpfCoordinator ctor am: 499d3cac73 am: 129077bd58 am: 9dba544999
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1623669

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Icc33ff9ddc0306bf58df81ff9f6e9756817a1534
2021-03-12 02:33:07 +00: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
Remi NGUYEN VAN
cede7f6032 Merge "Add flag to force choosing upstreams automatically" am: e43c960d50 am: a474b9edfa am: 62a1ba2d1b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1596352

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Id88654e5344f3be87885d4214189d5c90f66ae6d
2021-02-26 11:13:39 +00:00
Remi NGUYEN VAN
62a1ba2d1b Merge "Add flag to force choosing upstreams automatically" am: e43c960d50 am: a474b9edfa
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1596352

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iaef23446e43ef557521785a23e5dcf81655d7f05
2021-02-26 10:01:35 +00:00
Remi NGUYEN VAN
e43c960d50 Merge "Add flag to force choosing upstreams automatically" 2021-02-26 06:42:00 +00:00
Lorenzo Colitti
33b3e53faa Use the R checkAndNoteWriteSettingsOperation method.
In S, there is a new overload that takes an attribution tag as
well. Don't use this method yet, and add a TODO to call it via
a shim.

Bug: 167645754
Test: m com.android.tethering
Ignore-AOSP-First: needed to sync mainline-prod with AOSP
Change-Id: Ib49a73aa28d3abfc1b8f1cdad84abb022c49efe8
Merged-In: Ib0ac49609e444a53a6fee4575f5078e15f364eef
2021-02-25 16:53:26 +09:00
Lorenzo Colitti
09074df188 Merge remote-tracking branch 'goog/rvc-qpr-dev-plus-aosp' into merge-sc-dev-plus-aosp-then-rvc-qpr-dev-plus-aosp
This CL merges rvc-qpr-dev-plus-aosp on top of sc-dev-plus-aosp
on top of mainline-prod. It picks up changes that were merged
into aosp/master before sc-dev-plus-aosp was on the path between
AOSP and master. One such very simple CL is aosp/1554765.

There were no merge conflicts.

Current diffstat with aosp/master is:
 97 files changed, 2219 insertions(+), 84 deletions(-)

This includes 1800 lines of translations added in 72 files like
Tethering/res/values-*/strings.xml

Bug: 167645754
Test: no merge conflicts
Test: didn't even try to build
Ignore-AOSP-First: this is a merge from AOSP
Change-Id: I63af0b95e2d0e6bddc217c29014c03ea0dbda6ec
Merged-In: Ib0ac49609e444a53a6fee4575f5078e15f364eef
2021-02-25 16:23:06 +09:00
Lorenzo Colitti
bd23387276 Add a BpfMap#clear method. am: ffb0ccd04b am: 10be22076e am: ad38d27ebb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1604974

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I77144b7db5300bcddbfd97b72c5c958d126ca628
2021-02-24 13:18:44 +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
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
Tomasz Wasilczyk
99ed3f2a6f Merge "Don't crash Tethering service when WiFi feature is missing" am: 736f8ec55a am: 5278b64768 am: 6b10dc120d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1577289

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I48d8cca44619bc78ebe26b8eec2fe4b5174bcd0c
2021-02-18 20:53:51 +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
Lorenzo Colitti
c785e87cb5 Merge "Load JNI in all classes that have native methods." am: af97e51c01 am: ceafffa6c0 am: 531fa9e0cc
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1581528

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I140bce0fdff60614b246c67ffdcb724389532612
2021-02-12 06:14:22 +00:00
Lorenzo Colitti
6800811597 Load JNI in all classes that have native methods.
The tethering module uses JNI in various classes, but only calls
System.loadLibrary in TetheringService#makeTethering. This means
that:

1. Any test that uses a class that uses JNI must load the
   library itself.
2. Any code that runs before TetheringService#makeTethering could
   potentially crash if it uses JNI. We may never have such code
   though.

Instead, make every class that has a native method load the JNI
library itself at static initialization time. This guarantees
that the class will have the JNI code available in any context
(production, test, etc.)

System.loadLibrary is documented not to do anything if called
more than once with the same library name:
https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#loadLibrary(java.lang.String)

and the implementation has a lock so it is safe to call from
multiple threads concurrently.

Test: builds, boots, tethering starts
Test: atest TetheringCoverageTests
Change-Id: I9c0147ae9a28877f416aaff387b426d304ae552d
2021-02-10 15:43:38 +09:00
Lorenzo Colitti
d8f76bb096 Dump counters in "dumpsys tethering bpf". am: 4e92da06fa am: e033a1e543 am: 7081e9f184
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1575051

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7d74c663b554f5f6f1562d4e6dc2a13f67adb9c0
2021-02-10 06:19:33 +00: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
Lorenzo Colitti
6281d65f61 Don't leak map fds in BpfCoordinator#dump. am: 555472a186 am: a6c9626b5d am: a47891732f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1581523

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7f92f0c2768775ab51018ec76feef9cab6e273c4
2021-02-09 23:43:52 +00:00
Lorenzo Colitti
555472a186 Don't leak map fds in BpfCoordinator#dump.
Currently, the dump methods open BpfMap objects and never close
them. This leaks filedescriptors, and if dump is called often
enough, will crash the networkstack process.

Fix this by using try-with-resources statements that
automatically close the map when exiting the try block.

Change the signature of BpfMap#close from "throws Exception" to
"throws ErrnoException" since it does not throw any other type
of checked exceptions.

Test: "lsof | grep network_st" while running "dumpsys tethering bpf" in a loop
Change-Id: I66c407454c2715bf41bf3a2e81bd582f9ea5a905
2021-02-09 23:30:25 +09:00
Martin Stjernholm
423a270abb Revert "Don't crash Tethering service when WiFi feature is missing" am: 199641d451 am: b329062b20 am: b9e5c3b247
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1575305

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I786ef0fee68b2e4310b45b63cd54286f8a168a3f
2021-02-05 15:50:01 +00:00
Martin Stjernholm
199641d451 Revert "Don't crash Tethering service when WiFi feature is missing"
This reverts commit f6a1052f4e.

Reason for revert: Suspected reason for TetheringTests breakage
Bug: 179467044

Change-Id: I3a5ee621b32145b74a31d6c3e411bd789e395935
2021-02-05 11:47:48 +00:00
Tomasz Wasilczyk
dfb58b501b Don't crash Tethering service when WiFi feature is missing am: f6a1052f4e am: 75c7cb992a am: 86be613c85
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1559422

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib9aa310a0b58b466514c5c73485093dafaa6e883
2021-02-04 15:21:00 +00:00
Tomasz Wasilczyk
f6a1052f4e Don't crash Tethering service when WiFi feature is missing
Bug: 175430552
Test: disable WiFi feature on device with wlan0

Change-Id: I83012013ff6a276d9a5c70748b726289b007cb0a
2021-02-02 16:11:18 +00:00
Treehugger Robot
2b03d6d469 Merge "Dump BPF offload rules for upstream IPv4 and IPv6." am: 0f7f9b6e40 am: 959cc0be9f am: 24ee1bb6a0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1560404

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I013f36607aad1c3eab54aee8ed4526e26018129f
2021-01-27 08:50:39 +00:00
Lorenzo Colitti
61976f278f Dump BPF offload rules for upstream IPv4 and IPv6.
Add code to BpfCoordinator to dump upstream IPv4 and IPv6 rules.
For IPv4, currently only the upstream map is printed, because the
downstream map is expected to be symmetrical.

Example output:

=============
    21(21) -> 12(rmnet_data2) 86dd 00:00:00:00:00:00 00:00:00:00:00:00
    [wlan1]: iif(iface) oif(iface) v6addr srcmac dstmac
      12(rmnet_data2) 21(wlan1) /2001:240:2425:b5dc:21a9:995d:bc57:bc37 b2:b5:e0:24:21:c2 ca:06:8d:54:99:ad
    [IPv4]: iif(iface) oif(iface) src nat dst
      21(21) 12(rmnet_data2) 192.168.16.247:41544 -> 100.101.80.108:41544 -> 216.239.36.135:443
      21(21) 12(rmnet_data2) 192.168.16.247:42028 -> 100.101.80.108:42028 -> 8.8.4.4:853
      21(21) 12(rmnet_data2) 192.168.16.247:42032 -> 100.101.80.108:42032 -> 8.8.4.4:853
      21(21) 12(rmnet_data2) 192.168.16.247:42042 -> 100.101.80.108:42042 -> 8.8.4.4:853
      21(21) 12(rmnet_data2) 192.168.16.247:41816 -> 100.101.80.108:41816 -> 8.8.8.8:853
      21(21) 12(rmnet_data2) 192.168.16.247:42040 -> 100.101.80.108:42040 -> 8.8.4.4:853

=============

Also make it possible to do "dumpsys tethering bpf" and get only
the BPF dump.

Test: manual
Change-Id: I2aaa2fdda7d724994090c26feff585f24cd3283b
2021-01-27 14:30:51 +09:00
Lorenzo Colitti
1ae9762100 Merge changes Iaac422d7,Ia7638b31 am: 0913a7a415 am: 51875f6043 am: 798f4b0e56
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1560403

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8709e14b191c55f9a650edf6dc87a84a8f5449d6
2021-01-27 04:28:11 +00:00
Maciej Żenczykowski
52c0a7f446 fix comments am: cff64c8561 am: ec92651a11 am: 08a003ab33
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1561295

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6ed98e10a8873c6b5e86072964783313ba9de7e2
2021-01-27 04:26:17 +00:00
Lorenzo Colitti
eec343935b Add an isEmpty convenience method to BpfMap. am: 77262cea76 am: 63585e9630 am: bb226600c1
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1560402

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4a5d933ebce3974a10a8c859b964e3f649bdd7c1
2021-01-27 04:14:29 +00:00
Lorenzo Colitti
b9602938ef Program the upstream IPv6 map in BpfCoordinator. am: 5b1ed508cf am: e9eb340e3e am: 8c49368ee2
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1557099

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibb815ed4eb9a1d84b4b306aa6ab96d382c816a68
2021-01-27 04:14:23 +00:00
Lorenzo Colitti
1ba4be9119 Rename TetherDownstream6Value to Tether6Value. am: d69a886235 am: 6482088003 am: 80ede0e4d9
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1560395

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ieb7a49618a6f16053d51429d7183595f2fb2209c
2021-01-27 04:14:21 +00:00
Lorenzo Colitti
0913a7a415 Merge changes Iaac422d7,Ia7638b31
* changes:
  Remove IpServer.Dependencies#getIfIndex.
  Address comments on aosp/1559686.
2021-01-27 03:04:23 +00:00
Maciej Żenczykowski
cff64c8561 fix comments
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic217e08484c39077bcc408195daa3311ed93ad28
2021-01-26 16:45:21 -08: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
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
ee3d4edd51 Merge changes from topic "bpf_tether4_rename" am: 3c35666892 am: 7d0693f6dc am: 177975f25b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1559687

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I383d31ffb54f0e3f23d1df8b794b544a38a29cac
2021-01-26 15:01:17 +00: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
8564a5ca06 Mark the EntitlementManager PendingIntents as immutable. am: a36d65da0a am: ec93812466 am: 8688028150
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1557108

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie300969f4d942fedefb5f23d7cba6eab37de521f
2021-01-26 12:32:37 +00:00
Lorenzo Colitti
a36d65da0a Mark the EntitlementManager PendingIntents as immutable.
These are read-only intents and should not be mutated by any
app receiving them.

Bug: 178324405
Bug: 178249531
Test: atest TetheringTests TetheringCoverageTests GtsTetheringTestCases
Change-Id: I5395e7c19e6453640ad790f2b9a9ba22bbcefa88
2021-01-26 15:14:26 +09:00
Maciej Żenczykowski
911a7267f5 merge Tether{Down,Up}stream4{Key,Value} - part 3 - fixups
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia7840698e80ded33d8e0b59efe1ca7267254b892
2021-01-25 20:32:10 -08: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
Lorenzo Colitti
0d497319fe Merge changes I8cd6e49b,Ibb52c7b7 am: dc4189f0e4 am: 3b0f7f1d6e am: 4158939871
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1557658

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ifad6ded6097c458cc1b5dba9d167c5920ff2c180
2021-01-26 02:14:37 +00: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
Nucca Chen
a950792808 Merge changes I73f30477,I84db13ac am: 2f1c2b25cd am: 2b82a04b56 am: d98f2b685f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1534829

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I468c45d5bb13a55bc525dd8f839de1af87214b6b
2021-01-23 14:55:05 +00:00
Nucca Chen
36027bdbcd Merge "[NFCT.TETHER.1] Add conntrack monitor to BpfCoordinator" am: 168a96643d am: 3efbe8414f am: 4ad3fc7c39
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1488522

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I9ca46e6510116e0859c0284d9547a6dcb8370662
2021-01-22 12:45:20 +00:00
Hungming Chen
347dd90620 [NFCT.TETHER.9] Build IPv4 offload BPF rules for raw ip
Build the upstream and upstream rules when the conntrack event is
received.

Test: atest TetheringCoverageTests
Change-Id: Ibb52c7b75812bd586091d809e260bc9206c06262
2021-01-22 19:37:37 +08:00
Hungming Chen
8784a60eab [NFCT.TETHER.8] Prepare the upstream information for IPv4 offload rule
Add upstream interface index and its IPv4 address mapping

Required for building IPv4 forwarding rule when a conntrack event is
received.

Test: atest TetheringCoverageTests
Change-Id: I73f304777704f09481b80d18751e0bab5bab2edc
2021-01-22 19:37:31 +08:00
Hungming Chen
d71c06ec71 [NFCT.TETHER.7] Prepare the downstream information for IPv4 offload rule
Add and remove downstream client information to BpfCoordinator

Required for building IPv4 forwarding rule when a conntrack event is
received. The IpServer provides the following elements of a rule which
is not included in conntrack event:
- Downstream interface index
- Downstream Mac address
- Client IP address to Client Mac address

Test: atest TetheringCoverageTests
Change-Id: I84db13acc047ace5730d17f0d3dd99544f516084
2021-01-22 19:37:24 +08:00
Nucca Chen
168a96643d Merge "[NFCT.TETHER.1] Add conntrack monitor to BpfCoordinator" 2021-01-22 11:29:09 +00:00