Bug 292262 - netstat: numerous space-padded fields in JSON output
Summary: netstat: numerous space-padded fields in JSON output
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Johan Söllvander
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-08 00:11 UTC by Alan Somers
Modified: 2026-01-20 14:45 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2026-01-08 00:11:28 UTC
netstat has libxo support.  But its encoded output forms include numerous fields with space-padding where it doesn't belong.  For example:

$ netstat -c -p tcp -n --libxo=json,pretty | grep stack | sort | uniq
        "stack": "bbr    "
        "stack": "freebsd"


The common pattern in the code is xo_emit calls with field-format specifiers that include strings with widths, and no encoding-format specifiers.  For example, the above lines were caused by:

xo_emit(" {:stack/%-*.*s}",

Most such instances can be caught by this regex: "xo_emit[^/{]*\{[^}/]*/[^}/]*\}".  There are hundreds.
Comment 1 Johan Söllvander freebsd_committer freebsd_triage 2026-01-08 08:11:35 UTC
I can work on this if you want. Unless you've already started?
Comment 2 Alan Somers freebsd_committer freebsd_triage 2026-01-08 16:13:35 UTC
(In reply to Johan Söllvander from comment #1)
No, I'm not planning to.  If you want to, great.  I'll review it.
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-01-15 14:22:26 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=faa31fc0e7acc1c53bba2b69a63e9ff55d24faf7

commit faa31fc0e7acc1c53bba2b69a63e9ff55d24faf7
Author:     Johan Söllvander <js@FreeBSD.org>
AuthorDate: 2026-01-15 14:21:07 +0000
Commit:     Johan Söllvander <js@FreeBSD.org>
CommitDate: 2026-01-15 14:21:07 +0000

    netstat: Remove padding from cc and stack fields

    Trim white space padding that gets added libxo fields cc and stack when
    using -C and -c.

    The padding is only visible if you're using multiple stacks or
    congestion algorithms.

    PR:             292262
    MFC after:      5 days
    Reviewed by:    asomers, tuexen
    Approved by:    asomers (mentor)
    Differential Revision:  https://reviews.freebsd.org/D54709

 usr.bin/netstat/inet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-01-20 13:24:58 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=01ffd4516f3ce26d0b6d797818b47a974e7caabf

commit 01ffd4516f3ce26d0b6d797818b47a974e7caabf
Author:     Johan Söllvander <js@FreeBSD.org>
AuthorDate: 2026-01-15 14:21:07 +0000
Commit:     Johan Söllvander <js@FreeBSD.org>
CommitDate: 2026-01-20 11:47:30 +0000

    netstat: Remove padding from cc and stack fields

    Trim white space padding that gets added libxo fields cc and stack when
    using -C and -c.

    The padding is only visible if you're using multiple stacks or
    congestion algorithms.

    PR:             292262
    Reviewed by:    asomers, tuexen
    Approved by:    asomers (mentor)
    Differential Revision:  https://reviews.freebsd.org/D54709

    (cherry picked from commit faa31fc0e7acc1c53bba2b69a63e9ff55d24faf7)

 usr.bin/netstat/inet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-01-20 13:26:59 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=af46d309a72b73398c3d0e4bee9b21437af17d7a

commit af46d309a72b73398c3d0e4bee9b21437af17d7a
Author:     Johan Söllvander <js@FreeBSD.org>
AuthorDate: 2026-01-15 14:21:07 +0000
Commit:     Johan Söllvander <js@FreeBSD.org>
CommitDate: 2026-01-20 13:25:39 +0000

    netstat: Remove padding from cc and stack fields

    Trim white space padding that gets added libxo fields cc and stack when
    using -C and -c.

    The padding is only visible if you're using multiple stacks or
    congestion algorithms.

    PR:             292262
    Reviewed by:    asomers, tuexen
    Approved by:    asomers (mentor)
    Differential Revision:  https://reviews.freebsd.org/D54709

    (cherry picked from commit faa31fc0e7acc1c53bba2b69a63e9ff55d24faf7)

 usr.bin/netstat/inet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)