Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nshlib/ifconfig: Generate default IPv4 gateway with netmask #2220

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

wengzhe
Copy link
Contributor

@wengzhe wengzhe commented Dec 6, 2023

Summary

Patches included:

  • nshlib/ifconfig: Set network mask before setting gateway
    • Switch the order of setting network mask and gateway, re-order only, no logic change.
  • nshlib/ifconfig: Generate default IPv4 gateway with netmask
    • Generate default gateway using configured netmask instead of fixed 255.255.255.0, which may be more flexible under certain situations. e.g. A subnet like 10.0.23.16/28 may not contain the .1 address.

Before:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 => Mask:255.255.255.0 DRaddr:10.0.23.1

After:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.21
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.17
ifconfig eth0 10.0.23.22 netmask 255.255.255.0 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0 => DRaddr:10.0.0.1
ifconfig eth0 10.0.23.22 => Mask:255.255.255.0 DRaddr:10.0.23.1

Impact

ifconfig command

Testing

Manually

Switch the order of setting network mask and gateway, re-order only, no
logic change.

In IPv6 cases, we may set `addr6` and prefix length together to an
interface, but the gateway logic may change the value in `addr6`, and
result in wrong address set to the interface.

The order doesn't change behavior in network stack, so we just need to
make sure the value is correct.

Signed-off-by: Zhe Weng <[email protected]>
nshlib/nsh_netcmds.c Outdated Show resolved Hide resolved
Generate default gateway using configured netmask instead of fixed
255.255.255.0, which may be more flexible under certain situations.
e.g. A subnet like 10.0.23.16/28 may not contain the .1 address.

Before:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.0   => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0     => DRaddr:10.0.23.1

ifconfig eth0 10.0.23.22 => Mask:255.255.255.0      DRaddr:10.0.23.1

After:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.21
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.17
ifconfig eth0 10.0.23.22 netmask 255.255.255.0   => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0     => DRaddr:10.0.0.1

ifconfig eth0 10.0.23.22 => Mask:255.255.255.0      DRaddr:10.0.23.1

Signed-off-by: Zhe Weng <[email protected]>
@xiaoxiang781216 xiaoxiang781216 merged commit 9abc82c into apache:master Dec 7, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants