commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1_100-1-g3dc


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1_100-1-g3dc3bb4
Date: Thu, 19 Sep 2013 13:04:53 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  3dc3bb447e058b7903b242ce231a27736c569066 (commit)
      from  bedab2f2d1f87a5a84866e9cf26b982a2f14e61a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=3dc3bb447e058b7903b242ce231a27736c569066


commit 3dc3bb447e058b7903b242ce231a27736c569066
Author: Mats Erik Andersson <address@hidden>
Date:   Thu Sep 19 02:20:37 2013 +0200

    ifconfig: Status and medium reports.
    
    Provide BSD systems, including GNU/kFreeBSD, with
    information on status and medium of the given unit.

diff --git a/ChangeLog b/ChangeLog
index fc172a3..4f2b026 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2013-09-19  Mats Erik Andersson  <address@hidden>
+
+       ifconfig: Status and medium reports on BSD.
+
+       * ifconfig/options.c (formats) <gnu, net-tools, unix>:
+       Add medium and status to printout.
+       * ifconfig/printif.c (format_handles): Add keys
+       `media?', `media', `status?', and `status'.
+       (fh_media_query, fh_media, fh_status_query, fh_status):
+       New functions.
+       * ifconfig/printif.h (fh_media_query, fh_media)
+       (fh_status_query, fh_status): New declarations.
+
+       * ifconfig/system/bsd.c: Include <net/if_media.h>.
+       (ifm) [SIOCGIFMEDIA]: New variable.
+       (media_descr): New variable.
+       (subtype_descr) [IFM_SUBTYPE_DESCRIPTIONS]: Likewise.
+       (ethernet_descr) [IFM_SUBTYPE_ETHERNET_DESCRIPTIONS]:
+       Likewise.
+       (subtype_shared_descr) [IFM_SUBTYPE_SHARED_DESCRIPTIONS]:
+       Likewise.
+       (option_descr): Likewise.
+       (status_descr) [IFM_STATUS_DESCRIPTION]: Likewise.
+       (system_fh_media_query, system_fh_media)
+       (system_fh_status_query, system_fh_status): New functions.
+       * ifconfig/system/bsd.h (SYSTEM_FORMAT_HANDLER):
+       Add keys `media?', `media', `status?', and `status'.
+       (system_fh_media_query)
+       (system_fh_media, system_fh_status_quey, system_fh_status):
+       New declarations.
+
 2013-09-18  Alfred M. Szmidt  <address@hidden>
 
        * cfg.mk (local-checks-to-skip): Added the
diff --git a/ifconfig/options.c b/ifconfig/options.c
index 25d89db..90c46de 100644
--- a/ifconfig/options.c
+++ b/ifconfig/options.c
@@ -89,6 +89,8 @@ struct format formats[] = {
    "${metric?}{  metric ${tab}{16}${metric}${\\n}}"
    "${exists?}{hwtype?}{${hwtype?}{  link encap ${tab}{16}${hwtype}${\\n}}}"
    "${exists?}{hwaddr?}{${hwaddr?}{  hardware addr ${tab}{16}${hwaddr}${\\n}}}"
+   "${media?}{  link medium ${tab}{16}${media}${\\n}}"
+   "${status?}{  link status ${tab}{16}${status}${\\n}}"
    "${exists?}{txqlen?}{${txqlen?}{  tx queue len ${tab}{16}${txqlen}${\\n}}}"
    "}"
   },
@@ -106,6 +108,9 @@ struct format formats[] = {
    "${tab}{10}${flags}"
    "${mtu?}{  MTU:${mtu}}"
    "${metric?}{  Metric:${metric}}"
+   "${media?}{"
+   "${newline}${tab}{10}Media: ${media}"
+   "${status?}{, ${status}}}"
    "${exists?}{ifstat?}{"
    "${ifstat?}{"
    "${newline}          RX packets:${rxpackets}"
@@ -164,6 +169,8 @@ struct format formats[] = {
    " netmask ${netmask}{0}{%#02x}${netmask}{1}{%02x}"
    "${netmask}{2}{%02x}${netmask}{3}{%02x}"
    "${brdaddr?}{ broadcast ${brdaddr}}${\\n}}"
+   "${media?}{${\\t}media: ${media}${\\n}}"
+   "${status?}{${\\t}status: ${status}${\\n}}"
    "}"
   },
   /* Resembles the output of ifconfig shipped with OSF 4.0g.  */
diff --git a/ifconfig/printif.c b/ifconfig/printif.c
index 4883539..c2efdbc 100644
--- a/ifconfig/printif.c
+++ b/ifconfig/printif.c
@@ -96,6 +96,10 @@ struct format_handle format_handles[] = {
   {"mtu", fh_mtu},
   {"metric?", fh_metric_query},
   {"metric", fh_metric},
+  {"media?", fh_media_query},
+  {"media", fh_media},
+  {"status?", fh_status_query},
+  {"status", fh_status},
 #ifdef HAVE_STRUCT_IFREQ_IFR_MAP
   {"map?", fh_map_query},
   {"irq?", fh_irq_query},
@@ -108,7 +112,7 @@ struct format_handle format_handles[] = {
   {"memend", fh_memend},
   {"dma?", fh_dma_query},
   {"dma", fh_dma},
-#endif
+#endif /* HAVE_STRUCT_IFREQ_IFR_MAP */
   {NULL, NULL}
 };
 
@@ -870,6 +874,40 @@ fh_flags (format_data_t form, int argc, char *argv[])
 #endif
 }
 
+void
+fh_media_query (format_data_t form, int argc, char *argv[])
+{
+  /* Must be overridden by a system dependent implementation.  */
+
+  /* Claim it to be absent.  */
+  select_arg (form, argc, argv, 1);
+}
+
+void
+fh_media (format_data_t form, int argc _GL_UNUSED_PARAMETER,
+         char *argv[] _GL_UNUSED_PARAMETER)
+{
+  /* Must be overridden by a system dependent implementation.  */
+  put_string (form, "(not known)");
+}
+
+void
+fh_status_query (format_data_t form, int argc, char *argv[])
+{
+  /* Must be overridden by a system dependent implementation.  */
+
+  /* Claim it to be absent.  */
+  select_arg (form, argc, argv, 1);
+}
+
+void
+fh_status (format_data_t form, int argc _GL_UNUSED_PARAMETER,
+          char *argv[] _GL_UNUSED_PARAMETER)
+{
+  /* Must be overridden by a system dependent implementation.  */
+  put_string (form, "(not known)");
+}
+
 #ifdef HAVE_STRUCT_IFREQ_IFR_MAP
 
 void
@@ -969,7 +1007,8 @@ fh_dma (format_data_t form, int argc, char *argv[])
   else
     put_string (form, "(not available)");
 }
-#endif
+
+#endif /* HAVE_STRUCT_IFREQ_IFR_MAP */
 
 void
 print_interfaceX (format_data_t form, int quiet)
diff --git a/ifconfig/printif.h b/ifconfig/printif.h
index e378349..9f945db 100644
--- a/ifconfig/printif.h
+++ b/ifconfig/printif.h
@@ -120,6 +120,10 @@ void fh_memend_query (format_data_t form, int argc, char 
*argv[]);
 void fh_memend (format_data_t form, int argc, char *argv[]);
 void fh_dma_query (format_data_t form, int argc, char *argv[]);
 void fh_dma (format_data_t form, int argc, char *argv[]);
+void fh_media_query (format_data_t form, int argc, char *argv[]);
+void fh_media (format_data_t form, int argc, char *argv[]);
+void fh_status_query (format_data_t form, int argc, char *argv[]);
+void fh_status (format_data_t form, int argc, char *argv[]);
 
 /* Used for recursion by format handlers.  */
 void print_interfaceX (format_data_t form, int quiet);
diff --git a/ifconfig/system/bsd.c b/ifconfig/system/bsd.c
index 601be88..321efee 100644
--- a/ifconfig/system/bsd.c
+++ b/ifconfig/system/bsd.c
@@ -26,6 +26,7 @@
 #include <net/if.h>
 #include <net/if_types.h>
 #include <net/if_dl.h>
+#include <net/if_media.h>
 #ifdef HAVE_NETINET_ETHER_H
 # include <netinet/ether.h>
 #endif
@@ -157,6 +158,10 @@ system_configure (int sfd _GL_UNUSED_PARAMETER,
 /* System hooks. */
 static struct ifaddrs *ifp = NULL;
 
+#ifdef SIOCGIFMEDIA
+struct ifmediareq ifm;
+#endif /* SIOCGIFMEDIA */
+
 #define ESTABLISH_IFADDRS \
   if (!ifp) \
     getifaddrs (&ifp);
@@ -264,3 +269,182 @@ system_fh_hwtype (format_data_t form, int argc 
_GL_UNUSED_PARAMETER,
        put_string (form, "(unknown hwtype)");
     }
 }
+
+/* Lookup structures provided by the system, each decoding
+ * to clear text the meaning of media and status flags.
+ *
+ * The naming is different in NetBSD and in FreeBSD.
+ */
+static const struct ifmedia_description media_descr[] =
+                       IFM_TYPE_DESCRIPTIONS;
+
+#ifdef IFM_SUBTYPE_DESCRIPTIONS
+static const struct ifmedia_description subtype_descr[] =
+                       IFM_SUBTYPE_DESCRIPTIONS;
+#endif
+
+#ifdef IFM_SUBTYPE_ETHERNET_DESCRIPTIONS
+static const struct ifmedia_description ethernet_descr[] =
+                       IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
+#endif
+
+#ifdef IFM_SUBTYPE_SHARED_DESCRIPTIONS
+static const struct ifmedia_description subtype_shared_descr[] =
+                       IFM_SUBTYPE_SHARED_DESCRIPTIONS;
+#endif
+
+static const struct ifmedia_description option_descr[] =
+#ifdef IFM_OPTION_DESCRIPTIONS
+                       IFM_OPTION_DESCRIPTIONS;
+#elif defined IFM_SHARED_OPTION_DESCRIPTIONS
+                       IFM_SHARED_OPTION_DESCRIPTIONS;
+#else
+                       { { 0, NULL }, };
+#endif
+
+
+#ifdef IFM_STATUS_DESCRIPTIONS
+static const struct ifmedia_status_description status_descr[] =
+                       IFM_STATUS_DESCRIPTIONS;
+#endif
+
+void
+system_fh_media_query (format_data_t form, int argc, char *argv[])
+{
+#ifdef SIOCGIFMEDIA
+  memset (&ifm, 0, sizeof (ifm));
+  strncpy (ifm.ifm_name, form->ifr->ifr_name, sizeof (ifm.ifm_name));
+
+  if (ioctl (form->sfd, SIOCGIFMEDIA, &ifm) >= 0)
+    select_arg (form, argc, argv, 0);
+  else
+#endif /* SIOCGIFMEDIA */
+    select_arg (form, argc, argv, 1);
+}
+
+void
+system_fh_media (format_data_t form, int argc _GL_UNUSED_PARAMETER,
+                char *argv[] _GL_UNUSED_PARAMETER)
+{
+#ifdef SIOCGIFMEDIA
+  memset (&ifm, 0, sizeof (ifm));
+  strncpy (ifm.ifm_name, form->ifr->ifr_name, sizeof (ifm.ifm_name));
+  if (ioctl (form->sfd, SIOCGIFMEDIA, &ifm) >= 0)
+    {
+      const char *medium = NULL, *options = NULL;
+      const char *subtype = NULL, *active_subtype = NULL;
+      const struct ifmedia_description *item;
+
+      /* Determine media type of adapter.  */
+      for (item = media_descr; item->ifmt_word; item++)
+       if (item->ifmt_word == IFM_TYPE (ifm.ifm_current))
+         {
+           medium = item->ifmt_string;
+           break;
+         }
+
+#ifdef IFM_SUBTYPE_DESCRIPTIONS
+      for (item = subtype_descr; item->ifmt_word || item->ifmt_string; item++)
+       {
+         if (item->ifmt_word == IFM_SUBTYPE (ifm.ifm_current) && !subtype)
+           subtype = item->ifmt_string;
+
+         if (item->ifmt_word == (ifm.ifm_active & (IFM_NMASK | IFM_TMASK))
+             && !active_subtype)
+           active_subtype = item->ifmt_string;
+       }
+#else /* !IFM_SUBTYPE_DESCRIPTIONS */
+      /* Systems like FreeBSD with sub-types split
+       * into shared and media specific structures.
+       *
+       * Sub-type specific media labels.
+       */
+      switch (IFM_TYPE (ifm.ifm_current))
+       {
+       case IFM_ETHER:
+         for (item = ethernet_descr; item->ifmt_word; item++)
+           {
+             /* Configured sub-type.  */
+             if (item->ifmt_word == IFM_SUBTYPE (ifm.ifm_current))
+               subtype = item->ifmt_string;
+
+             /* Active subtype.  */
+             if (item->ifmt_word == IFM_SUBTYPE (ifm.ifm_active))
+               active_subtype = item->ifmt_string;
+           }
+         ;;
+       default:
+         ;;
+       }
+
+      /* Shared media sub-types.  Only works if the previous
+       * loops did not assign any string value.
+       *
+       * One valid instance of 'ifmt_word' is naught,
+       * so loop condition needs care.
+       */
+      for (item = subtype_shared_descr; item->ifmt_word || item->ifmt_string; 
item++)
+       {
+         if (item->ifmt_word == IFM_SUBTYPE (ifm.ifm_current))
+           subtype = item->ifmt_string;
+
+         if (item->ifmt_word == IFM_SUBTYPE (ifm.ifm_active))
+           active_subtype = item->ifmt_string;
+       }
+#endif /* !IFM_SUBTYPE_DESCRIPTIONS */
+
+      /* Negotiated mode of operation.  */
+      for (item = option_descr; item->ifmt_word; item++)
+       if (item->ifmt_word == (ifm.ifm_active & IFM_GMASK) && !options)
+         options = item->ifmt_string;
+
+      /* Print the gathered information.  */
+      if (options)
+        printf ("%s %s (%s <%s>)", medium, subtype, active_subtype, options);
+      else
+        printf ("%s %s (%s)", medium, subtype,
+               active_subtype ? active_subtype : "none");
+
+      had_output++;
+    }
+  else
+#endif /* SIOCGIFMEDIA */
+    put_string (form, "(not known)");
+}
+
+void
+system_fh_status_query (format_data_t form, int argc, char *argv[])
+{
+  system_fh_media_query (form, argc, argv);
+}
+
+void
+system_fh_status (format_data_t form, int argc, char *argv[])
+{
+#ifdef SIOCGIFMEDIA
+  memset (&ifm, 0, sizeof (ifm));
+  strncpy (ifm.ifm_name, form->ifr->ifr_name, sizeof (ifm.ifm_name));
+  if (ioctl (form->sfd, SIOCGIFMEDIA, &ifm) >= 0)
+    {
+#ifdef IFM_STATUS_DESCRIPTIONS
+      const struct ifmedia_status_description *item;
+
+      for (item = status_descr; item->ifms_type; item++)
+       if (item->ifms_type == IFM_TYPE (ifm.ifm_current))
+         break;
+
+      if (item->ifms_type)
+       put_string (form, IFM_STATUS_DESC (item, ifm.ifm_status));
+      else
+       put_int (form, argc, argv, ifm.ifm_status);
+#else /* !IFM_STATUS_DESCRIPTIONS */
+      if (ifm.ifm_status & IFM_ACTIVE)
+       put_string (form, "active");
+      else
+       put_string (form, "no carrier");
+#endif /* IFM_STATUS_DESCRIPTIONS */
+    }
+  else
+#endif /* SIOCGIFMEDIA */
+    put_string (form, "(not known)");
+}
diff --git a/ifconfig/system/bsd.h b/ifconfig/system/bsd.h
index 8143c34..7bf4853 100644
--- a/ifconfig/system/bsd.h
+++ b/ifconfig/system/bsd.h
@@ -63,11 +63,19 @@ struct system_ifconfig
   {"hwaddr?", system_fh_hwaddr_query}, \
   {"hwaddr", system_fh_hwaddr}, \
   {"hwtype?", system_fh_hwtype_query}, \
-  {"hwtype", system_fh_hwtype},
+  {"hwtype", system_fh_hwtype},        \
+  {"media?", system_fh_media_query}, \
+  {"media", system_fh_media},  \
+  {"status?", system_fh_status_query}, \
+  {"status", system_fh_status},
 
 void system_fh_hwaddr_query (format_data_t form, int argc, char *argv[]);
 void system_fh_hwaddr (format_data_t form, int argc, char *argv[]);
 void system_fh_hwtype_query (format_data_t form, int argc, char *argv[]);
 void system_fh_hwtype (format_data_t form, int argc, char *argv[]);
+void system_fh_media_query (format_data_t form, int argc, char *argv[]);
+void system_fh_media (format_data_t form, int argc, char *argv[]);
+void system_fh_status_query (format_data_t form, int argc, char *argv[]);
+void system_fh_status (format_data_t form, int argc, char *argv[]);
 
 #endif /* IFCONFIG_SYSTEM_BSD_H */

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog             |   31 ++++++++
 ifconfig/options.c    |    7 ++
 ifconfig/printif.c    |   43 +++++++++++-
 ifconfig/printif.h    |    4 +
 ifconfig/system/bsd.c |  184 +++++++++++++++++++++++++++++++++++++++++++++++++
 ifconfig/system/bsd.h |   10 +++-
 6 files changed, 276 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]