Commit Graph

21 Commits

Author SHA1 Message Date
Treehugger Robot
8154deb5d6 Merge "remove unused combineUidTag()" 2023-02-07 17:43:17 +00:00
Maciej Żenczykowski
6d8a257be7 NetworkTraceHandlerTest - skip on non-64-bit builds
Bug: 268138838
Test: TreeHugger, atest NetworkTraceHandlerTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I379bde927a250d239da74dd9db0dc0aeb1f56d8f
2023-02-07 06:08:28 +00:00
Maciej Żenczykowski
7c80e7799f remove unused combineUidTag()
improves coverage...

(see also cs/ p:android$ combineUidTag showing this 1 hit)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I85524032b045bdad78876239c968a3008217ed67
2023-02-07 04:19:56 +00:00
Ryan Zuklie
5a2cc8f2cb Reduce binary size by excluding perfetto consumer
The network trace handler only produces, never consumes Perfetto events.
By cutting out the consumer code, we can reduce the binary size by
~280KB.

Bug: 246985031
Test: build and flash
Change-Id: Ie03129630cc425e1759770ef3f3d3391e78331d7
2023-01-31 17:29:30 -08:00
Ryan Zuklie
1b71b7f70b Register network tracing in system_server after boot
This runs the Perfetto and NetworkTraceHandler initialization on system
initialization along with the existing NetworkStatsService. The code is
run within the context of the system_server and is only executed on U or
later devices running eng or userdebug builds.

Bug: 246985031
Test: build & flash
Change-Id: I2b091e31c3ded54c0d7062d7d73f33ed47e0bf98
2023-01-24 06:52:09 -08:00
Ryan Zuklie
a603ce5b8e Add Perfetto part of NetworkTraceHandler
This adds the DataSource base class, data source registration and
overrides the lifecycle methods.

Adding the Perfetto SDK increases the size of the tethering apex by
450kb (~150 KB for the compressed apex).

Bug: 246985031
Test: atest libnetworkstats_test
Change-Id: Ie2e8f3e43c8080434408f752346e575a19e9042e
2023-01-24 06:49:11 -08:00
Ryan Zuklie
0b9478b53b Add NetworkTraceHandler with Start/Stop/ConsumeAll
This adds the base (non-perfetto) NetworkTraceHandler with support for
starting and stopping tracing, and pulling messages from BPF. The
included test covers the end-to-end scenario from socket creation,
socket tagging and data traffic.

Bug: 246985031
Test: atest --iterations 500 libnetworkstats_test
Change-Id: I035d2e03fa7c461ecb93d207b7fd2f53e6a2f52e
2023-01-23 13:35:24 -08:00
Maciej Żenczykowski
513474c1a7 rename bpf_shared.h to netd.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2e1569c8d70e98f9a3fdbab41fd2ba7f7b84dd37
2022-12-18 20:02:52 +00:00
Maciej Żenczykowski
9796860b25 remove only use of OVERFLOW_COUNTERSET
See:
  https://source.corp.google.com/search?q=p:android$%20OVERFLOW_COUNTERSET

(I'm guessing any remaining uses are in Java not C/C++?)

I'd like to remove the definition from the
  frameworks/libs/net/common/native/bpf_headers/include/bpf/BpfUtils.h
header file, where it really doesn't fit.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I687f4ca0f52c362b29be7fe612f90d8aed2afe9e
2022-12-14 09:15:30 +00:00
Maciej Żenczykowski
1453f129ea BpfNetworkStats - use static BpfMap objects for stats maps A & B
This might eliminate a failure mode with dreaded 524 error
from the kernel... or it might not, but it shouldn't hurt.

Bug: 230418056
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If2479daf77f61c220214ff507582295bd303fd21
2022-08-31 01:40:00 +00:00
Maciej Żenczykowski
9d39969c80 BpfNetworkStats - remove spurious code & use static maps
frameworks/libs/net/common/native/bpf_headers/include/bpf/BpfMap.h
(which is a mainline automerged path)

already aborts() on failure in the path taking constructor
(by calling abortOnKeyOrValueSizeMismatch), and as such
checking for isValid afterwards is pointless.

Also, there's no reason to waste cpu cycles opening and closing these maps, and creating and destroying the map objects.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icb5567ee32ca9a00fd8aeb565066716d350f1292
2022-06-24 17:41:49 +00:00
Maciej Żenczykowski
ffffa35ee8 BpfNetworkStatsTest - cleanup
We note that:
  0 <= BpfMap<K,V>.getMap()
is equivalent to
  BpfMap<K,V>.isValid()

but the latter is far more kosher.

Unfortunately there is more non-kosher stuff happening in this
file, so we still need to define BPF_MAP_MAKE_VISIBLE_FOR_TESTING anyway.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I138709c6a298a2d8511b525a8349e01ab87d9455
2022-06-13 19:39:06 -07:00
Lorenzo Colitti
60cbed385d Support more than 8 firewall chains / match types.
In the BPF code, per-UID network access (e.g., for doze mode,
standby, etc.) is stored in UidOwnerValue structures. Each of
these stores that UID's rules in a 32-bit bitmask of
UidOwnerMatchType values, so the code can support ~31 match
types.

However, which match types are enabled is stored in
configuration_map at index UID_RULES_CONFIGURATION_KEY, and
configuration_map only stores 8-bit values. So it's not
possible to define more than 7 match types.

Widen configuration_map to from 8 to 32 bits to match the width
of UidOwnerValue.rule. This doesn't impact memory because
configuration_map only has 2 entries.

Bug: 208371987
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7e1eee2daedd66d27965a2dd4ce6b4c3667892f7
2022-05-31 09:59:11 +00:00
Ken Chen
93ea4c3f5c Merge "Add traffic_controller, networkstats, netd_updatable tests to MTS." 2022-05-27 17:46:54 +00:00
Ken Chen
b9266bf507 Add traffic_controller, networkstats, netd_updatable tests to MTS.
In order to get counted by mts code coverage, these native tests need to
be run as part of mts.

Bug: 233904825
Test: m mts && mts-tradefed run mts-tethering-coverage
Change-Id: I79313197b146c7043ffb5e164faa46c2e16dd1d2
2022-05-27 15:00:18 +00:00
Ken Chen
322ffcb724 [NetworkStats] Return error on invalid value
Configuration map index 1(CURRENT_STATS_MAP_CONFIGURATION_KEY) can only
have value 0(SELECT_MAP_A) or 1(SELECT_MAP_B). Return error if it is any
other values. Otherwise, read out of array boundary can cause memory
corruption or security issues.

Bug: 231420457
Test: TH
Change-Id: Ia800ad78781f72b8118469c0230cc550796d334e
2022-05-23 22:27:40 +08:00
Remi NGUYEN VAN
d95048929c Add JNI stats libraries to connectivity
Add new symbols to libservice-connectivity loaded on T only, and the
framework libraries to apex and tests.

Bug: 197717846
Test: atest FrameworksNetTests
  (cherry-picked and splitting apex Android.bp to aosp/1994130)
Change-Id: Iae44344701a3267110e5cbf271120201134d59e5
Merged-In: Iae44344701a3267110e5cbf271120201134d59e5
2022-02-28 04:16:17 +00:00
Lorenzo Colitti
0db496ef39 Fix libnetworkstats_test.
If libraries are moved from the platform to a module, the test
will fail with:

CANNOT LINK EXECUTABLE "/data/local/tmp/libnetworkstats_test/arm64/libnetworkstats_test": library "libnetworkstats.so" not found: needed by main executable

This may be because it can't find libnetworkstats.so because that
is in platform.

In any case, since this is the test for libnetworkstats,
dynamically linking libnetworkstats is incorrect, because it
means if the same CL modifies both libnetworkstats and its test,
that CL will run the modified test against the unmodified
libnetworkstats.so on the device, when running updating tests
without reflashing the device.

Also remove libutils because it does not seem to be needed.

Test: atest libnetworkstats_test passes with libraries moved
Change-Id: Id49641c0a919129e2c54531c3995ec7421161002
2022-02-07 02:16:34 +00:00
Ken Chen
cc764a13fa Correct typos in libnetworkstats
Fix Typo-Lints in I23aad26d487b4d99e24ffecf79eeef3f8eea664b

Bug: N/A
Test: m
Change-Id: Id9df0a279e7aad048f2c0d7be66dec40e5a8ae8a
2022-01-24 11:54:04 +08:00
Ken Chen
f426b2b287 Rename libnetdbpf to libnetworkstats
Two reason for renaming:
1. Avoid module name collision in sc-mainline-prod branch.
2. The libnetdbpf was misnamed before.

Bug: 202086915
Test: atest libnetworkstats_test FrameworksNetTests
      ConnectivityCoverageTests FrameworksNetSmokeTests
      CtsAppOpsTestCases
Change-Id: I87fcf4b1a9d58780a45743a9aa91b9b936e54266
2022-01-24 11:53:59 +08:00
Ken Chen
f2bb7b1ae8 Copy libnetdbpf from system/net to tethering module
This is a clean copy (that can't build). Modifications will be in
followed commits.

Bug: 202086915
Test: $ diff -r
      packages/modules/Connectivity/service-t/native/libs/libnetdbpf/
      system/netd/libnetdbpf/
      (no different)
No-Typo-Check: Clean move
Change-Id: I23aad26d487b4d99e24ffecf79eeef3f8eea664b
2022-01-24 06:14:38 +08:00