On Sun, Dec 11, 2022 at 07:55:44PM -0700, Theo de Raadt wrote:
> The problem you have introduced is that so_state is copied from sockets
> to a sysctl record, where it also shows up as so_state.
> 
> At least fstat(8) looks at this field, and uses the old SS_CANTSENDMORE
> bit you have deleted.  The userland-visible name change is an API break.
> Furthermore you moved it, but your new so_snd.sb_state value is not
> exported in sysctl, and if we add this to sysctl it will be quite a big
> ABI break.  I suspect that is too expensive.
> 
> So what you need to here is leave the SS_* bits with their existing names.
> You cannot change their names.  It is exported API.  You cannot change their
> bit values either, it is exported ABI in sysctl.
> 
> What you can do is optionally use some bits in the socket, some bits in
> so_snd, and some bits in so_rcv (I assume that is the future).  And then
> in kern_sysctl.c around line 1187 you can merge the bits, since they are
> still unique:
> 
>        kf->so_state = so->so_state | so->so_snd.sb_state | so->so_rcv.sb_state
> 
> This will mean fstat can see all the bits in the one sysctl sub-variable.
> 
> It means you must go very quickly rename, or you should consider backing
> your commit out and trying again fresh.
> 

`sb_state' will contain some new bits so I guess it's better to restote
old SS_CANTSENDMORE and set it if SBS_CANTSENDMORE is set:

Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.408
diff -u -p -r1.408 kern_sysctl.c
--- sys/kern/kern_sysctl.c      7 Nov 2022 14:25:44 -0000       1.408
+++ sys/kern/kern_sysctl.c      12 Dec 2022 07:31:26 -0000
@@ -1185,6 +1185,8 @@ fill_file(struct kinfo_file *kf, struct 
 
                kf->so_type = so->so_type;
                kf->so_state = so->so_state;
+               if (so->so_rcv.sb_state & SBS_CANTSENDMORE)
+                       kf->so_state |= SS_CANTSENDMORE;
                if (show_pointers)
                        kf->so_pcb = PTRTOINT64(so->so_pcb);
                else
Index: sys/sys/socketvar.h
===================================================================
RCS file: /cvs/src/sys/sys/socketvar.h,v
retrieving revision 1.113
diff -u -p -r1.113 socketvar.h
--- sys/sys/socketvar.h 11 Dec 2022 21:19:08 -0000      1.113
+++ sys/sys/socketvar.h 12 Dec 2022 07:31:26 -0000
@@ -149,6 +149,7 @@ struct socket {
 #define        SS_ISCONNECTED          0x002   /* socket connected to a peer */
 #define        SS_ISCONNECTING         0x004   /* in process of connecting to 
peer */
 #define        SS_ISDISCONNECTING      0x008   /* in process of disconnecting 
*/
+#define SS_CANTSENDMORE                0x010   /* can't send more data to peer 
*/
 #define        SS_CANTRCVMORE          0x020   /* can't receive more data from 
peer */
 #define        SS_RCVATMARK            0x040   /* at mark on input */
 #define        SS_ISDISCONNECTED       0x800   /* socket disconnected from 
peer */

Reply via email to