You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "wengzhe (via GitHub)" <gi...@apache.org> on 2023/12/06 11:05:50 UTC
[PR] nshlib/ifconfig: Generate default IPv4 gateway with netmask [nuttx-apps]
wengzhe opened a new pull request, #2220:
URL: https://github.com/apache/nuttx-apps/pull/2220
## Summary
Patches included:
- nshlib/ifconfig: Set network mask before setting gateway
- Switch the order of setting network mask and gateway, re-order only, no logic change.
- nshlib/ifconfig: Generate default IPv4 gateway with netmask
- Generate default gateway using configured netmask instead of fixed 255.255.255.0, which may be more flexible under certain situations. e.g. A subnet like 10.0.23.16/28 may not contain the .1 address.
Before:
ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 => Mask:255.255.255.0 DRaddr:10.0.23.1
After:
ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.21
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.17
ifconfig eth0 10.0.23.22 netmask 255.255.255.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0 => DRaddr:10.0.0.1
ifconfig eth0 10.0.23.22 => Mask:255.255.255.0 DRaddr:10.0.23.1
## Impact
ifconfig command
## Testing
Manually
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] nshlib/ifconfig: Generate default IPv4 gateway with netmask [nuttx-apps]
Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #2220:
URL: https://github.com/apache/nuttx-apps/pull/2220#discussion_r1417983485
##########
nshlib/nsh_netcmds.c:
##########
@@ -971,10 +924,59 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
addr.s_addr = inet_addr("255.255.255.0");
}
+ mip = addr.s_addr;
netlib_set_ipv4netmask(ifname, &addr);
}
#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 != INADDR_ANY)
+ {
+ ninfo("Gateway: default\n");
+ gip = NTOHL(gip);
Review Comment:
I think it is better to use `htonl` at app layer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] nshlib/ifconfig: Generate default IPv4 gateway with netmask [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #2220:
URL: https://github.com/apache/nuttx-apps/pull/2220
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] nshlib/ifconfig: Generate default IPv4 gateway with netmask [nuttx-apps]
Posted by "wengzhe (via GitHub)" <gi...@apache.org>.
wengzhe commented on code in PR #2220:
URL: https://github.com/apache/nuttx-apps/pull/2220#discussion_r1418235188
##########
nshlib/nsh_netcmds.c:
##########
@@ -971,10 +924,59 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
addr.s_addr = inet_addr("255.255.255.0");
}
+ mip = addr.s_addr;
netlib_set_ipv4netmask(ifname, &addr);
}
#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 != INADDR_ANY)
+ {
+ ninfo("Gateway: default\n");
+ gip = NTOHL(gip);
Review Comment:
Great, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org