telnetd should listen both IPv4 and IPv6 for the dual stack

Change-Id: Ic1c2878f2eda721ccdf667b0a634289c643f5220
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-02-03 17:50:16 +08:00 committed by patacongo
parent c44f271195
commit 37135e5dfe
5 changed files with 41 additions and 56 deletions

View File

@ -78,16 +78,6 @@
# undef CONFIG_NSH_TELNET
#endif
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
* pick one.
*/
#ifdef CONFIG_NET_IPv6
# define ADDR_FAMILY AF_INET6
#else
# define ADDR_FAMILY AF_INET
#endif
/****************************************************************************
* Public Data
****************************************************************************/
@ -255,7 +245,7 @@ int main(int argc, FAR char *argv[])
*/
#ifdef CONFIG_NSH_TELNET
ret = nsh_telnetstart(ADDR_FAMILY);
ret = nsh_telnetstart(AF_UNSPEC);
if (ret < 0)
{
/* The daemon is NOT running. Report the error then fail...

View File

@ -68,15 +68,6 @@
# warning You probably do not really want CONFIG_NSH_USBKBD, try CONFIG_NXWM_KEYBOARD_USBHOST
#endif
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
* pick one.
*/
#ifdef CONFIG_NET_IPv6
# define ADDR_FAMILY AF_INET6
#else
# define ADDR_FAMILY AF_INET
#endif
/********************************************************************************************
* Private Types
********************************************************************************************/
@ -694,7 +685,7 @@ bool NxWM::nshlibInitialize(void)
// Telnet daemon.
#ifdef CONFIG_NSH_TELNET
int ret = nsh_telnetstart(ADDR_FAMILY);
int ret = nsh_telnetstart(AF_UNSPEC);
if (ret < 0)
{
// The daemon is NOT running!

View File

@ -75,16 +75,6 @@
# warning You probably do not really want CONFIG_NSH_USBKBD, try CONFIG_TWM4NX_KEYBOARD_USBHOST
#endif
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
* pick one.
*/
#ifdef CONFIG_NET_IPv6
# define ADDR_FAMILY AF_INET6
#else
# define ADDR_FAMILY AF_INET
#endif
/////////////////////////////////////////////////////////////////////////////
// Private Types
/////////////////////////////////////////////////////////////////////////////
@ -617,7 +607,7 @@ bool CNxTermFactory::nshlibInitialize(void)
// Telnet daemon.
#ifdef CONFIG_NSH_TELNET
int ret = nsh_telnetstart(ADDR_FAMILY);
int ret = nsh_telnetstart(AF_UNSPEC);
if (ret < 0)
{
// The daemon is NOT running!

View File

@ -269,7 +269,6 @@ int nsh_telnetstart(sa_family_t family)
/* Configure the telnet daemon */
config.d_port = HTONS(CONFIG_NSH_TELNETD_PORT);
config.d_family = family;
config.d_priority = CONFIG_NSH_TELNETD_DAEMONPRIO;
config.d_stacksize = CONFIG_NSH_TELNETD_DAEMONSTACKSIZE;
config.t_priority = CONFIG_NSH_TELNETD_CLIENTPRIO;
@ -280,15 +279,41 @@ int nsh_telnetstart(sa_family_t family)
ninfo("Starting the Telnet daemon\n");
ret = telnetd_start(&config);
if (ret < 0)
#ifdef CONFIG_NET_IPv4
if (family == AF_UNSPEC || family == AF_INET)
{
_err("ERROR: Failed to start the Telnet daemon: %d\n", ret);
state = TELNETD_NOTRUNNING;
config.d_family = AF_INET;
ret = telnetd_start(&config);
if (ret < 0)
{
_err("ERROR: Failed to start the Telnet IPv4 daemon: %d\n", ret);
}
else
{
state = TELNETD_RUNNING;
}
}
else
#endif
#ifdef CONFIG_NET_IPv6
if (family == AF_UNSPEC || family == AF_INET6)
{
state = TELNETD_RUNNING;
config.d_family = AF_INET6;
ret = telnetd_start(&config);
if (ret < 0)
{
_err("ERROR: Failed to start the Telnet IPv6 daemon: %d\n", ret);
}
else
{
state = TELNETD_RUNNING;
}
}
#endif
if (state == TELNETD_STARTED)
{
state = TELNETD_NOTRUNNING;
}
}
@ -324,18 +349,17 @@ int nsh_telnetstart(sa_family_t family)
#ifndef CONFIG_NSH_DISABLE_TELNETD
int cmd_telnetd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
sa_family_t family;
sa_family_t family = AF_UNSPEC;
/* If both IPv6 nd IPv4 are enabled, then the address family must
* be specified on the command line.
*/
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
family = (strcmp(argv[1], "ipv6") == 0) ? AF_INET6 : AF_INET;
#elif defined(CONFIG_NET_IPv6)
family = AF_INET6;
#else /* if defined(CONFIG_NET_IPv4) */
family = AF_INET;
if (argc >= 2)
{
family = (strcmp(argv[1], "ipv6") == 0) ? AF_INET6 : AF_INET;
}
#endif
return nsh_telnetstart(family) < 0 ? ERROR : OK;

View File

@ -103,16 +103,6 @@
# undef CONFIG_NSH_TELNET
#endif
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
* pick one.
*/
#ifdef CONFIG_NET_IPv6
# define ADDR_FAMILY AF_INET6
#else
# define ADDR_FAMILY AF_INET
#endif
/****************************************************************************
* Private Data
****************************************************************************/
@ -173,7 +163,7 @@ static int nsh_task(void)
* been initialized
*/
ret = nsh_telnetstart(ADDR_FAMILY);
ret = nsh_telnetstart(AF_UNSPEC);
if (ret < 0)
{
/* The daemon is NOT running. Report the error then fail...