From a3e5daee7205e8bffb44d914a74d38fe8ad0c986 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 2 Feb 2010 01:36:36 +0100 Subject: 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. --- zebra/connected.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ zebra/connected.h | 5 +++++ zebra/rt_netlink.c | 1 + 3 files changed, 53 insertions(+) (limited to 'zebra') 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]), -- cgit v1.2.3