Source-Changes-HG archive

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

[src/trunk]: src/sys Clean up this mess and simplify, so that all the socket ...



details:   https://anonhg.NetBSD.org/src/rev/370251e107ec
branches:  trunk
changeset: 840707:370251e107ec
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Apr 15 10:53:17 2019 +0000

description:
Clean up this mess and simplify, so that all the socket options get
handled correctly whether or not the compat_50 module is loaded.

diffstat:

 sys/compat/common/kern_uipc_socket_50.c |  46 ++++++++++++++++++++++----------
 sys/kern/uipc_socket.c                  |  38 +++++++--------------------
 sys/sys/compat_stub.h                   |   7 ++--
 3 files changed, 45 insertions(+), 46 deletions(-)

diffs (203 lines):

diff -r d049e41f2169 -r 370251e107ec sys/compat/common/kern_uipc_socket_50.c
--- a/sys/compat/common/kern_uipc_socket_50.c   Mon Apr 15 10:17:01 2019 +0000
+++ b/sys/compat/common/kern_uipc_socket_50.c   Mon Apr 15 10:53:17 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $ */
+/*     $NetBSD: kern_uipc_socket_50.c,v 1.2 2019/04/15 10:53:17 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_uipc_socket_50.c,v 1.2 2019/04/15 10:53:17 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -121,8 +121,7 @@
 #include <compat/common/compat_mod.h>
 
 static int
-uipc_socket_50_getopt1(int opt, struct socket *so, struct sockopt *sopt,
-    struct timeval *tv)
+uipc_socket_50_getopt1(int opt, struct socket *so, struct sockopt *sopt)
 {
        int optval, error;
        struct timeval50 otv;
@@ -151,27 +150,46 @@
 }
 
 static int
-uipc_socket_50_setopt1(int opt, struct socket *so, const struct sockopt *sopt,
-    struct timeval *tv)
+uipc_socket_50_setopt1(int opt, struct socket *so, const struct sockopt *sopt)
 {
        int optval, error;
        struct timeval50 otv;
+       struct timeval tv;
 
        switch (opt) {
 
        case SO_OSNDTIMEO:
        case SO_ORCVTIMEO:
+               solock(so);
+
                error = sockopt_get(sopt, &otv, sizeof(otv));
-               if (error) {
-                       solock(so);
+               if (error)
+                       break;
+
+               timeval50_to_timeval(&otv, &tv);
+
+               /* Code duplicated from sys/kern/uipc_socket.c */
+               if (tv.tv_sec < 0 || tv.tv_usec < 0 || tv.tv_usec >= 1000000) {
+                       error = EDOM;
                        break;
                }
-               timeval50_to_timeval(&otv, tv);
-               opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO;
-               /*
-                * Processing will continue as for SO_SNDTIMEO
-                * and SO_RCVTIMEO, using the new-format tv
-                */
+               if (tv.tv_sec > (INT_MAX - tv.tv_usec / tick) / hz) {
+                       error = EDOM;
+                       break;
+               }
+
+               optval = tv.tv_sec * hz + tv.tv_usec / tick;
+               if (optval == 0 && tv.tv_usec != 0)
+                       optval = 1;
+
+               switch (opt) {
+               case SO_OSNDTIMEO:
+                       so->so_snd.sb_timeo = optval;
+                       break;
+               case SO_ORCVTIMEO:
+                       so->so_rcv.sb_timeo = optval;
+                       break;
+               }       
                break;
 
        case SO_OTIMESTAMP:
diff -r d049e41f2169 -r 370251e107ec sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Mon Apr 15 10:17:01 2019 +0000
+++ b/sys/kern/uipc_socket.c    Mon Apr 15 10:53:17 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.277 2019/04/15 03:58:29 pgoyette Exp $       */
+/*     $NetBSD: uipc_socket.c,v 1.278 2019/04/15 10:53:17 pgoyette 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.277 2019/04/15 03:58:29 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.278 2019/04/15 10:53:17 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1713,15 +1713,6 @@
 
        opt = sopt->sopt_name;
 
-       MODULE_HOOK_CALL(uipc_socket_50_setopt1_hook, (opt, so, sopt, &tv),
-           enosys(), error);
-       if (error == EPASSTHROUGH)
-               error = EINVAL;
-       else if (error && error != ENOSYS) {
-               KASSERT(solocked(so));
-               return error;
-       }
-
        switch (opt) {
 
        case SO_ACCEPTFILTER:
@@ -1822,19 +1813,10 @@
                }
                break;
 
-       case SO_OSNDTIMEO:
-       case SO_ORCVTIMEO:
-               if (error == ENOSYS) {
-                       error = EINVAL;
-                       solock(so);
-                       break;
-               }
-               /* FALLTHROUGH */
        case SO_SNDTIMEO:
        case SO_RCVTIMEO:
-               if (error)
-                       error = sockopt_get(sopt, &tv, sizeof(tv));
                solock(so);
+               error = sockopt_get(sopt, &tv, sizeof(tv));
                if (error)
                        break;
 
@@ -1852,11 +1834,9 @@
                        optval = 1;
 
                switch (opt) {
-               case SO_OSNDTIMEO:
                case SO_SNDTIMEO:
                        so->so_snd.sb_timeo = optval;
                        break;
-               case SO_ORCVTIMEO:
                case SO_RCVTIMEO:
                        so->so_rcv.sb_timeo = optval;
                        break;
@@ -1864,10 +1844,12 @@
                break;
 
        default:
-               if (error == 0)
-                       break;
-               solock(so);
-               error = ENOPROTOOPT;
+               MODULE_HOOK_CALL(uipc_socket_50_setopt1_hook,
+                   (opt, so, sopt), enosys(), error);
+               if (error == ENOSYS || error == EPASSTHROUGH) {
+                       solock(so);
+                       error = ENOPROTOOPT;
+               }
                break;
        }
        KASSERT(solocked(so));
@@ -2006,7 +1988,7 @@
 
        default:
                MODULE_HOOK_CALL(uipc_socket_50_getopt1_hook,
-                   (opt, so, sopt, &tv), enosys(), error);
+                   (opt, so, sopt), enosys(), error);
                if (error)
                        error = ENOPROTOOPT;
                break;
diff -r d049e41f2169 -r 370251e107ec sys/sys/compat_stub.h
--- a/sys/sys/compat_stub.h     Mon Apr 15 10:17:01 2019 +0000
+++ b/sys/sys/compat_stub.h     Mon Apr 15 10:53:17 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_stub.h,v 1.12 2019/04/15 02:07:11 pgoyette Exp $        */
+/*     $NetBSD: compat_stub.h,v 1.13 2019/04/15 10:53:17 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -224,13 +224,12 @@
  * uipc_socket_50 compatibility
  */
 struct sockopt;
-struct timeval;
 struct mbuf;
 
 MODULE_HOOK(uipc_socket_50_setopt1_hook, int,
-    (int, struct socket *, const struct sockopt *, struct timeval *));
+    (int, struct socket *, const struct sockopt *));
 MODULE_HOOK(uipc_socket_50_getopt1_hook, int,
-    (int, struct socket *, struct sockopt *, struct timeval *));
+    (int, struct socket *, struct sockopt *));
 MODULE_HOOK(uipc_socket_50_sbts_hook, int, (int, struct mbuf **));
 
 /*



Home | Main Index | Thread Index | Old Index