• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "net_vpn_impl.h"
17 
18 #include <list>
19 
20 #include "bundle_mgr_client.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "os_account_manager.h"
24 #include "system_ability_definition.h"
25 
26 #include "net_conn_client.h"
27 #include "net_manager_constants.h"
28 #include "net_manager_ext_constants.h"
29 #include "netmanager_base_common_utils.h"
30 #include "netmgr_ext_log_wrapper.h"
31 #include "netsys_controller.h"
32 #ifdef SUPPORT_SYSVPN
33 #include "sysvpn_config.h"
34 #include "multi_vpn_helper.h"
35 #endif // SUPPORT_SYSVPN
36 
37 namespace OHOS {
38 namespace NetManagerStandard {
39 namespace {
40 constexpr int32_t INVALID_UID = -1;
41 constexpr int32_t IPV4_NET_MASK_MAX_LENGTH = 32;
42 constexpr const char *IPV4_DEFAULT_ROUTE_ADDR = "0.0.0.0";
43 constexpr const char *IPV6_DEFAULT_ROUTE_ADDR = "fe80::";
44 constexpr int32_t BITS_24 = 24;
45 constexpr int32_t BITS_16 = 16;
46 constexpr int32_t BITS_8 = 8;
47 constexpr const char *IPADDR_DELIMITER = ".";
48 } // namespace
49 
NetVpnImpl(sptr<VpnConfig> config,const std::string & pkg,int32_t userId,std::vector<int32_t> & activeUserIds)50 NetVpnImpl::NetVpnImpl(sptr<VpnConfig> config, const std::string &pkg, int32_t userId, std::vector<int32_t> &activeUserIds)
51     : vpnConfig_(config), pkgName_(pkg), userId_(userId), activeUserIds_(activeUserIds)
52 {
53     netSupplierInfo_ = new (std::nothrow) NetSupplierInfo();
54     if (netSupplierInfo_ == nullptr) {
55         NETMGR_EXT_LOG_E("NetSupplierInfo new failed");
56     }
57 #ifdef SUPPORT_SYSVPN
58     if (netSupplierInfo_ != nullptr) {
59         netSupplierInfo_->uid_ = IPCSkeleton::GetCallingUid();
60     }
61 #endif // SUPPORT_SYSVPN
62 }
63 
RegisterConnectStateChangedCb(std::shared_ptr<IVpnConnStateCb> callback)64 int32_t NetVpnImpl::RegisterConnectStateChangedCb(std::shared_ptr<IVpnConnStateCb> callback)
65 {
66     if (callback == nullptr) {
67         NETMGR_EXT_LOG_E("Register vpn connect callback is null.");
68         return NETMANAGER_EXT_ERR_INTERNAL;
69     }
70     connChangedCb_ = callback;
71     return NETMANAGER_EXT_SUCCESS;
72 }
73 
NotifyConnectState(const VpnConnectState & state)74 void NetVpnImpl::NotifyConnectState(const VpnConnectState &state)
75 {
76     if (connChangedCb_ == nullptr) {
77         NETMGR_EXT_LOG_E("NotifyConnectState connect callback is null.");
78         return;
79     }
80 #ifdef SUPPORT_SYSVPN
81     if (multiVpnInfo_ != nullptr) {
82         multiVpnInfo_->vpnConnectState = state;
83         connChangedCb_->OnMultiVpnConnStateChanged(state, multiVpnInfo_->vpnId);
84     }
85 #endif // SUPPORT_SYSVPN
86     connChangedCb_->OnVpnConnStateChanged(state);
87 }
88 
SetUp()89 int32_t NetVpnImpl::SetUp()
90 {
91     if (vpnConfig_ == nullptr) {
92         NETMGR_EXT_LOG_E("VpnConnect vpnConfig_ is nullptr");
93         return NETMANAGER_EXT_ERR_INTERNAL;
94     }
95     NETMGR_EXT_LOG_I("SetUp interface name:%{public}s", GetInterfaceName().c_str());
96     VpnEventType legacy = IsInternalVpn() ? VpnEventType::TYPE_LEGACY : VpnEventType::TYPE_EXTENDED;
97 
98     auto &netConnClientIns = NetConnClient::GetInstance();
99     if (!RegisterNetSupplier(netConnClientIns)) {
100         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_REG_NET_SUPPLIER_ERROR,
101                                                  "register Supplier failed");
102         return NETMANAGER_EXT_ERR_INTERNAL;
103     }
104 
105     if (!UpdateNetSupplierInfo(netConnClientIns, true)) {
106         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_UPDATE_SUPPLIER_INFO_ERROR,
107                                                  "update Supplier info failed");
108         return NETMANAGER_EXT_ERR_INTERNAL;
109     }
110 
111     if (!UpdateNetLinkInfo()) {
112         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_UPDATE_NETLINK_INFO_ERROR,
113                                                  "update link info failed");
114         return NETMANAGER_EXT_ERR_INTERNAL;
115     }
116 
117     std::list<int32_t> netIdList;
118     netConnClientIns.GetNetIdByIdentifier(GetInterfaceName(), netIdList);
119     if (netIdList.size() == 0) {
120         NETMGR_EXT_LOG_E("get netId failed, netId list size is 0");
121         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_INTERNAL_ERROR, "get Net id failed");
122         return NETMANAGER_EXT_ERR_INTERNAL;
123     }
124     netId_ = *(netIdList.begin());
125     NETMGR_EXT_LOG_I("vpn network netid: %{public}d", netId_);
126 
127     SetAllUidRanges();
128     if (NetsysController::GetInstance().NetworkAddUids(netId_, beginUids_, endUids_)) {
129         NETMGR_EXT_LOG_E("vpn set whitelist rule error");
130         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_SET_APP_UID_RULE_ERROR,
131                                                  "set app uid rule failed");
132         return NETMANAGER_EXT_ERR_INTERNAL;
133     }
134 #ifdef SUPPORT_SYSVPN
135     ProcessUpRules(true);
136     if (!IsSystemVpn()) {
137         NotifyConnectState(VpnConnectState::VPN_CONNECTED);
138     }
139 #else
140     NotifyConnectState(VpnConnectState::VPN_CONNECTED);
141 #endif
142     isVpnConnecting_ = true;
143     return NETMANAGER_EXT_SUCCESS;
144 }
145 
SetAllUidRanges()146 void NetVpnImpl::SetAllUidRanges()
147 {
148     if (userId_ != 0) {
149         GenerateUidRanges(userId_, beginUids_, endUids_);
150     }
151     for (auto &elem : activeUserIds_) {
152         GenerateUidRanges(elem, beginUids_, endUids_);
153     }
154 #ifdef ENABLE_VPN_FOR_USER0
155     GenerateUidRanges(0, beginUids_, endUids_);
156 #endif
157 }
158 
ResumeUids()159 int32_t NetVpnImpl::ResumeUids()
160 {
161     if (!isVpnConnecting_) {
162         NETMGR_EXT_LOG_I("unecessary to resume uids");
163         return NETMANAGER_EXT_ERR_INTERNAL;
164     }
165 
166     if (NetsysController::GetInstance().NetworkAddUids(netId_, beginUids_, endUids_)) {
167         NETMGR_EXT_LOG_E("vpn set whitelist rule error");
168         VpnEventType legacy = IsInternalVpn() ? VpnEventType::TYPE_LEGACY : VpnEventType::TYPE_EXTENDED;
169         VpnHisysEvent::SendFaultEventConnSetting(legacy, VpnEventErrorType::ERROR_SET_APP_UID_RULE_ERROR,
170             "set app uid rule failed");
171         return NETMANAGER_EXT_ERR_INTERNAL;
172     }
173 
174     return NETMANAGER_EXT_SUCCESS;
175 }
176 
Destroy()177 int32_t NetVpnImpl::Destroy()
178 {
179 #ifdef SUPPORT_SYSVPN
180     ProcessUpRules(false);
181 #endif // SUPPORT_SYSVPN
182     VpnEventType legacy = IsInternalVpn() ? VpnEventType::TYPE_LEGACY : VpnEventType::TYPE_EXTENDED;
183     if (NetsysController::GetInstance().NetworkDelUids(netId_, beginUids_, endUids_)) {
184         NETMGR_EXT_LOG_W("vpn remove whitelist rule error");
185         VpnHisysEvent::SendFaultEventConnDestroy(legacy, VpnEventErrorType::ERROR_SET_APP_UID_RULE_ERROR,
186                                                  "remove app uid rule failed");
187     }
188 
189     auto &netConnClientIns = NetConnClient::GetInstance();
190     DelNetLinkInfo(netConnClientIns);
191     UpdateNetSupplierInfo(netConnClientIns, false);
192     UnregisterNetSupplier(netConnClientIns);
193 #ifdef SUPPORT_SYSVPN
194     if (!IsSystemVpn()) {
195         NotifyConnectState(VpnConnectState::VPN_DISCONNECTED);
196     }
197 #else
198     NotifyConnectState(VpnConnectState::VPN_DISCONNECTED);
199 #endif
200     isVpnConnecting_ = false;
201     return NETMANAGER_EXT_SUCCESS;
202 }
203 
204 #ifdef SUPPORT_SYSVPN
GetVpnCertData(const int32_t certType,std::vector<int8_t> & certData)205 int32_t NetVpnImpl::GetVpnCertData(const int32_t certType, std::vector<int8_t> &certData)
206 {
207     return NETMANAGER_EXT_SUCCESS;
208 }
209 
GetConnectedSysVpnConfig(sptr<SysVpnConfig> & vpnConfig)210 int32_t NetVpnImpl::GetConnectedSysVpnConfig(sptr<SysVpnConfig> &vpnConfig)
211 {
212     return NETMANAGER_EXT_SUCCESS;
213 }
214 
NotifyConnectStage(const std::string & stage,const int32_t & result)215 int32_t NetVpnImpl::NotifyConnectStage(const std::string &stage, const int32_t &result)
216 {
217     return NETMANAGER_EXT_SUCCESS;
218 }
219 
GetSysVpnCertUri(const int32_t certType,std::string & certUri)220 int32_t NetVpnImpl::GetSysVpnCertUri(const int32_t certType, std::string &certUri)
221 {
222     return NETMANAGER_EXT_SUCCESS;
223 }
224 
IsSystemVpn()225 bool NetVpnImpl::IsSystemVpn()
226 {
227     return false;
228 }
229 
ProcessUpRules(bool isUp)230 void NetVpnImpl::ProcessUpRules(bool isUp)
231 {
232     if (vpnConfig_ != nullptr && !vpnConfig_->addresses_.empty()) {
233         std::vector<std::string> extMessages;
234         if (multiVpnInfo_ != nullptr && multiVpnInfo_->isVpnExtCall) {
235             INetAddr netAddr = vpnConfig_->addresses_.back();
236             extMessages.emplace_back(netAddr.address_);
237         } else {
238             INetAddr netAddr = vpnConfig_->addresses_.front();
239             extMessages.emplace_back(netAddr.address_);
240         }
241         NetsysController::GetInstance().UpdateVpnRules(netId_, extMessages, isUp);
242     }
243 }
244 #endif // SUPPORT_SYSVPN
245 
RegisterNetSupplier(NetConnClient & netConnClientIns)246 bool NetVpnImpl::RegisterNetSupplier(NetConnClient &netConnClientIns)
247 {
248     if (netSupplierId_) {
249         NETMGR_EXT_LOG_E("NetSupplier [%{public}d] has been registered ", netSupplierId_);
250         return false;
251     }
252     std::set<NetCap> netCap;
253     netCap.insert(NET_CAPABILITY_INTERNET);
254     if (vpnConfig_->isMetered_ == false) {
255         netCap.insert(NET_CAPABILITY_NOT_METERED);
256     }
257     if (netConnClientIns.RegisterNetSupplier(BEARER_VPN, GetInterfaceName(), netCap,
258         netSupplierId_) != NETMANAGER_SUCCESS) {
259         NETMGR_EXT_LOG_E("vpn netManager RegisterNetSupplier error.");
260         return false;
261     }
262     NETMGR_EXT_LOG_I("vpn RegisterNetSupplier netSupplierId_[%{public}d]", netSupplierId_);
263     return true;
264 }
265 
UnregisterNetSupplier(NetConnClient & netConnClientIns)266 void NetVpnImpl::UnregisterNetSupplier(NetConnClient &netConnClientIns)
267 {
268     if (!netSupplierId_) {
269         NETMGR_EXT_LOG_E("NetSupplier [%{public}d] has been unregistered ", netSupplierId_);
270         return;
271     }
272     if (!netConnClientIns.UnregisterNetSupplier(netSupplierId_)) {
273         netSupplierId_ = 0;
274     }
275 }
276 
UpdateNetSupplierInfo(NetConnClient & netConnClientIns,bool isAvailable)277 bool NetVpnImpl::UpdateNetSupplierInfo(NetConnClient &netConnClientIns, bool isAvailable)
278 {
279     if (!netSupplierId_) {
280         NETMGR_EXT_LOG_E("vpn UpdateNetSupplierInfo error, netSupplierId is zero");
281         return false;
282     }
283     if (netSupplierInfo_ == nullptr) {
284         NETMGR_EXT_LOG_E("vpn UpdateNetSupplierInfo netSupplierInfo_ is nullptr");
285         return false;
286     }
287     netSupplierInfo_->isAvailable_ = isAvailable;
288     netConnClientIns.UpdateNetSupplierInfo(netSupplierId_, netSupplierInfo_);
289     return true;
290 }
291 
UpdateNetLinkInfo()292 bool NetVpnImpl::UpdateNetLinkInfo()
293 {
294     if (vpnConfig_ == nullptr) {
295         NETMGR_EXT_LOG_E("vpnConfig_ is nullptr");
296         return false;
297     }
298     sptr<NetLinkInfo> linkInfo = new (std::nothrow) NetLinkInfo();
299     if (linkInfo == nullptr) {
300         NETMGR_EXT_LOG_E("linkInfo is nullptr");
301         return false;
302     }
303     linkInfo->ifaceName_ = GetInterfaceName();
304     linkInfo->netAddrList_.assign(vpnConfig_->addresses_.begin(), vpnConfig_->addresses_.end());
305 
306     if (vpnConfig_->routes_.empty()) {
307         if (vpnConfig_->isAcceptIPv4_ == true) {
308             Route ipv4DefaultRoute;
309             SetIpv4DefaultRoute(ipv4DefaultRoute);
310             linkInfo->routeList_.emplace_back(ipv4DefaultRoute);
311         }
312         if (vpnConfig_->isAcceptIPv6_== true) {
313             Route ipv6DefaultRoute;
314             SetIpv6DefaultRoute(ipv6DefaultRoute);
315             linkInfo->routeList_.emplace_back(ipv6DefaultRoute);
316         }
317     } else {
318         linkInfo->routeList_.assign(vpnConfig_->routes_.begin(), vpnConfig_->routes_.end());
319         for (auto &route : linkInfo->routeList_) {
320             AdjustRouteInfo(route);
321         }
322     }
323 
324     for (auto dnsServer : vpnConfig_->dnsAddresses_) {
325         INetAddr dns;
326         if (vpnConfig_->isAcceptIPv4_ == true) {
327             dns.type_ = INetAddr::IpType::IPV4;
328             dns.family_ = INetAddr::IpType::IPV4;
329         } else {
330             dns.type_ = INetAddr::IpType::IPV6;
331             dns.family_ = INetAddr::IpType::IPV6;
332         }
333         dns.address_ = dnsServer;
334         linkInfo->dnsList_.emplace_back(dns);
335         linkInfo->isUserDefinedDnsServer_ = true;
336     }
337 
338     for (auto domain : vpnConfig_->searchDomains_) {
339         linkInfo->domain_.append(domain).append(" ");
340     }
341     linkInfo->mtu_ = vpnConfig_->mtu_;
342     NetConnClient::GetInstance().UpdateNetLinkInfo(netSupplierId_, linkInfo);
343     return true;
344 }
345 
SetIpv4DefaultRoute(Route & ipv4DefaultRoute)346 void NetVpnImpl::SetIpv4DefaultRoute(Route &ipv4DefaultRoute)
347 {
348     ipv4DefaultRoute.iface_ = GetInterfaceName();
349     ipv4DefaultRoute.destination_.type_ = INetAddr::IPV4;
350     ipv4DefaultRoute.destination_.address_ = IPV4_DEFAULT_ROUTE_ADDR;
351     ipv4DefaultRoute.destination_.prefixlen_ = CommonUtils::GetMaskLength(IPV4_DEFAULT_ROUTE_ADDR);
352     ipv4DefaultRoute.gateway_.address_ = IPV4_DEFAULT_ROUTE_ADDR;
353 }
354 
SetIpv6DefaultRoute(Route & ipv6DefaultRoute)355 void NetVpnImpl::SetIpv6DefaultRoute(Route &ipv6DefaultRoute)
356 {
357     ipv6DefaultRoute.iface_ = GetInterfaceName();
358     ipv6DefaultRoute.destination_.type_ = INetAddr::IPV6;
359     ipv6DefaultRoute.destination_.address_ = IPV6_DEFAULT_ROUTE_ADDR;
360     ipv6DefaultRoute.destination_.prefixlen_ = CommonUtils::Ipv6PrefixLen(IPV6_DEFAULT_ROUTE_ADDR);
361     ipv6DefaultRoute.gateway_.address_ = IPV6_DEFAULT_ROUTE_ADDR;
362 }
363 
DelNetLinkInfo(NetConnClient & netConnClientIns)364 void NetVpnImpl::DelNetLinkInfo(NetConnClient &netConnClientIns)
365 {
366     for (auto &route : vpnConfig_->routes_) {
367         AdjustRouteInfo(route);
368         std::string destAddress = route.destination_.address_ + "/" + std::to_string(route.destination_.prefixlen_);
369         NetsysController::GetInstance().NetworkRemoveRoute(netId_, route.iface_, destAddress, route.gateway_.address_);
370     }
371 }
372 
AdjustRouteInfo(Route & route)373 void NetVpnImpl::AdjustRouteInfo(Route &route)
374 {
375     if (route.iface_.empty()) {
376         route.iface_ = GetInterfaceName();
377     }
378     if (vpnConfig_->isAcceptIPv6_ == true && route.destination_.family_ == INetAddr::IpType::IPV6) {
379         route.destination_.address_ = CommonUtils::GetIpv6Prefix(route.destination_.address_,
380             route.destination_.prefixlen_);
381     } else {
382         uint32_t maskUint = (0xFFFFFFFF << (IPV4_NET_MASK_MAX_LENGTH - route.destination_.prefixlen_));
383         uint32_t ipAddrUint = CommonUtils::ConvertIpv4Address(route.destination_.address_);
384         uint32_t subNetAddress = ipAddrUint & maskUint;
385         route.destination_.address_ = ConvertVpnIpv4Address(subNetAddress);
386     }
387 }
388 
GenerateUidRangesByAcceptedApps(const std::set<int32_t> & uids,std::vector<int32_t> & beginUids,std::vector<int32_t> & endUids)389 void NetVpnImpl::GenerateUidRangesByAcceptedApps(const std::set<int32_t> &uids, std::vector<int32_t> &beginUids,
390                                                  std::vector<int32_t> &endUids)
391 {
392     int32_t start = INVALID_UID;
393     int32_t stop = INVALID_UID;
394     for (int32_t uid : uids) {
395         if (start == INVALID_UID) {
396             start = uid;
397         } else if (uid != stop + 1) {
398             beginUids.push_back(start);
399             endUids.push_back(stop);
400             start = uid;
401         }
402         stop = uid;
403     }
404     if (start != INVALID_UID) {
405         beginUids.push_back(start);
406         endUids.push_back(stop);
407     }
408 }
409 
GenerateUidRangesByRefusedApps(int32_t userId,const std::set<int32_t> & uids,std::vector<int32_t> & beginUids,std::vector<int32_t> & endUids)410 void NetVpnImpl::GenerateUidRangesByRefusedApps(int32_t userId, const std::set<int32_t> &uids, std::vector<int32_t> &beginUids,
411                                                 std::vector<int32_t> &endUids)
412 {
413     int32_t start = userId * AppExecFwk::Constants::BASE_USER_RANGE;
414     int32_t stop = userId * AppExecFwk::Constants::BASE_USER_RANGE + AppExecFwk::Constants::MAX_APP_UID;
415     for (int32_t uid : uids) {
416         if (uid == start) {
417             start++;
418         } else {
419             beginUids.push_back(start);
420             endUids.push_back(uid - 1);
421             start = uid + 1;
422         }
423     }
424     if (start <= stop) {
425         beginUids.push_back(start);
426         endUids.push_back(stop);
427     }
428 }
429 
GetAppsUids(int32_t userId,const std::vector<std::string> & applications)430 std::set<int32_t> NetVpnImpl::GetAppsUids(int32_t userId, const std::vector<std::string> &applications)
431 {
432     std::set<int32_t> uids;
433     auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
434     if (systemAbilityManager == nullptr) {
435         NETMGR_EXT_LOG_E("systemAbilityManager is null.");
436         return uids;
437     }
438     auto bundleMgrSa = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
439     if (bundleMgrSa == nullptr) {
440         NETMGR_EXT_LOG_E("bundleMgrSa is null.");
441         return uids;
442     }
443     auto bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(bundleMgrSa);
444     if (bundleMgr == nullptr) {
445         NETMGR_EXT_LOG_E("iface_cast is null.");
446         return uids;
447     }
448 
449     NETMGR_EXT_LOG_I("userId: %{public}d.", userId);
450     AppExecFwk::ApplicationFlag flags = AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO;
451     for (auto app : applications) {
452         AppExecFwk::ApplicationInfo appInfo;
453         if (bundleMgr->GetApplicationInfo(app, flags, userId, appInfo)) {
454             NETMGR_EXT_LOG_I("app: %{public}s success, uid=%{public}d.", app.c_str(), appInfo.uid);
455             uids.insert(appInfo.uid);
456         } else {
457             NETMGR_EXT_LOG_E("app: %{public}s error.", app.c_str());
458         }
459     }
460     NETMGR_EXT_LOG_I("uids.size: %{public}zd.", uids.size());
461     return uids;
462 }
463 
GenerateUidRanges(int32_t userId,std::vector<int32_t> & beginUids,std::vector<int32_t> & endUids)464 int32_t NetVpnImpl::GenerateUidRanges(int32_t userId, std::vector<int32_t> &beginUids, std::vector<int32_t> &endUids)
465 {
466     NETMGR_EXT_LOG_I("GenerateUidRanges userId:%{public}d.", userId);
467     if (userId == AppExecFwk::Constants::INVALID_USERID) {
468         userId = AppExecFwk::Constants::START_USERID;
469     }
470 #ifdef SUPPORT_SYSVPN
471     if (multiVpnInfo_ != nullptr && multiVpnInfo_->isVpnExtCall) {
472         if (vpnConfig_->acceptedApplications_.size() == 0) {
473             NETMGR_EXT_LOG_W("GenerateUidRangesMark is vpn ext call, but not accept uid ranges");
474             return NETMANAGER_EXT_SUCCESS;
475         }
476     }
477 #endif // SUPPORT_SYSVPN
478     if (vpnConfig_->acceptedApplications_.size()) {
479         std::set<int32_t> uids = GetAppsUids(userId, vpnConfig_->acceptedApplications_);
480         GenerateUidRangesByAcceptedApps(uids, beginUids, endUids);
481     } else if (vpnConfig_->refusedApplications_.size()) {
482         std::set<int32_t> uids = GetAppsUids(userId, vpnConfig_->refusedApplications_);
483         GenerateUidRangesByRefusedApps(userId, uids, beginUids, endUids);
484     } else {
485         int32_t start = userId * AppExecFwk::Constants::BASE_USER_RANGE;
486         int32_t stop = userId * AppExecFwk::Constants::BASE_USER_RANGE + AppExecFwk::Constants::MAX_APP_UID;
487         beginUids.push_back(start);
488         endUids.push_back(stop);
489         NETMGR_EXT_LOG_I("GenerateUidRanges default all app, uid range: %{public}d -- %{public}d.", start, stop);
490     }
491     return NETMANAGER_EXT_SUCCESS;
492 }
493 
ConvertVpnIpv4Address(uint32_t addressIpv4)494 std::string NetVpnImpl::ConvertVpnIpv4Address(uint32_t addressIpv4)
495 {
496     std::ostringstream stream;
497     stream << ((addressIpv4 >> BITS_24) & 0xFF) << IPADDR_DELIMITER << ((addressIpv4 >> BITS_16) & 0xFF)
498            << IPADDR_DELIMITER << ((addressIpv4 >> BITS_8) & 0xFF) << IPADDR_DELIMITER << (addressIpv4 & 0xFF);
499     return stream.str();
500 }
501 
502 } // namespace NetManagerStandard
503 } // namespace OHOS
504