• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
17 #include <net/route.h>
18 #include <netdb.h>
19 #include <unistd.h>
20 
21 #include "netmanager_base_common_utils.h"
22 #include "netnative_log_wrapper.h"
23 #include "securec.h"
24 
25 #include "netsys_native_service_stub.h"
26 
27 using namespace OHOS::NetManagerStandard::CommonUtils;
28 namespace OHOS {
29 namespace NetsysNative {
30 static constexpr int32_t MAX_FLAG_NUM = 64;
31 static constexpr int32_t MAX_DNS_CONFIG_SIZE = 4;
32 static constexpr uint32_t UIDS_LIST_MAX_SIZE = 1024;
33 
NetsysNativeServiceStub()34 NetsysNativeServiceStub::NetsysNativeServiceStub()
35 {
36     opToInterfaceMap_[NETSYS_SET_RESOLVER_CONFIG] = &NetsysNativeServiceStub::CmdSetResolverConfig;
37     opToInterfaceMap_[NETSYS_GET_RESOLVER_CONFIG] = &NetsysNativeServiceStub::CmdGetResolverConfig;
38     opToInterfaceMap_[NETSYS_CREATE_NETWORK_CACHE] = &NetsysNativeServiceStub::CmdCreateNetworkCache;
39     opToInterfaceMap_[NETSYS_DESTROY_NETWORK_CACHE] = &NetsysNativeServiceStub::CmdDestroyNetworkCache;
40     opToInterfaceMap_[NETSYS_GET_ADDR_INFO] = &NetsysNativeServiceStub::CmdGetAddrInfo;
41     opToInterfaceMap_[NETSYS_INTERFACE_SET_MTU] = &NetsysNativeServiceStub::CmdInterfaceSetMtu;
42     opToInterfaceMap_[NETSYS_INTERFACE_GET_MTU] = &NetsysNativeServiceStub::CmdInterfaceGetMtu;
43     opToInterfaceMap_[NETSYS_REGISTER_NOTIFY_CALLBACK] = &NetsysNativeServiceStub::CmdRegisterNotifyCallback;
44     opToInterfaceMap_[NETSYS_UNREGISTER_NOTIFY_CALLBACK] = &NetsysNativeServiceStub::CmdUnRegisterNotifyCallback;
45     opToInterfaceMap_[NETSYS_NETWORK_ADD_ROUTE] = &NetsysNativeServiceStub::CmdNetworkAddRoute;
46     opToInterfaceMap_[NETSYS_NETWORK_REMOVE_ROUTE] = &NetsysNativeServiceStub::CmdNetworkRemoveRoute;
47     opToInterfaceMap_[NETSYS_NETWORK_ADD_ROUTE_PARCEL] = &NetsysNativeServiceStub::CmdNetworkAddRouteParcel;
48     opToInterfaceMap_[NETSYS_NETWORK_REMOVE_ROUTE_PARCEL] = &NetsysNativeServiceStub::CmdNetworkRemoveRouteParcel;
49     opToInterfaceMap_[NETSYS_NETWORK_SET_DEFAULT] = &NetsysNativeServiceStub::CmdNetworkSetDefault;
50     opToInterfaceMap_[NETSYS_NETWORK_GET_DEFAULT] = &NetsysNativeServiceStub::CmdNetworkGetDefault;
51     opToInterfaceMap_[NETSYS_NETWORK_CLEAR_DEFAULT] = &NetsysNativeServiceStub::CmdNetworkClearDefault;
52     opToInterfaceMap_[NETSYS_GET_PROC_SYS_NET] = &NetsysNativeServiceStub::CmdGetProcSysNet;
53     opToInterfaceMap_[NETSYS_SET_PROC_SYS_NET] = &NetsysNativeServiceStub::CmdSetProcSysNet;
54     opToInterfaceMap_[NETSYS_NETWORK_CREATE_PHYSICAL] = &NetsysNativeServiceStub::CmdNetworkCreatePhysical;
55     opToInterfaceMap_[NETSYS_INTERFACE_ADD_ADDRESS] = &NetsysNativeServiceStub::CmdInterfaceAddAddress;
56     opToInterfaceMap_[NETSYS_INTERFACE_DEL_ADDRESS] = &NetsysNativeServiceStub::CmdInterfaceDelAddress;
57     opToInterfaceMap_[NETSYS_INTERFACE_SET_IP_ADDRESS] = &NetsysNativeServiceStub::CmdInterfaceSetIpAddress;
58     opToInterfaceMap_[NETSYS_INTERFACE_SET_IFF_UP] = &NetsysNativeServiceStub::CmdInterfaceSetIffUp;
59     opToInterfaceMap_[NETSYS_NETWORK_ADD_INTERFACE] = &NetsysNativeServiceStub::CmdNetworkAddInterface;
60     opToInterfaceMap_[NETSYS_NETWORK_REMOVE_INTERFACE] = &NetsysNativeServiceStub::CmdNetworkRemoveInterface;
61     opToInterfaceMap_[NETSYS_NETWORK_DESTROY] = &NetsysNativeServiceStub::CmdNetworkDestroy;
62     opToInterfaceMap_[NETSYS_GET_FWMARK_FOR_NETWORK] = &NetsysNativeServiceStub::CmdGetFwmarkForNetwork;
63     opToInterfaceMap_[NETSYS_INTERFACE_SET_CONFIG] = &NetsysNativeServiceStub::CmdInterfaceSetConfig;
64     opToInterfaceMap_[NETSYS_INTERFACE_GET_CONFIG] = &NetsysNativeServiceStub::CmdInterfaceGetConfig;
65     opToInterfaceMap_[NETSYS_INTERFACE_GET_LIST] = &NetsysNativeServiceStub::CmdInterfaceGetList;
66     opToInterfaceMap_[NETSYS_START_DHCP_CLIENT] = &NetsysNativeServiceStub::CmdStartDhcpClient;
67     opToInterfaceMap_[NETSYS_STOP_DHCP_CLIENT] = &NetsysNativeServiceStub::CmdStopDhcpClient;
68     opToInterfaceMap_[NETSYS_START_DHCP_SERVICE] = &NetsysNativeServiceStub::CmdStartDhcpService;
69     opToInterfaceMap_[NETSYS_STOP_DHCP_SERVICE] = &NetsysNativeServiceStub::CmdStopDhcpService;
70     opToInterfaceMap_[NETSYS_IPENABLE_FORWARDING] = &NetsysNativeServiceStub::CmdIpEnableForwarding;
71     opToInterfaceMap_[NETSYS_IPDISABLE_FORWARDING] = &NetsysNativeServiceStub::CmdIpDisableForwarding;
72     opToInterfaceMap_[NETSYS_ENABLE_NAT] = &NetsysNativeServiceStub::CmdEnableNat;
73     opToInterfaceMap_[NETSYS_DISABLE_NAT] = &NetsysNativeServiceStub::CmdDisableNat;
74     opToInterfaceMap_[NETSYS_IPFWD_ADD_INTERFACE_FORWARD] = &NetsysNativeServiceStub::CmdIpfwdAddInterfaceForward;
75     opToInterfaceMap_[NETSYS_IPFWD_REMOVE_INTERFACE_FORWARD] = &NetsysNativeServiceStub::CmdIpfwdRemoveInterfaceForward;
76     opToInterfaceMap_[NETSYS_TETHER_DNS_SET] = &NetsysNativeServiceStub::CmdShareDnsSet;
77     opToInterfaceMap_[NETSYS_START_DNS_PROXY_LISTEN] = &NetsysNativeServiceStub::CmdStartDnsProxyListen;
78     opToInterfaceMap_[NETSYS_STOP_DNS_PROXY_LISTEN] = &NetsysNativeServiceStub::CmdStopDnsProxyListen;
79     opToInterfaceMap_[NETSYS_GET_SHARING_NETWORK_TRAFFIC] = &NetsysNativeServiceStub::CmdGetNetworkSharingTraffic;
80     InitBandwidthOpToInterfaceMap();
81     InitFirewallOpToInterfaceMap();
82 }
83 
InitBandwidthOpToInterfaceMap()84 void NetsysNativeServiceStub::InitBandwidthOpToInterfaceMap()
85 {
86     opToInterfaceMap_[NETSYS_BANDWIDTH_ENABLE_DATA_SAVER] = &NetsysNativeServiceStub::CmdBandwidthEnableDataSaver;
87     opToInterfaceMap_[NETSYS_BANDWIDTH_SET_IFACE_QUOTA] = &NetsysNativeServiceStub::CmdBandwidthSetIfaceQuota;
88     opToInterfaceMap_[NETSYS_BANDWIDTH_REMOVE_IFACE_QUOTA] = &NetsysNativeServiceStub::CmdBandwidthRemoveIfaceQuota;
89     opToInterfaceMap_[NETSYS_BANDWIDTH_ADD_DENIED_LIST] = &NetsysNativeServiceStub::CmdBandwidthAddDeniedList;
90     opToInterfaceMap_[NETSYS_BANDWIDTH_REMOVE_DENIED_LIST] = &NetsysNativeServiceStub::CmdBandwidthRemoveDeniedList;
91     opToInterfaceMap_[NETSYS_BANDWIDTH_ADD_ALLOWED_LIST] = &NetsysNativeServiceStub::CmdBandwidthAddAllowedList;
92     opToInterfaceMap_[NETSYS_BANDWIDTH_REMOVE_ALLOWED_LIST] = &NetsysNativeServiceStub::CmdBandwidthRemoveAllowedList;
93 }
94 
InitFirewallOpToInterfaceMap()95 void NetsysNativeServiceStub::InitFirewallOpToInterfaceMap()
96 {
97     opToInterfaceMap_[NETSYS_FIREWALL_SET_UID_ALLOWED_LIST_CHAIN] =
98         &NetsysNativeServiceStub::CmdFirewallSetUidsAllowedListChain;
99     opToInterfaceMap_[NETSYS_FIREWALL_SET_UID_DENIED_LIST_CHAIN] =
100         &NetsysNativeServiceStub::CmdFirewallSetUidsDeniedListChain;
101     opToInterfaceMap_[NETSYS_FIREWALL_ENABLE_CHAIN] = &NetsysNativeServiceStub::CmdFirewallEnableChain;
102     opToInterfaceMap_[NETSYS_FIREWALL_SET_UID_RULE] = &NetsysNativeServiceStub::CmdFirewallSetUidRule;
103 }
104 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)105 int32_t NetsysNativeServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
106                                                  MessageOption &option)
107 {
108     NETNATIVE_LOG_D("Begin to call procedure with code %{public}u", code);
109     auto interfaceIndex = opToInterfaceMap_.find(code);
110     if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
111         NETNATIVE_LOGE("Cannot response request %d: unknown tranction", code);
112         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
113     }
114     const std::u16string descriptor = NetsysNativeServiceStub::GetDescriptor();
115     const std::u16string remoteDescriptor = data.ReadInterfaceToken();
116     if (descriptor != remoteDescriptor) {
117         NETNATIVE_LOGE("Check remote descriptor failed");
118         return IPC_STUB_INVALID_DATA_ERR;
119     }
120     return (this->*(interfaceIndex->second))(data, reply);
121 }
122 
CmdSetResolverConfig(MessageParcel & data,MessageParcel & reply)123 int32_t NetsysNativeServiceStub::CmdSetResolverConfig(MessageParcel &data, MessageParcel &reply)
124 {
125     uint16_t netId = 0;
126     uint16_t baseTimeoutMsec = 0;
127     uint8_t retryCount = 0;
128     std::vector<std::string> servers;
129     std::vector<std::string> domains;
130     if (!data.ReadUint16(netId)) {
131         return ERR_FLATTEN_OBJECT;
132     }
133     if (!data.ReadUint16(baseTimeoutMsec)) {
134         return ERR_FLATTEN_OBJECT;
135     }
136     if (!data.ReadUint8(retryCount)) {
137         return ERR_FLATTEN_OBJECT;
138     }
139     int32_t vServerSize;
140     if (!data.ReadInt32(vServerSize)) {
141         return ERR_FLATTEN_OBJECT;
142     }
143     vServerSize = (vServerSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vServerSize;
144     std::string s;
145     for (int32_t i = 0; i < vServerSize; ++i) {
146         std::string().swap(s);
147         if (!data.ReadString(s)) {
148             return ERR_FLATTEN_OBJECT;
149         }
150         servers.push_back(s);
151     }
152     int32_t vDomainSize;
153     if (!data.ReadInt32(vDomainSize)) {
154         return ERR_FLATTEN_OBJECT;
155     }
156     vDomainSize = (vDomainSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vDomainSize;
157     for (int32_t i = 0; i < vDomainSize; ++i) {
158         std::string().swap(s);
159         if (!data.ReadString(s)) {
160             return ERR_FLATTEN_OBJECT;
161         }
162         domains.push_back(s);
163     }
164 
165     int32_t result = SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
166     reply.WriteInt32(result);
167     NETNATIVE_LOG_D("SetResolverConfig has received result %{public}d", result);
168 
169     return ERR_NONE;
170 }
171 
CmdGetResolverConfig(MessageParcel & data,MessageParcel & reply)172 int32_t NetsysNativeServiceStub::CmdGetResolverConfig(MessageParcel &data, MessageParcel &reply)
173 {
174     uint16_t baseTimeoutMsec;
175     uint8_t retryCount;
176     uint16_t netId = 0;
177     std::vector<std::string> servers;
178     std::vector<std::string> domains;
179 
180     data.ReadUint16(netId);
181     int32_t result = GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
182     reply.WriteInt32(result);
183     reply.WriteUint16(baseTimeoutMsec);
184     reply.WriteUint8(retryCount);
185     auto vServerSize = static_cast<int32_t>(servers.size());
186     vServerSize = (vServerSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vServerSize;
187     reply.WriteInt32(vServerSize);
188     int32_t index = 0;
189     for (auto &server : servers) {
190         if (++index > MAX_DNS_CONFIG_SIZE) {
191             break;
192         }
193         reply.WriteString(server);
194     }
195     auto vDomainsSize = static_cast<int32_t>(domains.size());
196     vDomainsSize = (vDomainsSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vDomainsSize;
197     reply.WriteInt32(vDomainsSize);
198     std::vector<std::string>::iterator iterDomains;
199     index = 0;
200     for (iterDomains = domains.begin(); iterDomains != domains.end(); ++iterDomains) {
201         if (++index > MAX_DNS_CONFIG_SIZE) {
202             break;
203         }
204         reply.WriteString(*iterDomains);
205     }
206     NETNATIVE_LOG_D("GetResolverConfig has recved result %{public}d", result);
207     return ERR_NONE;
208 }
209 
CmdCreateNetworkCache(MessageParcel & data,MessageParcel & reply)210 int32_t NetsysNativeServiceStub::CmdCreateNetworkCache(MessageParcel &data, MessageParcel &reply)
211 {
212     uint16_t netid = data.ReadUint16();
213     NETNATIVE_LOGI("CreateNetworkCache  netid %{public}d", netid);
214     int32_t result = CreateNetworkCache(netid);
215     reply.WriteInt32(result);
216     NETNATIVE_LOG_D("CreateNetworkCache has recved result %{public}d", result);
217 
218     return ERR_NONE;
219 }
220 
CmdDestroyNetworkCache(MessageParcel & data,MessageParcel & reply)221 int32_t NetsysNativeServiceStub::CmdDestroyNetworkCache(MessageParcel &data, MessageParcel &reply)
222 {
223     uint16_t netId = data.ReadUint16();
224     int32_t result = DestroyNetworkCache(netId);
225     reply.WriteInt32(result);
226     NETNATIVE_LOG_D("DestroyNetworkCache has recved result %{public}d", result);
227 
228     return ERR_NONE;
229 }
230 
NetsysFreeAddrinfo(struct addrinfo * aihead)231 int32_t NetsysNativeServiceStub::NetsysFreeAddrinfo(struct addrinfo *aihead)
232 {
233     struct addrinfo *ai, *ainext;
234     for (ai = aihead; ai != nullptr; ai = ainext) {
235         if (ai->ai_addr != nullptr)
236             free(ai->ai_addr);
237         if (ai->ai_canonname != nullptr)
238             free(ai->ai_canonname);
239         ainext = ai->ai_next;
240         free(ai);
241     }
242     return ERR_NONE;
243 }
244 
CmdGetAddrInfo(MessageParcel & data,MessageParcel & reply)245 int32_t NetsysNativeServiceStub::CmdGetAddrInfo(MessageParcel &data, MessageParcel &reply)
246 {
247     std::string hostName;
248     std::string serverName;
249     AddrInfo hints = {};
250     uint16_t netId;
251     if (!data.ReadString(hostName)) {
252         return IPC_STUB_INVALID_DATA_ERR;
253     }
254 
255         if (!data.ReadString(serverName)) {
256             return IPC_STUB_INVALID_DATA_ERR;
257     }
258 
259         auto p = data.ReadRawData(sizeof(AddrInfo));
260         if (p == nullptr) {
261             return IPC_STUB_INVALID_DATA_ERR;
262         }
263         if (memcpy_s(&hints, sizeof(AddrInfo), p, sizeof(AddrInfo)) != EOK) {
264             return IPC_STUB_INVALID_DATA_ERR;
265         }
266 
267         if (!data.ReadUint16(netId)) {
268             return IPC_STUB_INVALID_DATA_ERR;
269         }
270 
271         std::vector<AddrInfo> retInfo;
272         auto ret = GetAddrInfo(hostName, serverName, hints, netId, retInfo);
273         if (retInfo.size() > MAX_RESULTS) {
274             return IPC_STUB_INVALID_DATA_ERR;
275         }
276 
277         if (!reply.WriteInt32(ret)) {
278             return IPC_STUB_WRITE_PARCEL_ERR;
279         }
280 
281         if (ret != ERR_NONE) {
282             return ERR_NONE;
283         }
284 
285         if (!reply.WriteUint32(static_cast<uint32_t>(retInfo.size()))) {
286             return IPC_STUB_WRITE_PARCEL_ERR;
287         }
288 
289         for (const auto &info : retInfo) {
290             if (!reply.WriteRawData(&info, sizeof(AddrInfo))) {
291                 return IPC_STUB_WRITE_PARCEL_ERR;
292         }
293     }
294     return ERR_NONE;
295 }
296 
CmdInterfaceSetMtu(MessageParcel & data,MessageParcel & reply)297 int32_t NetsysNativeServiceStub::CmdInterfaceSetMtu(MessageParcel &data, MessageParcel &reply)
298 {
299     std::string ifName = data.ReadString();
300     int32_t mtu = data.ReadInt32();
301     int32_t result = InterfaceSetMtu(ifName, mtu);
302     reply.WriteInt32(result);
303     NETNATIVE_LOG_D("InterfaceSetMtu has recved result %{public}d", result);
304 
305     return ERR_NONE;
306 }
307 
CmdInterfaceGetMtu(MessageParcel & data,MessageParcel & reply)308 int32_t NetsysNativeServiceStub::CmdInterfaceGetMtu(MessageParcel &data, MessageParcel &reply)
309 {
310     std::string ifName = data.ReadString();
311     int32_t result = InterfaceGetMtu(ifName);
312     reply.WriteInt32(result);
313     NETNATIVE_LOG_D("InterfaceGetMtu has recved result %{public}d", result);
314 
315     return ERR_NONE;
316 }
317 
CmdRegisterNotifyCallback(MessageParcel & data,MessageParcel & reply)318 int32_t NetsysNativeServiceStub::CmdRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply)
319 {
320     NETNATIVE_LOG_D("Begin to dispatch cmd RegisterNotifyCallback");
321     sptr<IRemoteObject> remote = data.ReadRemoteObject();
322     if (remote == nullptr) {
323         NETNATIVE_LOGE("Callback ptr is nullptr.");
324         return -1;
325     }
326 
327     sptr<INotifyCallback> callback = iface_cast<INotifyCallback>(remote);
328     int32_t result = RegisterNotifyCallback(callback);
329     reply.WriteInt32(result);
330     return ERR_NONE;
331 }
332 
CmdUnRegisterNotifyCallback(MessageParcel & data,MessageParcel & reply)333 int32_t NetsysNativeServiceStub::CmdUnRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply)
334 {
335     NETNATIVE_LOG_D("Begin to dispatch cmd UnRegisterNotifyCallback");
336     sptr<IRemoteObject> remote = data.ReadRemoteObject();
337     if (remote == nullptr) {
338         NETNATIVE_LOGE("Callback ptr is nullptr.");
339         return -1;
340     }
341 
342     sptr<INotifyCallback> callback = iface_cast<INotifyCallback>(remote);
343     int32_t result = UnRegisterNotifyCallback(callback);
344     reply.WriteInt32(result);
345     return ERR_NONE;
346 }
347 
CmdNetworkAddRoute(MessageParcel & data,MessageParcel & reply)348 int32_t NetsysNativeServiceStub::CmdNetworkAddRoute(MessageParcel &data, MessageParcel &reply)
349 {
350     int32_t netId = data.ReadInt32();
351     std::string ifName = data.ReadString();
352     std::string destination = data.ReadString();
353     std::string nextHop = data.ReadString();
354 
355     NETNATIVE_LOGI("netId[%{public}d}, ifName[%{public}s], destination[%{public}s}, nextHop[%{public}s]", netId,
356                    ifName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
357     int32_t result = NetworkAddRoute(netId, ifName, destination, nextHop);
358     reply.WriteInt32(result);
359     NETNATIVE_LOG_D("NetworkAddRoute has recved result %{public}d", result);
360     return result;
361 }
362 
CmdNetworkRemoveRoute(MessageParcel & data,MessageParcel & reply)363 int32_t NetsysNativeServiceStub::CmdNetworkRemoveRoute(MessageParcel &data, MessageParcel &reply)
364 {
365     int32_t netId = data.ReadInt32();
366     std::string interfaceName = data.ReadString();
367     std::string destination = data.ReadString();
368     std::string nextHop = data.ReadString();
369 
370     NETNATIVE_LOGI("netId[%{public}d}, ifName[%{public}s], destination[%{public}s}, nextHop[%{public}s]", netId,
371                    interfaceName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
372     int32_t result = NetworkRemoveRoute(netId, interfaceName, destination, nextHop);
373     reply.WriteInt32(result);
374     NETNATIVE_LOG_D("NetworkRemoveRoute has recved result %{public}d", result);
375 
376     return result;
377 }
378 
CmdNetworkAddRouteParcel(MessageParcel & data,MessageParcel & reply)379 int32_t NetsysNativeServiceStub::CmdNetworkAddRouteParcel(MessageParcel &data, MessageParcel &reply)
380 {
381     RouteInfoParcel routeInfo = {};
382     int32_t netId = data.ReadInt32();
383     routeInfo.ifName = data.ReadString();
384     routeInfo.destination = data.ReadString();
385     routeInfo.nextHop = data.ReadString();
386     int32_t result = NetworkAddRouteParcel(netId, routeInfo);
387     reply.WriteInt32(result);
388     NETNATIVE_LOG_D("NetworkAddRouteParcel has recved result %{public}d", result);
389 
390     return result;
391 }
392 
CmdNetworkRemoveRouteParcel(MessageParcel & data,MessageParcel & reply)393 int32_t NetsysNativeServiceStub::CmdNetworkRemoveRouteParcel(MessageParcel &data, MessageParcel &reply)
394 {
395     RouteInfoParcel routeInfo = {};
396     int32_t netId = data.ReadInt32();
397     routeInfo.ifName = data.ReadString();
398     routeInfo.destination = data.ReadString();
399     routeInfo.nextHop = data.ReadString();
400 
401     int32_t result = NetworkRemoveRouteParcel(netId, routeInfo);
402     reply.WriteInt32(result);
403     NETNATIVE_LOG_D("NetworkRemoveRouteParcel has recved result %{public}d", result);
404 
405     return result;
406 }
407 
CmdNetworkSetDefault(MessageParcel & data,MessageParcel & reply)408 int32_t NetsysNativeServiceStub::CmdNetworkSetDefault(MessageParcel &data, MessageParcel &reply)
409 {
410     int32_t netId = data.ReadInt32();
411 
412     int32_t result = NetworkSetDefault(netId);
413     reply.WriteInt32(result);
414     NETNATIVE_LOG_D("NetworkSetDefault has recved result %{public}d", result);
415 
416     return result;
417 }
418 
CmdNetworkGetDefault(MessageParcel & data,MessageParcel & reply)419 int32_t NetsysNativeServiceStub::CmdNetworkGetDefault(MessageParcel &data, MessageParcel &reply)
420 {
421     int32_t result = NetworkGetDefault();
422     reply.WriteInt32(result);
423     NETNATIVE_LOG_D("NetworkGetDefault has recved result %{public}d", result);
424 
425     return result;
426 }
427 
CmdNetworkClearDefault(MessageParcel & data,MessageParcel & reply)428 int32_t NetsysNativeServiceStub::CmdNetworkClearDefault(MessageParcel &data, MessageParcel &reply)
429 {
430     int32_t result = NetworkClearDefault();
431     reply.WriteInt32(result);
432     NETNATIVE_LOG_D("NetworkClearDefault has recved result %{public}d", result);
433 
434     return result;
435 }
436 
CmdGetProcSysNet(MessageParcel & data,MessageParcel & reply)437 int32_t NetsysNativeServiceStub::CmdGetProcSysNet(MessageParcel &data, MessageParcel &reply)
438 {
439     NETNATIVE_LOG_D("Begin to dispatch cmd GetProcSysNet");
440     int32_t ipversion = data.ReadInt32();
441     int32_t which = data.ReadInt32();
442     std::string ifname = data.ReadString();
443     std::string parameter = data.ReadString();
444     std::string value;
445     int32_t result = GetProcSysNet(ipversion, which, ifname, parameter, value);
446     reply.WriteInt32(result);
447     std::string valueRsl = value;
448     reply.WriteString(valueRsl);
449     return result;
450 }
451 
CmdSetProcSysNet(MessageParcel & data,MessageParcel & reply)452 int32_t NetsysNativeServiceStub::CmdSetProcSysNet(MessageParcel &data, MessageParcel &reply)
453 {
454     int32_t ipversion = data.ReadInt32();
455     int32_t which = data.ReadInt32();
456     std::string ifname = data.ReadString();
457     std::string parameter = data.ReadString();
458     std::string value = data.ReadString();
459     int32_t result = SetProcSysNet(ipversion, which, ifname, parameter, value);
460     reply.WriteInt32(result);
461     NETNATIVE_LOG_D("SetProcSysNet has recved result %{public}d", result);
462 
463     return result;
464 }
465 
CmdNetworkCreatePhysical(MessageParcel & data,MessageParcel & reply)466 int32_t NetsysNativeServiceStub::CmdNetworkCreatePhysical(MessageParcel &data, MessageParcel &reply)
467 {
468     int32_t netId = data.ReadInt32();
469     int32_t permission = data.ReadInt32();
470 
471     int32_t result = NetworkCreatePhysical(netId, permission);
472     reply.WriteInt32(result);
473     NETNATIVE_LOG_D("NetworkCreatePhysical has recved result %{public}d", result);
474 
475     return result;
476 }
477 
CmdInterfaceAddAddress(MessageParcel & data,MessageParcel & reply)478 int32_t NetsysNativeServiceStub::CmdInterfaceAddAddress(MessageParcel &data, MessageParcel &reply)
479 {
480     std::string interfaceName = data.ReadString();
481     std::string ipAddr = data.ReadString();
482     int32_t prefixLength = data.ReadInt32();
483 
484     int32_t result = InterfaceAddAddress(interfaceName, ipAddr, prefixLength);
485     reply.WriteInt32(result);
486     NETNATIVE_LOG_D("InterfaceAddAddress has recved result %{public}d", result);
487 
488     return result;
489 }
490 
CmdInterfaceDelAddress(MessageParcel & data,MessageParcel & reply)491 int32_t NetsysNativeServiceStub::CmdInterfaceDelAddress(MessageParcel &data, MessageParcel &reply)
492 {
493     std::string interfaceName = data.ReadString();
494     std::string ipAddr = data.ReadString();
495     int32_t prefixLength = data.ReadInt32();
496 
497     int32_t result = InterfaceDelAddress(interfaceName, ipAddr, prefixLength);
498     reply.WriteInt32(result);
499     NETNATIVE_LOG_D("InterfaceDelAddress has recved result %{public}d", result);
500 
501     return result;
502 }
503 
CmdInterfaceSetIpAddress(MessageParcel & data,MessageParcel & reply)504 int32_t NetsysNativeServiceStub::CmdInterfaceSetIpAddress(MessageParcel &data, MessageParcel &reply)
505 {
506     std::string ifaceName = data.ReadString();
507     std::string ipAddress = data.ReadString();
508 
509     int32_t result = InterfaceSetIpAddress(ifaceName, ipAddress);
510     reply.WriteInt32(result);
511     NETNATIVE_LOG_D("InterfaceSetIpAddress has recved result %{public}d", result);
512 
513     return result;
514 }
515 
CmdInterfaceSetIffUp(MessageParcel & data,MessageParcel & reply)516 int32_t NetsysNativeServiceStub::CmdInterfaceSetIffUp(MessageParcel &data, MessageParcel &reply)
517 {
518     std::string ifaceName = data.ReadString();
519 
520     int32_t result = InterfaceSetIffUp(ifaceName);
521     reply.WriteInt32(result);
522     NETNATIVE_LOG_D("InterfaceSetIffUp has recved result %{public}d", result);
523 
524     return result;
525 }
526 
CmdNetworkAddInterface(MessageParcel & data,MessageParcel & reply)527 int32_t NetsysNativeServiceStub::CmdNetworkAddInterface(MessageParcel &data, MessageParcel &reply)
528 {
529     int32_t netId = data.ReadInt32();
530     std::string iface = data.ReadString();
531 
532     int32_t result = NetworkAddInterface(netId, iface);
533     reply.WriteInt32(result);
534     NETNATIVE_LOG_D("NetworkAddInterface has recved result %{public}d", result);
535 
536     return result;
537 }
538 
CmdNetworkRemoveInterface(MessageParcel & data,MessageParcel & reply)539 int32_t NetsysNativeServiceStub::CmdNetworkRemoveInterface(MessageParcel &data, MessageParcel &reply)
540 {
541     int32_t netId = data.ReadInt32();
542     std::string iface = data.ReadString();
543     int32_t result = NetworkRemoveInterface(netId, iface);
544     reply.WriteInt32(result);
545     NETNATIVE_LOG_D("NetworkRemoveRouteParcel has recved result %{public}d", result);
546 
547     return result;
548 }
549 
CmdNetworkDestroy(MessageParcel & data,MessageParcel & reply)550 int32_t NetsysNativeServiceStub::CmdNetworkDestroy(MessageParcel &data, MessageParcel &reply)
551 {
552     int32_t netId = data.ReadInt32();
553     int32_t result = NetworkDestroy(netId);
554     reply.WriteInt32(result);
555     NETNATIVE_LOG_D("NetworkDestroy has recved result %{public}d", result);
556 
557     return result;
558 }
559 
CmdGetFwmarkForNetwork(MessageParcel & data,MessageParcel & reply)560 int32_t NetsysNativeServiceStub::CmdGetFwmarkForNetwork(MessageParcel &data, MessageParcel &reply)
561 {
562     MarkMaskParcel markMaskParcel = {};
563     int32_t netId = data.ReadInt32();
564     markMaskParcel.mark = data.ReadInt32();
565     markMaskParcel.mask = data.ReadInt32();
566     int32_t result = GetFwmarkForNetwork(netId, markMaskParcel);
567     reply.WriteInt32(result);
568     NETNATIVE_LOG_D("GetFwmarkForNetwork has recved result %{public}d", result);
569 
570     return result;
571 }
572 
CmdInterfaceSetConfig(MessageParcel & data,MessageParcel & reply)573 int32_t NetsysNativeServiceStub::CmdInterfaceSetConfig(MessageParcel &data, MessageParcel &reply)
574 {
575     InterfaceConfigurationParcel cfg = {};
576     cfg.ifName = data.ReadString();
577     cfg.hwAddr = data.ReadString();
578     cfg.ipv4Addr = data.ReadString();
579     cfg.prefixLength = data.ReadInt32();
580     int32_t vSize = data.ReadInt32();
581     vSize = (vSize > MAX_FLAG_NUM) ? MAX_FLAG_NUM : vSize;
582     std::vector<std::string> vFlags;
583     for (int i = 0; i < vSize; i++) {
584         vFlags.emplace_back(data.ReadString());
585     }
586     cfg.flags.assign(vFlags.begin(), vFlags.end());
587     int32_t result = InterfaceSetConfig(cfg);
588     reply.WriteInt32(result);
589     NETNATIVE_LOG_D("InterfaceSetConfig has recved result %{public}d", result);
590 
591     return result;
592 }
593 
CmdInterfaceGetConfig(MessageParcel & data,MessageParcel & reply)594 int32_t NetsysNativeServiceStub::CmdInterfaceGetConfig(MessageParcel &data, MessageParcel &reply)
595 {
596     NETNATIVE_LOG_D("Begin to dispatch cmd InterfaceGetConfig");
597     InterfaceConfigurationParcel cfg = {};
598     cfg.ifName = data.ReadString();
599     int32_t result = InterfaceGetConfig(cfg);
600     reply.WriteInt32(result);
601     reply.WriteString(cfg.ifName);
602     reply.WriteString(cfg.hwAddr);
603     reply.WriteString(cfg.ipv4Addr);
604     reply.WriteInt32(cfg.prefixLength);
605     int32_t vsize = static_cast<int32_t>(cfg.flags.size());
606     vsize = vsize > MAX_DNS_CONFIG_SIZE ? MAX_DNS_CONFIG_SIZE : vsize;
607     reply.WriteInt32(vsize);
608     std::vector<std::string>::iterator iter;
609     int32_t index = 0;
610     for (iter = cfg.flags.begin(); iter != cfg.flags.end(); ++iter) {
611         if (++index > MAX_DNS_CONFIG_SIZE) {
612             break;
613         }
614         reply.WriteString(*iter);
615     }
616     return result;
617 }
618 
CmdInterfaceGetList(MessageParcel & data,MessageParcel & reply)619 int32_t NetsysNativeServiceStub::CmdInterfaceGetList(MessageParcel &data, MessageParcel &reply)
620 {
621     NETNATIVE_LOG_D("Begin to dispatch cmd InterfaceGetList");
622     std::vector<std::string> ifaces;
623     int32_t result = InterfaceGetList(ifaces);
624     reply.WriteInt32(result);
625     auto vsize = static_cast<int32_t>(ifaces.size());
626     reply.WriteInt32(vsize);
627     std::vector<std::string>::iterator iter;
628     for (iter = ifaces.begin(); iter != ifaces.end(); ++iter) {
629         reply.WriteString(*iter);
630     }
631     return result;
632 }
633 
CmdStartDhcpClient(MessageParcel & data,MessageParcel & reply)634 int32_t NetsysNativeServiceStub::CmdStartDhcpClient(MessageParcel &data, MessageParcel &reply)
635 {
636     NETNATIVE_LOG_D("Begin to dispatch cmd CmdStartDhcpClient");
637     std::string iface = data.ReadString();
638     bool bIpv6 = data.ReadBool();
639     int32_t result = StartDhcpClient(iface, bIpv6);
640     reply.WriteInt32(result);
641     return result;
642 }
643 
CmdStopDhcpClient(MessageParcel & data,MessageParcel & reply)644 int32_t NetsysNativeServiceStub::CmdStopDhcpClient(MessageParcel &data, MessageParcel &reply)
645 {
646     NETNATIVE_LOG_D("Begin to dispatch cmd CmdStopDhcpClient");
647     std::string iface = data.ReadString();
648     bool bIpv6 = data.ReadBool();
649     int32_t result = StopDhcpClient(iface, bIpv6);
650     reply.WriteInt32(result);
651     return result;
652 }
653 
CmdStartDhcpService(MessageParcel & data,MessageParcel & reply)654 int32_t NetsysNativeServiceStub::CmdStartDhcpService(MessageParcel &data, MessageParcel &reply)
655 {
656     NETNATIVE_LOG_D("Begin to dispatch cmd CmdStartDhcpService");
657     std::string iface = data.ReadString();
658     std::string ipv4addr = data.ReadString();
659     int32_t result = StartDhcpService(iface, ipv4addr);
660     reply.WriteInt32(result);
661     return result;
662 }
663 
CmdStopDhcpService(MessageParcel & data,MessageParcel & reply)664 int32_t NetsysNativeServiceStub::CmdStopDhcpService(MessageParcel &data, MessageParcel &reply)
665 {
666     NETNATIVE_LOG_D("Begin to dispatch cmd CmdStopDhcpService");
667     std::string iface = data.ReadString();
668     int32_t result = StopDhcpService(iface);
669     reply.WriteInt32(result);
670     return result;
671 }
672 
CmdIpEnableForwarding(MessageParcel & data,MessageParcel & reply)673 int32_t NetsysNativeServiceStub::CmdIpEnableForwarding(MessageParcel &data, MessageParcel &reply)
674 {
675     NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpEnableForwarding");
676     const auto &requester = data.ReadString();
677     int32_t result = IpEnableForwarding(requester);
678     reply.WriteInt32(result);
679     return result;
680 }
681 
CmdIpDisableForwarding(MessageParcel & data,MessageParcel & reply)682 int32_t NetsysNativeServiceStub::CmdIpDisableForwarding(MessageParcel &data, MessageParcel &reply)
683 {
684     NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpDisableForwarding");
685     const auto &requester = data.ReadString();
686     int32_t result = IpDisableForwarding(requester);
687     reply.WriteInt32(result);
688     return result;
689 }
690 
CmdEnableNat(MessageParcel & data,MessageParcel & reply)691 int32_t NetsysNativeServiceStub::CmdEnableNat(MessageParcel &data, MessageParcel &reply)
692 {
693     NETNATIVE_LOG_D("Begin to dispatch cmd CmdEnableNat");
694     const auto &downstreamIface = data.ReadString();
695     const auto &upstreamIface = data.ReadString();
696     int32_t result = EnableNat(downstreamIface, upstreamIface);
697     reply.WriteInt32(result);
698     return result;
699 }
700 
CmdDisableNat(MessageParcel & data,MessageParcel & reply)701 int32_t NetsysNativeServiceStub::CmdDisableNat(MessageParcel &data, MessageParcel &reply)
702 {
703     NETNATIVE_LOG_D("Begin to dispatch cmd CmdDisableNat");
704     const auto &downstreamIface = data.ReadString();
705     const auto &upstreamIface = data.ReadString();
706     int32_t result = DisableNat(downstreamIface, upstreamIface);
707     reply.WriteInt32(result);
708     return result;
709 }
710 
CmdIpfwdAddInterfaceForward(MessageParcel & data,MessageParcel & reply)711 int32_t NetsysNativeServiceStub::CmdIpfwdAddInterfaceForward(MessageParcel &data, MessageParcel &reply)
712 {
713     NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpfwdAddInterfaceForward");
714     const auto &fromIface = data.ReadString();
715     const auto &toIface = data.ReadString();
716     int32_t result = IpfwdAddInterfaceForward(fromIface, toIface);
717     reply.WriteInt32(result);
718     return result;
719 }
720 
CmdIpfwdRemoveInterfaceForward(MessageParcel & data,MessageParcel & reply)721 int32_t NetsysNativeServiceStub::CmdIpfwdRemoveInterfaceForward(MessageParcel &data, MessageParcel &reply)
722 {
723     NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpfwdRemoveInterfaceForward");
724     const auto &fromIface = data.ReadString();
725     const auto &toIface = data.ReadString();
726     int32_t result = IpfwdRemoveInterfaceForward(fromIface, toIface);
727     reply.WriteInt32(result);
728     return result;
729 }
730 
CmdBandwidthEnableDataSaver(MessageParcel & data,MessageParcel & reply)731 int32_t NetsysNativeServiceStub::CmdBandwidthEnableDataSaver(MessageParcel &data, MessageParcel &reply)
732 {
733     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthEnableDataSaver");
734     bool enable = data.ReadBool();
735     int32_t result = BandwidthEnableDataSaver(enable);
736     reply.WriteInt32(result);
737     return result;
738 }
739 
CmdBandwidthSetIfaceQuota(MessageParcel & data,MessageParcel & reply)740 int32_t NetsysNativeServiceStub::CmdBandwidthSetIfaceQuota(MessageParcel &data, MessageParcel &reply)
741 {
742     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthSetIfaceQuota");
743     std::string ifName = data.ReadString();
744     int64_t bytes = data.ReadInt64();
745     int32_t result = BandwidthSetIfaceQuota(ifName, bytes);
746     reply.WriteInt32(result);
747     return result;
748 }
749 
CmdBandwidthRemoveIfaceQuota(MessageParcel & data,MessageParcel & reply)750 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveIfaceQuota(MessageParcel &data, MessageParcel &reply)
751 {
752     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveIfaceQuota");
753     std::string ifName = data.ReadString();
754     int32_t result = BandwidthRemoveIfaceQuota(ifName);
755     reply.WriteInt32(result);
756     return result;
757 }
758 
CmdBandwidthAddDeniedList(MessageParcel & data,MessageParcel & reply)759 int32_t NetsysNativeServiceStub::CmdBandwidthAddDeniedList(MessageParcel &data, MessageParcel &reply)
760 {
761     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthAddDeniedList");
762     uint32_t uid = data.ReadUint32();
763     int32_t result = BandwidthAddDeniedList(uid);
764     reply.WriteInt32(result);
765     return result;
766 }
CmdBandwidthRemoveDeniedList(MessageParcel & data,MessageParcel & reply)767 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveDeniedList(MessageParcel &data, MessageParcel &reply)
768 {
769     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveDeniedList");
770     uint32_t uid = data.ReadUint32();
771     int32_t result = BandwidthRemoveDeniedList(uid);
772     reply.WriteInt32(result);
773     return result;
774 }
775 
CmdBandwidthAddAllowedList(MessageParcel & data,MessageParcel & reply)776 int32_t NetsysNativeServiceStub::CmdBandwidthAddAllowedList(MessageParcel &data, MessageParcel &reply)
777 {
778     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthAddAllowedList");
779     uint32_t uid = data.ReadUint32();
780     int32_t result = BandwidthAddAllowedList(uid);
781     reply.WriteInt32(result);
782     return result;
783 }
784 
CmdBandwidthRemoveAllowedList(MessageParcel & data,MessageParcel & reply)785 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveAllowedList(MessageParcel &data, MessageParcel &reply)
786 {
787     NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveAllowedList");
788     uint32_t uid = data.ReadUint32();
789     int32_t result = BandwidthRemoveAllowedList(uid);
790     reply.WriteInt32(result);
791     return result;
792 }
793 
CmdFirewallSetUidsAllowedListChain(MessageParcel & data,MessageParcel & reply)794 int32_t NetsysNativeServiceStub::CmdFirewallSetUidsAllowedListChain(MessageParcel &data, MessageParcel &reply)
795 {
796     NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidsAllowedListChain");
797     uint32_t chain = data.ReadUint32();
798     std::vector<uint32_t> uids;
799     uint32_t uidSize = data.ReadUint32();
800     uidSize = (uidSize > UIDS_LIST_MAX_SIZE) ? UIDS_LIST_MAX_SIZE : uidSize;
801     for (uint32_t i = 0; i < uidSize; i++) {
802         uint32_t uid = data.ReadUint32();
803         uids.push_back(uid);
804     }
805     int32_t result = FirewallSetUidsAllowedListChain(chain, uids);
806     reply.WriteInt32(result);
807     return result;
808 }
809 
CmdFirewallSetUidsDeniedListChain(MessageParcel & data,MessageParcel & reply)810 int32_t NetsysNativeServiceStub::CmdFirewallSetUidsDeniedListChain(MessageParcel &data, MessageParcel &reply)
811 {
812     NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidsDeniedListChain");
813     uint32_t chain = data.ReadUint32();
814     std::vector<uint32_t> uids;
815     uint32_t uidSize = data.ReadUint32();
816     uidSize = (uidSize > UIDS_LIST_MAX_SIZE) ? UIDS_LIST_MAX_SIZE : uidSize;
817     for (uint32_t i = 0; i < uidSize; i++) {
818         uint32_t uid = data.ReadUint32();
819         uids.push_back(uid);
820     }
821     int32_t result = FirewallSetUidsDeniedListChain(chain, uids);
822     reply.WriteInt32(result);
823     return result;
824 }
825 
CmdFirewallEnableChain(MessageParcel & data,MessageParcel & reply)826 int32_t NetsysNativeServiceStub::CmdFirewallEnableChain(MessageParcel &data, MessageParcel &reply)
827 {
828     NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallEnableChain");
829     uint32_t chain = data.ReadUint32();
830     bool enable = data.ReadBool();
831     int32_t result = FirewallEnableChain(chain, enable);
832     reply.WriteInt32(result);
833     return result;
834 }
835 
CmdFirewallSetUidRule(MessageParcel & data,MessageParcel & reply)836 int32_t NetsysNativeServiceStub::CmdFirewallSetUidRule(MessageParcel &data, MessageParcel &reply)
837 {
838     NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidRule");
839     uint32_t chain = (unsigned)data.ReadUint32();
840     uint32_t uid = (unsigned)data.ReadInt32();
841     uint32_t firewallRule = (unsigned)data.ReadInt32();
842     int32_t result = FirewallSetUidRule(chain, uid, firewallRule);
843     reply.WriteInt32(result);
844     return result;
845 }
846 
CmdShareDnsSet(MessageParcel & data,MessageParcel & reply)847 int32_t NetsysNativeServiceStub::CmdShareDnsSet(MessageParcel &data, MessageParcel &reply)
848 {
849     uint16_t netId = 0;
850     data.ReadUint16(netId);
851     int32_t result = ShareDnsSet(netId);
852     reply.WriteInt32(result);
853     NETNATIVE_LOG_D("ShareDnsSet has received result %{public}d", result);
854 
855     return result;
856 }
857 
CmdStartDnsProxyListen(MessageParcel & data,MessageParcel & reply)858 int32_t NetsysNativeServiceStub::CmdStartDnsProxyListen(MessageParcel &data, MessageParcel &reply)
859 {
860     int32_t result = StartDnsProxyListen();
861     reply.WriteInt32(result);
862     NETNATIVE_LOG_D("StartDnsProxyListen has recved result %{public}d", result);
863 
864     return result;
865 }
866 
CmdStopDnsProxyListen(MessageParcel & data,MessageParcel & reply)867 int32_t NetsysNativeServiceStub::CmdStopDnsProxyListen(MessageParcel &data, MessageParcel &reply)
868 {
869     int32_t result = StopDnsProxyListen();
870     reply.WriteInt32(result);
871     NETNATIVE_LOG_D("StopDnsProxyListen has recved result %{public}d", result);
872 
873     return result;
874 }
875 
CmdGetNetworkSharingTraffic(MessageParcel & data,MessageParcel & reply)876 int32_t NetsysNativeServiceStub::CmdGetNetworkSharingTraffic(MessageParcel &data, MessageParcel &reply)
877 {
878     NETNATIVE_LOG_D("Begin to dispatch cmd GetNetworkSharingTraffic");
879     std::string downIface = data.ReadString();
880     std::string upIface = data.ReadString();
881     NetworkSharingTraffic traffic;
882     int32_t result = GetNetworkSharingTraffic(downIface, upIface, traffic);
883     reply.WriteInt32(result);
884     reply.WriteInt64(traffic.receive);
885     reply.WriteInt64(traffic.send);
886     reply.WriteInt64(traffic.all);
887 
888     return result;
889 }
890 } // namespace NetsysNative
891 } // namespace OHOS
892