blob: 839cd1691fa4fdb645b3331755a8acc0a093105d [file] [log] [blame]
Wayne Ma0ea3bdc2022-01-12 01:12:11 +08001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000019import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE;
20import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY;
21import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1;
22import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2;
23import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3;
24import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
25import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED;
26import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY;
Motomu Utsumi40230be2022-07-05 03:27:35 +000027import static android.net.ConnectivityManager.FIREWALL_RULE_ALLOW;
28import static android.net.ConnectivityManager.FIREWALL_RULE_DENY;
Motomu Utsumi65271202022-07-05 08:21:41 +000029import static android.net.INetd.PERMISSION_INTERNET;
30import static android.net.INetd.PERMISSION_UNINSTALLED;
Motomu Utsumi18b287d2022-06-19 10:45:30 +000031import static android.system.OsConstants.EINVAL;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +000032import static android.system.OsConstants.ENODEV;
Motomu Utsumi60ed3be2022-06-24 10:38:57 +000033import static android.system.OsConstants.ENOENT;
Ken Chene6d511f2022-01-25 11:10:42 +080034import static android.system.OsConstants.EOPNOTSUPP;
35
Motomu Utsumif688eeb2022-07-22 03:47:35 +000036import android.content.Context;
Wayne Ma2fde98c2022-01-17 18:04:05 +080037import android.net.INetd;
38import android.os.RemoteException;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080039import android.os.ServiceSpecificException;
Motomu Utsumif688eeb2022-07-22 03:47:35 +000040import android.provider.DeviceConfig;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000041import android.system.ErrnoException;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080042import android.system.Os;
43import android.util.Log;
44
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000045import com.android.internal.annotations.VisibleForTesting;
Ken Chenf5f51332022-01-28 10:08:16 +080046import com.android.modules.utils.build.SdkLevel;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000047import com.android.net.module.util.BpfMap;
Motomu Utsumif688eeb2022-07-22 03:47:35 +000048import com.android.net.module.util.DeviceConfigUtils;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000049import com.android.net.module.util.Struct.U32;
Motomu Utsumi65271202022-07-05 08:21:41 +000050import com.android.net.module.util.Struct.U8;
Ken Chenf5f51332022-01-28 10:08:16 +080051
Ken Chene6d511f2022-01-25 11:10:42 +080052import java.io.FileDescriptor;
53import java.io.IOException;
Motomu Utsumi9be2ea02022-07-05 06:14:59 +000054import java.util.Arrays;
55import java.util.HashSet;
56import java.util.Set;
57import java.util.stream.Collectors;
Ken Chene6d511f2022-01-25 11:10:42 +080058
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080059/**
60 * BpfNetMaps is responsible for providing traffic controller relevant functionality.
61 *
62 * {@hide}
63 */
64public class BpfNetMaps {
Motomu Utsumi305975f2022-06-27 09:24:32 +000065 private static final boolean PRE_T = !SdkLevel.isAtLeastT();
66 static {
67 if (!PRE_T) {
68 System.loadLibrary("service-connectivity");
69 }
70 }
71
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080072 private static final String TAG = "BpfNetMaps";
Wayne Ma2fde98c2022-01-17 18:04:05 +080073 private final INetd mNetd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +000074 private final Dependencies mDeps;
Ken Chenf5f51332022-01-28 10:08:16 +080075 // Use legacy netd for releases before T.
Ken Chenf5f51332022-01-28 10:08:16 +080076 private static boolean sInitialized = false;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080077
Motomu Utsumif688eeb2022-07-22 03:47:35 +000078 private static Boolean sEnableJavaBpfMap = null;
79 private static final String BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP =
80 "bpf_net_maps_enable_java_bpf_map";
81
Motomu Utsumi18b287d2022-06-19 10:45:30 +000082 // Lock for sConfigurationMap entry for UID_RULES_CONFIGURATION_KEY.
83 // This entry is not accessed by others.
84 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
85 private static final Object sUidRulesConfigBpfMapLock = new Object();
86
Motomu Utsumi7abeaa42022-07-20 07:54:18 +000087 // Lock for sConfigurationMap entry for CURRENT_STATS_MAP_CONFIGURATION_KEY.
88 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
89 // BpfNetMaps is an only writer of this entry.
90 private static final Object sCurrentStatsMapConfigLock = new Object();
91
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000092 private static final String CONFIGURATION_MAP_PATH =
93 "/sys/fs/bpf/netd_shared/map_netd_configuration_map";
Motomu Utsumi5a68a212022-06-24 10:14:31 +000094 private static final String UID_OWNER_MAP_PATH =
95 "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map";
Motomu Utsumi65271202022-07-05 08:21:41 +000096 private static final String UID_PERMISSION_MAP_PATH =
97 "/sys/fs/bpf/netd_shared/map_netd_uid_permission_map";
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000098 private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0);
Motomu Utsumiba2fa152022-07-25 01:57:23 +000099 private static final U32 CURRENT_STATS_MAP_CONFIGURATION_KEY = new U32(1);
100 private static final long UID_RULES_DEFAULT_CONFIGURATION = 0;
101 private static final long STATS_SELECT_MAP_A = 0;
102 private static final long STATS_SELECT_MAP_B = 1;
103
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000104 private static BpfMap<U32, U32> sConfigurationMap = null;
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000105 // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
106 private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
Motomu Utsumi65271202022-07-05 08:21:41 +0000107 private static BpfMap<U32, U8> sUidPermissionMap = null;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000108
109 // LINT.IfChange(match_type)
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000110 @VisibleForTesting public static final long NO_MATCH = 0;
111 @VisibleForTesting public static final long HAPPY_BOX_MATCH = (1 << 0);
112 @VisibleForTesting public static final long PENALTY_BOX_MATCH = (1 << 1);
113 @VisibleForTesting public static final long DOZABLE_MATCH = (1 << 2);
114 @VisibleForTesting public static final long STANDBY_MATCH = (1 << 3);
115 @VisibleForTesting public static final long POWERSAVE_MATCH = (1 << 4);
116 @VisibleForTesting public static final long RESTRICTED_MATCH = (1 << 5);
117 @VisibleForTesting public static final long LOW_POWER_STANDBY_MATCH = (1 << 6);
118 @VisibleForTesting public static final long IIF_MATCH = (1 << 7);
119 @VisibleForTesting public static final long LOCKDOWN_VPN_MATCH = (1 << 8);
120 @VisibleForTesting public static final long OEM_DENY_1_MATCH = (1 << 9);
121 @VisibleForTesting public static final long OEM_DENY_2_MATCH = (1 << 10);
122 @VisibleForTesting public static final long OEM_DENY_3_MATCH = (1 << 11);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000123 // LINT.ThenChange(packages/modules/Connectivity/bpf_progs/bpf_shared.h)
124
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000125 /**
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000126 * Set sEnableJavaBpfMap for test.
127 */
128 @VisibleForTesting
129 public static void setEnableJavaBpfMapForTest(boolean enable) {
130 sEnableJavaBpfMap = enable;
131 }
132
133 /**
Motomu Utsumi305975f2022-06-27 09:24:32 +0000134 * Set configurationMap for test.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000135 */
136 @VisibleForTesting
Motomu Utsumi305975f2022-06-27 09:24:32 +0000137 public static void setConfigurationMapForTest(BpfMap<U32, U32> configurationMap) {
138 sConfigurationMap = configurationMap;
139 }
140
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000141 /**
142 * Set uidOwnerMap for test.
143 */
144 @VisibleForTesting
145 public static void setUidOwnerMapForTest(BpfMap<U32, UidOwnerValue> uidOwnerMap) {
146 sUidOwnerMap = uidOwnerMap;
147 }
148
Motomu Utsumi65271202022-07-05 08:21:41 +0000149 /**
150 * Set uidPermissionMap for test.
151 */
152 @VisibleForTesting
153 public static void setUidPermissionMapForTest(BpfMap<U32, U8> uidPermissionMap) {
154 sUidPermissionMap = uidPermissionMap;
155 }
156
Motomu Utsumi305975f2022-06-27 09:24:32 +0000157 private static BpfMap<U32, U32> getConfigurationMap() {
158 try {
159 return new BpfMap<>(
160 CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class);
161 } catch (ErrnoException e) {
162 throw new IllegalStateException("Cannot open netd configuration map", e);
163 }
164 }
165
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000166 private static BpfMap<U32, UidOwnerValue> getUidOwnerMap() {
167 try {
168 return new BpfMap<>(
169 UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class);
170 } catch (ErrnoException e) {
171 throw new IllegalStateException("Cannot open uid owner map", e);
172 }
173 }
174
Motomu Utsumi65271202022-07-05 08:21:41 +0000175 private static BpfMap<U32, U8> getUidPermissionMap() {
176 try {
177 return new BpfMap<>(
178 UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U8.class);
179 } catch (ErrnoException e) {
180 throw new IllegalStateException("Cannot open uid permission map", e);
181 }
182 }
183
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000184 private static void initBpfMaps() {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000185 if (sConfigurationMap == null) {
186 sConfigurationMap = getConfigurationMap();
187 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000188 try {
189 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY,
190 new U32(UID_RULES_DEFAULT_CONFIGURATION));
191 } catch (ErrnoException e) {
192 throw new IllegalStateException("Failed to initialize uid rules configuration", e);
193 }
194 try {
195 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
196 new U32(STATS_SELECT_MAP_A));
197 } catch (ErrnoException e) {
198 throw new IllegalStateException("Failed to initialize current stats configuration", e);
199 }
200
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000201 if (sUidOwnerMap == null) {
202 sUidOwnerMap = getUidOwnerMap();
203 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000204 try {
205 sUidOwnerMap.clear();
206 } catch (ErrnoException e) {
207 throw new IllegalStateException("Failed to initialize uid owner map", e);
208 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000209
210 if (sUidPermissionMap == null) {
211 sUidPermissionMap = getUidPermissionMap();
212 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000213 }
214
Ken Chenf5f51332022-01-28 10:08:16 +0800215 /**
216 * Initializes the class if it is not already initialized. This method will open maps but not
217 * cause any other effects. This method may be called multiple times on any thread.
218 */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000219 private static synchronized void ensureInitialized(final Context context) {
Ken Chenf5f51332022-01-28 10:08:16 +0800220 if (sInitialized) return;
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000221 if (sEnableJavaBpfMap == null) {
222 sEnableJavaBpfMap = DeviceConfigUtils.isFeatureEnabled(context,
223 DeviceConfig.NAMESPACE_TETHERING, BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP,
224 SdkLevel.isAtLeastU() /* defaultValue */);
225 }
226 Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap);
227
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000228 initBpfMaps();
Motomu Utsumi305975f2022-06-27 09:24:32 +0000229 native_init();
Ken Chenf5f51332022-01-28 10:08:16 +0800230 sInitialized = true;
Wayne Ma2fde98c2022-01-17 18:04:05 +0800231 }
232
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000233 /**
234 * Dependencies of BpfNetMaps, for injection in tests.
235 */
236 @VisibleForTesting
237 public static class Dependencies {
238 /**
239 * Get interface index.
240 */
241 public int getIfIndex(final String ifName) {
242 return Os.if_nametoindex(ifName);
243 }
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000244
245 /**
246 * Call synchronize_rcu()
247 */
248 public int synchronizeKernelRCU() {
249 return native_synchronizeKernelRCU();
250 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000251 }
252
markchien49e944c2022-03-01 15:22:20 +0800253 /** Constructor used after T that doesn't need to use netd anymore. */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000254 public BpfNetMaps(final Context context) {
255 this(context, null);
markchien49e944c2022-03-01 15:22:20 +0800256
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000257 if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T");
markchien49e944c2022-03-01 15:22:20 +0800258 }
259
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000260 public BpfNetMaps(final Context context, final INetd netd) {
261 this(context, netd, new Dependencies());
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000262 }
263
264 @VisibleForTesting
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000265 public BpfNetMaps(final Context context, final INetd netd, final Dependencies deps) {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000266 if (!PRE_T) {
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000267 ensureInitialized(context);
Motomu Utsumi305975f2022-06-27 09:24:32 +0000268 }
Wayne Ma2fde98c2022-01-17 18:04:05 +0800269 mNetd = netd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000270 mDeps = deps;
Wayne Ma790c83e2022-01-13 10:35:05 +0800271 }
272
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000273 /**
274 * Get corresponding match from firewall chain.
275 */
276 @VisibleForTesting
277 public long getMatchByFirewallChain(final int chain) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000278 switch (chain) {
279 case FIREWALL_CHAIN_DOZABLE:
280 return DOZABLE_MATCH;
281 case FIREWALL_CHAIN_STANDBY:
282 return STANDBY_MATCH;
283 case FIREWALL_CHAIN_POWERSAVE:
284 return POWERSAVE_MATCH;
285 case FIREWALL_CHAIN_RESTRICTED:
286 return RESTRICTED_MATCH;
287 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
288 return LOW_POWER_STANDBY_MATCH;
289 case FIREWALL_CHAIN_OEM_DENY_1:
290 return OEM_DENY_1_MATCH;
291 case FIREWALL_CHAIN_OEM_DENY_2:
292 return OEM_DENY_2_MATCH;
293 case FIREWALL_CHAIN_OEM_DENY_3:
294 return OEM_DENY_3_MATCH;
295 default:
296 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000297 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000298 }
299
300 /**
301 * Get if the chain is allow list or not.
302 *
303 * ALLOWLIST means the firewall denies all by default, uids must be explicitly allowed
304 * DENYLIST means the firewall allows all by default, uids must be explicitly denyed
305 */
306 @VisibleForTesting
307 public boolean isFirewallAllowList(final int chain) {
308 switch (chain) {
309 case FIREWALL_CHAIN_DOZABLE:
310 case FIREWALL_CHAIN_POWERSAVE:
311 case FIREWALL_CHAIN_RESTRICTED:
312 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
313 return true;
314 case FIREWALL_CHAIN_STANDBY:
315 case FIREWALL_CHAIN_OEM_DENY_1:
316 case FIREWALL_CHAIN_OEM_DENY_2:
317 case FIREWALL_CHAIN_OEM_DENY_3:
318 return false;
319 default:
320 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
321 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000322 }
323
Ken Chenf5f51332022-01-28 10:08:16 +0800324 private void maybeThrow(final int err, final String msg) {
325 if (err != 0) {
326 throw new ServiceSpecificException(err, msg + ": " + Os.strerror(err));
327 }
328 }
329
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000330 private void throwIfPreT(final String msg) {
331 if (PRE_T) {
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000332 throw new UnsupportedOperationException(msg);
333 }
334 }
335
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000336 private void removeRule(final int uid, final long match, final String caller) {
337 try {
338 synchronized (sUidOwnerMap) {
339 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
340
341 if (oldMatch == null) {
342 throw new ServiceSpecificException(ENOENT,
343 "sUidOwnerMap does not have entry for uid: " + uid);
344 }
345
346 final UidOwnerValue newMatch = new UidOwnerValue(
347 (match == IIF_MATCH) ? 0 : oldMatch.iif,
348 oldMatch.rule & ~match
349 );
350
351 if (newMatch.rule == 0) {
352 sUidOwnerMap.deleteEntry(new U32(uid));
353 } else {
354 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
355 }
356 }
357 } catch (ErrnoException e) {
358 throw new ServiceSpecificException(e.errno,
359 caller + " failed to remove rule: " + Os.strerror(e.errno));
360 }
361 }
362
Motomu Utsumi389278e2022-06-28 07:05:05 +0000363 private void addRule(final int uid, final long match, final long iif, final String caller) {
364 if (match != IIF_MATCH && iif != 0) {
365 throw new ServiceSpecificException(EINVAL,
366 "Non-interface match must have zero interface index");
367 }
368
369 try {
370 synchronized (sUidOwnerMap) {
371 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
372
373 final UidOwnerValue newMatch;
374 if (oldMatch != null) {
375 newMatch = new UidOwnerValue(
376 (match == IIF_MATCH) ? iif : oldMatch.iif,
377 oldMatch.rule | match
378 );
379 } else {
380 newMatch = new UidOwnerValue(
381 iif,
382 match
383 );
384 }
385 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
386 }
387 } catch (ErrnoException e) {
388 throw new ServiceSpecificException(e.errno,
389 caller + " failed to add rule: " + Os.strerror(e.errno));
390 }
391 }
392
393 private void addRule(final int uid, final long match, final String caller) {
394 addRule(uid, match, 0 /* iif */, caller);
395 }
396
Ken Chenf5f51332022-01-28 10:08:16 +0800397 /**
398 * Add naughty app bandwidth rule for specific app
399 *
400 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800401 * @throws ServiceSpecificException in case of failure, with an error code indicating the
402 * cause of the failure.
403 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900404 public void addNaughtyApp(final int uid) {
Motomu Utsumi389278e2022-06-28 07:05:05 +0000405 throwIfPreT("addNaughtyApp is not available on pre-T devices");
Motomu Utsumi55c282e2022-08-03 06:25:33 +0000406
407 if (sEnableJavaBpfMap) {
408 addRule(uid, PENALTY_BOX_MATCH, "addNaughtyApp");
409 } else {
410 final int err = native_addNaughtyApp(uid);
411 maybeThrow(err, "Unable to add naughty app");
412 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800413 }
414
Ken Chenf5f51332022-01-28 10:08:16 +0800415 /**
416 * Remove naughty app bandwidth rule for specific app
417 *
418 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800419 * @throws ServiceSpecificException in case of failure, with an error code indicating the
420 * cause of the failure.
421 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900422 public void removeNaughtyApp(final int uid) {
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000423 throwIfPreT("removeNaughtyApp is not available on pre-T devices");
Motomu Utsumi878ce0d2022-08-03 06:22:42 +0000424
425 if (sEnableJavaBpfMap) {
426 removeRule(uid, PENALTY_BOX_MATCH, "removeNaughtyApp");
427 } else {
428 final int err = native_removeNaughtyApp(uid);
429 maybeThrow(err, "Unable to remove naughty app");
430 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800431 }
432
Ken Chenf5f51332022-01-28 10:08:16 +0800433 /**
434 * Add nice app bandwidth rule for specific app
435 *
436 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800437 * @throws ServiceSpecificException in case of failure, with an error code indicating the
438 * cause of the failure.
439 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900440 public void addNiceApp(final int uid) {
Motomu Utsumi55630d02022-06-29 07:46:52 +0000441 throwIfPreT("addNiceApp is not available on pre-T devices");
Motomu Utsumi7f19df92022-08-03 06:29:59 +0000442
443 if (sEnableJavaBpfMap) {
444 addRule(uid, HAPPY_BOX_MATCH, "addNiceApp");
445 } else {
446 final int err = native_addNiceApp(uid);
447 maybeThrow(err, "Unable to add nice app");
448 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800449 }
450
Ken Chenf5f51332022-01-28 10:08:16 +0800451 /**
452 * Remove nice app bandwidth rule for specific app
453 *
454 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800455 * @throws ServiceSpecificException in case of failure, with an error code indicating the
456 * cause of the failure.
457 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900458 public void removeNiceApp(final int uid) {
Motomu Utsumi7392eb42022-06-29 03:53:03 +0000459 throwIfPreT("removeNiceApp is not available on pre-T devices");
Motomu Utsumi5f15f752022-08-03 06:27:51 +0000460
461 if (sEnableJavaBpfMap) {
462 removeRule(uid, HAPPY_BOX_MATCH, "removeNiceApp");
463 } else {
464 final int err = native_removeNiceApp(uid);
465 maybeThrow(err, "Unable to remove nice app");
466 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800467 }
468
Ken Chenf5f51332022-01-28 10:08:16 +0800469 /**
470 * Set target firewall child chain
471 *
472 * @param childChain target chain to enable
473 * @param enable whether to enable or disable child chain.
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000474 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800475 * @throws ServiceSpecificException in case of failure, with an error code indicating the
476 * cause of the failure.
477 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900478 public void setChildChain(final int childChain, final boolean enable) {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000479 throwIfPreT("setChildChain is not available on pre-T devices");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000480
Motomu Utsumie057dd42022-08-03 01:23:49 +0000481 if (sEnableJavaBpfMap) {
482 final long match = getMatchByFirewallChain(childChain);
483 try {
484 synchronized (sUidRulesConfigBpfMapLock) {
485 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
486 final long newConfig = enable ? (config.val | match) : (config.val & ~match);
487 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig));
488 }
489 } catch (ErrnoException e) {
490 throw new ServiceSpecificException(e.errno,
491 "Unable to set child chain: " + Os.strerror(e.errno));
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000492 }
Motomu Utsumie057dd42022-08-03 01:23:49 +0000493 } else {
494 final int err = native_setChildChain(childChain, enable);
495 maybeThrow(err, "Unable to set child chain");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000496 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800497 }
498
499 /**
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000500 * Get the specified firewall chain's status.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000501 *
502 * @param childChain target chain
503 * @return {@code true} if chain is enabled, {@code false} if chain is not enabled.
504 * @throws UnsupportedOperationException if called on pre-T devices.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000505 * @throws ServiceSpecificException in case of failure, with an error code indicating the
506 * cause of the failure.
507 */
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000508 public boolean isChainEnabled(final int childChain) {
509 throwIfPreT("isChainEnabled is not available on pre-T devices");
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000510
511 final long match = getMatchByFirewallChain(childChain);
512 try {
513 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000514 return (config.val & match) != 0;
515 } catch (ErrnoException e) {
516 throw new ServiceSpecificException(e.errno,
517 "Unable to get firewall chain status: " + Os.strerror(e.errno));
518 }
519 }
520
521 /**
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800522 * Replaces the contents of the specified UID-based firewall chain.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000523 * Enables the chain for specified uids and disables the chain for non-specified uids.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800524 *
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000525 * @param chain Target chain.
Ken Chenf5f51332022-01-28 10:08:16 +0800526 * @param uids The list of UIDs to allow/deny.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000527 * @throws UnsupportedOperationException if called on pre-T devices.
528 * @throws IllegalArgumentException if {@code chain} is not a valid chain.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800529 */
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000530 public void replaceUidChain(final int chain, final int[] uids) {
531 throwIfPreT("replaceUidChain is not available on pre-T devices");
532
Motomu Utsumic7c16852022-08-03 06:51:41 +0000533 if (sEnableJavaBpfMap) {
534 final long match;
535 try {
536 match = getMatchByFirewallChain(chain);
537 } catch (ServiceSpecificException e) {
538 // Throws IllegalArgumentException to keep the behavior of
539 // ConnectivityManager#replaceFirewallChain API
540 throw new IllegalArgumentException("Invalid firewall chain: " + chain);
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000541 }
Motomu Utsumic7c16852022-08-03 06:51:41 +0000542 final Set<Integer> uidSet = Arrays.stream(uids).boxed().collect(Collectors.toSet());
543 final Set<Integer> uidSetToRemoveRule = new HashSet<>();
544 try {
545 synchronized (sUidOwnerMap) {
546 sUidOwnerMap.forEach((uid, config) -> {
547 // config could be null if there is a concurrent entry deletion.
Motomu Utsumi8e420ea2022-08-24 18:03:30 +0900548 // http://b/220084230. But sUidOwnerMap update must be done while holding a
549 // lock, so this should not happen.
550 if (config == null) {
551 Log.wtf(TAG, "sUidOwnerMap entry was deleted while holding a lock");
552 } else if (!uidSet.contains((int) uid.val) && (config.rule & match) != 0) {
Motomu Utsumic7c16852022-08-03 06:51:41 +0000553 uidSetToRemoveRule.add((int) uid.val);
554 }
555 });
556
557 for (final int uid : uidSetToRemoveRule) {
558 removeRule(uid, match, "replaceUidChain");
559 }
560 for (final int uid : uids) {
561 addRule(uid, match, "replaceUidChain");
562 }
563 }
564 } catch (ErrnoException | ServiceSpecificException e) {
565 Log.e(TAG, "replaceUidChain failed: " + e);
566 }
567 } else {
568 final int err;
569 switch (chain) {
570 case FIREWALL_CHAIN_DOZABLE:
571 err = native_replaceUidChain("fw_dozable", true /* isAllowList */, uids);
572 break;
573 case FIREWALL_CHAIN_STANDBY:
574 err = native_replaceUidChain("fw_standby", false /* isAllowList */, uids);
575 break;
576 case FIREWALL_CHAIN_POWERSAVE:
577 err = native_replaceUidChain("fw_powersave", true /* isAllowList */, uids);
578 break;
579 case FIREWALL_CHAIN_RESTRICTED:
580 err = native_replaceUidChain("fw_restricted", true /* isAllowList */, uids);
581 break;
582 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
583 err = native_replaceUidChain(
584 "fw_low_power_standby", true /* isAllowList */, uids);
585 break;
586 case FIREWALL_CHAIN_OEM_DENY_1:
587 err = native_replaceUidChain("fw_oem_deny_1", false /* isAllowList */, uids);
588 break;
589 case FIREWALL_CHAIN_OEM_DENY_2:
590 err = native_replaceUidChain("fw_oem_deny_2", false /* isAllowList */, uids);
591 break;
592 case FIREWALL_CHAIN_OEM_DENY_3:
593 err = native_replaceUidChain("fw_oem_deny_3", false /* isAllowList */, uids);
594 break;
595 default:
596 throw new IllegalArgumentException("replaceFirewallChain with invalid chain: "
597 + chain);
598 }
599 if (err != 0) {
600 Log.e(TAG, "replaceUidChain failed: " + Os.strerror(-err));
601 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800602 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800603 }
604
Ken Chenf5f51332022-01-28 10:08:16 +0800605 /**
606 * Set firewall rule for uid
607 *
608 * @param childChain target chain
609 * @param uid uid to allow/deny
610 * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY
Ken Chenf5f51332022-01-28 10:08:16 +0800611 * @throws ServiceSpecificException in case of failure, with an error code indicating the
612 * cause of the failure.
613 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900614 public void setUidRule(final int childChain, final int uid, final int firewallRule) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000615 throwIfPreT("setUidRule is not available on pre-T devices");
616
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000617 if (sEnableJavaBpfMap) {
618 final long match = getMatchByFirewallChain(childChain);
619 final boolean isAllowList = isFirewallAllowList(childChain);
620 final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList)
621 || (firewallRule == FIREWALL_RULE_DENY && !isAllowList);
Motomu Utsumi40230be2022-07-05 03:27:35 +0000622
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000623 if (add) {
624 addRule(uid, match, "setUidRule");
625 } else {
626 removeRule(uid, match, "setUidRule");
627 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000628 } else {
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000629 final int err = native_setUidRule(childChain, uid, firewallRule);
630 maybeThrow(err, "Unable to set uid rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000631 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800632 }
633
634 /**
635 * Add ingress interface filtering rules to a list of UIDs
636 *
637 * For a given uid, once a filtering rule is added, the kernel will only allow packets from the
638 * allowed interface and loopback to be sent to the list of UIDs.
639 *
640 * Calling this method on one or more UIDs with an existing filtering rule but a different
641 * interface name will result in the filtering rule being updated to allow the new interface
642 * instead. Otherwise calling this method will not affect existing rules set on other UIDs.
643 *
644 * @param ifName the name of the interface on which the filtering rules will allow packets to
Ken Chenf5f51332022-01-28 10:08:16 +0800645 * be received.
646 * @param uids an array of UIDs which the filtering rules will be set
647 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800648 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800649 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800650 */
Ken Chenf5f51332022-01-28 10:08:16 +0800651 public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000652 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800653 mNetd.firewallAddUidInterfaceRules(ifName, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800654 return;
655 }
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000656
657 if (sEnableJavaBpfMap) {
658 // Null ifName is a wildcard to allow apps to receive packets on all interfaces and
659 // ifIndex is set to 0.
660 final int ifIndex;
661 if (ifName == null) {
662 ifIndex = 0;
663 } else {
664 ifIndex = mDeps.getIfIndex(ifName);
665 if (ifIndex == 0) {
666 throw new ServiceSpecificException(ENODEV,
667 "Failed to get index of interface " + ifName);
668 }
669 }
670 for (final int uid : uids) {
671 try {
672 addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules");
673 } catch (ServiceSpecificException e) {
674 Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e);
675 }
676 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000677 } else {
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000678 final int err = native_addUidInterfaceRules(ifName, uids);
679 maybeThrow(err, "Unable to add uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000680 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800681 }
682
683 /**
684 * Remove ingress interface filtering rules from a list of UIDs
685 *
686 * Clear the ingress interface filtering rules from the list of UIDs which were previously set
687 * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule.
688 *
689 * @param uids an array of UIDs from which the filtering rules will be removed
Ken Chenf5f51332022-01-28 10:08:16 +0800690 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800691 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800692 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800693 */
Ken Chenf5f51332022-01-28 10:08:16 +0800694 public void removeUidInterfaceRules(final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000695 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800696 mNetd.firewallRemoveUidInterfaceRules(uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800697 return;
698 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000699
700 if (sEnableJavaBpfMap) {
701 for (final int uid : uids) {
702 try {
703 removeRule(uid, IIF_MATCH, "removeUidInterfaceRules");
704 } catch (ServiceSpecificException e) {
705 Log.e(TAG, "removeRule failed uid=" + uid + ", " + e);
706 }
Motomu Utsumi599c4e52022-06-30 03:37:18 +0000707 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000708 } else {
709 final int err = native_removeUidInterfaceRules(uids);
710 maybeThrow(err, "Unable to remove uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000711 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800712 }
713
Ken Chenf5f51332022-01-28 10:08:16 +0800714 /**
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000715 * Update lockdown rule for uid
716 *
717 * @param uid target uid to add/remove the rule
718 * @param add {@code true} to add the rule, {@code false} to remove the rule.
719 * @throws ServiceSpecificException in case of failure, with an error code indicating the
720 * cause of the failure.
721 */
722 public void updateUidLockdownRule(final int uid, final boolean add) {
Motomu Utsumi697b2992022-06-30 02:25:29 +0000723 throwIfPreT("updateUidLockdownRule is not available on pre-T devices");
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000724
725 if (sEnableJavaBpfMap) {
726 if (add) {
727 addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
728 } else {
729 removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
730 }
Motomu Utsumi697b2992022-06-30 02:25:29 +0000731 } else {
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000732 final int err = native_updateUidLockdownRule(uid, add);
733 maybeThrow(err, "Unable to update lockdown rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000734 }
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000735 }
736
737 /**
Ken Chenf5f51332022-01-28 10:08:16 +0800738 * Request netd to change the current active network stats map.
739 *
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000740 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800741 * @throws ServiceSpecificException in case of failure, with an error code indicating the
742 * cause of the failure.
743 */
markchien49e944c2022-03-01 15:22:20 +0800744 public void swapActiveStatsMap() {
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000745 throwIfPreT("swapActiveStatsMap is not available on pre-T devices");
746
747 if (sEnableJavaBpfMap) {
748 try {
749 synchronized (sCurrentStatsMapConfigLock) {
750 final long config = sConfigurationMap.getValue(
751 CURRENT_STATS_MAP_CONFIGURATION_KEY).val;
752 final long newConfig = (config == STATS_SELECT_MAP_A)
753 ? STATS_SELECT_MAP_B : STATS_SELECT_MAP_A;
754 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
755 new U32(newConfig));
756 }
757 } catch (ErrnoException e) {
758 throw new ServiceSpecificException(e.errno, "Failed to swap active stats map");
759 }
760
761 // After changing the config, it's needed to make sure all the current running eBPF
762 // programs are finished and all the CPUs are aware of this config change before the old
763 // map is modified. So special hack is needed here to wait for the kernel to do a
764 // synchronize_rcu(). Once the kernel called synchronize_rcu(), the updated config will
765 // be available to all cores and the next eBPF programs triggered inside the kernel will
766 // use the new map configuration. So once this function returns it is safe to modify the
767 // old stats map without concerning about race between the kernel and userspace.
768 final int err = mDeps.synchronizeKernelRCU();
769 maybeThrow(err, "synchronizeKernelRCU failed");
770 } else {
771 final int err = native_swapActiveStatsMap();
772 maybeThrow(err, "Unable to swap active stats map");
773 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800774 }
775
Ken Chenf5f51332022-01-28 10:08:16 +0800776 /**
777 * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids
778 * specified. Or remove all permissions from the uids.
779 *
780 * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or
781 * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then
782 * revoke all permissions for the uids.
783 * @param uids uid of users to grant permission
784 * @throws RemoteException when netd has crashed.
785 */
786 public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000787 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800788 mNetd.trafficSetNetPermForUids(permissions, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800789 return;
790 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000791
792 if (sEnableJavaBpfMap) {
793 // Remove the entry if package is uninstalled or uid has only INTERNET permission.
794 if (permissions == PERMISSION_UNINSTALLED || permissions == PERMISSION_INTERNET) {
795 for (final int uid : uids) {
796 try {
797 sUidPermissionMap.deleteEntry(new U32(uid));
798 } catch (ErrnoException e) {
799 Log.e(TAG, "Failed to remove uid " + uid + " from permission map: " + e);
800 }
801 }
802 return;
803 }
804
805 for (final int uid : uids) {
806 try {
807 sUidPermissionMap.updateEntry(new U32(uid), new U8((short) permissions));
808 } catch (ErrnoException e) {
809 Log.e(TAG, "Failed to set permission "
810 + permissions + " to uid " + uid + ": " + e);
811 }
812 }
813 } else {
814 native_setPermissionForUids(permissions, uids);
815 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800816 }
817
Ken Chene6d511f2022-01-25 11:10:42 +0800818 /**
819 * Dump BPF maps
820 *
821 * @param fd file descriptor to output
822 * @throws IOException when file descriptor is invalid.
823 * @throws ServiceSpecificException when the method is called on an unsupported device.
824 */
825 public void dump(final FileDescriptor fd, boolean verbose)
826 throws IOException, ServiceSpecificException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000827 if (PRE_T) {
Ken Chene6d511f2022-01-25 11:10:42 +0800828 throw new ServiceSpecificException(
829 EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T"
830 + " devices, use dumpsys netd trafficcontroller instead.");
831 }
832 native_dump(fd, verbose);
833 }
834
Wayne Ma790c83e2022-01-13 10:35:05 +0800835 private static native void native_init();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800836 private native int native_addNaughtyApp(int uid);
837 private native int native_removeNaughtyApp(int uid);
838 private native int native_addNiceApp(int uid);
839 private native int native_removeNiceApp(int uid);
Motomu Utsumi114cd9c2022-08-01 02:08:35 +0000840 private native int native_setChildChain(int childChain, boolean enable);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800841 private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
842 private native int native_setUidRule(int childChain, int uid, int firewallRule);
843 private native int native_addUidInterfaceRules(String ifName, int[] uids);
844 private native int native_removeUidInterfaceRules(int[] uids);
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000845 private native int native_updateUidLockdownRule(int uid, boolean add);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800846 private native int native_swapActiveStatsMap();
Wayne Ma2fde98c2022-01-17 18:04:05 +0800847 private native void native_setPermissionForUids(int permissions, int[] uids);
Ken Chene6d511f2022-01-25 11:10:42 +0800848 private native void native_dump(FileDescriptor fd, boolean verbose);
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000849 private static native int native_synchronizeKernelRCU();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800850}