• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef INCLUDE_VIRTUAL_NETWORK_H
17 #define INCLUDE_VIRTUAL_NETWORK_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include <sys/types.h>
27 
28 #include "netsys_network.h"
29 #include "network_permission.h"
30 #include "uid_range.h"
31 
32 namespace OHOS {
33 namespace nmd {
34 using namespace NetManagerStandard;
35 class VirtualNetwork : public NetsysNetwork {
36 public:
37     VirtualNetwork(uint16_t netId, bool hasDns);
38     virtual ~VirtualNetwork() = default;
39 
40     /**
41      * Judge network type whether or not physical
42      *
43      * @return Returns true physical
44      */
IsPhysical()45     bool IsPhysical() override
46     {
47         return false;
48     }
49 
50     bool GetHasDns() const;
51 
52     int32_t AddUids(const std::vector<UidRange> &uidRanges);
53     int32_t RemoveUids(const std::vector<UidRange> &uidRanges);
54 
55 private:
GetNetworkType()56     std::string GetNetworkType() const override
57     {
58         return "VIRTUAL";
59     };
60 
61     int32_t AddInterface(std::string &interfaceName) override;
62     int32_t RemoveInterface(std::string &interfaceName) override;
63 
64 private:
65     const bool hasDns_ = false;
66     std::vector<UidRange> uidRanges_;
67     std::mutex mutex_;
68 };
69 } // namespace nmd
70 } // namespace OHOS
71 #endif // INCLUDE_VIRTUAL_NETWORK_H
72