summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2010-03-29 09:04:44 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2010-03-29 09:04:44 +0000
commit4310b6e0e7578af8e22492f30466678413c8a490 (patch)
treead28874a8a74c3c3789c83e3525eed34cccc5f03
parent60b6125f1ad61de92915c9f04172ce8aa7276009 (diff)
Implement a log_rd() function to print the route destinguisher in a nice
way. Use it for now in log_addr() to show VPN routes with a prepended RD. OK henning
-rw-r--r--usr.sbin/bgpd/bgpd.h3
-rw-r--r--usr.sbin/bgpd/util.c43
2 files changed, 41 insertions, 5 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 3e466fde63f..b260974eed6 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.253 2010/03/05 15:25:00 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.254 2010/03/29 09:04:43 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -871,6 +871,7 @@ const char *log_addr(const struct bgpd_addr *);
const char *log_in6addr(const struct in6_addr *);
const char *log_sockaddr(struct sockaddr *);
const char *log_as(u_int32_t);
+const char *log_rd(u_int64_t);
const char *log_ext_subtype(u_int8_t);
int aspath_snprint(char *, size_t, void *, u_int16_t);
int aspath_asprint(char **, void *, u_int16_t);
diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c
index aa217e1ef42..f700774408f 100644
--- a/usr.sbin/bgpd/util.c
+++ b/usr.sbin/bgpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.10 2010/01/13 06:02:37 claudio Exp $ */
+/* $OpenBSD: util.c,v 1.11 2010/03/29 09:04:43 claudio Exp $ */
/*
* Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@@ -32,6 +32,7 @@ const char *
log_addr(const struct bgpd_addr *addr)
{
static char buf[48];
+ char tbuf[16];
switch (addr->aid) {
case AID_INET:
@@ -41,9 +42,11 @@ log_addr(const struct bgpd_addr *addr)
return ("?");
return (buf);
case AID_VPN_IPv4:
- if (inet_ntop(AF_INET, &addr->vpn4.addr, buf,
- sizeof(buf)) == NULL)
+ if (inet_ntop(AF_INET, &addr->vpn4.addr, tbuf,
+ sizeof(tbuf)) == NULL)
return ("?");
+ snprintf(buf, sizeof(buf), "%s %s", log_rd(addr->vpn4.rd),
+ tbuf);
return (buf);
}
return ("???");
@@ -100,7 +103,39 @@ log_as(u_int32_t as)
return (buf);
}
-/* XXX this function does not check if the type/subtype combo is
+const char *
+log_rd(u_int64_t rd)
+{
+ static char buf[32];
+ struct in_addr addr;
+ u_int32_t u32;
+ u_int16_t u16;
+
+ rd = betoh64(rd);
+ switch (rd >> 48) {
+ case EXT_COMMUNITY_TWO_AS:
+ u32 = rd & 0xffffffff;
+ u16 = (rd >> 32) & 0xffff;
+ snprintf(buf, sizeof(buf), "rd %i:%i", u16, u32);
+ break;
+ case EXT_COMMUNITY_FOUR_AS:
+ u32 = (rd >> 16) & 0xffffffff;
+ u16 = rd & 0xffff;
+ snprintf(buf, sizeof(buf), "rd %s:%i", log_as(u32), u16);
+ break;
+ case EXT_COMMUNITY_IPV4:
+ u32 = (rd >> 16) & 0xffffffff;
+ u16 = rd & 0xffff;
+ addr.s_addr = htonl(u32);
+ snprintf(buf, sizeof(buf), "rd %s:%i", inet_ntoa(addr), u16);
+ break;
+ default:
+ return ("rd ?");
+ }
+ return (buf);
+}
+
+/* NOTE: this function does not check if the type/subtype combo is
* actually valid. */
const char *
log_ext_subtype(u_int8_t subtype)