Move functions to print link status etc. to util.c so that bgpd can use them
authorclaudio <claudio@openbsd.org>
Sun, 22 Jul 2018 16:52:27 +0000 (16:52 +0000)
committerclaudio <claudio@openbsd.org>
Sun, 22 Jul 2018 16:52:27 +0000 (16:52 +0000)
as well. OK benno@

usr.sbin/bgpctl/bgpctl.c
usr.sbin/bgpd/bgpd.h
usr.sbin/bgpd/util.c

index 1305934..c8015f5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpctl.c,v 1.207 2018/07/20 12:49:49 claudio Exp $ */
+/*     $OpenBSD: bgpctl.c,v 1.208 2018/07/22 16:52:27 claudio Exp $ */
 
 /*
  * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -22,9 +22,6 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/un.h>
-#include <net/if.h>
-#include <net/if_media.h>
-#include <net/if_types.h>
 
 #include <err.h>
 #include <errno.h>
@@ -73,10 +70,6 @@ int           show_fib_msg(struct imsg *);
 void            show_nexthop_head(void);
 int             show_nexthop_msg(struct imsg *);
 void            show_interface_head(void);
-uint64_t        ift2ifm(uint8_t);
-const char *    get_media_descr(uint64_t);
-const char *    get_linkstate(uint8_t, int);
-const char *    get_baudrate(u_int64_t, char *);
 int             show_interface_msg(struct imsg *);
 void            show_rib_summary_head(void);
 void            print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t);
@@ -1152,75 +1145,6 @@ show_interface_head(void)
            "Link state");
 }
 
-const struct if_status_description
-               if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
-const struct ifmedia_description
-               ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
-
-uint64_t
-ift2ifm(uint8_t if_type)
-{
-       switch (if_type) {
-       case IFT_ETHER:
-               return (IFM_ETHER);
-       case IFT_FDDI:
-               return (IFM_FDDI);
-       case IFT_CARP:
-               return (IFM_CARP);
-       case IFT_IEEE80211:
-               return (IFM_IEEE80211);
-       default:
-               return (0);
-       }
-}
-
-const char *
-get_media_descr(uint64_t media_type)
-{
-       const struct ifmedia_description        *p;
-
-       for (p = ifm_type_descriptions; p->ifmt_string != NULL; p++)
-               if (media_type == p->ifmt_word)
-                       return (p->ifmt_string);
-
-       return ("unknown media");
-}
-
-const char *
-get_linkstate(uint8_t if_type, int link_state)
-{
-       const struct if_status_description *p;
-       static char buf[8];
-
-       for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
-               if (LINK_STATE_DESC_MATCH(p, if_type, link_state))
-                       return (p->ifs_string);
-       }
-       snprintf(buf, sizeof(buf), "[#%d]", link_state);
-       return (buf);
-}
-
-const char *
-get_baudrate(u_int64_t baudrate, char *unit)
-{
-       static char bbuf[16];
-
-       if (baudrate > IF_Gbps(1))
-               snprintf(bbuf, sizeof(bbuf), "%llu G%s",
-                   baudrate / IF_Gbps(1), unit);
-       else if (baudrate > IF_Mbps(1))
-               snprintf(bbuf, sizeof(bbuf), "%llu M%s",
-                   baudrate / IF_Mbps(1), unit);
-       else if (baudrate > IF_Kbps(1))
-               snprintf(bbuf, sizeof(bbuf), "%llu K%s",
-                   baudrate / IF_Kbps(1), unit);
-       else
-               snprintf(bbuf, sizeof(bbuf), "%llu %s",
-                   baudrate, unit);
-
-       return (bbuf);
-}
-
 int
 show_interface_msg(struct imsg *imsg)
 {
index 71f6272..bb310a3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.h,v 1.327 2018/07/20 14:58:20 claudio Exp $ */
+/*     $OpenBSD: bgpd.h,v 1.328 2018/07/22 16:52:27 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -1189,6 +1189,10 @@ sa_family_t       aid2af(u_int8_t);
 int             af2aid(sa_family_t, u_int8_t, u_int8_t *);
 struct sockaddr        *addr2sa(struct bgpd_addr *, u_int16_t);
 void            sa2addr(struct sockaddr *, struct bgpd_addr *);
+uint64_t        ift2ifm(uint8_t);
+const char *    get_media_descr(uint64_t);
+const char *    get_linkstate(uint8_t, int);
+const char *    get_baudrate(u_int64_t, char *);
 
 static const char * const log_procnames[] = {
        "parent",
index e7c40df..8ae8272 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: util.c,v 1.27 2018/07/20 14:58:20 claudio Exp $ */
+/*     $OpenBSD: util.c,v 1.28 2018/07/22 16:52:27 claudio Exp $ */
 
 /*
  * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@@ -18,6 +18,9 @@
  */
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
@@ -849,3 +852,73 @@ sa2addr(struct sockaddr *sa, struct bgpd_addr *addr)
                break;
        }
 }
+
+const struct if_status_description
+               if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
+const struct ifmedia_description
+               ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
+
+uint64_t
+ift2ifm(uint8_t if_type)
+{
+       switch (if_type) {
+       case IFT_ETHER:
+               return (IFM_ETHER);
+       case IFT_FDDI:
+               return (IFM_FDDI);
+       case IFT_CARP:
+               return (IFM_CARP);
+       case IFT_IEEE80211:
+               return (IFM_IEEE80211);
+       default:
+               return (0);
+       }
+}
+
+const char *
+get_media_descr(uint64_t media_type)
+{
+       const struct ifmedia_description        *p;
+
+       for (p = ifm_type_descriptions; p->ifmt_string != NULL; p++)
+               if (media_type == p->ifmt_word)
+                       return (p->ifmt_string);
+
+       return ("unknown media");
+}
+
+const char *
+get_linkstate(uint8_t if_type, int link_state)
+{
+       const struct if_status_description *p;
+       static char buf[8];
+
+       for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+               if (LINK_STATE_DESC_MATCH(p, if_type, link_state))
+                       return (p->ifs_string);
+       }
+       snprintf(buf, sizeof(buf), "[#%d]", link_state);
+       return (buf);
+}
+
+const char *
+get_baudrate(u_int64_t baudrate, char *unit)
+{
+       static char bbuf[16];
+
+       if (baudrate > IF_Gbps(1))
+               snprintf(bbuf, sizeof(bbuf), "%llu G%s",
+                   baudrate / IF_Gbps(1), unit);
+       else if (baudrate > IF_Mbps(1))
+               snprintf(bbuf, sizeof(bbuf), "%llu M%s",
+                   baudrate / IF_Mbps(1), unit);
+       else if (baudrate > IF_Kbps(1))
+               snprintf(bbuf, sizeof(bbuf), "%llu K%s",
+                   baudrate / IF_Kbps(1), unit);
+       else
+               snprintf(bbuf, sizeof(bbuf), "%llu %s",
+                   baudrate, unit);
+
+       return (bbuf);
+}
+