Split the COMPAT_50 socket-timeout stuff out of kern/uipc_socket.c

and into its own source file, which is now included in the compat_50
module.

(Not sure how this got missed during the original [pgoyette-compat] work)
This commit is contained in:
pgoyette 2019-04-15 02:07:11 +00:00
parent a30bc70869
commit 68c01b4b73
8 changed files with 297 additions and 63 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat_50_mod.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $ */
/* $NetBSD: compat_50_mod.c,v 1.3 2019/04/15 02:07:11 pgoyette Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.3 2019/04/15 02:07:11 pgoyette Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -87,6 +87,7 @@ compat_50_init(void)
vnd_50_init();
rndpseudo_50_init();
rtsock_50_init();
kern_uipc_socket_50_init();
return error;
@ -107,6 +108,7 @@ compat_50_fini(void)
{
int error = 0;
kern_uipc_socket_50_fini();
rtsock_50_fini();
rndpseudo_50_fini();
vnd_50_fini();
@ -152,6 +154,7 @@ compat_50_fini(void)
vnd_50_init();
rndpseudo_50_init();
rtsock_50_init();
kern_uipc_socket_50_init();
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat_mod.h,v 1.3 2019/01/28 15:46:49 christos Exp $ */
/* $NetBSD: compat_mod.h,v 1.4 2019/04/15 02:07:11 pgoyette Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -76,6 +76,8 @@ void rndpseudo_50_init(void);
void rndpseudo_50_fini(void);
void rtsock_50_init(void);
void rtsock_50_fini(void);
void kern_uipc_socket_50_init(void);
void kern_uipc_socket_50_fini(void);
#endif
#ifdef COMPAT_40

View File

@ -1,4 +1,4 @@
# $NetBSD: files.common,v 1.2 2019/01/27 02:08:39 pgoyette Exp $
# $NetBSD: files.common,v 1.3 2019/04/15 02:07:11 pgoyette Exp $
#
# Generic utility files, used by various compat options.
@ -85,6 +85,7 @@ file compat/common/vnd_50.c compat_50
file compat/common/clockctl_50.c compat_50
file compat/common/if_spppsubr50.c compat_50
file compat/common/uvm_50.c compat_50
file compat/common/kern_uipc_socket_50.c compat_50
# Compatibility code for NetBSD 6.0
file compat/common/compat_60_mod.c compat_60

View File

@ -0,0 +1,233 @@
/* $NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $ */
/*
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 2004 The FreeBSD Foundation
* Copyright (c) 2004 Robert Watson
* Copyright (c) 1982, 1986, 1988, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95
*/
/*
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: vn.c 1.13 94/04/02$
*
* @(#)vn.c 8.9 (Berkeley) 5/14/95
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/file.h>
#include <sys/compat_stub.h>
#include <sys/socketvar.h>
#include <compat/sys/time.h>
#include <compat/sys/socket.h>
#include <compat/common/compat_mod.h>
static int
uipc_socket_50_getopt1(int opt, struct socket *so, struct sockopt *sopt,
struct timeval *tv)
{
int optval, error;
struct timeval50 otv;
switch (opt) {
case SO_OSNDTIMEO:
case SO_ORCVTIMEO:
optval = (opt == SO_OSNDTIMEO ?
so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
otv.tv_sec = optval / hz;
otv.tv_usec = (optval % hz) * tick;
error = sockopt_set(sopt, &otv, sizeof(otv));
break;
case SO_OTIMESTAMP:
error = sockopt_setint(sopt, (so->so_options & opt) ? 1 : 0);
break;
default:
error = EPASSTHROUGH;
}
return error;
}
static int
uipc_socket_50_setopt1(int opt, struct socket *so, const struct sockopt *sopt,
struct timeval *tv)
{
int optval, error;
struct timeval50 otv;
switch (opt) {
case SO_OSNDTIMEO:
case SO_ORCVTIMEO:
error = sockopt_get(sopt, &otv, sizeof(otv));
if (error) {
solock(so);
break;
}
timeval50_to_timeval(&otv, tv);
opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO;
/*
* Processing will continue as for SO_SNDTIMEO
* and SO_RCVTIMEO, using the new-format tv
*/
break;
case SO_OTIMESTAMP:
error = sockopt_getint(sopt, &optval);
solock(so);
if (error)
break;
if (optval)
so->so_options |= opt;
else
so->so_options &= ~opt;
break;
default:
error = EPASSTHROUGH;
}
return error;
}
static int
uipc_socket_50_sbts(int opt, struct mbuf **mp)
{
struct timeval50 tv50;
struct timeval tv;
microtime(&tv);
if (opt & SO_OTIMESTAMP) {
timeval_to_timeval50(&tv, &tv50);
*mp = sbcreatecontrol(&tv50, sizeof(tv50), SCM_OTIMESTAMP,
SOL_SOCKET);
if (*mp)
mp = &(*mp)->m_next;
return 0;
} else
return EPASSTHROUGH;
}
void
kern_uipc_socket_50_init(void)
{
MODULE_HOOK_SET(uipc_socket_50_setopt1_hook, "sockop_50",
uipc_socket_50_setopt1);
MODULE_HOOK_SET(uipc_socket_50_getopt1_hook, "sockop_50",
uipc_socket_50_getopt1);
MODULE_HOOK_SET(uipc_socket_50_sbts_hook, "sbts_50",
uipc_socket_50_sbts);
}
void
kern_uipc_socket_50_fini(void)
{
MODULE_HOOK_UNSET(uipc_socket_50_setopt1_hook);
MODULE_HOOK_UNSET(uipc_socket_50_getopt1_hook);
MODULE_HOOK_UNSET(uipc_socket_50_sbts_hook);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat_stub.c,v 1.8 2019/02/05 23:28:02 christos Exp $ */
/* $NetBSD: compat_stub.c,v 1.9 2019/04/15 02:07:11 pgoyette Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -173,10 +173,17 @@ struct if43_cvtcmd_20_hook_t if43_cvtcmd_20_hook;
struct tty_ttioctl_43_hook_t tty_ttioctl_43_hook;
/*
* uipc_syscalls_40 compatability
* uipc_syscalls_40 compatibility
*/
struct uipc_syscalls_40_hook_t uipc_syscalls_40_hook;
/*
* uipc_socket_50 compatibility
*/
struct uipc_socket_50_setopt1_hook_t uipc_socket_50_setopt1_hook;
struct uipc_socket_50_getopt1_hook_t uipc_socket_50_getopt1_hook;
struct uipc_socket_50_sbts_hook_t uipc_socket_50_sbts_hook;
/*
* uipc_syscalls_50 compatability
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket.c,v 1.274 2019/04/14 09:09:55 maxv Exp $ */
/* $NetBSD: uipc_socket.c,v 1.275 2019/04/15 02:07:11 pgoyette Exp $ */
/*
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.274 2019/04/14 09:09:55 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.275 2019/04/15 02:07:11 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -104,11 +104,10 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.274 2019/04/14 09:09:55 maxv Exp $
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/kthread.h>
#include <sys/compat_stub.h>
#ifdef COMPAT_50
#include <compat/sys/time.h>
#include <compat/sys/socket.h>
#endif
#include <uvm/uvm_extern.h>
#include <uvm/uvm_loan.h>
@ -1707,12 +1706,23 @@ sorflush(struct socket *so)
static int
sosetopt1(struct socket *so, const struct sockopt *sopt)
{
int error = EINVAL, opt;
int error, opt;
int optval = 0; /* XXX: gcc */
struct linger l;
struct timeval tv;
switch ((opt = sopt->sopt_name)) {
opt = sopt->sopt_name;
MODULE_HOOK_CALL(uipc_socket_50_setopt1_hook, (opt, so, sopt, &tv),
enosys(), error);
if (error == EPASSTHROUGH)
error = EINVAL;
else if (error && error != ENOSYS) {
KASSERT(solocked(so));
return error;
}
switch (opt) {
case SO_ACCEPTFILTER:
error = accept_filt_setopt(so, sopt);
@ -1747,9 +1757,6 @@ sosetopt1(struct socket *so, const struct sockopt *sopt)
case SO_TIMESTAMP:
case SO_NOSIGPIPE:
case SO_RERROR:
#ifdef SO_OTIMESTAMP
case SO_OTIMESTAMP:
#endif
error = sockopt_getint(sopt, &optval);
solock(so);
if (error)
@ -1815,25 +1822,15 @@ sosetopt1(struct socket *so, const struct sockopt *sopt)
}
break;
#ifdef COMPAT_50
case SO_OSNDTIMEO:
case SO_ORCVTIMEO: {
struct timeval50 otv;
error = sockopt_get(sopt, &otv, sizeof(otv));
if (error) {
case SO_ORCVTIMEO:
if (error == ENOSYS) {
error = EINVAL;
solock(so);
break;
}
timeval50_to_timeval(&otv, &tv);
opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO;
error = 0;
/*FALLTHROUGH*/
}
#endif /* COMPAT_50 */
/*FALLTHROUGH*/
/* FALLTHROUGH */
case SO_SNDTIMEO:
/*FALLTHROUGH*/
case SO_RCVTIMEO:
if (error)
error = sockopt_get(sopt, &tv, sizeof(tv));
@ -1955,9 +1952,6 @@ sogetopt1(struct socket *so, struct sockopt *sopt)
case SO_TIMESTAMP:
case SO_NOSIGPIPE:
case SO_RERROR:
#ifdef SO_OTIMESTAMP
case SO_OTIMESTAMP:
#endif
case SO_ACCEPTCONN:
error = sockopt_setint(sopt, (so->so_options & opt) ? 1 : 0);
break;
@ -1991,22 +1985,6 @@ sogetopt1(struct socket *so, struct sockopt *sopt)
error = sockopt_setint(sopt, so->so_rcv.sb_lowat);
break;
#ifdef COMPAT_50
case SO_OSNDTIMEO:
case SO_ORCVTIMEO: {
struct timeval50 otv;
optval = (opt == SO_OSNDTIMEO ?
so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
otv.tv_sec = optval / hz;
otv.tv_usec = (optval % hz) * tick;
error = sockopt_set(sopt, &otv, sizeof(otv));
break;
}
#endif /* COMPAT_50 */
case SO_SNDTIMEO:
case SO_RCVTIMEO:
optval = (opt == SO_SNDTIMEO ?
@ -2023,7 +2001,10 @@ sogetopt1(struct socket *so, struct sockopt *sopt)
break;
default:
error = ENOPROTOOPT;
MODULE_HOOK_CALL(uipc_socket_50_getopt1_hook,
(opt, so, sopt, &tv), enosys(), error);
if (error)
error = ENOPROTOOPT;
break;
}
@ -2441,19 +2422,13 @@ struct mbuf **
sbsavetimestamp(int opt, struct mbuf **mp)
{
struct timeval tv;
int error;
microtime(&tv);
#ifdef SO_OTIMESTAMP
if (opt & SO_OTIMESTAMP) {
struct timeval50 tv50;
timeval_to_timeval50(&tv, &tv50);
*mp = sbcreatecontrol(&tv50, sizeof(tv50),
SCM_OTIMESTAMP, SOL_SOCKET);
if (*mp)
mp = &(*mp)->m_next;
} else
#endif
MODULE_HOOK_CALL(uipc_socket_50_sbts_hook, (opt, mp), enosys(), error);
if (error == 0)
return mp;
if (opt & SO_TIMESTAMP) {
*mp = sbcreatecontrol(&tv, sizeof(tv),

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.3 2019/02/17 04:05:45 rin Exp $
# $NetBSD: Makefile,v 1.4 2019/04/15 02:07:11 pgoyette Exp $
.include "../Makefile.inc"
@ -12,6 +12,7 @@ SRCS+= compat_50_mod.c
SRCS+= kern_50.c kern_time_50.c kern_select_50.c
SRCS+= vfs_syscalls_50.c uipc_syscalls_50.c uvm_50.c
SRCS+= rndpseudo_50.c clockctl_50.c if_spppsubr50.c
SRCS+= kern_uipc_socket_50.c
CPPFLAGS+= -DINET -DINET6
# XXX someday we'll need to add

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat_stub.h,v 1.11 2019/02/05 23:28:02 christos Exp $ */
/* $NetBSD: compat_stub.h,v 1.12 2019/04/15 02:07:11 pgoyette Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -220,6 +220,19 @@ MODULE_HOOK(tty_ttioctl_43_hook, int,
MODULE_HOOK(uipc_syscalls_40_hook, int, (u_long, void *));
/*
* uipc_socket_50 compatibility
*/
struct sockopt;
struct timeval;
struct mbuf;
MODULE_HOOK(uipc_socket_50_setopt1_hook, int,
(int, struct socket *, const struct sockopt *, struct timeval *));
MODULE_HOOK(uipc_socket_50_getopt1_hook, int,
(int, struct socket *, struct sockopt *, struct timeval *));
MODULE_HOOK(uipc_socket_50_sbts_hook, int, (int, struct mbuf **));
/*
* uipc_syscalls_50 compatibility
*/
@ -311,7 +324,6 @@ MODULE_HOOK(vfs_openat_10_hook, int, (struct pathbuf **));
/*
* Hook for compat_70_unp_addsockcred
*/
struct mbuf;
MODULE_HOOK(uipc_unp_70_hook, struct mbuf *,
(struct lwp *, struct mbuf *));