nshlib/ifconfig: Set network mask before setting gateway
Switch the order of setting network mask and gateway, re-order only, no logic change. In IPv6 cases, we may set `addr6` and prefix length together to an interface, but the gateway logic may change the value in `addr6`, and result in wrong address set to the interface. The order doesn't change behavior in network stack, so we just need to make sure the value is correct. Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
91a697a3f4
commit
fb72849089
@ -855,54 +855,6 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/* Set gateway */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
if (inet6)
|
||||
#endif
|
||||
{
|
||||
/* Only set the gateway address if it was explicitly provided. */
|
||||
|
||||
if (gwip != NULL)
|
||||
{
|
||||
ninfo("Gateway: %s\n", gwip);
|
||||
inet_pton(AF_INET6, gwip, &addr6);
|
||||
|
||||
netlib_set_dripv6addr(ifname, &addr6);
|
||||
gip6 = addr6;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (gwip != NULL)
|
||||
{
|
||||
ninfo("Gateway: %s\n", gwip);
|
||||
gip = addr.s_addr = inet_addr(gwip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gip != 0)
|
||||
{
|
||||
ninfo("Gateway: default\n");
|
||||
gip = NTOHL(gip);
|
||||
gip &= ~0x000000ff;
|
||||
gip |= 0x00000001;
|
||||
gip = HTONL(gip);
|
||||
}
|
||||
|
||||
addr.s_addr = gip;
|
||||
}
|
||||
|
||||
netlib_set_dripv4addr(ifname, &addr);
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/* Set network mask */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
@ -975,6 +927,54 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/* Set gateway */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
if (inet6)
|
||||
#endif
|
||||
{
|
||||
/* Only set the gateway address if it was explicitly provided. */
|
||||
|
||||
if (gwip != NULL)
|
||||
{
|
||||
ninfo("Gateway: %s\n", gwip);
|
||||
inet_pton(AF_INET6, gwip, &addr6);
|
||||
|
||||
netlib_set_dripv6addr(ifname, &addr6);
|
||||
gip6 = addr6;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (gwip != NULL)
|
||||
{
|
||||
ninfo("Gateway: %s\n", gwip);
|
||||
gip = addr.s_addr = inet_addr(gwip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gip != 0)
|
||||
{
|
||||
ninfo("Gateway: default\n");
|
||||
gip = NTOHL(gip);
|
||||
gip &= ~0x000000ff;
|
||||
gip |= 0x00000001;
|
||||
gip = HTONL(gip);
|
||||
}
|
||||
|
||||
addr.s_addr = gip;
|
||||
}
|
||||
|
||||
netlib_set_dripv4addr(ifname, &addr);
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
UNUSED(ifname); /* Not used in all configurations */
|
||||
|
||||
#if defined(CONFIG_NETINIT_DHCPC) || defined(CONFIG_NETINIT_DNS)
|
||||
|
Loading…
Reference in New Issue
Block a user