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 #define LOG_TAG "Netd"
18*8542734aSAndroid Build Coastguard Worker
19*8542734aSAndroid Build Coastguard Worker #include "LocalNetwork.h"
20*8542734aSAndroid Build Coastguard Worker
21*8542734aSAndroid Build Coastguard Worker #include "RouteController.h"
22*8542734aSAndroid Build Coastguard Worker
23*8542734aSAndroid Build Coastguard Worker #include "log/log.h"
24*8542734aSAndroid Build Coastguard Worker
25*8542734aSAndroid Build Coastguard Worker namespace android {
26*8542734aSAndroid Build Coastguard Worker namespace net {
27*8542734aSAndroid Build Coastguard Worker
LocalNetwork(unsigned netId)28*8542734aSAndroid Build Coastguard Worker LocalNetwork::LocalNetwork(unsigned netId) : Network(netId) {
29*8542734aSAndroid Build Coastguard Worker }
30*8542734aSAndroid Build Coastguard Worker
~LocalNetwork()31*8542734aSAndroid Build Coastguard Worker LocalNetwork::~LocalNetwork() {
32*8542734aSAndroid Build Coastguard Worker }
33*8542734aSAndroid Build Coastguard Worker
addInterface(const std::string & interface)34*8542734aSAndroid Build Coastguard Worker int LocalNetwork::addInterface(const std::string& interface) {
35*8542734aSAndroid Build Coastguard Worker if (hasInterface(interface)) {
36*8542734aSAndroid Build Coastguard Worker return 0;
37*8542734aSAndroid Build Coastguard Worker }
38*8542734aSAndroid Build Coastguard Worker if (int ret = RouteController::addInterfaceToLocalNetwork(mNetId, interface.c_str())) {
39*8542734aSAndroid Build Coastguard Worker ALOGE("failed to add interface %s to local netId %u", interface.c_str(), mNetId);
40*8542734aSAndroid Build Coastguard Worker return ret;
41*8542734aSAndroid Build Coastguard Worker }
42*8542734aSAndroid Build Coastguard Worker mInterfaces.insert(interface);
43*8542734aSAndroid Build Coastguard Worker return 0;
44*8542734aSAndroid Build Coastguard Worker }
45*8542734aSAndroid Build Coastguard Worker
removeInterface(const std::string & interface)46*8542734aSAndroid Build Coastguard Worker int LocalNetwork::removeInterface(const std::string& interface) {
47*8542734aSAndroid Build Coastguard Worker if (!hasInterface(interface)) {
48*8542734aSAndroid Build Coastguard Worker return 0;
49*8542734aSAndroid Build Coastguard Worker }
50*8542734aSAndroid Build Coastguard Worker if (int ret = RouteController::removeInterfaceFromLocalNetwork(mNetId, interface.c_str())) {
51*8542734aSAndroid Build Coastguard Worker ALOGE("failed to remove interface %s from local netId %u", interface.c_str(), mNetId);
52*8542734aSAndroid Build Coastguard Worker return ret;
53*8542734aSAndroid Build Coastguard Worker }
54*8542734aSAndroid Build Coastguard Worker mInterfaces.erase(interface);
55*8542734aSAndroid Build Coastguard Worker return 0;
56*8542734aSAndroid Build Coastguard Worker }
57*8542734aSAndroid Build Coastguard Worker
58*8542734aSAndroid Build Coastguard Worker } // namespace net
59*8542734aSAndroid Build Coastguard Worker } // namespace android
60