1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdlib>
17 #include <net/route.h>
18 #include <netdb.h>
19 #include <unistd.h>
20
21 #include "ipc_skeleton.h"
22 #include "net_manager_constants.h"
23 #include "netmanager_base_common_utils.h"
24 #include "netmanager_base_permission.h"
25 #include "netnative_log_wrapper.h"
26 #include "netsys_native_service_stub.h"
27 #include "securec.h"
28 #include "i_net_dns_result_callback.h"
29 #include "i_net_dns_health_callback.h"
30 #include "netsys_traffic_callback_proxy.h"
31
32 using namespace OHOS::NetManagerStandard::CommonUtils;
33 namespace OHOS {
34 namespace NetsysNative {
35 namespace {
36 constexpr int32_t MAX_VNIC_UID_ARRAY_SIZE = 20;
37 constexpr int32_t MAX_FLAG_NUM = 64;
38 constexpr int32_t MAX_DNS_CONFIG_SIZE = 7;
39 constexpr int32_t NETMANAGER_ERR_PERMISSION_DENIED = 201;
40 constexpr uint32_t UIDS_LIST_MAX_SIZE = 1024;
41 constexpr uint32_t MAX_UID_ARRAY_SIZE = 1024;
42 constexpr uint32_t MAX_CONFIG_LIST_SIZE = 1024;
43 constexpr uint32_t MAX_ROUTE_TABLE_SIZE = 128;
44 constexpr uint32_t MAX_IFACENAMES_SIZE = 128;
45 } // namespace
46
NetsysNativeServiceStub()47 NetsysNativeServiceStub::NetsysNativeServiceStub()
48 {
49 InitNetInfoOpToInterfaceMap();
50 InitBandwidthOpToInterfaceMap();
51 InitFirewallOpToInterfaceMap();
52 InitOpToInterfaceMapExt();
53 InitNetDiagOpToInterfaceMap();
54 InitNetDnsDiagOpToInterfaceMap();
55 InitStaticArpToInterfaceMap();
56 InitNetVnicInterfaceMap();
57 InitNetVirnicInterfaceMap();
58 InitNetStatsInterfaceMap();
59 InitStaticIpv6ToInterfaceMap();
60 #ifdef SUPPORT_SYSVPN
61 InitVpnOpToInterfaceMap();
62 #endif // SUPPORT_SYSVPN
63 InitDnsServerOpToInterfaceMap();
64 #ifdef FEATURE_ENTERPRISE_ROUTE_CUSTOM
65 InitEnterpriseMap();
66 #endif
67 uids_ = {UID_ROOT, UID_HIVIEW, UID_SHELL, UID_NET_MANAGER, UID_WIFI, UID_RADIO, UID_HIDUMPER_SERVICE,
68 UID_SAMGR, UID_PARAM_WATCHER, UID_EDM, UID_SECURITY_COLLECTOR, UID_IOT_NET_MANAGER};
69 }
70
InitNetInfoOpToInterfaceMap()71 void NetsysNativeServiceStub::InitNetInfoOpToInterfaceMap()
72 {
73 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_RESOLVER_CONFIG)] =
74 &NetsysNativeServiceStub::CmdSetResolverConfig;
75 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_RESOLVER_CONFIG)] =
76 &NetsysNativeServiceStub::CmdGetResolverConfig;
77 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_CREATE_NETWORK_CACHE)] =
78 &NetsysNativeServiceStub::CmdCreateNetworkCache;
79 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DESTROY_NETWORK_CACHE)] =
80 &NetsysNativeServiceStub::CmdDestroyNetworkCache;
81 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_ADDR_INFO)] =
82 &NetsysNativeServiceStub::CmdGetAddrInfo;
83 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_SET_MTU)] =
84 &NetsysNativeServiceStub::CmdSetInterfaceMtu;
85 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_GET_MTU)] =
86 &NetsysNativeServiceStub::CmdGetInterfaceMtu;
87 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_TCP_BUFFER_SIZES)] =
88 &NetsysNativeServiceStub::CmdSetTcpBufferSizes;
89 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_REGISTER_NOTIFY_CALLBACK)] =
90 &NetsysNativeServiceStub::CmdRegisterNotifyCallback;
91 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UNREGISTER_NOTIFY_CALLBACK)] =
92 &NetsysNativeServiceStub::CmdUnRegisterNotifyCallback;
93 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_ADD_ROUTE)] =
94 &NetsysNativeServiceStub::CmdNetworkAddRoute;
95 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_REMOVE_ROUTE)] =
96 &NetsysNativeServiceStub::CmdNetworkRemoveRoute;
97 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_ADD_ROUTE_PARCEL)] =
98 &NetsysNativeServiceStub::CmdNetworkAddRouteParcel;
99 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_REMOVE_ROUTE_PARCEL)] =
100 &NetsysNativeServiceStub::CmdNetworkRemoveRouteParcel;
101 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_SET_DEFAULT)] =
102 &NetsysNativeServiceStub::CmdNetworkSetDefault;
103 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_GET_DEFAULT)] =
104 &NetsysNativeServiceStub::CmdNetworkGetDefault;
105 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_CLEAR_DEFAULT)] =
106 &NetsysNativeServiceStub::CmdNetworkClearDefault;
107 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_PROC_SYS_NET)] =
108 &NetsysNativeServiceStub::CmdGetProcSysNet;
109 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_PROC_SYS_NET)] =
110 &NetsysNativeServiceStub::CmdSetProcSysNet;
111 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_CREATE_PHYSICAL)] =
112 &NetsysNativeServiceStub::CmdNetworkCreatePhysical;
113 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_ADD_ADDRESS)] =
114 &NetsysNativeServiceStub::CmdAddInterfaceAddress;
115 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_DEL_ADDRESS)] =
116 &NetsysNativeServiceStub::CmdDelInterfaceAddress;
117 #ifdef FEATURE_WEARABLE_DISTRIBUTED_NET_ENABLE
118 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ENABLE_WEARABLE_DISTRIBUTED_NET_FORWARD)] =
119 &NetsysNativeServiceStub::CmdEnableWearableDistributedNetForward;
120 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DISABLE_WEARABLE_DISTRIBUTED_NET_FORWARD)] =
121 &NetsysNativeServiceStub::CmdDisableWearableDistributedNetForward;
122 #endif
123 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_SET_IPV6_PRIVCAY_EXTENSION)] =
124 &NetsysNativeServiceStub::CmdSetIpv6PrivacyExtensions;
125 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_ENABLE_IPV6)] =
126 &NetsysNativeServiceStub::CmdSetIpv6Enable;
127 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_START_CLAT)] =
128 &NetsysNativeServiceStub::CmdStartClat;
129 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_STOP_CLAT)] =
130 &NetsysNativeServiceStub::CmdStopClat;
131 }
132
InitBandwidthOpToInterfaceMap()133 void NetsysNativeServiceStub::InitBandwidthOpToInterfaceMap()
134 {
135 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_SHARING_NETWORK_TRAFFIC)] =
136 &NetsysNativeServiceStub::CmdGetNetworkSharingTraffic;
137 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_CELLULAR_SHARING_NETWORK_TRAFFIC)] =
138 &NetsysNativeServiceStub::CmdGetNetworkCellularSharingTraffic;
139 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_TOTAL_STATS)] =
140 &NetsysNativeServiceStub::CmdGetTotalStats;
141 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_UID_STATS)] =
142 &NetsysNativeServiceStub::CmdGetUidStats;
143 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_IFACE_STATS)] =
144 &NetsysNativeServiceStub::CmdGetIfaceStats;
145 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_ALL_SIM_STATS_INFO)] =
146 &NetsysNativeServiceStub::CmdGetAllSimStatsInfo;
147 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DELETE_SIM_STATS_INFO)] =
148 &NetsysNativeServiceStub::CmdDeleteSimStatsInfo;
149 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_ALL_STATS_INFO)] =
150 &NetsysNativeServiceStub::CmdGetAllStatsInfo;
151 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DELETE_STATS_INFO)] =
152 &NetsysNativeServiceStub::CmdDeleteStatsInfo;
153 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_COOKIE_STATS)] =
154 &NetsysNativeServiceStub::CmdGetCookieStats;
155 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_CREATE_VIRTUAL)] =
156 &NetsysNativeServiceStub::CmdNetworkCreateVirtual;
157 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_ADD_UIDS)] =
158 &NetsysNativeServiceStub::CmdNetworkAddUids;
159 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_DEL_UIDS)] =
160 &NetsysNativeServiceStub::CmdNetworkDelUids;
161 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_ENABLE_DATA_SAVER)] =
162 &NetsysNativeServiceStub::CmdBandwidthEnableDataSaver;
163 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_SET_IFACE_QUOTA)] =
164 &NetsysNativeServiceStub::CmdBandwidthSetIfaceQuota;
165 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_REMOVE_IFACE_QUOTA)] =
166 &NetsysNativeServiceStub::CmdBandwidthRemoveIfaceQuota;
167 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_ADD_DENIED_LIST)] =
168 &NetsysNativeServiceStub::CmdBandwidthAddDeniedList;
169 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_REMOVE_DENIED_LIST)] =
170 &NetsysNativeServiceStub::CmdBandwidthRemoveDeniedList;
171 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_ADD_ALLOWED_LIST)] =
172 &NetsysNativeServiceStub::CmdBandwidthAddAllowedList;
173 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_BANDWIDTH_REMOVE_ALLOWED_LIST)] =
174 &NetsysNativeServiceStub::CmdBandwidthRemoveAllowedList;
175 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_INTERNET_PERMISSION)] =
176 &NetsysNativeServiceStub::CmdSetInternetPermission;
177 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_NETWORK_ACCESS_POLICY)] =
178 &NetsysNativeServiceStub::CmdSetNetworkAccessPolicy;
179 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DEL_NETWORK_ACCESS_POLICY)] =
180 &NetsysNativeServiceStub::CmdDelNetworkAccessPolicy;
181 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NOTIFY_NETWORK_BEARER_TYPE_CHANGE)] =
182 &NetsysNativeServiceStub::CmdNotifyNetBearerTypeChange;
183 }
184
InitFirewallOpToInterfaceMap()185 void NetsysNativeServiceStub::InitFirewallOpToInterfaceMap()
186 {
187 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_FIREWALL_SET_UID_ALLOWED_LIST_CHAIN)] =
188 &NetsysNativeServiceStub::CmdFirewallSetUidsAllowedListChain;
189 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_FIREWALL_SET_UID_DENIED_LIST_CHAIN)] =
190 &NetsysNativeServiceStub::CmdFirewallSetUidsDeniedListChain;
191 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_FIREWALL_ENABLE_CHAIN)] =
192 &NetsysNativeServiceStub::CmdFirewallEnableChain;
193 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_FIREWALL_SET_UID_RULE)] =
194 &NetsysNativeServiceStub::CmdFirewallSetUidRule;
195 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_NETWORK_SHARING_TYPE)] =
196 &NetsysNativeServiceStub::CmdGetNetworkSharingType;
197 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UPDATE_NETWORK_SHARING_TYPE)] =
198 &NetsysNativeServiceStub::CmdUpdateNetworkSharingType;
199 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_CLEAR_FIREWALL_RULE)] =
200 &NetsysNativeServiceStub::CmdClearFirewallAllRules;
201 #ifdef FEATURE_NET_FIREWALL_ENABLE
202 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_SET_RULES)] =
203 &NetsysNativeServiceStub::CmdSetFirewallRules;
204 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_SET_DEFAULT_ACTION)] =
205 &NetsysNativeServiceStub::CmdSetFirewallDefaultAction;
206 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_SET_USER_ID)] =
207 &NetsysNativeServiceStub::CmdSetFirewallCurrentUserId;
208 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_CLEAR_RULES)] =
209 &NetsysNativeServiceStub::CmdClearFirewallRules;
210 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_REGISTER)] =
211 &NetsysNativeServiceStub::CmdRegisterNetFirewallCallback;
212 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_UNREGISTER)] =
213 &NetsysNativeServiceStub::CmdUnRegisterNetFirewallCallback;
214 #endif
215 }
216
217 #ifdef SUPPORT_SYSVPN
InitVpnOpToInterfaceMap()218 void NetsysNativeServiceStub::InitVpnOpToInterfaceMap()
219 {
220 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_PROCESS_VPN_STAGE)] =
221 &NetsysNativeServiceStub::CmdProcessVpnStage;
222 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UPDATE_VPN_RULES)] =
223 &NetsysNativeServiceStub::CmdUpdateVpnRules;
224 }
225 #endif
226
InitOpToInterfaceMapExt()227 void NetsysNativeServiceStub::InitOpToInterfaceMapExt()
228 {
229 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_SET_IP_ADDRESS)] =
230 &NetsysNativeServiceStub::CmdInterfaceSetIpAddress;
231 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_SET_IFF_UP)] =
232 &NetsysNativeServiceStub::CmdInterfaceSetIffUp;
233 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_ADD_INTERFACE)] =
234 &NetsysNativeServiceStub::CmdNetworkAddInterface;
235 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_REMOVE_INTERFACE)] =
236 &NetsysNativeServiceStub::CmdNetworkRemoveInterface;
237 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETWORK_DESTROY)] =
238 &NetsysNativeServiceStub::CmdNetworkDestroy;
239 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_FWMARK_FOR_NETWORK)] =
240 &NetsysNativeServiceStub::CmdGetFwmarkForNetwork;
241 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_SET_CONFIG)] =
242 &NetsysNativeServiceStub::CmdSetInterfaceConfig;
243 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_GET_CONFIG)] =
244 &NetsysNativeServiceStub::CmdGetInterfaceConfig;
245 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_INTERFACE_GET_LIST)] =
246 &NetsysNativeServiceStub::CmdInterfaceGetList;
247 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_START_DHCP_CLIENT)] =
248 &NetsysNativeServiceStub::CmdStartDhcpClient;
249 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_STOP_DHCP_CLIENT)] =
250 &NetsysNativeServiceStub::CmdStopDhcpClient;
251 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_START_DHCP_SERVICE)] =
252 &NetsysNativeServiceStub::CmdStartDhcpService;
253 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_STOP_DHCP_SERVICE)] =
254 &NetsysNativeServiceStub::CmdStopDhcpService;
255 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_IPENABLE_FORWARDING)] =
256 &NetsysNativeServiceStub::CmdIpEnableForwarding;
257 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_IPDISABLE_FORWARDING)] =
258 &NetsysNativeServiceStub::CmdIpDisableForwarding;
259 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ENABLE_NAT)] =
260 &NetsysNativeServiceStub::CmdEnableNat;
261 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DISABLE_NAT)] =
262 &NetsysNativeServiceStub::CmdDisableNat;
263 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_IPFWD_ADD_INTERFACE_FORWARD)] =
264 &NetsysNativeServiceStub::CmdIpfwdAddInterfaceForward;
265 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_IPFWD_REMOVE_INTERFACE_FORWARD)] =
266 &NetsysNativeServiceStub::CmdIpfwdRemoveInterfaceForward;
267 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_IPTABLES_CMD_FOR_RES)] =
268 &NetsysNativeServiceStub::CmdSetIptablesCommandForRes;
269 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_TETHER_DNS_SET)] =
270 &NetsysNativeServiceStub::CmdShareDnsSet;
271 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_START_DNS_PROXY_LISTEN)] =
272 &NetsysNativeServiceStub::CmdStartDnsProxyListen;
273 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_STOP_DNS_PROXY_LISTEN)] =
274 &NetsysNativeServiceStub::CmdStopDnsProxyListen;
275 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_NIC_TRAFFIC_ALLOWED)] =
276 &NetsysNativeServiceStub::CmdSetNicTrafficAllowed;
277 }
278
InitDnsServerOpToInterfaceMap()279 void NetsysNativeServiceStub::InitDnsServerOpToInterfaceMap()
280 {
281 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_USER_DEFINED_SERVER_FLAG)] =
282 &NetsysNativeServiceStub::CmdSetUserDefinedServerFlag;
283 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_FLUSH_DNS_CACHE)] =
284 &NetsysNativeServiceStub::CmdFlushDnsCache;
285 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_DNS_CACHE)] =
286 &NetsysNativeServiceStub::CmdSetDnsCache;
287 }
288
InitNetDiagOpToInterfaceMap()289 void NetsysNativeServiceStub::InitNetDiagOpToInterfaceMap()
290 {
291 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_PING_HOST)] =
292 &NetsysNativeServiceStub::CmdNetDiagPingHost;
293 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_GET_ROUTE_TABLE)] =
294 &NetsysNativeServiceStub::CmdNetDiagGetRouteTable;
295 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_GET_SOCKETS_INFO)] =
296 &NetsysNativeServiceStub::CmdNetDiagGetSocketsInfo;
297 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_GET_IFACE_CONFIG)] =
298 &NetsysNativeServiceStub::CmdNetDiagGetInterfaceConfig;
299 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_UPDATE_IFACE_CONFIG)] =
300 &NetsysNativeServiceStub::CmdNetDiagUpdateInterfaceConfig;
301 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NETDIAG_SET_IFACE_ACTIVE_STATE)] =
302 &NetsysNativeServiceStub::CmdNetDiagSetInterfaceActiveState;
303 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_IPCMD_FOR_RES)] =
304 &NetsysNativeServiceStub::CmdSetIpCommandForRes;
305 }
306
InitStaticArpToInterfaceMap()307 void NetsysNativeServiceStub::InitStaticArpToInterfaceMap()
308 {
309 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ADD_STATIC_ARP)] =
310 &NetsysNativeServiceStub::CmdAddStaticArp;
311 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DEL_STATIC_ARP)] =
312 &NetsysNativeServiceStub::CmdDelStaticArp;
313 }
314
InitStaticIpv6ToInterfaceMap()315 void NetsysNativeServiceStub::InitStaticIpv6ToInterfaceMap()
316 {
317 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ADD_STATIC_IPV6)] =
318 &NetsysNativeServiceStub::CmdAddStaticIpv6Addr;
319 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DEL_STATIC_IPV6)] =
320 &NetsysNativeServiceStub::CmdDelStaticIpv6Addr;
321 }
322
InitNetDnsDiagOpToInterfaceMap()323 void NetsysNativeServiceStub::InitNetDnsDiagOpToInterfaceMap()
324 {
325 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_REGISTER_DNS_RESULT_LISTENER)] =
326 &NetsysNativeServiceStub::CmdRegisterDnsResultListener;
327 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UNREGISTER_DNS_RESULT_LISTENER)] =
328 &NetsysNativeServiceStub::CmdUnregisterDnsResultListener;
329 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_REGISTER_DNS_HEALTH_LISTENER)] =
330 &NetsysNativeServiceStub::CmdRegisterDnsHealthListener;
331 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UNREGISTER_DNS_HEALTH_LISTENER)] =
332 &NetsysNativeServiceStub::CmdUnregisterDnsHealthListener;
333 }
334
InitNetVnicInterfaceMap()335 void NetsysNativeServiceStub::InitNetVnicInterfaceMap()
336 {
337 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_VNIC_CREATE)] =
338 &NetsysNativeServiceStub::CmdCreateVnic;
339 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_VNIC_DESTROY)] =
340 &NetsysNativeServiceStub::CmdDestroyVnic;
341 }
342
InitNetVirnicInterfaceMap()343 void NetsysNativeServiceStub::InitNetVirnicInterfaceMap()
344 {
345 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ENABLE_DISTRIBUTE_CLIENT_NET)] =
346 &NetsysNativeServiceStub::CmdEnableDistributedClientNet;
347 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_ENABLE_DISTRIBUTE_SERVER_NET)] =
348 &NetsysNativeServiceStub::CmdEnableDistributedServerNet;
349 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DISABLE_DISTRIBUTE_NET)] =
350 &NetsysNativeServiceStub::CmdDisableDistributedNet;
351 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_CLOSE_SOCKETS_UID)] =
352 &NetsysNativeServiceStub::CmdCloseSocketsUid;
353 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DEL_BROKER_UID_NETWORK_POLICY)] =
354 &NetsysNativeServiceStub::CmdDelBrokerUidAccessPolicyMap;
355 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_BROKER_UID_NETWORK_POLICY)] =
356 &NetsysNativeServiceStub::CmdSetBrokerUidAccessPolicyMap;
357 }
358
InitNetStatsInterfaceMap()359 void NetsysNativeServiceStub::InitNetStatsInterfaceMap()
360 {
361 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_TRAFFIC_REGISTER)] =
362 &NetsysNativeServiceStub::CmdRegisterNetsysTrafficCallback;
363 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_TRAFFIC_UNREGISTER)] =
364 &NetsysNativeServiceStub::CmdUnRegisterNetsysTrafficCallback;
365 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_TRAFFIC_AVAILABLE_MAP)] =
366 &NetsysNativeServiceStub::CmdSetNetStateTrafficMap;
367 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_GET_TRAFFIC_AVAILABLE_MAP)] =
368 &NetsysNativeServiceStub::CmdGetNetStateTrafficMap;
369 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_CLEAR_INCRE_TRAFFIC_MAP)] =
370 &NetsysNativeServiceStub::CmdClearIncreaseTrafficMap;
371 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_DELETE_INCRE_TRAFFIC_MAP)] =
372 &NetsysNativeServiceStub::CmdDeleteIncreaseTrafficMap;
373 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UPDATE_IFINDEX_MAP)] =
374 &NetsysNativeServiceStub::CmdUpdateIfIndexMap;
375 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_NET_STATUS_MAP)] =
376 &NetsysNativeServiceStub::CmdSetNetStatusMap;
377 }
378
379 #ifdef FEATURE_ENTERPRISE_ROUTE_CUSTOM
InitEnterpriseMap()380 void NetsysNativeServiceStub::InitEnterpriseMap()
381 {
382 opToInterfaceMap_[static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_UPDATE_ENTERPRISE_ROUTE)] =
383 &NetsysNativeServiceStub::CmdUpdateEnterpriseRoute;
384 }
385 #endif
386
CmdRegisterNetsysTrafficCallback(MessageParcel & data,MessageParcel & reply)387 int32_t NetsysNativeServiceStub::CmdRegisterNetsysTrafficCallback(MessageParcel &data, MessageParcel &reply)
388 {
389 NETNATIVE_LOGI("CmdRegisterNetsysTrafficCallback start.");
390 int32_t result = NETMANAGER_SUCCESS;
391 sptr<IRemoteObject> remote = data.ReadRemoteObject();
392 if (remote == nullptr) {
393 NETNATIVE_LOGE("Callback ptr is nullptr.");
394 result = IPC_STUB_ERR;
395 reply.WriteInt32(result);
396 return result;
397 }
398
399 sptr<INetsysTrafficCallback> callback = iface_cast<INetsysTrafficCallback>(remote);
400 if (callback == nullptr) {
401 NETNATIVE_LOGE("CmdRegisterNetsysTrafficCallback err.");
402 result = ERR_FLATTEN_OBJECT;
403 reply.WriteInt32(result);
404 return result;
405 }
406
407 result = RegisterNetsysTrafficCallback(callback);
408 reply.WriteInt32(result);
409 NETNATIVE_LOGI("CmdRegisterNetsysTrafficCallback end. result:%{public}d", result);
410 return result;
411 }
412
CmdUnRegisterNetsysTrafficCallback(MessageParcel & data,MessageParcel & reply)413 int32_t NetsysNativeServiceStub::CmdUnRegisterNetsysTrafficCallback(MessageParcel &data, MessageParcel &reply)
414 {
415 int32_t result = NETMANAGER_SUCCESS;
416 sptr<IRemoteObject> remote = data.ReadRemoteObject();
417 if (remote == nullptr) {
418 NETNATIVE_LOGE("Callback ptr is nullptr.");
419 result = IPC_STUB_ERR;
420 reply.WriteInt32(result);
421 return result;
422 }
423
424 sptr<INetsysTrafficCallback> callback = iface_cast<INetsysTrafficCallback>(remote);
425 if (callback == nullptr) {
426 result = ERR_FLATTEN_OBJECT;
427 reply.WriteInt32(result);
428 return result;
429 }
430
431 result = UnRegisterNetsysTrafficCallback(callback);
432 reply.WriteInt32(result);
433 return result;
434 }
435
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)436 int32_t NetsysNativeServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
437 MessageOption &option)
438 {
439 NETNATIVE_LOG_D("Begin to call procedure with code %{public}u", code);
440 auto interfaceIndex = opToInterfaceMap_.find(code);
441 if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
442 NETNATIVE_LOGE("Cannot response request %d: unknown tranction", code);
443 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
444 }
445 auto uid = IPCSkeleton::GetCallingUid();
446 if (std::find(uids_.begin(), uids_.end(), uid) == uids_.end()) {
447 NETNATIVE_LOGE("This uid connot use netsys %{public}d", uid);
448 if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
449 return IPC_STUB_WRITE_PARCEL_ERR;
450 }
451 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
452 }
453
454 if ((code == static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_IPTABLES_CMD_FOR_RES) ||
455 code == static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_SET_IPCMD_FOR_RES)) && uid != UID_EDM &&
456 uid != UID_NET_MANAGER && uid != UID_IOT_NET_MANAGER) {
457 if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
458 return IPC_STUB_WRITE_PARCEL_ERR;
459 }
460 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
461 }
462
463 const std::u16string descriptor = NetsysNativeServiceStub::GetDescriptor();
464 const std::u16string remoteDescriptor = data.ReadInterfaceToken();
465 if (descriptor != remoteDescriptor) {
466 NETNATIVE_LOGE("Check remote descriptor failed");
467 return IPC_STUB_INVALID_DATA_ERR;
468 }
469
470 #ifdef FEATURE_NET_FIREWALL_ENABLE
471 if (code >= static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_SET_DEFAULT_ACTION) &&
472 code <= static_cast<uint32_t>(NetsysInterfaceCode::NETSYS_NET_FIREWALL_UNREGISTER) &&
473 !NetManagerPermission::CheckPermission(Permission::NETSYS_INTERNAL)) {
474 if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
475 return IPC_STUB_WRITE_PARCEL_ERR;
476 }
477 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
478 }
479 #endif
480
481 return (this->*(interfaceIndex->second))(data, reply);
482 }
483
CmdSetResolverConfig(MessageParcel & data,MessageParcel & reply)484 int32_t NetsysNativeServiceStub::CmdSetResolverConfig(MessageParcel &data, MessageParcel &reply)
485 {
486 uint16_t netId = 0;
487 uint16_t baseTimeoutMsec = 0;
488 uint8_t retryCount = 0;
489 std::vector<std::string> servers;
490 std::vector<std::string> domains;
491 if (!data.ReadUint16(netId)) {
492 return ERR_FLATTEN_OBJECT;
493 }
494 if (!data.ReadUint16(baseTimeoutMsec)) {
495 return ERR_FLATTEN_OBJECT;
496 }
497 if (!data.ReadUint8(retryCount)) {
498 return ERR_FLATTEN_OBJECT;
499 }
500 int32_t vServerSize;
501 if (!data.ReadInt32(vServerSize)) {
502 return ERR_FLATTEN_OBJECT;
503 }
504 vServerSize = (vServerSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vServerSize;
505 std::string s;
506 for (int32_t i = 0; i < vServerSize; ++i) {
507 std::string().swap(s);
508 if (!data.ReadString(s)) {
509 return ERR_FLATTEN_OBJECT;
510 }
511 servers.push_back(s);
512 }
513 int32_t vDomainSize;
514 if (!data.ReadInt32(vDomainSize)) {
515 return ERR_FLATTEN_OBJECT;
516 }
517 vDomainSize = (vDomainSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vDomainSize;
518 for (int32_t i = 0; i < vDomainSize; ++i) {
519 std::string().swap(s);
520 if (!data.ReadString(s)) {
521 return ERR_FLATTEN_OBJECT;
522 }
523 domains.push_back(s);
524 }
525
526 int32_t result = SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
527 reply.WriteInt32(result);
528 NETNATIVE_LOG_D("SetResolverConfig has received result %{public}d", result);
529
530 return ERR_NONE;
531 }
532
CmdGetResolverConfig(MessageParcel & data,MessageParcel & reply)533 int32_t NetsysNativeServiceStub::CmdGetResolverConfig(MessageParcel &data, MessageParcel &reply)
534 {
535 uint16_t baseTimeoutMsec;
536 uint8_t retryCount;
537 uint16_t netId = 0;
538 std::vector<std::string> servers;
539 std::vector<std::string> domains;
540
541 data.ReadUint16(netId);
542 int32_t result = GetResolverConfig(netId, servers, domains, baseTimeoutMsec, retryCount);
543 reply.WriteInt32(result);
544 reply.WriteUint16(baseTimeoutMsec);
545 reply.WriteUint8(retryCount);
546 auto vServerSize = static_cast<int32_t>(servers.size());
547 vServerSize = (vServerSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vServerSize;
548 reply.WriteInt32(vServerSize);
549 int32_t index = 0;
550 for (auto &server : servers) {
551 if (++index > MAX_DNS_CONFIG_SIZE) {
552 break;
553 }
554 reply.WriteString(server);
555 }
556 auto vDomainsSize = static_cast<int32_t>(domains.size());
557 vDomainsSize = (vDomainsSize > MAX_DNS_CONFIG_SIZE) ? MAX_DNS_CONFIG_SIZE : vDomainsSize;
558 reply.WriteInt32(vDomainsSize);
559 std::vector<std::string>::iterator iterDomains;
560 index = 0;
561 for (iterDomains = domains.begin(); iterDomains != domains.end(); ++iterDomains) {
562 if (++index > MAX_DNS_CONFIG_SIZE) {
563 break;
564 }
565 reply.WriteString(*iterDomains);
566 }
567 NETNATIVE_LOG_D("GetResolverConfig has recved result %{public}d", result);
568 return ERR_NONE;
569 }
570
CmdCreateNetworkCache(MessageParcel & data,MessageParcel & reply)571 int32_t NetsysNativeServiceStub::CmdCreateNetworkCache(MessageParcel &data, MessageParcel &reply)
572 {
573 uint16_t netid = data.ReadUint16();
574 bool isVpnNet = data.ReadBool();
575 NETNATIVE_LOGI("CreateNetworkCache netid %{public}d, isVpnNet %{public}d", netid, isVpnNet);
576 int32_t result = CreateNetworkCache(netid, isVpnNet);
577 reply.WriteInt32(result);
578 NETNATIVE_LOG_D("CreateNetworkCache has recved result %{public}d", result);
579
580 return ERR_NONE;
581 }
582
CmdDestroyNetworkCache(MessageParcel & data,MessageParcel & reply)583 int32_t NetsysNativeServiceStub::CmdDestroyNetworkCache(MessageParcel &data, MessageParcel &reply)
584 {
585 uint16_t netId = data.ReadUint16();
586 bool isVpnNet = data.ReadBool();
587 NETNATIVE_LOGI("DestroyNetworkCache netId %{public}d, isVpnNet %{public}d", netId, isVpnNet);
588 int32_t result = DestroyNetworkCache(netId, isVpnNet);
589 reply.WriteInt32(result);
590 NETNATIVE_LOG_D("DestroyNetworkCache has recved result %{public}d", result);
591 return ERR_NONE;
592 }
593
NetsysFreeAddrinfo(struct addrinfo * aihead)594 int32_t NetsysNativeServiceStub::NetsysFreeAddrinfo(struct addrinfo *aihead)
595 {
596 struct addrinfo *ai;
597 struct addrinfo *ainext;
598 for (ai = aihead; ai != nullptr; ai = ainext) {
599 if (ai->ai_addr != nullptr)
600 free(ai->ai_addr);
601 if (ai->ai_canonname != nullptr)
602 free(ai->ai_canonname);
603 ainext = ai->ai_next;
604 free(ai);
605 }
606 return ERR_NONE;
607 }
608
CmdGetAddrInfo(MessageParcel & data,MessageParcel & reply)609 int32_t NetsysNativeServiceStub::CmdGetAddrInfo(MessageParcel &data, MessageParcel &reply)
610 {
611 std::string hostName;
612 std::string serverName;
613 AddrInfo hints = {};
614 uint16_t netId;
615 if (!data.ReadString(hostName)) {
616 return IPC_STUB_INVALID_DATA_ERR;
617 }
618
619 if (!data.ReadString(serverName)) {
620 return IPC_STUB_INVALID_DATA_ERR;
621 }
622
623 auto p = data.ReadRawData(sizeof(AddrInfo));
624 if (p == nullptr) {
625 return IPC_STUB_INVALID_DATA_ERR;
626 }
627 if (memcpy_s(&hints, sizeof(AddrInfo), p, sizeof(AddrInfo)) != EOK) {
628 return IPC_STUB_INVALID_DATA_ERR;
629 }
630
631 if (!data.ReadUint16(netId)) {
632 return IPC_STUB_INVALID_DATA_ERR;
633 }
634
635 std::vector<AddrInfo> retInfo;
636 auto ret = GetAddrInfo(hostName, serverName, hints, netId, retInfo);
637 if (retInfo.size() > MAX_RESULTS) {
638 return IPC_STUB_INVALID_DATA_ERR;
639 }
640
641 if (!reply.WriteInt32(ret)) {
642 return IPC_STUB_WRITE_PARCEL_ERR;
643 }
644
645 if (ret != ERR_NONE) {
646 return ERR_NONE;
647 }
648
649 if (!reply.WriteUint32(static_cast<uint32_t>(retInfo.size()))) {
650 return IPC_STUB_WRITE_PARCEL_ERR;
651 }
652
653 for (const auto &info : retInfo) {
654 if (!reply.WriteRawData(&info, sizeof(AddrInfo))) {
655 return IPC_STUB_WRITE_PARCEL_ERR;
656 }
657 }
658 return ERR_NONE;
659 }
660
CmdSetInterfaceMtu(MessageParcel & data,MessageParcel & reply)661 int32_t NetsysNativeServiceStub::CmdSetInterfaceMtu(MessageParcel &data, MessageParcel &reply)
662 {
663 std::string ifName = data.ReadString();
664 int32_t mtu = data.ReadInt32();
665 int32_t result = SetInterfaceMtu(ifName, mtu);
666 reply.WriteInt32(result);
667 NETNATIVE_LOG_D("SetInterfaceMtu has recved result %{public}d", result);
668
669 return ERR_NONE;
670 }
671
CmdGetInterfaceMtu(MessageParcel & data,MessageParcel & reply)672 int32_t NetsysNativeServiceStub::CmdGetInterfaceMtu(MessageParcel &data, MessageParcel &reply)
673 {
674 std::string ifName = data.ReadString();
675 int32_t result = GetInterfaceMtu(ifName);
676 reply.WriteInt32(result);
677 NETNATIVE_LOG_D("GetInterfaceMtu has recved result %{public}d", result);
678
679 return ERR_NONE;
680 }
681
CmdSetTcpBufferSizes(MessageParcel & data,MessageParcel & reply)682 int32_t NetsysNativeServiceStub::CmdSetTcpBufferSizes(MessageParcel &data, MessageParcel &reply)
683 {
684 std::string tcpBufferSizes = data.ReadString();
685 int32_t result = SetTcpBufferSizes(tcpBufferSizes);
686 reply.WriteInt32(result);
687 NETNATIVE_LOG_D("SetTcpBufferSizes has recved result %{public}d", result);
688
689 return ERR_NONE;
690 }
691
CmdRegisterNotifyCallback(MessageParcel & data,MessageParcel & reply)692 int32_t NetsysNativeServiceStub::CmdRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply)
693 {
694 NETNATIVE_LOG_D("Begin to dispatch cmd RegisterNotifyCallback");
695 sptr<IRemoteObject> remote = data.ReadRemoteObject();
696 if (remote == nullptr) {
697 NETNATIVE_LOGE("Callback ptr is nullptr.");
698 return -1;
699 }
700
701 sptr<INotifyCallback> callback = iface_cast<INotifyCallback>(remote);
702 int32_t result = RegisterNotifyCallback(callback);
703 reply.WriteInt32(result);
704 return ERR_NONE;
705 }
706
CmdUnRegisterNotifyCallback(MessageParcel & data,MessageParcel & reply)707 int32_t NetsysNativeServiceStub::CmdUnRegisterNotifyCallback(MessageParcel &data, MessageParcel &reply)
708 {
709 NETNATIVE_LOG_D("Begin to dispatch cmd UnRegisterNotifyCallback");
710 sptr<IRemoteObject> remote = data.ReadRemoteObject();
711 if (remote == nullptr) {
712 NETNATIVE_LOGE("Callback ptr is nullptr.");
713 return -1;
714 }
715
716 sptr<INotifyCallback> callback = iface_cast<INotifyCallback>(remote);
717 int32_t result = UnRegisterNotifyCallback(callback);
718 reply.WriteInt32(result);
719 return ERR_NONE;
720 }
721
CmdNetworkAddRoute(MessageParcel & data,MessageParcel & reply)722 int32_t NetsysNativeServiceStub::CmdNetworkAddRoute(MessageParcel &data, MessageParcel &reply)
723 {
724 int32_t netId = data.ReadInt32();
725 std::string ifName = data.ReadString();
726 std::string destination = data.ReadString();
727 std::string nextHop = data.ReadString();
728 bool isExcludedRoute = data.ReadBool();
729
730 NETNATIVE_LOGI("netId[%{public}d}, ifName[%{public}s], destination[%{public}s}, nextHop[%{public}s], \
731 isExcludedRoute[%{public}d]", netId, ifName.c_str(), ToAnonymousIp(destination).c_str(),
732 ToAnonymousIp(nextHop).c_str(), isExcludedRoute);
733 int32_t result = NetworkAddRoute(netId, ifName, destination, nextHop, isExcludedRoute);
734 reply.WriteInt32(result);
735 NETNATIVE_LOG_D("NetworkAddRoute has recved result %{public}d", result);
736 return result;
737 }
738
CmdNetworkRemoveRoute(MessageParcel & data,MessageParcel & reply)739 int32_t NetsysNativeServiceStub::CmdNetworkRemoveRoute(MessageParcel &data, MessageParcel &reply)
740 {
741 int32_t netId = data.ReadInt32();
742 std::string interfaceName = data.ReadString();
743 std::string destination = data.ReadString();
744 std::string nextHop = data.ReadString();
745
746 NETNATIVE_LOGI("netId[%{public}d}, ifName[%{public}s], destination[%{public}s}, nextHop[%{public}s]", netId,
747 interfaceName.c_str(), ToAnonymousIp(destination).c_str(), ToAnonymousIp(nextHop).c_str());
748 int32_t result = NetworkRemoveRoute(netId, interfaceName, destination, nextHop);
749 reply.WriteInt32(result);
750 NETNATIVE_LOG_D("NetworkRemoveRoute has recved result %{public}d", result);
751
752 return result;
753 }
754
CmdNetworkAddRouteParcel(MessageParcel & data,MessageParcel & reply)755 int32_t NetsysNativeServiceStub::CmdNetworkAddRouteParcel(MessageParcel &data, MessageParcel &reply)
756 {
757 RouteInfoParcel routeInfo = {};
758 int32_t netId = data.ReadInt32();
759 routeInfo.ifName = data.ReadString();
760 routeInfo.destination = data.ReadString();
761 routeInfo.nextHop = data.ReadString();
762 int32_t result = NetworkAddRouteParcel(netId, routeInfo);
763 reply.WriteInt32(result);
764 NETNATIVE_LOG_D("NetworkAddRouteParcel has recved result %{public}d", result);
765
766 return result;
767 }
768
CmdNetworkRemoveRouteParcel(MessageParcel & data,MessageParcel & reply)769 int32_t NetsysNativeServiceStub::CmdNetworkRemoveRouteParcel(MessageParcel &data, MessageParcel &reply)
770 {
771 RouteInfoParcel routeInfo = {};
772 int32_t netId = data.ReadInt32();
773 routeInfo.ifName = data.ReadString();
774 routeInfo.destination = data.ReadString();
775 routeInfo.nextHop = data.ReadString();
776
777 int32_t result = NetworkRemoveRouteParcel(netId, routeInfo);
778 reply.WriteInt32(result);
779 NETNATIVE_LOG_D("NetworkRemoveRouteParcel has recved result %{public}d", result);
780
781 return result;
782 }
783
CmdNetworkSetDefault(MessageParcel & data,MessageParcel & reply)784 int32_t NetsysNativeServiceStub::CmdNetworkSetDefault(MessageParcel &data, MessageParcel &reply)
785 {
786 int32_t netId = data.ReadInt32();
787
788 int32_t result = NetworkSetDefault(netId);
789 reply.WriteInt32(result);
790 NETNATIVE_LOG_D("NetworkSetDefault has recved result %{public}d", result);
791
792 return result;
793 }
794
CmdNetworkGetDefault(MessageParcel & data,MessageParcel & reply)795 int32_t NetsysNativeServiceStub::CmdNetworkGetDefault(MessageParcel &data, MessageParcel &reply)
796 {
797 int32_t result = NetworkGetDefault();
798 reply.WriteInt32(result);
799 NETNATIVE_LOG_D("NetworkGetDefault has recved result %{public}d", result);
800
801 return result;
802 }
803
CmdNetworkClearDefault(MessageParcel & data,MessageParcel & reply)804 int32_t NetsysNativeServiceStub::CmdNetworkClearDefault(MessageParcel &data, MessageParcel &reply)
805 {
806 int32_t result = NetworkClearDefault();
807 reply.WriteInt32(result);
808 NETNATIVE_LOG_D("NetworkClearDefault has recved result %{public}d", result);
809
810 return result;
811 }
812
CmdGetProcSysNet(MessageParcel & data,MessageParcel & reply)813 int32_t NetsysNativeServiceStub::CmdGetProcSysNet(MessageParcel &data, MessageParcel &reply)
814 {
815 NETNATIVE_LOG_D("Begin to dispatch cmd GetProcSysNet");
816 int32_t family = data.ReadInt32();
817 int32_t which = data.ReadInt32();
818 std::string ifname = data.ReadString();
819 std::string parameter = data.ReadString();
820 std::string value;
821 int32_t result = GetProcSysNet(family, which, ifname, parameter, value);
822 reply.WriteInt32(result);
823 std::string valueRsl = value;
824 reply.WriteString(valueRsl);
825 return result;
826 }
827
CmdSetProcSysNet(MessageParcel & data,MessageParcel & reply)828 int32_t NetsysNativeServiceStub::CmdSetProcSysNet(MessageParcel &data, MessageParcel &reply)
829 {
830 int32_t family = data.ReadInt32();
831 int32_t which = data.ReadInt32();
832 std::string ifname = data.ReadString();
833 std::string parameter = data.ReadString();
834 std::string value = data.ReadString();
835 int32_t result = SetProcSysNet(family, which, ifname, parameter, value);
836 reply.WriteInt32(result);
837 NETNATIVE_LOG_D("SetProcSysNet has recved result %{public}d", result);
838
839 return result;
840 }
841
CmdSetInternetPermission(MessageParcel & data,MessageParcel & reply)842 int32_t NetsysNativeServiceStub::CmdSetInternetPermission(MessageParcel &data, MessageParcel &reply)
843 {
844 uint32_t uid = data.ReadUint32();
845 uint8_t allow = data.ReadUint8();
846 uint8_t isBroker = data.ReadUint8();
847 int32_t result = SetInternetPermission(uid, allow, isBroker);
848 reply.WriteInt32(result);
849 NETNATIVE_LOG_D("SetInternetPermission has recved result %{public}d", result);
850 return result;
851 }
852
CmdNetworkCreatePhysical(MessageParcel & data,MessageParcel & reply)853 int32_t NetsysNativeServiceStub::CmdNetworkCreatePhysical(MessageParcel &data, MessageParcel &reply)
854 {
855 int32_t netId = data.ReadInt32();
856 int32_t permission = data.ReadInt32();
857
858 int32_t result = NetworkCreatePhysical(netId, permission);
859 reply.WriteInt32(result);
860 NETNATIVE_LOG_D("NetworkCreatePhysical has recved result %{public}d", result);
861
862 return result;
863 }
864
CmdNetworkCreateVirtual(MessageParcel & data,MessageParcel & reply)865 int32_t NetsysNativeServiceStub::CmdNetworkCreateVirtual(MessageParcel &data, MessageParcel &reply)
866 {
867 int32_t netId = 0;
868 bool hasDns = false;
869 if (!data.ReadInt32(netId) || !data.ReadBool(hasDns)) {
870 NETNATIVE_LOGE("read net id or hasDns failed");
871 return IPC_STUB_ERR;
872 }
873
874 int32_t result = NetworkCreateVirtual(netId, hasDns);
875 if (!reply.WriteInt32(result)) {
876 return IPC_STUB_WRITE_PARCEL_ERR;
877 }
878 NETNATIVE_LOG_D("NetworkCreateVirtual has recved result %{public}d", result);
879 return ERR_NONE;
880 }
881
CmdNetworkAddUids(MessageParcel & data,MessageParcel & reply)882 int32_t NetsysNativeServiceStub::CmdNetworkAddUids(MessageParcel &data, MessageParcel &reply)
883 {
884 int32_t netId = 0;
885 int32_t size = 0;
886 if (!data.ReadInt32(netId) || !data.ReadInt32(size)) {
887 NETNATIVE_LOGE("read net id or size failed");
888 return IPC_STUB_ERR;
889 }
890 size = (size > static_cast<int32_t>(MAX_UID_ARRAY_SIZE)) ? static_cast<int32_t>(MAX_UID_ARRAY_SIZE) : size;
891
892 sptr<UidRange> uid;
893 std::vector<UidRange> uidRanges;
894 for (int32_t index = 0; index < size; index++) {
895 uid = UidRange::Unmarshalling(data);
896 if (uid == nullptr) {
897 NETNATIVE_LOGE("UidRange::Unmarshalling(parcel) is null");
898 return IPC_STUB_ERR;
899 }
900 uidRanges.push_back(*uid);
901 }
902 int32_t result = NetworkAddUids(netId, uidRanges);
903 if (!reply.WriteInt32(result)) {
904 return IPC_STUB_WRITE_PARCEL_ERR;
905 }
906 NETNATIVE_LOG_D("NetworkAddUids has recved result %{public}d", result);
907 return ERR_NONE;
908 }
909
CmdNetworkDelUids(MessageParcel & data,MessageParcel & reply)910 int32_t NetsysNativeServiceStub::CmdNetworkDelUids(MessageParcel &data, MessageParcel &reply)
911 {
912 int32_t netId = 0;
913 int32_t size = 0;
914 if (!data.ReadInt32(netId) || !data.ReadInt32(size)) {
915 NETNATIVE_LOGE("read net id or size failed");
916 return IPC_STUB_ERR;
917 }
918
919 size = (size > static_cast<int32_t>(MAX_UID_ARRAY_SIZE)) ? static_cast<int32_t>(MAX_UID_ARRAY_SIZE) : size;
920
921 sptr<UidRange> uid;
922 std::vector<UidRange> uidRanges;
923 for (int32_t index = 0; index < size; index++) {
924 uid = UidRange::Unmarshalling(data);
925 if (uid == nullptr) {
926 NETNATIVE_LOGE("UidRange::Unmarshalling(parcel) is null");
927 return IPC_STUB_ERR;
928 }
929 uidRanges.push_back(*uid);
930 }
931 int32_t result = NetworkDelUids(netId, uidRanges);
932 if (!reply.WriteInt32(result)) {
933 return IPC_STUB_WRITE_PARCEL_ERR;
934 }
935 NETNATIVE_LOG_D("NetworkDelUids has recved result %{public}d", result);
936 return ERR_NONE;
937 }
938
CmdAddInterfaceAddress(MessageParcel & data,MessageParcel & reply)939 int32_t NetsysNativeServiceStub::CmdAddInterfaceAddress(MessageParcel &data, MessageParcel &reply)
940 {
941 std::string interfaceName = data.ReadString();
942 std::string ipAddr = data.ReadString();
943 int32_t prefixLength = data.ReadInt32();
944
945 int32_t result = AddInterfaceAddress(interfaceName, ipAddr, prefixLength);
946 reply.WriteInt32(result);
947 NETNATIVE_LOG_D("AddInterfaceAddress has recved result %{public}d", result);
948
949 return result;
950 }
951
CmdDelInterfaceAddress(MessageParcel & data,MessageParcel & reply)952 int32_t NetsysNativeServiceStub::CmdDelInterfaceAddress(MessageParcel &data, MessageParcel &reply)
953 {
954 std::string interfaceName = data.ReadString();
955 std::string ipAddr = data.ReadString();
956 int32_t prefixLength = data.ReadInt32();
957 std::string netCapabilities;
958 int32_t result = 0;
959 if (!data.ReadString(netCapabilities)) {
960 NETNATIVE_LOG_D("DelInterfaceAddress");
961 result = DelInterfaceAddress(interfaceName, ipAddr, prefixLength);
962 } else {
963 NETNATIVE_LOG_D("DelInterfaceAddress with netCapabilities %{public}s", netCapabilities.c_str());
964 result = DelInterfaceAddress(interfaceName, ipAddr, prefixLength, netCapabilities);
965 }
966 reply.WriteInt32(result);
967 NETNATIVE_LOG_D("DelInterfaceAddress has recved result %{public}d", result);
968
969 return result;
970 }
971
972 #ifdef FEATURE_WEARABLE_DISTRIBUTED_NET_ENABLE
CmdEnableWearableDistributedNetForward(MessageParcel & data,MessageParcel & reply)973 int32_t NetsysNativeServiceStub::CmdEnableWearableDistributedNetForward(MessageParcel &data, MessageParcel &reply)
974 {
975 NETNATIVE_LOGI("NetsysNativeServiceStub enable wearable distributed net forward");
976 int32_t tcpPort = data.ReadInt32();
977 int32_t udpPort = data.ReadInt32();
978 int32_t result = EnableWearableDistributedNetForward(tcpPort, udpPort);
979 if (!reply.WriteInt32(result)) {
980 return NETMANAGER_ERR_WRITE_DATA_FAIL;
981 }
982
983 return result;
984 }
985
CmdDisableWearableDistributedNetForward(MessageParcel & data,MessageParcel & reply)986 int32_t NetsysNativeServiceStub::CmdDisableWearableDistributedNetForward(MessageParcel &data, MessageParcel &reply)
987 {
988 NETNATIVE_LOGI("NetsysNativeServiceStub disable wearable distributed net forward");
989 int32_t result = DisableWearableDistributedNetForward();
990 if (!reply.WriteInt32(result)) {
991 return NETMANAGER_ERR_WRITE_DATA_FAIL;
992 }
993
994 return result;
995 }
996 #endif
997
CmdInterfaceSetIpAddress(MessageParcel & data,MessageParcel & reply)998 int32_t NetsysNativeServiceStub::CmdInterfaceSetIpAddress(MessageParcel &data, MessageParcel &reply)
999 {
1000 std::string ifaceName = data.ReadString();
1001 std::string ipAddress = data.ReadString();
1002
1003 int32_t result = InterfaceSetIpAddress(ifaceName, ipAddress);
1004 reply.WriteInt32(result);
1005 NETNATIVE_LOG_D("InterfaceSetIpAddress has recved result %{public}d", result);
1006
1007 return result;
1008 }
1009
CmdInterfaceSetIffUp(MessageParcel & data,MessageParcel & reply)1010 int32_t NetsysNativeServiceStub::CmdInterfaceSetIffUp(MessageParcel &data, MessageParcel &reply)
1011 {
1012 std::string ifaceName = data.ReadString();
1013
1014 int32_t result = InterfaceSetIffUp(ifaceName);
1015 reply.WriteInt32(result);
1016 NETNATIVE_LOG_D("InterfaceSetIffUp has recved result %{public}d", result);
1017
1018 return result;
1019 }
1020
CmdNetworkAddInterface(MessageParcel & data,MessageParcel & reply)1021 int32_t NetsysNativeServiceStub::CmdNetworkAddInterface(MessageParcel &data, MessageParcel &reply)
1022 {
1023 int32_t netId = data.ReadInt32();
1024 std::string iface = data.ReadString();
1025 NetBearType netBearerType = static_cast<NetBearType>(data.ReadUint8());
1026
1027 int32_t result = NetworkAddInterface(netId, iface, netBearerType);
1028 reply.WriteInt32(result);
1029 NETNATIVE_LOG_D("NetworkAddInterface has recved result %{public}d", result);
1030
1031 return result;
1032 }
1033
CmdNetworkRemoveInterface(MessageParcel & data,MessageParcel & reply)1034 int32_t NetsysNativeServiceStub::CmdNetworkRemoveInterface(MessageParcel &data, MessageParcel &reply)
1035 {
1036 int32_t netId = data.ReadInt32();
1037 std::string iface = data.ReadString();
1038 int32_t result = NetworkRemoveInterface(netId, iface);
1039 reply.WriteInt32(result);
1040 NETNATIVE_LOG_D("NetworkRemoveInterface has recved result %{public}d", result);
1041
1042 return result;
1043 }
1044
CmdNetworkDestroy(MessageParcel & data,MessageParcel & reply)1045 int32_t NetsysNativeServiceStub::CmdNetworkDestroy(MessageParcel &data, MessageParcel &reply)
1046 {
1047 int32_t netId = data.ReadInt32();
1048 bool isVpnNet = data.ReadBool();
1049 int32_t result = NetworkDestroy(netId, isVpnNet);
1050 reply.WriteInt32(result);
1051 NETNATIVE_LOG_D("NetworkDestroy has recved result %{public}d", result);
1052
1053 return result;
1054 }
1055
CmdCreateVnic(MessageParcel & data,MessageParcel & reply)1056 int32_t NetsysNativeServiceStub::CmdCreateVnic(MessageParcel &data, MessageParcel &reply)
1057 {
1058 uint16_t mtu = data.ReadUint16();
1059 std::string tunAddr = data.ReadString();
1060 int32_t prefix = data.ReadInt32();
1061 std::set<int32_t> uids;
1062 int32_t size = 0;
1063 int32_t uid = 0;
1064 if (!data.ReadInt32(size)) {
1065 return NETMANAGER_ERR_READ_DATA_FAIL;
1066 }
1067
1068 if (size < 0 || size > MAX_VNIC_UID_ARRAY_SIZE) {
1069 NETNATIVE_LOGE("vnic uids size is invalid");
1070 return NETMANAGER_ERR_READ_DATA_FAIL;
1071 }
1072
1073 for (int32_t index = 0; index < size; index++) {
1074 if (!data.ReadInt32(uid)) {
1075 return NETMANAGER_ERR_READ_DATA_FAIL;
1076 }
1077 uids.insert(uid);
1078 }
1079 int32_t result = CreateVnic(mtu, tunAddr, prefix, uids);
1080 reply.WriteInt32(result);
1081 NETNATIVE_LOG_D("VnciCreate has recved result %{public}d", result);
1082
1083 return result;
1084 }
1085
CmdDestroyVnic(MessageParcel & data,MessageParcel & reply)1086 int32_t NetsysNativeServiceStub::CmdDestroyVnic(MessageParcel &data, MessageParcel &reply)
1087 {
1088 int32_t result = DestroyVnic();
1089 reply.WriteInt32(result);
1090 NETNATIVE_LOG_D("VnicDestroy has recved result %{public}d", result);
1091
1092 return result;
1093 }
1094
CmdEnableDistributedClientNet(MessageParcel & data,MessageParcel & reply)1095 int32_t NetsysNativeServiceStub::CmdEnableDistributedClientNet(MessageParcel &data, MessageParcel &reply)
1096 {
1097 std::string virnicAddr = data.ReadString();
1098 std::string iif = data.ReadString();
1099
1100 int32_t result = EnableDistributedClientNet(virnicAddr, iif);
1101 reply.WriteInt32(result);
1102 NETNATIVE_LOG_D("CmdEnableDistributedClientNet has recved result %{public}d", result);
1103
1104 return result;
1105 }
1106
CmdEnableDistributedServerNet(MessageParcel & data,MessageParcel & reply)1107 int32_t NetsysNativeServiceStub::CmdEnableDistributedServerNet(MessageParcel &data, MessageParcel &reply)
1108 {
1109 std::string iif = data.ReadString();
1110 std::string devIface = data.ReadString();
1111 std::string dstAddr = data.ReadString();
1112
1113 int32_t result = EnableDistributedServerNet(iif, devIface, dstAddr);
1114 reply.WriteInt32(result);
1115 NETNATIVE_LOG_D("CmdEnableDistributedServerNet has recved result %{public}d", result);
1116
1117 return result;
1118 }
1119
CmdDisableDistributedNet(MessageParcel & data,MessageParcel & reply)1120 int32_t NetsysNativeServiceStub::CmdDisableDistributedNet(MessageParcel &data, MessageParcel &reply)
1121 {
1122 bool isServer = data.ReadBool();
1123
1124 int32_t result = DisableDistributedNet(isServer);
1125 reply.WriteInt32(result);
1126 NETNATIVE_LOG_D("CmdDisableDistributedNet has recved result %{public}d", result);
1127
1128 return result;
1129 }
1130
CmdGetFwmarkForNetwork(MessageParcel & data,MessageParcel & reply)1131 int32_t NetsysNativeServiceStub::CmdGetFwmarkForNetwork(MessageParcel &data, MessageParcel &reply)
1132 {
1133 MarkMaskParcel markMaskParcel = {};
1134 int32_t netId = data.ReadInt32();
1135 markMaskParcel.mark = data.ReadInt32();
1136 markMaskParcel.mask = data.ReadInt32();
1137 int32_t result = GetFwmarkForNetwork(netId, markMaskParcel);
1138 reply.WriteInt32(result);
1139 NETNATIVE_LOG_D("GetFwmarkForNetwork has recved result %{public}d", result);
1140
1141 return result;
1142 }
1143
CmdSetInterfaceConfig(MessageParcel & data,MessageParcel & reply)1144 int32_t NetsysNativeServiceStub::CmdSetInterfaceConfig(MessageParcel &data, MessageParcel &reply)
1145 {
1146 InterfaceConfigurationParcel cfg = {};
1147 cfg.ifName = data.ReadString();
1148 cfg.hwAddr = data.ReadString();
1149 cfg.ipv4Addr = data.ReadString();
1150 cfg.prefixLength = data.ReadInt32();
1151 int32_t vSize = data.ReadInt32();
1152 vSize = (vSize > MAX_FLAG_NUM) ? MAX_FLAG_NUM : vSize;
1153 std::vector<std::string> vFlags;
1154 for (int i = 0; i < vSize; i++) {
1155 vFlags.emplace_back(data.ReadString());
1156 }
1157 cfg.flags.assign(vFlags.begin(), vFlags.end());
1158 int32_t result = SetInterfaceConfig(cfg);
1159 reply.WriteInt32(result);
1160 NETNATIVE_LOG_D("SetInterfaceConfig has recved result %{public}d", result);
1161
1162 return result;
1163 }
1164
CmdGetInterfaceConfig(MessageParcel & data,MessageParcel & reply)1165 int32_t NetsysNativeServiceStub::CmdGetInterfaceConfig(MessageParcel &data, MessageParcel &reply)
1166 {
1167 NETNATIVE_LOG_D("Begin to dispatch cmd GetInterfaceConfig");
1168 InterfaceConfigurationParcel cfg = {};
1169 cfg.ifName = data.ReadString();
1170 int32_t result = GetInterfaceConfig(cfg);
1171 reply.WriteInt32(result);
1172 reply.WriteString(cfg.ifName);
1173 reply.WriteString(cfg.hwAddr);
1174 reply.WriteString(cfg.ipv4Addr);
1175 reply.WriteInt32(cfg.prefixLength);
1176 int32_t vsize = static_cast<int32_t>(cfg.flags.size());
1177 vsize = vsize > MAX_DNS_CONFIG_SIZE ? MAX_DNS_CONFIG_SIZE : vsize;
1178 reply.WriteInt32(vsize);
1179 std::vector<std::string>::iterator iter;
1180 int32_t index = 0;
1181 for (iter = cfg.flags.begin(); iter != cfg.flags.end(); ++iter) {
1182 if (++index > MAX_DNS_CONFIG_SIZE) {
1183 break;
1184 }
1185 reply.WriteString(*iter);
1186 }
1187 return result;
1188 }
1189
CmdInterfaceGetList(MessageParcel & data,MessageParcel & reply)1190 int32_t NetsysNativeServiceStub::CmdInterfaceGetList(MessageParcel &data, MessageParcel &reply)
1191 {
1192 NETNATIVE_LOG_D("Begin to dispatch cmd InterfaceGetList");
1193 std::vector<std::string> ifaces;
1194 int32_t result = InterfaceGetList(ifaces);
1195 reply.WriteInt32(result);
1196 auto vsize = static_cast<int32_t>(ifaces.size());
1197 reply.WriteInt32(vsize);
1198 std::vector<std::string>::iterator iter;
1199 for (iter = ifaces.begin(); iter != ifaces.end(); ++iter) {
1200 reply.WriteString(*iter);
1201 }
1202 return result;
1203 }
1204
CmdStartDhcpClient(MessageParcel & data,MessageParcel & reply)1205 int32_t NetsysNativeServiceStub::CmdStartDhcpClient(MessageParcel &data, MessageParcel &reply)
1206 {
1207 NETNATIVE_LOG_D("Begin to dispatch cmd CmdStartDhcpClient");
1208 std::string iface = data.ReadString();
1209 bool bIpv6 = data.ReadBool();
1210 int32_t result = StartDhcpClient(iface, bIpv6);
1211 reply.WriteInt32(result);
1212 return result;
1213 }
1214
CmdStopDhcpClient(MessageParcel & data,MessageParcel & reply)1215 int32_t NetsysNativeServiceStub::CmdStopDhcpClient(MessageParcel &data, MessageParcel &reply)
1216 {
1217 NETNATIVE_LOG_D("Begin to dispatch cmd CmdStopDhcpClient");
1218 std::string iface = data.ReadString();
1219 bool bIpv6 = data.ReadBool();
1220 int32_t result = StopDhcpClient(iface, bIpv6);
1221 reply.WriteInt32(result);
1222 return result;
1223 }
1224
CmdStartDhcpService(MessageParcel & data,MessageParcel & reply)1225 int32_t NetsysNativeServiceStub::CmdStartDhcpService(MessageParcel &data, MessageParcel &reply)
1226 {
1227 NETNATIVE_LOG_D("Begin to dispatch cmd CmdStartDhcpService");
1228 std::string iface = data.ReadString();
1229 std::string ipv4addr = data.ReadString();
1230 int32_t result = StartDhcpService(iface, ipv4addr);
1231 reply.WriteInt32(result);
1232 return result;
1233 }
1234
CmdStopDhcpService(MessageParcel & data,MessageParcel & reply)1235 int32_t NetsysNativeServiceStub::CmdStopDhcpService(MessageParcel &data, MessageParcel &reply)
1236 {
1237 NETNATIVE_LOG_D("Begin to dispatch cmd CmdStopDhcpService");
1238 std::string iface = data.ReadString();
1239 int32_t result = StopDhcpService(iface);
1240 reply.WriteInt32(result);
1241 return result;
1242 }
1243
CmdIpEnableForwarding(MessageParcel & data,MessageParcel & reply)1244 int32_t NetsysNativeServiceStub::CmdIpEnableForwarding(MessageParcel &data, MessageParcel &reply)
1245 {
1246 NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpEnableForwarding");
1247 const auto &requester = data.ReadString();
1248 int32_t result = IpEnableForwarding(requester);
1249 reply.WriteInt32(result);
1250 return result;
1251 }
1252
CmdIpDisableForwarding(MessageParcel & data,MessageParcel & reply)1253 int32_t NetsysNativeServiceStub::CmdIpDisableForwarding(MessageParcel &data, MessageParcel &reply)
1254 {
1255 NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpDisableForwarding");
1256 const auto &requester = data.ReadString();
1257 int32_t result = IpDisableForwarding(requester);
1258 reply.WriteInt32(result);
1259 return result;
1260 }
1261
CmdEnableNat(MessageParcel & data,MessageParcel & reply)1262 int32_t NetsysNativeServiceStub::CmdEnableNat(MessageParcel &data, MessageParcel &reply)
1263 {
1264 NETNATIVE_LOG_D("Begin to dispatch cmd CmdEnableNat");
1265 const auto &downstreamIface = data.ReadString();
1266 const auto &upstreamIface = data.ReadString();
1267 int32_t result = EnableNat(downstreamIface, upstreamIface);
1268 reply.WriteInt32(result);
1269 return result;
1270 }
1271
CmdDisableNat(MessageParcel & data,MessageParcel & reply)1272 int32_t NetsysNativeServiceStub::CmdDisableNat(MessageParcel &data, MessageParcel &reply)
1273 {
1274 NETNATIVE_LOG_D("Begin to dispatch cmd CmdDisableNat");
1275 const auto &downstreamIface = data.ReadString();
1276 const auto &upstreamIface = data.ReadString();
1277 int32_t result = DisableNat(downstreamIface, upstreamIface);
1278 reply.WriteInt32(result);
1279 return result;
1280 }
1281
CmdIpfwdAddInterfaceForward(MessageParcel & data,MessageParcel & reply)1282 int32_t NetsysNativeServiceStub::CmdIpfwdAddInterfaceForward(MessageParcel &data, MessageParcel &reply)
1283 {
1284 NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpfwdAddInterfaceForward");
1285 std::string fromIface = data.ReadString();
1286 std::string toIface = data.ReadString();
1287 int32_t result = IpfwdAddInterfaceForward(fromIface, toIface);
1288 reply.WriteInt32(result);
1289 return result;
1290 }
1291
CmdIpfwdRemoveInterfaceForward(MessageParcel & data,MessageParcel & reply)1292 int32_t NetsysNativeServiceStub::CmdIpfwdRemoveInterfaceForward(MessageParcel &data, MessageParcel &reply)
1293 {
1294 NETNATIVE_LOG_D("Begin to dispatch cmd CmdIpfwdRemoveInterfaceForward");
1295 const auto &fromIface = data.ReadString();
1296 const auto &toIface = data.ReadString();
1297 int32_t result = IpfwdRemoveInterfaceForward(fromIface, toIface);
1298 reply.WriteInt32(result);
1299 return result;
1300 }
1301
CmdBandwidthEnableDataSaver(MessageParcel & data,MessageParcel & reply)1302 int32_t NetsysNativeServiceStub::CmdBandwidthEnableDataSaver(MessageParcel &data, MessageParcel &reply)
1303 {
1304 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthEnableDataSaver");
1305 bool enable = data.ReadBool();
1306 int32_t result = BandwidthEnableDataSaver(enable);
1307 reply.WriteInt32(result);
1308 return result;
1309 }
1310
CmdBandwidthSetIfaceQuota(MessageParcel & data,MessageParcel & reply)1311 int32_t NetsysNativeServiceStub::CmdBandwidthSetIfaceQuota(MessageParcel &data, MessageParcel &reply)
1312 {
1313 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthSetIfaceQuota");
1314 std::string ifName = data.ReadString();
1315 int64_t bytes = data.ReadInt64();
1316 int32_t result = BandwidthSetIfaceQuota(ifName, bytes);
1317 reply.WriteInt32(result);
1318 return result;
1319 }
1320
CmdBandwidthRemoveIfaceQuota(MessageParcel & data,MessageParcel & reply)1321 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveIfaceQuota(MessageParcel &data, MessageParcel &reply)
1322 {
1323 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveIfaceQuota");
1324 std::string ifName = data.ReadString();
1325 int32_t result = BandwidthRemoveIfaceQuota(ifName);
1326 reply.WriteInt32(result);
1327 return result;
1328 }
1329
CmdBandwidthAddDeniedList(MessageParcel & data,MessageParcel & reply)1330 int32_t NetsysNativeServiceStub::CmdBandwidthAddDeniedList(MessageParcel &data, MessageParcel &reply)
1331 {
1332 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthAddDeniedList");
1333 uint32_t uid = data.ReadUint32();
1334 int32_t result = BandwidthAddDeniedList(uid);
1335 reply.WriteInt32(result);
1336 return result;
1337 }
CmdBandwidthRemoveDeniedList(MessageParcel & data,MessageParcel & reply)1338 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveDeniedList(MessageParcel &data, MessageParcel &reply)
1339 {
1340 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveDeniedList");
1341 uint32_t uid = data.ReadUint32();
1342 int32_t result = BandwidthRemoveDeniedList(uid);
1343 reply.WriteInt32(result);
1344 return result;
1345 }
1346
CmdBandwidthAddAllowedList(MessageParcel & data,MessageParcel & reply)1347 int32_t NetsysNativeServiceStub::CmdBandwidthAddAllowedList(MessageParcel &data, MessageParcel &reply)
1348 {
1349 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthAddAllowedList");
1350 uint32_t uid = data.ReadUint32();
1351 int32_t result = BandwidthAddAllowedList(uid);
1352 reply.WriteInt32(result);
1353 return result;
1354 }
1355
CmdBandwidthRemoveAllowedList(MessageParcel & data,MessageParcel & reply)1356 int32_t NetsysNativeServiceStub::CmdBandwidthRemoveAllowedList(MessageParcel &data, MessageParcel &reply)
1357 {
1358 NETNATIVE_LOG_D("Begin to dispatch cmd CmdBandwidthRemoveAllowedList");
1359 uint32_t uid = data.ReadUint32();
1360 int32_t result = BandwidthRemoveAllowedList(uid);
1361 reply.WriteInt32(result);
1362 return result;
1363 }
1364
CmdFirewallSetUidsAllowedListChain(MessageParcel & data,MessageParcel & reply)1365 int32_t NetsysNativeServiceStub::CmdFirewallSetUidsAllowedListChain(MessageParcel &data, MessageParcel &reply)
1366 {
1367 NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidsAllowedListChain");
1368 uint32_t chain = data.ReadUint32();
1369 std::vector<uint32_t> uids;
1370 uint32_t uidSize = data.ReadUint32();
1371 uidSize = (uidSize > UIDS_LIST_MAX_SIZE) ? UIDS_LIST_MAX_SIZE : uidSize;
1372 for (uint32_t i = 0; i < uidSize; i++) {
1373 uint32_t uid = data.ReadUint32();
1374 uids.push_back(uid);
1375 }
1376 int32_t result = FirewallSetUidsAllowedListChain(chain, uids);
1377 reply.WriteInt32(result);
1378 return result;
1379 }
1380
CmdFirewallSetUidsDeniedListChain(MessageParcel & data,MessageParcel & reply)1381 int32_t NetsysNativeServiceStub::CmdFirewallSetUidsDeniedListChain(MessageParcel &data, MessageParcel &reply)
1382 {
1383 NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidsDeniedListChain");
1384 uint32_t chain = data.ReadUint32();
1385 std::vector<uint32_t> uids;
1386 uint32_t uidSize = data.ReadUint32();
1387 uidSize = (uidSize > UIDS_LIST_MAX_SIZE) ? UIDS_LIST_MAX_SIZE : uidSize;
1388 for (uint32_t i = 0; i < uidSize; i++) {
1389 uint32_t uid = data.ReadUint32();
1390 uids.push_back(uid);
1391 }
1392 int32_t result = FirewallSetUidsDeniedListChain(chain, uids);
1393 reply.WriteInt32(result);
1394 return result;
1395 }
1396
CmdFirewallEnableChain(MessageParcel & data,MessageParcel & reply)1397 int32_t NetsysNativeServiceStub::CmdFirewallEnableChain(MessageParcel &data, MessageParcel &reply)
1398 {
1399 NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallEnableChain");
1400 uint32_t chain = data.ReadUint32();
1401 bool enable = data.ReadBool();
1402 int32_t result = FirewallEnableChain(chain, enable);
1403 reply.WriteInt32(result);
1404 return result;
1405 }
1406
CmdFirewallSetUidRule(MessageParcel & data,MessageParcel & reply)1407 int32_t NetsysNativeServiceStub::CmdFirewallSetUidRule(MessageParcel &data, MessageParcel &reply)
1408 {
1409 NETNATIVE_LOG_D("Begin to dispatch cmd CmdFirewallSetUidRule");
1410 uint32_t chain = (unsigned)data.ReadUint32();
1411 std::vector<uint32_t> uids;
1412 data.ReadUInt32Vector(&uids);
1413 uint32_t firewallRule = (unsigned)data.ReadInt32();
1414 int32_t result = FirewallSetUidRule(chain, uids, firewallRule);
1415 reply.WriteInt32(result);
1416 return result;
1417 }
1418
CmdShareDnsSet(MessageParcel & data,MessageParcel & reply)1419 int32_t NetsysNativeServiceStub::CmdShareDnsSet(MessageParcel &data, MessageParcel &reply)
1420 {
1421 uint16_t netId = 0;
1422 data.ReadUint16(netId);
1423 int32_t result = ShareDnsSet(netId);
1424 reply.WriteInt32(result);
1425 NETNATIVE_LOG_D("ShareDnsSet has received result %{public}d", result);
1426
1427 return result;
1428 }
1429
CmdStartDnsProxyListen(MessageParcel & data,MessageParcel & reply)1430 int32_t NetsysNativeServiceStub::CmdStartDnsProxyListen(MessageParcel &data, MessageParcel &reply)
1431 {
1432 int32_t result = StartDnsProxyListen();
1433 reply.WriteInt32(result);
1434 NETNATIVE_LOG_D("StartDnsProxyListen has recved result %{public}d", result);
1435
1436 return result;
1437 }
1438
CmdStopDnsProxyListen(MessageParcel & data,MessageParcel & reply)1439 int32_t NetsysNativeServiceStub::CmdStopDnsProxyListen(MessageParcel &data, MessageParcel &reply)
1440 {
1441 int32_t result = StopDnsProxyListen();
1442 reply.WriteInt32(result);
1443 NETNATIVE_LOG_D("StopDnsProxyListen has recved result %{public}d", result);
1444
1445 return result;
1446 }
1447
CmdGetNetworkSharingTraffic(MessageParcel & data,MessageParcel & reply)1448 int32_t NetsysNativeServiceStub::CmdGetNetworkSharingTraffic(MessageParcel &data, MessageParcel &reply)
1449 {
1450 NETNATIVE_LOG_D("Begin to dispatch cmd GetNetworkSharingTraffic");
1451 std::string downIface = data.ReadString();
1452 std::string upIface = data.ReadString();
1453 NetworkSharingTraffic traffic;
1454 int32_t result = GetNetworkSharingTraffic(downIface, upIface, traffic);
1455 reply.WriteInt32(result);
1456 reply.WriteInt64(traffic.receive);
1457 reply.WriteInt64(traffic.send);
1458 reply.WriteInt64(traffic.all);
1459
1460 return result;
1461 }
1462
CmdGetNetworkCellularSharingTraffic(MessageParcel & data,MessageParcel & reply)1463 int32_t NetsysNativeServiceStub::CmdGetNetworkCellularSharingTraffic(MessageParcel &data, MessageParcel &reply)
1464 {
1465 NETNATIVE_LOG_D("Begin to dispatch cmd GetNetworkSharingTraffic");
1466 std::string ifaceName;
1467 NetworkSharingTraffic traffic;
1468 int32_t result = GetNetworkCellularSharingTraffic(traffic, ifaceName);
1469 reply.WriteInt32(result);
1470 reply.WriteInt64(traffic.receive);
1471 reply.WriteInt64(traffic.send);
1472 reply.WriteInt64(traffic.all);
1473 reply.WriteString(ifaceName);
1474
1475 return result;
1476 }
1477
CmdGetTotalStats(MessageParcel & data,MessageParcel & reply)1478 int32_t NetsysNativeServiceStub::CmdGetTotalStats(MessageParcel &data, MessageParcel &reply)
1479 {
1480 uint32_t type = data.ReadUint32();
1481 uint64_t stats = 0;
1482 int32_t result = GetTotalStats(stats, type);
1483 if (!reply.WriteInt32(result)) {
1484 NETNATIVE_LOGE("Write parcel failed");
1485 return ERR_FLATTEN_OBJECT;
1486 }
1487 if (!reply.WriteUint64(stats)) {
1488 NETNATIVE_LOGE("Write parcel failed");
1489 return ERR_FLATTEN_OBJECT;
1490 }
1491 return result;
1492 }
1493
CmdGetUidStats(MessageParcel & data,MessageParcel & reply)1494 int32_t NetsysNativeServiceStub::CmdGetUidStats(MessageParcel &data, MessageParcel &reply)
1495 {
1496 uint32_t type = data.ReadUint32();
1497 uint32_t uId = data.ReadUint32();
1498 uint64_t stats = 0;
1499 int32_t result = GetUidStats(stats, type, uId);
1500 if (!reply.WriteInt32(result)) {
1501 NETNATIVE_LOGE("Write parcel failed");
1502 return ERR_FLATTEN_OBJECT;
1503 }
1504 if (!reply.WriteUint64(stats)) {
1505 NETNATIVE_LOGE("Write parcel failed");
1506 return ERR_FLATTEN_OBJECT;
1507 }
1508 return result;
1509 }
1510
CmdGetIfaceStats(MessageParcel & data,MessageParcel & reply)1511 int32_t NetsysNativeServiceStub::CmdGetIfaceStats(MessageParcel &data, MessageParcel &reply)
1512 {
1513 uint32_t type = data.ReadUint32();
1514 std::string interfaceName = data.ReadString();
1515 uint64_t stats = 0;
1516 int32_t result = GetIfaceStats(stats, type, interfaceName);
1517 if (!reply.WriteInt32(result)) {
1518 NETNATIVE_LOGE("Write parcel failed");
1519 return ERR_FLATTEN_OBJECT;
1520 }
1521 if (!reply.WriteUint64(stats)) {
1522 NETNATIVE_LOGE("Write parcel failed");
1523 return ERR_FLATTEN_OBJECT;
1524 }
1525 return result;
1526 }
1527
CmdGetAllSimStatsInfo(MessageParcel & data,MessageParcel & reply)1528 int32_t NetsysNativeServiceStub::CmdGetAllSimStatsInfo(MessageParcel &data, MessageParcel &reply)
1529 {
1530 std::vector<OHOS::NetManagerStandard::NetStatsInfo> stats;
1531 int32_t result = GetAllSimStatsInfo(stats);
1532 if (!reply.WriteInt32(result)) {
1533 NETNATIVE_LOGE("Write parcel failed");
1534 return ERR_FLATTEN_OBJECT;
1535 }
1536 if (!OHOS::NetManagerStandard::NetStatsInfo::Marshalling(reply, stats)) {
1537 NETNATIVE_LOGE("Read stats info failed");
1538 return ERR_FLATTEN_OBJECT;
1539 }
1540 return result;
1541 }
1542
CmdDeleteSimStatsInfo(MessageParcel & data,MessageParcel & reply)1543 int32_t NetsysNativeServiceStub::CmdDeleteSimStatsInfo(MessageParcel &data, MessageParcel &reply)
1544 {
1545 uint32_t uid = data.ReadUint32();
1546 int32_t ret = DeleteSimStatsInfo(uid);
1547 NETNATIVE_LOG_D("DeleteSimStatsInfo uid[%{public}d] ret[%{public}d]", uid, ret);
1548 if (!reply.WriteInt32(ret)) {
1549 NETNATIVE_LOGE("Write parcel failed");
1550 return ERR_FLATTEN_OBJECT;
1551 }
1552 return NetManagerStandard::NETMANAGER_SUCCESS;
1553 }
1554
CmdGetAllStatsInfo(MessageParcel & data,MessageParcel & reply)1555 int32_t NetsysNativeServiceStub::CmdGetAllStatsInfo(MessageParcel &data, MessageParcel &reply)
1556 {
1557 std::vector<OHOS::NetManagerStandard::NetStatsInfo> stats;
1558 int32_t result = GetAllStatsInfo(stats);
1559 if (!reply.WriteInt32(result)) {
1560 NETNATIVE_LOGE("Write parcel failed");
1561 return ERR_FLATTEN_OBJECT;
1562 }
1563 if (!OHOS::NetManagerStandard::NetStatsInfo::Marshalling(reply, stats)) {
1564 NETNATIVE_LOGE("Read stats info failed");
1565 return ERR_FLATTEN_OBJECT;
1566 }
1567 return result;
1568 }
1569
CmdDeleteStatsInfo(MessageParcel & data,MessageParcel & reply)1570 int32_t NetsysNativeServiceStub::CmdDeleteStatsInfo(MessageParcel &data, MessageParcel &reply)
1571 {
1572 uint32_t uid = data.ReadUint32();
1573 int32_t ret = DeleteStatsInfo(uid);
1574 NETNATIVE_LOG_D("DeleteStatsInfo uid[%{public}d] ret[%{public}d]", uid, ret);
1575 if (!reply.WriteInt32(ret)) {
1576 NETNATIVE_LOGE("Write parcel failed");
1577 return ERR_FLATTEN_OBJECT;
1578 }
1579 return NetManagerStandard::NETMANAGER_SUCCESS;
1580 }
1581
CmdSetNetStateTrafficMap(MessageParcel & data,MessageParcel & reply)1582 int32_t NetsysNativeServiceStub::CmdSetNetStateTrafficMap(MessageParcel &data, MessageParcel &reply)
1583 {
1584 uint8_t flag = 0;
1585 uint64_t availableTraffic = 0;
1586 if (!data.ReadUint8(flag)) {
1587 return ERR_FLATTEN_OBJECT;
1588 }
1589 if (!data.ReadUint64(availableTraffic)) {
1590 return ERR_FLATTEN_OBJECT;
1591 }
1592
1593 int32_t result = SetNetStateTrafficMap(flag, availableTraffic);
1594 if (!reply.WriteInt32(result)) {
1595 NETNATIVE_LOGE("Write parcel failed");
1596 return ERR_FLATTEN_OBJECT;
1597 }
1598 return result;
1599 }
1600
CmdGetNetStateTrafficMap(MessageParcel & data,MessageParcel & reply)1601 int32_t NetsysNativeServiceStub::CmdGetNetStateTrafficMap(MessageParcel &data, MessageParcel &reply)
1602 {
1603 uint8_t flag = 0;
1604 if (!data.ReadUint8(flag)) {
1605 return ERR_FLATTEN_OBJECT;
1606 }
1607 uint64_t availableTraffic = 0;
1608 int32_t result = GetNetStateTrafficMap(flag, availableTraffic);
1609 if (!reply.WriteInt32(result)) {
1610 NETNATIVE_LOGE("Write parcel failed");
1611 return ERR_FLATTEN_OBJECT;
1612 }
1613 if (!reply.WriteUint64(availableTraffic)) {
1614 NETNATIVE_LOGE("Write parcel failed");
1615 return ERR_FLATTEN_OBJECT;
1616 }
1617 return result;
1618 }
1619
CmdClearIncreaseTrafficMap(MessageParcel & data,MessageParcel & reply)1620 int32_t NetsysNativeServiceStub::CmdClearIncreaseTrafficMap(MessageParcel &data, MessageParcel &reply)
1621 {
1622 int32_t result = ClearIncreaseTrafficMap();
1623 if (!reply.WriteInt32(result)) {
1624 NETNATIVE_LOGE("Write parcel failed");
1625 return ERR_FLATTEN_OBJECT;
1626 }
1627 return result;
1628 }
1629
CmdDeleteIncreaseTrafficMap(MessageParcel & data,MessageParcel & reply)1630 int32_t NetsysNativeServiceStub::CmdDeleteIncreaseTrafficMap(MessageParcel &data, MessageParcel &reply)
1631 {
1632 uint64_t ifIndex = 0;
1633 if (!data.ReadUint64(ifIndex)) {
1634 return ERR_FLATTEN_OBJECT;
1635 }
1636 int32_t result = DeleteIncreaseTrafficMap(ifIndex);
1637 if (!reply.WriteInt32(result)) {
1638 NETNATIVE_LOGE("Write parcel failed");
1639 return ERR_FLATTEN_OBJECT;
1640 }
1641 return result;
1642 }
1643
CmdUpdateIfIndexMap(MessageParcel & data,MessageParcel & reply)1644 int32_t NetsysNativeServiceStub::CmdUpdateIfIndexMap(MessageParcel &data, MessageParcel &reply)
1645 {
1646 int8_t key = 0;
1647 uint64_t index = 0;
1648 if (!data.ReadInt8(key)) {
1649 return ERR_FLATTEN_OBJECT;
1650 }
1651 if (!data.ReadUint64(index)) {
1652 return ERR_FLATTEN_OBJECT;
1653 }
1654 int32_t result = UpdateIfIndexMap(key, index);
1655 if (!reply.WriteInt32(result)) {
1656 NETNATIVE_LOGE("Write parcel failed");
1657 return ERR_FLATTEN_OBJECT;
1658 }
1659 return result;
1660 }
1661
CmdSetNetStatusMap(MessageParcel & data,MessageParcel & reply)1662 int32_t NetsysNativeServiceStub::CmdSetNetStatusMap(MessageParcel &data, MessageParcel &reply)
1663 {
1664 uint8_t type = 0;
1665 uint8_t value = 0;
1666 if (!data.ReadUint8(type)) {
1667 return ERR_FLATTEN_OBJECT;
1668 }
1669 if (!data.ReadUint8(value)) {
1670 return ERR_FLATTEN_OBJECT;
1671 }
1672 int32_t result = SetNetStatusMap(type, value);
1673 if (!reply.WriteInt32(result)) {
1674 NETNATIVE_LOGE("Write parcel failed");
1675 return ERR_FLATTEN_OBJECT;
1676 }
1677 return result;
1678 }
1679
CmdSetIptablesCommandForRes(MessageParcel & data,MessageParcel & reply)1680 int32_t NetsysNativeServiceStub::CmdSetIptablesCommandForRes(MessageParcel &data, MessageParcel &reply)
1681 {
1682 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
1683 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
1684 NETNATIVE_LOGE("CmdSetIptablesCommandForRes CheckNetSysInternalPermission failed");
1685 return NETMANAGER_ERR_PERMISSION_DENIED;
1686 }
1687 std::string cmd = data.ReadString();
1688 IptablesType ipType = static_cast<IptablesType>(data.ReadUint32());
1689 std::string respond;
1690 int32_t result = SetIptablesCommandForRes(cmd, respond, ipType);
1691 if (!reply.WriteInt32(result)) {
1692 NETNATIVE_LOGE("Write CmdSetIptablesCommandForRes result failed");
1693 return ERR_FLATTEN_OBJECT;
1694 }
1695 if (!reply.WriteString(respond)) {
1696 NETNATIVE_LOGE("Write CmdSetIptablesCommandForRes respond failed");
1697 return ERR_FLATTEN_OBJECT;
1698 }
1699 return NetManagerStandard::NETMANAGER_SUCCESS;
1700 }
1701
CmdSetIpCommandForRes(MessageParcel & data,MessageParcel & reply)1702 int32_t NetsysNativeServiceStub::CmdSetIpCommandForRes(MessageParcel &data, MessageParcel &reply)
1703 {
1704 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
1705 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
1706 NETNATIVE_LOGE("CmdSetIpCommandForRes CheckNetSysInternalPermission failed");
1707 return NETMANAGER_ERR_PERMISSION_DENIED;
1708 }
1709 std::string cmd = data.ReadString();
1710 std::string respond;
1711 int32_t result = SetIpCommandForRes(cmd, respond);
1712 if (!reply.WriteInt32(result)) {
1713 NETNATIVE_LOGE("Write CmdSetIpCommandForRes result failed");
1714 return ERR_FLATTEN_OBJECT;
1715 }
1716 if (!reply.WriteString(respond)) {
1717 NETNATIVE_LOGE("Write CmdSetIpCommandForRes respond failed");
1718 return ERR_FLATTEN_OBJECT;
1719 }
1720 return NetManagerStandard::NETMANAGER_SUCCESS;
1721 }
1722
CmdNetDiagPingHost(MessageParcel & data,MessageParcel & reply)1723 int32_t NetsysNativeServiceStub::CmdNetDiagPingHost(MessageParcel &data, MessageParcel &reply)
1724 {
1725 NetDiagPingOption pingOption;
1726 if (!NetDiagPingOption::Unmarshalling(data, pingOption)) {
1727 NETNATIVE_LOGE("Unmarshalling failed.");
1728 return IPC_STUB_ERR;
1729 }
1730
1731 sptr<IRemoteObject> remote = data.ReadRemoteObject();
1732 if (remote == nullptr) {
1733 NETNATIVE_LOGE("remote is nullptr.");
1734 return IPC_STUB_ERR;
1735 }
1736
1737 sptr<INetDiagCallback> callback = iface_cast<INetDiagCallback>(remote);
1738 int32_t result = NetDiagPingHost(pingOption, callback);
1739 if (!reply.WriteInt32(result)) {
1740 NETNATIVE_LOGE("Write result failed");
1741 return ERR_FLATTEN_OBJECT;
1742 }
1743 return result;
1744 }
1745
CmdNetDiagGetRouteTable(MessageParcel & data,MessageParcel & reply)1746 int32_t NetsysNativeServiceStub::CmdNetDiagGetRouteTable(MessageParcel &data, MessageParcel &reply)
1747 {
1748 std::list<NetDiagRouteTable> routeTables;
1749 int32_t result = NetDiagGetRouteTable(routeTables);
1750 if (!reply.WriteInt32(result)) {
1751 NETNATIVE_LOGE("Write result failed");
1752 return ERR_FLATTEN_OBJECT;
1753 }
1754 if (result == NetManagerStandard::NETMANAGER_SUCCESS) {
1755 if (!reply.WriteUint32(
1756 static_cast<uint32_t>(std::min(MAX_ROUTE_TABLE_SIZE, static_cast<uint32_t>(routeTables.size()))))) {
1757 NETNATIVE_LOGE("Write uint32 failed");
1758 return ERR_FLATTEN_OBJECT;
1759 }
1760 uint32_t count = 0;
1761 for (const auto &routeTable : routeTables) {
1762 if (!routeTable.Marshalling(reply)) {
1763 NETNATIVE_LOGE("NetDiagRouteTable marshalling failed");
1764 return ERR_FLATTEN_OBJECT;
1765 }
1766 ++count;
1767 if (count >= MAX_ROUTE_TABLE_SIZE) {
1768 break;
1769 }
1770 }
1771 }
1772 return result;
1773 }
1774
CmdNetDiagGetSocketsInfo(MessageParcel & data,MessageParcel & reply)1775 int32_t NetsysNativeServiceStub::CmdNetDiagGetSocketsInfo(MessageParcel &data, MessageParcel &reply)
1776 {
1777 uint8_t socketType = 0;
1778 if (!data.ReadUint8(socketType)) {
1779 NETNATIVE_LOGE("Read uint8 failed");
1780 return ERR_FLATTEN_OBJECT;
1781 }
1782 NetDiagSocketsInfo socketsInfo;
1783 int32_t result = NetDiagGetSocketsInfo(static_cast<NetDiagProtocolType>(socketType), socketsInfo);
1784 if (!reply.WriteInt32(result)) {
1785 NETNATIVE_LOGE("Write result failed");
1786 return ERR_FLATTEN_OBJECT;
1787 }
1788 if (result == NetManagerStandard::NETMANAGER_SUCCESS) {
1789 if (!socketsInfo.Marshalling(reply)) {
1790 NETNATIVE_LOGE("NetDiagSocketsInfo marshalling failed.");
1791 return ERR_FLATTEN_OBJECT;
1792 }
1793 }
1794 return result;
1795 }
1796
CmdNetDiagGetInterfaceConfig(MessageParcel & data,MessageParcel & reply)1797 int32_t NetsysNativeServiceStub::CmdNetDiagGetInterfaceConfig(MessageParcel &data, MessageParcel &reply)
1798 {
1799 std::string ifaceName;
1800 if (!data.ReadString(ifaceName)) {
1801 NETNATIVE_LOGE("Read string failed");
1802 return ERR_FLATTEN_OBJECT;
1803 }
1804 std::list<NetDiagIfaceConfig> configList;
1805 int32_t result = NetDiagGetInterfaceConfig(configList, ifaceName);
1806 if (!reply.WriteInt32(result)) {
1807 NETNATIVE_LOGE("Write result failed");
1808 return ERR_FLATTEN_OBJECT;
1809 }
1810 if (result == NetManagerStandard::NETMANAGER_SUCCESS) {
1811 if (!reply.WriteUint32(
1812 static_cast<uint32_t>(std::min(MAX_CONFIG_LIST_SIZE, static_cast<uint32_t>(configList.size()))))) {
1813 NETNATIVE_LOGE("Write uint32 failed");
1814 return ERR_FLATTEN_OBJECT;
1815 }
1816 uint32_t count = 0;
1817 for (const auto &config : configList) {
1818 if (!config.Marshalling(reply)) {
1819 NETNATIVE_LOGE("NetDiagIfaceConfig marshalling failed");
1820 return ERR_FLATTEN_OBJECT;
1821 }
1822 ++count;
1823 if (count >= MAX_CONFIG_LIST_SIZE) {
1824 break;
1825 }
1826 }
1827 }
1828 return result;
1829 }
1830
CmdNetDiagUpdateInterfaceConfig(MessageParcel & data,MessageParcel & reply)1831 int32_t NetsysNativeServiceStub::CmdNetDiagUpdateInterfaceConfig(MessageParcel &data, MessageParcel &reply)
1832 {
1833 NetDiagIfaceConfig config;
1834 if (!NetDiagIfaceConfig::Unmarshalling(data, config)) {
1835 NETNATIVE_LOGE("NetDiagIfaceConfig unmarshalling failed.");
1836 return IPC_STUB_ERR;
1837 }
1838
1839 std::string ifaceName;
1840 if (!data.ReadString(ifaceName)) {
1841 NETNATIVE_LOGE("Read string failed");
1842 return ERR_FLATTEN_OBJECT;
1843 }
1844
1845 bool add = false;
1846 if (!data.ReadBool(add)) {
1847 NETNATIVE_LOGE("Read bool failed");
1848 return ERR_FLATTEN_OBJECT;
1849 }
1850
1851 int32_t result = NetDiagUpdateInterfaceConfig(config, ifaceName, add);
1852 if (!reply.WriteInt32(result)) {
1853 NETNATIVE_LOGE("Write result failed");
1854 return ERR_FLATTEN_OBJECT;
1855 }
1856 return result;
1857 }
1858
CmdNetDiagSetInterfaceActiveState(MessageParcel & data,MessageParcel & reply)1859 int32_t NetsysNativeServiceStub::CmdNetDiagSetInterfaceActiveState(MessageParcel &data, MessageParcel &reply)
1860 {
1861 std::string ifaceName;
1862 if (!data.ReadString(ifaceName)) {
1863 NETNATIVE_LOGE("Read string failed");
1864 return ERR_FLATTEN_OBJECT;
1865 }
1866
1867 bool up = false;
1868 if (!data.ReadBool(up)) {
1869 NETNATIVE_LOGE("Read bool failed");
1870 return ERR_FLATTEN_OBJECT;
1871 }
1872
1873 int32_t result = NetDiagSetInterfaceActiveState(ifaceName, up);
1874 if (!reply.WriteInt32(result)) {
1875 NETNATIVE_LOGE("Write result failed");
1876 return ERR_FLATTEN_OBJECT;
1877 }
1878 return result;
1879 }
1880
CmdAddStaticArp(MessageParcel & data,MessageParcel & reply)1881 int32_t NetsysNativeServiceStub::CmdAddStaticArp(MessageParcel &data, MessageParcel &reply)
1882 {
1883 std::string ipAddr = "";
1884 if (!data.ReadString(ipAddr)) {
1885 NETNATIVE_LOGE("Read string failed");
1886 return ERR_FLATTEN_OBJECT;
1887 }
1888
1889 std::string macAddr = "";
1890 if (!data.ReadString(macAddr)) {
1891 NETNATIVE_LOGE("Read string failed");
1892 return ERR_FLATTEN_OBJECT;
1893 }
1894
1895 std::string ifName = "";
1896 if (!data.ReadString(ifName)) {
1897 NETNATIVE_LOGE("Read string failed");
1898 return ERR_FLATTEN_OBJECT;
1899 }
1900
1901 int32_t result = AddStaticArp(ipAddr, macAddr, ifName);
1902 if (!reply.WriteInt32(result)) {
1903 NETNATIVE_LOGE("Write result failed");
1904 return ERR_FLATTEN_OBJECT;
1905 }
1906 NETNATIVE_LOG_D("CmdAddStaticArp has recved result %{public}d", result);
1907
1908 return result;
1909 }
1910
CmdDelStaticArp(MessageParcel & data,MessageParcel & reply)1911 int32_t NetsysNativeServiceStub::CmdDelStaticArp(MessageParcel &data, MessageParcel &reply)
1912 {
1913 std::string ipAddr = "";
1914 if (!data.ReadString(ipAddr)) {
1915 NETNATIVE_LOGE("Read string failed");
1916 return ERR_FLATTEN_OBJECT;
1917 }
1918
1919 std::string macAddr = "";
1920 if (!data.ReadString(macAddr)) {
1921 NETNATIVE_LOGE("Read string failed");
1922 return ERR_FLATTEN_OBJECT;
1923 }
1924
1925 std::string ifName = "";
1926 if (!data.ReadString(ifName)) {
1927 NETNATIVE_LOGE("Read string failed");
1928 return ERR_FLATTEN_OBJECT;
1929 }
1930
1931 int32_t result = DelStaticArp(ipAddr, macAddr, ifName);
1932 if (!reply.WriteInt32(result)) {
1933 NETNATIVE_LOGE("Write result failed");
1934 return ERR_FLATTEN_OBJECT;
1935 }
1936 NETNATIVE_LOG_D("CmdDelStaticArp has recved result %{public}d", result);
1937
1938 return result;
1939 }
1940
CmdAddStaticIpv6Addr(MessageParcel & data,MessageParcel & reply)1941 int32_t NetsysNativeServiceStub::CmdAddStaticIpv6Addr(MessageParcel &data, MessageParcel &reply)
1942 {
1943 std::string ipAddr = "";
1944 if (!data.ReadString(ipAddr)) {
1945 NETNATIVE_LOGE("Read string failed");
1946 return ERR_FLATTEN_OBJECT;
1947 }
1948
1949 std::string macAddr = "";
1950 if (!data.ReadString(macAddr)) {
1951 NETNATIVE_LOGE("Read string failed");
1952 return ERR_FLATTEN_OBJECT;
1953 }
1954
1955 std::string ifName = "";
1956 if (!data.ReadString(ifName)) {
1957 NETNATIVE_LOGE("Read string failed");
1958 return ERR_FLATTEN_OBJECT;
1959 }
1960
1961 int32_t result = AddStaticIpv6Addr(ipAddr, macAddr, ifName);
1962 if (!reply.WriteInt32(result)) {
1963 NETNATIVE_LOGE("Write result failed");
1964 return ERR_FLATTEN_OBJECT;
1965 }
1966 NETNATIVE_LOG_D("CmdAddStaticIpv6Addr has recved result %{public}d", result);
1967
1968 return result;
1969 }
1970
CmdDelStaticIpv6Addr(MessageParcel & data,MessageParcel & reply)1971 int32_t NetsysNativeServiceStub::CmdDelStaticIpv6Addr(MessageParcel &data, MessageParcel &reply)
1972 {
1973 std::string ipAddr = "";
1974 if (!data.ReadString(ipAddr)) {
1975 NETNATIVE_LOGE("Read string failed");
1976 return ERR_FLATTEN_OBJECT;
1977 }
1978
1979 std::string macAddr = "";
1980 if (!data.ReadString(macAddr)) {
1981 NETNATIVE_LOGE("Read string failed");
1982 return ERR_FLATTEN_OBJECT;
1983 }
1984
1985 std::string ifName = "";
1986 if (!data.ReadString(ifName)) {
1987 NETNATIVE_LOGE("Read string failed");
1988 return ERR_FLATTEN_OBJECT;
1989 }
1990
1991 int32_t result = DelStaticIpv6Addr(ipAddr, macAddr, ifName);
1992 if (!reply.WriteInt32(result)) {
1993 NETNATIVE_LOGE("Write result failed");
1994 return ERR_FLATTEN_OBJECT;
1995 }
1996 NETNATIVE_LOG_D("CmdDelStaticIpv6Addr has recved result %{public}d", result);
1997
1998 return result;
1999 }
2000
CmdRegisterDnsResultListener(MessageParcel & data,MessageParcel & reply)2001 int32_t NetsysNativeServiceStub::CmdRegisterDnsResultListener(MessageParcel &data, MessageParcel &reply)
2002 {
2003 int32_t result = NETMANAGER_SUCCESS;
2004 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2005 if (remote == nullptr) {
2006 NETNATIVE_LOGE("Callback ptr is nullptr.");
2007 result = IPC_STUB_ERR;
2008 reply.WriteInt32(result);
2009 return result;
2010 }
2011
2012 sptr<INetDnsResultCallback> callback = iface_cast<INetDnsResultCallback>(remote);
2013 if (callback == nullptr) {
2014 result = ERR_FLATTEN_OBJECT;
2015 reply.WriteInt32(result);
2016 return result;
2017 }
2018
2019 uint32_t delay;
2020 if (!data.ReadUint32(delay)) {
2021 NETNATIVE_LOGE("Read uint32 failed");
2022 return ERR_FLATTEN_OBJECT;
2023 }
2024
2025 result = RegisterDnsResultCallback(callback, delay);
2026 reply.WriteInt32(result);
2027 return result;
2028 }
2029
CmdUnregisterDnsResultListener(MessageParcel & data,MessageParcel & reply)2030 int32_t NetsysNativeServiceStub::CmdUnregisterDnsResultListener(MessageParcel &data, MessageParcel &reply)
2031 {
2032 int32_t result = NETMANAGER_SUCCESS;
2033 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2034 if (remote == nullptr) {
2035 NETNATIVE_LOGE("Callback ptr is nullptr.");
2036 result = IPC_STUB_ERR;
2037 reply.WriteInt32(result);
2038 return result;
2039 }
2040
2041 sptr<INetDnsResultCallback> callback = iface_cast<INetDnsResultCallback>(remote);
2042 if (callback == nullptr) {
2043 result = ERR_FLATTEN_OBJECT;
2044 reply.WriteInt32(result);
2045 return result;
2046 }
2047
2048 result = UnregisterDnsResultCallback(callback);
2049 reply.WriteInt32(result);
2050 return result;
2051 }
2052
CmdRegisterDnsHealthListener(MessageParcel & data,MessageParcel & reply)2053 int32_t NetsysNativeServiceStub::CmdRegisterDnsHealthListener(MessageParcel &data, MessageParcel &reply)
2054 {
2055 int32_t result = NETMANAGER_SUCCESS;
2056 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2057 if (remote == nullptr) {
2058 NETNATIVE_LOGE("Callback ptr is nullptr.");
2059 result = IPC_STUB_ERR;
2060 reply.WriteInt32(result);
2061 return result;
2062 }
2063
2064 sptr<INetDnsHealthCallback> callback = iface_cast<INetDnsHealthCallback>(remote);
2065 if (callback == nullptr) {
2066 result = ERR_FLATTEN_OBJECT;
2067 reply.WriteInt32(result);
2068 return result;
2069 }
2070
2071 result = RegisterDnsHealthCallback(callback);
2072 reply.WriteInt32(result);
2073 return result;
2074 }
2075
CmdUnregisterDnsHealthListener(MessageParcel & data,MessageParcel & reply)2076 int32_t NetsysNativeServiceStub::CmdUnregisterDnsHealthListener(MessageParcel &data, MessageParcel &reply)
2077 {
2078 int32_t result = NETMANAGER_SUCCESS;
2079 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2080 if (remote == nullptr) {
2081 NETNATIVE_LOGE("Callback ptr is nullptr.");
2082 result = IPC_STUB_ERR;
2083 reply.WriteInt32(result);
2084 return result;
2085 }
2086
2087 sptr<INetDnsHealthCallback> callback = iface_cast<INetDnsHealthCallback>(remote);
2088 if (callback == nullptr) {
2089 result = ERR_FLATTEN_OBJECT;
2090 reply.WriteInt32(result);
2091 return result;
2092 }
2093
2094 result = UnregisterDnsHealthCallback(callback);
2095 reply.WriteInt32(result);
2096 return result;
2097 }
2098
CmdGetCookieStats(MessageParcel & data,MessageParcel & reply)2099 int32_t NetsysNativeServiceStub::CmdGetCookieStats(MessageParcel &data, MessageParcel &reply)
2100 {
2101 uint32_t type = 0;
2102 if (!data.ReadUint32(type)) {
2103 NETNATIVE_LOGE("Read uint32 failed");
2104 return ERR_FLATTEN_OBJECT;
2105 }
2106
2107 uint64_t cookie = 0;
2108 if (!data.ReadUint64(cookie)) {
2109 NETNATIVE_LOGE("Read uint64 failed");
2110 return ERR_FLATTEN_OBJECT;
2111 }
2112
2113 uint64_t stats = 0;
2114 int32_t result = GetCookieStats(stats, type, cookie);
2115 if (!reply.WriteInt32(result)) {
2116 NETNATIVE_LOGE("Write parcel failed");
2117 return ERR_FLATTEN_OBJECT;
2118 }
2119 if (!reply.WriteUint64(stats)) {
2120 NETNATIVE_LOGE("Write parcel failed");
2121 return ERR_FLATTEN_OBJECT;
2122 }
2123 return result;
2124 }
2125
CmdGetNetworkSharingType(MessageParcel & data,MessageParcel & reply)2126 int32_t NetsysNativeServiceStub::CmdGetNetworkSharingType(MessageParcel &data, MessageParcel &reply)
2127 {
2128 std::set<uint32_t> sharingTypeIsOn;
2129 int32_t ret = GetNetworkSharingType(sharingTypeIsOn);
2130 if (!reply.WriteInt32(ret)) {
2131 NETNATIVE_LOGE("Write parcel failed");
2132 return ERR_FLATTEN_OBJECT;
2133 }
2134 if (!reply.WriteUint32(sharingTypeIsOn.size())) {
2135 NETNATIVE_LOGE("Write parcel failed");
2136 return ERR_FLATTEN_OBJECT;
2137 }
2138 for (auto mem : sharingTypeIsOn) {
2139 if (!reply.WriteUint32(mem)) {
2140 NETNATIVE_LOGE("Write parcel failed");
2141 return ERR_FLATTEN_OBJECT;
2142 }
2143 }
2144
2145 return ret;
2146 }
2147
CmdUpdateNetworkSharingType(MessageParcel & data,MessageParcel & reply)2148 int32_t NetsysNativeServiceStub::CmdUpdateNetworkSharingType(MessageParcel &data, MessageParcel &reply)
2149 {
2150 uint32_t type = ERR_NONE;
2151 if (!data.ReadUint32(type)) {
2152 NETNATIVE_LOGE("Read uint32 failed");
2153 return ERR_FLATTEN_OBJECT;
2154 }
2155 if (type < ERR_NONE) {
2156 NETNATIVE_LOGE("type parameter invalid");
2157 return ERR_INVALID_DATA;
2158 }
2159
2160 bool isOpen = false;
2161 if (!data.ReadBool(isOpen)) {
2162 NETNATIVE_LOGE("Read bool failed");
2163 return ERR_FLATTEN_OBJECT;
2164 }
2165
2166 int32_t ret = UpdateNetworkSharingType(type, isOpen);
2167 if (!reply.WriteInt32(ret)) {
2168 NETNATIVE_LOGE("Write parcel failed");
2169 return ERR_FLATTEN_OBJECT;
2170 }
2171
2172 return ret;
2173 }
2174
2175 #ifdef FEATURE_NET_FIREWALL_ENABLE
CmdSetFirewallRules(MessageParcel & data,MessageParcel & reply)2176 int32_t NetsysNativeServiceStub::CmdSetFirewallRules(MessageParcel &data, MessageParcel &reply)
2177 {
2178 int32_t type = 0;
2179 if (!data.ReadInt32(type)) {
2180 NETNATIVE_LOGE("Read rule type failed");
2181 return ERR_FLATTEN_OBJECT;
2182 }
2183 NetFirewallRuleType ruleType = static_cast<NetFirewallRuleType>(type);
2184 uint32_t size = 0;
2185 if (!data.ReadUint32(size)) {
2186 NETNATIVE_LOGE("Read size failed");
2187 return ERR_FLATTEN_OBJECT;
2188 }
2189 NETNATIVE_LOGI("NetsysNativeServiceStub::CmdSetFirewallRules ruleType=%{public}d, size=%{public}d", ruleType, size);
2190 uint32_t maxSize =
2191 ruleType == NetFirewallRuleType::RULE_IP ? FIREWALL_IPC_IP_RULE_PAGE_SIZE : FIREWALL_RULE_SIZE_MAX;
2192 if (size > maxSize) {
2193 return FIREWALL_ERR_EXCEED_MAX_IP;
2194 }
2195 bool isFinish = false;
2196 if (!data.ReadBool(isFinish)) {
2197 NETNATIVE_LOGE("Read isFinish failed");
2198 return ERR_FLATTEN_OBJECT;
2199 }
2200 std::vector<sptr<NetFirewallBaseRule>> ruleList;
2201 for (uint32_t i = 0; i < size; i++) {
2202 sptr<NetFirewallBaseRule> rule = nullptr;
2203 if (ruleType == NetFirewallRuleType::RULE_IP) {
2204 rule = NetFirewallIpRule::Unmarshalling(data);
2205 } else if (ruleType == NetFirewallRuleType::RULE_DOMAIN) {
2206 rule = NetFirewallDomainRule::Unmarshalling(data);
2207 } else if (ruleType == NetFirewallRuleType::RULE_DNS) {
2208 rule = NetFirewallDnsRule::Unmarshalling(data);
2209 }
2210 if (rule != nullptr) {
2211 ruleList.emplace_back(std::move(rule));
2212 }
2213 }
2214 return SetFirewallRules(ruleType, ruleList, isFinish);
2215 }
2216
CmdSetFirewallDefaultAction(MessageParcel & data,MessageParcel & reply)2217 int32_t NetsysNativeServiceStub::CmdSetFirewallDefaultAction(MessageParcel &data, MessageParcel &reply)
2218 {
2219 NETNATIVE_LOGI("NetsysNativeServiceStub::CmdSetFirewallDefaultAction");
2220 int32_t userId = 0;
2221 if (!data.ReadInt32(userId)) {
2222 NETNATIVE_LOGE("Read userId failed");
2223 return ERR_FLATTEN_OBJECT;
2224 }
2225 int32_t inDefault = 0;
2226 if (!data.ReadInt32(inDefault)) {
2227 NETNATIVE_LOGE("Read inDefault failed");
2228 return ERR_FLATTEN_OBJECT;
2229 }
2230 int32_t outDefault = 0;
2231 if (!data.ReadInt32(outDefault)) {
2232 NETNATIVE_LOGE("Read outDefault failed");
2233 return ERR_FLATTEN_OBJECT;
2234 }
2235 return SetFirewallDefaultAction(userId, static_cast<FirewallRuleAction>(inDefault),
2236 static_cast<FirewallRuleAction>(outDefault));
2237 }
2238
CmdSetFirewallCurrentUserId(MessageParcel & data,MessageParcel & reply)2239 int32_t NetsysNativeServiceStub::CmdSetFirewallCurrentUserId(MessageParcel &data, MessageParcel &reply)
2240 {
2241 NETNATIVE_LOGI("NetsysNativeServiceStub::CmdSetFirewallCurrentUserId");
2242 int32_t userId = 0;
2243 if (!data.ReadInt32(userId)) {
2244 NETNATIVE_LOGE("Read userId failed");
2245 return ERR_FLATTEN_OBJECT;
2246 }
2247 return SetFirewallCurrentUserId(userId);
2248 }
2249
CmdClearFirewallRules(MessageParcel & data,MessageParcel & reply)2250 int32_t NetsysNativeServiceStub::CmdClearFirewallRules(MessageParcel &data, MessageParcel &reply)
2251 {
2252 NETNATIVE_LOGI("NetsysNativeServiceStub::CmdClearFirewallRules");
2253 int32_t type = 0;
2254 if (!data.ReadInt32(type)) {
2255 NETNATIVE_LOGE("Read clear type failed");
2256 return ERR_FLATTEN_OBJECT;
2257 }
2258
2259 NetFirewallRuleType clearType = static_cast<NetFirewallRuleType>(type);
2260 return ClearFirewallRules(clearType);
2261 }
2262
CmdRegisterNetFirewallCallback(MessageParcel & data,MessageParcel & reply)2263 int32_t NetsysNativeServiceStub::CmdRegisterNetFirewallCallback(MessageParcel &data, MessageParcel &reply)
2264 {
2265 int32_t result = NETMANAGER_SUCCESS;
2266 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2267 if (remote == nullptr) {
2268 NETNATIVE_LOGE("Callback ptr is nullptr.");
2269 result = IPC_STUB_ERR;
2270 return result;
2271 }
2272
2273 sptr<INetFirewallCallback> callback = iface_cast<INetFirewallCallback>(remote);
2274 if (callback == nullptr) {
2275 result = ERR_FLATTEN_OBJECT;
2276 return result;
2277 }
2278
2279 return RegisterNetFirewallCallback(callback);
2280 }
2281
CmdUnRegisterNetFirewallCallback(MessageParcel & data,MessageParcel & reply)2282 int32_t NetsysNativeServiceStub::CmdUnRegisterNetFirewallCallback(MessageParcel &data, MessageParcel &reply)
2283 {
2284 int32_t result = NETMANAGER_SUCCESS;
2285 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2286 if (remote == nullptr) {
2287 NETNATIVE_LOGE("Callback ptr is nullptr.");
2288 result = IPC_STUB_ERR;
2289 return result;
2290 }
2291
2292 sptr<INetFirewallCallback> callback = iface_cast<INetFirewallCallback>(remote);
2293 if (callback == nullptr) {
2294 result = ERR_FLATTEN_OBJECT;
2295 return result;
2296 }
2297
2298 return UnRegisterNetFirewallCallback(callback);
2299 }
2300 #endif
2301
CmdSetIpv6PrivacyExtensions(MessageParcel & data,MessageParcel & reply)2302 int32_t NetsysNativeServiceStub::CmdSetIpv6PrivacyExtensions(MessageParcel &data, MessageParcel &reply)
2303 {
2304 std::string interfaceName = data.ReadString();
2305 int32_t on = data.ReadInt32();
2306
2307 int32_t result = SetIpv6PrivacyExtensions(interfaceName, on);
2308 reply.WriteInt32(result);
2309 NETNATIVE_LOGI("SetIpv6PrivacyExtensions has recved result %{public}d", result);
2310
2311 return result;
2312 }
2313
CmdSetIpv6Enable(MessageParcel & data,MessageParcel & reply)2314 int32_t NetsysNativeServiceStub::CmdSetIpv6Enable(MessageParcel &data, MessageParcel &reply)
2315 {
2316 std::string interfaceName = data.ReadString();
2317 int32_t on = data.ReadInt32();
2318
2319 int32_t result = SetEnableIpv6(interfaceName, on);
2320 reply.WriteInt32(result);
2321 NETNATIVE_LOGI("SetIpv6Enable has recved result %{public}d", result);
2322
2323 return result;
2324 }
2325
CmdSetNetworkAccessPolicy(MessageParcel & data,MessageParcel & reply)2326 int32_t NetsysNativeServiceStub::CmdSetNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply)
2327 {
2328 uint32_t uid = 0;
2329 if (!data.ReadUint32(uid)) {
2330 NETNATIVE_LOGE("Read uint32 failed");
2331 return ERR_FLATTEN_OBJECT;
2332 }
2333 uint8_t wifi_allow = 0;
2334 if (!data.ReadUint8(wifi_allow)) {
2335 NETNATIVE_LOGE("Read uint8 failed");
2336 return ERR_FLATTEN_OBJECT;
2337 }
2338 uint8_t cellular_allow = 0;
2339 if (!data.ReadUint8(cellular_allow)) {
2340 NETNATIVE_LOGE("Read uint8 failed");
2341 return ERR_FLATTEN_OBJECT;
2342 }
2343 bool reconfirmFlag = true;
2344 if (!data.ReadBool(reconfirmFlag)) {
2345 NETNATIVE_LOGE("Read bool failed");
2346 return ERR_FLATTEN_OBJECT;
2347 }
2348
2349 NetworkAccessPolicy policy;
2350 policy.wifiAllow = wifi_allow;
2351 policy.cellularAllow = cellular_allow;
2352 int32_t result = SetNetworkAccessPolicy(uid, policy, reconfirmFlag);
2353 reply.WriteInt32(result);
2354 return result;
2355 }
2356
CmdDelNetworkAccessPolicy(MessageParcel & data,MessageParcel & reply)2357 int32_t NetsysNativeServiceStub::CmdDelNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply)
2358 {
2359 uint32_t uid = 0;
2360 if (!data.ReadUint32(uid)) {
2361 NETNATIVE_LOGE("Read uint32 failed");
2362 return ERR_FLATTEN_OBJECT;
2363 }
2364
2365 int32_t result = DeleteNetworkAccessPolicy(uid);
2366 reply.WriteInt32(result);
2367 return result;
2368 }
2369
CmdNotifyNetBearerTypeChange(MessageParcel & data,MessageParcel & reply)2370 int32_t NetsysNativeServiceStub::CmdNotifyNetBearerTypeChange(MessageParcel &data, MessageParcel &reply)
2371 {
2372 std::set<NetBearType> bearerTypes;
2373
2374 uint32_t size = 0;
2375 uint32_t value = 0;
2376 if (!data.ReadUint32(size)) {
2377 return ERR_FLATTEN_OBJECT;
2378 }
2379
2380 for (uint32_t i = 0; i < size; i++) {
2381 if (!data.ReadUint32(value)) {
2382 return ERR_FLATTEN_OBJECT;
2383 }
2384 if (value >= BEARER_DEFAULT) {
2385 return ERR_FLATTEN_OBJECT;
2386 }
2387 bearerTypes.insert(static_cast<NetBearType>(value));
2388 }
2389 int32_t result = NotifyNetBearerTypeChange(bearerTypes);
2390 reply.WriteInt32(result);
2391 return result;
2392 }
2393
CmdStartClat(MessageParcel & data,MessageParcel & reply)2394 int32_t NetsysNativeServiceStub::CmdStartClat(MessageParcel &data, MessageParcel &reply)
2395 {
2396 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2397 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2398 NETNATIVE_LOGE("CmdStartClat CheckNetSysInternalPermission failed");
2399 return NETMANAGER_ERR_PERMISSION_DENIED;
2400 }
2401
2402 std::string interfaceName;
2403 if (!data.ReadString(interfaceName)) {
2404 NETNATIVE_LOGE("Read string failed");
2405 return ERR_FLATTEN_OBJECT;
2406 }
2407
2408 int32_t netId = 0;
2409 if (!data.ReadInt32(netId)) {
2410 NETNATIVE_LOGE("Read int32 failed");
2411 return ERR_FLATTEN_OBJECT;
2412 }
2413
2414 std::string nat64PrefixStr;
2415 if (!data.ReadString(nat64PrefixStr)) {
2416 NETNATIVE_LOGE("Read string failed");
2417 return ERR_FLATTEN_OBJECT;
2418 }
2419
2420 int32_t result = StartClat(interfaceName, netId, nat64PrefixStr);
2421 if (!reply.WriteInt32(result)) {
2422 NETNATIVE_LOGE("Write result failed");
2423 return ERR_FLATTEN_OBJECT;
2424 }
2425 return result;
2426 }
2427
CmdStopClat(MessageParcel & data,MessageParcel & reply)2428 int32_t NetsysNativeServiceStub::CmdStopClat(MessageParcel &data, MessageParcel &reply)
2429 {
2430 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2431 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2432 NETNATIVE_LOGE("CmdStopClat CheckNetSysInternalPermission failed");
2433 return NETMANAGER_ERR_PERMISSION_DENIED;
2434 }
2435
2436 std::string interfaceName;
2437 if (!data.ReadString(interfaceName)) {
2438 NETNATIVE_LOGE("Read string failed");
2439 return ERR_FLATTEN_OBJECT;
2440 }
2441
2442 int32_t result = StopClat(interfaceName);
2443 if (!reply.WriteInt32(result)) {
2444 NETNATIVE_LOGE("Write result failed");
2445 return ERR_FLATTEN_OBJECT;
2446 }
2447 return result;
2448 }
2449
CmdClearFirewallAllRules(MessageParcel & data,MessageParcel & reply)2450 int32_t NetsysNativeServiceStub::CmdClearFirewallAllRules(MessageParcel &data, MessageParcel &reply)
2451 {
2452 NETNATIVE_LOG_D("Begin to dispatch cmd CmdClearFirewallAllRules");
2453 int32_t result = ClearFirewallAllRules();
2454 reply.WriteInt32(result);
2455 return result;
2456 }
2457
CmdSetNicTrafficAllowed(MessageParcel & data,MessageParcel & reply)2458 int32_t NetsysNativeServiceStub::CmdSetNicTrafficAllowed(MessageParcel &data, MessageParcel &reply)
2459 {
2460 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2461 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2462 NETNATIVE_LOGE("CmdSetNicTrafficAllowed CheckNetSysInternalPermission failed");
2463 return NETMANAGER_ERR_PERMISSION_DENIED;
2464 }
2465
2466 bool status = false;
2467 int32_t size = 0;
2468 if (!data.ReadBool(status) || !data.ReadInt32(size)) {
2469 NETNATIVE_LOGE("CmdSetNicTrafficAllowed read status or size failed");
2470 return ERR_FLATTEN_OBJECT;
2471 }
2472 if (size > static_cast<int32_t>(MAX_IFACENAMES_SIZE)) {
2473 NETNATIVE_LOGE("CmdSetNicTrafficAllowed read data size too big");
2474 return ERR_FLATTEN_OBJECT;
2475 }
2476 std::vector<std::string> ifaceNames;
2477 std::string ifaceName;
2478 for (int32_t index = 0; index < size; index++) {
2479 data.ReadString(ifaceName);
2480 if (ifaceName.empty()) {
2481 NETNATIVE_LOGE("CmdSetNicTrafficAllowed ifaceName is empty, size mismatch");
2482 return ERR_FLATTEN_OBJECT;
2483 }
2484 ifaceNames.push_back(ifaceName);
2485 }
2486 int32_t result = SetNicTrafficAllowed(ifaceNames, status);
2487 if (!reply.WriteInt32(result)) {
2488 NETNATIVE_LOGE("Write CmdSetNicTrafficAllowed result failed");
2489 return ERR_FLATTEN_OBJECT;
2490 }
2491 return NetManagerStandard::NETMANAGER_SUCCESS;
2492 }
2493
2494 #ifdef SUPPORT_SYSVPN
CmdProcessVpnStage(MessageParcel & data,MessageParcel & reply)2495 int32_t NetsysNativeServiceStub::CmdProcessVpnStage(MessageParcel &data, MessageParcel &reply)
2496 {
2497 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2498 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2499 NETNATIVE_LOGE("CmdProcessVpnStage CheckNetSysInternalPermission failed");
2500 return NETMANAGER_ERR_PERMISSION_DENIED;
2501 }
2502
2503 int32_t stage = 0;
2504 if (!data.ReadInt32(stage)) {
2505 return ERR_FLATTEN_OBJECT;
2506 }
2507
2508 std::string message;
2509 if (!data.ReadString(message)) {
2510 return ERR_FLATTEN_OBJECT;
2511 }
2512 int32_t result = ProcessVpnStage(static_cast<NetsysNative::SysVpnStageCode>(stage), message);
2513 if (!reply.WriteInt32(result)) {
2514 NETNATIVE_LOGE("Write CmdProcessVpnStage result failed");
2515 return ERR_FLATTEN_OBJECT;
2516 }
2517 return NetManagerStandard::NETMANAGER_SUCCESS;
2518 }
2519
CmdUpdateVpnRules(MessageParcel & data,MessageParcel & reply)2520 int32_t NetsysNativeServiceStub::CmdUpdateVpnRules(MessageParcel &data, MessageParcel &reply)
2521 {
2522 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2523 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2524 NETNATIVE_LOGE("CmdUpdateVpnRules CheckNetSysInternalPermission failed");
2525 return NETMANAGER_ERR_PERMISSION_DENIED;
2526 }
2527
2528 uint16_t netId = 0;
2529 if (!data.ReadUint16(netId)) {
2530 NETNATIVE_LOGE("CmdUpdateVpnRules read netId failed");
2531 return ERR_FLATTEN_OBJECT;
2532 }
2533
2534 int32_t size = 0;
2535 if (!data.ReadInt32(size)) {
2536 NETNATIVE_LOGE("CmdUpdateVpnRules read size failed");
2537 return ERR_FLATTEN_OBJECT;
2538 }
2539
2540 if (size < 0 || size > MAX_VNIC_UID_ARRAY_SIZE) {
2541 NETNATIVE_LOGE("CmdUpdateVpnRules size is invalid");
2542 return ERR_FLATTEN_OBJECT;
2543 }
2544
2545 std::vector<std::string> extMessages;
2546 std::string extMessage;
2547 for (int32_t index = 0; index < size; index++) {
2548 if (!data.ReadString(extMessage)) {
2549 return ERR_FLATTEN_OBJECT;
2550 }
2551 if (extMessage.empty()) {
2552 NETNATIVE_LOGE("CmdUpdateVpnRules extMessage is empty, size mismatch");
2553 return ERR_FLATTEN_OBJECT;
2554 }
2555 extMessages.push_back(extMessage);
2556 }
2557
2558 bool add = false;
2559 if (!data.ReadBool(add)) {
2560 NETNATIVE_LOGE("CmdUpdateVpnRules read flag failed");
2561 return ERR_FLATTEN_OBJECT;
2562 }
2563 int32_t result = UpdateVpnRules(netId, extMessages, add);
2564 if (!reply.WriteInt32(result)) {
2565 NETNATIVE_LOGE("Write CmdUpdateVpnRules result failed");
2566 return ERR_FLATTEN_OBJECT;
2567 }
2568 return NetManagerStandard::NETMANAGER_SUCCESS;
2569 }
2570 #endif // SUPPORT_SYSVPN
2571
CmdCloseSocketsUid(MessageParcel & data,MessageParcel & reply)2572 int32_t NetsysNativeServiceStub::CmdCloseSocketsUid(MessageParcel &data, MessageParcel &reply)
2573 {
2574 NETNATIVE_LOG_D("Begin to CmdCloseSocketsUid");
2575 std::string ipAddr = data.ReadString();
2576 uint32_t uid = data.ReadUint32();
2577 int32_t result = CloseSocketsUid(ipAddr, uid);
2578 reply.WriteInt32(result);
2579 return result;
2580 }
2581
CmdSetBrokerUidAccessPolicyMap(MessageParcel & data,MessageParcel & reply)2582 int32_t NetsysNativeServiceStub::CmdSetBrokerUidAccessPolicyMap(MessageParcel &data, MessageParcel &reply)
2583 {
2584 std::unordered_map<uint32_t, uint32_t> params;
2585 uint32_t count = 0;
2586 if (!data.ReadUint32(count)) {
2587 NETNATIVE_LOGE("Read count failed");
2588 return ERR_FLATTEN_OBJECT;
2589 }
2590 if (count > UINT16_MAX) {
2591 NETNATIVE_LOGE("count too big");
2592 return ERR_FLATTEN_OBJECT;
2593 }
2594 uint32_t key = 0;
2595 uint32_t value = 0;
2596 for (uint32_t i = 0; i < count; i++) {
2597 if (!data.ReadUint32(key) || !data.ReadUint32(value)) {
2598 NETNATIVE_LOGE("Read param failed.");
2599 return ERR_FLATTEN_OBJECT;
2600 }
2601 params.emplace(key, value);
2602 }
2603 int32_t result = SetBrokerUidAccessPolicyMap(params);
2604 if (!reply.WriteInt32(result)) {
2605 NETNATIVE_LOGE("Write result failed");
2606 return ERR_FLATTEN_OBJECT;
2607 }
2608 return NETSYS_SUCCESS;
2609 }
2610
CmdDelBrokerUidAccessPolicyMap(MessageParcel & data,MessageParcel & reply)2611 int32_t NetsysNativeServiceStub::CmdDelBrokerUidAccessPolicyMap(MessageParcel &data, MessageParcel &reply)
2612 {
2613 uint32_t uid = 0;
2614 if (!data.ReadUint32(uid)) {
2615 NETNATIVE_LOGE("Read uid failed");
2616 return ERR_FLATTEN_OBJECT;
2617 }
2618
2619 int32_t result = DelBrokerUidAccessPolicyMap(uid);
2620 if (!reply.WriteInt32(result)) {
2621 NETNATIVE_LOGE("Write result failed");
2622 return ERR_FLATTEN_OBJECT;
2623 }
2624 return NETSYS_SUCCESS;
2625 }
2626
CmdSetUserDefinedServerFlag(MessageParcel & data,MessageParcel & reply)2627 int32_t NetsysNativeServiceStub::CmdSetUserDefinedServerFlag(MessageParcel &data, MessageParcel &reply)
2628 {
2629 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2630 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2631 NETNATIVE_LOGE("CmdSetUserDefinedServerFlag CheckNetSysInternalPermission failed");
2632 return NETMANAGER_ERR_PERMISSION_DENIED;
2633 }
2634
2635 bool flag = false;
2636 uint16_t netId = 0;
2637 if (!data.ReadUint16(netId)) {
2638 NETNATIVE_LOGE("CmdSetUserDefinedServerFlag read netId failed");
2639 return ERR_FLATTEN_OBJECT;
2640 }
2641 if (!data.ReadBool(flag)) {
2642 NETNATIVE_LOGE("CmdSetUserDefinedServerFlag read flag failed");
2643 return ERR_FLATTEN_OBJECT;
2644 }
2645 int32_t result = SetUserDefinedServerFlag(netId, flag);
2646 if (!reply.WriteInt32(result)) {
2647 NETNATIVE_LOGE("Write CmdSetUserDefinedServerFlag result failed");
2648 return ERR_FLATTEN_OBJECT;
2649 }
2650 return NetManagerStandard::NETMANAGER_SUCCESS;
2651 }
2652
CmdFlushDnsCache(MessageParcel & data,MessageParcel & reply)2653 int32_t NetsysNativeServiceStub::CmdFlushDnsCache(MessageParcel &data, MessageParcel &reply)
2654 {
2655 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2656 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2657 NETNATIVE_LOGE("CmdFlushDnsCache CheckNetSysInternalPermission failed");
2658 return NETMANAGER_ERR_PERMISSION_DENIED;
2659 }
2660 uint16_t netId = 0;
2661 if (!data.ReadUint16(netId)) {
2662 NETNATIVE_LOGE("CmdFlushDnsCache read netId failed");
2663 return ERR_FLATTEN_OBJECT;
2664 }
2665
2666 int32_t result = FlushDnsCache(netId);
2667 if (!reply.WriteInt32(result)) {
2668 NETNATIVE_LOGE("Write CmdFlushDnsCache result failed");
2669 return ERR_FLATTEN_OBJECT;
2670 }
2671 return NetManagerStandard::NETMANAGER_SUCCESS;
2672 }
2673
CmdSetDnsCache(MessageParcel & data,MessageParcel & reply)2674 int32_t NetsysNativeServiceStub::CmdSetDnsCache(MessageParcel &data, MessageParcel &reply)
2675 {
2676 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2677 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2678 NETNATIVE_LOGE("CmdSetDnsCache CheckNetSysInternalPermission failed");
2679 return NETMANAGER_ERR_PERMISSION_DENIED;
2680 }
2681 uint16_t netId = 0;
2682 if (!data.ReadUint16(netId)) {
2683 NETNATIVE_LOGE("CmdSetDnsCache read netId failed");
2684 return ERR_FLATTEN_OBJECT;
2685 }
2686
2687 std::string hostName;
2688 if (!data.ReadString(hostName)) {
2689 NETNATIVE_LOGE("CmdSetDnsCache read hostName failed");
2690 return ERR_FLATTEN_OBJECT;
2691 }
2692
2693 AddrInfo addrInfo = {};
2694 auto p = data.ReadRawData(sizeof(AddrInfo));
2695 if (p == nullptr) {
2696 NETNATIVE_LOGE("CmdSetDnsCache read addrInfo failed");
2697 return ERR_FLATTEN_OBJECT;
2698 }
2699 if (memcpy_s(&addrInfo, sizeof(AddrInfo), p, sizeof(AddrInfo)) != EOK) {
2700 return ERR_FLATTEN_OBJECT;
2701 }
2702
2703 int32_t result = SetDnsCache(netId, hostName, addrInfo);
2704 if (!reply.WriteInt32(result)) {
2705 NETNATIVE_LOGE("Write CmdSetDnsCache result failed");
2706 return ERR_FLATTEN_OBJECT;
2707 }
2708 return NetManagerStandard::NETMANAGER_SUCCESS;
2709 }
2710
2711 #ifdef FEATURE_ENTERPRISE_ROUTE_CUSTOM
CmdUpdateEnterpriseRoute(MessageParcel & data,MessageParcel & reply)2712 int32_t NetsysNativeServiceStub::CmdUpdateEnterpriseRoute(MessageParcel &data, MessageParcel &reply)
2713 {
2714 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
2715 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
2716 NETNATIVE_LOGE("CmdUpdateEnterpriseRoute CheckNetSysInternalPermission failed");
2717 return NETMANAGER_ERR_PERMISSION_DENIED;
2718 }
2719
2720 std::string interfaceName;
2721 if (!data.ReadString(interfaceName)) {
2722 NETNATIVE_LOGE("CmdUpdateEnterpriseRoute read interfaceName failed");
2723 return ERR_FLATTEN_OBJECT;
2724 }
2725
2726 uint32_t uid = 0;
2727 if (!data.ReadUint32(uid)) {
2728 NETNATIVE_LOGE("CmdUpdateEnterpriseRoute read uid failed");
2729 return ERR_FLATTEN_OBJECT;
2730 }
2731
2732 bool add = 0;
2733 if (!data.ReadBool(add)) {
2734 NETNATIVE_LOGE("CmdUpdateEnterpriseRoute read add failed");
2735 return ERR_FLATTEN_OBJECT;
2736 }
2737
2738 int32_t result = UpdateEnterpriseRoute(interfaceName, uid, add);
2739 if (!reply.WriteInt32(result)) {
2740 NETNATIVE_LOGE("Write CmdUpdateEnterpriseRoute result failed");
2741 return ERR_FLATTEN_OBJECT;
2742 }
2743
2744 return NetManagerStandard::NETMANAGER_SUCCESS;
2745 }
2746 #endif
2747 } // namespace NetsysNative
2748 } // namespace OHOS
2749