mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2025-02-16 23:08:59 +00:00
!3299 Add a host route when the IP address and gateway are in the same network segment.
Merge pull request !3299 from yinyongbin/master
This commit is contained in:
commit
ea65fdcaf8
@ -258,6 +258,7 @@ void WifiNetAgent::CreateNetLinkInfo(sptr<NetManagerStandard::NetLinkInfo> &netL
|
||||
SetNetLinkIPInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info);
|
||||
SetNetLinkRouteInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info);
|
||||
SetNetLinkDnsInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info);
|
||||
SetNetLinkHostRouteInfo(netLinkInfo, wifiIpInfo);
|
||||
SetNetLinkLocalRouteInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info);
|
||||
if (wifiProxyConfig.configureMethod == ConfigureProxyMethod::AUTOCONFIGUE) {
|
||||
/* Automatic proxy is not supported */
|
||||
@ -375,6 +376,21 @@ void WifiNetAgent::SetNetLinkRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &ne
|
||||
}
|
||||
}
|
||||
|
||||
void WifiNetAgent::SetNetLinkHostRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo)
|
||||
{
|
||||
if ((wifiIpInfo.ipAddress & wifiIpInfo.netmask) != (wifiIpInfo.gateway & wifiIpInfo.netmask)) {
|
||||
sptr<NetManagerStandard::Route> hostRoute = (std::make_unique<NetManagerStandard::Route>()).release();
|
||||
hostRoute->iface_ = netLinkInfo->ifaceName_;
|
||||
hostRoute->destination_.type_ = NetManagerStandard::INetAddr::IPV4;
|
||||
hostRoute->destination_.address_ = IpTools::ConvertIpv4Address(wifiIpInfo.gateway);
|
||||
hostRoute->destination_.family_ = NetManagerStandard::INetAddr::IPV4;
|
||||
hostRoute->destination_.prefixlen_ = MAX_PREFIX_LEN;
|
||||
hostRoute->gateway_.address_ = "0.0.0.0";
|
||||
netLinkInfo->routeList_.push_back(*hostRoute);
|
||||
LOGI("SetNetLinkHostRouteInfo gateway:%{public}s", IpAnonymize(hostRoute->gateway_.address_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void WifiNetAgent::SetNetLinkLocalRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
|
||||
IpV6Info &wifiIpV6Info)
|
||||
{
|
||||
|
@ -207,6 +207,8 @@ private:
|
||||
void SetNetLinkRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
|
||||
IpV6Info &wifiIpV6Info);
|
||||
|
||||
void SetNetLinkHostRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo);
|
||||
|
||||
void SetNetLinkLocalRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
|
||||
IpV6Info &wifiIpV6Info);
|
||||
|
||||
|
@ -197,6 +197,15 @@ HWTEST_F(WifiNetAgentTest, SetNetLinkRouteInfoTest001, TestSize.Level1)
|
||||
EXPECT_NE(wifiNetAgent.supplierId, TEN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiNetAgentTest, SetNetLinkHostRouteInfoTest001, TestSize.Level1)
|
||||
{
|
||||
WifiNetAgent wifiNetAgent;
|
||||
sptr<NetManagerStandard::NetLinkInfo> netLinkInfo = new NetManagerStandard::NetLinkInfo();
|
||||
IpInfo wifiIpInfo;
|
||||
wifiNetAgent.SetNetLinkHostRouteInfo(netLinkInfo, wifiIpInfo);
|
||||
EXPECT_NE(wifiNetAgent.supplierId, TEN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiNetAgentTest, SetNetLinkLocalRouteInfoTest001, TestSize.Level1)
|
||||
{
|
||||
WifiNetAgent wifiNetAgent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user