From 5969a6f1e4773bc086bf9006b602f030fa359137 Mon Sep 17 00:00:00 2001 From: "David P. Reese, Jr." Date: Sun, 7 Sep 2003 20:36:11 +0000 Subject: [PATCH] Change the split syscall naming convention from syscall1() to kern_syscall() while moving the prototypes from sys/syscall1.h to sys/kern_syscall.h. Split the listen(), getsockname(), getpeername(), and socketpair() syscalls. --- sys/emulation/linux/linux_socket.c | 12 +- sys/kern/uipc_syscalls.c | 277 +++++++++++++++---------- sys/sys/{syscall1.h => kern_syscall.h} | 20 +- 3 files changed, 187 insertions(+), 122 deletions(-) rename sys/sys/{syscall1.h => kern_syscall.h} (69%) diff --git a/sys/emulation/linux/linux_socket.c b/sys/emulation/linux/linux_socket.c index 420a19dd2f..cbe979b184 100644 --- a/sys/emulation/linux/linux_socket.c +++ b/sys/emulation/linux/linux_socket.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/compat/linux/linux_socket.c,v 1.19.2.8 2001/11/07 20:33:55 marcel Exp $ - * $DragonFly: src/sys/emulation/linux/linux_socket.c,v 1.9 2003/09/06 20:36:42 dillon Exp $ + * $DragonFly: src/sys/emulation/linux/linux_socket.c,v 1.10 2003/09/07 20:36:11 daver Exp $ */ /* XXX we use functions that might not exist. */ @@ -42,9 +42,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -442,7 +442,7 @@ linux_bind(struct linux_bind_args *args, int *res) if (error) return (error); - error = bind1(linux_args.s, sa); + error = kern_bind(linux_args.s, sa); FREE(sa, M_SONAME); return (error); @@ -476,7 +476,7 @@ linux_connect(struct linux_connect_args *args, int *res) if (error) return (error); - error = connect1(linux_args.s, sa); + error = kern_connect(linux_args.s, sa); FREE(sa, M_SONAME); if (error != EISCONN) @@ -556,7 +556,7 @@ linux_accept(struct linux_accept_args *args, int *res) if (error) return (error); - error = accept1(linux_args.s, &sa, &sa_len, res); + error = kern_accept(linux_args.s, &sa, &sa_len, res); if (error) { /* @@ -580,7 +580,7 @@ linux_accept(struct linux_accept_args *args, int *res) if (sa) FREE(sa, M_SONAME); } else { - error = accept1(linux_args.s, NULL, 0, res); + error = kern_accept(linux_args.s, NULL, 0, res); } if (error) diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 66e75d2ced..1615d69d4d 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.12 2003/09/06 20:34:35 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.13 2003/09/07 20:36:11 daver Exp $ */ #include "opt_compat.h" @@ -52,12 +52,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -80,8 +80,6 @@ static int sendit(int s, struct msghdr *mp, int flags, int *res); static int recvit(int s, struct msghdr *mp, caddr_t namelenp, int *res); static int do_sendfile(struct sendfile_args *uap, int compat); -static int getsockname1(struct getsockname_args *uap, int compat); -static int getpeername1(struct getpeername_args *uap, int compat); static SLIST_HEAD(, sf_buf) sf_freelist; static vm_offset_t sf_base; @@ -135,7 +133,7 @@ socket(struct socket_args *uap) } int -bind1(int s, struct sockaddr *sa) +kern_bind(int s, struct sockaddr *sa) { struct thread *td = curthread; struct proc *p = td->td_proc; @@ -163,18 +161,14 @@ bind(struct bind_args *uap) error = getsockaddr(&sa, uap->name, uap->namelen); if (error) return (error); - error = bind1(uap->s, sa); + error = kern_bind(uap->s, sa); FREE(sa, M_SONAME); return (error); } -/* - * listen_args(int s, int backlog) - */ -/* ARGSUSED */ int -listen(struct listen_args *uap) +kern_listen(int s, int backlog) { struct thread *td = curthread; struct proc *p = td->td_proc; @@ -182,22 +176,34 @@ listen(struct listen_args *uap) int error; KKASSERT(p); - error = holdsock(p->p_fd, uap->s, &fp); + error = holdsock(p->p_fd, s, &fp); if (error) return (error); - error = solisten((struct socket *)fp->f_data, uap->backlog, td); + error = solisten((struct socket *)fp->f_data, backlog, td); fdrop(fp, td); return(error); } /* - * The second argument to accept1() is a handle to a struct sockaddr. - * This allows accept1() to return a pointer to an allocated struct + * listen_args(int s, int backlog) + */ +int +listen(struct listen_args *uap) +{ + int error; + + error = kern_listen(uap->s, uap->backlog); + return (error); +} + +/* + * The second argument to kern_accept() is a handle to a struct sockaddr. + * This allows kern_accept() to return a pointer to an allocated struct * sockaddr which must be freed later with FREE(). The caller must * initialize *name to NULL. */ int -accept1(int s, struct sockaddr **name, int *namelen, int *res) +kern_accept(int s, struct sockaddr **name, int *namelen, int *res) { struct thread *td = curthread; struct proc *p = td->td_proc; @@ -352,7 +358,7 @@ accept(struct accept_args *uap) if (error) return (error); - error = accept1(uap->s, &sa, &sa_len, &uap->sysmsg_result); + error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result); if (error == 0) error = copyout(sa, uap->name, sa_len); @@ -363,7 +369,7 @@ accept(struct accept_args *uap) if (sa) FREE(sa, M_SONAME); } else { - error = accept1(uap->s, NULL, 0, &uap->sysmsg_result); + error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result); } return (error); } @@ -381,7 +387,7 @@ oaccept(struct accept_args *uap) if (error) return (error); - error = accept1(uap->s, &sa, &sa_len, &uap->sysmsg_result); + error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result); if (error) { /* @@ -404,14 +410,14 @@ oaccept(struct accept_args *uap) if (sa) FREE(sa, M_SONAME); } else { - error = accept1(uap->s, NULL, 0, &uap->sysmsg_result); + error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result); } return (error); } #endif /* COMPAT_OLDSOCK */ int -connect1(int s, struct sockaddr *sa) +kern_connect(int s, struct sockaddr *sa) { struct thread *td = curthread; struct proc *p = td->td_proc; @@ -466,31 +472,28 @@ connect(struct connect_args *uap) error = getsockaddr(&sa, uap->name, uap->namelen); if (error) return (error); - error = connect1(uap->s, sa); + error = kern_connect(uap->s, sa); FREE(sa, M_SONAME); return (error); } -/* - * socketpair(int domain, int type, int protocol, int *rsv) - */ int -socketpair(struct socketpair_args *uap) +kern_socketpair(int domain, int type, int protocol, int *sv) { struct thread *td = curthread; struct proc *p = td->td_proc; struct filedesc *fdp; struct file *fp1, *fp2; struct socket *so1, *so2; - int fd, error, sv[2]; + int fd, error; KKASSERT(p); fdp = p->p_fd; - error = socreate(uap->domain, &so1, uap->type, uap->protocol, td); + error = socreate(domain, &so1, type, protocol, td); if (error) return (error); - error = socreate(uap->domain, &so2, uap->type, uap->protocol, td); + error = socreate(domain, &so2, type, protocol, td); if (error) goto free1; error = falloc(p, &fp1, &fd); @@ -508,7 +511,7 @@ socketpair(struct socketpair_args *uap) error = soconnect2(so1, so2); if (error) goto free4; - if (uap->type == SOCK_DGRAM) { + if (type == SOCK_DGRAM) { /* * Datagram socket connection is asymmetric. */ @@ -519,7 +522,6 @@ socketpair(struct socketpair_args *uap) fp1->f_flag = fp2->f_flag = FREAD|FWRITE; fp1->f_ops = fp2->f_ops = &socketops; fp1->f_type = fp2->f_type = DTYPE_SOCKET; - error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int)); fdrop(fp1, td); fdrop(fp2, td); return (error); @@ -542,6 +544,21 @@ free1: return (error); } +/* + * socketpair(int domain, int type, int protocol, int *rsv) + */ +int +socketpair(struct socketpair_args *uap) +{ + int error, sockv[2]; + + error = kern_socketpair(uap->domain, uap->type, uap->protocol, sockv); + + if (error == 0) + error = copyout(sockv, uap->rsv, sizeof(sockv)); + return (error); +} + static int sendit(int s, struct msghdr *mp, int flags, int *res) { @@ -1170,147 +1187,191 @@ getsockopt(struct getsockopt_args *uap) } /* - * getsockname_args(int fdes, caddr_t asa, int *alen) - * - * Get socket name. + * The second argument to kern_getsockname() is a handle to a struct sockaddr. + * This allows kern_getsockname() to return a pointer to an allocated struct + * sockaddr which must be freed later with FREE(). The caller must + * initialize *name to NULL. */ -/* ARGSUSED */ -static int -getsockname1(struct getsockname_args *uap, int compat) +int +kern_getsockname(int s, struct sockaddr **name, int *namelen) { struct thread *td = curthread; struct proc *p = td->td_proc; struct file *fp; struct socket *so; - struct sockaddr *sa; - int len, error; + struct sockaddr *sa = NULL; + int error; - error = holdsock(p->p_fd, uap->fdes, &fp); + error = holdsock(p->p_fd, s, &fp); if (error) return (error); - error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len)); - if (error) { - fdrop(fp, td); - return (error); - } - if (len < 0) { + if (*namelen < 0) { fdrop(fp, td); return (EINVAL); } so = (struct socket *)fp->f_data; - sa = 0; error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &sa); - if (error) - goto bad; - if (sa == 0) { - len = 0; - goto gotnothing; + if (error == 0) { + if (sa == 0) { + *namelen = 0; + } else { + *namelen = MIN(*namelen, sa->sa_len); + *name = sa; + } } - len = MIN(len, sa->sa_len); -#ifdef COMPAT_OLDSOCK - if (compat) - ((struct osockaddr *)sa)->sa_family = sa->sa_family; -#endif - error = copyout(sa, (caddr_t)uap->asa, (u_int)len); - if (error == 0) -gotnothing: - error = copyout((caddr_t)&len, (caddr_t)uap->alen, - sizeof (len)); -bad: - if (sa) - FREE(sa, M_SONAME); fdrop(fp, td); return (error); } +/* + * getsockname_args(int fdes, caddr_t asa, int *alen) + * + * Get socket name. + */ int getsockname(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); - return (getsockname1(uap, 0)); + if (error == 0) + 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); } #ifdef COMPAT_OLDSOCK int ogetsockname(struct getsockname_args *uap) { + struct sockaddr *sa = NULL; + int error, sa_len; - return (getsockname1(uap, 1)); + 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 */ /* - * getpeername_args(int fdes, caddr_t asa, int *alen) - * - * Get name of peer for connected socket. + * 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 + * sockaddr which must be freed later with FREE(). The caller must + * initialize *name to NULL. */ -/* ARGSUSED */ -static int -getpeername1(struct getpeername_args *uap, int compat) +int +kern_getpeername(int s, struct sockaddr **name, int *namelen) { struct thread *td = curthread; struct proc *p = td->td_proc; struct file *fp; struct socket *so; - struct sockaddr *sa; - int len, error; + struct sockaddr *sa = NULL; + int error; - error = holdsock(p->p_fd, uap->fdes, &fp); + error = holdsock(p->p_fd, s, &fp); if (error) return (error); + if (*namelen < 0) { + fdrop(fp, td); + return (EINVAL); + } so = (struct socket *)fp->f_data; if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { fdrop(fp, td); return (ENOTCONN); } - error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len)); - if (error) { - fdrop(fp, td); - return (error); - } - if (len < 0) { - fdrop(fp, td); - return (EINVAL); - } - sa = 0; error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &sa); - if (error) - goto bad; - if (sa == 0) { - len = 0; - goto gotnothing; + if (error == 0) { + if (sa == 0) { + *namelen = 0; + } else { + *namelen = MIN(*namelen, sa->sa_len); + *name = sa; + } } - len = MIN(len, sa->sa_len); -#ifdef COMPAT_OLDSOCK - if (compat) - ((struct osockaddr *)sa)->sa_family = - sa->sa_family; -#endif - error = copyout(sa, (caddr_t)uap->asa, (u_int)len); - if (error) - goto bad; -gotnothing: - error = copyout((caddr_t)&len, (caddr_t)uap->alen, sizeof (len)); -bad: - if (sa) - FREE(sa, M_SONAME); + fdrop(fp, td); return (error); } +/* + * getpeername_args(int fdes, caddr_t asa, int *alen) + * + * Get name of peer for connected socket. + */ int getpeername(struct getpeername_args *uap) { - return (getpeername1(uap, 0)); + 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 = 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); } #ifdef COMPAT_OLDSOCK int ogetpeername(struct ogetpeername_args *uap) { - /* XXX uap should have type `getpeername_args *' to begin with. */ - return (getpeername1((struct getpeername_args *)uap, 1)); + 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 */ diff --git a/sys/sys/syscall1.h b/sys/sys/kern_syscall.h similarity index 69% rename from sys/sys/syscall1.h rename to sys/sys/kern_syscall.h index f817c0d617..04dbe93838 100644 --- a/sys/sys/syscall1.h +++ b/sys/sys/kern_syscall.h @@ -1,5 +1,5 @@ /* - * SYSCALL1.H - Split syscall prototypes + * KERN_SYSCALL.H - Split syscall prototypes * * Copyright (c) 2003 David P. Reese, Jr. * All rights reserved. @@ -25,16 +25,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/Attic/syscall1.h,v 1.1 2003/09/06 22:45:08 dillon Exp $ + * $DragonFly: src/sys/sys/kern_syscall.h,v 1.1 2003/09/07 20:36:11 daver Exp $ */ -#ifndef _SYS_SYSCALL1_H_ -#define _SYS_SYSCALL1_H_ +#ifndef _SYS_KERN_SYSCALL_H_ +#define _SYS_KERN_SYSCALL_H_ struct sockaddr; -int accept1(int s, struct sockaddr **name, int *namelen, int *res); -int bind1(int s, struct sockaddr *sa); -int connect1(int s, struct sockaddr *sa); +int kern_accept(int s, struct sockaddr **name, int *namelen, int *res); +int kern_bind(int s, struct sockaddr *sa); +int kern_connect(int s, struct sockaddr *sa); +int kern_listen(int s, int backlog); +int kern_getpeername(int s, struct sockaddr **name, int *namelen); +int kern_getsockname(int s, struct sockaddr **name, int *namelen); +int kern_socketpair(int domain, int type, int protocol, int *sockv); -#endif /* !_SYS_SYSCALL1_H_ */ +#endif /* !_SYS_KERN_SYSCALL_H_ */ -- 2.41.0