Commit graph android_packages_modules_Co.../Tethering/src
Message SHA1
Merge "Tethering: Throw exception when register null callback to avoid a crash" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2024-04-02 05:45:07 +00:00
c634eb5726
Merge "Allow enable DBG/VDBG without having to rebuild the module." into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-02 05:44:35 +00:00
5250ebe96e
Allow enable DBG/VDBG without having to rebuild the module.
Check out #isLoggable from frameworks/base/core/java/android/util/Log.java to
learn how to enable the log.

Bug: 329552689
Change-Id: I86ce0dae947cf56da069dfe3145ef074de11217e
Test: TH

Mark Chien   commited 2024-04-02 03:59:35 +00:00
9f69605fa0
Merge "Remove mWifiTetherRequested" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-04-02 03:20:31 +00:00
4775bb519a
Obtain BluetoothAdapter through BluetoothManager
BluetoothAdapter.getDefaultAdapter is deprecated and should be replaced
with BluetoothManager.

The AttributionSource is not necessarily set properly with
BluetoothAdapter.getDefaultAdapter, and may depend on which package is
returned first by PackageManager.getPackagesForUid. This has been
causing some flaky failures in presubmit.

Fixes: 332225348
Test: atest
Change-Id: I2f066f1a90a3c6fed7885f4bbee870abf96f664d

Remi NGUYEN VAN   commited 2024-04-01 16:35:24 +09:00
9b7fea5eee
Remove mWifiTetherRequested
Removing "mWifiTetherRequested" because it might cause Wi-Fi tethering
to not have an upstream if P2P is turned on. The issue could be
recovered when the upstream's capabilities or link properties change,
tethering calls "chooseUpstreamType" to select an upstream. If none of
the above situations happen, Wi-Fi tethering won't have an upstream.

1. When Wifi P2P is enabled and tethering enters TetherModeAliveState.
2. Turning on wifi tethering, TetherModeAliveState would first receive
   EVENT_IFACE_SERVING_STATE_INACTIVE when wifi tethering's IpServer
   is created and enters IpServer's InitialState. Then it will call
   updateUpstreamWanted and change mUpstreamWanted from false to true
   before wifi tethering's IpServer actually enters TetheredState.
3. When TetherModeAliveState receives EVENT_IFACE_SERVING_STATE_ACTIVE,
   which is triggered by wifi tethering's IpServer entering
   TetheredState, it won't call chooseUpstreamType() because
   mUpstreamWanted is already true.
   case EVENT_IFACE_SERVING_STATE_ACTIVE: {
       IpServer who = (IpServer) message.obj;
       if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
       handleInterfaceServingStateActive(message.arg1, who);
       who.sendMessage(IpServer.CMD_TETHER_CONNECTION_CHANGED,
               mCurrentUpstreamIfaceSet);
       // If there has been a change and an upstream is now
       // desired, kick off the selection process.
       final boolean previousUpstreamWanted = updateUpstreamWanted();
       if (!previousUpstreamWanted && mUpstreamWanted) {
           chooseUpstreamType(true);
       }

mWifiTetherRequested is only used to check upstreamWanted() and only be
used in TetherModeAliveState so that it is
safe to remove mWifiTetherRequested and always use mForwardedDownstreams
to check whether upstream is needed for TetherModeAliveState because all
the Tethered IpServer is added to mForwardedDownstreams when it enter
Tethered State and be removed from mForwardedDownstreams when it exit
Tethered State.

This change also move the upstreamWanted() function inside TetherMainSM
to prevent it from being used incorrectly outside of TetherMainSM.

Bug: 329552689
Test: atest TetheringTests

Change-Id: I6842170f455b280dd79aae039a1117d5e6d677f3

Mark Chien   commited 2024-03-26 08:08:01 +00:00
27d9121ef3
Tethering: Throw exception when register null callback to avoid a crash
Register null callback will cause a crash so throw an exception

Test: m, CtsTetheringTest
Change-Id: Id4337328f6793f1436c9d3561960fa69d17d030e

Ding Zhang   commited 2024-03-01 11:42:22 -08:00
52776a3c8c
Merge "Pass buffer size to NetlinkUtils.netlinkSocketForProto" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-01-31 01:42:49 +00:00
2cb28ea360
Pass buffer size to NetlinkUtils.netlinkSocketForProto
Pass buffer size to netlinkSocketForProto to allow callers to specify
buffer size. The buffer size is not set if 0 is passed in.

Following callers of netlinkSocketForProto passes SOCKET_RECV_BUFFERSIZE
to keep same behavior as before:
 * OffloadHardwareInterface.createConntrackSocket()
 * NetlinkUtils.sendOneShotKernelMessage()
 * IpSecXfrmController.Dependencies.newNetlinkSocket()
 * InetDiagMessage.getConnectionOwnerUid()
Following callers pass 0 to not update the buffer size:
 * TunInterfaceController - it uses the socket only for writing
 * NetlinkUtils.createNetLinkInetDiagSocket() same behavior as before
Added a SOCKET_DUMP_RECV_BUFFERSIZE of 128k to be used by socket
requesting dump information from kernel:
 * NetlinkUtils.getAndProcessNetlinkDumpMessages() - sends dump request
   and expecting multiple reply messages.

Bug: 320420453

Test: atest NetworkStaticLibTests
atest FrameworksNetTests

Change-Id: I3dcb76963cf2646eb311602b50ab4e44b8ad3e8f

Yang Sun   commited 2024-01-30 21:54:48 +08:00
7934241c8f
Merge "Add experiment flag for enabling sync sm" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-01-30 02:18:24 +00:00
c1647a0efc
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
BpfMap - add R/W constructor alias
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7cef2b19f55e6e056b46bb1b28f85c7f7376f6f4

Maciej Żenczykowski   commited 2024-01-23 16:16:44 -08:00
06155c8040
Add experiment flag for enabling sync sm
The logic is currently disabled by default, adding a flag so
that we can compare result with A/B rollout. Tethering only read
this flag once when it is created.

Bug: 319212113
Test: atest TetheringTests

Change-Id: I656b0389e56d29dd691738ee3abfa6418746846f

Mark   commited 2024-01-23 09:55:33 +00:00
c512ab7e23
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
Migrate Tethering#dump to use runWithScissorsForDump
This change includes:
  1. Refactor the logic in Tethering#dump into utils class.
  2. Move the utils class to a common place which could be referenced
     from other sub-modules.
  3. Add @MonitorThreadLeak annotation to enforce
     there is no thread leak problem.

Test: atest FrameworksNetTests NetworkStaticLibTests
Test: atest ConnectivityCoverageTests:com.android.networkstack.tethering.TetheringTest#testDumpTetheringLog
Test: adb shell dumpsys tethering (with hardcoded exception)
Fix: 312669345

Change-Id: Ia6fdfeeec2110afa0ec9e056e9db3843748845c3

Junyu Lai   commited 2024-01-10 13:56:55 +08:00
2ff42d264b
Merge changes I4888f8f2,Iba829ec0 into main
* changes:
  Revert "Refactor RouterAdvertisementDaemon with FdEventsReader"
  Revert "Refactor RouterAdvertisementDaemon to build new RA in HandlerThread"

Yuyang Huang   authored and   Gerrit Code Review   commited 2023-12-20 08:14:12 +00:00
71c24f190d
Revert "Refactor RouterAdvertisementDaemon with FdEventsReader"
This reverts commit bdcd7db9d8.

Reason for revert: Design changes, don't use extra Handler in RouterAdvertisementDaemon.

Change-Id: I4888f8f22aea2cadbb6064e63f872c605025930f

KH Shi   commited 2023-12-20 06:46:42 +00:00
ec801b887f
Revert "Refactor RouterAdvertisementDaemon to build new RA in HandlerThread"
This reverts commit 23a2158c38.

Reason for revert: Design changes, don't use extra Handler in RouterAdvertisementDaemon.

Change-Id: Iba829ec028e887b6625f4f972e936ca5757a7614

KH Shi   authored and   Gerrit Code Review   commited 2023-12-20 06:25:54 +00:00
f8ab26379e
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
Merge "Rename getXXX to makeXXX in TetheringDependencies" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-12-05 06:42:25 +00:00
ef41398c1f
Merge "Random select started prefix range" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-12-05 05:25:18 +00:00
78c0d088d7
Rename getXXX to makeXXX in TetheringDependencies
This fix the code review comment from aosp/2319853 that getXXX functions
should be renamed to makeXXX because it's actually creating the object.

Test: TH
Change-Id: Ife8e1cc3a90b835764a2dd9731388b05d8a5c964

Mark   authored and   Mark Chien   commited 2023-12-04 09:02:55 +00:00
b720d6d726
Random select started prefix range
Currently, PrivateAddressCoordinator always selects the /24 prefix
from the 192.168.x.x/16 range first. If the upstream is also a /24
prefix in the 192.168.x.x/16 range, there's a 1/256 chance of a
conflict (192.168.0.x/24 ~ 192.168.255.x/24). Since 192.168.x.x/16
is a popular range for home and small business networks, we should
randomize the starting prefix range to reduce the chance of a
conflict. The /8, /12, and /16 range selection rates are 0.39%,
5.86%, and 93.7%, respectively (see the inline comments for how
the rates are calculated).

The chance of selecting a /24 prefix is:
- 10.0.0.0/8: 1/(256*256) * 93.7% = 0.001429%
- 172.16.0.0/12: 1/(16*256) * 5.86% = 0.00143%
- 192.168.0.0/16: 1/256 * 0.39% = 0.001523%

Note: This change is currently turned off by the
tether_force_random_prefix_base_selection flag. We'll run experiments
to make sure tethering stays reliable with this change enabled.

Bug: 312647670
Test: atest TetheringTests
Change-Id: Iea03fdcf0fccad95410e79ae87fcb046d75da457

Mark   commited 2023-11-28 06:56:06 +00:00
c0b0f616d0
Avoid random twice to generate an address
The code currently calls RandomInt twice to generate an address.
For example, if you want to generate the address 192.168.A.B,
RandomInt will be called twice to generate the values for A and B.
To save resources, we can avoid calling RandomInt twice by reusing
the same random value with different masks for A and B.
Before:
  -  RandomInt() & 0xff00 -> A
  -  RandomInt() & 0x00ff -> B
After:
  -  RandomInt() & 0xffff -> A.B

Bug: 312647670
Test: atest TetheringTests
Change-Id: Iee49af3d82781309f78fe66ab07937b8137fa259

Mark   authored and   Mark Chien   commited 2023-11-24 03:10:11 +00:00
f25af65b28
Refactor RouterAdvertisementDaemon to build new RA in HandlerThread
HandlerThread was introduced in aosp/2493357. This patch moves the
code originally located in buildNewRa() into the HandlerThread.

Bug: 246928127
Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Change-Id: I5f6df0a3a79d7f4a865cfec7f88bc28816b1db95

KH Shi   commited 2023-11-22 07:25:16 +00:00
23a2158c38
Refactor RouterAdvertisementDaemon with FdEventsReader
This patch changes the implementation of UnicastResponder in the
RouterAdvertisementDaemon with FdEventsReader. The change includes
replacing Thread with HandlerThread, create socket in non-blocking
mode (required by FdEventsReader) and use FdEventsReader to listen
to the solicited RS packets. Two commands (CMD_START & CMD_STOP)
were added to control the lifecycle of the FdEventsReader.

Bug: 246928127
Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Test: Enable WiFi hotspot and connected with another Pixel client:
      1. Tcpdump on the Pixel client, checking the RA packets
      2. Verify IPv6 addresses were configured
      3. ping6 2001:4860:4860::64
Change-Id: I6e89903df90864e3bb34d498e353d6f87193e9d6

KH Shi   commited 2023-11-22 06:37:17 +00:00
bdcd7db9d8
Merge "SyncSM11.1 make some functions inline" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-11-22 03:03:22 +00:00
f1c04ca91f
Merge "SyncSM09: Add Callback to UpstreamNetworkMonitor" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-11-21 17:29:10 +00:00
309365558c
SyncSM11.1 make some functions inline
This is no-op change.

Test: atest TetheringTests
Change-Id: Ia5c68c403bdaa981f35ecad8ffc3e034746dfdea

Mark   commited 2023-11-21 06:11:32 +00:00
2ca4b1d156
SyncSM09: Add Callback to UpstreamNetworkMonitor
Instead of passing state machine to UpstreamNetworkMonitor, wrapped it
by an interface would have two benefits:
1. Easier for testing.
2. Isolate state machine operation in callback.

Test: atest TetheringTests
Change-Id: I2a97fd5cbc8c49df8c3c98428c6570916ab31ea5

Mark   commited 2023-11-21 05:53:29 +00:00
4465e4e2bd
Fix endian error when pass upstream prefixes to bpf
TetherUpstream6Key#src64 should be stored in network order. Use
a big-endian ByteBuffer to retrieve a value stored in network order
is actually converts it into native order, which is little-endian in
Android.

In this CL, we changed it to use byte[] instead of long to store the
top 64-bits of the source prefix.

Test: atest TetheringTests
      manual test with IPv6-only tethering upstream, check BPF stats.
Bug: 312072637
Change-Id: I79f9282d5eda28328aa6a764ea92b086d6285133

KH Shi   commited 2023-11-20 08:10:53 +00:00
84e3fb3afd
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
Avoid using FileDescriptor#getInt$() on R
FileDescriptor#getInt$() is a hidden API with the unsupportedApiUsage
annotation on R. Accessing it will cause a NewApi linter check error.
It should be removed from OffloadHalHidlImpl as it is only used for
log messages.

Bug: b/205762647
Test: m
Change-Id: Ie41d12988aee65a066dfb1529e828f4523cc0907

KH Shi   commited 2023-11-15 07:15:09 +00:00
92b990b85f
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
Merge "Avoid autoboxing overhead in hash calculation" into main
KH Shi   authored and   Gerrit Code Review   commited 2023-11-09 05:18:52 +00:00
d6909dbec2
Avoid autoboxing overhead in hash calculation
Avoid passing primitive data types into Objects.hash() which will
convert them to their corresponding object wrapper types
automatically.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I2efe7f3e50923ad2e33cfd58ae7e1e1cf7fd34bd

KH Shi   commited 2023-11-08 12:44:42 +00:00
99b7e62b3c
Rename TiramisuConnectivityInternalApiUtil
This can be used from S. There is no point in having a
release name in the name of this class.

Test: builds
Change-Id: I301bf032f856dd4c30554e06013f31ee57208c4e

Chalard Jean   commited 2023-11-07 17:29:39 +09:00
674f34702c
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 changes Ibe22b300,I0b0f0bf1 into main
* changes:
  SyncSM08: handle IpServer requestEnableTethering callback in mainSM
  SyncSM07.1: Add a test that shows tethering restarts when disabling

Mark Chien   authored and   Gerrit Code Review   commited 2023-10-27 08:50:04 +00:00
2c7e2b8448
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