1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (c) 2021-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#include <arpa/inet.h>
17b1b8bc3fSopenharmony_ci#include <cstring>
18b1b8bc3fSopenharmony_ci#include <fcntl.h>
19b1b8bc3fSopenharmony_ci#include <linux/if_tun.h>
20b1b8bc3fSopenharmony_ci#include <netinet/in.h>
21b1b8bc3fSopenharmony_ci#include <sys/ioctl.h>
22b1b8bc3fSopenharmony_ci#include <sys/socket.h>
23b1b8bc3fSopenharmony_ci#include <sys/types.h>
24b1b8bc3fSopenharmony_ci#include <thread>
25b1b8bc3fSopenharmony_ci#include <pthread.h>
26b1b8bc3fSopenharmony_ci#include <unistd.h>
27b1b8bc3fSopenharmony_ci
28b1b8bc3fSopenharmony_ci#include "iservice_registry.h"
29b1b8bc3fSopenharmony_ci#include "system_ability_definition.h"
30b1b8bc3fSopenharmony_ci
31b1b8bc3fSopenharmony_ci#include "net_conn_constants.h"
32b1b8bc3fSopenharmony_ci#include "net_conn_types.h"
33b1b8bc3fSopenharmony_ci#include "net_manager_constants.h"
34b1b8bc3fSopenharmony_ci#include "net_mgr_log_wrapper.h"
35b1b8bc3fSopenharmony_ci#include "netmanager_base_common_utils.h"
36b1b8bc3fSopenharmony_ci#include "netsys_native_client.h"
37b1b8bc3fSopenharmony_ci#include "netsys_native_service_proxy.h"
38b1b8bc3fSopenharmony_ci#include "ipc_skeleton.h"
39b1b8bc3fSopenharmony_ci
40b1b8bc3fSopenharmony_ciusing namespace OHOS::NetManagerStandard::CommonUtils;
41b1b8bc3fSopenharmony_cinamespace OHOS {
42b1b8bc3fSopenharmony_cinamespace NetManagerStandard {
43b1b8bc3fSopenharmony_cistatic constexpr const char *DEV_NET_TUN_PATH = "/dev/net/tun";
44b1b8bc3fSopenharmony_cistatic constexpr const char *IF_CFG_UP = "up";
45b1b8bc3fSopenharmony_cistatic constexpr const char *IF_CFG_DOWN = "down";
46b1b8bc3fSopenharmony_cistatic constexpr const char *NETSYS_ROUTE_INIT_DIR_PATH = "/data/service/el1/public/netmanager/route";
47b1b8bc3fSopenharmony_cistatic constexpr uint32_t WAIT_FOR_SERVICE_TIME_S = 1;
48b1b8bc3fSopenharmony_cistatic constexpr uint32_t MAX_GET_SERVICE_COUNT = 30;
49b1b8bc3fSopenharmony_cistatic constexpr uint32_t IPV4_MAX_LENGTH = 32;
50b1b8bc3fSopenharmony_cistatic constexpr int UID_FOUNDATION = 5523;
51b1b8bc3fSopenharmony_ci
52b1b8bc3fSopenharmony_ciNetsysNativeClient::NativeNotifyCallback::NativeNotifyCallback(NetsysNativeClient &netsysNativeClient)
53b1b8bc3fSopenharmony_ci    : netsysNativeClient_(netsysNativeClient)
54b1b8bc3fSopenharmony_ci{
55b1b8bc3fSopenharmony_ci}
56b1b8bc3fSopenharmony_ci
57b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceAddressUpdated(const std::string &addr,
58b1b8bc3fSopenharmony_ci                                                                            const std::string &ifName, int flags,
59b1b8bc3fSopenharmony_ci                                                                            int scope)
60b1b8bc3fSopenharmony_ci{
61b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
62b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
63b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
64b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
65b1b8bc3fSopenharmony_ci        } else {
66b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceAddressUpdated(addr, ifName, flags, scope);
67b1b8bc3fSopenharmony_ci            ++cb;
68b1b8bc3fSopenharmony_ci        }
69b1b8bc3fSopenharmony_ci    }
70b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
71b1b8bc3fSopenharmony_ci}
72b1b8bc3fSopenharmony_ci
73b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceAddressRemoved(const std::string &addr,
74b1b8bc3fSopenharmony_ci                                                                            const std::string &ifName, int flags,
75b1b8bc3fSopenharmony_ci                                                                            int scope)
76b1b8bc3fSopenharmony_ci{
77b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
78b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
79b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
80b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
81b1b8bc3fSopenharmony_ci        } else {
82b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceAddressRemoved(addr, ifName, flags, scope);
83b1b8bc3fSopenharmony_ci            ++cb;
84b1b8bc3fSopenharmony_ci        }
85b1b8bc3fSopenharmony_ci    }
86b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
87b1b8bc3fSopenharmony_ci}
88b1b8bc3fSopenharmony_ci
89b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceAdded(const std::string &ifName)
90b1b8bc3fSopenharmony_ci{
91b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
92b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
93b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
94b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
95b1b8bc3fSopenharmony_ci        } else {
96b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceAdded(ifName);
97b1b8bc3fSopenharmony_ci            ++cb;
98b1b8bc3fSopenharmony_ci        }
99b1b8bc3fSopenharmony_ci    }
100b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
101b1b8bc3fSopenharmony_ci}
102b1b8bc3fSopenharmony_ci
103b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceRemoved(const std::string &ifName)
104b1b8bc3fSopenharmony_ci{
105b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
106b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
107b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
108b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
109b1b8bc3fSopenharmony_ci        } else {
110b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceRemoved(ifName);
111b1b8bc3fSopenharmony_ci            ++cb;
112b1b8bc3fSopenharmony_ci        }
113b1b8bc3fSopenharmony_ci    }
114b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
115b1b8bc3fSopenharmony_ci}
116b1b8bc3fSopenharmony_ci
117b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceChanged(const std::string &ifName, bool up)
118b1b8bc3fSopenharmony_ci{
119b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
120b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
121b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
122b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
123b1b8bc3fSopenharmony_ci        } else {
124b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceChanged(ifName, up);
125b1b8bc3fSopenharmony_ci            ++cb;
126b1b8bc3fSopenharmony_ci        }
127b1b8bc3fSopenharmony_ci    }
128b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
129b1b8bc3fSopenharmony_ci}
130b1b8bc3fSopenharmony_ci
131b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnInterfaceLinkStateChanged(const std::string &ifName, bool up)
132b1b8bc3fSopenharmony_ci{
133b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
134b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
135b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
136b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
137b1b8bc3fSopenharmony_ci        } else {
138b1b8bc3fSopenharmony_ci            (*cb)->OnInterfaceLinkStateChanged(ifName, up);
139b1b8bc3fSopenharmony_ci            ++cb;
140b1b8bc3fSopenharmony_ci        }
141b1b8bc3fSopenharmony_ci    }
142b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
143b1b8bc3fSopenharmony_ci}
144b1b8bc3fSopenharmony_ci
145b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnRouteChanged(bool updated, const std::string &route,
146b1b8bc3fSopenharmony_ci                                                                 const std::string &gateway, const std::string &ifName)
147b1b8bc3fSopenharmony_ci{
148b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbObjMutex_);
149b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbObjects_.begin(); cb != netsysNativeClient_.cbObjects_.end();) {
150b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
151b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbObjects_.erase(cb);
152b1b8bc3fSopenharmony_ci        } else {
153b1b8bc3fSopenharmony_ci            (*cb)->OnRouteChanged(updated, route, gateway, ifName);
154b1b8bc3fSopenharmony_ci            ++cb;
155b1b8bc3fSopenharmony_ci        }
156b1b8bc3fSopenharmony_ci    }
157b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
158b1b8bc3fSopenharmony_ci}
159b1b8bc3fSopenharmony_ci
160b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnDhcpSuccess(sptr<OHOS::NetsysNative::DhcpResultParcel> &dhcpResult)
161b1b8bc3fSopenharmony_ci{
162b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("OnDhcpSuccess");
163b1b8bc3fSopenharmony_ci    netsysNativeClient_.ProcessDhcpResult(dhcpResult);
164b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
165b1b8bc3fSopenharmony_ci}
166b1b8bc3fSopenharmony_ci
167b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNotifyCallback::OnBandwidthReachedLimit(const std::string &limitName,
168b1b8bc3fSopenharmony_ci                                                                          const std::string &iface)
169b1b8bc3fSopenharmony_ci{
170b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("OnBandwidthReachedLimit");
171b1b8bc3fSopenharmony_ci    netsysNativeClient_.ProcessBandwidthReachedLimit(limitName, iface);
172b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
173b1b8bc3fSopenharmony_ci}
174b1b8bc3fSopenharmony_ci
175b1b8bc3fSopenharmony_ciNetsysNativeClient::NativeNetDnsResultCallback::NativeNetDnsResultCallback(NetsysNativeClient &netsysNativeClient)
176b1b8bc3fSopenharmony_ci    : netsysNativeClient_(netsysNativeClient)
177b1b8bc3fSopenharmony_ci{
178b1b8bc3fSopenharmony_ci}
179b1b8bc3fSopenharmony_ci
180b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NativeNetDnsResultCallback::OnDnsResultReport(uint32_t size,
181b1b8bc3fSopenharmony_ci    std::list<OHOS::NetsysNative::NetDnsResultReport> res)
182b1b8bc3fSopenharmony_ci{
183b1b8bc3fSopenharmony_ci    std::lock_guard lock(netsysNativeClient_.cbDnsReportObjMutex_);
184b1b8bc3fSopenharmony_ci    for (auto cb = netsysNativeClient_.cbDnsReportObjects_.begin();
185b1b8bc3fSopenharmony_ci         cb != netsysNativeClient_.cbDnsReportObjects_.end();) {
186b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
187b1b8bc3fSopenharmony_ci            cb = netsysNativeClient_.cbDnsReportObjects_.erase(cb);
188b1b8bc3fSopenharmony_ci        } else {
189b1b8bc3fSopenharmony_ci            (*cb)->OnDnsResultReport(size, res);
190b1b8bc3fSopenharmony_ci            ++cb;
191b1b8bc3fSopenharmony_ci        }
192b1b8bc3fSopenharmony_ci    }
193b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
194b1b8bc3fSopenharmony_ci}
195b1b8bc3fSopenharmony_ci
196b1b8bc3fSopenharmony_ciNetsysNativeClient::NetsysNativeClient()
197b1b8bc3fSopenharmony_ci{
198b1b8bc3fSopenharmony_ci    RegisterNotifyCallback();
199b1b8bc3fSopenharmony_ci}
200b1b8bc3fSopenharmony_ci
201b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetInternetPermission(uint32_t uid, uint8_t allow)
202b1b8bc3fSopenharmony_ci{
203b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
204b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
205b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
206b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
207b1b8bc3fSopenharmony_ci    }
208b1b8bc3fSopenharmony_ci    auto callingUid = IPCSkeleton::GetCallingUid();
209b1b8bc3fSopenharmony_ci    return proxy->SetInternetPermission(uid, allow, callingUid != UID_FOUNDATION);
210b1b8bc3fSopenharmony_ci}
211b1b8bc3fSopenharmony_ci
212b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkCreatePhysical(int32_t netId, int32_t permission)
213b1b8bc3fSopenharmony_ci{
214b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Create Physical network: netId[%{public}d], permission[%{public}d]", netId, permission);
215b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
216b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
217b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
218b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
219b1b8bc3fSopenharmony_ci    }
220b1b8bc3fSopenharmony_ci    return proxy->NetworkCreatePhysical(netId, permission);
221b1b8bc3fSopenharmony_ci}
222b1b8bc3fSopenharmony_ci
223b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkCreateVirtual(int32_t netId, bool hasDns)
224b1b8bc3fSopenharmony_ci{
225b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Create Virtual network: netId[%{public}d], hasDns[%{public}d]", netId, hasDns);
226b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
227b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
228b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
229b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
230b1b8bc3fSopenharmony_ci    }
231b1b8bc3fSopenharmony_ci    return proxy->NetworkCreateVirtual(netId, hasDns);
232b1b8bc3fSopenharmony_ci}
233b1b8bc3fSopenharmony_ci
234b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkDestroy(int32_t netId)
235b1b8bc3fSopenharmony_ci{
236b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Destroy network: netId[%{public}d]", netId);
237b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
238b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
239b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
240b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
241b1b8bc3fSopenharmony_ci    }
242b1b8bc3fSopenharmony_ci    return proxy->NetworkDestroy(netId);
243b1b8bc3fSopenharmony_ci}
244b1b8bc3fSopenharmony_ci
245b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix,
246b1b8bc3fSopenharmony_ci                                       const std::set<int32_t> &uids)
247b1b8bc3fSopenharmony_ci{
248b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Create vnic");
249b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
250b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
251b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
252b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
253b1b8bc3fSopenharmony_ci    }
254b1b8bc3fSopenharmony_ci    return proxy->CreateVnic(mtu, tunAddr, prefix, uids);
255b1b8bc3fSopenharmony_ci}
256b1b8bc3fSopenharmony_ci
257b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DestroyVnic()
258b1b8bc3fSopenharmony_ci{
259b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Destroy vnic");
260b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
261b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
262b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
263b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
264b1b8bc3fSopenharmony_ci    }
265b1b8bc3fSopenharmony_ci    return proxy->DestroyVnic();
266b1b8bc3fSopenharmony_ci}
267b1b8bc3fSopenharmony_ci
268b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::EnableDistributedClientNet(const std::string &virnicAddr, const std::string &iif)
269b1b8bc3fSopenharmony_ci{
270b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
271b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
272b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
273b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
274b1b8bc3fSopenharmony_ci    }
275b1b8bc3fSopenharmony_ci    return proxy->EnableDistributedClientNet(virnicAddr, iif);
276b1b8bc3fSopenharmony_ci}
277b1b8bc3fSopenharmony_ci
278b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::EnableDistributedServerNet(const std::string &iif, const std::string &devIface,
279b1b8bc3fSopenharmony_ci                                                       const std::string &dstAddr)
280b1b8bc3fSopenharmony_ci{
281b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
282b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
283b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
284b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
285b1b8bc3fSopenharmony_ci    }
286b1b8bc3fSopenharmony_ci    return proxy->EnableDistributedServerNet(iif, devIface, dstAddr);
287b1b8bc3fSopenharmony_ci}
288b1b8bc3fSopenharmony_ci
289b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DisableDistributedNet(bool isServer)
290b1b8bc3fSopenharmony_ci{
291b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
292b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
293b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
294b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
295b1b8bc3fSopenharmony_ci    }
296b1b8bc3fSopenharmony_ci    return proxy->DisableDistributedNet(isServer);
297b1b8bc3fSopenharmony_ci}
298b1b8bc3fSopenharmony_ci
299b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges)
300b1b8bc3fSopenharmony_ci{
301b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Add uids to vpn network: netId[%{public}d]", netId);
302b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
303b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
304b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
305b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
306b1b8bc3fSopenharmony_ci    }
307b1b8bc3fSopenharmony_ci    return proxy->NetworkAddUids(netId, uidRanges);
308b1b8bc3fSopenharmony_ci}
309b1b8bc3fSopenharmony_ci
310b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges)
311b1b8bc3fSopenharmony_ci{
312b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Remove uids from vpn network: netId[%{public}d]", netId);
313b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
314b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
315b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
316b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
317b1b8bc3fSopenharmony_ci    }
318b1b8bc3fSopenharmony_ci    return proxy->NetworkDelUids(netId, uidRanges);
319b1b8bc3fSopenharmony_ci}
320b1b8bc3fSopenharmony_ci
321b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType)
322b1b8bc3fSopenharmony_ci{
323b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Add network interface: netId[%{public}d], iface[%{public}s, bearerType[%{public}u]]", netId,
324b1b8bc3fSopenharmony_ci                 iface.c_str(), netBearerType);
325b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
326b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
327b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
328b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
329b1b8bc3fSopenharmony_ci    }
330b1b8bc3fSopenharmony_ci    return proxy->NetworkAddInterface(netId, iface, netBearerType);
331b1b8bc3fSopenharmony_ci}
332b1b8bc3fSopenharmony_ci
333b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkRemoveInterface(int32_t netId, const std::string &iface)
334b1b8bc3fSopenharmony_ci{
335b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Remove network interface: netId[%{public}d], iface[%{public}s]", netId, iface.c_str());
336b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
337b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
338b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
339b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
340b1b8bc3fSopenharmony_ci    }
341b1b8bc3fSopenharmony_ci    return proxy->NetworkRemoveInterface(netId, iface);
342b1b8bc3fSopenharmony_ci}
343b1b8bc3fSopenharmony_ci
344b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkAddRoute(int32_t netId, const std::string &ifName, const std::string &destination,
345b1b8bc3fSopenharmony_ci                                            const std::string &nextHop)
346b1b8bc3fSopenharmony_ci{
347b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Add Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
348b1b8bc3fSopenharmony_ci                 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
349b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
350b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
351b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
352b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
353b1b8bc3fSopenharmony_ci    }
354b1b8bc3fSopenharmony_ci    return proxy->NetworkAddRoute(netId, ifName, destination, nextHop);
355b1b8bc3fSopenharmony_ci}
356b1b8bc3fSopenharmony_ci
357b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetworkRemoveRoute(int32_t netId, const std::string &ifName, const std::string &destination,
358b1b8bc3fSopenharmony_ci                                               const std::string &nextHop)
359b1b8bc3fSopenharmony_ci{
360b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Remove Route: netId[%{public}d], ifName[%{public}s], destination[%{public}s], nextHop[%{public}s]",
361b1b8bc3fSopenharmony_ci                 netId, ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
362b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
363b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
364b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
365b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
366b1b8bc3fSopenharmony_ci    }
367b1b8bc3fSopenharmony_ci    return proxy->NetworkRemoveRoute(netId, ifName, destination, nextHop);
368b1b8bc3fSopenharmony_ci}
369b1b8bc3fSopenharmony_ci
370b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetInterfaceConfig(OHOS::nmd::InterfaceConfigurationParcel &cfg)
371b1b8bc3fSopenharmony_ci{
372b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Get interface config: ifName[%{public}s]", cfg.ifName.c_str());
373b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
374b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
375b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
376b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
377b1b8bc3fSopenharmony_ci    }
378b1b8bc3fSopenharmony_ci    return proxy->GetInterfaceConfig(cfg);
379b1b8bc3fSopenharmony_ci}
380b1b8bc3fSopenharmony_ci
381b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetInterfaceConfig(const OHOS::nmd::InterfaceConfigurationParcel &cfg)
382b1b8bc3fSopenharmony_ci{
383b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set interface config: ifName[%{public}s]", cfg.ifName.c_str());
384b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
385b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
386b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
387b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
388b1b8bc3fSopenharmony_ci    }
389b1b8bc3fSopenharmony_ci    return proxy->SetInterfaceConfig(cfg);
390b1b8bc3fSopenharmony_ci}
391b1b8bc3fSopenharmony_ci
392b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetInterfaceDown(const std::string &iface)
393b1b8bc3fSopenharmony_ci{
394b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set interface down: iface[%{public}s]", iface.c_str());
395b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
396b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
397b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
398b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
399b1b8bc3fSopenharmony_ci    }
400b1b8bc3fSopenharmony_ci    OHOS::nmd::InterfaceConfigurationParcel ifCfg;
401b1b8bc3fSopenharmony_ci    ifCfg.ifName = iface;
402b1b8bc3fSopenharmony_ci    proxy->GetInterfaceConfig(ifCfg);
403b1b8bc3fSopenharmony_ci    auto fit = std::find(ifCfg.flags.begin(), ifCfg.flags.end(), IF_CFG_UP);
404b1b8bc3fSopenharmony_ci    if (fit != ifCfg.flags.end()) {
405b1b8bc3fSopenharmony_ci        ifCfg.flags.erase(fit);
406b1b8bc3fSopenharmony_ci    }
407b1b8bc3fSopenharmony_ci    ifCfg.flags.emplace_back(IF_CFG_DOWN);
408b1b8bc3fSopenharmony_ci    return proxy->SetInterfaceConfig(ifCfg);
409b1b8bc3fSopenharmony_ci}
410b1b8bc3fSopenharmony_ci
411b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetInterfaceUp(const std::string &iface)
412b1b8bc3fSopenharmony_ci{
413b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set interface up: iface[%{public}s]", iface.c_str());
414b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
415b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
416b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
417b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
418b1b8bc3fSopenharmony_ci    }
419b1b8bc3fSopenharmony_ci    OHOS::nmd::InterfaceConfigurationParcel ifCfg;
420b1b8bc3fSopenharmony_ci    ifCfg.ifName = iface;
421b1b8bc3fSopenharmony_ci    proxy->GetInterfaceConfig(ifCfg);
422b1b8bc3fSopenharmony_ci    auto fit = std::find(ifCfg.flags.begin(), ifCfg.flags.end(), IF_CFG_DOWN);
423b1b8bc3fSopenharmony_ci    if (fit != ifCfg.flags.end()) {
424b1b8bc3fSopenharmony_ci        ifCfg.flags.erase(fit);
425b1b8bc3fSopenharmony_ci    }
426b1b8bc3fSopenharmony_ci    ifCfg.flags.emplace_back(IF_CFG_UP);
427b1b8bc3fSopenharmony_ci    return proxy->SetInterfaceConfig(ifCfg);
428b1b8bc3fSopenharmony_ci}
429b1b8bc3fSopenharmony_ci
430b1b8bc3fSopenharmony_civoid NetsysNativeClient::ClearInterfaceAddrs(const std::string &ifName)
431b1b8bc3fSopenharmony_ci{
432b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Clear addrs: ifName[%{public}s]", ifName.c_str());
433b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
434b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
435b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
436b1b8bc3fSopenharmony_ci        return;
437b1b8bc3fSopenharmony_ci    }
438b1b8bc3fSopenharmony_ci}
439b1b8bc3fSopenharmony_ci
440b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetInterfaceMtu(const std::string &ifName)
441b1b8bc3fSopenharmony_ci{
442b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Get mtu: ifName[%{public}s]", ifName.c_str());
443b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
444b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
445b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
446b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
447b1b8bc3fSopenharmony_ci    }
448b1b8bc3fSopenharmony_ci    return proxy->GetInterfaceMtu(ifName);
449b1b8bc3fSopenharmony_ci}
450b1b8bc3fSopenharmony_ci
451b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetInterfaceMtu(const std::string &ifName, int32_t mtu)
452b1b8bc3fSopenharmony_ci{
453b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set mtu: ifName[%{public}s], mtu[%{public}d]", ifName.c_str(), mtu);
454b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
455b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
456b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
457b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
458b1b8bc3fSopenharmony_ci    }
459b1b8bc3fSopenharmony_ci    return proxy->SetInterfaceMtu(ifName, mtu);
460b1b8bc3fSopenharmony_ci}
461b1b8bc3fSopenharmony_ci
462b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetTcpBufferSizes(const std::string &tcpBufferSizes)
463b1b8bc3fSopenharmony_ci{
464b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set tcp buffer sizes: tcpBufferSizes[%{public}s]", tcpBufferSizes.c_str());
465b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
466b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
467b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
468b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
469b1b8bc3fSopenharmony_ci    }
470b1b8bc3fSopenharmony_ci    return proxy->SetTcpBufferSizes(tcpBufferSizes);
471b1b8bc3fSopenharmony_ci}
472b1b8bc3fSopenharmony_ci
473b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
474b1b8bc3fSopenharmony_ci                                                int32_t prefixLength)
475b1b8bc3fSopenharmony_ci{
476b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Add address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
477b1b8bc3fSopenharmony_ci        ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
478b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
479b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
480b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
481b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
482b1b8bc3fSopenharmony_ci    }
483b1b8bc3fSopenharmony_ci    return proxy->AddInterfaceAddress(ifName, ipAddr, prefixLength);
484b1b8bc3fSopenharmony_ci}
485b1b8bc3fSopenharmony_ci
486b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
487b1b8bc3fSopenharmony_ci                                                int32_t prefixLength)
488b1b8bc3fSopenharmony_ci{
489b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
490b1b8bc3fSopenharmony_ci        ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
491b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
492b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
493b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
494b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
495b1b8bc3fSopenharmony_ci    }
496b1b8bc3fSopenharmony_ci    return proxy->DelInterfaceAddress(ifName, ipAddr, prefixLength);
497b1b8bc3fSopenharmony_ci}
498b1b8bc3fSopenharmony_ci
499b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
500b1b8bc3fSopenharmony_ci                                                int32_t prefixLength, const std::string &netCapabilities)
501b1b8bc3fSopenharmony_ci{
502b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Delete address: ifName[%{public}s], ipAddr[%{public}s], prefixLength[%{public}d]",
503b1b8bc3fSopenharmony_ci        ifName.c_str(), ToAnonymousIp(ipAddr).c_str(), prefixLength);
504b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
505b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
506b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
507b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
508b1b8bc3fSopenharmony_ci    }
509b1b8bc3fSopenharmony_ci    return proxy->DelInterfaceAddress(ifName, ipAddr, prefixLength, netCapabilities);
510b1b8bc3fSopenharmony_ci}
511b1b8bc3fSopenharmony_ci
512b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
513b1b8bc3fSopenharmony_ci{
514b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set Ip Address: ifaceName[%{public}s], ipAddr[%{public}s]",
515b1b8bc3fSopenharmony_ci        ifaceName.c_str(), ToAnonymousIp(ipAddress).c_str());
516b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
517b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
518b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
519b1b8bc3fSopenharmony_ci        return IPC_PROXY_ERR;
520b1b8bc3fSopenharmony_ci    }
521b1b8bc3fSopenharmony_ci    return proxy->InterfaceSetIpAddress(ifaceName, ipAddress);
522b1b8bc3fSopenharmony_ci}
523b1b8bc3fSopenharmony_ci
524b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::InterfaceSetIffUp(const std::string &ifaceName)
525b1b8bc3fSopenharmony_ci{
526b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set Iff Up: ifaceName[%{public}s]", ifaceName.c_str());
527b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
528b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
529b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
530b1b8bc3fSopenharmony_ci        return IPC_PROXY_ERR;
531b1b8bc3fSopenharmony_ci    }
532b1b8bc3fSopenharmony_ci    return proxy->InterfaceSetIffUp(ifaceName);
533b1b8bc3fSopenharmony_ci}
534b1b8bc3fSopenharmony_ci
535b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
536b1b8bc3fSopenharmony_ci                                              const std::vector<std::string> &servers,
537b1b8bc3fSopenharmony_ci                                              const std::vector<std::string> &domains)
538b1b8bc3fSopenharmony_ci{
539b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Set resolver config: netId[%{public}d]", netId);
540b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
541b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
542b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
543b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
544b1b8bc3fSopenharmony_ci    }
545b1b8bc3fSopenharmony_ci    return proxy->SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
546b1b8bc3fSopenharmony_ci}
547b1b8bc3fSopenharmony_ci
548b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
549b1b8bc3fSopenharmony_ci                                              std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
550b1b8bc3fSopenharmony_ci                                              uint8_t &retryCount)
551b1b8bc3fSopenharmony_ci{
552b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Get resolver config: netId[%{public}d]", netId);
553b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
554b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
555b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
556b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
557b1b8bc3fSopenharmony_ci    }
558b1b8bc3fSopenharmony_ci    return proxy->GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
559b1b8bc3fSopenharmony_ci}
560b1b8bc3fSopenharmony_ci
561b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::CreateNetworkCache(uint16_t netId)
562b1b8bc3fSopenharmony_ci{
563b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("create dns cache: netId[%{public}d]", netId);
564b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
565b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
566b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
567b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
568b1b8bc3fSopenharmony_ci    }
569b1b8bc3fSopenharmony_ci    return proxy->CreateNetworkCache(netId);
570b1b8bc3fSopenharmony_ci}
571b1b8bc3fSopenharmony_ci
572b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DestroyNetworkCache(uint16_t netId)
573b1b8bc3fSopenharmony_ci{
574b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Destroy dns cache: netId[%{public}d]", netId);
575b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
576b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
577b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
578b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
579b1b8bc3fSopenharmony_ci    }
580b1b8bc3fSopenharmony_ci    return proxy->DestroyNetworkCache(netId);
581b1b8bc3fSopenharmony_ci}
582b1b8bc3fSopenharmony_ci
583b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetAddrInfo(const std::string &hostName, const std::string &serverName,
584b1b8bc3fSopenharmony_ci                                        const AddrInfo &hints, uint16_t netId, std::vector<AddrInfo> &res)
585b1b8bc3fSopenharmony_ci{
586b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
587b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
588b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("GetAddrInfo netsysNativeService_ is null");
589b1b8bc3fSopenharmony_ci        return NET_CONN_ERR_SERVICE_UPDATE_NET_LINK_INFO_FAIL;
590b1b8bc3fSopenharmony_ci    }
591b1b8bc3fSopenharmony_ci    return proxy->GetAddrInfo(hostName, serverName, hints, netId, res);
592b1b8bc3fSopenharmony_ci}
593b1b8bc3fSopenharmony_ci
594b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
595b1b8bc3fSopenharmony_ci                                                     nmd::NetworkSharingTraffic &traffic)
596b1b8bc3fSopenharmony_ci{
597b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetNetworkSharingTraffic");
598b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
599b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
600b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
601b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
602b1b8bc3fSopenharmony_ci    }
603b1b8bc3fSopenharmony_ci    return proxy->GetNetworkSharingTraffic(downIface, upIface, traffic);
604b1b8bc3fSopenharmony_ci}
605b1b8bc3fSopenharmony_ci
606b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetCellularRxBytes()
607b1b8bc3fSopenharmony_ci{
608b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetCellularRxBytes");
609b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
610b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
611b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
612b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
613b1b8bc3fSopenharmony_ci    }
614b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
615b1b8bc3fSopenharmony_ci}
616b1b8bc3fSopenharmony_ci
617b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetCellularTxBytes()
618b1b8bc3fSopenharmony_ci{
619b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetCellularTxBytes");
620b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
621b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
622b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
623b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
624b1b8bc3fSopenharmony_ci    }
625b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
626b1b8bc3fSopenharmony_ci}
627b1b8bc3fSopenharmony_ci
628b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetAllRxBytes()
629b1b8bc3fSopenharmony_ci{
630b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetAllRxBytes");
631b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
632b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
633b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
634b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
635b1b8bc3fSopenharmony_ci    }
636b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
637b1b8bc3fSopenharmony_ci}
638b1b8bc3fSopenharmony_ci
639b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetAllTxBytes()
640b1b8bc3fSopenharmony_ci{
641b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetAllTxBytes");
642b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
643b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
644b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
645b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
646b1b8bc3fSopenharmony_ci    }
647b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
648b1b8bc3fSopenharmony_ci}
649b1b8bc3fSopenharmony_ci
650b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetUidRxBytes(uint32_t uid)
651b1b8bc3fSopenharmony_ci{
652b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetUidRxBytes uid is [%{public}u]", uid);
653b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
654b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
655b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
656b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
657b1b8bc3fSopenharmony_ci    }
658b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
659b1b8bc3fSopenharmony_ci}
660b1b8bc3fSopenharmony_ci
661b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetUidTxBytes(uint32_t uid)
662b1b8bc3fSopenharmony_ci{
663b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetUidTxBytes uid is [%{public}u]", uid);
664b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
665b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
666b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
667b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
668b1b8bc3fSopenharmony_ci    }
669b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
670b1b8bc3fSopenharmony_ci}
671b1b8bc3fSopenharmony_ci
672b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetUidOnIfaceRxBytes(uint32_t uid, const std::string &interfaceName)
673b1b8bc3fSopenharmony_ci{
674b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetUidOnIfaceRxBytes uid is [%{public}u] iface name is [%{public}s]", uid,
675b1b8bc3fSopenharmony_ci                 interfaceName.c_str());
676b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
677b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
678b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
679b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
680b1b8bc3fSopenharmony_ci    }
681b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
682b1b8bc3fSopenharmony_ci}
683b1b8bc3fSopenharmony_ci
684b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetUidOnIfaceTxBytes(uint32_t uid, const std::string &interfaceName)
685b1b8bc3fSopenharmony_ci{
686b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetUidOnIfaceTxBytes uid is [%{public}u] iface name is [%{public}s]", uid,
687b1b8bc3fSopenharmony_ci                 interfaceName.c_str());
688b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
689b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
690b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
691b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
692b1b8bc3fSopenharmony_ci    }
693b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
694b1b8bc3fSopenharmony_ci}
695b1b8bc3fSopenharmony_ci
696b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetIfaceRxBytes(const std::string &interfaceName)
697b1b8bc3fSopenharmony_ci{
698b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetIfaceRxBytes iface name is [%{public}s]", interfaceName.c_str());
699b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
700b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
701b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
702b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
703b1b8bc3fSopenharmony_ci    }
704b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
705b1b8bc3fSopenharmony_ci}
706b1b8bc3fSopenharmony_ci
707b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetIfaceTxBytes(const std::string &interfaceName)
708b1b8bc3fSopenharmony_ci{
709b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetIfaceTxBytes iface name is [%{public}s]", interfaceName.c_str());
710b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
711b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
712b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
713b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
714b1b8bc3fSopenharmony_ci    }
715b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
716b1b8bc3fSopenharmony_ci}
717b1b8bc3fSopenharmony_ci
718b1b8bc3fSopenharmony_cistd::vector<std::string> NetsysNativeClient::InterfaceGetList()
719b1b8bc3fSopenharmony_ci{
720b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient InterfaceGetList");
721b1b8bc3fSopenharmony_ci    std::vector<std::string> ret;
722b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
723b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
724b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
725b1b8bc3fSopenharmony_ci        return ret;
726b1b8bc3fSopenharmony_ci    }
727b1b8bc3fSopenharmony_ci    proxy->InterfaceGetList(ret);
728b1b8bc3fSopenharmony_ci    return ret;
729b1b8bc3fSopenharmony_ci}
730b1b8bc3fSopenharmony_ci
731b1b8bc3fSopenharmony_cistd::vector<std::string> NetsysNativeClient::UidGetList()
732b1b8bc3fSopenharmony_ci{
733b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient UidGetList");
734b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
735b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
736b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
737b1b8bc3fSopenharmony_ci        return {};
738b1b8bc3fSopenharmony_ci    }
739b1b8bc3fSopenharmony_ci    return {};
740b1b8bc3fSopenharmony_ci}
741b1b8bc3fSopenharmony_ci
742b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetIfaceRxPackets(const std::string &interfaceName)
743b1b8bc3fSopenharmony_ci{
744b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetIfaceRxPackets iface name is [%{public}s]", interfaceName.c_str());
745b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
746b1b8bc3fSopenharmony_ci}
747b1b8bc3fSopenharmony_ci
748b1b8bc3fSopenharmony_ciint64_t NetsysNativeClient::GetIfaceTxPackets(const std::string &interfaceName)
749b1b8bc3fSopenharmony_ci{
750b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient GetIfaceTxPackets iface name is [%{public}s]", interfaceName.c_str());
751b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
752b1b8bc3fSopenharmony_ci}
753b1b8bc3fSopenharmony_ci
754b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetDefaultNetWork(int32_t netId)
755b1b8bc3fSopenharmony_ci{
756b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient SetDefaultNetWork");
757b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
758b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
759b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
760b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
761b1b8bc3fSopenharmony_ci    }
762b1b8bc3fSopenharmony_ci    return proxy->NetworkSetDefault(netId);
763b1b8bc3fSopenharmony_ci}
764b1b8bc3fSopenharmony_ci
765b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::ClearDefaultNetWorkNetId()
766b1b8bc3fSopenharmony_ci{
767b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient ClearDefaultNetWorkNetId");
768b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
769b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
770b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
771b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
772b1b8bc3fSopenharmony_ci    }
773b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
774b1b8bc3fSopenharmony_ci}
775b1b8bc3fSopenharmony_ci
776b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BindSocket(int32_t socketFd, uint32_t netId)
777b1b8bc3fSopenharmony_ci{
778b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::BindSocket: netId = [%{public}u]", netId);
779b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
780b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
781b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
782b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
783b1b8bc3fSopenharmony_ci    }
784b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
785b1b8bc3fSopenharmony_ci}
786b1b8bc3fSopenharmony_ci
787b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::IpEnableForwarding(const std::string &requestor)
788b1b8bc3fSopenharmony_ci{
789b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient IpEnableForwarding: requestor[%{public}s]", requestor.c_str());
790b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
791b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
792b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
793b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
794b1b8bc3fSopenharmony_ci    }
795b1b8bc3fSopenharmony_ci    return proxy->IpEnableForwarding(requestor);
796b1b8bc3fSopenharmony_ci}
797b1b8bc3fSopenharmony_ci
798b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::IpDisableForwarding(const std::string &requestor)
799b1b8bc3fSopenharmony_ci{
800b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient IpDisableForwarding: requestor[%{public}s]", requestor.c_str());
801b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
802b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
803b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
804b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
805b1b8bc3fSopenharmony_ci    }
806b1b8bc3fSopenharmony_ci    return proxy->IpDisableForwarding(requestor);
807b1b8bc3fSopenharmony_ci}
808b1b8bc3fSopenharmony_ci
809b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
810b1b8bc3fSopenharmony_ci{
811b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient EnableNat: intIface[%{public}s] intIface[%{public}s]", downstreamIface.c_str(),
812b1b8bc3fSopenharmony_ci                 upstreamIface.c_str());
813b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
814b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
815b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
816b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
817b1b8bc3fSopenharmony_ci    }
818b1b8bc3fSopenharmony_ci    return proxy->EnableNat(downstreamIface, upstreamIface);
819b1b8bc3fSopenharmony_ci}
820b1b8bc3fSopenharmony_ci
821b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
822b1b8bc3fSopenharmony_ci{
823b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient DisableNat: intIface[%{public}s] intIface[%{public}s]", downstreamIface.c_str(),
824b1b8bc3fSopenharmony_ci                 upstreamIface.c_str());
825b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
826b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
827b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
828b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
829b1b8bc3fSopenharmony_ci    }
830b1b8bc3fSopenharmony_ci    return proxy->DisableNat(downstreamIface, upstreamIface);
831b1b8bc3fSopenharmony_ci}
832b1b8bc3fSopenharmony_ci
833b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
834b1b8bc3fSopenharmony_ci{
835b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
836b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
837b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
838b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
839b1b8bc3fSopenharmony_ci    }
840b1b8bc3fSopenharmony_ci    return proxy->IpfwdAddInterfaceForward(fromIface, toIface);
841b1b8bc3fSopenharmony_ci}
842b1b8bc3fSopenharmony_ci
843b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface)
844b1b8bc3fSopenharmony_ci{
845b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient IpfwdRemoveInterfaceForward: fromIface[%{public}s], toIface[%{public}s]",
846b1b8bc3fSopenharmony_ci                 fromIface.c_str(), toIface.c_str());
847b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
848b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
849b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
850b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
851b1b8bc3fSopenharmony_ci    }
852b1b8bc3fSopenharmony_ci    return proxy->IpfwdRemoveInterfaceForward(fromIface, toIface);
853b1b8bc3fSopenharmony_ci}
854b1b8bc3fSopenharmony_ci
855b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::ShareDnsSet(uint16_t netId)
856b1b8bc3fSopenharmony_ci{
857b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
858b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
859b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
860b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
861b1b8bc3fSopenharmony_ci    }
862b1b8bc3fSopenharmony_ci    return proxy->ShareDnsSet(netId);
863b1b8bc3fSopenharmony_ci}
864b1b8bc3fSopenharmony_ci
865b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StartDnsProxyListen()
866b1b8bc3fSopenharmony_ci{
867b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
868b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
869b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
870b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
871b1b8bc3fSopenharmony_ci    }
872b1b8bc3fSopenharmony_ci    return proxy->StartDnsProxyListen();
873b1b8bc3fSopenharmony_ci}
874b1b8bc3fSopenharmony_ci
875b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StopDnsProxyListen()
876b1b8bc3fSopenharmony_ci{
877b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
878b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
879b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
880b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
881b1b8bc3fSopenharmony_ci    }
882b1b8bc3fSopenharmony_ci    return proxy->StopDnsProxyListen();
883b1b8bc3fSopenharmony_ci}
884b1b8bc3fSopenharmony_ci
885b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::RegisterNetsysNotifyCallback(const NetsysNotifyCallback &callback)
886b1b8bc3fSopenharmony_ci{
887b1b8bc3fSopenharmony_ci    (void)callback;
888b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient RegisterNetsysNotifyCallback");
889b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
890b1b8bc3fSopenharmony_ci}
891b1b8bc3fSopenharmony_ci
892b1b8bc3fSopenharmony_ci__attribute__((no_sanitize("cfi"))) sptr<OHOS::NetsysNative::INetsysService> NetsysNativeClient::GetProxy()
893b1b8bc3fSopenharmony_ci{
894b1b8bc3fSopenharmony_ci    std::lock_guard lock(mutex_);
895b1b8bc3fSopenharmony_ci    if (netsysNativeService_) {
896b1b8bc3fSopenharmony_ci        return netsysNativeService_;
897b1b8bc3fSopenharmony_ci    }
898b1b8bc3fSopenharmony_ci
899b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("Execute GetSystemAbilityManager");
900b1b8bc3fSopenharmony_ci    auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
901b1b8bc3fSopenharmony_ci    if (samgr == nullptr) {
902b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient samgr null");
903b1b8bc3fSopenharmony_ci        return nullptr;
904b1b8bc3fSopenharmony_ci    }
905b1b8bc3fSopenharmony_ci
906b1b8bc3fSopenharmony_ci    auto remote = samgr->GetSystemAbility(OHOS::COMM_NETSYS_NATIVE_SYS_ABILITY_ID);
907b1b8bc3fSopenharmony_ci    if (remote == nullptr) {
908b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Get remote service failed");
909b1b8bc3fSopenharmony_ci        return nullptr;
910b1b8bc3fSopenharmony_ci    }
911b1b8bc3fSopenharmony_ci
912b1b8bc3fSopenharmony_ci    deathRecipient_ = new (std::nothrow) NetNativeConnDeathRecipient(*this);
913b1b8bc3fSopenharmony_ci    if (deathRecipient_ == nullptr) {
914b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Recipient new failed!");
915b1b8bc3fSopenharmony_ci        return nullptr;
916b1b8bc3fSopenharmony_ci    }
917b1b8bc3fSopenharmony_ci
918b1b8bc3fSopenharmony_ci    if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
919b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("add death recipient failed");
920b1b8bc3fSopenharmony_ci        return nullptr;
921b1b8bc3fSopenharmony_ci    }
922b1b8bc3fSopenharmony_ci
923b1b8bc3fSopenharmony_ci    netsysNativeService_ = iface_cast<NetsysNative::INetsysService>(remote);
924b1b8bc3fSopenharmony_ci    if (netsysNativeService_ == nullptr) {
925b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Get remote service proxy failed");
926b1b8bc3fSopenharmony_ci        return nullptr;
927b1b8bc3fSopenharmony_ci    }
928b1b8bc3fSopenharmony_ci
929b1b8bc3fSopenharmony_ci    return netsysNativeService_;
930b1b8bc3fSopenharmony_ci}
931b1b8bc3fSopenharmony_ci
932b1b8bc3fSopenharmony_civoid NetsysNativeClient::RegisterNotifyCallback()
933b1b8bc3fSopenharmony_ci{
934b1b8bc3fSopenharmony_ci    std::thread t([this]() {
935b1b8bc3fSopenharmony_ci        uint32_t count = 0;
936b1b8bc3fSopenharmony_ci        while (GetProxy() == nullptr && count < MAX_GET_SERVICE_COUNT) {
937b1b8bc3fSopenharmony_ci            std::this_thread::sleep_for(std::chrono::seconds(WAIT_FOR_SERVICE_TIME_S));
938b1b8bc3fSopenharmony_ci            count++;
939b1b8bc3fSopenharmony_ci        }
940b1b8bc3fSopenharmony_ci        auto proxy = GetProxy();
941b1b8bc3fSopenharmony_ci        NETMGR_LOG_W("Get proxy %{public}s, count: %{public}u", proxy == nullptr ? "failed" : "success", count);
942b1b8bc3fSopenharmony_ci        if (proxy != nullptr) {
943b1b8bc3fSopenharmony_ci            if (nativeNotifyCallback_ == nullptr) {
944b1b8bc3fSopenharmony_ci                nativeNotifyCallback_ = new (std::nothrow) NativeNotifyCallback(*this);
945b1b8bc3fSopenharmony_ci            }
946b1b8bc3fSopenharmony_ci
947b1b8bc3fSopenharmony_ci            NETMGR_LOG_D("call proxy->RegisterNotifyCallback");
948b1b8bc3fSopenharmony_ci            proxy->RegisterNotifyCallback(nativeNotifyCallback_);
949b1b8bc3fSopenharmony_ci
950b1b8bc3fSopenharmony_ci            if (nativeDnsReportCallback_ == nullptr) {
951b1b8bc3fSopenharmony_ci                nativeDnsReportCallback_ = new (std::nothrow) NativeNetDnsResultCallback(*this);
952b1b8bc3fSopenharmony_ci            }
953b1b8bc3fSopenharmony_ci
954b1b8bc3fSopenharmony_ci            NETMGR_LOG_D("call proxy->RegisterDnsResultCallback");
955b1b8bc3fSopenharmony_ci            proxy->RegisterDnsResultCallback(nativeDnsReportCallback_, dnsReportTimeStep);
956b1b8bc3fSopenharmony_ci        }
957b1b8bc3fSopenharmony_ci    });
958b1b8bc3fSopenharmony_ci    std::string threadName = "netsysGetProxy";
959b1b8bc3fSopenharmony_ci    pthread_setname_np(t.native_handle(), threadName.c_str());
960b1b8bc3fSopenharmony_ci    t.detach();
961b1b8bc3fSopenharmony_ci}
962b1b8bc3fSopenharmony_ci
963b1b8bc3fSopenharmony_civoid NetsysNativeClient::OnRemoteDied(const wptr<IRemoteObject> &remote)
964b1b8bc3fSopenharmony_ci{
965b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("on remote died");
966b1b8bc3fSopenharmony_ci    if (remote == nullptr) {
967b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("remote object is nullptr");
968b1b8bc3fSopenharmony_ci        return;
969b1b8bc3fSopenharmony_ci    }
970b1b8bc3fSopenharmony_ci
971b1b8bc3fSopenharmony_ci    std::lock_guard lock(mutex_);
972b1b8bc3fSopenharmony_ci    if (netsysNativeService_ == nullptr) {
973b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("netsysNativeService_ is nullptr");
974b1b8bc3fSopenharmony_ci        return;
975b1b8bc3fSopenharmony_ci    }
976b1b8bc3fSopenharmony_ci
977b1b8bc3fSopenharmony_ci    sptr<IRemoteObject> local = netsysNativeService_->AsObject();
978b1b8bc3fSopenharmony_ci    if (local != remote.promote()) {
979b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy and stub is not same remote object");
980b1b8bc3fSopenharmony_ci        return;
981b1b8bc3fSopenharmony_ci    }
982b1b8bc3fSopenharmony_ci    local->RemoveDeathRecipient(deathRecipient_);
983b1b8bc3fSopenharmony_ci
984b1b8bc3fSopenharmony_ci    if (access(NETSYS_ROUTE_INIT_DIR_PATH, F_OK) == 0) {
985b1b8bc3fSopenharmony_ci        NETMGR_LOG_D("NetConnService netsys restart, clear NETSYS_ROUTE_INIT_DIR_PATH");
986b1b8bc3fSopenharmony_ci        rmdir(NETSYS_ROUTE_INIT_DIR_PATH);
987b1b8bc3fSopenharmony_ci    }
988b1b8bc3fSopenharmony_ci
989b1b8bc3fSopenharmony_ci    netsysNativeService_ = nullptr;
990b1b8bc3fSopenharmony_ci
991b1b8bc3fSopenharmony_ci    RegisterNotifyCallback();
992b1b8bc3fSopenharmony_ci}
993b1b8bc3fSopenharmony_ci
994b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BindNetworkServiceVpn(int32_t socketFd)
995b1b8bc3fSopenharmony_ci{
996b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::BindNetworkServiceVpn: socketFd[%{public}d]", socketFd);
997b1b8bc3fSopenharmony_ci    /* netsys provide default interface name */
998b1b8bc3fSopenharmony_ci    const char *defaultNetName = "wlan0";
999b1b8bc3fSopenharmony_ci    socklen_t defaultNetNameLen = strlen(defaultNetName);
1000b1b8bc3fSopenharmony_ci    /* set socket by option. */
1001b1b8bc3fSopenharmony_ci    int32_t ret = setsockopt(socketFd, SOL_SOCKET, SO_MARK, defaultNetName, defaultNetNameLen);
1002b1b8bc3fSopenharmony_ci    if (ret < 0) {
1003b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The SO_BINDTODEVICE of setsockopt failed.");
1004b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1005b1b8bc3fSopenharmony_ci    }
1006b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1007b1b8bc3fSopenharmony_ci}
1008b1b8bc3fSopenharmony_ci
1009b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::EnableVirtualNetIfaceCard(int32_t socketFd, struct ifreq &ifRequest, int32_t &ifaceFd)
1010b1b8bc3fSopenharmony_ci{
1011b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::EnableVirtualNetIfaceCard: socketFd[%{public}d]", socketFd);
1012b1b8bc3fSopenharmony_ci    int32_t ifaceFdTemp = 0;
1013b1b8bc3fSopenharmony_ci    if ((ifaceFdTemp = open(DEV_NET_TUN_PATH, O_RDWR)) < 0) {
1014b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("VPN tunnel device open was failed.");
1015b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1016b1b8bc3fSopenharmony_ci    }
1017b1b8bc3fSopenharmony_ci
1018b1b8bc3fSopenharmony_ci    /*
1019b1b8bc3fSopenharmony_ci     * Flags:
1020b1b8bc3fSopenharmony_ci     * IFF_TUN   - TUN device (no Ethernet headers)
1021b1b8bc3fSopenharmony_ci     * IFF_TAP   - TAP device
1022b1b8bc3fSopenharmony_ci     * IFF_NO_PI - Do not provide packet information
1023b1b8bc3fSopenharmony_ci     **/
1024b1b8bc3fSopenharmony_ci    ifRequest.ifr_flags = IFF_TUN | IFF_NO_PI;
1025b1b8bc3fSopenharmony_ci    /**
1026b1b8bc3fSopenharmony_ci     * Try to create the device. if it cannot assign the device interface name, kernel can
1027b1b8bc3fSopenharmony_ci     * allocate the next device interface name. for example, there is tun0, kernel can
1028b1b8bc3fSopenharmony_ci     * allocate tun1.
1029b1b8bc3fSopenharmony_ci     **/
1030b1b8bc3fSopenharmony_ci    if (ioctl(ifaceFdTemp, TUNSETIFF, &ifRequest) < 0) {
1031b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The TUNSETIFF of ioctl failed, ifRequest.ifr_name[%{public}s]", ifRequest.ifr_name);
1032b1b8bc3fSopenharmony_ci        close(ifaceFdTemp);
1033b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1034b1b8bc3fSopenharmony_ci    }
1035b1b8bc3fSopenharmony_ci
1036b1b8bc3fSopenharmony_ci    /* Activate the device */
1037b1b8bc3fSopenharmony_ci    ifRequest.ifr_flags = IFF_UP;
1038b1b8bc3fSopenharmony_ci    if (ioctl(socketFd, SIOCSIFFLAGS, &ifRequest) < 0) {
1039b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The SIOCSIFFLAGS of ioctl failed.");
1040b1b8bc3fSopenharmony_ci        close(ifaceFdTemp);
1041b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1042b1b8bc3fSopenharmony_ci    }
1043b1b8bc3fSopenharmony_ci
1044b1b8bc3fSopenharmony_ci    ifaceFd = ifaceFdTemp;
1045b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1046b1b8bc3fSopenharmony_ci}
1047b1b8bc3fSopenharmony_ci
1048b1b8bc3fSopenharmony_cistatic inline in_addr_t *AsInAddr(sockaddr *sa)
1049b1b8bc3fSopenharmony_ci{
1050b1b8bc3fSopenharmony_ci    return &(reinterpret_cast<sockaddr_in *>(sa))->sin_addr.s_addr;
1051b1b8bc3fSopenharmony_ci}
1052b1b8bc3fSopenharmony_ci
1053b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetIpAddress(int32_t socketFd, const std::string &ipAddress, int32_t prefixLen,
1054b1b8bc3fSopenharmony_ci                                         struct ifreq &ifRequest)
1055b1b8bc3fSopenharmony_ci{
1056b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::SetIpAddress: socketFd[%{public}d]", socketFd);
1057b1b8bc3fSopenharmony_ci
1058b1b8bc3fSopenharmony_ci    ifRequest.ifr_addr.sa_family = AF_INET;
1059b1b8bc3fSopenharmony_ci    ifRequest.ifr_netmask.sa_family = AF_INET;
1060b1b8bc3fSopenharmony_ci
1061b1b8bc3fSopenharmony_ci    /* inet_pton is IP ipAddress translation to binary network byte order. */
1062b1b8bc3fSopenharmony_ci    if (inet_pton(AF_INET, ipAddress.c_str(), AsInAddr(&ifRequest.ifr_addr)) != 1) {
1063b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("inet_pton failed.");
1064b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1065b1b8bc3fSopenharmony_ci    }
1066b1b8bc3fSopenharmony_ci    if (ioctl(socketFd, SIOCSIFADDR, &ifRequest) < 0) {
1067b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The SIOCSIFADDR of ioctl failed.");
1068b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1069b1b8bc3fSopenharmony_ci    }
1070b1b8bc3fSopenharmony_ci    in_addr_t addressPrefixLength = prefixLen ? (~0 << (IPV4_MAX_LENGTH - prefixLen)) : 0;
1071b1b8bc3fSopenharmony_ci    *AsInAddr(&ifRequest.ifr_netmask) = htonl(addressPrefixLength);
1072b1b8bc3fSopenharmony_ci    if (ioctl(socketFd, SIOCSIFNETMASK, &ifRequest)) {
1073b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The SIOCSIFNETMASK of ioctl failed.");
1074b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1075b1b8bc3fSopenharmony_ci    }
1076b1b8bc3fSopenharmony_ci
1077b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1078b1b8bc3fSopenharmony_ci}
1079b1b8bc3fSopenharmony_ci
1080b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetBlocking(int32_t ifaceFd, bool isBlock)
1081b1b8bc3fSopenharmony_ci{
1082b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::SetBlocking");
1083b1b8bc3fSopenharmony_ci    int32_t blockingFlag = 0;
1084b1b8bc3fSopenharmony_ci    blockingFlag = fcntl(ifaceFd, F_GETFL);
1085b1b8bc3fSopenharmony_ci    if (blockingFlag < 0) {
1086b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The blockingFlag of fcntl failed.");
1087b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1088b1b8bc3fSopenharmony_ci    }
1089b1b8bc3fSopenharmony_ci
1090b1b8bc3fSopenharmony_ci    if (!isBlock) {
1091b1b8bc3fSopenharmony_ci        blockingFlag = static_cast<int>(static_cast<uint32_t>(blockingFlag) | static_cast<uint32_t>(O_NONBLOCK));
1092b1b8bc3fSopenharmony_ci    } else {
1093b1b8bc3fSopenharmony_ci        blockingFlag = static_cast<int>(static_cast<uint32_t>(blockingFlag) | static_cast<uint32_t>(~O_NONBLOCK));
1094b1b8bc3fSopenharmony_ci    }
1095b1b8bc3fSopenharmony_ci
1096b1b8bc3fSopenharmony_ci    if (fcntl(ifaceFd, F_SETFL, blockingFlag) < 0) {
1097b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("The F_SETFL of fcntl failed.");
1098b1b8bc3fSopenharmony_ci        return NETSYS_ERR_VPN;
1099b1b8bc3fSopenharmony_ci    }
1100b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1101b1b8bc3fSopenharmony_ci}
1102b1b8bc3fSopenharmony_ci
1103b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StartDhcpClient(const std::string &iface, bool bIpv6)
1104b1b8bc3fSopenharmony_ci{
1105b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::StartDhcpClient");
1106b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1107b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1108b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1109b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1110b1b8bc3fSopenharmony_ci    }
1111b1b8bc3fSopenharmony_ci    return proxy->StartDhcpClient(iface, bIpv6);
1112b1b8bc3fSopenharmony_ci}
1113b1b8bc3fSopenharmony_ci
1114b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StopDhcpClient(const std::string &iface, bool bIpv6)
1115b1b8bc3fSopenharmony_ci{
1116b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::StopDhcpClient");
1117b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1118b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1119b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1120b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1121b1b8bc3fSopenharmony_ci    }
1122b1b8bc3fSopenharmony_ci    return proxy->StopDhcpClient(iface, bIpv6);
1123b1b8bc3fSopenharmony_ci}
1124b1b8bc3fSopenharmony_ci
1125b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::RegisterCallback(const sptr<NetsysControllerCallback> &callback)
1126b1b8bc3fSopenharmony_ci{
1127b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::RegisterCallback");
1128b1b8bc3fSopenharmony_ci    if (callback == nullptr) {
1129b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Callback is nullptr");
1130b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_LOCAL_PTR_NULL;
1131b1b8bc3fSopenharmony_ci    }
1132b1b8bc3fSopenharmony_ci    std::lock_guard lock(cbObjMutex_);
1133b1b8bc3fSopenharmony_ci    cbObjects_.push_back(callback);
1134b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1135b1b8bc3fSopenharmony_ci}
1136b1b8bc3fSopenharmony_ci
1137b1b8bc3fSopenharmony_civoid NetsysNativeClient::ProcessDhcpResult(sptr<OHOS::NetsysNative::DhcpResultParcel> &dhcpResult)
1138b1b8bc3fSopenharmony_ci{
1139b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("NetsysNativeClient::ProcessDhcpResult");
1140b1b8bc3fSopenharmony_ci    std::lock_guard lock(cbObjMutex_);
1141b1b8bc3fSopenharmony_ci    NetsysControllerCallback::DhcpResult result;
1142b1b8bc3fSopenharmony_ci    for (auto cb = cbObjects_.begin(); cb != cbObjects_.end();) {
1143b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
1144b1b8bc3fSopenharmony_ci            cb = cbObjects_.erase(cb);
1145b1b8bc3fSopenharmony_ci        } else {
1146b1b8bc3fSopenharmony_ci            result.iface_ = dhcpResult->iface_;
1147b1b8bc3fSopenharmony_ci            result.ipAddr_ = dhcpResult->ipAddr_;
1148b1b8bc3fSopenharmony_ci            result.gateWay_ = dhcpResult->gateWay_;
1149b1b8bc3fSopenharmony_ci            result.subNet_ = dhcpResult->subNet_;
1150b1b8bc3fSopenharmony_ci            result.route1_ = dhcpResult->route1_;
1151b1b8bc3fSopenharmony_ci            result.route2_ = dhcpResult->route2_;
1152b1b8bc3fSopenharmony_ci            result.dns1_ = dhcpResult->dns1_;
1153b1b8bc3fSopenharmony_ci            result.dns2_ = dhcpResult->dns2_;
1154b1b8bc3fSopenharmony_ci            (*cb)->OnDhcpSuccess(result);
1155b1b8bc3fSopenharmony_ci            ++cb;
1156b1b8bc3fSopenharmony_ci        }
1157b1b8bc3fSopenharmony_ci    }
1158b1b8bc3fSopenharmony_ci}
1159b1b8bc3fSopenharmony_ci
1160b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
1161b1b8bc3fSopenharmony_ci{
1162b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient StartDhcpService");
1163b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1164b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1165b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1166b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1167b1b8bc3fSopenharmony_ci    }
1168b1b8bc3fSopenharmony_ci    return proxy->StartDhcpService(iface, ipv4addr);
1169b1b8bc3fSopenharmony_ci}
1170b1b8bc3fSopenharmony_ci
1171b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StopDhcpService(const std::string &iface)
1172b1b8bc3fSopenharmony_ci{
1173b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient StopDhcpService");
1174b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1175b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1176b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1177b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1178b1b8bc3fSopenharmony_ci    }
1179b1b8bc3fSopenharmony_ci    return proxy->StopDhcpService(iface);
1180b1b8bc3fSopenharmony_ci}
1181b1b8bc3fSopenharmony_ci
1182b1b8bc3fSopenharmony_civoid NetsysNativeClient::ProcessBandwidthReachedLimit(const std::string &limitName, const std::string &iface)
1183b1b8bc3fSopenharmony_ci{
1184b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient ProcessBandwidthReachedLimit, limitName=%{public}s, iface=%{public}s",
1185b1b8bc3fSopenharmony_ci                 limitName.c_str(), iface.c_str());
1186b1b8bc3fSopenharmony_ci    std::lock_guard lock(cbObjMutex_);
1187b1b8bc3fSopenharmony_ci    for (auto cb = cbObjects_.begin(); cb != cbObjects_.end();) {
1188b1b8bc3fSopenharmony_ci        if (*cb == nullptr) {
1189b1b8bc3fSopenharmony_ci            cb = cbObjects_.erase(cb);
1190b1b8bc3fSopenharmony_ci        } else {
1191b1b8bc3fSopenharmony_ci            (*cb)->OnBandwidthReachedLimit(limitName, iface);
1192b1b8bc3fSopenharmony_ci            ++cb;
1193b1b8bc3fSopenharmony_ci        }
1194b1b8bc3fSopenharmony_ci    }
1195b1b8bc3fSopenharmony_ci}
1196b1b8bc3fSopenharmony_ci
1197b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthEnableDataSaver(bool enable)
1198b1b8bc3fSopenharmony_ci{
1199b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1200b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1201b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1202b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1203b1b8bc3fSopenharmony_ci    }
1204b1b8bc3fSopenharmony_ci    return proxy->BandwidthEnableDataSaver(enable);
1205b1b8bc3fSopenharmony_ci}
1206b1b8bc3fSopenharmony_ci
1207b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
1208b1b8bc3fSopenharmony_ci{
1209b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1210b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1211b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1212b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1213b1b8bc3fSopenharmony_ci    }
1214b1b8bc3fSopenharmony_ci    return proxy->BandwidthSetIfaceQuota(ifName, bytes);
1215b1b8bc3fSopenharmony_ci}
1216b1b8bc3fSopenharmony_ci
1217b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthRemoveIfaceQuota(const std::string &ifName)
1218b1b8bc3fSopenharmony_ci{
1219b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1220b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1221b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1222b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1223b1b8bc3fSopenharmony_ci    }
1224b1b8bc3fSopenharmony_ci    return proxy->BandwidthRemoveIfaceQuota(ifName);
1225b1b8bc3fSopenharmony_ci}
1226b1b8bc3fSopenharmony_ci
1227b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthAddDeniedList(uint32_t uid)
1228b1b8bc3fSopenharmony_ci{
1229b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1230b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1231b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1232b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1233b1b8bc3fSopenharmony_ci    }
1234b1b8bc3fSopenharmony_ci    return proxy->BandwidthAddDeniedList(uid);
1235b1b8bc3fSopenharmony_ci}
1236b1b8bc3fSopenharmony_ci
1237b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthRemoveDeniedList(uint32_t uid)
1238b1b8bc3fSopenharmony_ci{
1239b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1240b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1241b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1242b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1243b1b8bc3fSopenharmony_ci    }
1244b1b8bc3fSopenharmony_ci    return proxy->BandwidthRemoveDeniedList(uid);
1245b1b8bc3fSopenharmony_ci}
1246b1b8bc3fSopenharmony_ci
1247b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthAddAllowedList(uint32_t uid)
1248b1b8bc3fSopenharmony_ci{
1249b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1250b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1251b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1252b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1253b1b8bc3fSopenharmony_ci    }
1254b1b8bc3fSopenharmony_ci    return proxy->BandwidthAddAllowedList(uid);
1255b1b8bc3fSopenharmony_ci}
1256b1b8bc3fSopenharmony_ci
1257b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::BandwidthRemoveAllowedList(uint32_t uid)
1258b1b8bc3fSopenharmony_ci{
1259b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1260b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1261b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1262b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1263b1b8bc3fSopenharmony_ci    }
1264b1b8bc3fSopenharmony_ci    return proxy->BandwidthRemoveAllowedList(uid);
1265b1b8bc3fSopenharmony_ci}
1266b1b8bc3fSopenharmony_ci
1267b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
1268b1b8bc3fSopenharmony_ci{
1269b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1270b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1271b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1272b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1273b1b8bc3fSopenharmony_ci    }
1274b1b8bc3fSopenharmony_ci    return proxy->FirewallSetUidsAllowedListChain(chain, uids);
1275b1b8bc3fSopenharmony_ci}
1276b1b8bc3fSopenharmony_ci
1277b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
1278b1b8bc3fSopenharmony_ci{
1279b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1280b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1281b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1282b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1283b1b8bc3fSopenharmony_ci    }
1284b1b8bc3fSopenharmony_ci    return proxy->FirewallSetUidsDeniedListChain(chain, uids);
1285b1b8bc3fSopenharmony_ci}
1286b1b8bc3fSopenharmony_ci
1287b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::FirewallEnableChain(uint32_t chain, bool enable)
1288b1b8bc3fSopenharmony_ci{
1289b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1290b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1291b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1292b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1293b1b8bc3fSopenharmony_ci    }
1294b1b8bc3fSopenharmony_ci    return proxy->FirewallEnableChain(chain, enable);
1295b1b8bc3fSopenharmony_ci}
1296b1b8bc3fSopenharmony_ci
1297b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule)
1298b1b8bc3fSopenharmony_ci{
1299b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1300b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1301b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1302b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1303b1b8bc3fSopenharmony_ci    }
1304b1b8bc3fSopenharmony_ci    return proxy->FirewallSetUidRule(chain, uids, firewallRule);
1305b1b8bc3fSopenharmony_ci}
1306b1b8bc3fSopenharmony_ci
1307b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetTotalStats(uint64_t &stats, uint32_t type)
1308b1b8bc3fSopenharmony_ci{
1309b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1310b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1311b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1312b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1313b1b8bc3fSopenharmony_ci    }
1314b1b8bc3fSopenharmony_ci    return proxy->GetTotalStats(stats, type);
1315b1b8bc3fSopenharmony_ci}
1316b1b8bc3fSopenharmony_ci
1317b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid)
1318b1b8bc3fSopenharmony_ci{
1319b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1320b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1321b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1322b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1323b1b8bc3fSopenharmony_ci    }
1324b1b8bc3fSopenharmony_ci    return proxy->GetUidStats(stats, type, uid);
1325b1b8bc3fSopenharmony_ci}
1326b1b8bc3fSopenharmony_ci
1327b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName)
1328b1b8bc3fSopenharmony_ci{
1329b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1330b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1331b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1332b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1333b1b8bc3fSopenharmony_ci    }
1334b1b8bc3fSopenharmony_ci    return proxy->GetIfaceStats(stats, type, interfaceName);
1335b1b8bc3fSopenharmony_ci}
1336b1b8bc3fSopenharmony_ci
1337b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
1338b1b8bc3fSopenharmony_ci{
1339b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1340b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1341b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1342b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1343b1b8bc3fSopenharmony_ci    }
1344b1b8bc3fSopenharmony_ci    return proxy->GetAllSimStatsInfo(stats);
1345b1b8bc3fSopenharmony_ci}
1346b1b8bc3fSopenharmony_ci
1347b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DeleteSimStatsInfo(uint32_t uid)
1348b1b8bc3fSopenharmony_ci{
1349b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1350b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1351b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1352b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1353b1b8bc3fSopenharmony_ci    }
1354b1b8bc3fSopenharmony_ci    return proxy->DeleteSimStatsInfo(uid);
1355b1b8bc3fSopenharmony_ci}
1356b1b8bc3fSopenharmony_ci
1357b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats)
1358b1b8bc3fSopenharmony_ci{
1359b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1360b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1361b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1362b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1363b1b8bc3fSopenharmony_ci    }
1364b1b8bc3fSopenharmony_ci    return proxy->GetAllStatsInfo(stats);
1365b1b8bc3fSopenharmony_ci}
1366b1b8bc3fSopenharmony_ci
1367b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DeleteStatsInfo(uint32_t uid)
1368b1b8bc3fSopenharmony_ci{
1369b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1370b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1371b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1372b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1373b1b8bc3fSopenharmony_ci    }
1374b1b8bc3fSopenharmony_ci    return proxy->DeleteStatsInfo(uid);
1375b1b8bc3fSopenharmony_ci}
1376b1b8bc3fSopenharmony_ci
1377b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetIptablesCommandForRes(const std::string &cmd, std::string &respond,
1378b1b8bc3fSopenharmony_ci    NetsysNative::IptablesType ipType)
1379b1b8bc3fSopenharmony_ci{
1380b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1381b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1382b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1383b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1384b1b8bc3fSopenharmony_ci    }
1385b1b8bc3fSopenharmony_ci    return proxy->SetIptablesCommandForRes(cmd, respond, ipType);
1386b1b8bc3fSopenharmony_ci}
1387b1b8bc3fSopenharmony_ci
1388b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagPingHost(const OHOS::NetsysNative::NetDiagPingOption &pingOption,
1389b1b8bc3fSopenharmony_ci                                            const sptr<OHOS::NetsysNative::INetDiagCallback> &callback)
1390b1b8bc3fSopenharmony_ci{
1391b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1392b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1393b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1394b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1395b1b8bc3fSopenharmony_ci    }
1396b1b8bc3fSopenharmony_ci    return proxy->NetDiagPingHost(pingOption, callback);
1397b1b8bc3fSopenharmony_ci}
1398b1b8bc3fSopenharmony_ci
1399b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagGetRouteTable(std::list<OHOS::NetsysNative::NetDiagRouteTable> &routeTables)
1400b1b8bc3fSopenharmony_ci{
1401b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1402b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1403b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1404b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1405b1b8bc3fSopenharmony_ci    }
1406b1b8bc3fSopenharmony_ci    return proxy->NetDiagGetRouteTable(routeTables);
1407b1b8bc3fSopenharmony_ci}
1408b1b8bc3fSopenharmony_ci
1409b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagGetSocketsInfo(OHOS::NetsysNative::NetDiagProtocolType socketType,
1410b1b8bc3fSopenharmony_ci                                                  OHOS::NetsysNative::NetDiagSocketsInfo &socketsInfo)
1411b1b8bc3fSopenharmony_ci{
1412b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1413b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1414b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1415b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1416b1b8bc3fSopenharmony_ci    }
1417b1b8bc3fSopenharmony_ci    return proxy->NetDiagGetSocketsInfo(socketType, socketsInfo);
1418b1b8bc3fSopenharmony_ci}
1419b1b8bc3fSopenharmony_ci
1420b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagGetInterfaceConfig(std::list<OHOS::NetsysNative::NetDiagIfaceConfig> &configs,
1421b1b8bc3fSopenharmony_ci                                                      const std::string &ifaceName)
1422b1b8bc3fSopenharmony_ci{
1423b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1424b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1425b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1426b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1427b1b8bc3fSopenharmony_ci    }
1428b1b8bc3fSopenharmony_ci    return proxy->NetDiagGetInterfaceConfig(configs, ifaceName);
1429b1b8bc3fSopenharmony_ci}
1430b1b8bc3fSopenharmony_ci
1431b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagUpdateInterfaceConfig(const OHOS::NetsysNative::NetDiagIfaceConfig &config,
1432b1b8bc3fSopenharmony_ci                                                         const std::string &ifaceName, bool add)
1433b1b8bc3fSopenharmony_ci{
1434b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1435b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1436b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1437b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1438b1b8bc3fSopenharmony_ci    }
1439b1b8bc3fSopenharmony_ci    return proxy->NetDiagUpdateInterfaceConfig(config, ifaceName, add);
1440b1b8bc3fSopenharmony_ci}
1441b1b8bc3fSopenharmony_ci
1442b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up)
1443b1b8bc3fSopenharmony_ci{
1444b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1445b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1446b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1447b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1448b1b8bc3fSopenharmony_ci    }
1449b1b8bc3fSopenharmony_ci    return proxy->NetDiagSetInterfaceActiveState(ifaceName, up);
1450b1b8bc3fSopenharmony_ci}
1451b1b8bc3fSopenharmony_ci
1452b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
1453b1b8bc3fSopenharmony_ci                                         const std::string &ifName)
1454b1b8bc3fSopenharmony_ci{
1455b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1456b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1457b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1458b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1459b1b8bc3fSopenharmony_ci    }
1460b1b8bc3fSopenharmony_ci    return proxy->AddStaticArp(ipAddr, macAddr, ifName);
1461b1b8bc3fSopenharmony_ci}
1462b1b8bc3fSopenharmony_ci
1463b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
1464b1b8bc3fSopenharmony_ci                                         const std::string &ifName)
1465b1b8bc3fSopenharmony_ci{
1466b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1467b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1468b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1469b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1470b1b8bc3fSopenharmony_ci    }
1471b1b8bc3fSopenharmony_ci    return proxy->DelStaticArp(ipAddr, macAddr, ifName);
1472b1b8bc3fSopenharmony_ci}
1473b1b8bc3fSopenharmony_ci
1474b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::RegisterDnsResultCallback(
1475b1b8bc3fSopenharmony_ci    const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback, uint32_t timeStep)
1476b1b8bc3fSopenharmony_ci{
1477b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("NetsysNativeClient::RegisterCallback");
1478b1b8bc3fSopenharmony_ci    if (callback == nullptr) {
1479b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Callback is nullptr");
1480b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_LOCAL_PTR_NULL;
1481b1b8bc3fSopenharmony_ci    }
1482b1b8bc3fSopenharmony_ci    std::lock_guard lock(cbDnsReportObjMutex_);
1483b1b8bc3fSopenharmony_ci    cbDnsReportObjects_.push_back(callback);
1484b1b8bc3fSopenharmony_ci    dnsReportTimeStep = timeStep;
1485b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1486b1b8bc3fSopenharmony_ci}
1487b1b8bc3fSopenharmony_ci
1488b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::UnregisterDnsResultCallback(
1489b1b8bc3fSopenharmony_ci    const sptr<OHOS::NetManagerStandard::NetsysDnsReportCallback> &callback)
1490b1b8bc3fSopenharmony_ci{
1491b1b8bc3fSopenharmony_ci    if (callback == nullptr) {
1492b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("Callback is nullptr");
1493b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_LOCAL_PTR_NULL;
1494b1b8bc3fSopenharmony_ci    }
1495b1b8bc3fSopenharmony_ci    std::lock_guard lock(cbDnsReportObjMutex_);
1496b1b8bc3fSopenharmony_ci    cbDnsReportObjects_.remove(callback);
1497b1b8bc3fSopenharmony_ci    return NETMANAGER_SUCCESS;
1498b1b8bc3fSopenharmony_ci}
1499b1b8bc3fSopenharmony_ci
1500b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::RegisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1501b1b8bc3fSopenharmony_ci{
1502b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1503b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1504b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1505b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1506b1b8bc3fSopenharmony_ci    }
1507b1b8bc3fSopenharmony_ci    return proxy->RegisterDnsHealthCallback(callback);
1508b1b8bc3fSopenharmony_ci}
1509b1b8bc3fSopenharmony_ci
1510b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::UnregisterDnsHealthCallback(const sptr<OHOS::NetsysNative::INetDnsHealthCallback> &callback)
1511b1b8bc3fSopenharmony_ci{
1512b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1513b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1514b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("NetsysNativeClient proxy is nullptr");
1515b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1516b1b8bc3fSopenharmony_ci    }
1517b1b8bc3fSopenharmony_ci    return proxy->UnregisterDnsHealthCallback(callback);
1518b1b8bc3fSopenharmony_ci}
1519b1b8bc3fSopenharmony_ci
1520b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie)
1521b1b8bc3fSopenharmony_ci{
1522b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1523b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1524b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1525b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1526b1b8bc3fSopenharmony_ci    }
1527b1b8bc3fSopenharmony_ci    return proxy->GetCookieStats(stats, type, cookie);
1528b1b8bc3fSopenharmony_ci}
1529b1b8bc3fSopenharmony_ci
1530b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn)
1531b1b8bc3fSopenharmony_ci{
1532b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1533b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1534b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1535b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1536b1b8bc3fSopenharmony_ci    }
1537b1b8bc3fSopenharmony_ci    return proxy->GetNetworkSharingType(sharingTypeIsOn);
1538b1b8bc3fSopenharmony_ci}
1539b1b8bc3fSopenharmony_ci
1540b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::UpdateNetworkSharingType(uint32_t type, bool isOpen)
1541b1b8bc3fSopenharmony_ci{
1542b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1543b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1544b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1545b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1546b1b8bc3fSopenharmony_ci    }
1547b1b8bc3fSopenharmony_ci    return proxy->UpdateNetworkSharingType(type, isOpen);
1548b1b8bc3fSopenharmony_ci}
1549b1b8bc3fSopenharmony_ci
1550b1b8bc3fSopenharmony_ci#ifdef FEATURE_NET_FIREWALL_ENABLE
1551b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetFirewallRules(NetFirewallRuleType type,
1552b1b8bc3fSopenharmony_ci                                             const std::vector<sptr<NetFirewallBaseRule>> &ruleList, bool isFinish)
1553b1b8bc3fSopenharmony_ci{
1554b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::SetFirewallRules");
1555b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1556b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1557b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1558b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1559b1b8bc3fSopenharmony_ci    }
1560b1b8bc3fSopenharmony_ci    return proxy->SetFirewallRules(type, ruleList, isFinish);
1561b1b8bc3fSopenharmony_ci}
1562b1b8bc3fSopenharmony_ci
1563b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetFirewallDefaultAction(FirewallRuleAction inDefault, FirewallRuleAction outDefault)
1564b1b8bc3fSopenharmony_ci{
1565b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::SetFirewallDefaultAction");
1566b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1567b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1568b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1569b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1570b1b8bc3fSopenharmony_ci    }
1571b1b8bc3fSopenharmony_ci    return proxy->SetFirewallDefaultAction(inDefault, outDefault);
1572b1b8bc3fSopenharmony_ci}
1573b1b8bc3fSopenharmony_ci
1574b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetFirewallCurrentUserId(int32_t userId)
1575b1b8bc3fSopenharmony_ci{
1576b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::SetFirewallCurrentUserId");
1577b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1578b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1579b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1580b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1581b1b8bc3fSopenharmony_ci    }
1582b1b8bc3fSopenharmony_ci    return proxy->SetFirewallCurrentUserId(userId);
1583b1b8bc3fSopenharmony_ci}
1584b1b8bc3fSopenharmony_ci
1585b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::ClearFirewallRules(NetFirewallRuleType type)
1586b1b8bc3fSopenharmony_ci{
1587b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::ClearFirewallRules");
1588b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1589b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1590b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1591b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1592b1b8bc3fSopenharmony_ci    }
1593b1b8bc3fSopenharmony_ci    return proxy->ClearFirewallRules(type);
1594b1b8bc3fSopenharmony_ci}
1595b1b8bc3fSopenharmony_ci
1596b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::RegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback)
1597b1b8bc3fSopenharmony_ci{
1598b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::RegisterNetFirewallCallback");
1599b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1600b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1601b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1602b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1603b1b8bc3fSopenharmony_ci    }
1604b1b8bc3fSopenharmony_ci    return proxy->RegisterNetFirewallCallback(callback);
1605b1b8bc3fSopenharmony_ci}
1606b1b8bc3fSopenharmony_ci
1607b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::UnRegisterNetFirewallCallback(const sptr<NetsysNative::INetFirewallCallback> &callback)
1608b1b8bc3fSopenharmony_ci{
1609b1b8bc3fSopenharmony_ci    NETMGR_LOG_D("NetsysNativeClient::UnRegisterNetFirewallCallback");
1610b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1611b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1612b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1613b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1614b1b8bc3fSopenharmony_ci    }
1615b1b8bc3fSopenharmony_ci    return proxy->UnRegisterNetFirewallCallback(callback);
1616b1b8bc3fSopenharmony_ci}
1617b1b8bc3fSopenharmony_ci#endif
1618b1b8bc3fSopenharmony_ci
1619b1b8bc3fSopenharmony_ci#ifdef FEATURE_WEARABLE_DISTRIBUTED_NET_ENABLE
1620b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::EnableWearableDistributedNetForward(const int32_t tcpPortId, const int32_t udpPortId)
1621b1b8bc3fSopenharmony_ci{
1622b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Enabling wearable distributed net forward for TCP port and UDP port");
1623b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1624b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1625b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1626b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1627b1b8bc3fSopenharmony_ci    }
1628b1b8bc3fSopenharmony_ci    return proxy->EnableWearableDistributedNetForward(tcpPortId, udpPortId);
1629b1b8bc3fSopenharmony_ci}
1630b1b8bc3fSopenharmony_ci
1631b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DisableWearableDistributedNetForward()
1632b1b8bc3fSopenharmony_ci{
1633b1b8bc3fSopenharmony_ci    NETMGR_LOG_I("Disabling wearable distributed net forward");
1634b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1635b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1636b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1637b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1638b1b8bc3fSopenharmony_ci    }
1639b1b8bc3fSopenharmony_ci    return proxy->DisableWearableDistributedNetForward();
1640b1b8bc3fSopenharmony_ci}
1641b1b8bc3fSopenharmony_ci#endif
1642b1b8bc3fSopenharmony_ci
1643b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on)
1644b1b8bc3fSopenharmony_ci{
1645b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1646b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1647b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1648b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1649b1b8bc3fSopenharmony_ci    }
1650b1b8bc3fSopenharmony_ci    return proxy->SetIpv6PrivacyExtensions(interfaceName, on);
1651b1b8bc3fSopenharmony_ci}
1652b1b8bc3fSopenharmony_ci
1653b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetEnableIpv6(const std::string &interfaceName, const uint32_t on)
1654b1b8bc3fSopenharmony_ci{
1655b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1656b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1657b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1658b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1659b1b8bc3fSopenharmony_ci    }
1660b1b8bc3fSopenharmony_ci    return proxy->SetEnableIpv6(interfaceName, on);
1661b1b8bc3fSopenharmony_ci}
1662b1b8bc3fSopenharmony_ci
1663b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag,
1664b1b8bc3fSopenharmony_ci                                                   bool isBroker)
1665b1b8bc3fSopenharmony_ci{
1666b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1667b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1668b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1669b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1670b1b8bc3fSopenharmony_ci    }
1671b1b8bc3fSopenharmony_ci
1672b1b8bc3fSopenharmony_ci    return proxy->SetNetworkAccessPolicy(uid, policy, reconfirmFlag, isBroker);
1673b1b8bc3fSopenharmony_ci}
1674b1b8bc3fSopenharmony_ci
1675b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::DeleteNetworkAccessPolicy(uint32_t uid)
1676b1b8bc3fSopenharmony_ci{
1677b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1678b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1679b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1680b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1681b1b8bc3fSopenharmony_ci    }
1682b1b8bc3fSopenharmony_ci
1683b1b8bc3fSopenharmony_ci    return proxy->DeleteNetworkAccessPolicy(uid);
1684b1b8bc3fSopenharmony_ci}
1685b1b8bc3fSopenharmony_ci
1686b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::ClearFirewallAllRules()
1687b1b8bc3fSopenharmony_ci{
1688b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1689b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1690b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1691b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1692b1b8bc3fSopenharmony_ci    }
1693b1b8bc3fSopenharmony_ci
1694b1b8bc3fSopenharmony_ci    return proxy->ClearFirewallAllRules();
1695b1b8bc3fSopenharmony_ci}
1696b1b8bc3fSopenharmony_ci
1697b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes)
1698b1b8bc3fSopenharmony_ci{
1699b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1700b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1701b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1702b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1703b1b8bc3fSopenharmony_ci    }
1704b1b8bc3fSopenharmony_ci
1705b1b8bc3fSopenharmony_ci    return proxy->NotifyNetBearerTypeChange(bearerTypes);
1706b1b8bc3fSopenharmony_ci}
1707b1b8bc3fSopenharmony_ci
1708b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StartClat(const std::string &interfaceName, int32_t netId,
1709b1b8bc3fSopenharmony_ci                                      const std::string &nat64PrefixStr)
1710b1b8bc3fSopenharmony_ci{
1711b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1712b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1713b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1714b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1715b1b8bc3fSopenharmony_ci    }
1716b1b8bc3fSopenharmony_ci    return proxy->StartClat(interfaceName, netId, nat64PrefixStr);
1717b1b8bc3fSopenharmony_ci}
1718b1b8bc3fSopenharmony_ci
1719b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::StopClat(const std::string &interfaceName)
1720b1b8bc3fSopenharmony_ci{
1721b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1722b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1723b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1724b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1725b1b8bc3fSopenharmony_ci    }
1726b1b8bc3fSopenharmony_ci    return proxy->StopClat(interfaceName);
1727b1b8bc3fSopenharmony_ci}
1728b1b8bc3fSopenharmony_ci
1729b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status)
1730b1b8bc3fSopenharmony_ci{
1731b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1732b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1733b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1734b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1735b1b8bc3fSopenharmony_ci    }
1736b1b8bc3fSopenharmony_ci    return proxy->SetNicTrafficAllowed(ifaceNames, status);
1737b1b8bc3fSopenharmony_ci}
1738b1b8bc3fSopenharmony_ci
1739b1b8bc3fSopenharmony_ci#ifdef SUPPORT_SYSVPN
1740b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::ProcessVpnStage(NetsysNative::SysVpnStageCode stage)
1741b1b8bc3fSopenharmony_ci{
1742b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1743b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1744b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1745b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1746b1b8bc3fSopenharmony_ci    }
1747b1b8bc3fSopenharmony_ci    return proxy->ProcessVpnStage(stage);
1748b1b8bc3fSopenharmony_ci}
1749b1b8bc3fSopenharmony_ci#endif // SUPPORT_SYSVPN
1750b1b8bc3fSopenharmony_ci
1751b1b8bc3fSopenharmony_ciint32_t NetsysNativeClient::CloseSocketsUid(const std::string &ipAddr, uint32_t uid)
1752b1b8bc3fSopenharmony_ci{
1753b1b8bc3fSopenharmony_ci    auto proxy = GetProxy();
1754b1b8bc3fSopenharmony_ci    if (proxy == nullptr) {
1755b1b8bc3fSopenharmony_ci        NETMGR_LOG_E("proxy is nullptr");
1756b1b8bc3fSopenharmony_ci        return NETMANAGER_ERR_GET_PROXY_FAIL;
1757b1b8bc3fSopenharmony_ci    }
1758b1b8bc3fSopenharmony_ci    return proxy->CloseSocketsUid(ipAddr, uid);
1759b1b8bc3fSopenharmony_ci}
1760b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard
1761b1b8bc3fSopenharmony_ci} // namespace OHOS
1762