blob: 07208243a4a7ac6653455fb8b2208a6d70126c3c [file] [log] [blame]
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -07001/*
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
Bernie Innocenti762dcf42019-06-14 19:52:49 +090017#pragma once
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070018
19#include "Network.h"
20#include "Permission.h"
21
Bernie Innocenti762dcf42019-06-14 19:52:49 +090022namespace android::net {
Lorenzo Colitti7035f222017-02-13 18:29:00 +090023
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070024class PhysicalNetwork : public Network {
Bernie Innocenti762dcf42019-06-14 19:52:49 +090025 public:
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070026 class Delegate {
Bernie Innocenti762dcf42019-06-14 19:52:49 +090027 public:
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070028 virtual ~Delegate();
29
Bernie Innocenti762dcf42019-06-14 19:52:49 +090030 [[nodiscard]] virtual int addFallthrough(const std::string& physicalInterface,
31 Permission permission) = 0;
32 [[nodiscard]] virtual int removeFallthrough(const std::string& physicalInterface,
33 Permission permission) = 0;
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070034 };
35
36 PhysicalNetwork(unsigned netId, Delegate* delegate);
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070037 virtual ~PhysicalNetwork();
38
39 // These refer to permissions that apps must have in order to use this network.
40 Permission getPermission() const;
Bernie Innocenti762dcf42019-06-14 19:52:49 +090041 [[nodiscard]] int setPermission(Permission permission);
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070042
Bernie Innocenti762dcf42019-06-14 19:52:49 +090043 [[nodiscard]] int addAsDefault();
44 [[nodiscard]] int removeAsDefault();
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070045
Bernie Innocenti762dcf42019-06-14 19:52:49 +090046 private:
Sreeram Ramachandrane09b20a2014-07-05 17:15:14 -070047 Type getType() const override;
Bernie Innocenti762dcf42019-06-14 19:52:49 +090048 [[nodiscard]] int addInterface(const std::string& interface) override;
49 [[nodiscard]] int removeInterface(const std::string& interface) override;
Lorenzo Colittic6201c32016-09-14 02:25:05 +090050 int destroySocketsLackingPermission(Permission permission);
Lorenzo Colitti4662e162017-09-08 11:31:59 +090051 void invalidateRouteCache(const std::string& interface);
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070052
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070053 Delegate* const mDelegate;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070054 Permission mPermission;
55 bool mIsDefault;
56};
57
Bernie Innocenti762dcf42019-06-14 19:52:49 +090058} // namespace android::net