Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys make accept, getsockname and getpeername syscalls use so...
details: https://anonhg.NetBSD.org/src/rev/45fdad8f9945
branches: trunk
changeset: 337718:45fdad8f9945
user: rtr <rtr%NetBSD.org@localhost>
date: Fri Apr 24 22:32:37 2015 +0000
description:
make accept, getsockname and getpeername syscalls use sockaddr_big and modify
pr_{accept,sockname,peername} nam parameter type from mbuf * to sockaddr *.
* retained use of mbuftypes[MT_SONAME] for now.
* bump to netbsd version 7.99.12 for parameter type change.
patch posted to tech-net@ 2015/04/19
diffstat:
sys/compat/svr4/svr4_stream.c | 41 +++++-----
sys/kern/uipc_socket.c | 6 +-
sys/kern/uipc_syscalls.c | 133 ++++++++++++++++++++---------------
sys/kern/uipc_usrreq.c | 48 ++++--------
sys/net/if_gre.c | 29 ++----
sys/net/link_proto.c | 16 ++--
sys/net/raw_cb.h | 6 +-
sys/net/raw_usrreq.c | 14 +--
sys/net/rtsock.c | 10 +-
sys/netatalk/ddp_usrreq.c | 21 ++---
sys/netbt/hci_socket.c | 18 +--
sys/netbt/l2cap_socket.c | 25 ++----
sys/netbt/rfcomm_socket.c | 25 ++----
sys/netbt/sco_socket.c | 25 ++----
sys/netinet/dccp_usrreq.c | 18 ++--
sys/netinet/in_pcb.c | 14 +--
sys/netinet/in_pcb.h | 6 +-
sys/netinet/raw_ip.c | 14 +-
sys/netinet/tcp_usrreq.c | 34 +++++----
sys/netinet/udp_usrreq.c | 14 +-
sys/netinet6/dccp6_usrreq.c | 16 ++--
sys/netinet6/in6_pcb.c | 14 +--
sys/netinet6/in6_pcb.h | 6 +-
sys/netinet6/raw_ip6.c | 14 +-
sys/netinet6/udp6_usrreq.c | 14 +-
sys/netipsec/keysock.c | 10 +-
sys/netmpls/mpls_proto.c | 10 +-
sys/netnatm/natm.c | 15 +--
sys/rump/net/lib/libsockin/sockin.c | 28 +++---
sys/sys/param.h | 4 +-
sys/sys/protosw.h | 17 ++-
sys/sys/socketvar.h | 10 +-
32 files changed, 318 insertions(+), 357 deletions(-)
diffs (truncated from 2150 to 300 lines):
diff -r 2e4c0ac5a8af -r 45fdad8f9945 sys/compat/svr4/svr4_stream.c
--- a/sys/compat/svr4/svr4_stream.c Fri Apr 24 19:49:24 2015 +0000
+++ b/sys/compat/svr4/svr4_stream.c Fri Apr 24 22:32:37 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: svr4_stream.c,v 1.83 2015/04/19 19:17:37 rtr Exp $ */
+/* $NetBSD: svr4_stream.c,v 1.84 2015/04/24 22:32:37 rtr Exp $ */
/*-
* Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.83 2015/04/19 19:17:37 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.84 2015/04/24 22:32:37 rtr Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -872,11 +872,12 @@
struct svr4_strm *st = svr4_stream_get(fp);
int error;
struct svr4_strmcmd sc;
- struct mbuf *name;
+ struct sockaddr_big sbig;
if (st == NULL)
return EINVAL;
+ sbig.sb_len = UCHAR_MAX;
sc.offs = 0x10;
if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
@@ -887,14 +888,14 @@
switch (cmd) {
case SVR4_TI_GETMYNAME:
DPRINTF(("TI_GETMYNAME\n"));
- error = do_sys_getsockname(fd, &name);
+ error = do_sys_getsockname(fd, (struct sockaddr *)&sbig);
if (error != 0)
return error;
break;
case SVR4_TI_GETPEERNAME:
DPRINTF(("TI_GETPEERNAME\n"));
- error = do_sys_getpeername(fd, &name);
+ error = do_sys_getpeername(fd, (struct sockaddr *)&sbig);
if (error != 0)
return error;
break;
@@ -913,12 +914,12 @@
switch (st->s_family) {
case AF_INET:
- sockaddr_to_netaddr_in(&sc, mtod(name, void *));
+ sockaddr_to_netaddr_in(&sc, (struct sockaddr_in *)&sbig);
skb.len = sizeof (struct sockaddr_in);
break;
case AF_LOCAL:
- sockaddr_to_netaddr_un(&sc, mtod(name, void *));
+ sockaddr_to_netaddr_un(&sc, (struct sockaddr_un *)&sbig);
/* XXX: the length gets adjusted but the copyout doesn't */
skb.len = sizeof (struct sockaddr_un) + 4;
break;
@@ -926,12 +927,10 @@
default:
DPRINTF(("ti_ioctl: Unsupported address family %d\n",
st->s_family));
- m_free(name);
return ENOSYS;
}
- error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), name->m_len);
- m_free(name);
+ error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), sbig.sb_len);
if (error != 0) {
DPRINTF(("ti_ioctl: error copying out socket data\n"));
return error;
@@ -1539,8 +1538,10 @@
struct iovec aiov;
struct svr4_strm *st;
int fl;
+ struct sockaddr_big sbig;
struct mbuf *name;
+ sbig.sb_len = UCHAR_MAX;
memset(&sc, 0, sizeof(sc));
#ifdef DEBUG_SVR4
@@ -1618,7 +1619,8 @@
* a connect verification.
*/
- error = do_sys_getsockname(SCARG(uap, fd), &name);
+ error = do_sys_getsockname(SCARG(uap, fd),
+ (struct sockaddr *)&sbig);
if (error != 0) {
DPRINTF(("getmsg: getsockname failed %d\n", error));
goto out;
@@ -1633,20 +1635,20 @@
switch (st->s_family) {
case AF_INET:
sc.len = sizeof (struct sockaddr_in) + 4;
- sockaddr_to_netaddr_in(&sc, mtod(name, void *));
+ sockaddr_to_netaddr_in(&sc,
+ (struct sockaddr_in *)&sbig);
break;
case AF_LOCAL:
sc.len = sizeof (struct sockaddr_un) + 4;
- sockaddr_to_netaddr_un(&sc, mtod(name, void *));
+ sockaddr_to_netaddr_un(&sc,
+ (struct sockaddr_un *)&sbig);
break;
default:
- m_free(name);
error = ENOSYS;
goto out;
}
- m_free(name);
ctl.len = 40;
dat.len = -1;
@@ -1675,8 +1677,8 @@
* We are after a listen, so we try to accept...
*/
- error = do_sys_accept(l, SCARG(uap, fd), &name, retval,
- NULL, 0, FNONBLOCK);
+ error = do_sys_accept(l, SCARG(uap, fd),
+ (struct sockaddr *)&sbig, retval, NULL, 0, FNONBLOCK);
if (error != 0) {
DPRINTF(("getmsg: accept failed %d\n", error));
goto out;
@@ -1693,7 +1695,8 @@
switch (st->s_family) {
case AF_INET:
sc.pad[1] = 0x28;
- sockaddr_to_netaddr_in(&sc, mtod(name, void *));
+ sockaddr_to_netaddr_in(&sc,
+ (struct sockaddr_in *)&sbig);
ctl.len = 40;
sc.len = sizeof (struct sockaddr_in);
break;
@@ -1707,11 +1710,9 @@
break;
default:
- m_free(name);
error = ENOSYS;
goto out;
}
- m_free(name);
dat.len = -1;
fl = 0;
diff -r 2e4c0ac5a8af -r 45fdad8f9945 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c Fri Apr 24 19:49:24 2015 +0000
+++ b/sys/kern/uipc_socket.c Fri Apr 24 22:32:37 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket.c,v 1.238 2015/04/05 23:19:56 rtr Exp $ */
+/* $NetBSD: uipc_socket.c,v 1.239 2015/04/24 22:32:37 rtr 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.238 2015/04/05 23:19:56 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.239 2015/04/24 22:32:37 rtr Exp $");
#include "opt_compat_netbsd.h"
#include "opt_sock_counters.h"
@@ -793,7 +793,7 @@
}
int
-soaccept(struct socket *so, struct mbuf *nam)
+soaccept(struct socket *so, struct sockaddr *nam)
{
int error;
diff -r 2e4c0ac5a8af -r 45fdad8f9945 sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c Fri Apr 24 19:49:24 2015 +0000
+++ b/sys/kern/uipc_syscalls.c Fri Apr 24 22:32:37 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_syscalls.c,v 1.175 2015/04/03 20:01:07 rtr Exp $ */
+/* $NetBSD: uipc_syscalls.c,v 1.176 2015/04/24 22:32:37 rtr Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.175 2015/04/03 20:01:07 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.176 2015/04/24 22:32:37 rtr Exp $");
#include "opt_pipe.h"
@@ -92,6 +92,8 @@
extern const struct fileops socketops;
static int sockargs_sb(struct sockaddr_big *, const void *, socklen_t);
+static int copyout_sockname_sb(struct sockaddr *, unsigned int *,
+ int , struct sockaddr_big *);
int
sys___socket30(struct lwp *l, const struct sys___socket30_args *uap,
@@ -161,11 +163,10 @@
}
int
-do_sys_accept(struct lwp *l, int sock, struct mbuf **name,
+do_sys_accept(struct lwp *l, int sock, struct sockaddr *name,
register_t *new_sock, const sigset_t *mask, int flags, int clrflags)
{
file_t *fp, *fp2;
- struct mbuf *nam;
int error, fd;
struct socket *so, *so2;
short wakeup_state = 0;
@@ -180,7 +181,6 @@
fd_putfile(sock);
return error;
}
- nam = m_get(M_WAIT, MT_SONAME);
*new_sock = fd;
so = fp->f_socket;
solock(so);
@@ -235,12 +235,11 @@
so2->so_state |= SS_NBIO;
else
so2->so_state &= ~SS_NBIO;
- error = soaccept(so2, nam);
+ error = soaccept(so2, name);
so2->so_cred = kauth_cred_dup(so->so_cred);
sounlock(so);
if (error) {
/* an error occurred, free the file descriptor and mbuf */
- m_freem(nam);
mutex_enter(&fp2->f_lock);
fp2->f_count++;
mutex_exit(&fp2->f_lock);
@@ -249,7 +248,6 @@
} else {
fd_set_exclose(l, fd, (flags & SOCK_CLOEXEC) != 0);
fd_affix(curproc, fp2, fd);
- *name = nam;
}
fd_putfile(sock);
if (__predict_false(mask))
@@ -257,7 +255,6 @@
return error;
bad:
sounlock(so);
- m_freem(nam);
fd_putfile(sock);
fd_abort(curproc, fp2, fd);
if (__predict_false(mask))
@@ -274,15 +271,15 @@
syscallarg(unsigned int *) anamelen;
} */
int error, fd;
- struct mbuf *name;
+ struct sockaddr_big name;
- error = do_sys_accept(l, SCARG(uap, s), &name, retval, NULL, 0, 0);
+ name.sb_len = UCHAR_MAX;
+ error = do_sys_accept(l, SCARG(uap, s), (struct sockaddr *)&name,
+ retval, NULL, 0, 0);
if (error != 0)
return error;
- error = copyout_sockname(SCARG(uap, name), SCARG(uap, anamelen),
- MSG_LENUSRSPACE, name);
- if (name != NULL)
- m_free(name);
+ error = copyout_sockname_sb(SCARG(uap, name), SCARG(uap, anamelen),
+ MSG_LENUSRSPACE, &name);
if (error != 0) {
fd = (int)*retval;
if (fd_getfile(fd) != NULL)
@@ -303,7 +300,7 @@
syscallarg(int) flags;
} */
int error, fd;
- struct mbuf *name;
+ struct sockaddr_big name;
sigset_t *mask, amask;
if (SCARG(uap, mask) != NULL) {
@@ -314,14 +311,13 @@
} else
mask = NULL;
- error = do_sys_accept(l, SCARG(uap, s), &name, retval, mask,
- SCARG(uap, flags), FNONBLOCK);
+ name.sb_len = UCHAR_MAX;
Home |
Main Index |
Thread Index |
Old Index