Commit Graph

280 Commits

Author SHA1 Message Date
Mike Yu
f5032571a8 Add tests for DnsSvcbRecord and DnsSvcbPacket
This change adds the test coverage for DnsSvcbRecord
and DnsSvcbPacket.

Bug: 240259333
Test: atest ConnectivityCoverageTests
Change-Id: I0b6328337fd61c5ac2e5f6b3737238f7d678245a
2023-11-09 02:14:29 +00:00
Mike Yu
9b96c83238 Add DnsSvcbRecord
This change is an initial implementation of DNS SVCB Record. It
can parse an SVCB Record in wire format.

The RDATA field of a SVCB Record is formatted as follows:
- SvcPriority: 2-byte field
- TargetName: a domain name that follows RFC1035 section 5.1
- SvcParams (optional): a list of SvcParam

This initial implementation focuses on the SvcParams related to DDR,
including alpn, port, ipv4hint, ipv6hint, and dohpath. For the other
SvcParams, such as mandatory and ech, this change doesn't check
whether their value is valid.

Bug: 240259333
Test: atest ConnectivityCoverageTests
Test: No test for DnsSvcbRecord for now. will add some tests in a
      follow-up change
Change-Id: Icfe9b623eda8390c40b106123a718cdd2af3af99
2023-11-09 02:14:29 +00:00
Chiachang Wang
fe84f59ff0 Rename method connectSocketToNetlink to connectToKernel
Address leftover comments in aosp/2354202.

Bug: 265877161
Test: atest FrameworksNetTests NetworkStackTests
Change-Id: I77f36b890265e9af6f5ab866d5e0071363bb3d0f
2023-11-06 03:18:18 +00:00
Motomu Utsumi
d232211291 Merge "Handle v4-mapped v6 address in Struct parsing" into main 2023-10-31 12:02:47 +00:00
Motomu Utsumi
cb62c1b120 Merge "Add util method to generate IPv4-mapped IPv6 address from IPv4 address" into main 2023-10-31 12:02:08 +00:00
Motomu Utsumi
e3e34bdf3a Handle v4-mapped v6 address in Struct parsing
testV4MappedV6Address fails without change in Struct.java

Bug: 295800201
Test: atest ConnectivityCoverageTests
Change-Id: I4a40bc47b051860c6420f211491e2ecd34c1d732
2023-10-31 17:01:48 +09:00
Motomu Utsumi
52366e0fb1 Add util method to generate IPv4-mapped IPv6 address from IPv4 address
Bug: 295800201
Test: NetworkStaticLibTests
Change-Id: Ia10e7dd14edfabe0edf5c9e12ceae54a1ff88d13
2023-10-31 17:01:43 +09:00
Remi NGUYEN VAN
eaa71ff305 Increase HandlerUtilsTest timeout to 500ms
The test is currently 1~3% flaky with a 200ms timeout, in particular it
may fail if a GC runs while waitForIdle is running.

Increase the timeout to 1s, which should be enough to cover such cases.

Change-Id: Ic6d4ff18fb81feb09639442196cdef3c5cfdf30c
Fixes: 302949876
Test: TH
2023-10-06 08:20:53 +00:00
Treehugger Robot
a675e966b2 Merge "Remove defaultEnabled arg from isNetworkStackFeatureEnabled" into main 2023-10-03 11:51:32 +00:00
Treehugger Robot
f74f42b4c0 Merge "Add method to read trunk stable flag" into main 2023-10-02 13:17:53 +00:00
Motomu Utsumi
b0f489021b Add method to read trunk stable flag
aconfig soong modules should be used to read the trunk stable flag.
However they are not available in the mainline branch.
So this CL adds the method to check if the trunk stable flag is enabled
or not by directly reading from DeviceConfig.
It's expected that this does not work correctly if flag value is not
stored in the DeviceConfig.
But for the time being, this method can be used to keep development.
Once the mainline branch supports the aconfig soong modules, method
added by this CL must be removed and java_aconfig_library should be
used instead.

Test: adb shell device_config put android_core_networking \
Test: com.android.net.flags.test_feature true
Test: Compares the value from java_aconfig_library and DeviceConfigUtils
Change-Id: I8e35b33a3201192e940e88f96aad3b2b6685b046
2023-10-02 19:34:01 +09:00
Xiao Ma
f45ec2858a Merge "Exclude testGetNeighborsQuery from NetworkStackCoverageTests." into main 2023-09-29 05:42:16 +00:00
Xiao Ma
998f6b0eda Exclude testGetNeighborsQuery from NetworkStackCoverageTests.
sepolicy gates RTM_GETNEIGH{TBL} with a new permission nlmsg_getneigh
and block access from untrusted_apps, but NetworkStackCoverageTests
uses the same UID with NetworkStack module, so it still has the
permission to send RTM_GETNEIGH(context: u:r:network_stack:s0<00>),
which causes the test always fails. Add the same assumeFalse check
for tests with network_stack context.

Bug: 283346574
Test: atest NetworkStackCoverageTests
Change-Id: Iaf652841bb9868783c924aa22fdf0c4f07e1e391
2023-09-29 12:26:49 +09:00
Motomu Utsumi
2359e7b554 Remove defaultEnabled arg from isNetworkStackFeatureEnabled
Test: NetworkStaticLibsTests
Bug: 279108992
Change-Id: Id5409158fd720efc92e1b39678e636a8a7d5a0a5
2023-09-27 17:39:31 +09:00
Motomu Utsumi
ed4e7ec954 Update the logic of isFeatureEnabled and isFeatureNotChickenedOut
If the flag value is unset or 0, isFeatureEnabled return false and
isFeatureNotChickenedOut return true.
If the flag value is -1 (force disable), both return false.
If the flag value is other values, both query the package version and
return `flagValue <= packageVersion`

Now the only difference is a default behavior when the flag is not set
or 0.
So isFeatureEnabled and isFeatureNotChickenedOut can use the same flag.

This CL also fixes the issue in rollback.
Before this CL, isFeatureNotChickenedOut did not check the module
version and could have a issue if there is a rollback.

Test: NetworkStaticLibsTests
Bug: 279108992
Change-Id: I12d6ebadff3aee7b7c614aca4eb0a34ef0db9857
2023-09-27 17:30:01 +09:00
Maciej Żenczykowski
127a1441c3 bump min_sdk_version from 29 (Q) to 30 (R)
Mainline no longer supports Q.
These files were recently moved into p/m/C as part of a refactor.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0f06ace921db6c79d63c0048bdb73d167ff606cf
2023-09-19 23:22:58 +00:00
Motomu Utsumi
daae5ca53d Merge "Rename to isNetworkStackFeatureEnabled" into main 2023-09-08 09:27:13 +00:00
Motomu Utsumi
958ee15299 Merge "Remove unnecessary arguments from isTetheringFeatureEnabled" into main 2023-09-08 09:24:57 +00:00
Motomu Utsumi
e323c1db81 Rename to isNetworkStackFeatureEnabled
DeviceConfigUtils had isFeatureEnabled for NetworkStack and Tethering
which were confusing since the difference was only the arguments.
This CL renames isFeatureEnabled for NetworkStack module to
isNetworkStackFeatureEnabled to avoid confusion.

This CL also removes unnecessary arguments.

Bug: 279108992
Test: m
Change-Id: I523b98bd3754c209c64ce7d1513b5afcb36599b9
2023-09-05 17:50:24 +09:00
Motomu Utsumi
6a22207190 Remove unnecessary arguments from isTetheringFeatureEnabled
Test: m
Bug: 279108992
Change-Id: Iadc1b4665c364bf754ed32e7bb53b78e555ed457
2023-09-05 17:50:15 +09:00
Yuyang Huang
343683916f Merge "Add util to check if permission has system signature" into main 2023-09-05 08:45:40 +00:00
Xiao Ma
bdd723259e Merge "Add isNetworkStackFeatureNotChickenedOut API for NetworkStack module." into main 2023-08-31 03:11:01 +00:00
Junyu Lai
fefde209df Merge "Make structs in StructTest accessible from Struct" into main 2023-08-29 10:44:51 +00:00
Junyu Lai
e2eff036ed Make structs in StructTest accessible from Struct
After link Struct statically into framework-connectivity,
the structs in StructTest are no longer accessible from Struct
because Struct is loaded by bootclasspath classloader.
Make classes and members public for accessing from Struct.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest
Bug: 297836825
Change-Id: I3b1f466f10247306c84d6cac0d7402353770fac4
2023-08-29 10:33:38 +08:00
Xiao Ma
9209b00164 Add isNetworkStackFeatureNotChickenedOut API for NetworkStack module.
Bug: 279108992
Test: atest NetworkStaticLibsTests
Change-Id: If42eb401b812017bd4d724b4323a8d51f7430606
2023-08-28 17:52:04 +09:00
Yuyang Huang
82952a2228 Add util to check if permission has system signature
Bug: 294777050
Test: m
Change-Id: I66e94595ce5f4ab3b4f372e4e5e6cb06dc686c21
2023-08-24 16:48:48 +09:00
Yuyang Huang
62a016e514 Merge "Move ArpPacket.java to frameworks/libs/net" into main 2023-08-24 07:12:27 +00:00
Yuyang Huang
6acc55e129 Move ArpPacket.java to frameworks/libs/net
Bug: 281639507
Test: TH
Change-Id: Ic0d273695d3f0f85a0ec56337a9d12d77b60ea3b
2023-08-24 12:48:02 +09:00
Colin Cross
1d1c0e7282 Merge "Fix kotlin nullable errors in net-test-utils and NetworkStaticLibTests" into main 2023-08-21 19:04:15 +00:00
Motomu Utsumi
c046ac418e Rename to isTetheringFeatureEnabled
DeviceConfigUtils has isFeatureEnabled for NetworkStack and Tethering
which were confusing since the difference was only the arguments.
This CL renames isFeatureEnabled for Tethering module to
isTetheringFeatureEnabled to avoid confusion.

Bug: 279108992
Test: m
Change-Id: I16e8e4f6c0080d73533ce8bd36adfa7038347500
2023-08-17 19:00:22 +09:00
Motomu Utsumi
aad6281844 Rename to isTetheringFeatureNotChickenedOut
Expected use case of isTetheringFeatureForceDisabled was
`enabled = !isTetheringFeatureForceDisabled`, which is error prune.
So this CL renames to isTetheringFeatureNotChickenedOut and updates to
return true if the feature is not disabled.
If the feature is enabled by default and disabled by flag push (kill
switch), isTetheringFeatureNotChickenedOut should be used.

Bug: 279108992
Test: m
Change-Id: I5f85c24032bae298831bbf042874a63ea2c9b75f
2023-08-17 02:18:22 +00:00
Colin Cross
d91c89ba51 Fix kotlin nullable errors in net-test-utils and NetworkStaticLibTests
Fix kotlin nullable errors that were exposed by setting the retention
of android.annotation.NonNull and android.annotation.Nullable to
class retention.

Bug: 294110802
Test: builds
Change-Id: I2a2c91188b64619fca190a9bd7812d32f9610abd
2023-08-08 14:26:10 -07:00
Chiachang Wang
cc5c2a648a Merge "Add isFeatureSupported and isTetheringFeatureForceDisabled methods" into main 2023-08-03 06:58:28 +00:00
chiachangwang
1637730010 Add isFeatureSupported and isTetheringFeatureForceDisabled methods
Add isFeatureSupported helper method to check whether
a specific feature is supported. This is useful when a specific
module version is required on a cross module feature, e.g.
a connectivity feauture requires to work with a older
networkstack module.

This commit also adds isTetheringFeatureForceDisabled() method
as a method that refers to DeviceConfig which can be controlled
to explicitly disabled.

Bug: 291870956
Test: atest FrameworksNetTests NetworkStaticLibTests
Change-Id: I511d00663e2378c36b4ca017db4b88d88f650852
2023-08-02 13:12:14 +00:00
Remi NGUYEN VAN
fa33ba6f3d Merge "Add DomainsUtils class to encode/decode domain names." into main 2023-08-02 00:58:40 +00:00
Xiao Ma
9e9bc97317 Remove truth lib denpendency temporarily due to code coverage regression.
Bug: 291341416
Test: atest NetworkStaticLibTests
Change-Id: Id8fac2ff76dab174761fbc48d0599bcce81918ed
2023-07-27 12:12:41 +09:00
fqjc86
48693a994a Add DomainsUtils class to encode/decode domain names.
Both encode and deocde methods support message compression which is
described in RFC1035 section 4.1.4. We can leverage both methods in
a follow-up CL to parse DHCPv4 option 119 and DNSSL RA option.

This cl also adds maxLabelCount argument for DnsRecordParser#parseName
to prevent the potential recursion from overflowing the stack.

Bug: 189865016
Test: atest NetworkStaticLibTests
Change-Id: I90101ecda64bfecb0233e80ea93c91c204fbf176
2023-07-25 18:29:23 +05:30
Xiao Ma
c4789d0df4 Merge "Add DomainsUtils class to encode/decode domain names." into main 2023-07-20 09:03:24 +00:00
Xiao Ma
da97a39255 Improve testBasicWorkingGetAddrQuery by checking the specific IPv4/v6 address.
Parse the entire RTM_NEWADDR message instead of only parsing the nlmsg
header and Ifaddr header. Besides, that would be better to know which IP
address will be returned from kernel via netlink message, that's IPv4
and IPv6 loopback addresses.

Test: atest NetworkStaticLibTests
Change-Id: I3a01137db4a7774fa30ebdec5a1711697991b9fe
2023-07-12 13:32:19 +09:00
fqjc86
cece401526 Add DomainsUtils class to encode/decode domain names.
Both encode and deocde methods support message compression which is
described in RFC1035 section 4.1.4. We can leverage both methods in
a follow-up CL to parse DHCPv4 option 119 and DNSSL RA option.

This cl also adds maxLabelCount argument for DnsRecordParser#parseName
to prevent the potential recursion from overflowing the stack.

Bug: 189865016
Test: atest NetworkStaticLibTests
Change-Id: I624649c224f141848a475ac85c56012d138c5224
2023-07-11 18:04:18 +09:00
Xiao Ma
2ca9f07b99 Merge "Remove duplicated IfaddrMsg and RtgenMsg Struct used in NetlinkUtilsTests." into main 2023-07-10 04:08:55 +00:00
Xiao Ma
3ffb814525 Remove duplicated IfaddrMsg and RtgenMsg Struct used in NetlinkUtilsTests.
Bug: 263222068
Test: atest NetworkStaticLibTests
Change-Id: Iea5f91e0b20db7cd4cb4451b06e713dd68e9c387
2023-07-10 11:12:33 +09:00
Motomu Utsumi
2ba922ad85 Use default package version in isFeatureEnabled if package is not found
Bug: 287359634
Bug: 289173013
Test: atest HostsideVpnTests
Change-Id: I379cde0391f96a8ac5dcdb2ff7723ea950684e36
2023-07-07 15:57:58 +09:00
Xiao Ma
723515738d Add a method helper to create RTM_DELADDR message in user space.
Bug: 260934173
Bug: 263222068
Test: atest NetworkStaticLibTests
Change-Id: Ibddaed91b12d3f27778d0bd2171bc5be38ff8bda
2023-06-30 23:52:23 +09:00
Junyu Lai
729c65662c Merge "Parse DnsRecord by factory method" 2023-06-27 03:21:08 +00:00
Junyu Lai
cba11a2370 Parse DnsRecord by factory method
Currently, DnsPacket calls DnsRecord constructor to create
DnsRecord instances from a ByteBuffer. However, invoking
DnsRecord constructor cannot create subclass instances of
DnsRecord.

To fix this, use a factory method to parse DnsRecord. This
factory method will peek the nsType field of the DnsRecord
as an argument, and it will use this field to determine which
subclass of DnsRecord to create.

This change is no-op, because it does not change the
functionality of DnsPacket. However, it does allow subsequent
changes to create subclass instances of DnsRecord in the future.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.DnsPacketTest

Change-Id: Ibbdeaf6e5a844573f393f05609310658d8d225b3
2023-06-26 14:52:21 +08:00
Xiao Ma
34ab408ade Parse rta_cacheinfo structure in RtNetlinkRouteMessage.
Bug: 183601771
Test: atest NetworkStaticLibTests
Change-Id: I9ea55ad297f5183853eeaa2e53f2406d79a90a20
2023-06-22 10:37:39 +09:00
Hansen Kurli
8b39bca655 Merge "Use ThrowingSupplier for visibleOnHandlerThread." 2023-05-24 02:39:07 +00:00
Hansen Kurli
0cd46d480d Use ThrowingSupplier for visibleOnHandlerThread.
In order to return values from functions that are run on the handler
thread, use a ThrowingSupplier instead of a ThrowingRunnable.
Also maintain the case with ThrowingRunnable by overloading.

Test: NetworkStaticLibTests
Change-Id: Ic1b86f9f764997ce5d6848f04185194a961d1106
2023-05-23 06:17:52 +00:00
Chalard Jean
677b663aaf Correctly test for an object being of the correct type
This `as? T` instruction warns that this is an unchecked cast.
It's unchecked in the literal sense : the compiler actually
doesn't check that the var is of that type. Accordingly, this
will only fail if `it` is null, which never happens.

Concretely what that means is that Java code calling this
method like

  expect(AVAILABLE, network)

...will actually pass for *any* callback matching the network,
because the class is not checked.

Thankfully this code is recent and there doesn't seem to be a
lot of tests that got accepted by this bug when they should
have been rejected.

Test: ConnectivityServiceTest, TH
      new test in this patch that fails before but succeeds after
Change-Id: I2e48dae28ff92045f002cfb2798d383c9c19d5ed
2023-05-22 17:55:11 +09:00