blob: 7166e0ea0677e4fdbe26b92c1e16edbc2c7a89d8 [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
Chalard Jean04845142022-12-02 19:39:36 +090036 PhysicalNetwork(unsigned netId, Delegate* delegate, bool local);
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();
Ken Chen53360bf2021-12-10 02:41:05 +080045 [[nodiscard]] int addUsers(const UidRanges& uidRanges, int32_t subPriority) override;
46 [[nodiscard]] int removeUsers(const UidRanges& uidRanges, int32_t subPriority) override;
Ken Chen6559f1a2021-03-30 16:29:50 +080047 bool isPhysical() override { return true; }
48 bool canAddUsers() override { return true; }
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070049
Bernie Innocenti762dcf42019-06-14 19:52:49 +090050 private:
Ken Chen2f661522021-03-30 19:41:49 +080051 std::string getTypeString() const override { return "PHYSICAL"; };
Bernie Innocenti762dcf42019-06-14 19:52:49 +090052 [[nodiscard]] int addInterface(const std::string& interface) override;
53 [[nodiscard]] int removeInterface(const std::string& interface) override;
Lorenzo Colittic6201c32016-09-14 02:25:05 +090054 int destroySocketsLackingPermission(Permission permission);
Lorenzo Colitti4662e162017-09-08 11:31:59 +090055 void invalidateRouteCache(const std::string& interface);
Ken Chen53360bf2021-12-10 02:41:05 +080056 bool isValidSubPriority(int32_t priority) override;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070057
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070058 Delegate* const mDelegate;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070059 Permission mPermission;
60 bool mIsDefault;
Chalard Jean04845142022-12-02 19:39:36 +090061 const bool mIsLocalNetwork;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070062};
63
Bernie Innocenti762dcf42019-06-14 19:52:49 +090064} // namespace android::net