Commit Graph

1238 Commits

Author SHA1 Message Date
Hungming Chen
435833f2cd Add a class to build IPv4 TCP packet
Note that IPv4 and TCP options are not supported.

Test: atest NetworkStaticLibTests

Change-Id: Ie62b95bf759b74d72a5e85d312d17978422f633b
2021-12-14 18:12:34 +08:00
Maciej Żenczykowski
98dfa5354c Merge "Move libipchecksum to frameworks/libs/net." 2021-12-14 06:52:47 +00:00
Lorenzo Colitti
0aab036101 Move libipchecksum to frameworks/libs/net.
This code is used by the DNS resolver mainline module, so it
should be in a directory that is automerged to sc-mainline-prod,
not in /system/core.

Test: m
Change-Id: I2d953afa3d2766ca2b4529e9e49151c098b466aa
2021-12-13 19:59:14 -08:00
Taras Antoshchuk
00ef48f122 Suppress NewApi warnings for @SystemApi -> public APIs
Android Lint doesn't handle API change from @SystemApi to public API
correctly (see b/193460475). We have to manually suppress those
warnings for now.

This CL suppresses warnings related to:
 - IpPrefix(InetAddress, int)
 - RouteInfo#getType

Bug: 186082280
Test: presubmit
Change-Id: Ib24b2d3fb21b86bd9e3555316a5a5bcb94434c00
2021-12-13 11:11:00 +01:00
Taras Antoshchuk
9ad8a4a6aa Suppress NewApi warnings for @SystemApi -> public APIs
Android Lint doesn't handle API change from @SystemApi to public API
correctly (see b/193460475). We have to manually suppress those
warnings for now.

This CL suppresses warnings related to:
 - IpPrefix(InetAddress, int)
 - RouteInfo#getType

Bug: 186082280
Test: presubmit
Change-Id: Ib24b2d3fb21b86bd9e3555316a5a5bcb94434c00
2021-12-13 11:11:00 +01:00
Treehugger Robot
9a560bfaa2 Merge "Return null RtNetlinkAddressMessage if IFA_FLAGS attr is malformed." 2021-12-11 09:22:29 +00:00
Bob Badour
2b71c97f99 [LSC] Add LOCAL_LICENSE_KINDS to frameworks/libs/net
Added SPDX-license-identifier-Apache-2.0 to:
  common/native/bpf_map_utils/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: I4f254c63df574bcce60aa5854107fccbb888f424
2021-12-09 13:57:00 -08:00
Nucca Chen
3c4d353df2 Merge changes I98571b8e,Icda61c12,If5062d86
* changes:
  Add StructUdpHeader class to parse UDP header from a packet
  Add StructTcpHeader class to parse TCP header from a packet
  Add StructIpv4Header class to parse IPv4 header from a packet
2021-12-09 12:53:31 +00:00
Maciej Żenczykowski
034ad460e9 Merge "[NETD-TC#7] Move getIfaceNames() and getIfaceList() to libnetdutils." 2021-12-09 11:04:38 +00:00
Treehugger Robot
c6afd1c451 Merge "Add unit test to parse UTF-8 IFLA_IFNAME attribute." 2021-12-08 18:47:23 +00:00
Treehugger Robot
876367a5b8 Merge "Add more logs in TestableNetworkStatsProvider" 2021-12-08 12:56:18 +00:00
waynema
51800daf8e [NETD-TC#7] Move getIfaceNames() and getIfaceList() to libnetdutils.
getIfaceNames() and getIfaceList() are used by Netd.

Test: m; flash; boot
Change-Id: Id95e2e7e83c07b2f420880feebdf12d4c477c958
2021-12-08 14:33:21 +08:00
Hungming Chen
9afec31417 Add StructUdpHeader class to parse UDP header from a packet
Test: atest NetworkStaticLibTests
Change-Id: I98571b8ed916b8e0da5940fe3d8d1f66b24ad93e
2021-12-07 08:19:28 +00:00
Ken Chen
38edd75a6f Merge "[NETD-BPF#30] bpf_map_utils add visibility for libnetd_mainline" 2021-12-07 05:52:57 +00:00
Ken Chen
3250a84f93 [NETD-BPF#23] Make libnetdutils apex_available for tethering module
libconn_for_netd.so in tethering module needs utilities in libnetdutils,
e.g. Status class.

Bug: 202086915
Test: m
Change-Id: Idb7f11d146570972f2467b7faa624f41bd859062
2021-12-07 03:22:07 +00:00
Ken Chen
4bce28bc2a [NETD-BPF#25] Add bpf_syscall_wrappers visibility for libnetd_mainline
retrieveProgram() in bpf_syscall_wrappers is used by libnetd_mainline.

Bug: 202086915
Test: m; flash; boot
Change-Id: I69573a6925fd9f5fcd65935d681e7a340ee73f17
2021-12-07 02:42:32 +00:00
Jean Chalard
cd49d01e7a Merge "Support multiple cleanup blocks in tryTest{}" 2021-12-07 01:27:50 +00:00
Chalard Jean
997300b9d1 Support multiple cleanup blocks in tryTest{}
This is useful for some tests that need to make sure a few
things all happen, but some of them may throw an exception.

In vanilla Java you'd say

try {
  ...
} finally {
  try {
    ...
  } finally {
    try {
      ...
    } finally {
      ...
    }
  }
}

With this patch, you can pass a list of blocks to clean.
Kotlin :

tryTest {
  ...
} cleanupStep {
  ...
} cleanupStep {
  ...
} cleanup {
  ...
}

Java :
tryAndCleanup(() -> {
  ...
  }, () -> {
  ...
  }, () -> {
  ...
  })

This keeps the semantics of tryTest{} of throwing any
exception that was thrown in tryTest{} and adding the
exception in the cleanup steps as suppressed.

Test: new tests for this
Change-Id: Ie26b802cb4893e13a70646aa0b7887701dee1ec6
2021-12-06 17:57:29 +09:00
Ken Chen
eb911f1cf1 [NETD-BPF#30] bpf_map_utils add visibility for libnetd_mainline
libnetd_mainline uses WaitForProgsLoaded() in bpf_map_utils.

Bug: 202086915
Test: m; flash; boot
Change-Id: Ia9546002b66e0ff7918c0f1145d38cbc6e28790c
2021-12-06 03:19:20 +00:00
Xiao Ma
76ce961e1f Add unit test to parse UTF-8 IFLA_IFNAME attribute.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I6e2f8c642fa1612e14b2a6b104164c9b54345053
2021-12-05 08:33:53 +00:00
Ken Chen
de0bb52562 [NETD-BPF#15] Move BPF map definition and utils to frameworks/libs/net/
1. Move BPF map definition and utilities to a common place that easy to
be referenced from both mainline module and platform code.

2. Create cc_library_headers bpf_map_utils which includes BPF map
definition and utils.

Bug: 202086915
Test: m; flash; boot
Test: cd system/netd/ && atest
Test: cd packages/modules/Connectivity && atest
Test: m gpuservice_unittest libtimeinstate_test bpf_module_test
      CtsAppOpsTestCases libbpf_load_test VtsBootconfigTest
      vts_test_binary_bpf_module bpf_benchmark libbpf_load_test
      libbpf_android_test
Change-Id: I4d54b0d69029f593b8da3099d7ae16279692dabd
2021-12-04 11:46:53 +00:00
Tyler Wear
fbbfadf393 Move TestableNetworkAgent to Common Util Location
To prep TestableNetworkAgent being accessible for multiple
tests, move to common location.

Change-Id: Ib885553550259509b4843cdbc91d2b4bbfaa5fb8
2021-12-03 10:12:00 -08:00
Maciej Żenczykowski
501a1f481f Merge "Add IFF_UP device flag constant in NetlinkConstants." 2021-12-03 18:01:50 +00:00
Alessio Balsini
9efcabc929 Allow MediaProvider to use BPF utilities
The FUSE daemon in MediaProvider needs to access the file descriptor of
its pinned BPF program.
The BPF syscall wrappers are handy and would avoid code duplication,
thus extend this project visibility to MediaProvider.

Bug: 202785178
Test: adb logcat FuseDaemon:V \*:S (in git_master)
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I406c760bb96d74597ca7d8f701cd12c3bd318f68
2021-12-03 01:54:31 +00:00
Ken Chen
eb7132442b Merge "[NETD-BPF#1] Move libnetdutils to framework/libs/net/..." 2021-12-02 12:50:07 +00:00
Xiao Ma
9adc333f21 Return null RtNetlinkAddressMessage if IFA_FLAGS attr is malformed.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I62732634d7cc31c6ca8a3ea63bb76079d8d22c14
2021-11-30 01:37:51 +00:00
Aswin Sankar
37176da85b [DnsPacketUtils] Knob for name compression support
- Allows clients of DnsRecordParser to explicitly mention
whether name compression is supported.

Test: atest NetworkStaticLibTests
Bug: b/207710965
Change-Id: Iac92f062a16f8f28f58cb180ab27e7626a9bd701
2021-11-29 18:58:48 +00:00
Xiao Ma
ab4bf15d76 Add IFF_UP device flag constant in NetlinkConstants.
Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: I81965261e8ccecd680504d3d98378973d6f44436
2021-11-29 06:58:37 +00:00
Paul Hu
d2c8b5dbf0 Merge "Add ContextUtils" 2021-11-26 06:53:23 +00:00
Hungming Chen
0b2577504f Add StructTcpHeader class to parse TCP header from a packet
Note that this class does not contain option and data fields.

Test: atest NetworkStaticLibTests
Change-Id: Icda61c129c9693e504d3f19a05242677b9dc41da
2021-11-25 21:22:00 +08:00
Hungming Chen
0dc0f8770d Add StructIpv4Header class to parse IPv4 header from a packet
Note that this class doesn't contain options field.

Test: atest NetworkStaticLibTests
Change-Id: If5062d8612e277bb283e253a0c7aa79ea9a3ce60
2021-11-25 21:22:00 +08:00
Chalard Jean
fee2cab5d6 Correct a comment
Test: TH
Change-Id: I08ac8f0f40b9e3732564da73057cd3d22c06c79b
2021-11-25 19:55:59 +09:00
Junyu Lai
bb84528e38 Add more logs in TestableNetworkStatsProvider
Test: m gts && atest \
      GtsNetworkStackHostTestCases:NetworkStatsHostTest#testNetworkStatsProvider
Bug: 175742577
Change-Id: Ib8f45a20879517af08f9bf9cbb2b16314351d2da
2021-11-25 09:47:23 +00:00
Chalard Jean
28348e43ae Have tryTest{} work with throwables
Test: NetworkStaticLibTests
Change-Id: I9ee52e7d34866c82e169bbecbca3f928bfd79993
2021-11-25 16:26:42 +09:00
Chalard Jean
2918ada958 Rename ExceptionCleanupBlock into TryExpr
This is a lot more inline with standard compiling theory

Test: NetworkStaticLibTests
Change-Id: I32c8926cb08a30b4a87bc6867ce194483a7f0c3a
2021-11-25 16:26:42 +09:00
Chalard Jean
8f0a33054b Add catch{} to tryTest{}
Usage is
tryTest {
  ...
}.catch<Exception> {
  it
} cleanup {
  ...
}

Test: New tests for this
Change-Id: Idb7d9bd33034921c8f212288179b34a175e866f4
2021-11-25 16:26:42 +09:00
Chalard Jean
b6fdf63095 tryTest to return its last evaluated expression
This is the same thing try{} does, and allows to lift
return out of tryTest.

This allows syntaxes like :
fun foo() = try {
    "Foo";
  } cleanup {
    doSomeCleanup()
  }
}

val network = try {
    registerNetworkCallback
    callback.getNetwork()
  } cleanup {
    unregisterNetworkCallback
  }
}

Note: bypassing ktlint because of b/185077240

Test: FrameworksNetTests
Change-Id: Ib8f6fde7ccfd62fdcb3c1e3b7b03909ed94d4b23
2021-11-25 16:26:42 +09:00
Treehugger Robot
fb868bf794 Merge "Disallow non-local returns in tryTest{}" 2021-11-24 10:36:59 +00:00
Treehugger Robot
27339b5e5d Merge "Make sure no suppressed expression is present when they shouldn't" 2021-11-24 10:09:40 +00:00
Treehugger Robot
8e8e260afb Merge "Replace assert with assertTrue in CleanupTest" 2021-11-24 09:55:08 +00:00
Chalard Jean
7df6f89c37 Disallow non-local returns in tryTest{}
Non-local returns will prevent the execution of the cleanup{}
block, which is too much of a footgun to allow. See the bug
for details of how it happens.

There doesn't seem to be a way to keep the nice syntax, allow
non-local returns and still guarantee execution of the cleanup
block in all cases. Thus, forbid non-local returns. Users can
still use return@tryTest to accomplish almost the same thing,
and the next patch will also let tryTest{} return its last
evaluated value, fixing remaining cases.

E.g.
tryTest {
  foo()
  if (condition) return result
  bar()
} cleanup {
  doCleanup()
}

can always be written

return tryTest {
  foo()
  if (condition) return@tryTest result
  bar()
} cleanup {
  doCleanup()
}

...and it's a rare case, so the additional syntax is acceptable.

Test: NetworkStaticLibTests
Bug: 207358921
Change-Id: I40443acf7e4d86813641adc877e27fb2334d0daf
2021-11-24 17:08:54 +09:00
Chalard Jean
bfbcacef6d Make sure no suppressed expression is present when they shouldn't
In fact the test already passes, because addSuppressed contains
an explicit test that if this === argument, then it doesn't add
it. But otherwise that's a bug in tryCleanup

Test: NetworkStaticLibTests
Change-Id: I202790bbe8d82445c5affdd9076561c2c6ea9b59
2021-11-24 17:07:28 +09:00
Chalard Jean
cf858ba920 Replace assert with assertTrue in CleanupTest
Test: NetworkStaticLibTests
Change-Id: I9b403d4d3491a5ee34b69d1fa4767defdaff70c2
2021-11-24 16:34:24 +09:00
Aswin Sankar
601d6f9c71 Spin off DnsPacket into separate library
- Packages that don't need the entire 'net-utils-framework-common'
library can depend on this lightweight library.
- This library does not depend on 'framework-annotations' which
was a problem for the mainline modularization team in allowing
other libs to depend on it.
- Spins off the DnsRecord parsing logic into its own class so that
custom DNS resolvers can re-use it.

Test: atest NetworkStaticLibTests

Bug: 193442330
Change-Id: I27d6ee4591d8ab126b7df31f0df8377794fa50f1
2021-11-24 01:45:04 +00:00
paulhu
9053e46508 Add ContextUtils
Some tests need to create a Context with assigned user and
should delegate to orignal Context. Thus, add
ContextUtils#mockContextAsUser to factorize the usage.

Bug: 170593746
Test: atest FrameworksNetTests
Change-Id: I93f64a141709e181276ed4b5195811c36100c1d0
2021-11-22 21:05:07 +08:00
Chiachang Wang
a37d20ed00 Merge "Enable strict_updatability_linting in frameworks/libs/net" 2021-11-22 02:48:24 +00:00
Ken Chen
38cf698179 [NETD-BPF#1] Move libnetdutils to framework/libs/net/...
libnetdutils is referenced by netd.c and TrafficController.cpp, which
are going to be mainlined. Therefore, move libnetdutils to a common
place where both mainline module and platform code (Netd) can refer to.

Bug: 202086915
Test: build; flash; cd system/netd; atest
No-Typo-Check: Clean code move with no other changes.
BYPASS_INCLUSIVE_LANGUAGE_REASON=Clean code move with no other changes.

Merged-In: I645bfe35f6543149c9a9f894cd4158d27a481abe
Change-Id: I645bfe35f6543149c9a9f894cd4158d27a481abe
2021-11-20 17:10:41 +08:00
Treehugger Robot
1f8da2f79a Merge "Fix libs/net tests package" 2021-11-19 15:38:36 +00:00
Remi NGUYEN VAN
0cf724af27 Fix libs/net tests package
Move test classes that were not in the same com.android.module.util
package as their associated class into the right package, and make
net-utils-service-common visible to tests.

Bug: 207020032
Test: atest ConnectivityCoverageTests
Change-Id: Iabe86a7d4c2437b3d01d68d53fb01d4e3c05a02b
2021-11-19 18:33:12 +09:00
Chiachang Wang
7068c88921 Enable strict_updatability_linting in frameworks/libs/net
Enable the strict_updatability_linting here first as a prior
commit to enable strict_updatability_linting in connectivity
modules.

Bug: 188851968
Test: m lint-check ; atest NetworkStaticLibTests
Change-Id: Idac98a1c85bf5bb86269b1daad2b444cfb58db8a
2021-11-19 15:41:27 +08:00