summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2003-02-03 17:36:52 +0000
committerume <ume@FreeBSD.org>2003-02-03 17:36:52 +0000
commit56a5dfaa24349bed857b3805b98341abc2ffd79b (patch)
tree1a379b9a0014f36717f9a339198f8586b7c11477
parentf23045a1e28bb22381513299781e2c1dc85015f5 (diff)
downloadFreeBSD-src-56a5dfaa24349bed857b3805b98341abc2ffd79b.zip
FreeBSD-src-56a5dfaa24349bed857b3805b98341abc2ffd79b.tar.gz
Break out the bind and connect syscalls to intend to make calling
these syscalls internally easy. This is preparation for force coming IPv6 support for Linuxlator. Submitted by: dwmalone MFC after: 10 days
-rw-r--r--sys/kern/uipc_syscalls.c55
-rw-r--r--sys/sys/syscallsubr.h4
2 files changed, 44 insertions, 15 deletions
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c
index 145e138..d0ccfa0 100644
--- a/sys/kern/uipc_syscalls.c
+++ b/sys/kern/uipc_syscalls.c
@@ -61,6 +61,7 @@
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/signalvar.h>
+#include <sys/syscallsubr.h>
#include <sys/uio.h>
#include <sys/vnode.h>
#ifdef KTRACE
@@ -167,28 +168,40 @@ bind(td, uap)
int namelen;
} */ *uap;
{
- struct socket *so;
struct sockaddr *sa;
int error;
+ if ((error = getsockaddr(&sa, uap->name, uap->namelen)) != 0)
+ return (error);
+
+ return (kern_bind(td, uap->s, sa));
+}
+
+int
+kern_bind(td, fd, sa)
+ struct thread *td;
+ int fd;
+ struct sockaddr *sa;
+{
+ struct socket *so;
+ int error;
+
mtx_lock(&Giant);
- if ((error = fgetsock(td, uap->s, &so, NULL)) != 0)
+ if ((error = fgetsock(td, fd, &so, NULL)) != 0)
goto done2;
- if ((error = getsockaddr(&sa, uap->name, uap->namelen)) != 0)
- goto done1;
#ifdef MAC
error = mac_check_socket_bind(td->td_ucred, so, sa);
- if (error) {
- FREE(sa, M_SONAME);
+ if (error)
goto done1;
- }
#endif
error = sobind(so, sa, td);
- FREE(sa, M_SONAME);
+#ifdef MAC
done1:
+#endif
fputsock(so);
done2:
mtx_unlock(&Giant);
+ FREE(sa, M_SONAME);
return (error);
}
@@ -442,20 +455,33 @@ connect(td, uap)
int namelen;
} */ *uap;
{
- struct socket *so;
struct sockaddr *sa;
+ int error;
+
+ error = getsockaddr(&sa, uap->name, uap->namelen);
+ if (error)
+ return error;
+
+ return (kern_connect(td, uap->s, sa));
+}
+
+
+int
+kern_connect(td, fd, sa)
+ struct thread *td;
+ int fd;
+ struct sockaddr *sa;
+{
+ struct socket *so;
int error, s;
mtx_lock(&Giant);
- if ((error = fgetsock(td, uap->s, &so, NULL)) != 0)
+ if ((error = fgetsock(td, fd, &so, NULL)) != 0)
goto done2;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
error = EALREADY;
goto done1;
}
- error = getsockaddr(&sa, uap->name, uap->namelen);
- if (error)
- goto done1;
#ifdef MAC
error = mac_check_socket_connect(td->td_ucred, so, sa);
if (error)
@@ -465,7 +491,6 @@ connect(td, uap)
if (error)
goto bad;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
- FREE(sa, M_SONAME);
error = EINPROGRESS;
goto done1;
}
@@ -482,13 +507,13 @@ connect(td, uap)
splx(s);
bad:
so->so_state &= ~SS_ISCONNECTING;
- FREE(sa, M_SONAME);
if (error == ERESTART)
error = EINTR;
done1:
fputsock(so);
done2:
mtx_unlock(&Giant);
+ FREE(sa, M_SONAME);
return (error);
}
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 25c2f53..874bffd 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -31,15 +31,19 @@
#include <sys/signal.h>
#include <sys/uio.h>
+struct sockaddr;
+
int kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg,
u_int buflen);
int kern_access(struct thread *td, char *path, enum uio_seg pathseg,
int flags);
+int kern_bind(struct thread *td, int fd, struct sockaddr *sa);
int kern_chdir(struct thread *td, char *path, enum uio_seg pathseg);
int kern_chmod(struct thread *td, char *path, enum uio_seg pathseg,
int mode);
int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid,
int gid);
+int kern_connect(struct thread *td, int fd, struct sockaddr *sa);
int kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg);
int kern_futimes(struct thread *td, int fd, struct timeval *tptr,
enum uio_seg tptrseg);
OpenPOWER on IntegriCloud