Source-Changes-HG archive

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

[src/trunk]: src Add SIOCGETHERCAP ioctl.



details:   https://anonhg.NetBSD.org/src/rev/f389ff1733e4
branches:  trunk
changeset: 782374:f389ff1733e4
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Oct 31 10:17:34 2012 +0000

description:
Add SIOCGETHERCAP ioctl.
There was no way to know the setting of ec_capabilities and ec_capenable
other than grepping the source.

See http://mail-index.netbsd.org/tech-kern/2010/07/28/msg008613.html

diffstat:

 sbin/ifconfig/Makefile.inc |   3 +-
 sbin/ifconfig/ether.c      |  88 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/net/if_ether.h         |  15 +++++++-
 sys/net/if_ethersubr.c     |  10 ++++-
 sys/sys/sockio.h           |   7 +++-
 5 files changed, 118 insertions(+), 5 deletions(-)

diffs (197 lines):

diff -r 6bef469284e6 -r f389ff1733e4 sbin/ifconfig/Makefile.inc
--- a/sbin/ifconfig/Makefile.inc        Wed Oct 31 08:54:39 2012 +0000
+++ b/sbin/ifconfig/Makefile.inc        Wed Oct 31 10:17:34 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.8 2010/12/13 17:35:08 pooka Exp $
+#      $NetBSD: Makefile.inc,v 1.9 2012/10/31 10:17:34 msaitoh Exp $
 
 # shared stuff with src/distrib/utils/x_ifconfig for install media.
 # stuff not required by install media should be into Makefile.
@@ -13,6 +13,7 @@
 SRCS+= af_inetany.c
 SRCS+= agr.c
 SRCS+= env.c
+SRCS+= ether.c
 SRCS+= ieee80211.c
 SRCS+= ifconfig.c
 SRCS+= media.c
diff -r 6bef469284e6 -r f389ff1733e4 sbin/ifconfig/ether.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/ifconfig/ether.c     Wed Oct 31 10:17:34 2012 +0000
@@ -0,0 +1,88 @@
+/*     $NetBSD: ether.c,v 1.1 2012/10/31 10:17:34 msaitoh Exp $        */
+
+/*
+ * Copyright (c) 1983, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * 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. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: ether.c,v 1.1 2012/10/31 10:17:34 msaitoh Exp $");
+#endif /* not lint */
+
+#include <sys/param.h> 
+#include <sys/ioctl.h> 
+
+#include <net/if.h> 
+#include <net/if_ether.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <util.h>
+
+#include "env.h"
+#include "parse.h"
+#include "extern.h"
+#include "prog_ops.h"
+
+static void ether_status(prop_dictionary_t, prop_dictionary_t);
+static void ether_constructor(void) __attribute__((constructor));
+
+static status_func_t status;
+
+void
+ether_status(prop_dictionary_t env, prop_dictionary_t oenv)
+{
+       struct eccapreq eccr;
+       char fbuf[BUFSIZ];
+
+       memset(&eccr, 0, sizeof(eccr));
+
+       if (direct_ioctl(env, SIOCGETHERCAP, &eccr) == -1)
+               return;
+
+       if (eccr.eccr_capabilities != 0) {
+               (void)snprintb(fbuf, sizeof(fbuf), ECCAPBITS,
+                   eccr.eccr_capabilities);
+               printf("\tec_capabilities=%s\n", &fbuf[2]);
+               (void)snprintb(fbuf, sizeof(fbuf), ECCAPBITS,
+                   eccr.eccr_capenable);
+               printf("\tec_enabled=%s\n", &fbuf[2]);
+       }
+}
+
+static void
+ether_constructor(void)
+{
+
+       status_func_init(&status, ether_status);
+       register_status(&status);
+}
diff -r 6bef469284e6 -r f389ff1733e4 sys/net/if_ether.h
--- a/sys/net/if_ether.h        Wed Oct 31 08:54:39 2012 +0000
+++ b/sys/net/if_ether.h        Wed Oct 31 10:17:34 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ether.h,v 1.60 2012/10/25 11:53:14 msaitoh Exp $    */
+/*     $NetBSD: if_ether.h,v 1.61 2012/10/31 10:17:34 msaitoh Exp $    */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -187,6 +187,19 @@
 #define        ETHERCAP_VLAN_HWTAGGING 0x00000002      /* hardware VLAN tag support */
 #define        ETHERCAP_JUMBO_MTU      0x00000004      /* 9000 byte MTU supported */
 
+#define        ECCAPBITS               \
+       "\020"                  \
+       "\1VLAN_MTU"            \
+       "\2VLAN_HWTAGGING"      \
+       "\3JUMBO_MTU"
+
+/* ioctl() for Ethernet capabilities */
+struct eccapreq {
+       char            eccr_name[IFNAMSIZ];    /* if name, e.g. "en0" */
+       int             eccr_capabilities;      /* supported capabiliites */
+       int             eccr_capenable;         /* capabilities enabled */
+};
+
 #ifdef _KERNEL
 extern const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN];
 extern const uint8_t ethermulticastaddr_slowprotocols[ETHER_ADDR_LEN];
diff -r 6bef469284e6 -r f389ff1733e4 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Wed Oct 31 08:54:39 2012 +0000
+++ b/sys/net/if_ethersubr.c    Wed Oct 31 10:17:34 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.192 2012/10/11 20:05:50 christos Exp $      */
+/*     $NetBSD: if_ethersubr.c,v 1.193 2012/10/31 10:17:34 msaitoh Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.192 2012/10/11 20:05:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.193 2012/10/31 10:17:34 msaitoh Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -1494,6 +1494,7 @@
 ether_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
        struct ethercom *ec = (void *) ifp;
+       struct eccapreq *eccr;
        struct ifreq *ifr = (struct ifreq *)data;
        struct if_laddrreq *iflr = data;
        const struct sockaddr_dl *sdl;
@@ -1571,6 +1572,11 @@
                        break;
                }
                return 0;
+       case SIOCGETHERCAP:
+               eccr = (struct eccapreq *)data;
+               eccr->eccr_capabilities = ec->ec_capabilities;
+               eccr->eccr_capenable = ec->ec_capenable;
+               return 0;
        case SIOCADDMULTI:
                return ether_addmulti(ifreq_getaddr(cmd, ifr), ec);
        case SIOCDELMULTI:
diff -r 6bef469284e6 -r f389ff1733e4 sys/sys/sockio.h
--- a/sys/sys/sockio.h  Wed Oct 31 08:54:39 2012 +0000
+++ b/sys/sys/sockio.h  Wed Oct 31 10:17:34 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sockio.h,v 1.30 2010/11/15 22:42:36 pooka Exp $        */
+/*     $NetBSD: sockio.h,v 1.31 2012/10/31 10:17:35 msaitoh Exp $      */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993, 1994
@@ -132,6 +132,11 @@
 #define SIOCGLINKSTR   _IOWR('i', 135, struct ifdrv)
 #define SIOCSLINKSTR    _IOW('i', 136, struct ifdrv)
 
+/* 137 is SIOCGATHSTATS in athioctl.h */
+/* 138 is SIOCGATHDIAG in athioctl.h */
+
+#define        SIOCGETHERCAP   _IOWR('i', 139, struct eccapreq) /* get ethercap */
+
 #define        SIOCSETPFSYNC   _IOW('i', 247, struct ifreq)    
 #define        SIOCGETPFSYNC   _IOWR('i', 248, struct ifreq)
 



Home | Main Index | Thread Index | Old Index