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