summaryrefslogtreecommitdiffstats
path: root/zebra
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2010-02-02 01:36:36 +0100
committerDavid Lamparter <equinox@diac24.net>2010-02-03 05:26:36 +0100
commita3e5daee7205e8bffb44d914a74d38fe8ad0c986 (patch)
treec581dcec56ab5bcb077ab8841e659b29bbdac99e /zebra
parentfd7307bd4efb5739a949256d6836dc6535c877c9 (diff)
downloadquagga-a3e5daee7205e8bffb44d914a74d38fe8ad0c986.tar.bz2
quagga-a3e5daee7205e8bffb44d914a74d38fe8ad0c986.tar.xz
netlink: display scope value in debug
add functions to convert scope value from int to string and back. put them to use to display address scope in debug output.
Diffstat (limited to 'zebra')
-rw-r--r--zebra/connected.c47
-rw-r--r--zebra/connected.h5
-rw-r--r--zebra/rt_netlink.c1
3 files changed, 53 insertions, 0 deletions
diff --git a/zebra/connected.c b/zebra/connected.c
index bf5715e4..25186a80 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -36,6 +36,53 @@
#include "zebra/interface.h"
#include "zebra/connected.h"
extern struct zebra_t zebrad;
+
+#ifdef HAVE_NETLINK
+static const struct message rtscope_str[] = {
+ {RT_SCOPE_UNIVERSE, "global"},
+ {RT_SCOPE_SITE, "site"},
+ {RT_SCOPE_LINK, "link"},
+ {RT_SCOPE_HOST, "host"},
+ {RT_SCOPE_NOWHERE, "nowhere"},
+ {0, NULL}
+};
+
+/* for use in show interface */
+const char *
+connected_scope_name(unsigned value)
+{
+ const char *str;
+ static char buf[16];
+
+ str = lookup (rtscope_str, value);
+ if (!str || !*str) {
+ snprintf (buf, sizeof(buf), "%d", value);
+ str = buf;
+ }
+ return str;
+}
+
+int
+connected_scope_number(const char *name)
+{
+ const struct message *m;
+ char *errptr;
+ unsigned value;
+
+ if (!name || !*name)
+ return -1;
+
+ for (m = rtscope_str; m->str; m++)
+ if (!strcmp (m->str, name))
+ return m->key;
+
+ value = strtoul (name, &errptr, 0);
+ if (*errptr || value > 255)
+ return -1;
+
+ return value;
+}
+#endif /* HAVE_NETLINK */
/* withdraw a connected address */
static void
diff --git a/zebra/connected.h b/zebra/connected.h
index 0f7c586b..d7934055 100644
--- a/zebra/connected.h
+++ b/zebra/connected.h
@@ -54,4 +54,9 @@ extern void connected_down_ipv6 (struct interface *ifp, struct connected *);
#endif /* HAVE_IPV6 */
+#ifdef HAVE_NETLINK
+extern const char *connected_scope_name (unsigned value);
+extern int connected_scope_number (const char *name);
+#endif /* HAVE_NETLINK */
+
#endif /*_ZEBRA_CONNECTED_H */
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index dfe88002..da255e0f 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -549,6 +549,7 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
char buf[BUFSIZ];
zlog_debug ("netlink_interface_addr %s %s:",
lookup (nlmsg_str, h->nlmsg_type), ifp->name);
+ zlog_debug (" ifa_scope %s", connected_scope_name (ifa->ifa_scope));
if (tb[IFA_LOCAL])
zlog_debug (" IFA_LOCAL %s/%d",
inet_ntop (ifa->ifa_family, RTA_DATA (tb[IFA_LOCAL]),