Commit graph android_packages_modules_Co.../service/native/TrafficControllerTest.cpp
Message SHA1
TrafficController - remove dead code
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id3a128cd72f467fa60213f57c6dd942a0629ba1d

Maciej Żenczykowski   commited 2023-08-20 18:48:48 +00:00
29c8830417
Move CookieTag map dump to BpfNetMaps
Also removes dump tests in TrafficController

Bug: 217624062
Test: atest BpfNetMaps TagSocketTest
Change-Id: I92adad60c55443435d7c7a0bfc84b38162fd51b0

Motomu Utsumi   commited 2022-10-05 18:28:13 +09:00
ef546a9bd5
Move Interface stats map dump to NetworkStatsService
Bug: 217624062
Test: dumpsys netstats, atest NetworkStatsServiceTest
Change-Id: Ie0357a79925c0bbb34aa05442f727c776f434f88

Motomu Utsumi   commited 2022-10-05 17:33:02 +09:00
809a316035
Move ownerMatch config dump to BpfNetMaps
Information in the dump does not change
....
current ownerMatch configuration: 516 DOZABLE_MATCH OEM_DENY_1_MATCH
....

Bug: 217624062
Test: dumpsys connectivity trafficcontroller, atest BpfNetMapsTest
Change-Id: I5f7b56e4ba03256414f49d0e82d65477fb97f05a

Motomu Utsumi   commited 2022-10-04 15:02:43 +09:00
372c9b45ee
Move current StatsMap dump to BpfNetMaps
Information in the dump does not change
....
current statsMap configuration: 0 SELECT_MAP_A
....

Bug: 217624062
Test: dumpsys connectivity trafficcontroller, atest BpfNetMapsTest
Change-Id: I42a844227f258b91ba5b368d8e8abf82a773a801

Motomu Utsumi   commited 2022-10-04 15:02:43 +09:00
c675d6fc01
Move uidOwnerMap dump to BpfNetMaps
Before this CL
....
mUidOwnerMap:
10050  IIF_MATCH LOCKDOWN_VPN_MATCH 0
10061  HAPPY_BOX_MATCH
10091  HAPPY_BOX_MATCH IIF_MATCH LOCKDOWN_VPN_MATCH 0
....

After this CL
....
sUidOwnerMap:
  10050 IIF_MATCH LOCKDOWN_VPN_MATCH 0
  10061 HAPPY_BOX_MATCH
  10091 HAPPY_BOX_MATCH IIF_MATCH LOCKDOWN_VPN_MATCH 0
....

Bug: 217624062
Test: dumpsys connectivity trafficcontroller, atest BpfNetMapsTest
Change-Id: I0e2358e462824273a89fcba6e19e75a233f9fe18

Motomu Utsumi   commited 2022-10-04 15:02:41 +09:00
956d86ccdf
Move uidPermissionMap dump to BpfNetMaps
Also remove the dump of mPrivilegedUser because this is not used now and
the information is duplicated with uidPermissionMap dump.

Before this CL
....
mUidPermissionMap:
10049 PERMISSION_NONE
10027  BPF_PERMISSION_INTERNET BPF_PERMISSION_UPDATE_DEVICE_STATS
1041  BPF_PERMISSION_UPDATE_DEVICE_STATS
....

After this CL
....
sUidPermissionMap:
  10049 PERMISSION_NONE
  10027 PERMISSION_INTERNET PERMISSION_UPDATE_DEVICE_STATS
  1041 PERMISSION_UPDATE_DEVICE_STATS
....

Bug: 217624062
Test: dumpsys connectivity trafficcontroller, atest BpfNetMapsTest
Change-Id: I416501d5a28a5443f954f9c8c58ea255e5cdc897

Motomu Utsumi   commited 2022-10-04 15:00:34 +09:00
310850f210
Move Interface index name map dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.

Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
     mIfaceIndexNameMap:
      ifaceIndex=5 ifaceName=ip6_vti0
      ifaceIndex=19 ifaceName=r_rmnet_data3
      ifaceIndex=17 ifaceName=r_rmnet_data1
      ifaceIndex=18 ifaceName=r_rmnet_data2
      ifaceIndex=23 ifaceName=wifi-aware0
....

$ dumpsys netstats
....
  BPF map content:
    ifaceIndex=5 ifaceName=ip6_vti0
    ifaceIndex=19 ifaceName=r_rmnet_data3
    ifaceIndex=17 ifaceName=r_rmnet_data1
    ifaceIndex=18 ifaceName=r_rmnet_data2
    ifaceIndex=8 ifaceName=rmnet_ipa0
....

Bug: 217624062
Test: dumpsys netstats, atest
com.android.server.net.BpfInterfaceMapUpdaterTest

Change-Id: If182bd97f72713b6347028668cf7bd4676b8aea4

Motomu Utsumi   commited 2022-09-12 16:53:51 +09:00
fdb601603d
Move stats map A/B dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.

Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
      mStatsMapA:
      ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
      20 wlan0 0x0 1051 0 144 2 312 4
      10 rmnet_data0 0x0 0 0 0 0 48 1
      20 wlan0 0x0 0 0 0 0 136 2
      20 wlan0 0xffffff82 1051 0 144 2 312 4

      mStatsMapB:
      ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
....

$ dumpsys netstats
....
  mStatsMapA:
    ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
    20 wlan0 0x0 1051 0 144 2 312 4
    10 rmnet_data0 0x0 0 0 0 0 48 1
    20 wlan0 0x0 0 0 0 0 136 2
    20 wlan0 0xffffff82 1051 0 144 2 312 4
  mStatsMapB:
    ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
....

Bug: 217624062
Test: dumpsys netstats, dumpstate, atest NetworkStatsServiceTest

Change-Id: Ifbd45f0ad6dd9c519a15a7680cf0ea99fb5f5dcf

Motomu Utsumi   commited 2022-09-12 16:53:48 +09:00
608c32c782
Revert mCookieTagMap dump in TrafficController
aosp/2167063 moved mCookieTagMap dump from TrafficController to
NetworkStatsService.
But this dump was used from Cts TagSocketTest.
So, this CL re-adds mCookieTagMap dump to TrafficController to avoid
failure of released Cts.
Upcoming CL will update Cts test to check dump both from
TrafficController and NetworkStatsService.
And after the old Cts support period is over, mCookieTagMap dump in
TrafficController can be removed.

Bug: 241787285
Test: atest TagSocketTest TrafficControllerTest
Change-Id: Ie2ef09fa7d91cf96f56c5efcbe9d863dd68a1020

Motomu Utsumi   commited 2022-08-10 03:51:40 +00:00
872c369ecc
Move app uid stats map dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.

Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
      mAppUidStatsMap::
      uid rxBytes rxPackets txBytes txPackets
      0 135 1 3602 47
      1001 2414 8 385 6
      1021 76 1 76 1
      1000 290 2 260 3
....
$ dumpsys netstats
....
  mAppUidStatsMap:
    uid rxBytes rxPackets txBytes txPackets
    0 135 1 3602 47
    1001 2414 8 385 6
    1021 76 1 76 1
    1000 290 2 260 3
....

Bug: 217624062
Test: dumpsys netstats, dumpstate, atest NetworkStatsServiceTest
Change-Id: I71988117c6dc3033f710b26a15d15879b35d50a4

Motomu Utsumi   commited 2022-08-02 09:41:46 +00:00
b8dd98e4d1
Move uid counter set map dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.

Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
mUidCounterSetMap:
      10093 1
      10060 1
      1073 1
      1001 1
      10089 1
....
$ dumpsys netstats
....
  mUidCounterSetMap:
    uid=10093 set=1
    uid=10090 set=1
    uid=1073 set=1
    uid=10089 set=1
    uid=1000 set=1
....

Bug: 217624062
Test: dumpsys netstats, dumpstate, atest NetworkStatsServiceTest
Change-Id: Ia70379a3cee820f3f05d1f036947b357d9da4bd7

Motomu Utsumi   commited 2022-08-02 09:41:23 +00:00
7013b92a22
Move cookie tag bpf map dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.

Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
      mCookieTagMap:
      cookie=1398 tag=0x0 uid=1029
      cookie=1433 tag=0xffffff82 uid=1051
      cookie=1166 tag=0xfffffe01 uid=1073

$ dumpsys netstats
....
  mCookieTagMap:
    cookie=1144 tag=0xfffffe01 uid=1073
    cookie=1376 tag=0x0 uid=1029
    cookie=1408 tag=0xffffff82 uid=1051

Bug: 217624062
Test: dumpsys netstats, dumpstate, atest NetworkStatsServiceTest
Change-Id: I14dd6f969a0b5eb24ace62361ce2484cf18b7470

Motomu Utsumi   commited 2022-08-02 09:41:03 +00:00
cedfab91c6
switch netd_configuration_map from hash map to array
This eliminates the need for netd_updatable BpfHandler.cpp
to initialize the hash map with a zero.

On startup the map will be freshly initialized and thus zero.

On restart it might not be empty, but it doesn't matter to netd.
Furthermore the mainline component of the system server will
re-initialize it again anyway:
see service/native/TrafficController.cpp initMaps()

This does remove the ability to call deleteValue on a key,
since that would always return -EINVAL, but since we don't
currently do that, that's really a feature.

(It does suggest though that we should have a BpfMapNonNullable
 class which is writeable, but without a deleteValue() function)

Additionally BpfMap arrays are more efficient for the kernel bpf jit
compiler, as - on newer kernels - it can optimize the read/write
into a simple memory access (as opposed to a bpf helper call).

Before:
  $ adb shell ls -l /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:20 /sys/fs/bpf/netd_shared/ map_netd_configuration_map

After:
  $ adbz shell ls -l /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -r--rw---- 1 root net_bw_acct 0 2022-06-16 15:03 /sys/fs/bpf/netd_shared/map_netd_configuration_map

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

Maciej Żenczykowski   commited 2022-06-16 22:53:42 +00:00
b10e055f4b
Merge changes Ic6ff7a3d,Iff9b9792
* changes:
  Refactor code and improve tests for VPN filtering
  Remove LOCKDOWN from FirewallChain IntDef

Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-06-16 01:32:20 +00:00
5d787feef0
Merge changes from topic "bpfmap1"
* changes:
  netd.c - reduce privs on maps
  BpfHandler.h - switch mStatsMapB from BpfMap to BpfMapRO
  BpfNetworkStatsTest - cleanup
  TEST_BPF_MAP -> BPF_MAP_MAKE_VISIBLE_FOR_TESTING
  BpfHandlerTest - minor fixups
  TrafficController - minor cleanup

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-06-14 06:18:46 +00:00
8f03c4495e
TEST_BPF_MAP -> BPF_MAP_MAKE_VISIBLE_FOR_TESTING
Per request of Lorenzo on:
  https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/libs/net/+/18694820
  https://googleplex-android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/18695355

Although he'd suggested 'BPF_MAP_TEST_ONLY',
but I think this is even clearer.

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

Maciej Żenczykowski   commited 2022-06-13 19:39:06 -07:00
01319d931a
Cleanup dead code in TrafficControllerTest
Test: atest TrafficControllerTest
Change-Id: I26c61b120ef773144562b7d72a3cf2230d5aff7a

Wayne Ma   commited 2022-06-13 17:05:25 +08:00
6e0b747c7b
Remove LOCKDOWN from FirewallChain IntDef
LOCKDOWN_VPN was in the FirewallChain IntDef but this was not a right
place because LOCKDOWN_VPN was not a valid value for Connectivity APIs
that take an argument annotated with @FirewallChain(setUidFirewallRule,
setFirewallChainEnabled, replaceFirewallChain).

LOCKDOWN_VPN was in the FirewallChain IntDef because
BpfNetMaps#setUidRule was used to add/remove LOCKDOWN_VPN entries.
This commit adds BpfNetMaps#updateUidLockdownRule and uses this to
add/remove LOCKDOWN_VPN entries instead of BpfNetMaps#setUidRule and
removes LOCKDOWN from FirewallChain.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest
PermissionMonitorTest HostsideVpnTests#testBlockIncomingPacket

Change-Id: Iff9b9792fc0f208f153e10e396c6d5034b412d7c

Motomu Utsumi   commited 2022-06-10 02:49:25 +00:00
8b42e6d431
TrafficControllerTest: improve error declaration in dumpsysInvalidMaps
Test: atest TrafficControllerTest
Change-Id: Id2b2e8edefed615ccb3e94667bc91bc03e14ad81

Hungming Chen   authored and   Nucca Chen   commited 2022-06-09 05:38:37 +00:00
56b9013bcb
TrafficControllerTest: add test dumpsysInvalidMaps
dump function has no enough code coverage for error handling.
Add a simple unit test so that code lines can be executed and counted.

Test: atest TrafficControllerTest
Change-Id: I65a322cc93d559896f0b481ca849b39315432df3

Hungming Chen   commited 2022-06-09 01:37:01 +08:00
410bb12d5f
Add unit test for uidMatchTypeToString function
uidMatchTypeToString function has no enough line coverage currently.
Add a simple unit test so that code lines can be executed and counted.

NO_MATCH(0) can't be verified because match type flag is added by OR
operator. See TrafficController::addRule.

Bug: N/A
Test: atest
Change-Id: I6178d4a8cc21430882fae3c1f53f7bc1cebb6c01

Hungming Chen   authored and   Nucca Chen   commited 2022-06-08 04:04:49 +00:00
1d4d3d2695
Add OEM_DENY_3 in getFirewallType test
Bug: N/A
Change-Id: Ia53f607f69ccaf79223d0a089ced56f2f39f016a
Test: treehugger

Ken Chen   commited 2022-06-08 02:54:13 +00:00
d3a3af5c34
Merge "Add 3rd deny firewall chain for OEM"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-06-07 05:34:31 +00:00
1259ebcb59
Extend unit test for dump function
Add more values in different maps to cover more code lines in dump
function.

The original test code is also modified to have one entry per map.
Because the entries are hashed in the map. The order of each entry is
not a fixed order.

Bug: N/A
Test: atest
Change-Id: Ie21016768309e8501a127cb3da02211d21b06c2c

Ken Chen   commited 2022-06-06 23:55:28 +08:00
0dd7495a08
Add 3rd deny firewall chain for OEM
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
ConnectivityServiceTest

Change-Id: Ib521fa02f6a19270cb88a3d85321bda822516c78

Motomu Utsumi   commited 2022-06-06 07:47:35 +00:00
1d9054ba5f
Add unit test for getFirewallType
Add the test to increase code line coverage.

Bug: N/A
Test: atest
Change-Id: Ic469da984dd5879acb229d1a147a670b1787e996

Ken Chen   commited 2022-06-06 15:42:18 +08:00
77a6b71989
Add unit test for dump function
Dump function has no code line coverage currently. Add a simple unit
test so that code lines can be executed and counted.

Bug: N/A
Test: atest
Change-Id: I6362a679d11c26be66ab49216666f0f8c6f2c4f0

Ken Chen   commited 2022-06-06 15:42:10 +08:00
2fb8636268
Add deny firewall chain for OEM
Bug: 207773349
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
--iterations 50 && atest ConnectivityServiceTest --iterations 10

Change-Id: I60d5540821abcced03356f366775f16ee369d7f9

Motomu Utsumi   commited 2022-06-03 09:10:57 +00:00
d980149817
Merge "tests: simplify BpfMap.reset(createMap()) -> BpfMap.resetMap()"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-06-01 09:00:46 +00:00
69777762e7
Merge changes I25158126,I99fcf77b
* changes:
  TrafficControllerTest - trivial simplification
  simplify bpf tests and check type correctness

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2022-06-01 08:59:19 +00:00
d9b378eeef
tests: simplify BpfMap.reset(createMap()) -> BpfMap.resetMap()
BpfMap.reset(createMap()) is equivalent to newly added BpfMap.resetMap(),
except that the latter makes it impossible to screw up the Key/Value sizes.

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

Maciej Żenczykowski   commited 2022-05-31 07:35:04 -07:00
439bac2e56
TrafficControllerTest - trivial simplification
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I25158126c968707f44f595f731547a8bd9bb503d

Maciej Żenczykowski   commited 2022-05-31 07:35:04 -07:00
ced3531ad5
simplify bpf tests and check type correctness
We notice that:
  BpfMap.reset(dupFd_with_cloexec(BpfMap.getMap())
is equivalent to
  BpfMap = BpfMap
due to the current implementation of the BpfMap assignment operator.

Except the latter also verifies BpfMap<K,V> template types match.

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

Maciej Żenczykowski   commited 2022-05-31 07:35:03 -07:00
55ab87aa49
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

Lorenzo Colitti   authored and   Maciej Żenczykowski   commited 2022-05-31 09:59:11 +00:00
60cbed385d
remove spurious newlines on ALOG lines
(for consistency with rest of code base)

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

Maciej Żenczykowski   commited 2022-05-23 20:53:12 +00:00
e0f5846897
Block incoming packets in VPN Lockdown mode.
Currently, even when VPN Lockdown mode is enabled, incoming packets are
not dropped if VPN is not connected.

This commit fixed this issue.
After this commit, If VPN Lockdown mode is enabled, incoming packets
are dropped regardless of the VPN connectivity.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest PermissionMonitorTest
Change-Id: If52ece613c8aac1073355e43b6fb9cb3fcc87d1d

Motomu Utsumi   commited 2022-05-16 10:40:59 +00:00
b08654ca04
Remove unused BpfNetMap jni function
native_deleteTagData and native_setCounterSet is replaced as BpfMap java
implementation inside NetworkStatsService.java

Test: atest traffic_controller_unit_test
Change-Id: Ic33ca9d9887380d39becbd0dc3a0e159b3dc82a2

markchien   authored and   Mark Chien   commited 2022-02-11 08:04:55 +00:00
4dd5be6606
Add Low Power Standby support to TrafficController
Bug: 190822356
Test: atest TrafficControllerTest
Change-Id: I84a95081ab6e6a86543fe2cddf0efdab16c90d72

Robert Horvath   commited 2022-02-02 22:54:21 +01:00
d945bf0b4f
Move netlink_listener_test into TrafficControllerTest
netlink_listener_test tests the socket destroy listener, so it makes
sense to just merge it into the TrafficControllerTest.

Test: atest traffic_controller_unit_test
Change-Id: Ibc0b483203150aa2d7898a761fa4715dce6f4218

Patrick Rohr   commited 2022-02-01 21:13:30 +01:00
61e9467fa6
[NETD-TC#13] Make TrafficControllerTest as traffic_controller_unit_test
Delete tagSocket(), privilegedTagSocket() and untagSocket() revelant
test cases since thay are moved out of TrafficController in
aosp/1849156.

Bug: 202086915
Test: atest traffic_controller_unit_test passed
Change-Id: I605577ee4d7076f0c8ad75888a4d32bff90f6104

Wayne Ma   commited 2022-01-23 21:26:09 +08:00
7be6bce52d
Delete dead codes within TrafficController in mainline module
Delete tagSocket(), privilegedTagSocket() and untagSocket() since
they are moved out of TrafficController in aosp/1849156.

Test: m
Change-Id: I6162c758446f597eb79734e00348dc8b1fe2d422

Wayne Ma   commited 2022-01-21 15:45:09 +00:00
92d80790d3
Move TrafficController relevant files from netd to mainline module
git diff packages/modules/Connectivity/service/native/TrafficController.cpp system/netd/server/TrafficController.cpp
git diff packages/modules/Connectivity/service/native/TrafficControllerTest.cpp system/netd/server/TrafficControllerTest.cpp
git diff packages/modules/Connectivity/service/native/include/TrafficController.h system/netd/server/TrafficController.h

Test: m
No-Typo-Check: clean move
BYPASS_INCLUSIVE_LANGUAGE_REASON= clean move
Change-Id: I7c0200e28e5e4459477d370912277fa1281b786b

Wayne Ma   commited 2022-01-21 15:37:34 +00:00
4d69233e63