Commit Graph

739 Commits

Author SHA1 Message Date
Mark Chien
2c7e2b8448 Merge changes Ibe22b300,I0b0f0bf1 into main
* changes:
  SyncSM08: handle IpServer requestEnableTethering callback in mainSM
  SyncSM07.1: Add a test that shows tethering restarts when disabling
2023-10-27 08:50:04 +00:00
KH Shi
f92d211c71 Merge "Pass upstream prefixes to bpf tethering offload" into main 2023-10-27 07:23:52 +00:00
Jean Chalard
23376e6fe7 Merge "Add forwarding methods to RoutingCoordinator" into main 2023-10-27 05:12:07 +00:00
KH Shi
3f738fcd3d Pass upstream prefixes to bpf tethering offload
BPF needs upstream prefixes information to filter spoofing IPv6 source
addresses carried in downstream traffic.

We retrieve prefixes from upstream interface's LinkProperties and pass
it to the BpfCoordinator. Forwarding rules will also be updated when
upstream interface's IPv6 link addresses change.

Test: atest TetheringTests
Bug: 261923493
Change-Id: If8cfc3b191e520ca838654d1b5211ab9e9ec021d
2023-10-26 13:13:38 +00:00
Chalard Jean
55ccfe19e2 Add forwarding methods to RoutingCoordinator
Test: RoutingCoordinatorServiceTest
      TetheringTest
Change-Id: Ic3b36ddc236e8615e7d931b6e526556bbd2dac17
2023-10-26 20:18:48 +09:00
Mark
5cc386bdef SyncSM08: handle IpServer requestEnableTethering callback in mainSM
This can make it easier to adopt SM shim replacement in follow up change,
as both SyncSM and AsyncSM will process the same message without any
difference.

This change also fix a problem that bring up downstream before it's
IpServer completely disabled.

Previous:
CMD_NOTIFY_PREFIX_CONFLICT -> requestEnableTethering(false) ->
requestEnableTethering(true) -> IpServer stopped ->
reportTetherStateChanged(downstream inactive) -> IpServer started
-> reportTetherStateChanged(downstream active)
New:
CMD_NOTIFY_PREFIX_CONFLICT -> requestEnableTethering(false) ->
IpServer stopped -> reportTetherStateChanged(downstream inactive)
-> requestEnableTethering(true) -> IpServer started
-> reportTetherStateChanged(downstream active)

Test: atest MtsTetheringTestLatestSdk
Change-Id: Ibe22b300c56125359f4fa452bd01a0a2381fda23
2023-10-26 09:28:22 +00:00
Mark
2150296476 SyncSM07: Replace IpServer's state machine with StateMachineShim
A simple replacement without changing any behavior.

Test: atest TetheringTests
Change-Id: I34903b57df68081e974163edec82a851ee4ccc98
2023-10-26 09:26:15 +00:00
Mark
2ec1595d0b SyncSM06: Add StateMachineShim
Test: atest StateMachineShimTest

Change-Id: Ic818aa55e7e0fd7a62dfce50a6ad719e6e1c44ec
2023-10-26 09:24:55 +00:00
Chalard Jean
2fb66f1b28 Add a routing coordinator class
Test: In followup changes : RoutingCoordinatorManagerTest
Change-Id: Ia6811d614e02123a072c7638291828745abae051
2023-10-24 22:12:26 +09:00
KH Shi
2a6a7359b7 Merge "Decouple Ipv6UpstreamRule with Ipv6DownstreamRule" into main 2023-10-02 05:33:48 +00:00
Mark
21cdb40e59 SyncSM04: implement processMessage function
After this change, all synchronous state machine functions are
implemented.
There are some intentional limiations:
1. Allow setup states before machine thread started or inside machine
   thread but states can only be setup once before calling #start.
2. The behavior of transitionTo is defined so that the destination
   state can never change during state transitions. Once a destination
   has been specified, it cannot be changed until the previous state
   transition is complete. In other words, SyncStateMachine does not
   support calling transitionTo in State enter or exit.
3. Support sendSelfMessage in State#processMessage(), #enter() and
   #exit(). This allow automaton to decide the follow up action by
   itself. For example: if something wrong happens during state
   transition, the implementation can enqueue an error message then
   process the error message after finishing the current state
   transition.

Test: atest SynStateMachineTest
Change-Id: I0790df4eeab2dccdb9f407d9131a62c3c12d123b
2023-09-19 08:20:56 +00:00
KH Shi
701c3ca2f5 Decouple Ipv6UpstreamRule with Ipv6DownstreamRule
Currently, Ipv6UpstreamRule is added follows the adding of
Ipv6DownstreamRule when it is the first rule from a downstream
interface to the upstream interface.

This CL changed it to:
1. Upstream interface change updates both IPv6 upstream and downstream
   forwarding rules.
2. Neighbor events updates only IPv6 downstream forwarding rules.

Data limit setting on the upstream interface is now depend on the
upstream rules instead of the downstream rules. This CL also updates
corresponding test cases in IpServerTest and BpfCoordinatorTest.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I5b4df64a3d276afb7a24bbef3a0432f53377e8b2
2023-09-19 08:02:24 +00:00
Mark
9e572d10f3 SyncSM03: implement state transition logic
Implement performTransitions which does state transitions.
1. Determine the common ancestor state of current/destination states
2. Invoke state exit list from current state to common ancestor state.
3. Invoke state enter list from common ancestor state to destState by
going through mEnterStateStack.

The state transition is always defined so that the target can never be
changed mid-way of a state transition. In other words, calling
transitionTo in State enter and exit is not allowed.

Test: atest SyncStateMachineTest
Change-Id: I51e8c5440a8b9ac25715c3d030717421f68c15b3
2023-09-15 14:38:12 +00:00
Mark
1d460b568e SyncSM02: implement addState function
Duplicated state is not allowed.

Test: atest SynStateMachineTest
Change-Id: I0d5c73f666f90aebcfbf535cf0f824c5050941a2
2023-09-15 14:23:52 +00:00
Mark
b48caa22f3 SyncSM01: define SyncStateMachine user interface
This change adds SyncStateMachine class and provides the user
interface but doesn't have the details implementation.

Test: m
Change-Id: Ic2fa69b9e6424601fc2df2d07a052f48a6a46370
2023-09-15 08:07:22 +00:00
Motomu Utsumi
3e0be398a2 Remove unnecessary arguments from isTetheringFeatureEnabled
This CL also updates not to use isTetheringFeatureEnabled for
TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION which is wrongly configured in
Connectivity namespace.

Test: m
Bug: 279108992
Change-Id: If4f3a57c749bbaeb85454c31248c5bc5feaab936
2023-09-08 16:11:28 +09:00
KH Shi
e4d549ab11 Remove duplicated bpf offload support check in IpServer
In current code, IpServer will ensure bpf offload is supported before
calling BpfCoordinator's APIs. But those APIs already have the same
checks inside the function. This CL removed duplicated checks in
IpServer.

After this change, the BPF offload support status is only determined
inside BpfCoordinator and it won't change during the life cycle of
Tethering. Tethering initializes mBpfCoordinator just once in the
constructor. After that point, the value of isUsingBpf can never
change, because mIsBpfEnabled is final and
mBpfCoordinatorShim.isInitialized() is either always true (api30) or
can either never change (api31).

Also fixed a bug in IpServerTest upon this change.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I50f231a83bf678b90eae4fd9bfa6035e86978bb3
2023-09-01 07:37:18 +00:00
KH Shi
6877034343 Relief unnecessary dependencies of code order
The original code requires updating mLastIPv6LinkProperties before
calling updateIpv6ForwardingRules because mLastIPv6LinkProperties will
be used inside an internal function later. Remove this unnecessary
dependency by passing the interface name into the function.

Bug: 294025403
Test: atest TetheringTests
Change-Id: I5699fba3d7caf3314d102b643b02da2b2797dd66
2023-08-30 09:33:30 +00:00
KH Shi
59ad35ee19 Introduce Ipv6UpstreamRule to bpf tethering offload
Replaced startUpstreamIpv6Forwarding and stopUpstreamIpv6Forwarding
with add/remove Ipv6UpstreamRule. This is a preparation for following
CLs which will pass the upstream's prefixes to the bpf map. We might
have more than one upstream rules.

Also renamed Ipv6ForwardingRule to Ipv6DownstreamRule since we have
defined the Ipv6UpstreamRule.

No logic changes are being made in this CL.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I022f97c2daf468bbd4a4279a069ccf498013e7e7
2023-08-24 12:02:23 +00:00
Motomu Utsumi
624aeb4274 Rename to isTetheringFeatureEnabled
DeviceConfigUtils has isFeatureEnabled for NetworkStack and Tethering
which were confusing since the difference was only the arguments.
This CL renames isFeatureEnabled for Tethering module to
isTetheringFeatureEnabled to avoid confusion.

Bug: 279108992
Test: m
Change-Id: I05255bb38619afbe621d29524d7910d206a149f1
2023-08-17 17:47:19 +09:00
Treehugger Robot
b8ea09efd7 Merge "Import RFC7421_PREFIX_LENGTH from NetworkStackConstants." into main 2023-08-10 13:07:20 +00:00
KH Shi
c8fb1a2530 bpf tethering offload - add src subnet to upstream ipv6 direction
This patch is based on aosp/2535559 from maze@.

Add source prefix into the upstream key such that only packets which
source IPv6 address matches it will be forwarded to the upstream
interface.

In this patch, the source prefix is set to zero so there is no
behavior changes. Next CL in patch series will use the real source
prefixes retrieved from upstream interface.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I43d068a29b937c7dfeb6fab632a8effb47ee2263
2023-08-10 16:01:21 +08:00
Xiao Ma
1f993309c6 Import RFC7421_PREFIX_LENGTH from NetworkStackConstants.
Remove the dependency on services-connectivity-shared-srcs
filegroup gradually.

Bug: 290885904
Test: TH
Change-Id: I6474563a3a0b521945e6467a2832862764ad4770
2023-08-09 20:02:15 +09:00
Zemeng Li
32ef13d7f3 Fix bug for failing to init Offload AIDL HAL service
When fail to init offload AIDL service, OFFLOAD_HAL_VERSION_NONE is
returned. Not as expected, it go to close the FDs for AIDL service and
causes a NE.

Bug: 277834236
Test: atest com.android.networkstack.tethering
Change-Id: I26a7412cb7d88f0d56b713db18af5cd9583a7942
2023-07-24 21:19:31 +08:00
Hungming Chen
fc52868213 Tethering: ignore duplicate upstream changed event
Different network objects with the same network ID should be
treated as the same network.

chooseUpstreamType compares the current upstream and new upstream
by object (comparison operator) instead of network id
(Network#equals). This implies that different objects with the
same network id still trigger upstream changed report.

Since this commit, reportUpstreamChanged is only called when upsteam
has really changed (connected, switched or disconnected) in
chooseUpstreamType. In previous code, reportUpstreamChanged is also
called if EVENT_ON_CAPABILITIES is called when the upstream is the
same but its capabilities changed.

The NotificationUpdater#onUpstreamCapabilitiesChanged method only
needs to be called by chooseUpstreamType when it chooses a new
upstream. If the upstream remains the same but its capabilities
change, the EVENT_ON_CAPABILITIES will call
onUpstreamCapabilitiesChanged.

Bug: 243516306
Test: atest TetheringTest
Change-Id: I009383a61a5fabd249ba78fcffd524a5bbe4602e
2023-06-19 06:51:03 +00:00
Mark
49649c9aea Support SAP and LOHS enabled at the same time
Use type + scope as key to build cached address map so that
SAP (key: TETHERING_WIFI + INTERNET) and LOHS
(key: TETHERING_WIFI + LOCAL) can use different address.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I46a4b3ee919628092b7540202a43d79f407b09b6
2023-05-25 08:31:33 +00:00
Mark
ae3abdfa4b Allow SAP and LOHS wifi clients exist at the same time
This change store localOnly wifi clients in its own field so that
tethered and localOnly hotspot clients can exist at the same time.

Currently, there are no tethered and localOnly hotspot clients at
the same time because PrivateAddressCoordinator does not support
SAP + LOHS. A follow-up change will be made to allow this.

When both SAP and LOHS are enabled, the SAP and LOHS clients from
TetheringEventCallback#onClientsChanged are all TETHERING_WIFI.
Currently, there is no way for the listeners to distinguish between
SAP and LOHS clients.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I01b0a6abb084f7135f7825e0c5303e49c16a4c39
2023-05-25 08:31:06 +00:00
Mark
3ec851ef03 Add mDesiredServingState field in BaseServingState
As the suggestion from:
https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2489359/9/Tethering/src/android/net/ip/IpServer.java#b1176

Make BaseServingState an abstract class to prevent it from being used
directly. Additionally, move the handleNewPrefixRequest method into
BaseServingState because it is the only class that uses it.
To avoid TetheredState and LocalHotspotState from having to implement
their own enter function, add the mDesiredInterfaceState field to
BaseServingState.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I03269c37e666345efb0c61039a2bb213f223a5a2
2023-05-24 17:00:41 +00:00
Mark Chien
65a73dbf78 Merge "Fix entitlement recheck fail in U" 2023-05-17 05:54:39 +00:00
Mark
e86fb5ef56 Fix entitlement recheck fail in U
Starting with U, only explicit intents will be allowed to
launch non-exported internal components. Set package name
to entitlement recheck intent so that the intent could be
delivered to tethering itself successfully.

Bug: 278482046
Test: atest TetheringTests
      manual verify entitlement recheck work in U
Change-Id: Ife30eee13fe39509ccb5786d2a76fbb7baa022a8
2023-05-16 07:59:32 +00:00
Remi NGUYEN VAN
6d38c01852 Add a dependency object in TetheringConfiguration
Address a TODO in TetheringConfiguration to use a dependency object
instead of static mocking on DeviceConfig.

This avoids TetheringConfiguration dependencies on internal
implementation of DeviceConfigUtils, unblocking changes in
DeviceConfigUtils.

Bug: 279108992
Test: atest TetheringTests
Change-Id: I252eaadff85fa47b894e989b4f2527b00c5dca56
2023-04-28 19:18:43 +09:00
KH Shi
bcd62d18f4 Merge "Remove TODO comment that was already done" 2023-04-24 09:32:56 +00:00
Wayne Ma
b5ee365614 Add tx_bytes and rx_bytes to UpstreamEvent message
This commit adds two new fields, tx_bytes and rx_bytes, to the
UpstreamEvent message. These fields provide information about the
amount of data transferred during the event, which can be useful for
network performance analysis. The current tx/rx usages are always
zero, but it will be updated in a later change to reflect the actual
usage. No changes were made to the existing fields upstream_type and
duration_millis.

Test: atest TetheringMetricsTest
Change-Id: I9e1043b3fff5aa3f548b8696bac7e5bc4271c77c
2023-04-21 11:15:56 +08:00
KH Shi
11dee200f9 Add forwarded stats dump in tethering hardware offload
The information can be useful for issue debugging, it shows the
accumulated traffic offloaded to the hardware for all upstreams.

$ dumpsys tethering
....
    ForwardedStats:
      rmnet_data2: rx:155686981 tx:799922
....

Bug: b/205762647
Test: adb shell dumpsys tethering
Change-Id: I94143329bdc8ad0eff79c32f329fae95ad3acf8a
2023-04-19 09:14:57 +00:00
Maciej Żenczykowski
b68f73cc17 No Tethering Offload HAL is not really an error
Bug: 278660842
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I978de7fe33b77b432df183b4c7a1966849f17389
2023-04-18 10:05:13 +00:00
Wayne Ma
fab745c8ae Address comment from aosp/2335004
Bug: 263681262
Test: atest TetheringMetricsTest
Change-Id: I7372b7717a903d43a543f82e31a0439725d02e3a
2023-04-13 10:01:36 +08:00
KH Shi
5655bf52e7 Remove TODO comment that was already done
The TODO is used to track to dynamically pass down the TTL from the
upstream interface. Remove it as it was already done in IpServer.

Test: No code changes
Change-Id: Idb12f82023315661f1bf4c767b9b7744a151e821
2023-03-24 11:38:18 +08:00
Wayne Ma
9d6b724887 Merge "Implement logging of upstream event type and duration." 2023-03-20 16:50:37 +00:00
KH Shi
7b8568927e Merge "Add Tetheroffload AIDL interface support" 2023-03-20 03:58:42 +00:00
KH Shi
3d5e65cb48 Add Tetheroffload AIDL interface support
Add the AIDL HAL service interface support and abstract the HIDL/AIDL
interface implementations to allow OffloadController to talk to both
interfaces.

Bug: b/205762647
Test: atest com.android.networkstack.tethering
      atest ConnectivityCoverageTests
      atest ConntrackSocketTest
Change-Id: If7634a298d03668ed70b328f1ad6ca0ac0fe170b
2023-03-17 16:56:47 +08:00
Wayne Ma
c0e9e2901b Implement logging of upstream event type and duration.
Bug: 263681262
Test: atest TetheringMetricsTest
Test: statsd_testdrive 303
Change-Id: I80301ee035a9814920e3ce4b9eca6bcdc59350db
2023-03-17 16:40:06 +08:00
Hungming Chen
85d98ea79f BpfCoordinator: refactor updateUpstreamNetworkState to get MTU
This is a preparation for CLAT offload.

Move the getting the MTU into a function for refactoring
updateUpstreamNetworkState() which could be simpler.

Bug: 258637850
Test: atest BpfCoordinatorTest
Change-Id: I8f22b022d4d00597810b56ab6e3e55ed7ab9076d
2023-02-21 23:00:51 +08:00
Maciej Żenczykowski
f95fd405d7 Increase RA default lifetime.
Currently we have 300s..600s RA interval, so ~450 seconds,
and a 6 * 600s, ie. 3600s (1h) lifetime.
This means on average about 8 RAs during the lifetime.

APF's FRACTION_OF_LIFETIME_TO_FILTER is 6, so the first
3600s / 6 = 600s of RAs are filtered out by a hotspot client
Android device.  This means we really only get 3600s - 600s = 3000s
worth of RAs (after the initial one).
Hence, the client will get approximately 3000s / 450s = 6.666 RAs.

Thus, assuming a clientside DTIM multiplier of just 2, the client
phone only needs to fail a 50/50 coin toss 6 times in a row to
lose all 6 of those RAs.

That's a 1 in 2**6 = 64 chance, and it gets rerolled every ~450s.

Per https://www.codechef.com/wiki/tutorial-expectation
expected number of coin flips for getting N consecutive heads is:
2**(N+1) - 2

N=6 --> 2**7-2 = 126

126 * ~450s = 56700s = 15.75h

This means failure is expected roughly on the order of 16 hours.

By doubling the lifetime from 1h to 2h, we effectively double
the number of RAs, and lower the failure chance from 1 in 2**6,
to 1 in 2**13, which is 1 in 8K and thus much less failure prone.

N=13 -> 2**14-2 = 16382  --> failure expected after ~85 days

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I70db3096db5666bca0c248f2d49f801f333514b3
2023-02-16 22:56:25 +00:00
Treehugger Robot
7acd206160 Merge changes Ie2ba9805,I8f5b23f9
* changes:
  Move onUpstreamCapabilitiesChanged out of reportUpstreamChange
  TetheringTest: improve onUpstreamCapabilitiesChanged test
2023-02-01 06:35:13 +00:00
Treehugger Robot
42d28f1d66 Merge "UpstreamNetworkMonitor: remove unused mTetheringUpstreamNetwork" 2023-02-01 05:59:59 +00:00
Hungming Chen
650cc9c0d3 BpfCoordinatorTest: add testUpdateUpstreamNetworkState
Bug: 258637850
Bug: 241106456
Test: atest ConnectivityServiceTest
Change-Id: I156398ef7ffaceb454dc187682238821da77c72b
2023-01-31 16:35:09 +08:00
Mark
a1f6362931 Move onUpstreamCapabilitiesChanged out of reportUpstreamChange
onUpstreamCapabilitiesChanged not only be called inside
reportUpstreamChange. Separate onUpstreamCapabilitiesChanged out
of reportUpstreamChange so that reportUpstreamChange can focus
on upstream network change callback.

Bug: 243516306
Test: atest TetheringTests
Change-Id: Ie2ba9805fc43f921100c0286a9300df02f63e35d
2023-01-18 15:13:49 +08:00
Hungming Chen
50b25b1136 UpstreamNetworkMonitor: remove unused mTetheringUpstreamNetwork
The variable mTetheringUpstreamNetwork is unused.
Remove the dead variable and its related setter setCurrentUpstream().

History:
aosp/507635: add mTetheringUpstreamNetwork
aosp/1183410: some functions stop using mTetheringUpstreamNetwork
aosp/1203243: stop using mTetheringUpstreamNetwork completely

Bug: 243516306
Test: atest TetheringTest
Change-Id: I07784c47e49dd9ef034f91bef9089ca48c187f30
2023-01-18 15:13:49 +08:00
Treehugger Robot
401f1ff2db Merge changes from topic "deprecate_connectivity_action_in_tethering"
* changes:
  Tethering: deprecate CONNECTIVITY_ACTION on U+ device
  Test: add tests to testChooseDunUpstreamByAutomaticMode_*
  TetheringTest: separate setup func from chooseDunUpstreamTestCommon
2023-01-13 08:41:20 +00:00
Steven Moreland
f4e0f096b5 Merge "unregistered null callback will cause a crash later" 2023-01-07 02:11:16 +00:00