Bug #11545
closedWant configurable output field separator for libofmt
100%
Description
As part of adding the connstat(1M)
tool (see delphix/delphix-os@374241a), Delphix made some changes to the ofmt_*
functions in libinetutil
. Those have since been moved into their own libofmt
library, so as part of the porting connstat
, we'll want to pull in those changes and also document them in the manual page.
The changes to ofmt
were originally done by Sebastien Roy at Delphix, and the manual page was written by Cody Mello at Joyent, while porting it as part of OS-7325.
Updated by Cody Mello almost 3 years ago
Since these changes are used by connstat(1M)
, I ran the tool to verify that they work.
For example, it calls ofmt_print
for every TCP connection. When there are multiple connections, the header is only printed once since it's using both OFMT_NOHEADER
and ofmt_print_header
:
cpm@utu ~ % connstat -F laddr=0.0.0.0 LADDR LPORT RADDR RPORT STATE 0.0.0.0 22 0.0.0.0 0 LISTEN 0.0.0.0 111 0.0.0.0 0 LISTEN 0.0.0.0 0 0.0.0.0 0 IDLE 0.0.0.0 111 0.0.0.0 0 LISTEN 0.0.0.0 0 0.0.0.0 0 IDLE 0.0.0.0 33526 0.0.0.0 0 LISTEN 0.0.0.0 33823 0.0.0.0 0 LISTEN
connstat(1M)
also uses the ofmt_set_fs
function to change the parsable separator from the default ":"
to ","
:
cpm@utu ~ % connstat -P -o laddr,lport,raddr,rport,state,mss,outbytes -F laddr=0.0.0.0 0.0.0.0,22,0.0.0.0,0,LISTEN,536,0 0.0.0.0,111,0.0.0.0,0,LISTEN,1220,0 0.0.0.0,0,0.0.0.0,0,IDLE,1220,0 0.0.0.0,111,0.0.0.0,0,LISTEN,536,0 0.0.0.0,0,0.0.0.0,0,IDLE,536,0 0.0.0.0,33526,0.0.0.0,0,LISTEN,536,0 0.0.0.0,33823,0.0.0.0,0,LISTEN,1220,0
ipadm(1M)
and dladm(1M)
both also rely on ofmt, and should continue to work as they previously have. Here's an example showing them using ofmt for wrapping on commas in output, and also displaying specific fields in both parsable and non-parsable mode, where non-parsable includes the header:
cpm@utu ~ % dladm show-linkprop -o property,perm,value,default,possible e1000g1 PROPERTY PERM VALUE DEFAULT POSSIBLE speed r- 1000 1000 -- autopush rw -- -- -- zone rw -- -- -- duplex r- full full half,full state r- up up up,down adv_autoneg_cap rw 1 1 1,0 mtu rw 1500 1500 1500-16362 flowctrl rw no bi no,tx,rx,bi adv_100gfdx_cap r- -- 0 1,0 en_100gfdx_cap -- -- 0 1,0 adv_50gfdx_cap r- -- 0 1,0 en_50gfdx_cap -- -- 0 1,0 adv_40gfdx_cap r- -- 0 1,0 en_40gfdx_cap -- -- 0 1,0 adv_25gfdx_cap r- -- 0 1,0 en_25gfdx_cap -- -- 0 1,0 adv_10gfdx_cap r- -- 0 1,0 en_10gfdx_cap -- -- 0 1,0 adv_5000fdx_cap r- -- 0 1,0 en_5000fdx_cap -- -- 0 1,0 adv_2500fdx_cap r- -- 0 1,0 en_2500fdx_cap -- -- 0 1,0 adv_1000fdx_cap r- 1 0 1,0 en_1000fdx_cap rw 1 0 1,0 adv_1000hdx_cap r- 0 0 1,0 en_1000hdx_cap rw 0 0 1,0 adv_100fdx_cap r- 1 0 1,0 en_100fdx_cap rw 1 1 1,0 adv_100hdx_cap r- 1 0 1,0 en_100hdx_cap rw 1 1 1,0 adv_10fdx_cap r- 1 0 1,0 en_10fdx_cap rw 1 1 1,0 adv_10hdx_cap r- 1 0 1,0 en_10hdx_cap rw 1 1 1,0 maxbw rw -- -- -- cpus rw -- -- -- cpus-effective r- 0-3 -- -- pool rw -- -- -- pool-effective r- -- -- -- priority rw high high low,medium,high tagmode rw vlanonly vlanonly normal,vlanonly forward rw 1 1 1,0 default_tag rw 1 1 -- learn_limit rw 1000 1000 -- PROPERTY PERM VALUE DEFAULT POSSIBLE learn_decay rw 200 200 -- stp rw 1 1 1,0 stp_priority rw 128 128 -- stp_cost rw auto auto -- stp_edge rw 1 1 1,0 stp_p2p rw auto auto true,false,auto stp_mcheck rw 0 0 1,0 protection rw -- -- mac-nospoof, restricted, ip-nospoof, dhcp-nospoof allowed-ips rw -- -- -- allowed-dhcp-cids rw -- -- -- rxrings rw -- -- -- rxrings-effective r- 1 -- -- txrings rw -- -- -- txrings-effective r- -- -- -- txrings-available r- 0 -- -- rxrings-available r- 0 -- -- rxhwclnt-available r- 0 -- -- txhwclnt-available r- 0 -- -- cpm@utu ~ % ipadm show-prop -c -o proto,property,perm,current,persistent,default,possible ipv4:forwarding:rw:off::off:on,off ipv4:ttl:rw:255::255:1-255 ipv6:forwarding:rw:off::off:on,off ipv6:hoplimit:rw:255::255:1-255 ipv6:hostmodel:rw:weak::weak:strong,src-priority,weak ipv4:hostmodel:rw:weak::weak:strong,src-priority,weak icmp:max_buf:rw:262144::262144:65536-1073741824 icmp:recv_buf:rw:8192::8192:4096-262144 icmp:send_buf:rw:8192::8192:4096-262144 tcp:ecn:rw:passive::passive:never,passive,active tcp:extra_priv_ports:rw:2049,4045::2049,4045:1-65535 tcp:largest_anon_port:rw:65535::65535:1024-65535 tcp:max_buf:rw:1048576::1048576:8192-1073741824 tcp:recv_buf:rw:128000::128000:2048-1048576 tcp:sack:rw:active::active:never,passive,active tcp:send_buf:rw:49152::49152:4096-1048576 tcp:smallest_anon_port:rw:32768::32768:1024-65535 tcp:smallest_nonpriv_port:rw:1024::1024:1024-32768 udp:extra_priv_ports:rw:2049,4045::2049,4045:1-65535 udp:largest_anon_port:rw:65535::65535:1024-65535 udp:max_buf:rw:2097152::2097152:65536-1073741824 udp:recv_buf:rw:57344::57344:128-2097152 udp:send_buf:rw:57344::57344:1024-2097152 udp:smallest_anon_port:rw:32768::32768:1024-65535 udp:smallest_nonpriv_port:rw:1024::1024:1024-32768 sctp:extra_priv_ports:rw:2049,4045::2049,4045:1-65535 sctp:largest_anon_port:rw:65535::65535:1024-65535 sctp:max_buf:rw:1048576::1048576:8192-1073741824 sctp:recv_buf:rw:102400::102400:8192-1048576 sctp:send_buf:rw:102400::102400:8192-1048576 sctp:smallest_anon_port:rw:32768::32768:1024-65535 sctp:smallest_nonpriv_port:rw:1024::1024:1024-32768
Updated by Electric Monk almost 3 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
git commit 519cca71df494bfdf951168b57893cdbe961647f
commit 519cca71df494bfdf951168b57893cdbe961647f Author: Sebastien Roy <seb@delphix.com> Date: 2019-08-19T22:32:45.000Z 11545 Want configurable output field separator for libofmt Portions contributed by: Cody Peter Mello <cody.mello@joyent.com> Reviewed by: Jason King <jason.king@joyent.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Richard Lowe <richlowe@richlowe.net>