Skip to content

Commit

Permalink
make connect syscall use sockaddr_big and modify pr_{send,connect}
Browse files Browse the repository at this point in the history
nam parameter type from buf * to sockaddr *.

final commit for parameter type changes to protocol user requests

* bump kernel version to 7.99.15 for parameter type changes to pr_{send,connect}
  • Loading branch information
rtr committed May 2, 2015
1 parent df895d4 commit 10d0013
Show file tree
Hide file tree
Showing 41 changed files with 224 additions and 272 deletions.
10 changes: 5 additions & 5 deletions sys/compat/linux/common/linux_socket.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: linux_socket.c,v 1.123 2015/04/03 20:01:07 rtr Exp $ */
/* $NetBSD: linux_socket.c,v 1.124 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -35,7 +35,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.123 2015/04/03 20:01:07 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.124 2015/05/02 17:18:03 rtr Exp $");

#if defined(_KERNEL_OPT)
#include "opt_inet.h"
Expand Down Expand Up @@ -1402,14 +1402,14 @@ linux_sys_connect(struct lwp *l, const struct linux_sys_connect_args *uap, regis
syscallarg(int) namelen;
} */
int error;
struct mbuf *nam;
struct sockaddr_big sb;

error = linux_get_sa(l, SCARG(uap, s), &nam, SCARG(uap, name),
error = linux_get_sa_sb(l, SCARG(uap, s), &sb, SCARG(uap, name),
SCARG(uap, namelen));
if (error)
return (error);

error = do_sys_connect(l, SCARG(uap, s), nam);
error = do_sys_connect(l, SCARG(uap, s), (struct sockaddr *)&sb);

if (error == EISCONN) {
struct socket *so;
Expand Down
7 changes: 4 additions & 3 deletions sys/compat/svr4/svr4_stream.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: svr4_stream.c,v 1.84 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: svr4_stream.c,v 1.85 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -39,7 +39,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.84 2015/04/24 22:32:37 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.85 2015/05/02 17:18:03 rtr Exp $");

#include <sys/param.h>
#include <sys/kernel.h>
Expand Down Expand Up @@ -1495,7 +1495,8 @@ svr4_sys_putmsg(struct lwp *l, const struct svr4_sys_putmsg_args *uap, register_
switch (st->s_cmd = sc.cmd) {
case SVR4_TI_CONNECT_REQUEST: /* connect */
KERNEL_UNLOCK_ONE(NULL);
return do_sys_connect(l, SCARG(uap, fd), nam);
return do_sys_connect(l, SCARG(uap, fd),
mtod(nam, struct sockaddr *));

case SVR4_TI_SENDTO_REQUEST: /* sendto */
KERNEL_UNLOCK_ONE(NULL);
Expand Down
17 changes: 11 additions & 6 deletions sys/kern/uipc_socket.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket.c,v 1.239 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: uipc_socket.c,v 1.240 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -71,7 +71,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.239 2015/04/24 22:32:37 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.240 2015/05/02 17:18:03 rtr Exp $");

#include "opt_compat_netbsd.h"
#include "opt_sock_counters.h"
Expand Down Expand Up @@ -811,7 +811,7 @@ soaccept(struct socket *so, struct sockaddr *nam)
}

int
soconnect(struct socket *so, struct mbuf *nam, struct lwp *l)
soconnect(struct socket *so, struct sockaddr *nam, struct lwp *l)
{
int error;

Expand Down Expand Up @@ -1051,12 +1051,17 @@ sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top,
so->so_options |= SO_DONTROUTE;
if (resid > 0)
so->so_state |= SS_MORETOCOME;
if (flags & MSG_OOB)
if (flags & MSG_OOB) {
error = (*so->so_proto->pr_usrreqs->pr_sendoob)(so,
top, control);
else
} else {
struct sockaddr *sin = NULL;
if (addr) {
sin = mtod(addr, struct sockaddr *);
}
error = (*so->so_proto->pr_usrreqs->pr_send)(so,
top, addr, control, l);
top, sin, control, l);
}
if (dontroute)
so->so_options &= ~SO_DONTROUTE;
if (resid > 0)
Expand Down
16 changes: 6 additions & 10 deletions sys/kern/uipc_syscalls.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: uipc_syscalls.c,v 1.176 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.177 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -61,7 +61,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.176 2015/04/24 22:32:37 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.177 2015/05/02 17:18:03 rtr Exp $");

#include "opt_pipe.h"

Expand Down Expand Up @@ -336,28 +336,25 @@ sys_connect(struct lwp *l, const struct sys_connect_args *uap,
syscallarg(unsigned int) namelen;
} */
int error;
struct mbuf *nam;
struct sockaddr_big sbig;

error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen),
MT_SONAME);
error = sockargs_sb(&sbig, SCARG(uap, name), SCARG(uap, namelen));
if (error)
return error;
return do_sys_connect(l, SCARG(uap, s), nam);
return do_sys_connect(l, SCARG(uap, s), (struct sockaddr *)&sbig);
}

int
do_sys_connect(struct lwp *l, int fd, struct mbuf *nam)
do_sys_connect(struct lwp *l, int fd, struct sockaddr *nam)
{
struct socket *so;
int error;
int interrupted = 0;

if ((error = fd_getsock(fd, &so)) != 0) {
m_freem(nam);
return (error);
}
solock(so);
MCLAIM(nam, so->so_mowner);
if ((so->so_state & SS_ISCONNECTING) != 0) {
error = EALREADY;
goto out;
Expand Down Expand Up @@ -396,7 +393,6 @@ do_sys_connect(struct lwp *l, int fd, struct mbuf *nam)
out:
sounlock(so);
fd_putfile(fd);
m_freem(nam);
return error;
}

Expand Down
32 changes: 5 additions & 27 deletions sys/kern/uipc_usrreq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: uipc_usrreq.c,v 1.178 2015/04/26 21:40:48 rtr Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.179 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -96,7 +96,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.178 2015/04/26 21:40:48 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.179 2015/05/02 17:18:03 rtr Exp $");

#include <sys/param.h>
#include <sys/systm.h>
Expand Down Expand Up @@ -409,7 +409,7 @@ unp_recvoob(struct socket *so, struct mbuf *m, int flags)
}

static int
unp_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
unp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct lwp *l)
{
struct unpcb *unp = sotounpcb(so);
Expand Down Expand Up @@ -860,28 +860,6 @@ unp_sockaddr(struct socket *so, struct sockaddr *nam)
return 0;
}

/*
* Allocate the new sockaddr. We have to allocate one
* extra byte so that we can ensure that the pathname
* is nul-terminated. Note that unlike linux, we don't
* include in the address length the NUL in the path
* component, because doing so, would exceed sizeof(sockaddr_un)
* for fully occupied pathnames. Linux is also inconsistent,
* because it does not include the NUL in the length of
* what it calls "abstract" unix sockets.
*/
static struct sockaddr_un *
makeun(struct mbuf *nam, size_t *addrlen)
{
struct sockaddr_un *sun;

*addrlen = nam->m_len + 1;
sun = malloc(*addrlen, M_SONAME, M_WAITOK);
m_copydata(nam, 0, nam->m_len, (void *)sun);
*(((char *)sun) + nam->m_len) = '\0';
return sun;
}

/*
* we only need to perform this allocation until syscalls other than
* bind are adjusted to use sockaddr_big.
Expand Down Expand Up @@ -1105,7 +1083,7 @@ unp_connect1(struct socket *so, struct socket *so2, struct lwp *l)
}

int
unp_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
unp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l)
{
struct sockaddr_un *sun;
vnode_t *vp;
Expand All @@ -1127,7 +1105,7 @@ unp_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
unp->unp_flags |= UNP_BUSY;
sounlock(so);

sun = makeun(nam, &addrlen);
sun = makeun_sb(nam, &addrlen);
pb = pathbuf_create(sun->sun_path);
if (pb == NULL) {
error = ENOMEM;
Expand Down
28 changes: 7 additions & 21 deletions sys/net/if_gre.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: if_gre.c,v 1.164 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: if_gre.c,v 1.165 2015/05/02 17:18:03 rtr Exp $ */

/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -45,7 +45,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.164 2015/04/24 22:32:37 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.165 2015/05/02 17:18:03 rtr Exp $");

#include "opt_atalk.h"
#include "opt_gre.h"
Expand Down Expand Up @@ -418,9 +418,8 @@ static int
gre_socreate(struct gre_softc *sc, const struct gre_soparm *sp, int *fdout)
{
int fd, rc;
struct mbuf *m;
struct sockaddr *sa;
struct socket *so;
struct sockaddr_big sbig;
sa_family_t af;
int val;

Expand All @@ -436,32 +435,21 @@ gre_socreate(struct gre_softc *sc, const struct gre_soparm *sp, int *fdout)
if ((rc = fd_getsock(fd, &so)) != 0)
return rc;

if ((m = getsombuf(so, MT_SONAME)) == NULL) {
rc = ENOBUFS;
goto out;
}
sa = mtod(m, struct sockaddr *);
sockaddr_copy(sa, MIN(MLEN, sizeof(sp->sp_src)), sstocsa(&sp->sp_src));
m->m_len = sp->sp_src.ss_len;

if ((rc = sobind(so, sa, curlwp)) != 0) {
memcpy(&sbig, &sp->sp_src, sizeof(sp->sp_src));
if ((rc = sobind(so, (struct sockaddr *)&sbig, curlwp)) != 0) {
GRE_DPRINTF(sc, "sobind failed\n");
goto out;
}

sockaddr_copy(sa, MIN(MLEN, sizeof(sp->sp_dst)), sstocsa(&sp->sp_dst));
m->m_len = sp->sp_dst.ss_len;

memcpy(&sbig, &sp->sp_dst, sizeof(sp->sp_dst));
solock(so);
if ((rc = soconnect(so, m, curlwp)) != 0) {
if ((rc = soconnect(so, (struct sockaddr *)&sbig, curlwp)) != 0) {
GRE_DPRINTF(sc, "soconnect failed\n");
sounlock(so);
goto out;
}
sounlock(so);

m = NULL;

/* XXX convert to a (new) SOL_SOCKET call */
KASSERT(so->so_proto != NULL);
rc = so_setsockopt(curlwp, so, IPPROTO_IP, IP_TTL,
Expand All @@ -479,8 +467,6 @@ gre_socreate(struct gre_softc *sc, const struct gre_soparm *sp, int *fdout)
rc = 0;
}
out:
m_freem(m);

if (rc != 0)
fd_close(fd);
else {
Expand Down
12 changes: 6 additions & 6 deletions sys/net/link_proto.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: link_proto.c,v 1.27 2015/04/26 21:40:48 rtr Exp $ */
/* $NetBSD: link_proto.c,v 1.28 2015/05/02 17:18:03 rtr Exp $ */

/*-
* Copyright (c) 1982, 1986, 1993
Expand Down Expand Up @@ -32,7 +32,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.27 2015/04/26 21:40:48 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.28 2015/05/02 17:18:03 rtr Exp $");

#include <sys/param.h>
#include <sys/socket.h>
Expand All @@ -53,7 +53,7 @@ static void link_detach(struct socket *);
static int link_accept(struct socket *, struct sockaddr *);
static int link_bind(struct socket *, struct sockaddr *, struct lwp *);
static int link_listen(struct socket *, struct lwp *);
static int link_connect(struct socket *, struct mbuf *, struct lwp *);
static int link_connect(struct socket *, struct sockaddr *, struct lwp *);
static int link_connect2(struct socket *, struct socket *);
static int link_disconnect(struct socket *);
static int link_shutdown(struct socket *);
Expand All @@ -64,7 +64,7 @@ static int link_peeraddr(struct socket *, struct sockaddr *);
static int link_sockaddr(struct socket *, struct sockaddr *);
static int link_rcvd(struct socket *, int, struct lwp *);
static int link_recvoob(struct socket *, struct mbuf *, int);
static int link_send(struct socket *, struct mbuf *, struct mbuf *,
static int link_send(struct socket *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct lwp *);
static int link_sendoob(struct socket *, struct mbuf *, struct mbuf *);
static int link_purgeif(struct socket *, struct ifnet *);
Expand Down Expand Up @@ -287,7 +287,7 @@ link_listen(struct socket *so, struct lwp *l)
}

static int
link_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
link_connect(struct socket *so, struct sockaddr *nam, struct lwp *l)
{
KASSERT(solocked(so));

Expand Down Expand Up @@ -373,7 +373,7 @@ link_recvoob(struct socket *so, struct mbuf *m, int flags)
}

static int
link_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
link_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct lwp *l)
{
KASSERT(solocked(so));
Expand Down
4 changes: 2 additions & 2 deletions sys/net/raw_cb.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: raw_cb.h,v 1.24 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: raw_cb.h,v 1.25 2015/05/02 17:18:03 rtr Exp $ */

/*
* Copyright (c) 1980, 1986, 1993
Expand Down Expand Up @@ -71,7 +71,7 @@ int raw_usrreq(struct socket *,
void raw_setsockaddr(struct rawcb *, struct sockaddr *);
void raw_setpeeraddr(struct rawcb *, struct sockaddr *);
int raw_send(struct socket *,
struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
struct mbuf *, struct sockaddr *, struct mbuf *, struct lwp *);

#endif /* _KERNEL */

Expand Down
6 changes: 3 additions & 3 deletions sys/net/raw_usrreq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: raw_usrreq.c,v 1.53 2015/04/24 22:32:37 rtr Exp $ */
/* $NetBSD: raw_usrreq.c,v 1.54 2015/05/02 17:18:03 rtr Exp $ */

/*
* Copyright (c) 1980, 1986, 1993
Expand Down Expand Up @@ -36,7 +36,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.53 2015/04/24 22:32:37 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.54 2015/05/02 17:18:03 rtr Exp $");

#include <sys/param.h>
#include <sys/mbuf.h>
Expand Down Expand Up @@ -152,7 +152,7 @@ raw_setpeeraddr(struct rawcb *rp, struct sockaddr *nam)
}

int
raw_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
raw_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct lwp *l)
{
struct rawcb *rp = sotorawcb(so);
Expand Down
Loading

0 comments on commit 10d0013

Please sign in to comment.