Commit graph android_packages_modules_Co.../Tethering/src/android/net/ip/IpServer.java
Message SHA1
Merge "Revert "Add experiment flag for tethering refactor"" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-01-24 07:41:19 +00:00
e48d106863
Revert "Add experiment flag for tethering refactor"
This reverts commit cf11be9eb2.

Reason for revert: avoid some IpServer(s) running the new sync state machine while others use the async state machine.

Bug: 319212113
Change-Id: Ib086a7ccd102f38e579c79f94aceae9971f1853a

Mark Chien   authored and   Mark   commited 2024-01-22 11:34:14 +00:00
6e368d1bdd
Merge "Replace HashSet with ArraySet in RaParams" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2024-01-20 19:06:38 +00:00
86b8bf03d2
Add experiment flag for tethering refactor
The logic is currently disabled by default, adding a flag so
that we can compare result with A/B rollout.

Test: atest TetheringTests
Change-Id: If640b9a172b97aa67c49b2976cdef118218f1e0f

Mark   commited 2023-12-12 02:31:54 +00:00
cf11be9eb2
Make NewApi to error in Tethering
Bug: 293971841
Test: TH
Change-Id: Iae92b171abe8a4620325bd7ce0f7f76912d6d1d8

Motomu Utsumi   commited 2023-11-15 08:57:30 +00:00
ac7c5723c3
Replace HashSet with ArraySet in RaParams
ArraySet is designed to be more memory afficient than HashSet. It is
suitable to store small numbers of items.

Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Bug: 261923493
Change-Id: I2bd2eded801cc05ce53ef9f9486b13faf1772d22

KH Shi   commited 2023-11-13 03:12:53 +00:00
ff1400be4b
Add forwarding methods to RoutingCoordinator
Test: RoutingCoordinatorServiceTest
      TetheringTest
Change-Id: I2fa6250875d517c3452c85a3678d3feb0c0354d8

Chalard Jean   commited 2023-11-02 23:25:32 +09:00
820ce9df2d
Merge "SyncSM8.2: make IpServer support syncSM" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-10-30 07:51:54 +00:00
0b8bdb1074
Merge "SyncSM8.1 always call transitionTo under processMessage" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-10-30 07:51:06 +00:00
bdf6178a1a
Merge "Revert "Add forwarding methods to RoutingCoordinator"" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-10-28 06:34:26 +00:00
e26f93318c
Revert "Add forwarding methods to RoutingCoordinator"
This reverts commit 55ccfe19e2.

Reason for revert: this must be introducing some sort of race
it appears to cause
  atest EthernetTetheringTest 'NetdBinderTest#TetherForwardAddRemove'
to no longer reliably pass.

Change-Id: I5281ab3f42c5ce268d97a12db24a6768db3f4354

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-10-28 02:10:52 +00:00
543d0d32e4
Merge "Pass upstream prefixes to bpf tethering offload" into main
KH Shi   authored and   Gerrit Code Review   commited 2023-10-27 07:23:52 +00:00
f92d211c71
Merge "Add forwarding methods to RoutingCoordinator" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-27 05:12:07 +00:00
23376e6fe7
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

KH Shi   commited 2023-10-26 13:13:38 +00:00
3f738fcd3d
Add forwarding methods to RoutingCoordinator
Test: RoutingCoordinatorServiceTest
      TetheringTest
Change-Id: Ic3b36ddc236e8615e7d931b6e526556bbd2dac17

Chalard Jean   commited 2023-10-26 20:18:48 +09:00
55ccfe19e2
SyncSM8.2: make IpServer support syncSM
After this change, IpServer could switch to use syncSM.

Test: atest TetheringTests
Change-Id: I2d7fa47cd020f3e76e7a8beaefb98852e93545f8

Mark   commited 2023-10-26 09:34:23 +00:00
be99f86ad9
SyncSM8.1 always call transitionTo under processMessage
As state transitions always occur after a message has been processed,
calling transitionTo only under processMessage makes the flow easier
to understand and less error-prone.

The risk of this change is very minimal since it is only about
handling the error, but tethering will stop regardless.

Test: atest TetheringTests

Change-Id: I56c6cf6cc989464ee84a8333ac131afc808a3d95

Mark   commited 2023-10-26 09:31:18 +00:00
50eef8316c
SyncSM07: Replace IpServer's state machine with StateMachineShim
A simple replacement without changing any behavior.

Test: atest TetheringTests
Change-Id: I34903b57df68081e974163edec82a851ee4ccc98

Mark   commited 2023-10-26 09:26:15 +00:00
2150296476
Add a routing coordinator class
Test: In followup changes : RoutingCoordinatorManagerTest
Change-Id: Ia6811d614e02123a072c7638291828745abae051

Chalard Jean   commited 2023-10-24 22:12:26 +09:00
2fb66f1b28
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

KH Shi   commited 2023-09-19 08:02:24 +00:00
701c3ca2f5
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

KH Shi   commited 2023-09-01 07:37:18 +00:00
e4d549ab11
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

KH Shi   commited 2023-08-30 09:33:30 +00:00
6877034343
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

KH Shi   commited 2023-08-24 12:02:23 +00:00
59ad35ee19
Import RFC7421_PREFIX_LENGTH from NetworkStackConstants.
Remove the dependency on services-connectivity-shared-srcs
filegroup gradually.

Bug: 290885904
Test: TH
Change-Id: I6474563a3a0b521945e6467a2832862764ad4770

Xiao Ma   commited 2023-08-09 20:02:15 +09:00
1f993309c6
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

Mark   commited 2023-05-25 08:31:33 +00:00
49649c9aea
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

Mark   authored and   Mark Chien   commited 2023-05-24 17:00:41 +00:00
3ec851ef03
SyncSM08: statically import tethering error code constant
This can make the code using error code not so easy to over 100
words line limit.

Test: m
Change-Id: I952c51f2e3508ed320744985193802454d07ccfe

Mark   commited 2022-12-14 09:12:15 +00:00
74461fc13d
Wrap some IpServer commands
This is no-op change. Preparing for refactor.

Test: atest TetheringTests
Change-Id: I8fb67cbc95074e990074f08b5fe6afe7dfd28382

Mark   authored and   Mark Chien   commited 2022-12-02 04:48:00 +00:00
a542458c16
Remove dead code: updateUpstreamIPv6LinkProperties in InitialState
mRaemon only be created at BaseServingState#enter() and set to null at
BaseServingState#exit(). Thus, updateUpstreamIPv6LinkProperties just be
no-op in InitialState.

Test: atest TetheringTests MtsTetheringTestLatestSdk CtsTetheringTest
Change-Id: I0b8403a2acffb1aa0f40d2ad8721d4eff7c63ff0

Mark   commited 2022-11-23 08:22:32 +00:00
0e38307b4b
Make Tethering module depend on net-utils-device-common-ip.
NetworkStack module utils are duplicated to net-utils-device-common-ip,
delete the module utils source code and use net-utils-device-common-ip
instead.

Bug: 235901424
Test: atest TetheringTests
Change-Id: I19fe72a92d6de1084963c2b3a38d094f8da2a91e

Xiao Ma   commited 2022-07-13 04:32:28 +00:00
c81c066958
Use frameworks/libs/net version of SharedLog
Test: m
Bug: 235901424
Change-Id: Ibfa7821c68c41036a47e765f15078cd5d195afb8

Patrick Rohr   commited 2022-07-07 12:52:58 -07:00
b873e25ab4
Add tethering stats into statsd
Bug: 153942334
Test: atest TetheringTest IpServerTest
Test: Manual test with statsd_testdrive
Change-Id: I7205bb24dd30ba78b79bc352034da299d452750f

Wayne Ma   commited 2022-05-12 17:21:11 +08:00
6cd440fedd
Add config_p2p_leases_subnet_prefix_length configuration
Add new rro configuration which can be used to make the p2p dhcp
prefix length larger to reserve the address range outside of leases
subnet prefix length for EAPOL-Key feature. This configuration only
valid if its value larger than dhcp server address prefix length and
config_tether_enable_legacy_wifi_p2p_dedicated_ip is true.
E.g.:leaseSubnetPrefixLength = 25, p2p static address = 192.168.49.1/24
dhcp range: 192.168.49.0 ~ 192.168.49.127 (192.168.49.1/25), reserved
192.168.49.128 ~ 192.168.49.255 for EAPOL-Key feature.

Bug: 170056953
Test: atest TetheringTests

Change-Id: I1319efd871796da7234383a29ab64a1623101ae7

markchien   commited 2022-03-31 16:32:55 +08:00
fb65dfeb8d
Merge changes from topic "dedup-interfaceparams"
* changes:
  Remove unused InterfaceParams jarjar rule
  Deduplicate InterfaceParams

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-03-05 08:23:55 +00:00
a63535bfd1
Deduplicate InterfaceParams
CS should use InterfaceParams from frameworks/libs/net.

Test: builds
Bug: 222448728
Change-Id: I1f45d3171b265461a8724b4be7b212c030b63fe9

Patrick Rohr   commited 2022-03-04 16:53:51 +01:00
9f371f024b
Pass whole TetheringConfiguration to IpServer
This is a no-op CL that passing whole TetheringConfiguration to IpServer
to reduce the number of IpServer constructor parameters.

Bug: 170056953
Test: atest TetheringTests
Change-Id: I4ec17f7ecaefd7f275139ad9c7f7551635b192c9

markchien   authored and   Mark Chien   commited 2022-03-03 11:54:24 +00:00
b961d3d70f
Use new bluetooth API to enable/disable bt tethering after T
This change only apply to the device after T.
Use new bluetooth API to change bluetooth tethering settings and the
new API provide the callback to to notify Tethering when bluetooth
interface is ready. Tethering doesn't use bluetooth interface status
change event from netlink to add/remove IpServer anymore.

Tag: #feature
Bug: 190438212
Test: TetheringTest
Change-Id: Iae92d98d500f83b116da7282cf1130fb8fecf53d

markchien   commited 2022-01-17 16:47:43 +08:00
69681d65a5
Rename tethering util folder and its package name
Move tethering util files from android.net.util into
com.android.networkstack.tethering.util. The goal is move all of
tethering internal files into its own namespace
com.android.networkstack.tethering.util.

Bug: 205088391
Test: atest TetheringTests
      atest CtsTetheringTest
      atest TetheringPrivilegedTests

Change-Id: I6559fb4f873b3cad5b210b10e49df1b6c6914a70

markchien   commited 2021-11-09 17:02:47 +08:00
d02f9af918
Move to f/l/n instead of RouteUtils
Test: TetheringTests
Change-Id: I35b36538463a7fc2f02e142719c898d1694b2d6b

Chalard Jean   commited 2021-10-29 16:05:46 +09:00
adcec9ebbe
Use SdkLevel util instead of explicitly checking the version
There are IpServerTest test case fail because the code check the wrong
code name for T pre-release builds.

Bug: 194812819
Test: atest TetheringTests

Change-Id: I73bf58c60b6e790fe0060b60c023c10f5d8cbfa8

markchien   authored and   Mark Chien   commited 2021-08-12 07:08:34 +00:00
932df54493
Skip bpf offload if upstream interface is VCN
Bpf offload do not support VCN network yet, don't start bpf offload
if the interface is ipsec*.

Bug: 191178945
Test: atest TetheringTests
Change-Id: I1ad8cededddec42f45b08aaa31d583c548d105f0

markchien   authored and   Mark Chien   commited 2021-07-13 15:35:31 +00:00
7dc1b4da7b
Clear IPv4 offload rules when tethering stopped
The condition for deleting IPv4 forwarding rules.
1. When the tethering client has gone, deletes the client and its
   rules.
2. When the upstream has gone, deletes all rules.
3. When the upstream has changed, deletes all rules.

Test: atest TetheringCoverageTests and check IPv4 offload rules
via dumpsys tethering in the following test cases.

Bug: 190783768

Test cases:
a. Loss upstream interface while tethering
  1. Enable WIFI tethering
  2. Disable upstream interface
  3. Check the rules are removed.
b. Loss downstream interfaces while tethering
  1. Enable WIFI tethering
  2. Enable BT tethering
  3. Disable BT tethering
  4. Check the BT tether rules are removed.
  5. Disable WIFI tethering
  6. Check the WIFI tether rules are removed.
c. Switch upstream interface while tethering
  1. Enable WIFI tethering
  2. Enable BT tethering
  3. Switch upstream interface from cellular to wifi.
  4. Check all rules are removed.
d. Enable NAT failure (manual)

Log:
The rule deletion in each case.
- IpServer#stopIPv4: case b and case d.
- BpfCoordinator#updateUpstreamNetworkState: case a and case c.

Test case a
06-23 09:58:59.245  [...] Tethering: [BpfCoordinator]
    updateUpstreamNetworkState tetherOffloadRule4Clear wlan2

Test case b
06-07 22:17:51.886  [..] Tethering: [bt-pan] cleanupUpstream bt-pan
06-07 22:17:51.888  [..] Tethering: [bt-pan] stopIPv4 bt-pan
06-07 22:18:23.769  [..] Tethering: [wlan2] cleanupUpstream wlan2
06-07 22:18:23.772  [..] Tethering: [wlan2] stopIPv4 wlan2

Test case c
06-08 11:11:48.277  [..] Tethering: [BpfCoordinator]
    updateUpstreamNetworkState tetherOffloadRule4Clear bt-pan
06-08 11:11:48.396  [..] Tethering: [BpfCoordinator]
    updateUpstreamNetworkState tetherOffloadRule4Clear wlan2
06-08 11:11:48.579  [..] Tethering: [wlan2] cleanupUpstreamInterface
    wlan2
06-08 11:11:48.808  [..] Tethering: [bt-pan] cleanupUpstreamInterface
    bt-pan

Enabling NAT failure
06-08 13:04:18.117  [..] Tethering: [wlan2] Exception enabling NAT [..]
06-08 13:04:18.234  [..] Tethering: [wlan2] cleanupUpstream wlan2
06-08 13:04:18.246  [..] Tethering: [wlan2] stopIPv4 wlan2

Change-Id: Id505a3deb277bbe0f44403234d8ca8bbf01eec80

Hungming Chen   commited 2021-06-23 15:41:27 +08:00
a6e7869646
Suppress IpServer message logs
To avoid log flooding, suppress CMD_IPV6_TETHER_UPDATE and
CMD_NEIGHBOR_EVENT message log because they appear frequentlg and
don't have any content which means they are ueseless for debugging.
Also remove logMessage from BaseServingState to fix duplicated
message because all the message already log in TetheredState
and LocalHotspotState which inherit BaseServingState.

Bug: 162920185
Bug: 185649441
Test: atest TetheringCoverageTests
      atest MtsTetheringTestLatestSdk
      atest CtsTetheringTest
Change-Id: Ib8fe719f3c1c4a65e6b5152df5e5adf33aba2079

markchien   commited 2021-06-08 15:57:04 +08:00
21021efbe1
Allow callers of startTethering to choose local-only mode.
This is useful for OEMs that want to use RNDIS or NCM as a
local-only link that is directly connected to some other host.
This can be used to implement USB tethering using NCM, which
currently only supports local-only mode.

Bug: 175090447
Test: TetheringIntegrationTests:EthernetTetheringTest#testLocalOnlyTethering
Change-Id: I0ffaa46e4640e5b235340a15d25909106ceb0c07

Lorenzo Colitti   commited 2021-04-19 20:25:58 +09:00
8a36c297bc
Set the limit whenever any IPv4 or IPv6 rule exists.
Currently, BpfCoordinator only sets the data limit on a given
upstream whenever the first IPv6 rule is created on that
upstream, and clears it whenever the last rule is deleted on that
upstream. It never does this when adding or removing IPv4 rules.

This makes it impossible to offload traffic on IPv4-only
networks.

Fix this by setting the limit when IPv4 rules are created or
deleted as well.

Test: atest TetheringCoverageTests
Manual tests as the follows
Test {add, clear} limit with IPv6-only network [OK]
Test {add} limit with IPv4-only upstream [OK]

TODO:
Test {clear} limit with IPv4-only network. blocked by aosp/1579873
because the IPv4 rules have never deleted.

Change-Id: I5a29bdd18e564318759f617023163e23fb5a3ed0

Lorenzo Colitti   authored and   Hungming Chen   commited 2021-04-01 18:30:43 +08:00
dc6715c6f8
[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

Hungming Chen   commited 2021-03-11 17:49:42 +08:00
3dbd4a1cc4
Remove IpServer.Dependencies#getIfIndex.
This code is unused.

Test: atest TetheringTests
Change-Id: Iaac422d72e8538b67798cb3ae3737deb7b426401

Lorenzo Colitti   commited 2021-01-27 00:53:59 +09:00
f3b201f819
[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

Hungming Chen   commited 2021-01-22 19:37:24 +08:00
d71c06ec71
[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

Hungming Chen   commited 2021-01-21 21:25:18 +08:00
46c30b1fd4
Make the IP subnet persistent till reboot
Make the IP subnet persistent if it do not conflict with upstream.
It allow client to reuse its IP that usually reduce DHCP procedure.

Bug: 168169687
Test: atest TetheringTests
Change-Id: Iddc5304730dce7b11c5d124b7eddce057d752bbd

markchien   commited 2020-10-06 20:25:19 +08:00
a2ffad84c7