This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit ab7e0660d59adc131e1dff5ea41a8729aefd4634
Author: wangjianyu3 <[email protected]>
AuthorDate: Mon Aug 10 16:24:37 2026 +0800

    nshlib/ifconfig: support "ifconfig <iface> up|down"
    
    Previously "ifconfig eth0 up" fell through to the host-IP parsing
    branch, where inet_addr("up") returns INADDR_NONE, so the address was
    silently set to 255.255.255.255 and the interface was never brought
    up.  Users had to run the separate "ifup"/"ifdown" commands.
    
    Recognize the "up" and "down" tokens explicitly and apply them once
    the rest of the configuration is in place, so up/down is just another
    keyword in the argument list as it is in Linux ifconfig.
    
    A bare "ifconfig <iface> up|down" needs no special case: the preceding
    patch made the address, netmask, gateway, DNS and DHCP blocks check
    whether they were asked for, so the command falls through them without
    touching anything.
    
    The up/down handling calls netlib_ifup()/netlib_ifdown() from netlib, so
    it stays available regardless of CONFIG_NSH_DISABLE_IFUPDOWN (which only
    strips the standalone ifup/ifdown commands).
    
    Assisted-by: GitHubCopilot:claude-opus-5
    Signed-off-by: wangjianyu3 <[email protected]>
---
 nshlib/nsh_command.c |  2 +-
 nshlib/nsh_netcmds.c | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 098abaa76..8e136edc7 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -296,7 +296,7 @@ static const struct cmdmap_s g_cmdmap[] =
   CMD_MAP("ifconfig", cmd_ifconfig, 1, 12,
     "[interface [mtu <len>]|[address_family] [[add|del] <ip-address>|dhcp]]"
     "[dr|gw|gateway <dr-address>] [netmask <net-mask>|prefixlen <len>] "
-    "[dns <dns-address>] [hw <hw-mac>]"),
+    "[dns <dns-address>] [hw <hw-mac>] [up|down]"),
 #  endif
 #  if defined(CONFIG_NET_VLAN) && !defined(CONFIG_NSH_DISABLE_VCONFIG)
   CMD_MAP("vconfig", cmd_vconfig, 3, 5,
diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c
index defcb717f..c281650d2 100644
--- a/nshlib/nsh_netcmds.c
+++ b/nshlib/nsh_netcmds.c
@@ -584,6 +584,8 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 #endif
   bool missingarg = true;
   bool badarg = false;
+  bool ifup = false;
+  bool ifdown = false;
 #ifdef CONFIG_NET_ARP
   arp_cfg_e arpflag = ARP_DEFAULT;
 #endif
@@ -766,6 +768,14 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
               arpflag = ARP_DISABLE;
             }
 #endif
+          else if (!strcmp(tmp, "up"))
+            {
+              ifup = true;
+            }
+          else if (!strcmp(tmp, "down"))
+            {
+              ifdown = true;
+            }
           else if (hostip == NULL && i <= 4)
             {
               /* Let first non-option be host ip, to support inet/inet6
@@ -1079,6 +1089,17 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
     }
 #endif
 
+  /* Bring the interface up or down once everything else is in place. */
+
+  if (ifup)
+    {
+      netlib_ifup(ifname);
+    }
+  else if (ifdown)
+    {
+      netlib_ifdown(ifname);
+    }
+
 #if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
   UNUSED(hostip);
   UNUSED(mask);

Reply via email to