Commit Graph

739 Commits

Author SHA1 Message Date
Hungming Chen
378bdbc2ef [CTT-1] Rename conntrack related function, variable and constant
Bug: 190783768
Bug: 192804833
Test: atest TetheringCoverageTests

Change-Id: Ib7ba480138b8aa8c6f8dffaa97787bac74a3972e
2021-07-11 15:04:37 +08:00
Remi NGUYEN VAN
ca5530ed1d Remove catch clause on compat shim
registerSystemDefaultNetworkCallback no longer throws
UnsupportedApiLevelException as it has compatibility behavior down to Q,
so remove the catch clause for the checked exception.

The exception would previously not be thrown since the Tethering module
is only running on R+.

Bug: 182961265
Test: atest TetheringTests
Change-Id: I3c58235f3a59294995e5f32502fec6ccd17a3cf0
2021-07-09 10:24:44 +09:00
Lorenzo Colitti
844ca1290e Merge "Load ncm regexs config to tetherableUsbRegexs if isUsingNcm=true" 2021-07-06 03:39:31 +00:00
Lorenzo Colitti
d479e694f0 Merge "Enable and disable usb IpServer according to ACTION_USB_STATE" 2021-07-06 03:39:15 +00:00
markchien
b28740ec89 Load ncm regexs config to tetherableUsbRegexs if isUsingNcm=true
If config_tether_ncm_regexs is configured, load it to
tetherableUsbRegexs if ncm is used for TETHERING_USB. Load it to
tetherableNcmRegexs if ncm is used for TETHERING_NCM.

Bug: 185649441
Test: atest TetheringTests
Change-Id: I0c542560bd04e8c0a6a78d632da5a00a34d9a3fa
2021-07-05 23:11:50 +08:00
markchien
b41a00e778 Enable and disable usb IpServer according to ACTION_USB_STATE
Before this change, usb IpServer would be created if corresponding
interface is available even there is no enable tethering attempt. And
usb IpServer only be disabled when interface is removed. Usb tethering
could not be stopped if interface is always avaialbe.
After this change, usb IpServer would be enabled and disabled according
to ACTION_USB_STATE.

Bug: 185649441
Test: atest TetheringCoverageTests
      atest MtsTetheringTestLatestSdk
      atest CtsTetheringTest
Change-Id: I8375e3f998d677dc658370b2553facaec0d5ff7c
2021-07-05 22:53:07 +08:00
Hungming Chen
3004f0d8d9 Dump the protocol of IPv4 offload rule
Print the protocol {tcp, udp} of v4 rules in dumpsys.

Format:
proto [inDstMac] iif(iface) src -> nat -> dst [outDstMac] age
  udp [00:00:00:00:00:00] 14(rmnet0) 74.125.10.156:443
  -> 30(30) 10.254.92.123:60262 -> 192.168.128.240:60262
  [0a:bd:b5:e0:41:53] 96067ms

Bug: 190783768
Test: dumpsys tethering
Change-Id: Idae1042cfb454cc97b9b103587f11bc0700e0787
2021-07-01 11:52:12 +08:00
Hungming Chen
e7dff2f955 Dump the unused IPv4 BPF rule age correctly
Print a dash for the unused "lastUsed" of the rule.

The age should not equal the bootime if the rule has never been
updated the "lastUsed" field.

Format:
[inDstMac] iif(iface) src -> nat -> dst [outDstMac] age
[00:00:00:00:00:00] 14(rmnet0) 140.112.8.116:443
-> 30(30) 10.170.56.233:43720
-> 192.168.45.236:43720 [be:34:40:28:33:5f] -

Test: dumpsys tethering
Change-Id: Ie771becd2f72518cf02a86e5ae228315785752a5
2021-06-29 16:21:49 +08:00
Treehugger Robot
1e50b3ea24 Merge "Make "dumpsys tethering" print the number of registered callbacks." 2021-06-28 09:50:04 +00:00
Treehugger Robot
0b44491744 Merge "Remove wigig support from S tethering" 2021-06-28 07:51:07 +00:00
Mark Chien
840e2efd7f Merge "Fix and test usb function configuration change" 2021-06-28 04:16:14 +00:00
Lorenzo Colitti
ced68f5993 Make "dumpsys tethering" print the number of registered callbacks.
Test: manual
Bug: 177265744
Change-Id: I07f56459125d5629dcafe5683eecb42d0ef9e2bd
2021-06-28 12:46:37 +09:00
markchien
34f7857b07 Fix and test usb function configuration change
Allow stop TETHERING_NCM no matter ncm is used for TETHERING_USB or
TETHERING_NCM.

Add a test:
1. NCM is started for TETHERING_NCM
2. The config changes to use NCM for TETHERING_USB.
3. Then the config changes to use RNDIS for TETHERING_USB.

Also let some logs not only print in dumpsys, but also in logcat to
easiler debug unit test.

Bug: 185649441
Test: atest TetheringTests
Change-Id: Ia8d76a29646f36941cbb16cd68ae6887100ec8ec
2021-06-28 02:59:33 +00:00
Nucca Chen
a569410667 Merge "Refresh conntrack entry timeout" 2021-06-25 18:34:22 +00:00
Nucca Chen
7238b31c15 Merge "Clear IPv4 offload rules when tethering stopped" 2021-06-25 17:56:21 +00:00
markchien
8f9705126a Remove wigig support from S tethering
Bug: 176520801
Test: atest TetheringTests
Change-Id: Id0bf02c01419e0c69a1d0b6a41789826538444d3
2021-06-25 00:31:43 +08:00
junyulai
991433d8c8 [SP35] Pass data warning to tethering offload
This is supported by:
  1. Utilize the new API from both NetworkStatsProvider
     and IOffloadControl to send data warning quota to hardware.
     And pass the warning reached notification back to NPMS.
  2. Disable software solution introduced in R release for
     V1.1+ hardware, since now we can fully offload data warning
     and limit notification to hardware.

Test: atest TetheringTests
Fix: 149467454
Merged-In: Ie49461694d77ab7f25a549433b01b5b0167bd489
Change-Id: Ie49461694d77ab7f25a549433b01b5b0167bd489
  (cherry-picked from ag/13981692)
2021-06-24 08:33:28 +00:00
junyulai
da52dab266 [SP34] Adapt onSetWarningAndLimit
This is a no-op change that just adapt new API from
NetworkStatsProvider to get warning and limit bytes at the same
time. This change also stores them locally for subsequent
patches to set warning bytes to hardware.

Test: Will be included in the subsequent patch.
Bug: 149467454
Merged-In: Iec01cb01fd1ce481ce0bd736762baddde1e38084
Change-Id: Iec01cb01fd1ce481ce0bd736762baddde1e38084
  (cherry-picked from ag/13981691)
2021-06-24 08:33:28 +00:00
junyulai
37a7e620b4 [SP33] Adapt ITetheringOffloadCallback V1.1
This is a no-op change that redirect both V1.0 and V1.1 callback
events to the same handling function. Since the V1.1 callback
is extended from V1.0 callback, we can safely use V1.1
callback for both V1.0 and V1.1 control.

The change also provides interface for subsequent
OffloadController changes to set warning and limit at the
same time.

Test: atest TetheringTests
Bug: 149467454
Merged-In: I6505a04de8c57357dd1fa9ce898c13395e497816
Change-Id: I6505a04de8c57357dd1fa9ce898c13395e497816
  (cherry-picked from ag/13973147)
2021-06-24 08:33:28 +00:00
Hungming Chen
c27ec7c4a2 Refresh conntrack entry timeout
Needed because the BPF maps offloads IPv4 traffic. The kernel can't
trace the offloaded traffic to keep the conntrack entry.

Bug: 190783768
Test: atest TetheringCoverageTests
Change-Id: Idbcf686c9b2124b192944156ac5111be741744fb
2021-06-23 15:41:30 +08:00
Hungming Chen
a6e7869646 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
2021-06-23 15:41:27 +08:00
Junyu Lai
69bc4fede1 Merge "[SP32] Try to get 1.1 OffloadControl hardware if available" 2021-06-22 20:31:18 +00:00
Mark Chien
cec294d1b4 Merge changes I270ff43c,Ifc7eee24
* changes:
  Add enable and disable ip serving common functions
  Allow to use ncm function for usb tethering
2021-06-21 10:56:45 +00:00
markchien
76e2e1c702 Add enable and disable ip serving common functions
This is a op CL which prepare for refactor.

Bug: 185649441
Bug: 189410000
Bug: 178116595

Test: atest TetheringTests
Change-Id: I270ff43c01736b9d18bd40a8e88e1379e9e4e863
2021-06-18 21:35:40 +08:00
markchien
cab01b7ebc Allow to use ncm function for usb tethering
Adding the configuration to decide using rndis or ncm for usb tethering.
If ncm is configured for TETHEIRNG_USB, then TETHERING_NCM is not
available.

Bug: 162920185
Test: atest TetheringTests
      manul testing usb tethering
Change-Id: Ifc7eee2457a950a0e2d1c3cc89a3373a7ad23c9c
2021-06-18 11:20:26 +08:00
Lorenzo Colitti
8569168eda Correctly dump IPv4 downstream flows.
The current code does not print these correctly: it prints the
public address twice and then the NAT address. Fix this to print
the src, nat, and dst addresses.

Also dump the output MAC address.

Example output:

    IPv4 Upstream: [inDstMac] iif(iface) src -> nat -> dst [outDstMac] age
      [66:f1:6f:d8:66:0a] 31(31) 192.168.146.173:48594 -> 11(rmnet_data1) 100.100.109.185:48594 -> 8.8.8.8:853 [00:00:00:00:00:00] 32305ms
      [66:f1:6f:d8:66:0a] 31(31) 192.168.146.173:45806 -> 11(rmnet_data1) 100.100.109.185:45806 -> 8.8.4.4:853 [00:00:00:00:00:00] 32305ms
    IPv4 Downstream: [inDstMac] iif(iface) src -> nat -> dst [outDstMac] age
      [00:00:00:00:00:00] 11(rmnet_data1) 8.8.8.8:853 -> 31(31) 100.100.109.185:48594 -> 192.168.146.173:48594 [0e:a8:7f:ba:76:48] 32305ms
      [00:00:00:00:00:00] 11(rmnet_data1) 8.8.4.4:853 -> 31(31) 100.100.109.185:45806 -> 192.168.146.173:45806 [0e:a8:7f:ba:76:48] 32305ms

Test: manual
Bug: 190783768
Change-Id: I93a82064c95027c7c63cb30baf8482ecddcbd09d
2021-06-15 23:11:27 +09:00
Lorenzo Colitti
70f43ee58e Improve dumping IPv4 map entries.
1. Dump both upstream and downstream rules.
2. Also dump rule last used time.

Test: manual
Bug: 190783768
Change-Id: I3fffbf4a5dea68e61349de8b41bea49b8a319f86
2021-06-15 12:54:08 +09:00
Lorenzo Colitti
704b8013f1 Dump underlying BPF traffic stats as well as higher-level stats.
This provides a better way to tell whether traffic is flowing.

Test: manual
Bug: 190783768
Change-Id: If557b0a18fc0aea1bf6a65d91547fc1930098ed0
2021-06-15 12:49:07 +09:00
Lorenzo Colitti
a3f12dd52c Merge "Don't send onLinkPropertiesChanged after onLost for 464xlat." 2021-06-09 07:59:25 +00:00
markchien
21021efbe1 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
2021-06-08 15:57:04 +08:00
markchien
dc5903ae56 Remove *Locked wording
Since tethering run in single thread without any synchronized lock,
remove "Locked" wording from the methods which the use lock before.

Bug: 162920185
Test: atest TetheringCoverageTest
Change-Id: Ia8c057800cab30cdcbacae4db2d706b6427e9861
2021-06-08 15:56:14 +08:00
Lorenzo Colitti
b4bf015b57 Don't send onLinkPropertiesChanged after onLost for 464xlat.
Currently, when a network that uses 464xlat is torn down,
NetworkCallbacks will receive onLinkPropertiesChanged after
onLost. This is confusing and incorrect.

The incorrect callback is sent because handleLinkProperties
checks that the netId of the agent still exists, not that the
NetworkAgent is still registered. This is normally correct,
because the NetworkAgent is removed from mNetworkAgentInfos and
the netId are removed from mNetworkForNetId by the same method,
disconnectAndDestroyNetwork.

In this specific case it's not correct, because the call to
handleUpdateLinkProperties is from disconnectAndDestroyNetwork
itself via nai.clatd.update and calls Nat464Xlat#stop.

No other callers of handleUpdateLinkProperties are affected
because:

- EVENT_NETWORK_PROPERTIES_CHANGED is called only by
  maybeHandleNetworkAgentMessage, which first checks that the
  NetworkAgent is registered.
- handlePrivateDnsSettingsChanged only looks at registered
  NetworkAgents (it loops over mNetworkAgentInfos).
- handlePrivateDnsValidationUpdate, handleNat64PrefixEvent and
  handleCapportApiDataUpdate call getNetworkAgentInfoForNetId,
  which will correctly determine that the agent is no longer
  registered, since they run on the handler thread and thus
  cannot run at the same time as disconnectAndDestroyNetwork.

The existing code contains a check for the netId being current.
This is intended to ensure that an update from a NetworkAgent
cannot affect another agent with the same Network. This extra
check is not necessary, because code running on the handler
thread can never observe a NetworkAgent in mNetworkAgentInfos
unless mNetworkForNetId maps that NetworkAgent's Network to that
NetworkAgent. This is because mNetworkForNetId is updated by the
same methods as mNetworkAgentInfos, and those updates occur on
the handler thread. So all code on the handler thread will see
those two as consistent.

Bug: 176496580
Test: atest FrameworksNetTests CtsNetTestCases HostsideVpnTests
Change-Id: I944f4c6ad36206bdccd85a6ea7ef71324a29c685
2021-06-08 15:48:57 +09:00
markchien
35ad54b25e Add the tethering type to TetheringEventCallback methods
Before this change, tethering always report a list of tethered
interfaces and the caller need to use each tethering type's interface
regex to matching tethered list to manual implement the mapping of
tethering type and interface. This change allow caller to get rid of
tethering interface regex.

Bug: 162920185
Bug: 152203943
Test: atest CtsTetheringTest on S

Merged-In: I91bcccd676d109c1b974497ac29bd366a41b8899
Change-Id: I91bcccd676d109c1b974497ac29bd366a41b8899
2021-06-01 14:35:39 +08:00
markchien
89f2670b65 Disable tryCell when UpstreamMonitor stop
tryCell configuration would not be force disabled UpstreamMonitor stop.
If tethering stop with using mobile upstream and swap with SIM fron no
dun to dun supported, dun request would be filed even tethering is not
active.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I5505655f52da9fdca2fd43a58e043a9ab727741d
2021-05-21 20:35:11 +08:00
Mark Chien
84a8a13a92 Merge "Check whether feature is enabled by compare with apex version" 2021-05-18 03:09:20 +00:00
markchien
a3ef48117f Check whether feature is enabled by compare with apex version
Replace the isFeatureEnabled function which is check with apex version.

Bug: 187946226
Test: Set device config flag and check the result
Change-Id: Iba44a01e2fdd0698dcb338ea4a8fe8147cbaa7dd
2021-05-14 16:56:33 +08:00
Nucca Chen
aa10ddfa6f Merge "bpf: Add interface index to BPF devmap" 2021-05-14 02:45:38 +00:00
Junyu Lai
7fecf6a017 Merge "No-op Refactoring of startTrackDefaultNetwork" 2021-05-13 14:32:00 +00:00
junyulai
b95083ea6a No-op Refactoring of startTrackDefaultNetwork
While the actual part that track default request is inside
UpstreamNetworkMonitor, instead of passing it from Tethering,
move it into counter-part CL and use it from
UpstreamNetworkMonitor.

Since the current code is replaced by registerSystemDefaultCallback
in Android S, implement it inside the api30 shim implementation
to provide an unified interface to tethering.

Test: atest TetheringCoverageTests
Bug: 185952829
Change-Id: Iaf21b6b662aa6aba79c2b75379128b8523f81f02
2021-05-13 14:07:40 +08:00
Hungming Chen
3feb782282 bpf: Add interface index to BPF devmap
Add upstream and downstream interface index to BPF map and rename the
BPF map name from xdp_devmap to dev.

$ adb shell dumpsys tethering
    Device map:
      ifindex (iface) -> ifindex (iface)
        21 (21) -> 21 (21)
        25 (25) -> 25 (25)
        12 (rmnet_data2) -> 12 (rmnet_data2)

$ adb shell ip addr
12: rmnet_data2 ..
21: wlan1 ..
25: rndis0 ..

$ adb shell ls /sys/fs/bpf/tethering
map_offload_tether_dev_map

Test: atest TetheringCoverageTests

Change-Id: Ic49965f3374d9e196ee672ec2f0e9e08f3847deb
2021-05-12 19:57:18 +08:00
Lorenzo Colitti
2422319cb7 Remove dead code.
Remove a few legacy methods that have no callers.

Test: m
Change-Id: I499e940dc98453194fc528d65a89696471ad8bdd
2021-05-12 17:35:49 +09:00
Lorenzo Colitti
94311aa902 Remove mPublicSync.
This is no longer necessary as all the methods that take it are
running on on the handler thread, either in Tethering itself or
on the state machine thread in IpServer, which runs on the same
thread as Tethering.

Specifically:
- interfaceStatusChanged, interfaceAdded, interfaceRemoved,
  interfaceLinkStateChanged: run from mNetdCallback, which always
  posts them to mHandler.
- setWifiTethering: only called by enableTetheringInternal, which
  is called by the following:
  - startTethering, stopTethering: via lambda posted to mHandler
  - IpServerCallback#requestEnableTethering: called by IpServer
    while processing a command.
- setEthernetTethering: only called by enableTetheringInternal.
- EthernetCallback: runs on mExecutor, which posts to mHandler.
- getLastTetherError: only used by the test. Renamed to
  getLastErrorForTest to ensure no other callers.
- sendTetherStateChangedBroadcast: called only by
  notifyInterfaceStateChange, which is called only by
  - IpServerCallback#updateInterfaceState, which is called only
    by sendInterfaceState, which is called by various IpServer
    state enter methods.
- notifyLinkPropertiesChanged: called only by
  IpServerCallback#updateLinkProperties, which is only called by
  IpServer#sendLinkProperties, which is only called by:
  - Code that processes CMD_IPV6_TETHER_UPDATE
  - IpServer#handleNewPrefixRequest: only called when processing
    CMD_NEW_PREFIX_REQUEST.
  - IpServer#sendInterfaceState (see above)
- handleWifiApAction, handleWifiP2pAction: only called by
  mStateReceiver, which runs on the handler thread
- tether(String, int): called by:
  - tether(String, IIntResultListener): posted to mHandler
  - changeInterfaceState: called by:
    - EthernetCallback (see above)
    - enableWifiIpServingLocked: called by handleWifiApAction and
      handleWifiP2pAction (see above)
    - tetherMatchingInterfaces: only called by handleUsbAction,
      which is run from mStateReceiver on the handler thread.
- untether(String): called by:
  - untether(String, IIntResultListener): posted to mHandler
  - changeInterfaceState (see above)
- setUsbTethering: called by:
  - setUsbTethering(boolean, IIntResultListener): posted to mHandler
  - enableTetheringInternal (see above)
- setNcmTethering: called by enableTetheringInternal (see above)
- getTetheredIfaces: called only by TetheringTest. Renamed to
  getTetheredIfacesForTest to ensure no other callers.
- getErroredIfaces: unused, deleted in this CL
- getTetheredIfaces: called by:
  - isTetheringActive: called by onUserRestrictionsChanged, which
    is only called by mStateReceiver
  - TetheringTest
- dump(): changed to run on handler thread
- upstreamWanted: called by
  - TetherModeAliveState#enter
  - TetherModeAliveState#updateUpstreamWanted, which is called
    only by TetherModeAliveState#processMessage.

Test: atest TetheringCoverageTests
Test: enabled/disabled hotspot, USB tethering
Change-Id: Id49d33f027b8df4c97fda480ff239c0ba90bb96a
2021-05-12 17:35:49 +09:00
Lorenzo Colitti
5f729e14a3 Make Tethering#dump asynchronous.
This is in preparation for removing mPublicSync.

Test: m
Test: adb shell dumpsys tethering
Test: atest TetheringTests TetheringIntegrationTests
Change-Id: Ib2c9d0bff23614f76c8e075d32cb03412d3d21f7
2021-05-12 17:35:49 +09:00
junyulai
177dc86ad1 [SP32] Try to get 1.1 OffloadControl hardware if available
This is a no-op change that try to use 1.1 HAL if available.
Otherwise, fallback to 1.0 HAL. The change also provides version
information for subsequent patches to determine what to do for
specific version.

Test: atest TetheringTests
Bug: 149467454
Merged-In: I6a3ce877cdff2496087b97b191a9bfd5b0792827
Change-Id: I6a3ce877cdff2496087b97b191a9bfd5b0792827
  (cherry-picked from ag/13973146)
2021-04-29 18:19:55 +08:00
Mark Chien
07f8a618d2 Merge "Release mobile request when default upstream is not mobile" 2021-04-23 11:48:36 +00:00
markchien
d5096f504d Release mobile request when default upstream is not mobile
Some OEM may have special mobile data icon show up when non-default
(e.g. DUN) mobile connection connected even wifi is also connected.
So always connected DUN may let user hard to distinguish tethering
upstream in those OEM's devices. Also release unused mobile connection
may safe power.

This CL removes unnecessary code from selectPreferredUpstreamType.
In particular:
    - When a DUN or HIPRI upstream is selected, calling
    registerMobileNetworkRequest is unnecessary. A mobile
    NetworkRequest is always registered unless a non-mobile upstream
    is selected.

    - When a non-mobile upstream is found, releasing the mobile
    NetworkRequest is unnecessary in selectPreferredUpstreamType
    because it will be done by chooseUpstreamType immediately after
    selectPreferredUpstreamType returns.

    - When no upstream is found and cellular upstream is not permitted,
    it is not necessary to release the mobile NetworkRequest. When
    cellular is not permitted, no such NetworkRequest will be filed
    because registerMobileNetworkRequest checks with EntitlementManager
    before actually requesting the network. If cellular becomes the
    upstream and then later becomes not permitted because of an
    entitlement failure, all tethering will be stopped by Settings.

Note: currently legacy upstream selection has two known bugs:
1. If mobile has higher priority than non-mobile network, mobile request
should never be released and always prefer use mobile. But in practice,
mobile request would be released when tethering select non-mobile network
as upstream.
2. If mobile has higher priority than wifi network and default network
is wifi but mobile is still connected, tethering would choose mobile as
upstream because it has higher priority. Mobile disconnecting may not
trigger tethering to switch its upstream to wifi because currnetly
tethering rely on CONNECTIVITY_ACTION broadcast to handle upstream
disconnect.

Bug: 173068192
Test: atest TetheringTests
Change-Id: Id5df58af830cc534ecd79041ddf8a04171047e9b
2021-04-23 16:45:29 +08:00
Lorenzo Colitti
8a36c297bc 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
2021-04-19 20:25:58 +09:00
Treehugger Robot
2576c457de Merge "Put tether/untether calls into handler queue" 2021-04-15 14:46:25 +00:00
Lorenzo Colitti
a329e8c984 Fix a tethering crash when a 464xlat upstream disconnects.
When a 464xlat upstream disconnects, onLinkPropertiesChanged is
called after onLost. This breaks an UpstreamNetworkMonitor
assumption that no callback will ever arrive after onLost.

Bug: 173068192
Fix: 185117377
Test: new unit test
Change-Id: I4ff1eca6d5ed1680ff716c71b683891c8a0e5a77
2021-04-12 15:00:24 +00:00
Nucca Chen
68f6f5fe79 Merge "[NFCT.TETHER.11] Test TetherOffloadRule{Add, Remove} and set limit for IPv4" 2021-04-08 12:02:15 +00:00