From 9eee10d0a49e30cacf784e8a154c8132276048a2 Mon Sep 17 00:00:00 2001 From: "David P. Reese, Jr." Date: Fri, 12 Sep 2003 00:43:31 +0000 Subject: [PATCH] Create an emulation/43bsd directory and move the recently modified compatibility syscalls there. Any future work on the COMPAT_43 code should be split from the rest of the kernel and moved here. Everything in the kernel that explicity uses the osockaddr structure has been modified to include "emulation/43bsd/43bsd_socket.h". There was one case where struct osockaddr was used in userland, talk/talkd. This commit has a temporary fix for talk/talkd. --- include/protocols/talkd.h | 11 ++ sys/conf/files | 4 +- sys/emulation/43bsd/43bsd_socket.c | 178 +++++++++++++++++++++++++++++ sys/emulation/43bsd/43bsd_socket.h | 46 ++++++++ sys/emulation/svr4/svr4_ioctl.c | 4 +- sys/emulation/svr4/svr4_sockio.c | 4 +- sys/emulation/svr4/svr4_sysvec.c | 4 +- sys/kern/uipc_syscalls.c | 105 +---------------- sys/net/if.c | 6 +- sys/sys/socket.h | 10 +- 10 files changed, 257 insertions(+), 115 deletions(-) create mode 100644 sys/emulation/43bsd/43bsd_socket.c create mode 100644 sys/emulation/43bsd/43bsd_socket.h diff --git a/include/protocols/talkd.h b/include/protocols/talkd.h index 962e47be7e..623ffec7bb 100644 --- a/include/protocols/talkd.h +++ b/include/protocols/talkd.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)talkd.h 8.1 (Berkeley) 6/2/93 + * $DragonFly: src/include/protocols/talkd.h,v 1.2 2003/09/12 00:43:30 daver Exp $ */ #ifndef _PROTOCOLS_TALKD_H_ @@ -54,6 +55,16 @@ * stream connection through which the conversation takes place. */ +/* + * XXX: Nothing should explicity reference the structure osockaddr. + * It is for binary compatibility only. The talk protocol doesn't + * understand this yet. + */ +struct osockaddr { + u_short sa_family; + char sa_data[14]; +}; + /* * Client->server request message format. */ diff --git a/sys/conf/files b/sys/conf/files index 57210c6da6..9ad7fb9b99 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.12 2003/09/06 21:51:11 drhodus Exp $ +# $DragonFly: src/sys/conf/files,v 1.13 2003/09/12 00:43:30 daver Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -1433,4 +1433,4 @@ dev/drm/radeon/radeon_irq.c optional radeondrm dev/drm/radeon/radeon_mem.c optional radeondrm dev/drm/radeon/radeon_state.c optional radeondrm dev/drm/tdfx/tdfx_drv.c optional tdfxdrm - +emulation/43bsd/43bsd_socket.c optional compat_43 diff --git a/sys/emulation/43bsd/43bsd_socket.c b/sys/emulation/43bsd/43bsd_socket.c new file mode 100644 index 0000000000..cf41eb76c8 --- /dev/null +++ b/sys/emulation/43bsd/43bsd_socket.c @@ -0,0 +1,178 @@ +/* + * 43BSD_SOCKET.C - 4.3BSD compatibility socket syscalls + * + * Copyright (c) 1982, 1986, 1989, 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * $DragonFly: src/sys/emulation/43bsd/43bsd_socket.c,v 1.1 2003/09/12 00:43:30 daver Exp $ + * from: DragonFly kern/uipc_syscalls.c,v 1.13 + * + * The original versions of these syscalls used to live in + * kern/uipc_syscalls.c. These are heavily modified to use the + * new split syscalls. + */ + +#include "opt_compat.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "43bsd_socket.h" + +/* + * System call interface to the socket abstraction. + */ + +static int +compat_43_getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len) +{ + struct sockaddr *sa; + int error; + + *namp = NULL; + if (len > SOCK_MAXADDRLEN) + return ENAMETOOLONG; + if (len < offsetof(struct sockaddr, sa_data[0])) + return EDOM; + MALLOC(sa, struct sockaddr *, len, M_SONAME, M_WAITOK); + error = copyin(uaddr, sa, len); + if (error) { + FREE(sa, M_SONAME); + } else { + /* + * Convert to the 4.4BSD sockaddr structure. + */ + sa->sa_family = sa->sa_len; + sa->sa_len = len; + *namp = sa; + } + return error; +} + +static int +compat_43_copyout_sockaddr(struct sockaddr *sa, caddr_t uaddr) +{ + int error, sa_len; + + /* Save the length of sa before we destroy it */ + sa_len = sa->sa_len; + ((struct osockaddr *)sa)->sa_family = sa->sa_family; + + error = copyout(sa, uaddr, sa_len); + + return (error); +} + +int +oaccept(struct accept_args *uap) +{ + struct sockaddr *sa = NULL; + int sa_len; + int error; + + if (uap->name) { + error = copyin(uap->anamelen, &sa_len, sizeof(sa_len)); + if (error) + return (error); + + error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result); + + if (error) { + /* + * return a namelen of zero for older code which + * might ignore the return value from accept. + */ + sa_len = 0; + copyout(&sa_len, uap->anamelen, sizeof(*uap->anamelen)); + } else { + compat_43_copyout_sockaddr(sa, uap->name); + if (error == 0) { + error = copyout(&sa_len, uap->anamelen, + sizeof(*uap->anamelen)); + } + } + if (sa) + FREE(sa, M_SONAME); + } else { + error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result); + } + return (error); +} + +int +ogetsockname(struct getsockname_args *uap) +{ + struct sockaddr *sa = NULL; + int error, sa_len; + + error = copyin(uap->alen, &sa_len, sizeof(sa_len)); + if (error) + return (error); + + error = kern_getsockname(uap->fdes, &sa, &sa_len); + + if (error == 0) + error = compat_43_copyout_sockaddr(sa, uap->asa); + if (error == 0) { + error = copyout(&sa_len, uap->alen, sizeof(*uap->alen)); + } + if (sa) + FREE(sa, M_SONAME); + return (error); +} + +int +ogetpeername(struct ogetpeername_args *uap) +{ + struct sockaddr *sa = NULL; + int error, sa_len; + + error = copyin(uap->alen, &sa_len, sizeof(sa_len)); + if (error) + return (error); + + error = kern_getpeername(uap->fdes, &sa, &sa_len); + + if (error == 0) { + error = compat_43_copyout_sockaddr(sa, uap->asa); + } + if (error == 0) + error = copyout(&sa_len, uap->alen, sizeof(*uap->alen)); + if (sa) + FREE(sa, M_SONAME); + return (error); +} diff --git a/sys/emulation/43bsd/43bsd_socket.h b/sys/emulation/43bsd/43bsd_socket.h new file mode 100644 index 0000000000..751115982f --- /dev/null +++ b/sys/emulation/43bsd/43bsd_socket.h @@ -0,0 +1,46 @@ +/* + * 43BSD_SOCKET.H - 4.3BSD compatibility structures for the socket code + * + * Copyright (c) 1982, 1986, 1989, 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * $DragonFly: src/sys/emulation/43bsd/43bsd_socket.h,v 1.1 2003/09/12 00:43:30 daver Exp $ + * from: DragonFly sys/socket.h,v 1.3 + * + * These are the 4.3BSD compatibility structures from sys/socket.h. + * The structure omsghdr will migrate here after some changes are made + * to o{send,recv} and o{send,recv}msg. + */ + +struct osockaddr { + u_short sa_family; /* address family */ + char sa_data[14]; /* up to 14 bytes of direct address */ +}; diff --git a/sys/emulation/svr4/svr4_ioctl.c b/sys/emulation/svr4/svr4_ioctl.c index a92ede6bc3..7d2d843e15 100644 --- a/sys/emulation/svr4/svr4_ioctl.c +++ b/sys/emulation/svr4/svr4_ioctl.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_ioctl.c,v 1.6 1999/12/08 12:00:48 newton Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.10 2003/08/27 06:07:10 rob Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.11 2003/09/12 00:43:30 daver Exp $ */ #include @@ -38,6 +38,8 @@ #include #include +#include + #include "svr4.h" #include "svr4_types.h" #include "svr4_util.h" diff --git a/sys/emulation/svr4/svr4_sockio.c b/sys/emulation/svr4/svr4_sockio.c index dfdd859ea8..888e407b2a 100644 --- a/sys/emulation/svr4/svr4_sockio.c +++ b/sys/emulation/svr4/svr4_sockio.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_sockio.c,v 1.7 1999/12/08 12:00:48 newton Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sockio.c,v 1.5 2003/08/27 06:07:10 rob Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sockio.c,v 1.6 2003/09/12 00:43:30 daver Exp $ */ #include @@ -39,6 +39,8 @@ #include #include +#include + #include "svr4.h" #include "svr4_util.h" #include "svr4_ioctl.h" diff --git a/sys/emulation/svr4/svr4_sysvec.c b/sys/emulation/svr4/svr4_sysvec.c index 35e71ccea6..e470b060c7 100644 --- a/sys/emulation/svr4/svr4_sysvec.c +++ b/sys/emulation/svr4/svr4_sysvec.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_sysvec.c,v 1.10.2.2 2002/07/09 14:12:43 robert Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sysvec.c,v 1.6 2003/08/07 21:17:19 dillon Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sysvec.c,v 1.7 2003/09/12 00:43:30 daver Exp $ */ /* XXX we use functions that might not exist. */ @@ -57,6 +57,8 @@ #include #include +#include + #include "svr4.h" #include "svr4_types.h" #include "svr4_syscall.h" diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 1615d69d4d..5e6263a486 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -35,7 +35,7 @@ * * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 * $FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.65.2.17 2003/04/04 17:11:16 tegge Exp $ - * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.13 2003/09/07 20:36:11 daver Exp $ + * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.14 2003/09/12 00:43:30 daver Exp $ */ #include "opt_compat.h" @@ -73,6 +73,10 @@ #include #include +#if defined(COMPAT_43) +#include +#endif /* COMPAT_43 */ + static void sf_buf_init(void *arg); SYSINIT(sock_sf, SI_SUB_MBUF, SI_ORDER_ANY, sf_buf_init, NULL) @@ -374,48 +378,6 @@ accept(struct accept_args *uap) return (error); } -#ifdef COMPAT_OLDSOCK -int -oaccept(struct accept_args *uap) -{ - struct sockaddr *sa = NULL; - int sa_len; - int error; - - if (uap->name) { - error = copyin(uap->anamelen, &sa_len, sizeof(sa_len)); - if (error) - return (error); - - error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result); - - if (error) { - /* - * return a namelen of zero for older code which - * might ignore the return value from accept. - */ - sa_len = 0; - copyout(&sa_len, uap->anamelen, sizeof(*uap->anamelen)); - } else { - /* - * Convert sa to the 4.3BSD sockaddr structure. - */ - ((struct osockaddr *)sa)->sa_family = sa->sa_family; - error = copyout(sa, uap->name, sa_len); - if (error == 0) { - error = copyout(&sa_len, uap->anamelen, - sizeof(*uap->anamelen)); - } - } - if (sa) - FREE(sa, M_SONAME); - } else { - error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result); - } - return (error); -} -#endif /* COMPAT_OLDSOCK */ - int kern_connect(int s, struct sockaddr *sa) { @@ -1250,35 +1212,6 @@ getsockname(struct getsockname_args *uap) return (error); } -#ifdef COMPAT_OLDSOCK -int -ogetsockname(struct getsockname_args *uap) -{ - struct sockaddr *sa = NULL; - int error, sa_len; - - error = copyin(uap->alen, &sa_len, sizeof(sa_len)); - if (error) - return (error); - - error = kern_getsockname(uap->fdes, &sa, &sa_len); - - if (error == 0) { - /* - * Convert sa to the 4.3BSD sockaddr structure. - */ - ((struct osockaddr *)sa)->sa_family = sa->sa_family; - error = copyout(sa, uap->asa, sa_len); - } - if (error == 0) { - error = copyout(&sa_len, uap->alen, sizeof(*uap->alen)); - } - if (sa) - FREE(sa, M_SONAME); - return (error); -} -#endif /* COMPAT_OLDSOCK */ - /* * The second argument to kern_getpeername() is a handle to a struct sockaddr. * This allows kern_getpeername() to return a pointer to an allocated struct @@ -1347,34 +1280,6 @@ getpeername(struct getpeername_args *uap) return (error); } -#ifdef COMPAT_OLDSOCK -int -ogetpeername(struct ogetpeername_args *uap) -{ - struct sockaddr *sa = NULL; - int error, sa_len; - - error = copyin(uap->alen, &sa_len, sizeof(sa_len)); - if (error) - return (error); - - error = kern_getpeername(uap->fdes, &sa, &sa_len); - - if (error == 0) { - /* - * Convert sa to the 4.3BSD sockaddr structure. - */ - ((struct osockaddr *)sa)->sa_family = sa->sa_family; - error = copyout(sa, uap->asa, sa_len); - } - if (error == 0) - error = copyout(&sa_len, uap->alen, sizeof(*uap->alen)); - if (sa) - FREE(sa, M_SONAME); - return (error); -} -#endif /* COMPAT_OLDSOCK */ - int sockargs(mp, buf, buflen, type) struct mbuf **mp; diff --git a/sys/net/if.c b/sys/net/if.c index 57a08a7e46..a46db8f53e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.85.2.23 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if.c,v 1.6 2003/08/26 20:49:47 rob Exp $ + * $DragonFly: src/sys/net/if.c,v 1.7 2003/09/12 00:43:31 daver Exp $ */ #include "opt_compat.h" @@ -73,6 +73,10 @@ #endif #endif +#if defined(COMPAT_43) +#include +#endif /* COMPAT_43 */ + /* * System initialization */ diff --git a/sys/sys/socket.h b/sys/sys/socket.h index e3e48bebbb..a535141121 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -32,7 +32,7 @@ * * @(#)socket.h 8.4 (Berkeley) 2/21/94 * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $ - * $DragonFly: src/sys/sys/socket.h,v 1.3 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/socket.h,v 1.4 2003/09/12 00:43:31 daver Exp $ */ #ifndef _SYS_SOCKET_H_ @@ -393,14 +393,6 @@ struct cmsgcred { #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */ -/* - * 4.3 compat sockaddr, move to compat file later - */ -struct osockaddr { - u_short sa_family; /* address family */ - char sa_data[14]; /* up to 14 bytes of direct address */ -}; - /* * 4.3-compat message header (move to compat file later). */ -- 2.41.0