Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.net; |
| 18 | |
Suprabh Shukla | 2d893b6 | 2023-11-06 08:47:40 -0800 | [diff] [blame] | 19 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_BACKGROUND; |
Junyu Lai | e003152 | 2023-08-29 18:32:57 +0800 | [diff] [blame] | 20 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE; |
| 21 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY; |
| 22 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1; |
| 23 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2; |
| 24 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3; |
| 25 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE; |
| 26 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED; |
| 27 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY; |
| 28 | |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 29 | import android.util.Pair; |
| 30 | |
| 31 | import com.android.net.module.util.Struct; |
| 32 | |
| 33 | import java.util.Arrays; |
| 34 | import 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. |
| 44 | public 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 Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame] | 56 | public static final String DATA_SAVER_ENABLED_MAP_PATH = |
| 57 | "/sys/fs/bpf/netd_shared/map_netd_data_saver_enabled_map"; |
Motomu Utsumi | 77b4999 | 2023-10-23 17:06:12 +0900 | [diff] [blame] | 58 | public static final String INGRESS_DISCARD_MAP_PATH = |
| 59 | "/sys/fs/bpf/netd_shared/map_netd_ingress_discard_map"; |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 60 | 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 Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame] | 62 | 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 Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 66 | |
| 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 Shukla | 2d893b6 | 2023-11-06 08:47:40 -0800 | [diff] [blame] | 81 | public static final long BACKGROUND_MATCH = (1 << 12); |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 82 | |
| 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 Shukla | 2d893b6 | 2023-11-06 08:47:40 -0800 | [diff] [blame] | 95 | Pair.create(OEM_DENY_3_MATCH, "OEM_DENY_3_MATCH"), |
| 96 | Pair.create(BACKGROUND_MATCH, "BACKGROUND_MATCH") |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 97 | ); |
Junyu Lai | e003152 | 2023-08-29 18:32:57 +0800 | [diff] [blame] | 98 | |
| 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 Shukla | 2d893b6 | 2023-11-06 08:47:40 -0800 | [diff] [blame] | 108 | FIREWALL_CHAIN_LOW_POWER_STANDBY, |
| 109 | FIREWALL_CHAIN_BACKGROUND |
Junyu Lai | e003152 | 2023-08-29 18:32:57 +0800 | [diff] [blame] | 110 | ); |
| 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 Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 124 | } |