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
This commit is contained in:
ume 2003-02-03 17:36:52 +00:00
parent f23045a1e2
commit 56a5dfaa24
2 changed files with 45 additions and 16 deletions

View File

@ -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;
mtx_lock(&Giant);
if ((error = fgetsock(td, uap->s, &so, NULL)) != 0)
goto done2;
if ((error = getsockaddr(&sa, uap->name, uap->namelen)) != 0)
goto done1;
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, fd, &so, NULL)) != 0)
goto done2;
#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);
}

View File

@ -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);