Skip to content

Commit df93556

Browse files
committed
motd/20-ip-info: align (LAN)/(WAN) labels across IPv4 + IPv6 rows
The IPv4 row used a 14-char prefix (` IPv4:` + 8 trailing spaces); the IPv6 row used 15 (` IPv6:` + 9 trailing spaces). The extra space on v6 was an attempt to make the v6 address column line up with the v4 address column when v4 had a `(LAN)` label and v6 didn't (v6's LAN appendix had no label at all, just the bare address). Worked when v4 had `(LAN)` and v6 had something — broke the moment LAN got dropped against WAN by the dedup at lines 76-81 and only the `(WAN)` half remained. Net visible bug (addresses are RFC 5737 / RFC 3849 examples): IPv4: (WAN) 192.0.2.42 IPv6: (WAN) 2001:db8::42 ^ shifted by one column Fix: - Use the same 13-char prefix for both rows (IPv4: / IPv6: + 7 padding, no trailing space). - Both `(LAN)` and `(WAN)` appendices start with a single leading space — the label always sits at the same column regardless of which (or both) are present. - Add a `(LAN)` label to v6 too; the asymmetry was the original reason the spacing was offset, and removing it lets v4 and v6 structurally mirror each other. - Drop the trailing space the appendices used to carry — pure EOL whitespace, never visible. Verified across all four cases (LAN+WAN / LAN only / WAN only / nothing): `(LAN)` and `(WAN)` always align column-for-column on both rows.
1 parent 7138b33 commit df93556

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

packages/bsp/common/etc/update-motd.d/20-ip-info

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,32 @@ print_ip_lines() {
8080
ipv6s="$(printf '%s\n' $ipv6s | awk -v w="$wan6" '$0!=w' | paste -sd' ' -)"
8181
fi
8282

83+
# Both lines use the SAME prefix width and BOTH (LAN) and (WAN)
84+
# appendices start with a single leading space — that way the
85+
# labels always sit at the same column regardless of whether
86+
# one or both are present, and the v6 line stays aligned under
87+
# the v4 line. Previously the v6 prefix was 1 space wider and
88+
# v6 had no (LAN) label at all, so removing one half (the
89+
# common case is LAN deduped against WAN by the block above)
90+
# produced misaligned (WAN) labels across the two rows.
91+
local prefix4=" IPv4: "
92+
local prefix6=" IPv6: "
93+
8394
# IPv4 line
8495
if [[ -n "$ipv4s" || -n "$wan4" ]]; then
8596
_motd_mark_after_header
86-
local line=" IPv4: "
87-
[[ -n "$ipv4s" ]] && line+=" \x1B[93m(LAN)\x1B[0m \x1B[92m${ipv4s// /, }\x1B[0m "
88-
[[ -n "$wan4" ]] && line+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan4}\x1B[0m "
97+
local line="$prefix4"
98+
[[ -n "$ipv4s" ]] && line+=" \x1B[93m(LAN)\x1B[0m \x1B[92m${ipv4s// /, }\x1B[0m"
99+
[[ -n "$wan4" ]] && line+=" \x1B[93m(WAN)\x1B[0m \x1B[95m${wan4}\x1B[0m"
89100
printf '%b\n' "$line"
90101
fi
91102

92103
# IPv6 line
93104
if [[ -n "$ipv6s" || -n "$wan6" ]]; then
94-
_motd_mark_after_header
95-
local line=" IPv6: "
96-
[[ -n "$ipv6s" ]] && line+="\x1B[96m${ipv6s// /, }\x1B[0m "
97-
[[ -n "$wan6" ]] && line+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan6}\x1B[0m "
105+
_motd_mark_after_header
106+
local line="$prefix6"
107+
[[ -n "$ipv6s" ]] && line+=" \x1B[93m(LAN)\x1B[0m \x1B[96m${ipv6s// /, }\x1B[0m"
108+
[[ -n "$wan6" ]] && line+=" \x1B[93m(WAN)\x1B[0m \x1B[95m${wan6}\x1B[0m"
98109
printf '%b\n' "$line"
99110
fi
100111
}

0 commit comments

Comments
 (0)