1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License.
5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at
6b1b8bc3fSopenharmony_ci *
7b1b8bc3fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b1b8bc3fSopenharmony_ci *
9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and
13b1b8bc3fSopenharmony_ci * limitations under the License.
14b1b8bc3fSopenharmony_ci */
15b1b8bc3fSopenharmony_ci
16b1b8bc3fSopenharmony_ci#ifndef NET_DISTRIBUTED_MANAGER_H
17b1b8bc3fSopenharmony_ci#define NET_DISTRIBUTED_MANAGER_H
18b1b8bc3fSopenharmony_ci
19b1b8bc3fSopenharmony_ci#include "uid_range.h"
20b1b8bc3fSopenharmony_ci#include <cstdint>
21b1b8bc3fSopenharmony_ci#include <linux/if.h>
22b1b8bc3fSopenharmony_ci#include <map>
23b1b8bc3fSopenharmony_ci#include <set>
24b1b8bc3fSopenharmony_ci#include <string>
25b1b8bc3fSopenharmony_ci
26b1b8bc3fSopenharmony_cinamespace OHOS {
27b1b8bc3fSopenharmony_cinamespace NetManagerStandard {
28b1b8bc3fSopenharmony_ci
29b1b8bc3fSopenharmony_ciclass DistributedManager {
30b1b8bc3fSopenharmony_cipublic:
31b1b8bc3fSopenharmony_ci    static DistributedManager &GetInstance()
32b1b8bc3fSopenharmony_ci    {
33b1b8bc3fSopenharmony_ci        static DistributedManager instance;
34b1b8bc3fSopenharmony_ci        return instance;
35b1b8bc3fSopenharmony_ci    }
36b1b8bc3fSopenharmony_ci
37b1b8bc3fSopenharmony_cipublic:
38b1b8bc3fSopenharmony_ci    int32_t CreateDistributedNic(const std::string &virNicAddr, const std::string &ifName);
39b1b8bc3fSopenharmony_ci    int32_t DestroyDistributedNic(const std::string &ifName);
40b1b8bc3fSopenharmony_ci    int32_t CreateDistributedInterface(const std::string &ifName);
41b1b8bc3fSopenharmony_ci    int32_t SetDistributedNicMtu(const std::string &ifName, int32_t mtu);
42b1b8bc3fSopenharmony_ci    int32_t SetDistributedNicAddress(const std::string &ifName, const std::string &tunAddr);
43b1b8bc3fSopenharmony_ci    void SetServerNicInfo(const std::string &iif, const std::string &devIface);
44b1b8bc3fSopenharmony_ci    void CloseDistributedTunFd();
45b1b8bc3fSopenharmony_ci    std::string GetServerIifNic();
46b1b8bc3fSopenharmony_ci    std::string GetServerDevIfaceNic();
47b1b8bc3fSopenharmony_ci
48b1b8bc3fSopenharmony_ciprivate:
49b1b8bc3fSopenharmony_ci    DistributedManager() = default;
50b1b8bc3fSopenharmony_ci    ~DistributedManager() = default;
51b1b8bc3fSopenharmony_ci    DistributedManager(const DistributedManager &) = delete;
52b1b8bc3fSopenharmony_ci    DistributedManager &operator=(const DistributedManager &) = delete;
53b1b8bc3fSopenharmony_ci
54b1b8bc3fSopenharmony_ciprivate:
55b1b8bc3fSopenharmony_ci    int32_t SetDistributedNicUp(const std::string &ifName);
56b1b8bc3fSopenharmony_ci    int32_t SetDistributedNicDown(const std::string &ifName);
57b1b8bc3fSopenharmony_ci    int32_t InitIfreq(ifreq &ifr, const std::string &cardName);
58b1b8bc3fSopenharmony_ci    int32_t SetDistributedNicResult(std::atomic_int &fd, unsigned long cmd, ifreq &ifr);
59b1b8bc3fSopenharmony_ci    void CloseDistributedSocket();
60b1b8bc3fSopenharmony_ci
61b1b8bc3fSopenharmony_ciprivate:
62b1b8bc3fSopenharmony_ci    std::atomic_int tunFd_ = 0;
63b1b8bc3fSopenharmony_ci    std::atomic_int net4Sock_ = 0;
64b1b8bc3fSopenharmony_ci    std::string serverIif_;
65b1b8bc3fSopenharmony_ci    std::string serverDevIface_;
66b1b8bc3fSopenharmony_ci};
67b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard
68b1b8bc3fSopenharmony_ci} // namespace OHOS
69b1b8bc3fSopenharmony_ci#endif // NET_DISTRIBUTED_MANAGER_H
70