NSH Library: Add a route command that will dump the content of routing table.

This commit is contained in:
Gregory Nutt 2017-08-11 15:33:26 -06:00
parent 1e23b30afe
commit 5dcf5620e3
4 changed files with 96 additions and 9 deletions

View file

@ -195,6 +195,7 @@ config NSH_DISABLE_ADDROUTE
bool "Disable addroute"
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
depends on NET_ROUTE
config NSH_DISABLE_ARP
bool "Disable arp"
@ -255,6 +256,7 @@ config NSH_DISABLE_DELROUTE
bool "Disable delroute"
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
depends on NET_ROUTE
config NSH_DISABLE_DIRNAME
bool "Disable dirname"
@ -456,6 +458,12 @@ config NSH_DISABLE_RMDIR
bool "Disable rmdir"
default n
config NSH_DISABLE_ROUTE
bool "Disable delroute"
depends on FS_PROCFS && NET_ROUTE && !FS_PROCFS_EXCLUDE_NET && !FS_PROCFS_EXCLUDE_ROUTE
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
config NSH_DISABLE_SET
bool "Disable set"
default n

View file

@ -183,6 +183,17 @@
# define CONFIG_NSH_DISABLE_GET 1
#endif
/* Route depends on routing table support and procfs support */
#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_NET) || \
defined(CONFIG_FS_PROCFS_EXCLUDE_ROUTE) || !defined(CONFIG_NET_ROUTE) || \
defined(CONFIG_NSH_DISABLE_ROUTE) || \
(!defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6))
# ifndef CONFIG_FS_PROCFS_EXCLUDE_ROUTE
# define CONFIG_FS_PROCFS_EXCLUDE_ROUTE 1
# endif
#endif
/* wget depends on web client support */
#ifndef CONFIG_NETUTILS_WEBCLIENT
@ -1187,6 +1198,9 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
# endif
# ifndef CONFIG_FS_PROCFS_EXCLUDE_ROUTE
int cmd_route(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
# if defined(CONFIG_NSH_TELNET)
# ifndef CONFIG_NSH_DISABLE_TELNETD
int cmd_telnetd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);

View file

@ -436,6 +436,16 @@ static const struct cmdmap_s g_cmdmap[] =
{ "rmmod", cmd_rmmod, 2, 2, "<module-name>" },
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_ROUTE
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
{ "route", cmd_route, 2, 2, "ipv4|ipv6" },
#elif defined(CONFIG_NET_IPv4)
{ "route", cmd_route, 1, 2, "[ipv4]" },
#elif defined(CONFIG_NET_IPv6)
{ "route", cmd_route, 1, 2, "[ipv6]" },
#endif
#endif
#ifndef CONFIG_NSH_DISABLE_SET
# if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT)
{ "set", cmd_set, 2, 4, "[{+|-}{e|x|xe|ex}] [<name> <value>]" },

View file

@ -632,18 +632,73 @@ errout:
/****************************************************************************
* Name: cmd_route
*
* nsh> route
* nsh> route <ipv4|ipv6>
*
****************************************************************************/
#if !defined(CONFIG_NSH_DISABLE_DELROUTE) && \
!defined(CONFIG_BUILD_PROTECTED) && \
!defined(CONFIG_BUILD_KERNEL)
#ifndef CONFIG_FS_PROCFS_EXCLUDE_ROUTE
int cmd_route(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
bool ipv6 = false;
#endif
/* Perhaps... someday. This would current depend on using the internal
* OS interface net_foreachroute and internal OS data structures defined
* in nuttx/net/net_route.h
*/
#endif /* !CONFIG_NSH_DISABLE_DELROUTE && !CONFIG_BUILD_PROTECTED && !CONFIG_BUILD_KERNEL */
/* If both IPv4 and IPv6 and defined then there will be exactly one
* argument. Otherwise no arguments are required, but an addition
* argument is accepted.
*/
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
if (strcmp(argv[1], "ipv4") == 0)
{
ipv6 = false;
}
else if (strcmp(argv[1], "ipv6") == 0)
{
ipv6 = true;
}
else
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#elif defined(CONFIG_NET_IPv4)
if (argc == 2 && strcmp(argv[1], "ipv4") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#else
if (argc == 2 && strcmp(argv[1], "ipv6") != 0)
{
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
return ERROR;
}
#endif
/* Then just cat the procfs file containing the routing table info */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (!ipv6)
#endif
{
return nsh_catfile(vtbl, argv[0], "/proc/net/route/ipv4");
}
#endif
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
return nsh_catfile(vtbl, argv[0], "/proc/net/route/ipv6");
}
#endif
return ERROR; /* Shouldn't get here */
}
#endif
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */