Source-Changes-HG archive

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

[src/trunk]: src/sys The max subtype of the ifmedia word is 31. It's too smal...



details:   https://anonhg.NetBSD.org/src/rev/91ab377790af
branches:  trunk
changeset: 451346:91ab377790af
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri May 17 07:37:11 2019 +0000

description:
The max subtype of the ifmedia word is 31. It's too small for Ethernet now.
We currently use use it up to 30. We should extend the limit to be able to use
more than 10Gbps speeds. Our ifmedia(4) is inconvenience and have some problem
so we should redesign the interface, but it's too late for netbsd-9 to do it.
So, we keep the data structure size and modify the structure a bit. The
strategy is almost the same as FreeBSD. Many bits of IFM_OMASK for Ethernet
have not used, so use some of them for Ethernet's subtype.

The differences against FreeBSD are:
 - We use NetBSD style compat code (i.e. no SIOCGIFXMEDIA).
 - FreeBSD's IFM_ETH_XTYPE's bit location is from 11 to "14" even though
   IFM_OMASK is from 8 to "15". We use _IFM_ETH_XTMASK from bit 13 to "15".
 - FreeBSD changed the meaning of IFM_TYPE_MATCH(). I think we should
   not do it. We keep it not changing and added new IFM_TYPE_SUBTYPE_MATCH()
   macro for matching both TYPE and SUBTYPE.
 - Added up to 400GBASE-SR16.

New layout of the media word is as follows (from ifmedia_h):

 * if_media Options word:
 *      Bits    Use
 *      ----    -------
 *      0-4     Media subtype   MAX SUBTYPE == 255 for ETH and 31 for others
 *      5-7     Media type
 *      8-15    Type specific options
 *      16-18   Mode (for multi-mode devices)
 *      19      (Reserved for Future Use)
 *      20-27   Shared (global) options
 *      28-31   Instance
 *
 *   3                     2                   1
 *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 *  +-------+---------------+-+-----+---------------+-----+---------+
 *  |       |               |R|     |               |     |         |
 *  | IMASK |     GMASK     |F|MMASK+-----+ OMASK   |NMASK|  TMASK  |
 *  |       |               |U|     |XTMSK|         |     |         |
 *  +-------+---------------+-+-----+-----+---------+-----+---------+
 *   <----->                   <--->                 <--->
 *  IFM_INST()               IFM_MODE()            IFM_TYPE()
 *
 *                              IFM_SUBTYPE(other than ETH)<------->
 *
 *                                   <---> IFM_SUBTYPE(ETH)<------->
 *
 *
 *           <------------->         <------------->
 *                        IFM_OPTIONS()

diffstat:

 sys/compat/common/Makefile.sysio     |    4 +-
 sys/compat/common/compat_80_mod.c    |    6 +-
 sys/compat/common/compat_mod.h       |    4 +-
 sys/compat/common/files.common       |    3 +-
 sys/compat/common/if_43.c            |    8 +-
 sys/compat/common/if_media_80.c      |  192 ++++++++++++++++++++++++++
 sys/compat/netbsd32/netbsd32_ioctl.c |    6 +-
 sys/compat/netbsd32/netbsd32_ioctl.h |   10 +-
 sys/compat/sys/sockio.h              |    6 +-
 sys/kern/compat_stub.c               |    8 +-
 sys/net/if.c                         |   28 ++-
 sys/net/if_media.c                   |    9 +-
 sys/net/if_media.h                   |  256 +++++++++++++++++++++++++++++++++-
 sys/sys/compat_stub.h                |   11 +-
 sys/sys/sockio.h                     |    6 +-
 15 files changed, 507 insertions(+), 50 deletions(-)

diffs (truncated from 896 to 300 lines):

diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/Makefile.sysio
--- a/sys/compat/common/Makefile.sysio  Fri May 17 06:05:07 2019 +0000
+++ b/sys/compat/common/Makefile.sysio  Fri May 17 07:37:11 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.sysio,v 1.11 2019/01/27 02:08:39 pgoyette Exp $
+#      $NetBSD: Makefile.sysio,v 1.12 2019/05/17 07:37:11 msaitoh Exp $
 
 # Sources for syscall and ioctl compatibility across the versions.
 
@@ -47,7 +47,7 @@
 SRCS+= rtsock_70.c uipc_usrreq_70.c
 
 # Compatability code for NetBSD 8.0
-SRCS+= kern_mod_80.c
+SRCS+= kern_mod_80.c if_media_80.c
 
 # More compatibility code for NetBSD 5.0
 .PATH: ${S}/opencrypto
diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/compat_80_mod.c
--- a/sys/compat/common/compat_80_mod.c Fri May 17 06:05:07 2019 +0000
+++ b/sys/compat/common/compat_80_mod.c Fri May 17 07:37:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_80_mod.c,v 1.3 2019/04/17 09:21:57 msaitoh Exp $        */
+/*     $NetBSD: compat_80_mod.c,v 1.4 2019/05/17 07:37:11 msaitoh Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_80_mod.c,v 1.3 2019/04/17 09:21:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_80_mod.c,v 1.4 2019/05/17 07:37:11 msaitoh Exp $");
 
 #include <sys/systm.h>
 #include <sys/module.h>
@@ -51,6 +51,7 @@
 {
 
        kern_mod_80_init();
+       ifmedia_80_init();
 
        return 0;
 }
@@ -59,6 +60,7 @@
 compat_80_fini(void)
 {
 
+       ifmedia_80_fini();
        kern_mod_80_fini();
 
        return 0;
diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/compat_mod.h
--- a/sys/compat/common/compat_mod.h    Fri May 17 06:05:07 2019 +0000
+++ b/sys/compat/common/compat_mod.h    Fri May 17 07:37:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_mod.h,v 1.4 2019/04/15 02:07:11 pgoyette Exp $  */
+/*     $NetBSD: compat_mod.h,v 1.5 2019/05/17 07:37:11 msaitoh Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,6 +37,8 @@
 int compat_80_fini(void);
 void kern_mod_80_init(void);
 void kern_mod_80_fini(void);
+void ifmedia_80_init(void);
+void ifmedia_80_fini(void);
 #endif
 
 #ifdef COMPAT_70
diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/files.common
--- a/sys/compat/common/files.common    Fri May 17 06:05:07 2019 +0000
+++ b/sys/compat/common/files.common    Fri May 17 07:37:11 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.common,v 1.3 2019/04/15 02:07:11 pgoyette Exp $
+#      $NetBSD: files.common,v 1.4 2019/05/17 07:37:11 msaitoh Exp $
 
 #
 # Generic utility files, used by various compat options.
@@ -103,6 +103,7 @@
 # Compatability code for NetBSD 8.0
 file   compat/common/compat_80_mod.c           compat_80
 file   compat/common/kern_mod_80.c             compat_80
+file   compat/common/if_media_80.c             compat_80
 
 #
 # Sources for sysv ipc compatibility across the versions.
diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/if_43.c
--- a/sys/compat/common/if_43.c Fri May 17 06:05:07 2019 +0000
+++ b/sys/compat/common/if_43.c Fri May 17 07:37:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_43.c,v 1.21 2019/04/16 04:31:42 msaitoh Exp $       */
+/*     $NetBSD: if_43.c,v 1.22 2019/05/17 07:37:11 msaitoh Exp $       */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.21 2019/04/16 04:31:42 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.22 2019/05/17 07:37:11 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -126,8 +126,8 @@
                return SIOCADDMULTI;
        case OSIOCDELMULTI:
                return SIOCDELMULTI;
-       case OSIOCSIFMEDIA:
-               return SIOCSIFMEDIA;
+       case SIOCSIFMEDIA_43:
+               return SIOCSIFMEDIA_80;
        case OSIOCGIFMTU:
                return SIOCGIFMTU;
        case OSIOCGIFDATA:
diff -r 4d6702791ffd -r 91ab377790af sys/compat/common/if_media_80.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/common/if_media_80.c   Fri May 17 07:37:11 2019 +0000
@@ -0,0 +1,192 @@
+/*     $NetBSD: if_media_80.c,v 1.1 2019/05/17 07:37:11 msaitoh Exp $  */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1997
+ *     Jonathan Stone and Jason R. Thorpe.  All rights reserved.
+ *
+ * This software is derived from information provided by Matt Thomas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Jonathan Stone
+ *     and Jason R. Thorpe for the NetBSD Project.
+ * 4. The names of the authors may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/syscallargs.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/compat_stub.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <compat/sys/sockio.h>
+#include <compat/common/compat_mod.h>
+
+static void
+ifmword_n2o(int *oldwd, int *newwd)
+{
+
+       if (IFM_SUBTYPE(*newwd) > IFM_OTHER)
+               *oldwd = (*newwd & ~(_IFM_ETH_XTMASK | IFM_TMASK)) | IFM_OTHER;
+       else
+               *oldwd = *newwd;
+}
+
+/*ARGSUSED*/
+static int
+compat_ifmediareq_pre(struct ifreq *ifr, u_long *cmd, bool *do_post)
+{
+       struct ifmediareq *ifmr = (struct ifmediareq *)ifr;
+
+       switch (*cmd) {
+       case SIOCSIFMEDIA_80:
+               *cmd = SIOCSIFMEDIA; /* Convert to new one */
+               if ((IFM_TYPE(ifr->ifr_media) == IFM_ETHER) &&
+                   IFM_SUBTYPE(ifr->ifr_media) > IFM_OTHER) {
+                       /* Clear unused bits to not to change to wrong media */
+                       ifr->ifr_media &= ~_IFM_ETH_XTMASK;
+               }
+               return 0;
+       case SIOCGIFMEDIA_80:
+               *cmd = SIOCGIFMEDIA; /* Convert to new one */
+               if (ifmr->ifm_count != 0) {
+                       /*
+                        * Tell the upper layer to try to convert each ifmedia
+                        * entry in the post process.
+                        */
+                       *do_post = true;
+               }
+               return 0;
+       default:
+               return 0;
+       }
+}
+
+/*ARGSUSED*/
+static int
+compat_ifmediareq_post(struct ifreq *ifr, u_long cmd)
+{
+       struct ifmediareq *ifmr = (struct ifmediareq *)ifr;
+       size_t minwords;
+       int count, *kptr;
+       int error;
+
+       switch (cmd) {
+       case SIOCSIFMEDIA:
+               return 0;
+       case SIOCGIFMEDIA:
+               if (ifmr->ifm_count < 0)
+                       return EINVAL;
+               
+               /*
+                * ifmr->ifm_count was already ajusted in ifmedia_ioctl(), so
+                * there is no problem to trust ifm_count.
+                */
+               minwords = ifmr->ifm_count;
+               kptr = malloc(minwords * sizeof(*kptr), M_TEMP, M_WAITOK);
+               if (kptr == NULL)
+                       return ENOMEM;
+
+               /*
+                * Convert ifm_current and ifm_active.
+                * It's not required to convert ifm_mask.
+                */
+               ifmword_n2o(&ifmr->ifm_current, &ifmr->ifm_current);
+               ifmword_n2o(&ifmr->ifm_active, &ifmr->ifm_active);
+
+               /* Convert ifm_ulist array */
+               for (count = 0; count < minwords; count++) {
+                       int oldmwd;
+
+                       error = ufetch_int(&ifmr->ifm_ulist[count], &oldmwd);
+                       if (error != 0)
+                               goto out;
+                       ifmword_n2o(&kptr[count], &oldmwd);
+               }
+
+               /* Copy to userland in old format */
+               error = copyout(kptr, ifmr->ifm_ulist,
+                   minwords * sizeof(*kptr));
+out:
+               free(kptr, M_TEMP);
+               return error;
+       default:
+               return 0;
+       }
+}
+
+void
+ifmedia_80_init(void)
+{
+
+       MODULE_HOOK_SET(ifmedia_80_pre_hook, "ifmedia80",



Home | Main Index | Thread Index | Old Index