Skip to content

ifconfig, ip, AROSTCP: show IPv4 aliases, with their own netmask and broadcast - #2284

Merged
Kalamatee merged 3 commits into
aros-development-team:masterfrom
JJDSNT:review/ipv4-aliases
Nov 15, 2026
Merged

Kalamatee merged 3 commits into
aros-development-team:masterfrom
JJDSNT:review/ipv4-aliases

Conversation

@JJDSNT

@JJDSNT JJDSNT commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

The follow-up noted on #2277: IPv4 aliases are shown, each with its own netmask and broadcast address. Three commits:

  1. AROSTCP: an IPv4 alias's netmask and broadcast for the address named. SIOCGIFNETMASK, SIOCGIFBRDADDR and SIOCGIFDSTADDR answered for an interface's first IPv4 address whatever ifr_addr held. They now answer for the address in ifr_addr when the interface has it, as NetBSD's in_control() does and as IPv6's SIOCGIFNETMASK_IN6 already does here. Anything else there - nothing, or what an earlier request left (a program asking SIOCGIFADDR, SIOCGIFNETMASK and SIOCGIFBRDADDR with one ifreq has the mask in it by the third: ifconfig, arda_netdiag), or another interface's address - still names the first address, without NetBSD's EADDRNOTAVAIL: no caller in the tree changes. cunit-net-ifalias (master: 2 asserts fail). bsdsocket.library 5.48 (kernel v0.87).
  2. ifconfig, ip: show an interface's IPv4 aliases. Both printed the one address SIOCGIFADDR gives and used SIOCGIFCONF only for the interfaces' names. They now print the first address, then the interface's other AF_INET entries, each with its own mask, broadcast (or destination) and conflict detection state, asked for that address. ifconfig with an interface named shows them too; its interface list is one function, getifconf(), which printall() uses as well.
  3. ip: the prefix length of an IPv4 netmask. ip addr and ip route showed every IPv4 prefix as /0: mask2prefix() read a mask without a family from just after its family byte, where a sockaddr_in has sin_port. It now takes the family the mask is for (BSD's convention: laid out as the destination's sockaddr), and reads from sin_addr or sin6_addr.

Tested on hosted (eth0, eth1) and on AROS m68k on an emulated A3000:

master this PR
ifconfig -a, ip addr with 300 /32 aliases on eth0 (hosted) none shown 300 of 300, each /32
a /16 alias next to eth0's /24 not shown 10.77.0.1 netmask 0xffff0000 broadcast 10.77.255.255, 10.77.0.1/16 brd 10.77.255.255
ip addr, ip route prefixes 192.168.166.2/0, 192.168.166.0/0 /24, routes /24 and /16; IPv6 unchanged
m68k: 60 /32 aliases and a /16 none shown all shown, no fault

The whole cunit suite passes, with cunit-net-ifalias.

SIOCGIFNETMASK, SIOCGIFBRDADDR and SIOCGIFDSTADDR answered for an
interface's first IPv4 address whatever ifr_addr held, so a program could
not learn an alias's mask or broadcast address. They now answer for the
address in ifr_addr when the interface has it, as NetBSD's in_control()
does and as IPv6's SIOCGIFNETMASK_IN6 already does here. Anything else in
ifr_addr - nothing, or what an earlier request left there: a program
asking SIOCGIFADDR, SIOCGIFNETMASK and SIOCGIFBRDADDR with one ifreq has
the mask in it by the third (ifconfig, arda_netdiag), or another
interface's address - still names the first address, without the
EADDRNOTAVAIL NetBSD gives: no caller in the tree changes. SIOCGIFADDR is
the first address, as before.

cunit-net-ifalias: an alias named (10.77.0.1/16 on eth0) gives its own
mask and broadcast (master: the first address's, 2 asserts fail); the
first address named, or nothing, the first's; a mask or 127.0.0.1 in
ifr_addr, the first's; SIOCGIFADDR the first address. The whole cunit
suite, 69 of 69.

bsdsocket.library 5.48 (kernel v0.87).
ifconfig and ip addr printed one IPv4 address per interface, the one
SIOCGIFADDR gives - the first - and used SIOCGIFCONF only for the
interfaces' names: an alias, added with "ifconfig eth0 A netmask M alias"
(SIOCAIFADDR), was on the interface and in the list but never shown, so
it looked as if it had not been added.

Both now print the first address, then the interface's other AF_INET
entries of the list, each with its own netmask, broadcast (or
destination) address and conflict detection state: SIOCGIFNETMASK,
SIOCGIFBRDADDR, SIOCGIFDSTADDR and SIOCGIFAFLAG_IN are asked for that
address, which the stack answers for the address named in ifr_addr
(AROSTCP, the commit before; a stack that does not gives the first
address's mask and broadcast for every alias). ifconfig with an
interface named shows them too; its interface list is one function,
getifconf(), which printall() uses as well.
ip addr and ip route showed every IPv4 prefix as /0 (192.168.166.2/0,
192.168.166.0/0 via ...): the stack gives a netmask, from SIOCGIFNETMASK
and in routing messages, with no family, laid out as a sockaddr of the
destination's family and cut after its last non-zero byte - BSD's
convention - and mask2prefix() read such a mask from just after its
family byte, where a sockaddr_in has sin_port, zero. It now takes the
family the mask is for, and reads from sin_addr (IPv4) or sin6_addr
(IPv6), what lies past sa_len being zero; ip addr passes AF_INET or
AF_INET6, ip route the destination's family.
@JJDSNT
JJDSNT force-pushed the review/ipv4-aliases branch from 9573fde to 0d575e0 Compare November 14, 2026 23:36
@Kalamatee
Kalamatee merged commit 218afd1 into aros-development-team:master Nov 15, 2026
3 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.

2 participants