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;
|
||||
|
||||
/* Do nothing if socket is not listening */
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
||||
if (!SOLISTENING(so)) {
|
||||
HVSOCK_DBG(HVSOCK_DBG_ERR,
|
||||
"%s: socket is not a listening one\n", __func__);
|
||||
return;
|
||||
|
@ -172,7 +172,7 @@ accept_filt_getopt(struct socket *so, struct sockopt *sopt)
|
||||
error = 0;
|
||||
afap = malloc(sizeof(*afap), M_TEMP, M_WAITOK | M_ZERO);
|
||||
SOCK_LOCK(so);
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
||||
if (!SOLISTENING(so)) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@ -208,7 +208,7 @@ accept_filt_setopt(struct socket *so, struct sockopt *sopt)
|
||||
int wakeup;
|
||||
|
||||
SOCK_LOCK(so);
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
||||
if (!SOLISTENING(so)) {
|
||||
SOCK_UNLOCK(so);
|
||||
return (EINVAL);
|
||||
}
|
||||
@ -278,8 +278,7 @@ accept_filt_setopt(struct socket *so, struct sockopt *sopt)
|
||||
* without first removing it.
|
||||
*/
|
||||
SOCK_LOCK(so);
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0 ||
|
||||
so->sol_accept_filter != NULL) {
|
||||
if (!SOLISTENING(so) || so->sol_accept_filter != NULL) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -1180,7 +1180,6 @@ int
|
||||
soclose(struct socket *so)
|
||||
{
|
||||
struct accept_queue lqueue;
|
||||
bool listening;
|
||||
int error = 0;
|
||||
|
||||
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);
|
||||
|
||||
SOCK_LOCK(so);
|
||||
if ((listening = (so->so_options & SO_ACCEPTCONN))) {
|
||||
if (SOLISTENING(so)) {
|
||||
struct socket *sp;
|
||||
|
||||
TAILQ_INIT(&lqueue);
|
||||
@ -1237,7 +1236,7 @@ soclose(struct socket *so)
|
||||
KASSERT((so->so_state & SS_NOFDREF) == 0, ("soclose: NOFDREF"));
|
||||
so->so_state |= SS_NOFDREF;
|
||||
sorele(so);
|
||||
if (listening) {
|
||||
if (SOLISTENING(so)) {
|
||||
struct socket *sp, *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;
|
||||
|
||||
if (so->so_options & SO_ACCEPTCONN)
|
||||
/* XXXMJ racy */
|
||||
if (SOLISTENING(so))
|
||||
return (EOPNOTSUPP);
|
||||
|
||||
CURVNET_SET(so->so_vnet);
|
||||
|
@ -338,7 +338,7 @@ kern_accept4(struct thread *td, int s, struct sockaddr **name,
|
||||
if (error != 0)
|
||||
return (error);
|
||||
head = headfp->f_data;
|
||||
if ((head->so_options & SO_ACCEPTCONN) == 0) {
|
||||
if (!SOLISTENING(head)) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
@ -1603,7 +1603,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam,
|
||||
goto bad2;
|
||||
}
|
||||
if (connreq) {
|
||||
if (so2->so_options & SO_ACCEPTCONN) {
|
||||
if (SOLISTENING(so2)) {
|
||||
CURVNET_SET(so2->so_vnet);
|
||||
so2 = sonewconn(so2, 0);
|
||||
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);
|
||||
|
||||
LIST_FOREACH(p, &ng_btsocket_l2cap_sockets, next) {
|
||||
if (p->so == NULL || !(p->so->so_options & SO_ACCEPTCONN) ||
|
||||
p->psm != psm)
|
||||
if (p->so == NULL || !SOLISTENING(p->so) || p->psm != psm)
|
||||
continue;
|
||||
|
||||
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);
|
||||
|
||||
LIST_FOREACH(pcb, &ng_btsocket_rfcomm_sockets, next) {
|
||||
if (pcb->channel != channel ||
|
||||
!(pcb->so->so_options & SO_ACCEPTCONN))
|
||||
if (pcb->channel != channel || !SOLISTENING(pcb->so))
|
||||
continue;
|
||||
|
||||
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) {
|
||||
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);
|
||||
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) &&
|
||||
(M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) &&
|
||||
((inp->inp_socket == NULL) ||
|
||||
(inp->inp_socket->so_options & SO_ACCEPTCONN) == 0)) {
|
||||
((inp->inp_socket == NULL) || !SOLISTENING(inp->inp_socket))) {
|
||||
inp->inp_flowid = m->m_pkthdr.flowid;
|
||||
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
|
||||
* 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));
|
||||
if (tp->t_state == TCPS_LISTEN && (so->so_options & SO_ACCEPTCONN)) {
|
||||
if (tp->t_state == TCPS_LISTEN && SOLISTENING(so)) {
|
||||
struct in_conninfo inc;
|
||||
|
||||
bzero(&inc, sizeof(inc));
|
||||
|
@ -3696,8 +3696,8 @@ sysctl_drop(SYSCTL_HANDLER_ARGS)
|
||||
tcp_twclose(tw, 0);
|
||||
else
|
||||
INP_WUNLOCK(inp);
|
||||
} else if (!(inp->inp_flags & INP_DROPPED) &&
|
||||
!(inp->inp_socket->so_options & SO_ACCEPTCONN)) {
|
||||
} else if ((inp->inp_flags & INP_DROPPED) == 0 &&
|
||||
!SOLISTENING(inp->inp_socket)) {
|
||||
tp = intotcpcb(inp);
|
||||
tp = tcp_drop(tp, ECONNABORTED);
|
||||
if (tp != NULL)
|
||||
|
@ -329,7 +329,7 @@ svc_vc_accept(struct socket *head, struct socket **sop)
|
||||
short nbio;
|
||||
|
||||
/* XXXGL: shouldn't that be an assertion? */
|
||||
if ((head->so_options & SO_ACCEPTCONN) == 0) {
|
||||
if (!SOLISTENING(head)) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user