!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:
openharmony_ci 2024-11-09 12:14:05 +00:00 committed by Gitee
commit ea65fdcaf8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 27 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;