Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #ifndef NETD_SERVER_UID_RANGES_H |
| 18 | #define NETD_SERVER_UID_RANGES_H |
| 19 | |
Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 20 | #include "android/net/INetd.h" |
Robin Lee | 9f9aae9 | 2016-03-30 18:33:07 +0100 | [diff] [blame] | 21 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 22 | #include <sys/types.h> |
| 23 | #include <utility> |
| 24 | #include <vector> |
| 25 | |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace net { |
| 28 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 29 | class UidRanges { |
| 30 | public: |
Patrick Rohr | e2f1b5a | 2022-01-25 21:36:50 +0100 | [diff] [blame] | 31 | static constexpr int SUB_PRIORITY_HIGHEST = 0; |
Patrick Rohr | e6f198c | 2022-01-25 13:50:31 +0100 | [diff] [blame] | 32 | static constexpr int SUB_PRIORITY_LOWEST = 998; |
| 33 | // "Special" value used for giving UIDs access to a network (by installing explicit and implicit |
| 34 | // network rules) without automatically making that network default. This rule works in |
| 35 | // conjunction with the other subpriorities, meaning that the network could still be configured |
| 36 | // as the app's default using one of the lower values (0-998). |
| 37 | // Note: SUB_PRIORITY_NO_DEFAULT *must* be SUB_PRIORITY_LOWEST + 1! |
| 38 | static constexpr int SUB_PRIORITY_NO_DEFAULT = 999; |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 39 | |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 40 | UidRanges() {} |
Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 41 | UidRanges(const std::vector<android::net::UidRangeParcel>& ranges); |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 42 | |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 43 | bool hasUid(uid_t uid) const; |
Luke Huang | 94658ac | 2018-10-18 19:35:12 +0900 | [diff] [blame] | 44 | const std::vector<UidRangeParcel>& getRanges() const; |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 45 | |
| 46 | bool parseFrom(int argc, char* argv[]); |
Lorenzo Colitti | fff4bd3 | 2016-04-14 00:56:01 +0900 | [diff] [blame] | 47 | std::string toString() const; |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 48 | |
| 49 | void add(const UidRanges& other); |
| 50 | void remove(const UidRanges& other); |
| 51 | |
Ken Chen | 868ae63 | 2021-02-24 17:50:08 +0800 | [diff] [blame] | 52 | // check if 'mRanges' has uid overlap between elements. |
| 53 | bool overlapsSelf() const; |
chiachangwang | 65bc4ea | 2022-09-07 08:10:30 +0000 | [diff] [blame] | 54 | |
Ken Chen | 4ea8846 | 2021-05-23 14:56:43 +0800 | [diff] [blame] | 55 | bool empty() const { return mRanges.empty(); } |
Ken Chen | 868ae63 | 2021-02-24 17:50:08 +0800 | [diff] [blame] | 56 | |
Luke Huang | 7720e4a | 2019-02-20 15:09:28 +0800 | [diff] [blame] | 57 | private: |
| 58 | std::vector<UidRangeParcel> mRanges; |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 61 | } // namespace net |
| 62 | } // namespace android |
| 63 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 64 | #endif // NETD_SERVER_UID_RANGES_H |