nshlib/: ifconfig now uses /proc/net/eth0 to display network configuration. You will need to enable the procfs file system in order to use ifconfig
This commit is contained in:
parent
6c6df5e4ed
commit
bb88ff9b12
@ -1466,8 +1466,8 @@
|
|||||||
calls (2015-11-25).
|
calls (2015-11-25).
|
||||||
* apps/nshlib: If CONFIG_NETDEV_STATISTICS=y, then print the network
|
* apps/nshlib: If CONFIG_NETDEV_STATISTICS=y, then print the network
|
||||||
driver statistics in the ifconfig (15-11-26).
|
driver statistics in the ifconfig (15-11-26).
|
||||||
* apps/nshlib: The 'ifconfig' command now uses /proc/net/stat to
|
* apps/nshlib: The 'ifconfig' command now uses /proc/net/<dev> to view
|
||||||
show network statistics. A consequence of this is that you cannot
|
and network device configuration/status and /proc/net/stat to show
|
||||||
view network statistics if the procfs is not enabled and mounted
|
network statistics. A consequence of this is that you cannot view
|
||||||
at /proc (2015-11-27).
|
this network information if the procfs is not enabled and mounted at
|
||||||
|
/proc (2015-11-27).
|
||||||
|
15
nshlib/nsh.h
15
nshlib/nsh.h
@ -601,16 +601,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
|
#if defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
|
||||||
# undef CONFIG_NSH_DISABLE_PS /* 'ps' depends on sched_foreach */
|
# undef CONFIG_NSH_DISABLE_PS /* 'ps' depends on sched_foreach */
|
||||||
# define CONFIG_NSH_DISABLE_PS 1
|
# define CONFIG_NSH_DISABLE_PS 1
|
||||||
# undef CONFIG_NSH_DISABLE_DF /* 'df' depends on foreach_mountpoint */
|
# undef CONFIG_NSH_DISABLE_DF /* 'df' depends on foreach_mountpoint */
|
||||||
# define CONFIG_NSH_DISABLE_DF 1
|
# define CONFIG_NSH_DISABLE_DF 1
|
||||||
# undef CONFIG_NSH_DISABLE_MKFATFS /* 'mkfatfs' depends on mkfatfs interface */
|
# undef CONFIG_NSH_DISABLE_MKFATFS /* 'mkfatfs' depends on mkfatfs interface */
|
||||||
# define CONFIG_NSH_DISABLE_MKFATFS 1
|
# define CONFIG_NSH_DISABLE_MKFATFS 1
|
||||||
# undef CONFIG_NSH_DISABLE_MKRD /* 'mkrd' depends on ramdisk_register */
|
# undef CONFIG_NSH_DISABLE_MKRD /* 'mkrd' depends on ramdisk_register */
|
||||||
# define CONFIG_NSH_DISABLE_MKRD 1
|
# define CONFIG_NSH_DISABLE_MKRD 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Certain commands are only available if the procfs file system is enable */
|
||||||
|
|
||||||
|
#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
|
||||||
|
# undef CONFIG_NSH_DISABLE_IFCONFIG /* 'ifconfig' depends on network procfs */
|
||||||
|
# define CONFIG_NSH_DISABLE_IFCONFIG 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -285,88 +285,6 @@ static inline void net_statistics(FAR struct nsh_vtbl_s *vtbl)
|
|||||||
# define net_statistics(vtbl)
|
# define net_statistics(vtbl)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: net_statistics
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if defined(CONFIG_NETDEV_STATISTICS) && !defined(CONFIG_NSH_DISABLE_IFCONFIG)
|
|
||||||
static inline void netdev_statistics(FAR struct nsh_vtbl_s *vtbl,
|
|
||||||
FAR struct net_driver_s *dev)
|
|
||||||
{
|
|
||||||
FAR struct netdev_statistics_s *stats = &dev->d_statistics;
|
|
||||||
FAR char *fmt;
|
|
||||||
|
|
||||||
/* Rx Statistics */
|
|
||||||
|
|
||||||
nsh_output(vtbl, "\tRX: %-8s %-8s %-8s\n",
|
|
||||||
"Received", "Fragment", "Errors");
|
|
||||||
nsh_output(vtbl, "\t %08lx %08lx %08lx\n",
|
|
||||||
(unsigned long)stats->rx_packets,
|
|
||||||
(unsigned long)stats->rx_fragments,
|
|
||||||
(unsigned long)stats->rx_errors);
|
|
||||||
|
|
||||||
fmt = "\t "
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
"%-8s "
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
"%-8s "
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ARP
|
|
||||||
"%-8s "
|
|
||||||
#endif
|
|
||||||
"%-8s\n";
|
|
||||||
|
|
||||||
nsh_output(vtbl, fmt
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
, "IPv4"
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
, "IPv6"
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ARP
|
|
||||||
, "ARP"
|
|
||||||
#endif
|
|
||||||
, "Dropped");
|
|
||||||
|
|
||||||
fmt = "\t "
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
"%08lx "
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
"%08lx "
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ARP
|
|
||||||
"%08lx "
|
|
||||||
#endif
|
|
||||||
"%08lx\n";
|
|
||||||
|
|
||||||
nsh_output(vtbl, fmt
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
, (unsigned long)stats->rx_ipv4
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
, (unsigned long)stats->rx_ipv6
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ARP
|
|
||||||
, (unsigned long)stats->rx_arp
|
|
||||||
#endif
|
|
||||||
, (unsigned long)stats->rx_dropped);
|
|
||||||
|
|
||||||
nsh_output(vtbl, "\tTX: %-8s %-8s %-8s %-8s\n",
|
|
||||||
"Queued", "Sent", "Erorts", "Timeouts");
|
|
||||||
nsh_output(vtbl, "\t %08lx %08lx %08lx %08lx\n",
|
|
||||||
(unsigned long)stats->tx_packets,
|
|
||||||
(unsigned long)stats->tx_done,
|
|
||||||
(unsigned long)stats->tx_errors,
|
|
||||||
(unsigned long)stats->tx_timeouts);
|
|
||||||
nsh_output(vtbl, "\tTotal Errors: %08x\n\n",
|
|
||||||
(unsigned long)stats->errors);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define netdev_statistics(vtbl,dev)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ifconfig_callback
|
* Name: ifconfig_callback
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -374,153 +292,16 @@ static inline void netdev_statistics(FAR struct nsh_vtbl_s *vtbl,
|
|||||||
#if !defined(CONFIG_NSH_DISABLE_IFUPDOWN) || !defined(CONFIG_NSH_DISABLE_IFCONFIG)
|
#if !defined(CONFIG_NSH_DISABLE_IFUPDOWN) || !defined(CONFIG_NSH_DISABLE_IFCONFIG)
|
||||||
static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
|
static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
|
||||||
{
|
{
|
||||||
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
|
FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
|
||||||
#ifdef CONFIG_NET_IPv4
|
char buffer[IFNAMSIZ + 12];
|
||||||
struct in_addr addr;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
|
||||||
uint8_t preflen;
|
|
||||||
#endif
|
|
||||||
uint8_t iff;
|
|
||||||
const char *status;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Get the interface status: RUNNING, UP, or DOWN */
|
DEBUGASSERT(dev != NULL && vtbl != NULL);
|
||||||
|
|
||||||
ret = netlib_getifstatus(dev->d_ifname, &iff);
|
/* Construct the full path to the /proc/net entry for this device */
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, "\tGet %s interface flags error: %d\n",
|
|
||||||
dev->d_ifname, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iff & IFF_RUNNING)
|
snprintf(buffer, IFNAMSIZ + 12, "/proc/net/%s", dev->d_ifname);
|
||||||
{
|
(void)nsh_catfile(vtbl, "ifconfig", buffer);
|
||||||
status = "RUNNING";
|
|
||||||
}
|
|
||||||
else if (iff & IFF_UP)
|
|
||||||
{
|
|
||||||
status = "UP";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = "DOWN";
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_MULTILINK)
|
|
||||||
/* If there are multiple link types being supported, then selected the
|
|
||||||
* output appropriate for the link type associated with this device.
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch (dev->d_lltype)
|
|
||||||
{
|
|
||||||
# if defined(CONFIG_NET_ETHERNET)
|
|
||||||
case NET_LL_ETHERNET:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:Ethernet HWaddr %s",
|
|
||||||
dev->d_ifname, ether_ntoa(&dev->d_mac));
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(CONFIG_NET_LOOPBACK)
|
|
||||||
case NET_LL_LOOPBACK:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:Local Loopback", dev->d_ifname);
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(CONFIG_NET_SLIP)
|
|
||||||
case NET_LL_SLIP:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:SLIP", dev->d_ifname);
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(CONFIG_NET_PPP)
|
|
||||||
case NET_LL_PPP:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:P-t-P", dev->d_ifname);
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(CONFIG_NET_TUN)
|
|
||||||
case NET_LL_TUN:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:TUN", dev->d_ifname);
|
|
||||||
break;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
default:
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:UNSPEC", dev->d_ifname);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsh_output(vtbl, " at %s\n", status);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_NET_ETHERNET)
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:Ethernet HWaddr %s at %s\n",
|
|
||||||
dev->d_ifname, ether_ntoa(&dev->d_mac), status);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_NET_LOOPBACK)
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:Local Loopback at %s\n", dev->d_ifname, status);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_NET_SLIP)
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:SLIP at %s\n", dev->d_ifname, status);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_NET_PPP)
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:P-t-P at %s\n", dev->d_ifname, status);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_NET_TUN)
|
|
||||||
nsh_output(vtbl, "%s\tLink encap:TUN at %s\n", dev->d_ifname, status);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
/* Show the IPv4 address */
|
|
||||||
|
|
||||||
addr.s_addr = dev->d_ipaddr;
|
|
||||||
nsh_output(vtbl, "\tinet addr:%s ", inet_ntoa(addr));
|
|
||||||
|
|
||||||
/* Show the IPv4 default router address */
|
|
||||||
|
|
||||||
addr.s_addr = dev->d_draddr;
|
|
||||||
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
|
|
||||||
|
|
||||||
/* Show the IPv4 network mask */
|
|
||||||
|
|
||||||
addr.s_addr = dev->d_netmask;
|
|
||||||
nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr));
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
|
|
||||||
netlib_get_ipv4dnsaddr(&addr);
|
|
||||||
nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr));
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
/* Convert the 128 network mask to a human friendly prefix length */
|
|
||||||
|
|
||||||
preflen = netlib_ipv6netmask2prefix(dev->d_ipv6netmask);
|
|
||||||
|
|
||||||
/* Show the assigned IPv6 address */
|
|
||||||
|
|
||||||
if (inet_ntop(AF_INET6, dev->d_ipv6addr, addrstr, INET6_ADDRSTRLEN))
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, "\tinet6 addr:%s/%d\n", addrstr, preflen);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* REVISIT: Show the IPv6 default router address */
|
|
||||||
|
|
||||||
if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, "\tinet6 DRaddr:%s/%d\n", addrstr, preflen);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_DHCPCv6) || defined(CONFIG_NSH_DNS)
|
|
||||||
# warning Missing logic
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nsh_output(vtbl, "\n");
|
|
||||||
|
|
||||||
/* Show driver statistics */
|
|
||||||
|
|
||||||
netdev_statistics(vtbl, dev);
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif /* !CONFIG_NSH_DISABLE_IFUPDOWN || !CONFIG_NSH_DISABLE_IFCONFIG */
|
#endif /* !CONFIG_NSH_DISABLE_IFUPDOWN || !CONFIG_NSH_DISABLE_IFCONFIG */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user