Commit graph

103,373 commits

Message SHA1
[mdns] service implementation for public key
Bug: 317946010
Bug: 333232582

Change-Id: Iab66bf0a1af14878c7b18a7a3015c2de7a6514c8

Handa Wang   commited 2024-04-24 07:17:00 +00:00
52497d66cc
[mdns] add hidden API for public key
This commit adds support of registering a public key for a host/service.
This is required to enable Advertising Proxy feature for Thread devices.

For example:
```
NsdServiceInfo info = new NsdServiceInfo();

info.setServiceName("My Service");
info.setServiceType("_test._tcp");
info.setHostname("MyHost");
info.setHostAddresses(List.of(address1, address2));
info.setPublicKey(/* KEY RDATA */);

nsdManager.registerService(info, PROTOCOL_DNS_SD, listener);
```

Bug: 317946010

Change-Id: I367ebff8119d5c1dff0410c85e6fb86dca6c66b8

Handa Wang   commited 2024-04-24 07:02:42 +00:00
364aa570e2
Merge "Test whether APF program actually runs" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-24 04:17:31 +00:00
1b7c5e097c
Merge "Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-04-24 03:51:09 +00:00
c04493234e
Test whether APF program actually runs
Adds a test that sends a ping packet, asserts its reply, then installs a
filter and asserts that the second ping packet is dropped.

Test: test only
Change-Id: I832ea1b3cc35a44c98fbf8c86c16bf753f183c92

Patrick Rohr   commited 2024-04-23 09:01:04 -07:00
22e571353f
Only listen to echo replies
This discards anything that is not an echo reply. Technically, length
cannot be 0, since zero-length packets close the PacketReader (because
FdEventsReader#shoudlProcessZeroLengthPacket has not been overridden
(yet?)).

Test: atest ApfIntegrationTest
Change-Id: Ib7cd9bf819614e66c8b6b7fc15622be5c344a208

Patrick Rohr   commited 2024-04-23 08:24:44 -07:00
bd50241d03
Move turnScreenOff to BeforeClass setUp
A Thread.sleep() is needed after turnScreenOff() to ensure APF has
started running. This means it makes sense to move turnScreenOff to
a @BeforeClass setup to avoid slowing down the tests.

Test: atest ApfIntegrationTest
Change-Id: Ie1d9335fb1ad2ac3c51a48269b28f66f212f993c

Patrick Rohr   commited 2024-04-23 08:24:44 -07:00
2ec433dd58
Reapply "Send ICMPv6 ping to support IPv6-only network"
This reverts commit 98219a4e8a.

Moved the revert past "Only run APF tests on physical devices".
This broke on cuttlefish, as CF does not support IPv6.

Test: TH
Change-Id: I04d1adb4538e6c413a1325432e1c014ca78b41e3

Patrick Rohr   commited 2024-04-23 08:24:00 -07:00
c83731b8d9
Only run APF tests on physical devices
Cuttlefish does not actually implement APF, and there is no point in
general to test APF integration on virtual devices.

Test: atest ApfIntegrationTest
Change-Id: I1f0e25255d1ebcc5a6a50a42968ea1e14b5755db

Patrick Rohr   commited 2024-04-23 08:22:42 -07:00
5ec06b7a65
Merge "Use helper function getIndexForValue in MulticastRoutingCoordinator." into main
Yang Sun   authored and   Gerrit Code Review   commited 2024-04-23 12:58:39 +00:00
173ffb9278
Use helper function getIndexForValue in MulticastRoutingCoordinator.
The SparseArray.indexOfValue() uses == to compare values,
MulticastRoutingCoordinator uses SparseArray with String type values,
and the indexOfValue function would sometimes return -1 when looking for
a value in the SparseArray.

Added a helper function getIndexForValue in CollectionUtils to get index
by comparing values with equals, and used this function in MulticastRoutingCoordinator.

Updated
MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc
test case to use copies of interface names when updating the multicast
configs, so the test would fail without this fix.

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.CollectionUtilsTest#testGetIndexForValue
atest android.net.connectivity.com.android.server.connectivity.MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc

Change-Id: I862242d6be01b8552cdd6af6c9691948a9f0bfe0

Yang Sun   commited 2024-04-23 17:22:15 +08:00
4e7baadc71
Merge "Revert "Send ICMPv6 ping to support IPv6-only network"" into main
Daniel Hsieh   authored and   Gerrit Code Review   commited 2024-04-23 07:14:36 +00:00
0fc03c7c31
Revert "Send ICMPv6 ping to support IPv6-only network"
This reverts commit 03e958226e.

Reason for revert: This cl causes b/336432192.

Change-Id: Id103cbce07466213eb325fc99fe37f02aa72c786

Daniel Hsieh   authored and   Gerrit Code Review   commited 2024-04-23 06:05:09 +00:00
98219a4e8a
Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX
Follow up CLs will update CS to generate blocked reason from bpf map
instead of asking NPMS.

However, one issue is NPMS set PENALTY_BOX for
BLOCKED_METERED_REASON_USER_RESTRICTED and
BLOCKED_METERED_REASON_ADMIN_DISABLED without telling the reason.
So, CS can not know the reason of PENALTY_BOX.

This CL add new firewall chain and match to distinguish reasons.
NPMS must call setUidFirewallRule with
FIREWALL_CHAIN_METERED_DENY_USER or FIREWALL_CHAIN_METERED_DENY_ADMIN
based on the reason so that CS can know the reason of restriction.

Bug: 332628891
Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Change-Id: Ia4ad4bdb345abc22c782630e828edfad2452db36

Motomu Utsumi   commited 2024-04-23 15:04:28 +09:00
11d3345daa
Merge "NetBpfLoad: prog names are only valid on 4.15+" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-23 04:41:20 +00:00
926f012615
Merge "Assert fixed test method count in ConnectivityServiceTest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-23 03:38:41 +00:00
0168ae22f6
Merge "Send ICMPv6 ping to support IPv6-only network" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-23 03:18:51 +00:00
d601d1156c
NetBpfLoad: prog names are only valid on 4.15+
The following commit is only in 4.15:

  commit cb4d2b3f03d8eed90be3a194e5b54b734ec4bbe9
  Author: Martin KaFai Lau <kafai@fb.com>
  Date:   Wed Sep 27 14:37:52 2017 -0700

    bpf: Add name, load_time, uid and map_ids to bpf_prog_info

  $ git describe cb4d2b3f03d8eed90be3a194e5b54b734ec4bbe9
  v4.14-rc1-661-gcb4d2b3f03d8

Bug: 335390828
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I246a7a8640bea1e939f12f3ffd3fedc25a0a6422

Maciej Żenczykowski   commited 2024-04-23 03:16:05 +00:00
89efcc36e7
Merge "[mdns] add elapsedRealTime() to Dependencies for MdnsRecordRepository" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-23 01:59:30 +00:00
23a6d34788
Merge "NetBpfLoad: map names are only valid on 4.15+" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-23 01:02:39 +00:00
bba9e006b1
NetBpfLoad: map names are only valid on 4.15+
$ git checkout v4.14
HEAD is now at bebc6082da0a Linux 4.14

$ git grep map_name | egrep -v '^(arch|drivers|fs|include|samples|tools)/'

(nothing)

$ git checkout v4.15
HEAD is now at d8a5b80568a9 Linux 4.15

$ git co remotes/linux-$ git grep map_name | egrep -v '^(arch|drivers|fs|include|samples|tools)/'
kernel/bpf/syscall.c:381:#define BPF_MAP_CREATE_LAST_FIELD map_name
kernel/bpf/syscall.c:408:	err = bpf_obj_name_cpy(map->name, attr->map_name);

  commit ad5b177bd73f5107d97c36f56395c4281fb6f089
  Author: Martin KaFai Lau <kafai@fb.com>
  Date:   Wed Sep 27 14:37:53 2017 -0700

    bpf: Add map_name to bpf_map_info

  $ git describe ad5b177bd73f5
  v4.14-rc1-662-gad5b177bd73f

Bug: 335390828
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I74f8ac8bbf78184a06b3ce005d0bb520b1d1feeb

Maciej Żenczykowski   commited 2024-04-22 23:42:10 +00:00
d0bb172371
Send ICMPv6 ping to support IPv6-only network
When using IPv4 ping, the APF filter has to take clat into account. In
order to prevent this complexity, just send an ICMPv6 ping instead.

Test: atest ApfIntegrationTest
Change-Id: I7938366ea26295bb3b3b1077d7d31395bc493770

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
03e958226e
CompletableFuture can only be completed once
Also, it throws a TimeoutException instead of an ExecutionException if
get() times out. (ExecutionExceptions are thrown if the future completes
exceptionally, which is not the case here.)

Test: TH
Change-Id: If1bc359e8fefb819089e4f2885fb45ee7e3a996c

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
522d5c7e7a
Log ping packet and reply and use ByteArray.toHexString
ByteArray.toHexString is experimental stdlib API, so it requires a
special annotation to be used. If there is a good reason not to use the
experimental API, an extension function "asHexString()" could be added
to.
Unfortunately, ByteArray does not have a companion object, so it is not
possible to add a fun ByteArray.Companion.fromHexString().

Test: TH
Change-Id: Ifedc998e95d6a1e4cdeb5bd9982b9456e64e649c

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
2eb48f0265
[mdns] add elapsedRealTime() to Dependencies for MdnsRecordRepository
This CL adds elapsedRealTime() to Dependencies so that in the unit test
we can simulate the elapse of time.

Bug: 336268432
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsRecordRepositoryTest
Change-Id: I64cf0ac1772f54edf187cf9ca6351a75b81fd859

Handa Wang   commited 2024-04-22 16:06:38 +00:00
a1a80ad9c3
Merge "[mdns] separate the multicast reply quota for IPv4 and IPv6" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-22 13:50:18 +00:00
c03867b757
Assert fixed test method count in ConnectivityServiceTest
ConnectivityServiceTest is deprecated but people sometimes still
add new test methods to it, and getting review feedback to rewrite
tests in CSTest. This wastes resources.
Thus, assert fixed test method count to make it fails locally for
people to aware of it.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testTestMethodCount
Bug: N/A
Change-Id: I0a98a0e3fcd97484f372737e7c6fe24743c21834

Junyu Lai   commited 2024-04-22 17:11:50 +08:00
08f5b59482
[mdns] separate the multicast reply quota for IPv4 and IPv6
This CL separates the multicast reply quota for IPv4 and IPv6. Before
this change, when an IPv4 mDNS query and an IPv6 mdns query arrives at
the same time for the same record (which is a common behavior for DNS-SD
resolvers), MdnsRecordRepository will only respond to one of them. The
other response will be throttled silently.

It's especially problematic when the IPv4 query and IPv6 query are sent
by different hosts. One of the hosts will get no reply.

Bug: 335096961
Test: Unit test and verified on a local device.

Change-Id: I0d7a9fad2b43bbfb8b042828295cdf08bf4ae5c8

Handa Wang   commited 2024-04-22 07:37:22 +00:00
c8de4cb79f
Merge "Wait for start() to finish" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-20 02:11:34 +00:00
503a25c8f0
NetBpfLoad: consistently use logging tag of 'NetBpfLoad'
instead of using 'NetBpfLoad' from NetBpfLoad.cpp
and 'NetBpfLoader' from loader.cpp

This will make it easier to filter logcat.

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibd4e0b04592e8b41cde651c5596ce84bd8893c19

Maciej Żenczykowski   commited 2024-04-20 00:03:19 +00:00
3d14144698
bpf: offload.c - comment out CRITICAL mark
My guess is some 4.14-T devices lack the required
bpf_skb_change_head(), see comment in file at line 321:

// bpf_skb_change_head() is only present on 4.14+ and 2 trivial kernel patches are needed:
//   ANDROID: net: bpf: Allow TC programs to call BPF_FUNC_skb_change_head
//   ANDROID: net: bpf: permit redirect from ingress L3 to egress L2 devices at near max mtu
// (the first of those has already been upstreamed)
//
// These were added to 4.14+ Android Common Kernel in R (including the original release of ACK 5.4)
// and there is a test in kernel/tests/net/test/bpf_test.py testSkbChangeHead()
// and in system/netd/tests/binder_test.cpp NetdBinderTest TetherOffloadForwarding.

(will revert once we have a release key signed build for
 testing on user builds)

Bug: 335390828
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3517e70543d93ced2c1abd9c0f3ccc2b211d9966

Maciej Żenczykowski   commited 2024-04-19 18:50:31 +00:00
8099c3b1b8
Wait for start() to finish
Since start() triggers createFd(), it does need to wait for it to
complete. Otherwise, sendPing() might run before a socket has been
allocated.

Bug: 335824575
Test: TH
Change-Id: Ic65b691ea039c3cbbe99c792144f491c46c486b7

Patrick Rohr   commited 2024-04-19 10:50:33 -07:00
1588303666
Merge "Add a placeholder test to test IcmpPacketReader and sendPing" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-19 02:12:40 +00:00
a114c93950
Merge changes I1d0b73ef,I753dac68,Id3fb329b,I7037bee1 into main
* changes:
  Add support for sendPing
  Add support to expect ping reply or dropped ping
  Bind socket to WiFi network
  Add IcmpPacketReader to ApfIntegrationTest

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-19 02:12:32 +00:00
c0863c003e
Add a placeholder test to test IcmpPacketReader and sendPing
This will soon become an actual APF test.

Test: atest ApfIntegrationTest
Change-Id: I5c78b557177c96e3460a1057527f67de78290338

Patrick Rohr   commited 2024-04-18 13:12:48 -07:00
c2c667ba43
Add support for sendPing
This hard-codes the destination as 8.8.8.8.

Test: mm
Change-Id: I1d0b73ef5bfa20bf094d5ca81de6a2bbe443f30a

Patrick Rohr   commited 2024-04-18 13:12:21 -07:00
977573efd0
Add support to expect ping reply or dropped ping
Test: mm
Change-Id: I753dac687c5521b45bd99a6d57c7be60e25bb1ce

Patrick Rohr   commited 2024-04-18 13:03:22 -07:00
a89976d5f9
Bind socket to WiFi network
APF is only supported on WiFi, so make sure that the socket is bound to
the right network.

Test: TH
Change-Id: Id3fb329b0bb3125c9dfe64cc22f3e04bd586f70a

Patrick Rohr   commited 2024-04-18 12:46:23 -07:00
125deb970a
Add IcmpPacketReader to ApfIntegrationTest
This does not currently do anything as no one is sending packets yet.

Test: builds
Change-Id: I7037bee1997dda8ed2a706a8178dec9be995fcf1

Patrick Rohr   commited 2024-04-18 12:44:51 -07:00
824a659921
Merge "Return current testable networks directly in instant mode" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-18 12:02:42 +00:00
53babdfee5
Return current testable networks directly in instant mode
Some MultinetworkApiTest tests require a testable network and
attempt to request cell or Wi-Fi connections. This involves
calling ConnectivityManager#requestNetwork, which requires the
CHANGE_NETWORK_STATE permission. Since instant apps cannot be
granted this permission, return currently available testable
networks directly in instant mode instead of attempting to
request new ones.

Fix: 335103621
Test: atest CtsNetTestCases:android.net.cts.MultinetworkApiTest \
      --instant
Change-Id: I51dbd33e0dab12856e1c0f387e45e6286feefe20

Paul Hu   commited 2024-04-18 05:57:04 +00:00
82e396394b
Add safeguard against previous ethernet interfaces existing
The test EthernetManagerTest#testEnableDisableInterface_callbacks
captures the interface state changes of ethernet
interfaces that already exist instead of the test one created. Changes
the expectCallback to eventuallyExpect to account for this.

Test: atest EthernetManagerTest
Flag: TEST_ONLY
Bug: 333338569
Change-Id: Ic08444c87f93b3832c4fae1ce2f8382bbb71cb28

Chris Desir   commited 2024-04-17 15:00:00 -07:00
7e6f10ce0a
Merge "Allow MAC addresses to configure IP configurations" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-17 00:56:53 +00:00
fd207b88e7
Allow MAC addresses to configure IP configurations
This allows the behavior to align with how MAC addresses can configure
network capabilities in config.xml. Ethernet interfaces can be
configured in the following format "<interface name|mac address>;
[Network Capabilities];[IP config];[Override Transport]", however for IP
 configurations within EthernetTracker the mac address was not
 considered.

Additionally, this CL fixes lapses in the retrieval of network
capabilities by mac address as well (e.g. within isRestrictedInterface,
network capabilities were only retrieved by the interface name rather
than the interface name and the mac address)

Test: atest FrameworksNetTests
Bug: 142259350
Change-Id: I211dd6466abcdbb1de3ca512a65214ed9e249969

Chris Desir   commited 2024-04-16 15:26:19 -07:00
dbbada4d7b
Merge "[mdns] allow hostnames beginning with a digit" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-16 08:25:38 +00:00
f41e6019dd
Merge "Add prefixmsg struct to parse RTM_NEWPREFIX message header." into main
Xiao Ma   authored and   Gerrit Code Review   commited 2024-04-16 08:19:59 +00:00
22d42e6079
Add prefix_cacheinfo struct to parse PREFIX_CACHEINFO attribute.
Bug: 315069348
Test: TH
Change-Id: I6a2cd40ab81fa079cdd6bd309dd48387c6faf146

Xiao Ma   commited 2024-04-16 14:56:25 +09:00
44df982062
Add prefixmsg struct to parse RTM_NEWPREFIX message header.
Bug: 315069348
Test: TH
Change-Id: I8bc5bee20f3043203f591bdfe31a4879a09d1565

Xiao Ma   commited 2024-04-16 14:54:51 +09:00
a25a09d2c2
[mdns] allow hostnames beginning with a digit
A Matter device uses a hex as the hostname so it may begin with a digit
which wasn't allowed in NsdService. This CL looses this check to allow
Matter devices to register their services at Android Thread Border
Router.

Bug: 334828525
Test: CI
Change-Id: Ia779791e214158a08c2ec06adf8d5630ec8ea616

Handa Wang   commited 2024-04-16 05:52:01 +00:00
8310a5e2d4
Merge "Convert RTM_NEWPREFIX nlmsg type to string in stringForRtMsgType()." into main
Xiao Ma   authored and   Gerrit Code Review   commited 2024-04-16 00:12:22 +00:00
52b6244b67