1*8542734aSAndroid Build Coastguard Worker /* 2*8542734aSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project 3*8542734aSAndroid Build Coastguard Worker * 4*8542734aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*8542734aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*8542734aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*8542734aSAndroid Build Coastguard Worker * 8*8542734aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*8542734aSAndroid Build Coastguard Worker * 10*8542734aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*8542734aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*8542734aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*8542734aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*8542734aSAndroid Build Coastguard Worker * limitations under the License. 15*8542734aSAndroid Build Coastguard Worker */ 16*8542734aSAndroid Build Coastguard Worker 17*8542734aSAndroid Build Coastguard Worker #ifndef NETD_SERVER_UID_RANGES_H 18*8542734aSAndroid Build Coastguard Worker #define NETD_SERVER_UID_RANGES_H 19*8542734aSAndroid Build Coastguard Worker 20*8542734aSAndroid Build Coastguard Worker #include "android/net/INetd.h" 21*8542734aSAndroid Build Coastguard Worker 22*8542734aSAndroid Build Coastguard Worker #include <sys/types.h> 23*8542734aSAndroid Build Coastguard Worker #include <utility> 24*8542734aSAndroid Build Coastguard Worker #include <vector> 25*8542734aSAndroid Build Coastguard Worker 26*8542734aSAndroid Build Coastguard Worker namespace android { 27*8542734aSAndroid Build Coastguard Worker namespace net { 28*8542734aSAndroid Build Coastguard Worker 29*8542734aSAndroid Build Coastguard Worker class UidRanges { 30*8542734aSAndroid Build Coastguard Worker public: 31*8542734aSAndroid Build Coastguard Worker static constexpr int SUB_PRIORITY_HIGHEST = 0; 32*8542734aSAndroid Build Coastguard Worker static constexpr int SUB_PRIORITY_LOWEST = 998; 33*8542734aSAndroid Build Coastguard Worker // "Special" value used for giving UIDs access to a network (by installing explicit and implicit 34*8542734aSAndroid Build Coastguard Worker // network rules) without automatically making that network default. This rule works in 35*8542734aSAndroid Build Coastguard Worker // conjunction with the other subpriorities, meaning that the network could still be configured 36*8542734aSAndroid Build Coastguard Worker // as the app's default using one of the lower values (0-998). 37*8542734aSAndroid Build Coastguard Worker // Note: SUB_PRIORITY_NO_DEFAULT *must* be SUB_PRIORITY_LOWEST + 1! 38*8542734aSAndroid Build Coastguard Worker static constexpr int SUB_PRIORITY_NO_DEFAULT = 999; 39*8542734aSAndroid Build Coastguard Worker UidRanges()40*8542734aSAndroid Build Coastguard Worker UidRanges() {} 41*8542734aSAndroid Build Coastguard Worker UidRanges(const std::vector<android::net::UidRangeParcel>& ranges); 42*8542734aSAndroid Build Coastguard Worker 43*8542734aSAndroid Build Coastguard Worker bool hasUid(uid_t uid) const; 44*8542734aSAndroid Build Coastguard Worker const std::vector<UidRangeParcel>& getRanges() const; 45*8542734aSAndroid Build Coastguard Worker 46*8542734aSAndroid Build Coastguard Worker bool parseFrom(int argc, char* argv[]); 47*8542734aSAndroid Build Coastguard Worker std::string toString() const; 48*8542734aSAndroid Build Coastguard Worker 49*8542734aSAndroid Build Coastguard Worker void add(const UidRanges& other); 50*8542734aSAndroid Build Coastguard Worker void remove(const UidRanges& other); 51*8542734aSAndroid Build Coastguard Worker 52*8542734aSAndroid Build Coastguard Worker // check if 'mRanges' has uid overlap between elements. 53*8542734aSAndroid Build Coastguard Worker bool overlapsSelf() const; 54*8542734aSAndroid Build Coastguard Worker empty()55*8542734aSAndroid Build Coastguard Worker bool empty() const { return mRanges.empty(); } 56*8542734aSAndroid Build Coastguard Worker 57*8542734aSAndroid Build Coastguard Worker private: 58*8542734aSAndroid Build Coastguard Worker std::vector<UidRangeParcel> mRanges; 59*8542734aSAndroid Build Coastguard Worker }; 60*8542734aSAndroid Build Coastguard Worker 61*8542734aSAndroid Build Coastguard Worker } // namespace net 62*8542734aSAndroid Build Coastguard Worker } // namespace android 63*8542734aSAndroid Build Coastguard Worker 64*8542734aSAndroid Build Coastguard Worker #endif // NETD_SERVER_UID_RANGES_H 65