Consistently use the SOLISTENING() macro
Some code was using it already, but in many places we were testing SO_ACCEPTCONN directly. As a small step towards fixing some bugs involving synchronization with listen(2), make the kernel consistently use SOLISTENING(). No functional change intended. MFC after: 1 week Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
70dd5eebc0
commit
f4bb1869dd
@ -1482,7 +1482,7 @@ hvsock_open_conn_passive(struct vmbus_channel *chan, struct socket *so,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
/* Do nothing if socket is not listening */
|
/* Do nothing if socket is not listening */
|
||||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
if (!SOLISTENING(so)) {
|
||||||
HVSOCK_DBG(HVSOCK_DBG_ERR,
|
HVSOCK_DBG(HVSOCK_DBG_ERR,
|
||||||
"%s: socket is not a listening one\n", __func__);
|
"%s: socket is not a listening one\n", __func__);
|
||||||
return;
|
return;
|
||||||
|
@ -172,7 +172,7 @@ accept_filt_getopt(struct socket *so, struct sockopt *sopt)
|
|||||||
error = 0;
|
error = 0;
|
||||||
afap = malloc(sizeof(*afap), M_TEMP, M_WAITOK | M_ZERO);
|
afap = malloc(sizeof(*afap), M_TEMP, M_WAITOK | M_ZERO);
|
||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
if (!SOLISTENING(so)) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ accept_filt_setopt(struct socket *so, struct sockopt *sopt)
|
|||||||
int wakeup;
|
int wakeup;
|
||||||
|
|
||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
if (!SOLISTENING(so)) {
|
||||||
SOCK_UNLOCK(so);
|
SOCK_UNLOCK(so);
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
}
|
}
|
||||||
@ -278,8 +278,7 @@ accept_filt_setopt(struct socket *so, struct sockopt *sopt)
|
|||||||
* without first removing it.
|
* without first removing it.
|
||||||
*/
|
*/
|
||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
if ((so->so_options & SO_ACCEPTCONN) == 0 ||
|
if (!SOLISTENING(so) || so->sol_accept_filter != NULL) {
|
||||||
so->sol_accept_filter != NULL) {
|
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1180,7 +1180,6 @@ int
|
|||||||
soclose(struct socket *so)
|
soclose(struct socket *so)
|
||||||
{
|
{
|
||||||
struct accept_queue lqueue;
|
struct accept_queue lqueue;
|
||||||
bool listening;
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter"));
|
KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter"));
|
||||||
@ -1216,7 +1215,7 @@ soclose(struct socket *so)
|
|||||||
(*so->so_proto->pr_usrreqs->pru_close)(so);
|
(*so->so_proto->pr_usrreqs->pru_close)(so);
|
||||||
|
|
||||||
SOCK_LOCK(so);
|
SOCK_LOCK(so);
|
||||||
if ((listening = (so->so_options & SO_ACCEPTCONN))) {
|
if (SOLISTENING(so)) {
|
||||||
struct socket *sp;
|
struct socket *sp;
|
||||||
|
|
||||||
TAILQ_INIT(&lqueue);
|
TAILQ_INIT(&lqueue);
|
||||||
@ -1237,7 +1236,7 @@ soclose(struct socket *so)
|
|||||||
KASSERT((so->so_state & SS_NOFDREF) == 0, ("soclose: NOFDREF"));
|
KASSERT((so->so_state & SS_NOFDREF) == 0, ("soclose: NOFDREF"));
|
||||||
so->so_state |= SS_NOFDREF;
|
so->so_state |= SS_NOFDREF;
|
||||||
sorele(so);
|
sorele(so);
|
||||||
if (listening) {
|
if (SOLISTENING(so)) {
|
||||||
struct socket *sp, *tsp;
|
struct socket *sp, *tsp;
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(sp, &lqueue, so_list, tsp) {
|
TAILQ_FOREACH_SAFE(sp, &lqueue, so_list, tsp) {
|
||||||
@ -1317,7 +1316,8 @@ soconnectat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (so->so_options & SO_ACCEPTCONN)
|
/* XXXMJ racy */
|
||||||
|
if (SOLISTENING(so))
|
||||||
return (EOPNOTSUPP);
|
return (EOPNOTSUPP);
|
||||||
|
|
||||||
CURVNET_SET(so->so_vnet);
|
CURVNET_SET(so->so_vnet);
|
||||||
|
@ -338,7 +338,7 @@ kern_accept4(struct thread *td, int s, struct sockaddr **name,
|
|||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
head = headfp->f_data;
|
head = headfp->f_data;
|
||||||
if ((head->so_options & SO_ACCEPTCONN) == 0) {
|
if (!SOLISTENING(head)) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1603,7 +1603,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
|
|||||||
goto bad2;
|
goto bad2;
|
||||||
}
|
}
|
||||||
if (connreq) {
|
if (connreq) {
|
||||||
if (so2->so_options & SO_ACCEPTCONN) {
|
if (SOLISTENING(so2)) {
|
||||||
CURVNET_SET(so2->so_vnet);
|
CURVNET_SET(so2->so_vnet);
|
||||||
so2 = sonewconn(so2, 0);
|
so2 = sonewconn(so2, 0);
|
||||||
CURVNET_RESTORE();
|
CURVNET_RESTORE();
|
||||||
|
@ -2733,8 +2733,7 @@ ng_btsocket_l2cap_pcb_by_addr(bdaddr_p bdaddr, int psm)
|
|||||||
mtx_assert(&ng_btsocket_l2cap_sockets_mtx, MA_OWNED);
|
mtx_assert(&ng_btsocket_l2cap_sockets_mtx, MA_OWNED);
|
||||||
|
|
||||||
LIST_FOREACH(p, &ng_btsocket_l2cap_sockets, next) {
|
LIST_FOREACH(p, &ng_btsocket_l2cap_sockets, next) {
|
||||||
if (p->so == NULL || !(p->so->so_options & SO_ACCEPTCONN) ||
|
if (p->so == NULL || !SOLISTENING(p->so) || p->psm != psm)
|
||||||
p->psm != psm)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bcmp(&p->src, bdaddr, sizeof(p->src)) == 0)
|
if (bcmp(&p->src, bdaddr, sizeof(p->src)) == 0)
|
||||||
|
@ -3398,8 +3398,7 @@ ng_btsocket_rfcomm_pcb_listener(bdaddr_p src, int channel)
|
|||||||
mtx_lock(&ng_btsocket_rfcomm_sockets_mtx);
|
mtx_lock(&ng_btsocket_rfcomm_sockets_mtx);
|
||||||
|
|
||||||
LIST_FOREACH(pcb, &ng_btsocket_rfcomm_sockets, next) {
|
LIST_FOREACH(pcb, &ng_btsocket_rfcomm_sockets, next) {
|
||||||
if (pcb->channel != channel ||
|
if (pcb->channel != channel || !SOLISTENING(pcb->so))
|
||||||
!(pcb->so->so_options & SO_ACCEPTCONN))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bcmp(&pcb->src, src, sizeof(*src)) == 0)
|
if (bcmp(&pcb->src, src, sizeof(*src)) == 0)
|
||||||
|
@ -1829,7 +1829,7 @@ ng_btsocket_sco_pcb_by_addr(bdaddr_p bdaddr)
|
|||||||
LIST_FOREACH(p, &ng_btsocket_sco_sockets, next) {
|
LIST_FOREACH(p, &ng_btsocket_sco_sockets, next) {
|
||||||
mtx_lock(&p->pcb_mtx);
|
mtx_lock(&p->pcb_mtx);
|
||||||
|
|
||||||
if (p->so == NULL || !(p->so->so_options & SO_ACCEPTCONN)) {
|
if (p->so == NULL || !SOLISTENING(p->so)) {
|
||||||
mtx_unlock(&p->pcb_mtx);
|
mtx_unlock(&p->pcb_mtx);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -955,8 +955,7 @@ tcp_input_with_port(struct mbuf **mp, int *offp, int proto, uint16_t port)
|
|||||||
}
|
}
|
||||||
if ((inp->inp_flowtype == M_HASHTYPE_NONE) &&
|
if ((inp->inp_flowtype == M_HASHTYPE_NONE) &&
|
||||||
(M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) &&
|
(M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) &&
|
||||||
((inp->inp_socket == NULL) ||
|
((inp->inp_socket == NULL) || !SOLISTENING(inp->inp_socket))) {
|
||||||
(inp->inp_socket->so_options & SO_ACCEPTCONN) == 0)) {
|
|
||||||
inp->inp_flowid = m->m_pkthdr.flowid;
|
inp->inp_flowid = m->m_pkthdr.flowid;
|
||||||
inp->inp_flowtype = M_HASHTYPE_GET(m);
|
inp->inp_flowtype = M_HASHTYPE_GET(m);
|
||||||
}
|
}
|
||||||
@ -1055,9 +1054,9 @@ tcp_input_with_port(struct mbuf **mp, int *offp, int proto, uint16_t port)
|
|||||||
* state) we look into the SYN cache if this is a new connection
|
* state) we look into the SYN cache if this is a new connection
|
||||||
* attempt or the completion of a previous one.
|
* attempt or the completion of a previous one.
|
||||||
*/
|
*/
|
||||||
KASSERT(tp->t_state == TCPS_LISTEN || !(so->so_options & SO_ACCEPTCONN),
|
KASSERT(tp->t_state == TCPS_LISTEN || !SOLISTENING(so),
|
||||||
("%s: so accepting but tp %p not listening", __func__, tp));
|
("%s: so accepting but tp %p not listening", __func__, tp));
|
||||||
if (tp->t_state == TCPS_LISTEN && (so->so_options & SO_ACCEPTCONN)) {
|
if (tp->t_state == TCPS_LISTEN && SOLISTENING(so)) {
|
||||||
struct in_conninfo inc;
|
struct in_conninfo inc;
|
||||||
|
|
||||||
bzero(&inc, sizeof(inc));
|
bzero(&inc, sizeof(inc));
|
||||||
|
@ -3696,8 +3696,8 @@ sysctl_drop(SYSCTL_HANDLER_ARGS)
|
|||||||
tcp_twclose(tw, 0);
|
tcp_twclose(tw, 0);
|
||||||
else
|
else
|
||||||
INP_WUNLOCK(inp);
|
INP_WUNLOCK(inp);
|
||||||
} else if (!(inp->inp_flags & INP_DROPPED) &&
|
} else if ((inp->inp_flags & INP_DROPPED) == 0 &&
|
||||||
!(inp->inp_socket->so_options & SO_ACCEPTCONN)) {
|
!SOLISTENING(inp->inp_socket)) {
|
||||||
tp = intotcpcb(inp);
|
tp = intotcpcb(inp);
|
||||||
tp = tcp_drop(tp, ECONNABORTED);
|
tp = tcp_drop(tp, ECONNABORTED);
|
||||||
if (tp != NULL)
|
if (tp != NULL)
|
||||||
|
@ -329,7 +329,7 @@ svc_vc_accept(struct socket *head, struct socket **sop)
|
|||||||
short nbio;
|
short nbio;
|
||||||
|
|
||||||
/* XXXGL: shouldn't that be an assertion? */
|
/* XXXGL: shouldn't that be an assertion? */
|
||||||
if ((head->so_options & SO_ACCEPTCONN) == 0) {
|
if (!SOLISTENING(head)) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user