Push the assignment of a new or updated so_qlimit from solisten()

following the protocol pru_listen() call to solisten_proto(), so
that it occurs under the socket lock acquisition that also sets
SO_ACCEPTCONN.  This requires passing the new backlog parameter
to the protocol, which also allows the protocol to be aware of
changes in queue limit should it wish to do something about the
new queue limit.  This continues a move towards the socket layer
acting as a library for the protocol.

Bump __FreeBSD_version due to a change in the in-kernel protocol
interface.  This change has been tested with IPv4 and UNIX domain
sockets, but not other protocols.
This commit is contained in:
rwatson 2005-10-30 19:44:40 +00:00
parent 1d93f083bf
commit 49831ed8da
18 changed files with 49 additions and 49 deletions

View File

@ -1340,7 +1340,7 @@ pru_disconnect_notsupp(struct socket *so)
}
int
pru_listen_notsupp(struct socket *so, struct thread *td)
pru_listen_notsupp(struct socket *so, int backlog, struct thread *td)
{
return EOPNOTSUPP;
}

View File

@ -294,21 +294,8 @@ solisten(so, backlog, td)
int backlog;
struct thread *td;
{
int error;
error = (*so->so_proto->pr_usrreqs->pru_listen)(so, td);
if (error)
return (error);
/*
* XXXRW: The following state adjustment should occur in
* solisten_proto(), but we don't currently pass the backlog request
* to the protocol via pru_listen().
*/
if (backlog < 0 || backlog > somaxconn)
backlog = somaxconn;
so->so_qlimit = backlog;
return (0);
return ((*so->so_proto->pr_usrreqs->pru_listen)(so, backlog, td));
}
int
@ -325,12 +312,16 @@ solisten_proto_check(so)
}
void
solisten_proto(so)
solisten_proto(so, backlog)
struct socket *so;
int backlog;
{
SOCK_LOCK_ASSERT(so);
if (backlog < 0 || backlog > somaxconn)
backlog = somaxconn;
so->so_qlimit = backlog;
so->so_options |= SO_ACCEPTCONN;
}

View File

@ -1340,7 +1340,7 @@ pru_disconnect_notsupp(struct socket *so)
}
int
pru_listen_notsupp(struct socket *so, struct thread *td)
pru_listen_notsupp(struct socket *so, int backlog, struct thread *td)
{
return EOPNOTSUPP;
}

View File

@ -126,7 +126,8 @@ static void unp_mark(struct file *);
static void unp_discard(struct file *);
static void unp_freerights(struct file **, int);
static int unp_internalize(struct mbuf **, struct thread *);
static int unp_listen(struct socket *, struct unpcb *, struct thread *);
static int unp_listen(struct socket *, struct unpcb *, int,
struct thread *);
static int
uipc_abort(struct socket *so)
@ -275,7 +276,7 @@ uipc_disconnect(struct socket *so)
}
static int
uipc_listen(struct socket *so, struct thread *td)
uipc_listen(struct socket *so, int backlog, struct thread *td)
{
struct unpcb *unp;
int error;
@ -286,7 +287,7 @@ uipc_listen(struct socket *so, struct thread *td)
UNP_UNLOCK();
return (EINVAL);
}
error = unp_listen(so, unp, td);
error = unp_listen(so, unp, backlog, td);
UNP_UNLOCK();
return (error);
}
@ -1803,7 +1804,8 @@ unp_dispose(struct mbuf *m)
}
static int
unp_listen(struct socket *so, struct unpcb *unp, struct thread *td)
unp_listen(struct socket *so, struct unpcb *unp, int backlog,
struct thread *td)
{
int error;
@ -1814,7 +1816,7 @@ unp_listen(struct socket *so, struct unpcb *unp, struct thread *td)
if (error == 0) {
cru2x(td->td_ucred, &unp->unp_peercred);
unp->unp_flags |= UNP_HAVEPCCACHED;
solisten_proto(so);
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
return (error);

View File

@ -69,7 +69,8 @@ static int atm_aal5_attach(struct socket *, int, struct thread *td);
static int atm_aal5_detach(struct socket *);
static int atm_aal5_bind(struct socket *, struct sockaddr *,
struct thread *td);
static int atm_aal5_listen(struct socket *, struct thread *td);
static int atm_aal5_listen(struct socket *, int backlog,
struct thread *td);
static int atm_aal5_connect(struct socket *, struct sockaddr *,
struct thread *td);
static int atm_aal5_accept(struct socket *, struct sockaddr **);
@ -328,13 +329,14 @@ atm_aal5_bind(so, addr, td)
*
*/
static int
atm_aal5_listen(so, td)
atm_aal5_listen(so, backlog, td)
struct socket *so;
int backlog;
struct thread *td;
{
ATM_INTRO("listen");
err = atm_sock_listen(so, &atm_aal5_endpt);
err = atm_sock_listen(so, &atm_aal5_endpt, backlog);
ATM_OUTRO();
}

View File

@ -536,12 +536,13 @@ done:
*
*/
int
atm_cm_listen(so, epp, token, ap, copp)
atm_cm_listen(so, epp, token, ap, copp, backlog)
struct socket *so;
Atm_endpoint *epp;
void *token;
Atm_attributes *ap;
Atm_connection **copp;
int backlog;
{
Atm_connection *cop;
int s, err = 0;
@ -737,7 +738,7 @@ atm_cm_listen(so, epp, token, ap, copp)
cop->co_state = COS_LISTEN;
LINK2TAIL(cop, Atm_connection, atm_listen_queue, co_next);
if (so != NULL)
solisten_proto(so);
solisten_proto(so, backlog);
donex:
(void) splx(s);

View File

@ -335,9 +335,10 @@ atm_sock_bind(so, addr)
*
*/
int
atm_sock_listen(so, epp)
atm_sock_listen(so, epp, backlog)
struct socket *so;
Atm_endpoint *epp;
int backlog;
{
Atm_pcb *atp = sotoatmpcb(so);
@ -350,7 +351,8 @@ atm_sock_listen(so, epp)
/*
* Start listening for incoming calls
*/
return (atm_cm_listen(so, epp, atp, &atp->atp_attr, &atp->atp_conn));
return (atm_cm_listen(so, epp, atp, &atp->atp_attr, &atp->atp_conn,
backlog));
}

View File

@ -82,7 +82,7 @@ void atm_aal5_init(void);
int atm_cm_connect(Atm_endpoint *, void *, Atm_attributes *,
Atm_connection **);
int atm_cm_listen(struct socket *, Atm_endpoint *, void *,
Atm_attributes *, Atm_connection **);
Atm_attributes *, Atm_connection **, int);
int atm_cm_addllc(Atm_endpoint *, void *, struct attr_llc *,
Atm_connection *, Atm_connection **);
int atm_cm_addparty(Atm_connection *, int, struct t_atm_sap *);
@ -152,7 +152,7 @@ void atm_sock_init(void);
int atm_sock_attach(struct socket *, u_long, u_long);
int atm_sock_detach(struct socket *);
int atm_sock_bind(struct socket *, struct sockaddr *);
int atm_sock_listen(struct socket *, Atm_endpoint *);
int atm_sock_listen(struct socket *, Atm_endpoint *, int);
int atm_sock_connect(struct socket *, struct sockaddr *,
Atm_endpoint *);
int atm_sock_disconnect(struct socket *);

View File

@ -524,7 +524,7 @@ ipatm_start()
*/
if ((err = atm_cm_listen(NULL, &ipatm_endpt,
(void *)(intptr_t)i, &ipatm_listeners[i].attr,
&ipatm_listeners[i].conn)) != 0)
&ipatm_listeners[i].conn, -1)) != 0)
goto done;
}

View File

@ -195,7 +195,7 @@ int ng_btsocket_l2cap_control (struct socket *, u_long, caddr_t,
int ng_btsocket_l2cap_ctloutput (struct socket *, struct sockopt *);
int ng_btsocket_l2cap_detach (struct socket *);
int ng_btsocket_l2cap_disconnect (struct socket *);
int ng_btsocket_l2cap_listen (struct socket *, struct thread *);
int ng_btsocket_l2cap_listen (struct socket *, int, struct thread *);
int ng_btsocket_l2cap_peeraddr (struct socket *, struct sockaddr **);
int ng_btsocket_l2cap_send (struct socket *, int, struct mbuf *,
struct sockaddr *, struct mbuf *,

View File

@ -326,7 +326,7 @@ int ng_btsocket_rfcomm_control (struct socket *, u_long, caddr_t,
int ng_btsocket_rfcomm_ctloutput (struct socket *, struct sockopt *);
int ng_btsocket_rfcomm_detach (struct socket *);
int ng_btsocket_rfcomm_disconnect (struct socket *);
int ng_btsocket_rfcomm_listen (struct socket *, struct thread *);
int ng_btsocket_rfcomm_listen (struct socket *, int, struct thread *);
int ng_btsocket_rfcomm_peeraddr (struct socket *, struct sockaddr **);
int ng_btsocket_rfcomm_send (struct socket *, int, struct mbuf *,
struct sockaddr *, struct mbuf *,

View File

@ -2406,7 +2406,7 @@ ng_btsocket_l2cap_disconnect(struct socket *so)
*/
int
ng_btsocket_l2cap_listen(struct socket *so, struct thread *td)
ng_btsocket_l2cap_listen(struct socket *so, int backlog, struct thread *td)
{
ng_btsocket_l2cap_pcb_p pcb = so2l2cap_pcb(so);
int error;
@ -2427,7 +2427,7 @@ ng_btsocket_l2cap_listen(struct socket *so, struct thread *td)
error = EDESTADDRREQ;
goto out;
}
solisten_proto(so);
solisten_proto(so, backlog);
out:
SOCK_UNLOCK(so);
return (error);

View File

@ -794,7 +794,7 @@ ng_btsocket_rfcomm_disconnect(struct socket *so)
*/
int
ng_btsocket_rfcomm_listen(struct socket *so, struct thread *td)
ng_btsocket_rfcomm_listen(struct socket *so, int backlog, struct thread *td)
{
ng_btsocket_rfcomm_pcb_p pcb = so2rfcomm_pcb(so);
ng_btsocket_rfcomm_session_p s = NULL;
@ -858,7 +858,7 @@ ng_btsocket_rfcomm_listen(struct socket *so, struct thread *td)
goto out;
l2so = NULL;
}
solisten_proto(so);
solisten_proto(so, backlog);
out:
SOCK_UNLOCK(so);
mtx_unlock(&ng_btsocket_rfcomm_sessions_mtx);

View File

@ -290,7 +290,7 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
* Prepare to accept connections.
*/
static int
tcp_usr_listen(struct socket *so, struct thread *td)
tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
{
int error = 0;
struct inpcb *inp;
@ -304,7 +304,7 @@ tcp_usr_listen(struct socket *so, struct thread *td)
error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
if (error == 0) {
tp->t_state = TCPS_LISTEN;
solisten_proto(so);
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
COMMON_END(PRU_LISTEN);
@ -312,7 +312,7 @@ tcp_usr_listen(struct socket *so, struct thread *td)
#ifdef INET6
static int
tcp6_usr_listen(struct socket *so, struct thread *td)
tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
{
int error = 0;
struct inpcb *inp;
@ -330,7 +330,7 @@ tcp6_usr_listen(struct socket *so, struct thread *td)
}
if (error == 0) {
tp->t_state = TCPS_LISTEN;
solisten_proto(so);
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
COMMON_END(PRU_LISTEN);

View File

@ -99,7 +99,7 @@ static int spx_connect(struct socket *so, struct sockaddr *nam,
struct thread *td);
static int spx_detach(struct socket *so);
static int spx_usr_disconnect(struct socket *so);
static int spx_listen(struct socket *so, struct thread *td);
static int spx_listen(struct socket *so, int backlog, struct thread *td);
static int spx_rcvd(struct socket *so, int flags);
static int spx_rcvoob(struct socket *so, struct mbuf *m, int flags);
static int spx_send(struct socket *so, int flags, struct mbuf *m,
@ -1518,8 +1518,9 @@ spx_usr_disconnect(so)
}
static int
spx_listen(so, td)
spx_listen(so, backlog, td)
struct socket *so;
int backlog;
struct thread *td;
{
int error;
@ -1538,7 +1539,7 @@ spx_listen(so, td)
error = ipx_pcbbind(ipxp, NULL, td);
if (error == 0) {
cb->s_state = TCPS_LISTEN;
solisten_proto(so);
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
IPX_UNLOCK(ipxp);

View File

@ -57,7 +57,7 @@
* is created, otherwise 1.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 700003 /* Master, propagated to newvers */
#define __FreeBSD_version 700004 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>

View File

@ -208,7 +208,8 @@ struct pr_usrreqs {
struct ifnet *ifp, struct thread *td);
int (*pru_detach)(struct socket *so);
int (*pru_disconnect)(struct socket *so);
int (*pru_listen)(struct socket *so, struct thread *td);
int (*pru_listen)(struct socket *so, int backlog,
struct thread *td);
int (*pru_peeraddr)(struct socket *so, struct sockaddr **nam);
int (*pru_rcvd)(struct socket *so, int flags);
int (*pru_rcvoob)(struct socket *so, struct mbuf *m, int flags);
@ -257,7 +258,7 @@ int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
struct ifnet *ifp, struct thread *td);
int pru_detach_notsupp(struct socket *so);
int pru_disconnect_notsupp(struct socket *so);
int pru_listen_notsupp(struct socket *so, struct thread *td);
int pru_listen_notsupp(struct socket *so, int backlog, struct thread *td);
int pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam);
int pru_rcvd_notsupp(struct socket *so, int flags);
int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags);

View File

@ -514,7 +514,7 @@ void soisconnecting(struct socket *so);
void soisdisconnected(struct socket *so);
void soisdisconnecting(struct socket *so);
int solisten(struct socket *so, int backlog, struct thread *td);
void solisten_proto(struct socket *so);
void solisten_proto(struct socket *so, int backlog);
int solisten_proto_check(struct socket *so);
struct socket *
sonewconn(struct socket *head, int connstatus);