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 20 #include "android/net/INetd.h" 21 22 #include <sys/types.h> 23 #include <utility> 24 #include <vector> 25 26 namespace android { 27 namespace net { 28 29 class UidRanges { 30 public: 31 static constexpr int SUB_PRIORITY_HIGHEST = 0; 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; 39 UidRanges()40 UidRanges() {} 41 UidRanges(const std::vector<android::net::UidRangeParcel>& ranges); 42 43 bool hasUid(uid_t uid) const; 44 const std::vector<UidRangeParcel>& getRanges() const; 45 46 bool parseFrom(int argc, char* argv[]); 47 std::string toString() const; 48 49 void add(const UidRanges& other); 50 void remove(const UidRanges& other); 51 52 // check if 'mRanges' has uid overlap between elements. 53 bool overlapsSelf() const; 54 empty()55 bool empty() const { return mRanges.empty(); } 56 57 private: 58 std::vector<UidRangeParcel> mRanges; 59 }; 60 61 } // namespace net 62 } // namespace android 63 64 #endif // NETD_SERVER_UID_RANGES_H 65