Page MenuHomeFreeBSD

libxo'ify netstat.
ClosedPublic

Authored by alfred on Dec 25 2014, 5:49 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Feb 14, 10:16 PM
Unknown Object (File)
Mon, Feb 10, 3:23 AM
Unknown Object (File)
Jan 28 2025, 7:43 PM
Unknown Object (File)
Jan 21 2025, 6:03 PM
Unknown Object (File)
Jan 16 2025, 10:51 AM
Unknown Object (File)
Jan 16 2025, 9:38 AM
Unknown Object (File)
Dec 30 2024, 3:12 AM
Unknown Object (File)
Dec 13 2024, 10:39 PM
Subscribers

Details

Summary

Original diff: Phil Shafer
Additional code: Kim Shrier <kim@westryn.net>
Sponsored by: Norse

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

alfred updated this revision to Diff 2867.
alfred retitled this revision from to libxo'ify netstat..
alfred edited the test plan for this revision. (Show Details)
alfred updated this object.
  • remove WIP files
  • Cleanup route json.
  • libxo p_rtentry_kvm
  • Fixup route output from kvm
marcel edited edge metadata.

Thanks!

This revision is now accepted and ready to land.Dec 26 2014, 6:04 PM

I glossed over the review. There are a lot of changes and I'm not aware of how the libxo grammar works, but if this could be done in phases it would make it a lot easier to review...

usr.bin/netstat/Makefile
45–46

Use LIBADD instead of DPADD/LDADD? Just watch out for MFC issues..

usr.bin/netstat/if.c
129

xo_open_list and xo_close_list can fail. I think we care because that means that the output gathering would be all for naught, correct?

This comment applies to other areas where this pattern's applied as well.

134

style(9): remove space between (uintmax_t) and *a; this comment (spurious space between cast and variable) applies to other additions as well.

254

style(9): bad indentation -- 4 spaces after hard tab (here and elsewhere).

326

This indentation looks off. Is it a phabricator bug?

331

I understand what you're doing, but this seems a bit gratuitous, and ifa->ifa_name is a bit easier to grok than name.

416

Should this be size_t?

422

Indentation, and this also seemed like it should have been a general purpose function elsewhere..

usr.bin/netstat/inet.c
352

This seems a bit gratuitous (along with the next line's whitespace change). Should this be a separate commit?

usr.bin/netstat/main.c
864

(Random question) should usage messages be converted to libxo...?

alfred edited edge metadata.
  • use LIBADD instead of LDADD/DPADD
This revision now requires review to proceed.Dec 27 2014, 1:16 AM
alfred edited edge metadata.
  • Need to close socket instances for 'netstat -a'
  • Quote pointer values.
  • Fixup socket output, use a single list.
  • Pointers need to be quoted.
  • Remove whitespace from tcp/toe46 values.
  • Fix protocol whitespace in -Q output
  • Fixup padding between CPU&Name for -Q output
  • Only open socket list when doing control block print
  • quote icmp-address-responses
  • Need to close input-histogram
  • hex address needs to be quoted
  • Tests for json from netstat
  • Remove stray diff markers
  • debug macros
  • Workaround {P: can't take 0 pad and number args seem broken.
  • Deal with zero lenth LINK address.
  • Need to close interface instance.
  • Emit well formatted json when -q given with -w
  • Fix -B (bpfstats) with json
This comment was removed by se.
usr.bin/netstat/inet.c
1233–1234

Typo: output-histagram should be output-histogram

usr.bin/netstat/route.c
918–922

The format generated in "buffer" is suitable for printf(), but not for xo_emit().
Reason: "%s" in xo_emit() is printed verbatim, unless written as "{:/%s}" ...

The correct format strung for xo_emit() might be generated by:

snprintf(buffer, sizeof(buffer), "{d:/%%-%d.%ds }", wid_flags, wid_flags);

(untested)

  • spelling: histogram
  • Proper formatting for flags.
In D1380#28, @se wrote:

Typo: output-histagram should be output-histogram

Fixed!

In D1380#29, @se wrote:

The format generated in "buffer" is suitable for printf(), but not for xo_emit().
Reason: "%s" in xo_emit() is printed verbatim, unless written as "{:/%s}" ...

The correct format strung for xo_emit() might be generated by:

snprintf(buffer, sizeof(buffer), "{d:/%%-%d.%ds }", wid_flags, wid_flags);

(untested)

I took another direction with this, can you see if it makes sense? I now output the old flags as well as the new flags. Maybe there is even a better way to make "pretty_flags" into a key-value dict?

In D1380#33, @alfredperlstein wrote:
In D1380#29, @se wrote:

The format generated in "buffer" is suitable for printf(), but not for xo_emit().
Reason: "%s" in xo_emit() is printed verbatim, unless written as "{:/%s}" ...

The correct format strung for xo_emit() might be generated by:

snprintf(buffer, sizeof(buffer), "{d:/%%-%d.%ds }", wid_flags, wid_flags);

(untested)

I took another direction with this, can you see if it makes sense? I now output the old flags as well as the new flags. Maybe there is even a better way to make "pretty_flags" into a key-value dict?

Do you really need the textual version of the flags when generating XML or JSON?

I do actually consider the previous version better (with tag "flags" instead of "pretty_flags"). The individual elements are not "pretty", they are just the XML/JSON way of making the flag easily accessible for testing in scripts.

There is no better way to generate the key-value dict that I know of.

The "l" modifier of xo_emit() is undocumented except in the libxo sources, but it seems to be there exactly for your use case. I'd like to use a different API for libxo, which I'm going to discuss elsewhere.

(To give an idea of what I'd rather use instead of the "l" modifier: xo_emit("{:tag/...}") within xo_open_list("tag") should imply the "l" modifier for JSON output - this modifier is a NOP for all other formats, anyway.)

rodrigc edited edge metadata.

Looks OK. In a future pass, the testing logic should be converted from Makefile logic that is in there now
into a test that generates a Kyuafile under /usr/tests.

This revision is now accepted and ready to land.Jan 1 2015, 11:32 PM