2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "UidMarkMap.h"
18 #include "NetdConstants.h"
20 UidMarkMap::UidMarkEntry::UidMarkEntry(int start, int end, int new_mark) :
26 bool UidMarkMap::add(int uid_start, int uid_end, int mark) {
27 android::RWLock::AutoWLock lock(mRWLock);
28 if (uid_start > uid_end) {
32 UidMarkEntry *e = new UidMarkEntry(uid_start, uid_end, mark);
37 bool UidMarkMap::remove(int uid_start, int uid_end, int mark) {
38 android::RWLock::AutoWLock lock(mRWLock);
39 android::netd::List<UidMarkEntry*>::iterator it;
40 for (it = mMap.begin(); it != mMap.end(); it++) {
41 UidMarkEntry *entry = *it;
42 if (entry->uid_start == uid_start && entry->uid_end == uid_end && entry->mark == mark) {
51 int UidMarkMap::getMark(int uid) {
52 android::RWLock::AutoRLock lock(mRWLock);
53 android::netd::List<UidMarkEntry*>::iterator it;
54 for (it = mMap.begin(); it != mMap.end(); it++) {
55 UidMarkEntry *entry = *it;
56 if (entry->uid_start <= uid && entry->uid_end >= uid) {
60 // If the uid has no mark specified then it should be protected from any VPN rules that might
61 // be affecting the service acting on its behalf.
65 bool UidMarkMap::anyRulesForMark(int mark) {
66 android::RWLock::AutoRLock lock(mRWLock);
67 android::netd::List<UidMarkEntry*>::iterator it;
68 for (it = mMap.begin(); it != mMap.end(); it++) {
69 UidMarkEntry *entry = *it;
70 if (entry->mark == mark) {