Page MenuHomeFreeBSD

sockstat: fix column length for PROTO
ClosedPublic

Authored by tuexen on Oct 20 2025, 10:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 15, 12:37 AM
Unknown Object (File)
Sat, Dec 6, 9:02 PM
Unknown Object (File)
Tue, Dec 2, 10:38 AM
Unknown Object (File)
Mon, Dec 1, 12:05 AM
Unknown Object (File)
Nov 26 2025, 6:01 PM
Unknown Object (File)
Nov 26 2025, 1:31 AM
Unknown Object (File)
Nov 22 2025, 4:18 PM
Unknown Object (File)
Nov 16 2025, 12:43 PM
Subscribers

Details

Summary

The computation of the length was not taking into account that IPv6 endpoints, which are not IPv6 only, have a suffix of 46.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Can you give an example of the incorrect output? Does it matter whether "-q" is in use?

Can you give an example of the incorrect output? Does it matter whether "-q" is in use?

Here is the output without the fix:

tuexen@ampere32:~ % sockstat -Psctp
USER   COMMAND     PID FD PROTO LOCAL ADDRESS         FOREIGN ADDRESS      
nobody thttpd     3572  4 sctp46 10.0.1.86:80          *:*                  
??     ??           ?? ?? ??    192.168.1.86:80       ??                   
??     ??           ?? ?? ??    2a02:c6a0:4015:11::86 ??                   
??     ??           ?? ?? ??    fe80::6a05:caff:fe92: ??                   
??     ??           ?? ?? ??    212.201.121.86:80     ??                   
??     ??           ?? ?? ??    127.0.0.1:80          ??                   
??     ??           ?? ?? ??    fe80::1%lo0:80        ??                   
??     ??           ?? ?? ??    ::1:80                ??

Here is the output without the fix and using -q:

tuexen@ampere32:~ % sockstat -qPsctp
nobody thttpd     3572  4 sctp46 10.0.1.86:80          *:*                  
??     ??           ?? ?? ??    192.168.1.86:80       ??                   
??     ??           ?? ?? ??    2a02:c6a0:4015:11::86 ??                   
??     ??           ?? ?? ??    fe80::6a05:caff:fe92: ??                   
??     ??           ?? ?? ??    212.201.121.86:80     ??                   
??     ??           ?? ?? ??    127.0.0.1:80          ??                   
??     ??           ?? ?? ??    fe80::1%lo0:80        ??                   
??     ??           ?? ?? ??    ::1:80                ??

In both cases the problem is that sctp46 is too long and you have the misalignment in the first row. In case sctp4 and sctp6 it would look OK.
With the fix the output is:

tuexen@ampere32:~ % sockstat -Psctp
USER   COMMAND     PID FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
nobody thttpd     3572  4 sctp46 10.0.1.86:80          *:*                  
??     ??           ?? ?? ??     192.168.1.86:80       ??                   
??     ??           ?? ?? ??     2a02:c6a0:4015:11::86 ??                   
??     ??           ?? ?? ??     fe80::6a05:caff:fe92: ??                   
??     ??           ?? ?? ??     212.201.121.86:80     ??                   
??     ??           ?? ?? ??     127.0.0.1:80          ??                   
??     ??           ?? ?? ??     fe80::1%lo0:80        ??                   
??     ??           ?? ?? ??     ::1:80                ??

The problem is that the PROTO column is computed with:

snprintf(buf, bufsize, "%s%s%s",
        s->protoname,
        s->vflag & INP_IPV4 ? "4" : "",
        s->vflag & INP_IPV6 ? "6" : "");

whereas the length is computed by:

len = strlen(s->protoname);
if (s->vflag & (INP_IPV4 | INP_IPV6))
        len += 1;

So in the 46 case, you are off by one character.

That explains it. I was never testing with SCTP, and I doubt that Damin was, either.

This revision is now accepted and ready to land.Oct 20 2025, 1:31 PM

That explains it. I was never testing with SCTP, and I doubt that Damin was, either.

the same issue will come up with udplite (udplite4, udplite6, and udplite46), since the protocol name can be longer than PROTO.
I plan to add this soon.

This revision was automatically updated to reflect the committed changes.