blob: 5d0fe73ca47e57fac066b492220e4f1426ba46b2 [file] [log] [blame]
Junyu Lai29b7b632023-08-23 17:35:17 +08001/*
2 * Copyright (C) 2023 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 android.net;
18
Suprabh Shukla2d893b62023-11-06 08:47:40 -080019import static android.net.ConnectivityManager.FIREWALL_CHAIN_BACKGROUND;
Junyu Laie0031522023-08-29 18:32:57 +080020import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE;
21import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY;
22import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1;
23import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2;
24import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3;
25import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
26import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED;
27import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY;
28
Junyu Lai29b7b632023-08-23 17:35:17 +080029import android.util.Pair;
30
31import com.android.net.module.util.Struct;
32
33import java.util.Arrays;
34import java.util.List;
35
36/**
37 * BpfNetMaps related constants that can be shared among modules.
38 *
39 * @hide
40 */
41// Note that this class should be put into bootclasspath instead of static libraries.
42// Because modules could have different copies of this class if this is statically linked,
43// which would be problematic if the definitions in these modules are not synchronized.
44public class BpfNetMapsConstants {
45 // Prevent this class from being accidental instantiated.
46 private BpfNetMapsConstants() {}
47
48 public static final String CONFIGURATION_MAP_PATH =
49 "/sys/fs/bpf/netd_shared/map_netd_configuration_map";
50 public static final String UID_OWNER_MAP_PATH =
51 "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map";
52 public static final String UID_PERMISSION_MAP_PATH =
53 "/sys/fs/bpf/netd_shared/map_netd_uid_permission_map";
54 public static final String COOKIE_TAG_MAP_PATH =
55 "/sys/fs/bpf/netd_shared/map_netd_cookie_tag_map";
Ken Chen24330172023-10-20 13:02:14 +080056 public static final String DATA_SAVER_ENABLED_MAP_PATH =
57 "/sys/fs/bpf/netd_shared/map_netd_data_saver_enabled_map";
Motomu Utsumi77b49992023-10-23 17:06:12 +090058 public static final String INGRESS_DISCARD_MAP_PATH =
59 "/sys/fs/bpf/netd_shared/map_netd_ingress_discard_map";
Junyu Lai29b7b632023-08-23 17:35:17 +080060 public static final Struct.S32 UID_RULES_CONFIGURATION_KEY = new Struct.S32(0);
61 public static final Struct.S32 CURRENT_STATS_MAP_CONFIGURATION_KEY = new Struct.S32(1);
Ken Chen24330172023-10-20 13:02:14 +080062 public static final Struct.S32 DATA_SAVER_ENABLED_KEY = new Struct.S32(0);
63
64 public static final short DATA_SAVER_DISABLED = 0;
65 public static final short DATA_SAVER_ENABLED = 1;
Junyu Lai29b7b632023-08-23 17:35:17 +080066
67 // LINT.IfChange(match_type)
68 public static final long NO_MATCH = 0;
69 public static final long HAPPY_BOX_MATCH = (1 << 0);
70 public static final long PENALTY_BOX_MATCH = (1 << 1);
71 public static final long DOZABLE_MATCH = (1 << 2);
72 public static final long STANDBY_MATCH = (1 << 3);
73 public static final long POWERSAVE_MATCH = (1 << 4);
74 public static final long RESTRICTED_MATCH = (1 << 5);
75 public static final long LOW_POWER_STANDBY_MATCH = (1 << 6);
76 public static final long IIF_MATCH = (1 << 7);
77 public static final long LOCKDOWN_VPN_MATCH = (1 << 8);
78 public static final long OEM_DENY_1_MATCH = (1 << 9);
79 public static final long OEM_DENY_2_MATCH = (1 << 10);
80 public static final long OEM_DENY_3_MATCH = (1 << 11);
Suprabh Shukla2d893b62023-11-06 08:47:40 -080081 public static final long BACKGROUND_MATCH = (1 << 12);
Junyu Lai29b7b632023-08-23 17:35:17 +080082
83 public static final List<Pair<Long, String>> MATCH_LIST = Arrays.asList(
84 Pair.create(HAPPY_BOX_MATCH, "HAPPY_BOX_MATCH"),
85 Pair.create(PENALTY_BOX_MATCH, "PENALTY_BOX_MATCH"),
86 Pair.create(DOZABLE_MATCH, "DOZABLE_MATCH"),
87 Pair.create(STANDBY_MATCH, "STANDBY_MATCH"),
88 Pair.create(POWERSAVE_MATCH, "POWERSAVE_MATCH"),
89 Pair.create(RESTRICTED_MATCH, "RESTRICTED_MATCH"),
90 Pair.create(LOW_POWER_STANDBY_MATCH, "LOW_POWER_STANDBY_MATCH"),
91 Pair.create(IIF_MATCH, "IIF_MATCH"),
92 Pair.create(LOCKDOWN_VPN_MATCH, "LOCKDOWN_VPN_MATCH"),
93 Pair.create(OEM_DENY_1_MATCH, "OEM_DENY_1_MATCH"),
94 Pair.create(OEM_DENY_2_MATCH, "OEM_DENY_2_MATCH"),
Suprabh Shukla2d893b62023-11-06 08:47:40 -080095 Pair.create(OEM_DENY_3_MATCH, "OEM_DENY_3_MATCH"),
96 Pair.create(BACKGROUND_MATCH, "BACKGROUND_MATCH")
Junyu Lai29b7b632023-08-23 17:35:17 +080097 );
Junyu Laie0031522023-08-29 18:32:57 +080098
99 /**
100 * List of all firewall allow chains.
101 *
102 * Allow chains mean the firewall denies all uids by default, uids must be explicitly allowed.
103 */
104 public static final List<Integer> ALLOW_CHAINS = List.of(
105 FIREWALL_CHAIN_DOZABLE,
106 FIREWALL_CHAIN_POWERSAVE,
107 FIREWALL_CHAIN_RESTRICTED,
Suprabh Shukla2d893b62023-11-06 08:47:40 -0800108 FIREWALL_CHAIN_LOW_POWER_STANDBY,
109 FIREWALL_CHAIN_BACKGROUND
Junyu Laie0031522023-08-29 18:32:57 +0800110 );
111
112 /**
113 * List of all firewall deny chains.
114 *
115 * Deny chains mean the firewall allows all uids by default, uids must be explicitly denied.
116 */
117 public static final List<Integer> DENY_CHAINS = List.of(
118 FIREWALL_CHAIN_STANDBY,
119 FIREWALL_CHAIN_OEM_DENY_1,
120 FIREWALL_CHAIN_OEM_DENY_2,
121 FIREWALL_CHAIN_OEM_DENY_3
122 );
123 // LINT.ThenChange(../../../../bpf_progs/netd.h)
Junyu Lai29b7b632023-08-23 17:35:17 +0800124}