Commit graph android_packages_modules_Co.../service/src/com/android/server/BpfNetMaps.java
Message SHA1
Rename BpfNetMapsReader to NetworkStackBpfNetMaps
BpfNetMapsReader is loaded to bootclasspath. So this class should not
contain unnecessary codes.
To make this clear, this CL renames to NetowrkStackBpfNetMaps and add
comments

Bug: 328732146
Test: TH
Change-Id: I557627c9fae087eb6119c2ae31d46526fa9e5d7e

Motomu Utsumi   commited 2024-03-19 04:12:29 +00:00
fc504042f6
Bpf: open code PRE_T - too complex for errorprone linter
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1ad2d0dd288882e84925f0b59961dcd33612f3f7

Maciej Żenczykowski   commited 2024-01-25 16:09:11 -08:00
0d450d3e4d
BpfNetMaps - add RequiresApi(T) annotations
netd.o bpf program was mainlined in T

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

Maciej Żenczykowski   commited 2024-01-25 15:15:26 -08:00
6b9d921f1c
BpfMap - add R/W constructor alias
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7cef2b19f55e6e056b46bb1b28f85c7f7376f6f4

Maciej Żenczykowski   commited 2024-01-23 16:16:44 -08:00
06155c8040
switch SynchronizeKernelRCU back to jni - but from BpfMap
we can't use java for this, because pre-U-QPR2 does not include:
  https://android-review.googlesource.com/c/platform/system/sepolicy/+/2821590
  system_server dontaudit key_socket getopt

so we'll spew lots of:
  11-08 07:52:43.776 1469 1469 I auditd : type=1400 audit(0.0:4): avc: denied { getopt } for comm="system_server" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
  11-08 07:52:44.360 1469 1469 I auditd : type=1400 audit(0.0:5): avc: denied { getopt } for comm="NetworkStats" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
  11-08 07:52:44.508 1469 1469 I auditd : type=1400 audit(0.0:7): avc: denied { getopt } for comm="android.bg" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
and the like.

This is due to Java's Os.close() in:
  libcore/luni/src/main/java/libcore/io/BlockGuardOs.java;l=100
calling:
  if (fd.isSocket$()) if (isLingerSocket(fd)) ...

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

Maciej Żenczykowski   commited 2023-11-09 11:08:58 +00:00
c350db788a
Merge "remove BPF_NET_MAPS_FORCE_DISABLE_JAVA_BPF_MAP" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-11-09 04:31:05 +00:00
49c88a1d44
remove BPF_NET_MAPS_FORCE_DISABLE_JAVA_BPF_MAP
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I550357be83f946bf9f29b9f90037d6a6e66142d1

Maciej Żenczykowski   commited 2023-11-09 03:00:09 +00:00
23912ee104
remove BpfNetMaps.cpp
Test: builds, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If192c17881736c9fe7f8346ad8c5d41d7164eb03

Maciej Żenczykowski   commited 2023-11-08 07:12:46 +00:00
7b8f475e79
Merge changes Ie1a36c3c,Id727cf7b,Ifba198d9 into main
* changes:
  Remove unnecessary check for skDestroyListener
  Remove TrafficController
  Remove native code path in BpfNetMaps.java

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-11-07 19:32:51 +00:00
87f7f27ad0
Remove unnecessary check for skDestroyListener
skDestroyListener is always running with Java code so removed the
unnecessary check.

Bug: 217624062
Test: TH

Change-Id: Ie1a36c3c736005ec4821c5e9c9983998f7042afa

Motomu Utsumi   commited 2023-11-07 20:25:28 +09:00
ffa6d6152b
Remove native code path in BpfNetMaps.java
BpfNetMaps uses java library for updating bpf map as the default code
path.
This is already released to 100% production without any issues.
So this CL removes the old code path from BpfNetMaps.

Note that native_init only opens the bpf maps if sEnableJavaBpfMap is
true.
But if sEnableJavaBpfMap is true, no native code in TrafficController
access the bpf map.
So this CL can remove native_init.

Following CL will remove the nativce codes for old code path.

Bug: 217624062
Test: NetworkStaticLibsTests
Change-Id: Ifba198d9e6f93b53fd1dbf3b2aafb644da0b147d

Motomu Utsumi   commited 2023-11-07 17:45:32 +09:00
96b6c39229
Merge "Add methods for updating ingressDiscardRule bpf map to BpfNetMaps" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-11-06 10:41:53 +00:00
d872c3c960
[BR02] Implement isUidNetworkingBlocked
This is needed for data stall detection mechanism in NetworkStack
to get the information about whether the network is blocked for
a given uid and conditions. Because the API will be called
frequently from NetworkStack to resolve all status for all uids
on the device, the API cannot call into the service which
creates IPC. Instead, the API need to directly access bpf maps
in the user process to retrieve the status. In this case the
user process is the network stack, the access control is provided
by linux file permission and selinux.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.ConnectivityManagerTest
NO_IFTTT=Refactor only change for firewall chains definitions
Bug: 297836825

Change-Id: Iaf983b71ec98cbfe5152dcfade8a3120f938f135

Junyu Lai   commited 2023-10-31 16:33:41 +08:00
e003152e2c
Add methods for updating ingressDiscardRule bpf map to BpfNetMaps
Bug 295800201
Test: NetworkStaticLibsTests

Change-Id: I42bc0adc22c3018480029d624053f758d815e526

Motomu Utsumi   commited 2023-10-31 17:07:46 +09:00
77b49996d2
Write Data Saver setting to BPF map
The information is needed by modules who want to know whether a
specific UID is blocked by Data Saver feature.

1. Add a one-element map data_saver_enabled_map.
2. Update current data saver setting to the map.

Bug: 288340533
Test: atest FrameworksNetTests:android.net.connectivity.com.android.serv
er.BpfNetMapsTest
Test: atest bpf_existence_test

Change-Id: I981da4b569247c33cba2d365cb6f2691f673474e

Ken Chen   commited 2023-10-31 01:36:03 +00:00
243301748e
[BR01.1] Support BpfNetMapsReader
A helper class to *read* java BpfMaps. This is designed to
provide direct bpf access in the caller process through
ConnectivityManager APIs.

The change also removes any statical link to
net-utils-device-common-struct from service-connectivity.
This is because net-utils-device-common-struct is already
included in framework-connectivity. Including it again in
service-connectivity would create a r8 build fail by circular
dependency.

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Bug: 297836825
Change-Id: I7a6d2eb816d0dc7343167bddd672806b199f44fe

Junyu Lai   commited 2023-10-23 20:11:02 +08:00
626045a601
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

Motomu Utsumi   commited 2023-09-27 17:30:01 +09:00
ed4e7ec954
remove TrafficController::dump
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I399ac8dfc4992f4c604f1d32c2f1b8ae06710808

Maciej Żenczykowski   commited 2023-09-06 16:50:06 +00:00
d70a33061e
Split BpfNetMaps constants and utilities into standalone classes
This is a no-op refactoring that splits constants and utility
methods into standalone classes which will be shared with
a bpf reader class in subsequent CLs.

NO_IFTTT=No-op refactoring

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest

Bug: 297836825
Change-Id: I6d7ea044e43180ae001573009a166be74ebe6a5d

Junyu Lai   commited 2023-08-29 08:20:10 +00:00
29b7b6385a
Use Java code path for bpf map operations in BpfNetMaps
Experiment to verify bpf map operations refactoring showed no
change of map size metrics and no system health regressions.
So this CL update BpfNetMaps to always use new code path with kill
switch.

Test: m
Bug: 217624062
Change-Id: Ic17470ac5c075884871ea2df2c13c054f5ac2929

Motomu Utsumi   commited 2023-08-16 20:08:20 +09:00
7628ea30b0
Revert "KNOWN BAD CHANGE - it should cause lint failures (but doesn't??)."
This reverts commit fc9875f537.

Reason for revert: known to be bad.

Change-Id: I9b8db53c054119f454e50007f56232312a0ba595

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-07-18 20:14:38 +00:00
70fbfa43ed
KNOWN BAD CHANGE - it should cause lint failures (but doesn't??).
Build/TestCop - revert this if you see failures (just document where).
It erroneously(?) doesn't appear to cause any failures in TH
on aosp/master.

Bug: 291519274
Change-Id: I78b049302ae9bd2a8db8c03e79388dc4e51e110f

Maciej Żenczykowski   commited 2023-07-18 20:09:20 +00:00
fc9875f537
BpfNetMaps.java - add @Requires(T) to all native_ methods
Bug: 291519274
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0d6c68e639a975cf35ec6cc948be5744b104c98d

Maciej Żenczykowski   commited 2023-07-18 14:19:44 +00:00
e7da6fdff1
Close sockets from ConnectivityService#setFirewallChainEnabled
And replace netd.socketDestroy by Java implementation

Bug: 270298713
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0e200247ca010f9649254eeaac02740bd2bfdb21

Motomu Utsumi   commited 2023-05-11 12:22:09 +09:00
d44a33adb9
Fix isFeatureEnabled namespace and overload usage
From service-connectivity, NAMESPACE_TETHERING must be used, as
NAMESPACE_CONNECTIVITY is used for the NetworkStack module. Also the
isFeatureEnabled with module name must be used, otherwise the "android"
package version is queried instead of the tethering module version.

BpfNetMaps is using flag value 1 to workaround this issue.
flags in NsdService, AutomaticOnOffKeepaliveTracker, and ConnectivityFlags
were not pushed currently.
So, this change has no effect to devices.

Bug: 279108992
Test: TH
Change-Id: I2b4b6a13c048c20beef52b1f43b9e21aca0c637a

Motomu Utsumi   commited 2023-04-28 19:18:43 +09:00
278db58bf5
Add getUidRule method to BpfNetMaps
Upcoming CLs use this method to add chain status to failure log of
ConnectivityManagerTest#testFirewallBlocking which is a flaky test

Test: atest BpfNetMapsTest
Bug: 262141231
Change-Id: Ib130a28c708f675c79b889bf293dfe6b0f8d7f60

Motomu Utsumi   commited 2023-02-01 17:05:36 +09:00
56c412a9c8
check for U+ before checking device feature flags
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I12e147e61febd96324cdbb6642e0894e5c399526

Maciej Żenczykowski   commited 2022-12-27 10:57:59 +00:00
e7ebb15424
rename bpf_shared.h to netd.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2e1569c8d70e98f9a3fdbab41fd2ba7f7b84dd37

Maciej Żenczykowski   commited 2022-12-18 20:02:52 +00:00
513474c1a7
Enable java bpf map always in U devices
Having SdkLevel.isAtLeastU() as a default value of
DeviceConfigUtils.isFeatureEnabled could result confusing behavior.
For example, when flag value is pushed to only the T device and the T
device with the flag is ugraded to U, this device could disable java bpf
map while the device keeps the flag value.
This CL prevents above confusing behavior.

Bug: 246218229
Test: atest BpfNetMaps
Change-Id: I615603c337bb94101dccac77ea0e6fa857041259

Motomu Utsumi   commited 2022-12-06 15:03:20 +09:00
0e9c379c3e
Add sEnableJavaBpfMap value to the dump
Bug: 217624062
Test: dumpsys connectivity trafficcontroller
Change-Id: Icf3df3aac827e65415a8304df87a685272f38f9e

Motomu Utsumi   commited 2022-10-05 18:28:16 +09:00
316d057ded
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 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
BpfNetMaps.java - array index U32 -> S32
This converts the key, which is an index in an array, of sConfigurationMap from U32 to S32.

Since the array has exactly 2 elements, there's no real difference.
In addition while the kernel does indeed index arrays with U32s,
it doesn't matter, because you'd need to have over 2 billion
elements in the bpf map (at which point you'd need GBs of ram for
the bpf map itself)...

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

Maciej Żenczykowski   commited 2022-09-17 06:16:34 +00:00
dc88622eb8
BpfNetMaps.java - uid U32 -> S32
This converts the key, which is a uid, of sUidOwnerMap & sUidPermissionMap from U32 to S32.

The kernel is actually not consistent in whether uids & gids
are signed or unsigned, and neither is our Java code, which
also commonly uses just 'int' for uid.  In practice values
greater or equal to 2**31 often don't quite work right.
For example icmp sockets are enabled via a sysctl that
takes a minimum and maximum gid - and these are signed int32s.

It's worth pointing out that these functions already accept int's
as arguments, so when converting them to U32 (and thus long) they
technically previously did the wrong thing (though it's unlikely
it ever mattered).

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

Maciej Żenczykowski   commited 2022-09-17 06:06:23 +00:00
785793fe19
UidOwnerValue.java - replace U32 ifindex with S32
These are allocated in order by the kernel, if we go
over 2 billion, we've got other problems... besides
U32 to S32 conversion will work just fine anyway.

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

Maciej Żenczykowski   commited 2022-09-16 18:34:39 +00:00
6c1c6bb582
Add native_dump to the Dependencies
This is a preparation for the upcoming CL that will add the test for
BpfNetMaps#dump.

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

Motomu Utsumi   commited 2022-09-14 11:49:16 +09:00
df8d299ecc
Merge changes from topic "idiag_sock_id"
* changes:
  Switch SkDestroyListener based on the flag.
  Add startSkDestroyListener flag to native_init
  Add SkDestroyListenerTest

Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-09-10 02:02:11 +00:00
08ccd0d2e1
register callback to pull NetworkBpfMapInfo atom
Test: statsd_testdrive 10161, atest BpfNetMaps
Bug: 217624062
Bug: 245228691

Change-Id: I630a86cb5a34aaa1810eb75b374588dba570f0ff

Motomu Utsumi   commited 2022-09-09 11:23:10 +09:00
166f966209
Open CookieTagMap in BpfNetMaps
Upcoming CL will update BpfNetMaps to pull NetworkBpfMapInfo atom that
contains the cookieTagMap size field.

Test: m, atest BpfNetMaps
Bug: 217624062
Change-Id: I84bb0aa56e3916fc6fc0ca31ba5962f3b9be4b6f

Motomu Utsumi   commited 2022-09-06 22:33:44 +09:00
b9548860a9
Switch SkDestroyListener based on the flag.
Switch existing C SkDestroyListener and new Java SkDestroyListener based
on the experiment flag.

Bug: 217624062
Test: atest SkDestroyListenerTest
Change-Id: I7031ba7c155edb43e0e7b77449587058d6ba38fb

Motomu Utsumi   commited 2022-09-06 11:23:13 +09:00
d95a0dafa8
Add startSkDestroyListener flag to native_init
This CL prepares for upcoming CL.
Upcoming CL will add SkDestroyListener with Java BpfMap and switch
current C SkDestroyListener and new Java SkDestroyListener based on the
experiment flag.

Bug: 217624062
Test: atest SkDestroyListenerTest
Change-Id: I5ebb319d1b2262199d4ef6a3549894fee24c4ccf

Motomu Utsumi   commited 2022-09-06 11:23:13 +09:00
3af8f0e8d6
Merge "Use IBpfMap type instead of BpfMap type"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-08-31 03:54:28 +00:00
171c817072
Merge "Add wtf log for the case that should not happen"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-08-26 01:33:01 +00:00
9785a681d7
Merge "Convert int array to Integer Set without stream"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-08-26 01:32:17 +00:00
7631d15ff8
Use IBpfMap type instead of BpfMap type
Currently, production code uses BpfMap type and TestBpfMap extends
BpfMap but this makes it diffcult to test because TestBpfMap loads the
JNI.

This CL updates to use IBpfMap type in the production code.
Upcoming CL updates TestBpfMap to implement IBpfMap instead of extending
BpfMap so that test can still use TestBpfMap but tests do not need to
load JNI.

Bug: 217624062
Test: atest BpfCoordinatorTest BpfNetMapsTest
Change-Id: Ie67e14bf5519fb4427474ecc0fda441877a9555f

Motomu Utsumi   commited 2022-08-24 23:31:19 +09:00
73599a5f5d
Add wtf log for the case that should not happen
Bug: 243314552
Test: atest BpfNetMapsTest
Change-Id: I8e97c8150d0f427b7b0ac26374322e36b013320a

Motomu Utsumi   commited 2022-08-24 18:51:04 +09:00
8e420ead05
Convert int array to Integer Set without stream
Address a review comment on aosp/2145584

Bug: 243314552
Test: atest BpfNetMapsTest
Change-Id: Id4cb96b59c88221ad5de32ce3b170ca82c48e6f2

Motomu Utsumi   commited 2022-08-24 17:50:37 +09:00
1a477b0b33