Ken Chen | c52cbe0 | 2022-07-29 03:30:25 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 17 | |
| 18 | #pragma once |
| 19 | |
| 20 | #include <android-base/thread_annotations.h> |
Maciej Żenczykowski | 04fb386 | 2024-06-15 00:14:16 +0000 | [diff] [blame] | 21 | #define BPF_MAP_LOCKLESS_FOR_TEST |
Ken Chen | c52cbe0 | 2022-07-29 03:30:25 +0800 | [diff] [blame] | 22 | #include <bpf/BpfMap.h> |
Maciej Żenczykowski | 513474c | 2022-12-08 16:20:43 +0000 | [diff] [blame] | 23 | #include "netd.h" |
Ken Chen | c52cbe0 | 2022-07-29 03:30:25 +0800 | [diff] [blame] | 24 | |
| 25 | using android::base::Result; |
| 26 | using android::bpf::BpfMap; |
| 27 | |
| 28 | class Firewall { |
| 29 | public: |
| 30 | Firewall() EXCLUDES(mMutex); |
| 31 | static Firewall* getInstance(); |
| 32 | Result<void> toggleStandbyMatch(bool enable) EXCLUDES(mMutex); |
| 33 | Result<void> addRule(uint32_t uid, UidOwnerMatchType match, uint32_t iif = 0) EXCLUDES(mMutex); |
| 34 | Result<void> removeRule(uint32_t uid, UidOwnerMatchType match) EXCLUDES(mMutex); |
| 35 | Result<void> addUidInterfaceRules(const std::string& ifName, const std::vector<int32_t>& uids); |
| 36 | Result<void> removeUidInterfaceRules(const std::vector<int32_t>& uids); |
Ken Chen | 5b144a1 | 2023-10-26 14:00:23 +0800 | [diff] [blame] | 37 | Result<bool> getDataSaverSetting(); |
| 38 | Result<void> setDataSaver(bool enabled); |
Ken Chen | c52cbe0 | 2022-07-29 03:30:25 +0800 | [diff] [blame] | 39 | private: |
| 40 | BpfMap<uint32_t, uint32_t> mConfigurationMap GUARDED_BY(mMutex); |
| 41 | BpfMap<uint32_t, UidOwnerValue> mUidOwnerMap GUARDED_BY(mMutex); |
Ken Chen | 5b144a1 | 2023-10-26 14:00:23 +0800 | [diff] [blame] | 42 | BpfMap<uint32_t, bool> mDataSaverEnabledMap GUARDED_BY(mMutex); |
Ken Chen | c52cbe0 | 2022-07-29 03:30:25 +0800 | [diff] [blame] | 43 | std::mutex mMutex; |
| 44 | }; |