1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <csignal>
17 #include <sys/types.h>
18 #include <thread>
19 #include <unistd.h>
20
21 #include "iservice_registry.h"
22 #include "system_ability_definition.h"
23
24 #include "net_manager_constants.h"
25 #include "netmanager_base_common_utils.h"
26 #include "netnative_log_wrapper.h"
27 #include "netsys_native_service.h"
28
29 using namespace OHOS::NetManagerStandard::CommonUtils;
30 namespace OHOS {
31 namespace NetsysNative {
32 constexpr int32_t START_TIME_MS = 1900;
33 constexpr int32_t EXTRA_MONTH = 1;
34
REGISTER_SYSTEM_ABILITY_BY_ID(NetsysNativeService,COMM_NETSYS_NATIVE_SYS_ABILITY_ID,true)35 REGISTER_SYSTEM_ABILITY_BY_ID(NetsysNativeService, COMM_NETSYS_NATIVE_SYS_ABILITY_ID, true)
36
37 NetsysNativeService::NetsysNativeService()
38 : SystemAbility(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID, true),
39 netsysService_(nullptr),
40 manager_(nullptr),
41 notifyCallback_(nullptr)
42 {
43 }
44
OnStart()45 void NetsysNativeService::OnStart()
46 {
47 NETNATIVE_LOGI("NetsysNativeService::OnStart Begin");
48 std::lock_guard<std::mutex> guard(instanceLock_);
49 if (state_ == ServiceRunningState::STATE_RUNNING) {
50 return;
51 }
52
53 if (!Init()) {
54 NETNATIVE_LOGE("NetsysNativeService init failed!");
55 return;
56 }
57 bool res = SystemAbility::Publish(this);
58 if (!res) {
59 NETNATIVE_LOGE("publishing NetsysNativeService to sa manager failed!");
60 return;
61 }
62 NETNATIVE_LOGI("Publish NetsysNativeService SUCCESS");
63 state_ = ServiceRunningState::STATE_RUNNING;
64 struct tm *timeNow;
65 time_t second = time(0);
66 if (second < 0) {
67 return;
68 }
69 timeNow = localtime(&second);
70 if (timeNow != nullptr) {
71 NETNATIVE_LOGI(
72 "NetsysNativeService start time:%{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d",
73 timeNow->tm_year + START_TIME_MS, timeNow->tm_mon + EXTRA_MONTH, timeNow->tm_mday, timeNow->tm_hour,
74 timeNow->tm_min, timeNow->tm_sec);
75 }
76 manager_->StartListener();
77 }
78
OnStop()79 void NetsysNativeService::OnStop()
80 {
81 std::lock_guard<std::mutex> guard(instanceLock_);
82 struct tm *timeNow;
83 time_t second = time(0);
84 if (second < 0) {
85 return;
86 }
87 timeNow = localtime(&second);
88 if (timeNow != nullptr) {
89 NETNATIVE_LOGI(
90 "NetsysNativeService dump time:%{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d",
91 timeNow->tm_year + START_TIME_MS, timeNow->tm_mon + EXTRA_MONTH, timeNow->tm_mday, timeNow->tm_hour,
92 timeNow->tm_min, timeNow->tm_sec);
93 }
94 state_ = ServiceRunningState::STATE_STOPPED;
95 manager_->StopListener();
96 }
97
Dump(int32_t fd,const std::vector<std::u16string> & args)98 int32_t NetsysNativeService::Dump(int32_t fd, const std::vector<std::u16string> &args)
99 {
100 NETNATIVE_LOG_D("Start Dump, fd: %{public}d", fd);
101 std::string result;
102 GetDumpMessage(result);
103 int32_t ret = dprintf(fd, "%s\n", result.c_str());
104 return ret < 0 ? SESSION_UNOPEN_ERR : ERR_NONE;
105 }
106
GetDumpMessage(std::string & message)107 void NetsysNativeService::GetDumpMessage(std::string &message)
108 {
109 netsysService_->GetDumpInfo(message);
110 }
111
ExitHandler(int32_t signum)112 void ExitHandler(int32_t signum)
113 {
114 (void)signum;
115 exit(1);
116 }
117
Init()118 bool NetsysNativeService::Init()
119 {
120 (void)signal(SIGTERM, ExitHandler);
121 (void)signal(SIGABRT, ExitHandler);
122
123 netsysService_ = std::make_unique<nmd::NetManagerNative>();
124 if (netsysService_ == nullptr) {
125 NETNATIVE_LOGE("netsysService_ is nullptr!");
126 return false;
127 }
128 netsysService_->Init();
129
130 manager_ = std::make_unique<OHOS::nmd::NetlinkManager>();
131 if (manager_ == nullptr) {
132 NETNATIVE_LOGE("manager_ is nullptr!");
133 return false;
134 }
135 dhcpController_ = std::make_unique<OHOS::nmd::DhcpController>();
136 fwmarkNetwork_ = std::make_unique<OHOS::nmd::FwmarkNetwork>();
137 sharingManager_ = std::make_unique<SharingManager>();
138
139 AddSystemAbilityListener(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID);
140 return true;
141 }
142
OnNetManagerRestart()143 void NetsysNativeService::OnNetManagerRestart()
144 {
145 NETNATIVE_LOGI("NetsysNativeClient::OnNetManagerRestart");
146 if (netsysService_ != nullptr) {
147 netsysService_->NetworkReinitRoute();
148 }
149 if (manager_ != nullptr && notifyCallback_ != nullptr) {
150 manager_->UnregisterNetlinkCallback(notifyCallback_);
151 }
152 }
153
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)154 int32_t NetsysNativeService::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
155 const std::vector<std::string> &servers,
156 const std::vector<std::string> &domains)
157 {
158 netsysService_->DnsSetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
159 return 0;
160 }
161
GetResolverConfig(const uint16_t netid,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)162 int32_t NetsysNativeService::GetResolverConfig(const uint16_t netid, std::vector<std::string> &servers,
163 std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
164 uint8_t &retryCount)
165 {
166 NETNATIVE_LOG_D("GetResolverConfig netid = %{public}d", netid);
167 netsysService_->DnsGetResolverConfig(netid, servers, domains, baseTimeoutMsec, retryCount);
168 return 0;
169 }
170
CreateNetworkCache(const uint16_t netid)171 int32_t NetsysNativeService::CreateNetworkCache(const uint16_t netid)
172 {
173 NETNATIVE_LOG_D("CreateNetworkCache Begin");
174 netsysService_->DnsCreateNetworkCache(netid);
175
176 return 0;
177 }
178
DestroyNetworkCache(const uint16_t netId)179 int32_t NetsysNativeService::DestroyNetworkCache(const uint16_t netId)
180 {
181 NETNATIVE_LOG_D("DestroyNetworkCache");
182 return netsysService_->DnsDestroyNetworkCache(netId);
183 }
184
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)185 int32_t NetsysNativeService::GetAddrInfo(const std::string &hostName, const std::string &serverName,
186 const AddrInfo &hints, uint16_t netId, std::vector<AddrInfo> &res)
187 {
188 return netsysService_->DnsGetAddrInfo(hostName, serverName, hints, netId, res);
189 }
190
InterfaceSetMtu(const std::string & interfaceName,int32_t mtu)191 int32_t NetsysNativeService::InterfaceSetMtu(const std::string &interfaceName, int32_t mtu)
192 {
193 NETNATIVE_LOG_D("InterfaceSetMtu Begin");
194 return netsysService_->InterfaceSetMtu(interfaceName, mtu);
195 }
196
InterfaceGetMtu(const std::string & interfaceName)197 int32_t NetsysNativeService::InterfaceGetMtu(const std::string &interfaceName)
198 {
199 NETNATIVE_LOG_D("InterfaceSetMtu Begin");
200 return netsysService_->InterfaceGetMtu(interfaceName);
201 }
202
RegisterNotifyCallback(sptr<INotifyCallback> & callback)203 int32_t NetsysNativeService::RegisterNotifyCallback(sptr<INotifyCallback> &callback)
204 {
205 NETNATIVE_LOG_D("RegisterNotifyCallback");
206 notifyCallback_ = callback;
207 dhcpController_->RegisterNotifyCallback(callback);
208 manager_->RegisterNetlinkCallback(callback);
209 return 0;
210 }
211
UnRegisterNotifyCallback(sptr<INotifyCallback> & callback)212 int32_t NetsysNativeService::UnRegisterNotifyCallback(sptr<INotifyCallback> &callback)
213 {
214 NETNATIVE_LOGI("UnRegisterNotifyCallback");
215 manager_->UnregisterNetlinkCallback(notifyCallback_);
216 return 0;
217 }
218
NetworkAddRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)219 int32_t NetsysNativeService::NetworkAddRoute(int32_t netId, const std::string &interfaceName,
220 const std::string &destination, const std::string &nextHop)
221 {
222 NETNATIVE_LOG_D("NetsysNativeService::NetworkAddRoute unpacket %{public}d %{public}s %{public}s %{public}s", netId,
223 interfaceName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
224
225 int32_t result = netsysService_->NetworkAddRoute(netId, interfaceName, destination, nextHop);
226 NETNATIVE_LOG_D("NetworkAddRoute %{public}d", result);
227 return result;
228 }
229
NetworkRemoveRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)230 int32_t NetsysNativeService::NetworkRemoveRoute(int32_t netId, const std::string &interfaceName,
231 const std::string &destination, const std::string &nextHop)
232 {
233 int32_t result = netsysService_->NetworkRemoveRoute(netId, interfaceName, destination, nextHop);
234 NETNATIVE_LOG_D("NetworkRemoveRoute %{public}d", result);
235 return result;
236 }
237
NetworkAddRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)238 int32_t NetsysNativeService::NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo)
239 {
240 int32_t result = netsysService_->NetworkAddRouteParcel(netId, routeInfo);
241 NETNATIVE_LOG_D("NetworkAddRouteParcel %{public}d", result);
242 return result;
243 }
244
NetworkRemoveRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)245 int32_t NetsysNativeService::NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo)
246 {
247 int32_t result = netsysService_->NetworkRemoveRouteParcel(netId, routeInfo);
248 NETNATIVE_LOG_D("NetworkRemoveRouteParcel %{public}d", result);
249 return result;
250 }
251
NetworkSetDefault(int32_t netId)252 int32_t NetsysNativeService::NetworkSetDefault(int32_t netId)
253 {
254 NETNATIVE_LOG_D("NetworkSetDefault in.");
255 int32_t result = netsysService_->NetworkSetDefault(netId);
256 NETNATIVE_LOG_D("NetworkSetDefault out.");
257 return result;
258 }
259
NetworkGetDefault()260 int32_t NetsysNativeService::NetworkGetDefault()
261 {
262 int32_t result = netsysService_->NetworkGetDefault();
263 NETNATIVE_LOG_D("NetworkGetDefault");
264 return result;
265 }
266
NetworkClearDefault()267 int32_t NetsysNativeService::NetworkClearDefault()
268 {
269 int32_t result = netsysService_->NetworkClearDefault();
270 NETNATIVE_LOG_D("NetworkClearDefault");
271 return result;
272 }
273
GetProcSysNet(int32_t ipversion,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)274 int32_t NetsysNativeService::GetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname,
275 const std::string ¶meter, std::string &value)
276 {
277 int32_t result = netsysService_->GetProcSysNet(ipversion, which, ifname, parameter, &value);
278 NETNATIVE_LOG_D("GetProcSysNet");
279 return result;
280 }
281
SetProcSysNet(int32_t ipversion,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)282 int32_t NetsysNativeService::SetProcSysNet(int32_t ipversion, int32_t which, const std::string &ifname,
283 const std::string ¶meter, std::string &value)
284 {
285 int32_t result = netsysService_->SetProcSysNet(ipversion, which, ifname, parameter, value);
286 NETNATIVE_LOG_D("SetProcSysNet");
287 return result;
288 }
289
NetworkCreatePhysical(int32_t netId,int32_t permission)290 int32_t NetsysNativeService::NetworkCreatePhysical(int32_t netId, int32_t permission)
291 {
292 int32_t result = netsysService_->NetworkCreatePhysical(netId, permission);
293 NETNATIVE_LOG_D("NetworkCreatePhysical out.");
294 return result;
295 }
296
InterfaceAddAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)297 int32_t NetsysNativeService::InterfaceAddAddress(const std::string &interfaceName, const std::string &addrString,
298 int32_t prefixLength)
299 {
300 int32_t result = netsysService_->InterfaceAddAddress(interfaceName, addrString, prefixLength);
301 NETNATIVE_LOG_D("InterfaceAddAddress");
302 return result;
303 }
304
InterfaceDelAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)305 int32_t NetsysNativeService::InterfaceDelAddress(const std::string &interfaceName, const std::string &addrString,
306 int32_t prefixLength)
307 {
308 int32_t result = netsysService_->InterfaceDelAddress(interfaceName, addrString, prefixLength);
309 NETNATIVE_LOG_D("InterfaceDelAddress");
310 return result;
311 }
312
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)313 int32_t NetsysNativeService::InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress)
314 {
315 NETNATIVE_LOG_D("InterfaceSetIpAddress");
316 return netsysService_->InterfaceSetIpAddress(ifaceName, ipAddress);
317 }
318
InterfaceSetIffUp(const std::string & ifaceName)319 int32_t NetsysNativeService::InterfaceSetIffUp(const std::string &ifaceName)
320 {
321 NETNATIVE_LOG_D("InterfaceSetIffUp");
322 return netsysService_->InterfaceSetIffUp(ifaceName);
323 }
324
NetworkAddInterface(int32_t netId,const std::string & iface)325 int32_t NetsysNativeService::NetworkAddInterface(int32_t netId, const std::string &iface)
326 {
327 NETNATIVE_LOG_D("NetworkAddInterface");
328 int32_t result = netsysService_->NetworkAddInterface(netId, iface);
329 return result;
330 }
331
NetworkRemoveInterface(int32_t netId,const std::string & iface)332 int32_t NetsysNativeService::NetworkRemoveInterface(int32_t netId, const std::string &iface)
333 {
334 int32_t result = netsysService_->NetworkRemoveInterface(netId, iface);
335 NETNATIVE_LOG_D("NetworkRemoveInterface");
336 return result;
337 }
338
NetworkDestroy(int32_t netId)339 int32_t NetsysNativeService::NetworkDestroy(int32_t netId)
340 {
341 int32_t result = netsysService_->NetworkDestroy(netId);
342 NETNATIVE_LOG_D("NetworkDestroy");
343 return result;
344 }
345
GetFwmarkForNetwork(int32_t netId,MarkMaskParcel & markMaskParcel)346 int32_t NetsysNativeService::GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel)
347 {
348 markMaskParcel = netsysService_->GetFwmarkForNetwork(netId);
349 NETNATIVE_LOG_D("GetFwmarkForNetwork");
350 return ERR_NONE;
351 }
352
InterfaceSetConfig(const InterfaceConfigurationParcel & cfg)353 int32_t NetsysNativeService::InterfaceSetConfig(const InterfaceConfigurationParcel &cfg)
354 {
355 NETNATIVE_LOG_D("InterfaceSetConfig");
356 netsysService_->InterfaceSetConfig(cfg);
357 return ERR_NONE;
358 }
359
InterfaceGetConfig(InterfaceConfigurationParcel & cfg)360 int32_t NetsysNativeService::InterfaceGetConfig(InterfaceConfigurationParcel &cfg)
361 {
362 NETNATIVE_LOG_D("InterfaceGetConfig");
363 std::string ifName = cfg.ifName;
364 cfg = netsysService_->InterfaceGetConfig(ifName);
365 NETNATIVE_LOG_D("InterfaceGetConfig end");
366 return ERR_NONE;
367 }
368
InterfaceGetList(std::vector<std::string> & ifaces)369 int32_t NetsysNativeService::InterfaceGetList(std::vector<std::string> &ifaces)
370 {
371 NETNATIVE_LOG_D("InterfaceGetList");
372 ifaces = netsysService_->InterfaceGetList();
373 return ERR_NONE;
374 }
375
StartDhcpClient(const std::string & iface,bool bIpv6)376 int32_t NetsysNativeService::StartDhcpClient(const std::string &iface, bool bIpv6)
377 {
378 NETNATIVE_LOG_D("StartDhcpClient");
379 dhcpController_->StartDhcpClient(iface, bIpv6);
380 return ERR_NONE;
381 }
382
StopDhcpClient(const std::string & iface,bool bIpv6)383 int32_t NetsysNativeService::StopDhcpClient(const std::string &iface, bool bIpv6)
384 {
385 NETNATIVE_LOG_D("StopDhcpClient");
386 dhcpController_->StopDhcpClient(iface, bIpv6);
387 return ERR_NONE;
388 }
389
StartDhcpService(const std::string & iface,const std::string & ipv4addr)390 int32_t NetsysNativeService::StartDhcpService(const std::string &iface, const std::string &ipv4addr)
391 {
392 NETNATIVE_LOG_D("StartDhcpService");
393 dhcpController_->StartDhcpService(iface, ipv4addr);
394 return ERR_NONE;
395 }
396
StopDhcpService(const std::string & iface)397 int32_t NetsysNativeService::StopDhcpService(const std::string &iface)
398 {
399 NETNATIVE_LOG_D("StopDhcpService");
400 dhcpController_->StopDhcpService(iface);
401 return ERR_NONE;
402 }
403
IpEnableForwarding(const std::string & requester)404 int32_t NetsysNativeService::IpEnableForwarding(const std::string &requester)
405 {
406 NETNATIVE_LOG_D("ipEnableForwarding");
407 return netsysService_->IpEnableForwarding(requester);
408 }
409
IpDisableForwarding(const std::string & requester)410 int32_t NetsysNativeService::IpDisableForwarding(const std::string &requester)
411 {
412 NETNATIVE_LOG_D("ipDisableForwarding");
413 return netsysService_->IpDisableForwarding(requester);
414 }
415
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)416 int32_t NetsysNativeService::EnableNat(const std::string &downstreamIface, const std::string &upstreamIface)
417 {
418 NETNATIVE_LOG_D("enableNat");
419 return netsysService_->EnableNat(downstreamIface, upstreamIface);
420 }
421
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)422 int32_t NetsysNativeService::DisableNat(const std::string &downstreamIface, const std::string &upstreamIface)
423 {
424 NETNATIVE_LOG_D("disableNat");
425 return netsysService_->DisableNat(downstreamIface, upstreamIface);
426 }
427
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)428 int32_t NetsysNativeService::IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface)
429 {
430 NETNATIVE_LOG_D("ipfwdAddInterfaceForward");
431 return netsysService_->IpfwdAddInterfaceForward(fromIface, toIface);
432 }
433
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)434 int32_t NetsysNativeService::IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface)
435 {
436 NETNATIVE_LOG_D("ipfwdRemoveInterfaceForward");
437 return netsysService_->IpfwdRemoveInterfaceForward(fromIface, toIface);
438 }
439
BandwidthEnableDataSaver(bool enable)440 int32_t NetsysNativeService::BandwidthEnableDataSaver(bool enable)
441 {
442 NETNATIVE_LOG_D("bandwidthEnableDataSaver");
443 return netsysService_->BandwidthEnableDataSaver(enable);
444 }
445
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)446 int32_t NetsysNativeService::BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes)
447 {
448 NETNATIVE_LOG_D("BandwidthSetIfaceQuota");
449 return netsysService_->BandwidthSetIfaceQuota(ifName, bytes);
450 }
451
BandwidthRemoveIfaceQuota(const std::string & ifName)452 int32_t NetsysNativeService::BandwidthRemoveIfaceQuota(const std::string &ifName)
453 {
454 NETNATIVE_LOG_D("BandwidthRemoveIfaceQuota");
455 return netsysService_->BandwidthRemoveIfaceQuota(ifName);
456 }
457
BandwidthAddDeniedList(uint32_t uid)458 int32_t NetsysNativeService::BandwidthAddDeniedList(uint32_t uid)
459 {
460 NETNATIVE_LOG_D("BandwidthAddDeniedList");
461 return netsysService_->BandwidthAddDeniedList(uid);
462 }
463
BandwidthRemoveDeniedList(uint32_t uid)464 int32_t NetsysNativeService::BandwidthRemoveDeniedList(uint32_t uid)
465 {
466 NETNATIVE_LOG_D("BandwidthRemoveDeniedList");
467 return netsysService_->BandwidthRemoveDeniedList(uid);
468 }
469
BandwidthAddAllowedList(uint32_t uid)470 int32_t NetsysNativeService::BandwidthAddAllowedList(uint32_t uid)
471 {
472 NETNATIVE_LOG_D("BandwidthAddAllowedList");
473 return netsysService_->BandwidthAddAllowedList(uid);
474 }
475
BandwidthRemoveAllowedList(uint32_t uid)476 int32_t NetsysNativeService::BandwidthRemoveAllowedList(uint32_t uid)
477 {
478 NETNATIVE_LOG_D("BandwidthRemoveAllowedList");
479 return netsysService_->BandwidthRemoveAllowedList(uid);
480 }
481
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)482 int32_t NetsysNativeService::FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
483 {
484 NETNATIVE_LOG_D("FirewallSetUidsAllowedListChain");
485 return netsysService_->FirewallSetUidsAllowedListChain(chain, uids);
486 }
487
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)488 int32_t NetsysNativeService::FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids)
489 {
490 NETNATIVE_LOG_D("FirewallSetUidsDeniedListChain");
491 return netsysService_->FirewallSetUidsDeniedListChain(chain, uids);
492 }
493
FirewallEnableChain(uint32_t chain,bool enable)494 int32_t NetsysNativeService::FirewallEnableChain(uint32_t chain, bool enable)
495 {
496 NETNATIVE_LOG_D("FirewallEnableChain");
497 return netsysService_->FirewallEnableChain(chain, enable);
498 }
499
FirewallSetUidRule(uint32_t chain,uint32_t uid,uint32_t firewallRule)500 int32_t NetsysNativeService::FirewallSetUidRule(uint32_t chain, uint32_t uid, uint32_t firewallRule)
501 {
502 NETNATIVE_LOG_D("firewallSetUidRule");
503 return netsysService_->FirewallSetUidRule(chain, uid, firewallRule);
504 }
505
ShareDnsSet(uint16_t netid)506 int32_t NetsysNativeService::ShareDnsSet(uint16_t netid)
507 {
508 NETNATIVE_LOG_D("NetsysNativeService ShareDnsSet");
509 if (netsysService_ == nullptr) {
510 NETNATIVE_LOGE("netsysService_ is null");
511 return -1;
512 }
513 netsysService_->ShareDnsSet(netid);
514 return ERR_NONE;
515 }
516
StartDnsProxyListen()517 int32_t NetsysNativeService::StartDnsProxyListen()
518 {
519 NETNATIVE_LOG_D("NetsysNativeService StartDnsProxyListen");
520 if (netsysService_ == nullptr) {
521 NETNATIVE_LOGE("netsysService_ is null");
522 return -1;
523 }
524 netsysService_->StartDnsProxyListen();
525 return ERR_NONE;
526 }
527
StopDnsProxyListen()528 int32_t NetsysNativeService::StopDnsProxyListen()
529 {
530 NETNATIVE_LOG_D("NetsysNativeService StopDnsProxyListen");
531 if (netsysService_ == nullptr) {
532 NETNATIVE_LOGE("netsysService_ is null");
533 return -1;
534 }
535 netsysService_->StopDnsProxyListen();
536 return ERR_NONE;
537 }
538
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,NetworkSharingTraffic & traffic)539 int32_t NetsysNativeService::GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
540 NetworkSharingTraffic &traffic)
541 {
542 if (sharingManager_ == nullptr) {
543 NETNATIVE_LOGE("manager is null.");
544 return NetManagerStandard::NETMANAGER_ERROR;
545 }
546 return sharingManager_->GetNetworkSharingTraffic(downIface, upIface, traffic);
547 }
548
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)549 void NetsysNativeService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
550 {
551 NETNATIVE_LOGI("NetsysNativeService::OnAddSystemAbility systemAbilityId[%{public}d]", systemAbilityId);
552 if (systemAbilityId == COMM_NET_CONN_MANAGER_SYS_ABILITY_ID) {
553 if (!hasSARemoved_) {
554 hasSARemoved_ = true;
555 return;
556 }
557 OnNetManagerRestart();
558 }
559 }
560
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)561 void NetsysNativeService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
562 {
563 NETNATIVE_LOGI("NetsysNativeService::OnRemoveSystemAbility systemAbilityId[%{public}d]", systemAbilityId);
564 if (systemAbilityId == COMM_NET_CONN_MANAGER_SYS_ABILITY_ID) {
565 OnNetManagerRestart();
566 hasSARemoved_ = true;
567 }
568 }
569 } // namespace NetsysNative
570 } // namespace OHOS
571