Move the logic implementing retrieval of the SO_ACCEPTFILTER socket option
from uipc_socket.c to uipc_accf.c in do_getopt_accept_filter(), so that it now matches do_setopt_accept_filter(). Slightly reformulate the logic to match the optimistic allocation of storage for the argument in advance, and slightly expand the coverage of the socket lock.
This commit is contained in:
parent
9091954535
commit
a59f81d263
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143463
@ -162,6 +162,33 @@ accept_filt_generic_mod_event(module_t mod, int event, void *data)
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
do_getopt_accept_filter(struct socket *so, struct sockopt *sopt)
|
||||
{
|
||||
struct accept_filter_arg *afap;
|
||||
int error;
|
||||
|
||||
error = 0;
|
||||
MALLOC(afap, struct accept_filter_arg *, sizeof(*afap), M_TEMP,
|
||||
M_WAITOK | M_ZERO);
|
||||
SOCK_LOCK(so);
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if ((so->so_options & SO_ACCEPTFILTER) == 0)
|
||||
goto out;
|
||||
strcpy(afap->af_name, so->so_accf->so_accept_filter->accf_name);
|
||||
if (so->so_accf->so_accept_filter_str != NULL)
|
||||
strcpy(afap->af_arg, so->so_accf->so_accept_filter_str);
|
||||
out:
|
||||
SOCK_UNLOCK(so);
|
||||
if (error == 0)
|
||||
error = sooptcopyout(sopt, afap, sizeof(*afap));
|
||||
FREE(afap, M_TEMP);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
do_setopt_accept_filter(struct socket *so, struct sockopt *sopt)
|
||||
{
|
||||
|
@ -1745,9 +1745,6 @@ sogetopt(so, sopt)
|
||||
int error, optval;
|
||||
struct linger l;
|
||||
struct timeval tv;
|
||||
#ifdef INET
|
||||
struct accept_filter_arg *afap;
|
||||
#endif
|
||||
#ifdef MAC
|
||||
struct mac extmac;
|
||||
#endif
|
||||
@ -1763,23 +1760,9 @@ sogetopt(so, sopt)
|
||||
switch (sopt->sopt_name) {
|
||||
#ifdef INET
|
||||
case SO_ACCEPTFILTER:
|
||||
/* Unlocked read. */
|
||||
if ((so->so_options & SO_ACCEPTCONN) == 0)
|
||||
return (EINVAL);
|
||||
MALLOC(afap, struct accept_filter_arg *, sizeof(*afap),
|
||||
M_TEMP, M_WAITOK | M_ZERO);
|
||||
SOCK_LOCK(so);
|
||||
if ((so->so_options & SO_ACCEPTFILTER) != 0) {
|
||||
strcpy(afap->af_name, so->so_accf->so_accept_filter->accf_name);
|
||||
if (so->so_accf->so_accept_filter_str != NULL)
|
||||
strcpy(afap->af_arg, so->so_accf->so_accept_filter_str);
|
||||
}
|
||||
SOCK_UNLOCK(so);
|
||||
error = sooptcopyout(sopt, afap, sizeof(*afap));
|
||||
FREE(afap, M_TEMP);
|
||||
error = do_getopt_accept_filter(so, sopt);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SO_LINGER:
|
||||
SOCK_LOCK(so);
|
||||
l.l_onoff = so->so_options & SO_LINGER;
|
||||
|
@ -447,6 +447,7 @@ struct uio;
|
||||
/*
|
||||
* From uipc_socket and friends
|
||||
*/
|
||||
int do_getopt_accept_filter(struct socket *so, struct sockopt *sopt);
|
||||
int do_setopt_accept_filter(struct socket *so, struct sockopt *sopt);
|
||||
int so_setsockopt(struct socket *so, int level, int optname,
|
||||
void *optval, size_t optlen);
|
||||
|
Loading…
Reference in New Issue
Block a user