Commit Graph

1215 Commits

Author SHA1 Message Date
chiachangwang
9835a4eae0 Add resolvePkgPrefix() method
This is a no-op refactor change to create resolvePkgPrefix()
helper method to prevent code duplication for the follow up
commit.

Bug: 291870956
Test: atest NetworkStaticLibTests
Change-Id: I8deea97acdb793dfa076ce55f7f2c3eb0b224461
2023-07-31 14:01:24 +00:00
Junyu Lai
3416eae310 Merge "Make SkipPresubmit annotation visible by HostsideVpnTests" into main 2023-07-28 02:06:17 +00:00
Patrick Rohr
ea6b69dcec Merge "Remove truth lib denpendency temporarily due to code coverage regression." into main 2023-07-27 16:27:00 +00:00
Xiao Ma
80dbd06f64 Add Ipv6PktInfo (in6_pktinfo) struct.
in6_pktinfo structure specifies the source IPv6 address and interface
for an outgoing packet(used with UDP or RAW socket), we can specify the
IPV6_PKTINFO ancillary data on sendmsg() with this structure to set the
source address (e.g. a global IPv6 address).

Bug: 293393743
Test: TH
Change-Id: I2bd8ea6fcdb7398db9b3a54243c81ca27e832e45
2023-07-27 15:17:24 +09: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
Remi NGUYEN VAN
7035b4418d Merge "Add an annotation for @SkipMainlinePresubmit" into main 2023-07-27 02:13:22 +00:00
Junyu Lai
af464eb494 Make SkipPresubmit annotation visible by HostsideVpnTests
Test: TH
Bug: 291701394
Change-Id: I93d72a809b2779deec3c8182c5efed6d38393ab8
2023-07-26 14:42:56 +08:00
Remi NGUYEN VAN
5e4900dbbe Add an annotation for @SkipMainlinePresubmit
This will typically be used in mainline-presubmit TEST_MAPPING
configuration to exclude some tests.

This is necessary as some tests are flaky in mainline configurations
(when running on older devices), and they need to be disabled to meet
SLO requirements, but they are not flaky on presubmit using the latest
platform builds.

Test: m
Change-Id: Ia532d6d3f9833ddec613d79c0eb517d20a1c529a
2023-07-26 13:37:47 +09:00
Mike Yu
4838904eb3 Merge "Add DnsResolverModuleTest annotation" into main 2023-07-26 03:17:09 +00: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
Maciej Żenczykowski
54044cf4c9 Merge "BpfClassic - add three more macros" into main 2023-07-24 19:08:57 +00:00
Xiao Ma
72b0cd986a Add RouteInformation option Struct.
This structure is useful when building an RA with RIO for integration
tests and verify the device's provisioning behavior, for example, check
if devices in ULA networks can recover its IPv6 connectivity from
receiving a normal RA after losing IPv6 default route (e.g. received RA
with zero router lifetime).

Bug: 183601771
Test: m
Change-Id: I13b85000ea1633f56edc74e3d62b7a38b9a851bf
2023-07-24 12:51:01 +09:00
Maciej Żenczykowski
2cd8b69005 BpfClassic - add three more macros
Example use case:
  BPF_LOAD_SKB_PROTOCOL,
  BPF2_ACCEPT_IF_EQUAL(ETH_P_ARP),
  BPF2_REJECT_IF_NOT_EQUAL(ETH_P_IP),
  BPF_LOAD_IPV4_BE16(frag_off),
  BPF2_REJECT_IF_ANY_BITS_SET(IP_MF | IP_OFFMASK),
  BPF_ACCEPT,
which is a sample program which accepts ARP plus non-fragmented IPv4.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe6f9f7941f11bc7b767a092d3d108fa0291f360
2023-07-22 14:32:47 +00:00
Maciej Żenczykowski
28a8600dc0 Merge "Move ticksToMilliSeconds to NetlinkUtils." into main 2023-07-20 12:02:48 +00:00
Xiao Ma
c4789d0df4 Merge "Add DomainsUtils class to encode/decode domain names." into main 2023-07-20 09:03:24 +00:00
Xiao Ma
a56b949726 Move ticksToMilliSeconds to NetlinkUtils.
ticksToMilliSeconds is used to convert the clock ticks to milliseconds,
move it to a common utils class, we can call this method to convert the
rta_cacheinfo.rta_expires in user space as well to get when the default
route will expire.

Bug: 183601771
Test: atest NetworkStaticLibTests
Change-Id: Iabd510fe290f835a8fe690d91921d5b706a23b56
2023-07-20 16:54:46 +09: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
Xiao Ma
3a4ad37d61 Remove StructIfaddrMsg ctor VisibleForTesting annotation.
This allows other class to refer StructIfaddrMsg constructor as well,
otherwise, the default visibility is private.

Bug: 263222068
Test: atest NetworkStaticLibTests
Change-Id: If571b014ade51e3387748a4df0abcb49b59cb462
2023-06-30 23:48:27 +09:00
Junyu Lai
729c65662c Merge "Parse DnsRecord by factory method" 2023-06-27 03:21:08 +00:00
Mike Yu
8f4debc3f9 Add DnsResolverModuleTest annotation
This annotation can be used to mark a test case that requires
the latest resolv module. Tests that don't run with the latest
resolv module (for example CtsNetTestCasesLatestSdk) can exclude
the testcases being flaky due to some known issues in old resolv
module.

Bug: 279846955
Test: TreeHugger
Change-Id: Ie19eed1c4aa17645c4eec45493e7999027a01205
2023-06-26 07:40:18 +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
Lorenzo Colitti
4bf0632086 Merge "Add a dumpService variant that uses libbinder_ndk." 2023-06-23 03:54:37 +00:00
Lorenzo Colitti
49e4a98f78 Add a dumpService variant that uses libbinder_ndk.
The one in this file requires libbinder and cannot be used when
libbinder is not present (e.g., when compiling against the NDK).
This allows users of this code not to link against libbinder, and
have the resulting binary not depend on it:

$ m CtsNativeNetPlatformTestCases netd_integration_test
$ objdump -p out/target/product/vsoc_x86_64/testcases/netd_integration_test/x86_64/netd_integration_test64 | grep NEEDED | grep libbinder
  NEEDED               libbinder.so
  NEEDED               libbinder_ndk.so
$ objdump -p out/target/product/vsoc_x86_64/testcases/CtsNativeNetPlatformTestCases/x86_64/CtsNativeNetPlatformTestCases64 | grep NEEDED | grep libbinder
  NEEDED               libbinder_ndk.so
$

Bug: 268440865
Test: see other CL in topic
Merged-In: Icf982675aad4777677a36e357035809fb251d6e9
Change-Id: Icf982675aad4777677a36e357035809fb251d6e9
2023-06-22 19:14:10 +09:00
Chalard Jean
9302d7d7c3 Add constants for clat and v6 fragmentation
Test: manual
Change-Id: Ic18186c1a09c2bb79e7727c70d2d46d511a23075
2023-06-22 17:39:08 +09:00
Xiao Ma
e5e306cd49 Merge "Parse rta_cacheinfo structure in RtNetlinkRouteMessage." 2023-06-22 05:40:53 +00:00
Xiao Ma
b2f61ab77c Merge "Add netlink rta_cacheinfo structure." 2023-06-22 05:39:30 +00: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
Xiao Ma
4cb10fdc28 Add netlink rta_cacheinfo structure.
Bug: 183601771
Test: m
Change-Id: Iaa65425fa875a9dde4d4b7c1b110d9a2a406f444
2023-06-22 10:37:27 +09:00
Maciej Żenczykowski
f1416b5494 enforce bpf ring buffer size is a power of two
While at it enforce a min/max of 4 kiB and 256 MiB.

A bpf ringbuffer must be an integer multiple of page size
(which is at least 4kiB), so 4kB is forced.

256 MiB upper limit is probably higher than it should be,
but it's really only here to avoid the u32/s32 conversion
mess that happens for 2+ GiB.

Test: TreeHugger
Bug: 279819914
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2216d2273b0956a86c4222dd6ecf7293e0bafd41
2023-06-17 11:26:21 +00:00
Maciej Żenczykowski
1e1d7106bc Merge "add macro to disable BTF on user builds" 2023-06-16 02:37:14 +00:00
Maciej Żenczykowski
c6e4122db8 add createOuterMap()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icf49cc98daa339b0320b5c18cd055b8a53dcba6c
2023-06-14 09:14:19 +00:00
Maciej Żenczykowski
008f51e585 implement 'int bpfGetFdProgId(const BPF_FD_TYPE prog_fd)'
which fetches the internal kernel identifier of an ebpf program

side note: Linux in include/uapi/linux/bpf.h declares:
  4.14: struct bpf_map_info
  4.14: struct bpf_prog_info
  4.19: struct bpf_btf_info
  5.4: struct bpf_func_info
  5.4: struct bpf_line_info
  5.10: struct bpf_link_info
  5.10: struct bpf_pidns_info

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b2fe1a67bdefff521e41b3ff4ef37d29fc90fae
2023-06-14 09:13:09 +00:00
Maciej Żenczykowski
be02054c79 convert ptr_to_u64() macro to an inline function
This allows it to be used from outside this header file,
and provides slightly more type safety.

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I98e5e37a002188813b602e51fd4fcbb9ca4466cc
2023-06-14 02:15:07 +00:00
Treehugger Robot
111f341596 Merge "Make IaPrefixOption constructor public." 2023-06-09 07:00:11 +00:00
Maciej Żenczykowski
8837bf21a5 add macro to disable BTF on user builds
Bug: 286369326
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6a705ae99a12fb8464730dab1119f4ce2ef3f974
2023-06-09 06:06:36 +00:00
Xiao Ma
789baf20d3 Make IaPrefixOption constructor public.
Then we can create an IaPrefixOption instance via constructor in the
NetworkStackIntegration test.

Bug: 260934173
Test: atest NetworkStackIntegrationTests
Change-Id: I05be1dde6ba5bda125631674c5c0f8634eb18924
2023-06-09 11:38:11 +09:00
Maciej Żenczykowski
5bec8b44a9 force map key/value sizes < 1024/65536 bytes to match BpfMap.java
Test: TreeHugger
Bug: 286154283
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I31fb48aa032e22a83e3e9f0ac8d7f2b3253e995e
2023-06-07 06:59:40 +00:00
Xiao Ma
267467ec93 Merge "Add NetworkStackModuleTest annotation." 2023-06-05 01:45:01 +00:00
Treehugger Robot
cae8499e3d Merge "Add a helper function to send RTM_NEWADDR netlink message to kernel." 2023-06-01 08:52:02 +00:00
Mike Yu
eb1fe093ad Merge "Change DnsPacket.DnsRecord.MAXNAMESIZE to public" 2023-06-01 05:45:39 +00:00
Junyu Lai
14a8c7d913 Merge "Fix crash when socket read is interrupted" 2023-06-01 05:39:33 +00:00
Xiao Ma
cff263aa10 Add NetworkStackModuleTest annotation.
This annotation can be used to exclude the testcases which requires the
latest NetworkStack module in the CTS/MTS suite.

Bug: 283200648
Test: atest CtsTetheringTestLatestSdk
Change-Id: Idaffed93af077c2998081142af7b3bfa311dcd90
2023-06-01 13:34:01 +09:00
Xiao Ma
a6fba08f82 Add a helper function to send RTM_NEWADDR netlink message to kernel.
Bug: 260934173
Test: TH
Change-Id: I6e9100e6f04a85550790c90fb0fde8d839e74578
2023-06-01 11:02:05 +09:00
Junyu Lai
ab3fee4246 Fix crash when socket read is interrupted
The exception is thrown in some normal cases e.g. interrupt()
called when Os.read is blocked and waiting for the input.
Ignore such events.

Test: 1. atest NetworkStackCoverageMtsConfigTests on S device
      2. atest com.android.cts.net.HostsideVpnTests
      3. atest NetworkStatsIntegrationTest
Bug: 259632210
Change-Id: Ibff41312d9c7431c2b19f780844ab3a81b48f9e8
2023-05-31 14:14:01 +08:00
Mike Yu
4734d678a5 Change DnsPacket.DnsRecord.MAXNAMESIZE to public
Change this constant to public so that the implementation of other
type of DNS record, such as SVCB record, can reuse this constant
instead of defining a duplicate one.

Bug: 240259333
Test: TreeHugger
Change-Id: Ic5c6ecfba4d16f19adb3794dd50c5fc876d9f82a
2023-05-31 05:27:26 +00:00