Page MenuHomeFreeBSD

sockstat: Surround explicit IPv6 addresses with brackets
Needs ReviewPublic

Authored by michaelo on Fri, Dec 26, 6:26 PM.
Tags
None
Referenced Files
F140967468: D54375.diff
Tue, Dec 30, 5:17 AM
F140954786: D54375.diff
Tue, Dec 30, 1:53 AM
Unknown Object (File)
Sat, Dec 27, 8:29 AM
Subscribers

Details

Reviewers
otis
tuexen
des
Summary

PR: 254611
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 69480
Build 66363: arc lint + arc unit

Event Timeline

Have a patch locally for <=14 since code is different.
16-CURRENT:

# ./sockstat  -6
USER     COMMAND     PID FD PROTO LOCAL ADDRESS         FOREIGN ADDRESS
osipovmi sshd-sessi 2216  7 tcp6  [fe80::1%lo0]:22      [fe80::1%lo0]:52293
root     sshd-sessi 2213  7 tcp6  [fe80::1%lo0]:22      [fe80::1%lo0]:52293
osipovmi ssh        2212  3 tcp6  [fe80::1%lo0]:52293   [fe80::1%lo0]:22
root     sshd       1310  6 tcp6  *:22                  *:*
root     ntpd       1233 21 udp6  [::1]:123             *:*
root     ntpd       1233 22 udp6  [fe80::1%lo0]:123     *:*
root     rpc.statd  1061  4 udp6  *:934                 *:*
root     rpc.statd  1061  5 tcp6  *:934                 *:*
root     rpcbind    1059  8 udp6  *:111                 *:*
root     rpcbind    1059  9 udp6  *:868                 *:*
root     rpcbind    1059 10 tcp6  *:111                 *:*
root     rpcbind    1059 16 udp6  *:*                   *:*
??       ??           ?? ?? tcp6  *:887                 *:*
??       ??           ?? ?? udp6  *:931                 *:*
??       ??           ?? ?? udp6  *:652                 *:*

13-STABLE:

$ ./sockstat -6
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
osipovmi nc         33276 3  tcp6   [fe80::1%lo0]:6000    *:*
root     master     69090 14 tcp6   *:25                  *:*
postgres postgres   1948  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1947  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1932  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1931  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1930  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1929  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1928  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1927  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1926  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1925  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1924  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1923  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1922  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1921  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1920  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1919  9  tcp6   [::1]:10051           *:*
postgres postgres   1918  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1917  9  tcp6   [::1]:10051           *:*
postgres postgres   1916  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1915  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1914  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1913  9  tcp6   [::1]:10051           *:*
postgres postgres   1912  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1911  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1910  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1909  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1908  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1907  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1906  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1905  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1904  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1903  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1902  9  tcp6   [::1]:10051           *:*
postgres postgres   1901  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1900  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1899  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1898  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1896  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1895  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1894  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1893  9  tcp6   [::1]:10051           *:*
postgres postgres   1891  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1889  9  tcp6   [::1]:10051           *:*
postgres postgres   1887  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1885  9  tcp6   [::1]:10051           *:*
postgres postgres   1884  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1883  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1882  9  tcp6   [::1]:10051           *:*
postgres postgres   1881  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1880  9  tcp6   [::1]:10051           *:*
postgres postgres   1879  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1877  9  tcp6   [::1]:10051           *:*
postgres postgres   1876  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1875  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1873  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1872  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1870  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1869  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1868  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1867  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1866  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1865  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1864  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1863  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1862  9  tcp6   [::1]:10051           *:*
postgres postgres   1861  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1860  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1859  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1858  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1857  9  tcp6   [::1]:10051           *:*
postgres postgres   1820  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1818  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_ser 1817  9  tcp6   [::1]:10051           *:*
zabbix   zabbix_ser 1816  9  tcp6   [::1]:10051           *:*
postgres postgres   1801  9  udp6   [::1]:51742           [::1]:51742
root     sshd       1782  7  tcp6   *:22                  *:*
root     nfsd       1737  6  tcp6   *:2049                *:*
zabbix   zabbix_ser 1729  9  tcp6   [::1]:10051           *:*
root     mountd     1698  7  udp6   *:958                 *:*
root     mountd     1698  8  tcp6   *:958                 *:*
postgres postgres   1691  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1690  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1689  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1688  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1687  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1686  9  udp6   [::1]:51742           [::1]:51742
postgres postgres   1684  6  tcp6   [::1]:5432            *:*
postgres postgres   1684  9  udp6   [::1]:51742           [::1]:51742
zabbix   zabbix_age 1681  5  tcp6   *:10050               *:*
zabbix   zabbix_age 1680  5  tcp6   *:10050               *:*
zabbix   zabbix_age 1679  5  tcp6   *:10050               *:*
zabbix   zabbix_age 1678  5  tcp6   *:10050               *:*
zabbix   zabbix_age 1677  5  tcp6   *:10050               *:*
zabbix   zabbix_age 1668  5  tcp6   *:10050               *:*
root     ntpd       1660  21 udp6   [::1]:123             *:*
root     ntpd       1660  22 udp6   [fe80::1%lo0]:123     *:*
root     rpc.statd  1582  4  udp6   *:871                 *:*
root     rpc.statd  1582  5  tcp6   *:871                 *:*
root     rpcbind    1570  6  udp6   *:111                 *:*
root     rpcbind    1570  7  udp6   *:740                 *:*
root     rpcbind    1570  8  tcp6   *:111                 *:*
root     rpcbind    1570  13 udp6   *:*                   *:*
?        ?          ?     ?  udp6   *:2049                *:*
?        ?          ?     ?  tcp6   *:801                 *:*
?        ?          ?     ?  udp6   *:605                 *:*
?        ?          ?     ?  udp6   *:841                 *:*

Would it make sense to use the same way as netstat for consistency? This would mean to use . instead of : and no brackets.

Would it make sense to use the same way as netstat for consistency? This would mean to use . instead of : and no brackets.

I honestly must say that I never understood why netstat uses a dot to separate both components while the rest of the world uses colon. I wouldn't apply netstat's logic here.

This revision is now accepted and ready to land.Fri, Dec 26, 8:29 PM

I'd also say des@ should have a look as he's the author of sockstat. For me, I'm all in for this proposed change.

des requested changes to this revision.Mon, Dec 29, 12:14 PM

I did indeed write sockstat(8) but I did not write (most of) formataddr(), and I certainly would not have approved it if asked to review it.

usr.bin/sockstat/main.c
929
930
947–948
949
963
969

I would prefer a solution that ensures addrstr already contains brackets at this point.

971
972
This revision now requires changes to proceed.Mon, Dec 29, 12:14 PM

@des, thanks for the review. I don't want to modify code which I didn't touch. This can be done in a subsequent change.

usr.bin/sockstat/main.c
969

Are you sure because the address itself does not require square brackets, it is only required if it is not * or a port is present? I can easily connect to ssh fe80::1%lo0 if I don't need to the port. The brackets aren't part of the address.

michaelo marked an inline comment as not done.Mon, Dec 29, 5:01 PM
michaelo added inline comments.
usr.bin/sockstat/main.c
969

Moreover, if addrstr is modified *before* is_xo_style_encoding is evaluated then {:address/%s} will contain incorrectly bracketed data.

michaelo marked an inline comment as not done.Mon, Dec 29, 5:08 PM
michaelo added inline comments.
usr.bin/sockstat/main.c
969

Reference: https://datatracker.ietf.org/doc/html/rfc5952#section-6

It truly only applies when a port is in play.