Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add ioctl(2) handler for kernel part of sctp_peeloff().



details:   https://anonhg.NetBSD.org/src/rev/facf1e7ba12a
branches:  trunk
changeset: 365133:facf1e7ba12a
user:      rjs <rjs%NetBSD.org@localhost>
date:      Wed Aug 01 23:35:32 2018 +0000

description:
Add ioctl(2) handler for kernel part of sctp_peeloff().

diffstat:

 sys/kern/sys_socket.c    |  10 +++++-
 sys/kern/uipc_syscalls.c |  76 ++++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/socketvar.h      |   3 +-
 sys/sys/sockio.h         |   5 ++-
 4 files changed, 88 insertions(+), 6 deletions(-)

diffs (171 lines):

diff -r 7eb6a6e1d7b6 -r facf1e7ba12a sys/kern/sys_socket.c
--- a/sys/kern/sys_socket.c     Wed Aug 01 22:18:23 2018 +0000
+++ b/sys/kern/sys_socket.c     Wed Aug 01 23:35:32 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_socket.c,v 1.76 2017/11/30 20:25:55 christos Exp $ */
+/*     $NetBSD: sys_socket.c,v 1.77 2018/08/01 23:35:32 rjs Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.76 2017/11/30 20:25:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.77 2018/08/01 23:35:32 rjs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -192,6 +192,12 @@
                *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
                break;
 
+       case SIOCPEELOFF:
+               solock(so);
+               error = do_sys_peeloff(so, data);
+               sounlock(so);
+               break;
+
        default:
                /*
                 * Interface/routing/protocol specific ioctls:
diff -r 7eb6a6e1d7b6 -r facf1e7ba12a sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Wed Aug 01 22:18:23 2018 +0000
+++ b/sys/kern/uipc_syscalls.c  Wed Aug 01 23:35:32 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.195 2018/07/31 13:00:13 rjs Exp $  */
+/*     $NetBSD: uipc_syscalls.c,v 1.196 2018/08/01 23:35:32 rjs Exp $  */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,10 +61,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.195 2018/07/31 13:00:13 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.196 2018/08/01 23:35:32 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
+#include "opt_sctp.h"
 #endif
 
 #define MBUFTYPES
@@ -85,6 +86,11 @@
 #include <sys/atomic.h>
 #include <sys/kauth.h>
 
+#ifdef SCTP
+#include <netinet/sctp_uio.h>
+#include <netinet/sctp_peeloff.h>
+#endif
+
 #include <sys/mount.h>
 #include <sys/syscallargs.h>
 
@@ -1606,3 +1612,69 @@
                return EINVAL;
        }
 }
+
+int
+do_sys_peeloff(struct socket *head, void *data)
+{
+#ifdef SCTP
+       /*file_t *lfp = NULL;*/
+       file_t *nfp = NULL;
+       int error;
+       struct socket *so;
+       int fd;
+       uint32_t name;
+       /*short fflag;*/                /* type must match fp->f_flag */
+
+       name = *(uint32_t *) data;
+       error = sctp_can_peel_off(head, name);
+       if (error) {
+               printf("peeloff failed\n");
+               return error;
+       }
+       /*
+        * At this point we know we do have a assoc to pull
+        * we proceed to get the fd setup. This may block
+        * but that is ok.
+        */
+       error = fd_allocfile(&nfp, &fd);
+       if (error) {
+               /*
+                * Probably ran out of file descriptors. Put the
+                * unaccepted connection back onto the queue and
+                * do another wakeup so some other process might
+                * have a chance at it.
+                */
+               return error;
+       }
+       *(int *) data = fd;
+
+       so = sctp_get_peeloff(head, name, &error);
+       if (so == NULL) {
+               /*
+                * Either someone else peeled it off OR
+                * we can't get a socket.
+                * close the new descriptor, assuming someone hasn't ripped it
+                * out from under us.
+                */
+               mutex_enter(&nfp->f_lock);
+               nfp->f_count++;
+               mutex_exit(&nfp->f_lock);
+               fd_abort(curlwp->l_proc, nfp, fd);
+               return error;
+       }
+       so->so_state &= ~SS_NOFDREF;
+       so->so_state &= ~SS_ISCONNECTING;
+       so->so_head = NULL;
+       so->so_cred = kauth_cred_dup(head->so_cred);
+       nfp->f_socket = so;
+       nfp->f_flag = FREAD|FWRITE;
+       nfp->f_ops = &socketops;
+       nfp->f_type = DTYPE_SOCKET;
+
+       fd_affix(curlwp->l_proc, nfp, fd);
+
+       return error;
+#else
+       return EOPNOTSUPP;
+#endif
+}
diff -r 7eb6a6e1d7b6 -r facf1e7ba12a sys/sys/socketvar.h
--- a/sys/sys/socketvar.h       Wed Aug 01 22:18:23 2018 +0000
+++ b/sys/sys/socketvar.h       Wed Aug 01 23:35:32 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: socketvar.h,v 1.157 2018/07/20 08:26:25 msaitoh Exp $  */
+/*     $NetBSD: socketvar.h,v 1.158 2018/08/01 23:35:32 rjs Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -378,6 +378,7 @@
 int    do_sys_accept(struct lwp *, int, struct sockaddr *, register_t *,
            const sigset_t *, int, int);
 
+int    do_sys_peeloff(struct socket *, void *);
 /*
  * Inline functions for sockets and socket buffering.
  */
diff -r 7eb6a6e1d7b6 -r facf1e7ba12a sys/sys/sockio.h
--- a/sys/sys/sockio.h  Wed Aug 01 22:18:23 2018 +0000
+++ b/sys/sys/sockio.h  Wed Aug 01 23:35:32 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sockio.h,v 1.34 2018/07/31 16:44:30 khorben Exp $      */
+/*     $NetBSD: sockio.h,v 1.35 2018/08/01 23:35:32 rjs Exp $  */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993, 1994
@@ -44,6 +44,9 @@
 #define        SIOCATMARK       _IOR('s',  7, int)             /* at oob mark? */
 #define        SIOCSPGRP        _IOW('s',  8, int)             /* set process group */
 #define        SIOCGPGRP        _IOR('s',  9, int)             /* get process group */
+#define SIOCPEELOFF    _IOWR('s', 10, int)
+/* ('s', 11, ...) is SIOCCONNECTX in sctp_uio.h */
+/* ('s', 12, ...) is SIOCCONNECTXDEL in sctp_uio.h */
 
 #define        SIOCADDRT        _IOW('r', 10, struct ortentry) /* add route */
 #define        SIOCDELRT        _IOW('r', 11, struct ortentry) /* delete route */



Home | Main Index | Thread Index | Old Index