Date: Wed, 22 Apr 2020 17:32:21 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 245817] sendto() can return ENOTCONN on SOCK_STREAM unix socket, which is not documented Message-ID: <bug-245817-227-bhJXRlHKOo@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-245817-227@https.bugs.freebsd.org/bugzilla/> References: <bug-245817-227@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D245817 --- Comment #2 from Mark Johnston <markj@FreeBSD.org> --- I see. The SOCK_STREAM/SEQPACKET unix socket protocol descriptions set PR_CONNREQUIRED, which effectively disables sendto()/sendmsg() on unconnect= ed unix sockets. That is surprising since uipc_send() has explicit handling f= or that: 1137 case SOCK_SEQPACKET:=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 1138 case SOCK_STREAM:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 1139 if ((so->so_state & SS_ISCONNECTED) =3D=3D 0) {=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 1140 if (nam !=3D NULL) {=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1141 error =3D connect_internal(so, nam, td= );=20=20=20=20=20 1142 if (error !=3D 0)=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1143 break;=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1144 } else {=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 1145 error =3D ENOTCONN;=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1146 break;=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 1147 }=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 1148 } else {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20 1149 UNP_PCB_LOCK(unp);=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1150 } I think we can probably just clear PR_CONNREQUIRED for unix sockets. Thoug= h, I think we should indeed document ENOTCONN as a possible error for sendto() a= nd sendmsg(). It is documented here for instance: https://pubs.opengroup.org/onlinepubs/009695399/functions/sendto.html Also weird is this fragment in sosend_generic(): 1626 /*=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 1627 * `sendto' and `sendmsg' is allowed on a connection-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1628 * based socket if it supports implied connect= .=20=20=20=20 1629 * Return ENOTCONN if not connected and no add= ress is=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 1630 * supplied.=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 1631 */=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20 1632 if ((so->so_proto->pr_flags & PR_CONNREQUIRED)= &&=20=20 1633 (so->so_proto->pr_flags & PR_IMPLOPCL) =3D= =3D 0) {=20 1634 if ((so->so_state & SS_ISCONFIRMING) = =3D=3D 0 &&=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 1635 !(resid =3D=3D 0 && clen !=3D 0)) = {=20=20=20=20=20=20=20=20=20=20 1636 SOCKBUF_UNLOCK(&so->so_snd);= =20=20=20=20=20=20=20 1637 error =3D ENOTCONN;=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1638 goto release;=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 1639 } Specifically, the !(resid =3D=3D 0 && clen !=3D 0) check: we only return an= error if we are trying to send data and there is no control message. So, we *can* se= nd control messages over unconnected stream sockets even if CONNREQUIRED is se= t. Does any protocol except PF_LOCAL handle control messages to begin with? --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-245817-227-bhJXRlHKOo>