nuttx-apps/nshlib
wangjianyu3 a8d55f4a10 nshlib/ifconfig: only apply the settings that were asked for
cmd_ifconfig() pushed every setting to the device on each invocation,
whether or not the command line carried it, and stopped parsing as soon
as it saw "mtu".  So a command meant to touch one thing quietly rewrote
the rest of the interface configuration:

  ifconfig eth0 hw 00:11:22:33:44:55  # clears the address, netmask,
                                      # gateway and resolver, and kicks
                                      # off a DHCP request
  ifconfig eth0 mtu 1500              # same, plus the default route
  ifconfig eth0 mtu 1500 dns 8.8.8.8  # dns silently ignored

In detail:

  - the address was written unconditionally.  For IPv6 that read the
    uninitialized addr6 off the stack and pushed whatever it held into
    the device; for IPv4 it forced 0.0.0.0.
  - the netmask fell back to a hard-coded 255.255.255.0, or to
    ffff:ffff:ffff:ffff:: for IPv6.
  - the IPv4 gateway was always written, unlike the IPv6 one, so it fell
    back to INADDR_ANY.
  - the resolver fell back to that gateway, i.e. to 0.0.0.0.
  - the DHCP client was started whenever gip was left at zero instead of
    when "dhcp" was asked for, and gip only becomes non-zero when an
    address or a gateway is parsed.
  - the "mtu" branch returned as soon as netlib_set_mtu() succeeded, so
    every argument behind it was dropped.

Write each setting only when the user provided it, or when an address
is being assigned and the setting belongs to it.  Keeping the address
case is deliberate: a freshly assigned address still needs a mask and
a route, so dropping the derived netmask and "x.x.x.1" gateway there
would be a regression of its own.  DHCP now triggers on the "dhcp"
keyword, which is the only way to request it.  And with nothing left
to clobber, the "mtu" branch no longer has to bail out early.

This is how ifconfig behaves elsewhere: Linux net-tools walks the
argument vector in a single loop where every keyword handler ends in
"continue" and none of them returns, so each keyword is an independent,
idempotent operation applied in the order it was written.

As a side effect mip is now only read along the paths that assign it,
since the IPv4 gateway fallback only derives an address from mip when
gip came from hostip.

Assisted-by: GitHubCopilot:claude-opus-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-11 11:21:43 +08:00
..
CMakeLists.txt netutils/dropbear: add Dropbear SSH server port for NuttX 2026-06-27 08:42:00 -03:00
Kconfig nshlib, graphics/microwindows: require the keyboard byte stream 2026-08-02 18:36:37 +08:00
Make.defs nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
Makefile netutils/dropbear: add Dropbear SSH server port for NuttX 2026-06-27 08:42:00 -03:00
nsh.h nshlib: add du command support 2026-07-26 07:39:39 -03:00
nsh_alias.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_altconsole.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_builtin.c sched/signal: Add support to disable partial or all signals 2026-01-15 15:48:54 +08:00
nsh_codeccmd.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_command.c nshlib: add du command support 2026-07-26 07:39:39 -03:00
nsh_console.c nshlib: fix infinite loop on broken stdout in nsh_catfile 2026-05-26 16:06:28 -03:00
nsh_console.h nshlib: Add stderr redirection support 2026-01-27 03:14:00 +08:00
nsh_consolemain.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_dbgcmds.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_dropbear.c netutils/dropbear: add Dropbear SSH server port for NuttX 2026-06-27 08:42:00 -03:00
nsh_envcmds.c nsh/echo: Fix echo previous behavior, single write with '\n' 2026-06-27 13:44:14 +02:00
nsh_fileapps.c nshlib: Add stderr redirection support 2026-01-27 03:14:00 +08:00
nsh_fscmds.c nshlib: add du command support 2026-07-26 07:39:39 -03:00
nsh_fsutils.c nshlib: fix infinite loop on broken stdout in nsh_catfile 2026-05-26 16:06:28 -03:00
nsh_identity.c nsh: show real, effective, and saved IDs in id command 2026-07-31 01:14:30 +08:00
nsh_init.c netutils/dropbear: add Dropbear SSH server port for NuttX 2026-06-27 08:42:00 -03:00
nsh_login.c !nshlib: Remove fixed login; require FSUTILS_PASSWD 2026-07-22 17:21:22 +08:00
nsh_mmcmds.c apps/nshlib: Reuse local variable for cmd_memdump 2025-01-17 23:27:43 +08:00
nsh_mntcmds.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_modcmds.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_netcmds.c nshlib/ifconfig: only apply the settings that were asked for 2026-08-11 11:21:43 +08:00
nsh_parse.c nshlib: Add su, id, and whoami identity commands 2026-06-20 15:38:45 -03:00
nsh_passwdcmds.c !nshlib: Remove fixed login; require FSUTILS_PASSWD 2026-07-22 17:21:22 +08:00
nsh_printf.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_proccmds.c nshlib: top: add Linux-like summary and flicker-free refresh 2026-07-12 10:00:40 +08:00
nsh_prompt.c nshlib: Add su, id, and whoami identity commands 2026-06-20 15:38:45 -03:00
nsh_routecmds.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_script.c apps: Replace O_RDOK with O_RDONLY after alias removal 2026-06-28 13:00:52 +02:00
nsh_session.c readline: Make prompt-caching available 2026-07-24 14:12:38 -03:00
nsh_syscmds.c nshlib: boot: guard nsh_getfullpath against NULL argv[1] 2026-08-07 21:31:18 +08:00
nsh_system.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_telnetd.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_telnetlogin.c !nshlib: Remove fixed login; require FSUTILS_PASSWD 2026-07-22 17:21:22 +08:00
nsh_test.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
nsh_timcmds.c !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-22 13:38:25 +08:00
nsh_usbconsole.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_usbtrace.c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
nsh_vars.c fix: V-001 security vulnerability 2026-07-10 13:01:42 +08:00
nsh_wait.c nshlib: migrate to SPDX identifier 2024-12-30 18:02:50 +08:00
rc.sysinit.template nsh/script: support rc.sysinit script 2022-04-21 12:54:24 +03:00
rcS.template nsh/script: support rc.sysinit script 2022-04-21 12:54:24 +03:00