Commit Graph

10154 Commits

Author SHA1 Message Date
Lorenzo Colitti
2bc9317761 Add CTS tests for registerDefaultNetworkCallbackAsUid. am: ed26ffe92d am: 6cbdc19b2c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1669267

Change-Id: Icca5c5a62818ac83910e968dbbadd0610305aa0b
2021-04-09 16:45:46 +00:00
Lorenzo Colitti
6cbdc19b2c Add CTS tests for registerDefaultNetworkCallbackAsUid. am: ed26ffe92d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1669267

Change-Id: Id8d968130a52d419c65a628fb93e47e5ac48c81e
2021-04-09 15:59:13 +00:00
junyulai
74e03eb201 Fix NetworkCallback expecting wrong network am: 2e74377464 am: cfd7518bdc
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1657299

Change-Id: I4a04b1c4d0e761024a0a7506c7fcf32020413c4b
2021-04-09 09:38:43 +00:00
junyulai
cfd7518bdc Fix NetworkCallback expecting wrong network am: 2e74377464
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1657299

Change-Id: Ia3e24d519ab7101e9cd1be7ec18f1ba7f7fff7e9
2021-04-09 08:53:47 +00:00
junyulai
2e74377464 Fix NetworkCallback expecting wrong network
By current wifi design, wifi will report disconnected and
re-connected when changing from non-metered to metered.
However, the cts test app listens for all network, which
will get mobile network as active network when wifi is
changing meteredness. This is not expected. And causes
test failures when DUT has both wifi and mobile connections.

Thus, this change pass request to track currently active
network to the test app and register only for transport
types of currently active network to prevent from getting
unexpected network.

Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideNetworkCallbackTests
Bug: 182516128
Merged-In: I2dce6035b13472bbdc2609009d690aac96280033
Change-Id: I2dce6035b13472bbdc2609009d690aac96280033
  (cherry-picked from ag/14029457)
2021-04-09 10:16:18 +08:00
Nucca Chen
e37b9272f4 Merge "[NFCT.TETHER.11] Test TetherOffloadRule{Add, Remove} and set limit for IPv4" am: 68f6f5fe79 am: f0b3bb6e4e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1563332

Change-Id: I56c1250280473dd1e10693c9cae65e6d2e5e808d
2021-04-08 13:30:30 +00:00
Nucca Chen
f0b3bb6e4e Merge "[NFCT.TETHER.11] Test TetherOffloadRule{Add, Remove} and set limit for IPv4" am: 68f6f5fe79
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1563332

Change-Id: Id5f0d10b07b8fde23d627eaa7058b38512591f98
2021-04-08 12:46:23 +00:00
Lorenzo Colitti
ed26ffe92d Add CTS tests for registerDefaultNetworkCallbackAsUid.
Bug: 165835257
Test: test-only change
Change-Id: Ib3266665735ee587f3f8ae82dadd1e4ca7ce4353
2021-04-08 21:44:30 +09: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
Xiao Ma
5d0cec9328 Apply IPv6 utils struct stuff to build RA packet in the Daemon. am: 3e557d777a am: 7f8ae5c99d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1614996

Change-Id: I00b6312bc87f1958c1dae5f99584f93a12f75eae
2021-04-08 06:35:25 +00:00
Xiao Ma
7f8ae5c99d Apply IPv6 utils struct stuff to build RA packet in the Daemon. am: 3e557d777a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1614996

Change-Id: Id6b170c8743ba3c7449183c9694cce54f0bdf1bf
2021-04-08 05:51:56 +00:00
Treehugger Robot
5efb849dcf Merge "Improve RouterAdvertisementDaemonTest." am: 662237f2f8 am: 3b2ad2b764
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1669025

Change-Id: Ifcf397852832cb8e1550b4a3b933c9872f93cc50
2021-04-08 05:07:35 +00:00
Xiao Ma
3e557d777a Apply IPv6 utils struct stuff to build RA packet in the Daemon.
Traffic log of testSolicitRouterAdvertisement:
fe80::4473:4aff:fecb:7799 > ff02::1: ICMP6, router advertisement, length 88
fe80::1122:3344:5566:7788 > ff02::1: ICMP6, router solicitation, length 16
fe80::4473:4aff:fecb:7799 > fe80::1122:3344:5566:7788: ICMP6, router advertisement, length 88

Bug: 154669942
Test: atest TetheringPrivilegedTests --iterations
Change-Id: I7defb80ef9dd1832c9e04d154e1d06aed9e733dc
2021-04-08 04:50:49 +00:00
Treehugger Robot
3b2ad2b764 Merge "Improve RouterAdvertisementDaemonTest." am: 662237f2f8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1669025

Change-Id: I9e9bb95e095fa1b8d907d56cc0e347746ae9a01c
2021-04-08 04:45:41 +00:00
Treehugger Robot
662237f2f8 Merge "Improve RouterAdvertisementDaemonTest." 2021-04-08 04:07:14 +00:00
Xiao Ma
597d253f18 Improve RouterAdvertisementDaemonTest.
Add separate testing for unicast and multicast RAs.
Make the test more realistic by:
- Enabling forwarding. This ensures that the daemon actually
  receives the RS.
- Adding a link-local route. This ensures that the daemon is
  actually able to send a unicast response.

Bug: 154669942
Test: atest TetheringPrivilegedTests
Change-Id: Ibb1f51b5b1871657d7feff39335d3c71586cf64f
2021-04-08 11:02:02 +09:00
Nucca Chen
77ab55f55b Merge changes I515be275,Ied159454,I5a29bdd1 am: 8ba40704f3 am: 7cc20e1782
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662791

Change-Id: Ie340d743f8de13fcac7c360dd47f64d75b65123e
2021-04-07 15:30:54 +00:00
Nucca Chen
7cc20e1782 Merge changes I515be275,Ied159454,I5a29bdd1 am: 8ba40704f3
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662791

Change-Id: I220f3384baa2414dc7aad6e5754b59e6d3592bdc
2021-04-07 14:48:57 +00:00
Nucca Chen
8ba40704f3 Merge changes I515be275,Ied159454,I5a29bdd1
* changes:
  bpf_progs - adjust for dstMac addition
  Populate the key destination mac address
  Set the limit whenever any IPv4 or IPv6 rule exists.
2021-04-07 14:08:37 +00:00
Maciej Żenczykowski
e762de5deb bpf offload - make sure bpf code can access packet headers am: 8e69ec111f am: 3129be7a3b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1622559

Change-Id: Id2d51f17c4254f122445708fd8efc0cff7b53009
2021-04-07 02:00:16 +00:00
Maciej Żenczykowski
3129be7a3b bpf offload - make sure bpf code can access packet headers am: 8e69ec111f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1622559

Change-Id: I303cd63ee424c8c4ef1c744e1893c06a5d53f50a
2021-04-07 01:19:05 +00:00
Maciej Żenczykowski
8e69ec111f bpf offload - make sure bpf code can access packet headers
If a tc ebpf program writes into a packet using direct packet access
then the packet will automatically be uncloned and pulled by
additional prologue inserted by the kernel itself.  See
tc_cls_act_prologue() & bpf_unclone_prologue() in kernel sources
(this is how the clat ebpf program works, which does DPA writes).

However in the forwarding programs we only *read* from the packets
using direct packet access, but never write.  All writes happen via
kernel bpf helpers (this is mostly an implementation detail: since
we need to use helpers for checksum updates, I decided to also use
checksums for the writes themselves).  As such the insert 'automatic
unclone/pull' logic doesn't trigger.

It is thus possible (it depends on the skb layout delivered by the
nic driver) for 0 bytes of the packet to be accessible for read
using direct packet access.  We thus need to explicitly try to pull
in the header of the packet so that we can inspect it.

In most cases (on most drivers for most packet types) this will
end up being a no-op (because the headers will already be in
the linear portion of the skb).  But on some drivers for some
packet types it ends up mattering.

Test: TreeHugger, makes icmpv6 tether forwarding work on bramble
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4b07e57728ce544ffb908527ea11ecc315e5acec
2021-04-06 21:50:17 +00:00
Chiachang Wang
e08cfe35ca Merge "Update tests for onNetworkCreated and onNetworkDestroyed" am: 7d0e27bd7c am: d212efd8b0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1652210

Change-Id: Ie18feeed7a5fab34e9696f057633cd40f67ce0ba
2021-04-06 12:35:58 +00:00
Chiachang Wang
d212efd8b0 Merge "Update tests for onNetworkCreated and onNetworkDestroyed" am: 7d0e27bd7c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1652210

Change-Id: I4ced8a0913bd170e8b6e008480c3dd2cf60c6246
2021-04-06 11:44:11 +00:00
Chiachang Wang
7d0e27bd7c Merge "Update tests for onNetworkCreated and onNetworkDestroyed" 2021-04-06 11:04:30 +00:00
Chiachang Wang
9565064aad Merge "Ensure SSID is not exposed to apps without correct permission" am: 674a907cc4 am: c1c5f7f974
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1655447

Change-Id: I5e7ec1bec1e578b45cf3940b748fa585f6dda246
2021-04-06 09:37:37 +00:00
Chiachang Wang
c1c5f7f974 Merge "Ensure SSID is not exposed to apps without correct permission" am: 674a907cc4
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1655447

Change-Id: Ib93d650bc77e2b5daa75ce8f79bbd392e1f5c46c
2021-04-06 09:17:42 +00:00
Maciej Żenczykowski
ebddc8809f Merge "implement insertOrReplace()" am: 47851fc01b am: 40899ff9e8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662788

Change-Id: I5c9f760c6281d0154377a2edeaaac375bfc3020a
2021-04-06 09:17:33 +00:00
Chiachang Wang
674a907cc4 Merge "Ensure SSID is not exposed to apps without correct permission" 2021-04-06 08:58:50 +00:00
Maciej Żenczykowski
40899ff9e8 Merge "implement insertOrReplace()" am: 47851fc01b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662788

Change-Id: I06081f8ad3e27875ec6a0f13cb21f6b1ab006159
2021-04-06 08:55:52 +00:00
Maciej Żenczykowski
47851fc01b Merge "implement insertOrReplace()" 2021-04-06 08:17:42 +00:00
Frank Li
7f1a6eb12f Merge "Add session ID to VpnTransportInfo" am: 320cd17220 am: 45d9b25a36
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1652217

Change-Id: I42628292a9d30ac39e29278214b9a179f28e277c
2021-04-06 07:35:07 +00:00
Frank Li
45d9b25a36 Merge "Add session ID to VpnTransportInfo" am: 320cd17220
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1652217

Change-Id: I2bcafaaeb3f9dd2030745f1f7fa52f10f60733dd
2021-04-06 07:01:13 +00:00
Frank Li
320cd17220 Merge "Add session ID to VpnTransportInfo" 2021-04-06 06:50:48 +00:00
Lorenzo Colitti
658bdb7e1e Fix DadProxyTest when forwarding is on. am: b6bffbca95 am: 3f29d3ef39
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1664401

Change-Id: I5715c990a0de3b3de1a09e44a25bf96d7027feb5
2021-04-06 04:42:31 +00:00
Lorenzo Colitti
6033471338 Fix a race condition in upstream selection. am: 491999292b am: bf8a7b622d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662400

Change-Id: Ie771aba579b10a742b14d598dfcc50eee6baf4df
2021-04-06 04:42:30 +00:00
Lorenzo Colitti
48cd598f81 Add unit tests for race conditions in upstream selection. am: 6748e62ef2 am: afb685e650
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662399

Change-Id: I08b9b57734374ab12634ea8ba20c718c6e7c3280
2021-04-06 04:42:29 +00:00
Maciej Żenczykowski
a36ea6fb19 implement insertOrReplace()
Test: atest com.android.networkstack.tethering.BpfMapTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4a40898f03293d6d79b57c35f743271c669a8ea7
2021-04-06 04:38:46 +00:00
Lorenzo Colitti
3f29d3ef39 Fix DadProxyTest when forwarding is on. am: b6bffbca95
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1664401

Change-Id: I08b7f80b872a0cac5c1e0b930f4aca47c186b598
2021-04-06 03:59:23 +00:00
Lorenzo Colitti
bf8a7b622d Fix a race condition in upstream selection. am: 491999292b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662400

Change-Id: I6e1e1834489b80eb332176a69f4f6740e9575bdd
2021-04-06 03:59:22 +00:00
Lorenzo Colitti
afb685e650 Add unit tests for race conditions in upstream selection. am: 6748e62ef2
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662399

Change-Id: Id2dcfdc1ec744e67f9f7877ea264bffdf1354b62
2021-04-06 03:59:19 +00:00
Lorenzo Colitti
b6bffbca95 Fix DadProxyTest when forwarding is on.
When forwarding is on, DadProxyTest fails because forwarding
disables optimistic addresses. This results in the DAD proxy
getting EADDRNOTAVAIL.

Forwarding is on quite often on real hardware because many
solutions for wifi calling use forwarding.

Fix the test to retry after two seconds if the packet is not
forwarded on the first attempt.

It would also be possible to make this work more reliably in the
test by simply disabling DAD or disabling forwarding. However,
because DAD does happen in real usage (downstream interfaces
always disable DAD, but upstream interfaces don't), that seems
risky. For example, if the test disabled DAD, it would not catch
bugs where the DAD proxy crashed or stopped forwarding if it got
EADDRNOTAVAIL.

Test: atest TetheringPrivilegedTests on coral, which has forwarding on
Change-Id: I58280ef7c0e40371cd770ead4c8baa7190c288fd
2021-04-05 23:42:29 +09:00
Lorenzo Colitti
491999292b Fix a race condition in upstream selection.
Current upstream selection code suffers from a race where if the
CONNECTIVITY_ACTION broadcast for a given network switch is
received and processed before the NetworkCallbacks for that
network switch, upstream selection just re-selects the same
upstream it had before. The incorrect upstream persists until
another CONNECTIVITY_ACTION is received.

Fix this by defining a new EVENT_DEFAULT_SWITCHED message code
communicated from UpstreamNetworkMonitor to Tethering, and send
that whenever the default network switches.

The message is sent in onLinkPropertiesChanged, because the
tethering code stores all information about networks in an
UpstreamNetworkState structure that contains Network,
LinkProperties and NetworkCapabilities. When a network switch
occurs, onLinkPropertiesChanged always follows onAvailable and
onCapabilitiesChanged, and thus marks the first point in time
when all the information is available.

This CL tries not to change existing codepaths too much, but
it does move the update of mDefaultInternetNetwork from
onCapabilitiesChanged to onLinkPropertiesChanged. This should
not be a problem because the only thing that reads
mDefaultInternetNetwork is getCurrentPreferredUpstream, which,
in the case of a default network switch, will be run by the
onLinkPropertiesChanged which will immediately follow.

Bug: 173068192
Test: changes to existing unit tests show bug is fixed
Change-Id: Ic9196bc92892811b25bda463ffd839ee5c19d294
2021-04-05 22:52:13 +09:00
Lorenzo Colitti
6748e62ef2 Add unit tests for race conditions in upstream selection.
In the current tethering code, upstream selection is only
triggered by CONNECTIVITY_ACTION. But in automatic mode, the
upstream network is selected by listening to a NetworkCallback
that tracks the default network.

This causes a race where if the CONNECTIVITY_ACTION for a network
switch is received and processed before the callbacks for that
network switch, upstream selection just re-selects the upstream
currently in use.

Make it possible to test this by giving TestConnectivityManager
the ability to choose the ordering between NetworkCallbacks and
CONNECTIVITY_ACTION, and to run an arbitrary Runnable between
calling one and calling the other. TetheringTest passes a
Runnable that calls mLooper.dispatchAll(), which ensures that
the tethering code fully processes the first set of information
it receives (either the broadcast (or the callbacks) before
receiving any more information.

Add test coverage to testAutomaticUpstreamSelection that
exercises various orderings, and make the test pass by expecting
the buggy behaviour of the current code.

An upcoming CL will fix the bug and update the tests.

Bug: 173068192
Test: test-only change
Change-Id: I7805444dcf59f6d5f8517fbcf2f2b1641783d50b
2021-04-05 14:51:53 +09:00
Lorenzo Colitti
6ca408f317 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7 am: a16ca88456
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: Ib095466f92872d50cc751b34cc870df31dc8e345
2021-04-02 10:06:09 +00:00
Lorenzo Colitti
a16ca88456 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: I461c6214d0591d426f6cbc5f23dd2b56551abdcb
2021-04-02 09:26:29 +00:00
Lorenzo Colitti
e9bc8c9db7 Dump the input destination MAC address for IPv4 flows.
This is needed for forwarding to work, so it should be dumped.

New output:

  Forwarding rules:
    29(29) -> 14(rmnet2) 86dd 00:00:00:00:00:00 00:00:00:00:00:00
    [ap_br_wlan2]: iif(iface) oif(iface) v6addr srcmac dstmac
      14(rmnet2) 29(ap_br_wlan2) 2001:240:2423:13fa:3c21:e35a:6a59:ff8a da:17:fd:70:3d:14 26:5b:b2:ee:bc:ba
    IPv4: [inDstMac] iif(iface) src -> nat -> dst
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:39208 -> 14(rmnet2) 100.102.14.231:39208 -> 172.217.175.3:80
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:47386 -> 14(rmnet2) 100.102.14.231:47386 -> 216.58.197.196:443

Also add a call to getHostAddress() to remove the / on IPv6
forwarding rules.

Test: manual
Change-Id: I347ea5a3fd88c51f1fae0c76c75dfa30c68a55ad
2021-04-02 05:42:22 +00:00
Maciej Żenczykowski
62733f5524 bpf_progs - adjust for dstMac addition
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I515be275d09dc7e6bae2564f7db2445ea15cc757
2021-04-02 05:12:33 +00:00
Aaron Huang
b3cc853814 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" am: 5316e1ff18 am: 9c3cfaa9b8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626079

Change-Id: Ic491a32bbc6bb8173f15f491adb31a942eb7e773
2021-04-01 16:45:23 +00:00
Aaron Huang
9c3cfaa9b8 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" am: 5316e1ff18
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626079

Change-Id: Idd6ae755683a38d665a7b0744bcd7d8d1d29ea6f
2021-04-01 16:25:45 +00:00