mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-12 16:06:59 +00:00
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>
|
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| Kconfig | ||
| Make.defs | ||
| Makefile | ||
| nsh.h | ||
| nsh_alias.c | ||
| nsh_altconsole.c | ||
| nsh_builtin.c | ||
| nsh_codeccmd.c | ||
| nsh_command.c | ||
| nsh_console.c | ||
| nsh_console.h | ||
| nsh_consolemain.c | ||
| nsh_dbgcmds.c | ||
| nsh_dropbear.c | ||
| nsh_envcmds.c | ||
| nsh_fileapps.c | ||
| nsh_fscmds.c | ||
| nsh_fsutils.c | ||
| nsh_identity.c | ||
| nsh_init.c | ||
| nsh_login.c | ||
| nsh_mmcmds.c | ||
| nsh_mntcmds.c | ||
| nsh_modcmds.c | ||
| nsh_netcmds.c | ||
| nsh_parse.c | ||
| nsh_passwdcmds.c | ||
| nsh_printf.c | ||
| nsh_proccmds.c | ||
| nsh_prompt.c | ||
| nsh_routecmds.c | ||
| nsh_script.c | ||
| nsh_session.c | ||
| nsh_syscmds.c | ||
| nsh_system.c | ||
| nsh_telnetd.c | ||
| nsh_telnetlogin.c | ||
| nsh_test.c | ||
| nsh_timcmds.c | ||
| nsh_usbconsole.c | ||
| nsh_usbtrace.c | ||
| nsh_vars.c | ||
| nsh_wait.c | ||
| rc.sysinit.template | ||
| rcS.template | ||