summaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2016-02-09 14:53:29 +0100
committerJan Moskyto Matejka <mq@ucw.cz>2016-12-22 21:38:33 +0100
commitd311368bc58842552e25744a0aae9a09c42cda9f (patch)
tree7bdacfbca47c86148193f5438d9bb2ae89fa4342 /lib/net.c
parentd47c3d64b2733baea756f1bb37ef09f10d7f9644 (diff)
VPN4 and VPN6 literals
From now on, protocol static accepts VPN4 and VPN6 addressess. With some concerns about VPN6 Route Distinguishers, I finally chose to have the same format as for VPN4 (where it is defined by RFC 4364).
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/net.c b/lib/net.c
index 5a7e6fec..e46be8b2 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -58,6 +58,7 @@ int
net_format(const net_addr *N, char *buf, int buflen)
{
net_addr_union *n = (void *) N;
+ buf[0] = 0;
switch (n->n.type)
{
@@ -66,9 +67,23 @@ net_format(const net_addr *N, char *buf, int buflen)
case NET_IP6:
return bsnprintf(buf, buflen, "%I6/%d", n->ip6.prefix, n->ip6.pxlen);
case NET_VPN4:
- return bsnprintf(buf, buflen, "%u:%u %I4/%d", (u32) (n->vpn4.rd >> 32), (u32) n->vpn4.rd, n->vpn4.prefix, n->vpn4.pxlen);
+ switch (n->vpn4.rd >> 48)
+ {
+ case 0: return bsnprintf(buf, buflen, "0:%u:%u %I4/%d", (u32) (n->vpn4.rd >> 32), (u32) n->vpn4.rd, n->vpn4.prefix, n->vpn4.pxlen);
+ case 1: return bsnprintf(buf, buflen, "1:%I4:%u %I4/%d", ip4_from_u32(n->vpn4.rd >> 16), (u32) (n->vpn4.rd & 0xffff), n->vpn4.prefix, n->vpn4.pxlen);
+ case 2: return bsnprintf(buf, buflen, "2:%u:%u %I4/%d", (u32) (n->vpn4.rd >> 16), (u32) (n->vpn4.rd & 0xffff), n->vpn4.prefix, n->vpn4.pxlen);
+ }
+ return bsnprintf(buf, buflen, "X: %016x %I4/%d", (n->vpn4.rd), n->vpn4.prefix, n->vpn4.pxlen);
+
+ /* XXX: RD format is specified for VPN4; not found any for VPN6, reusing the same as for VPN4. */
case NET_VPN6:
- return bsnprintf(buf, buflen, "%u:%u %I6/%d", (u32) (n->vpn6.rd >> 32), (u32) n->vpn6.rd, n->vpn6.prefix, n->vpn6.pxlen);
+ switch (n->vpn6.rd >> 48)
+ {
+ case 0: return bsnprintf(buf, buflen, "0:%u:%u %I6/%d", (u32) (n->vpn6.rd >> 32), (u32) n->vpn6.rd, n->vpn6.prefix, n->vpn6.pxlen);
+ case 1: return bsnprintf(buf, buflen, "1:%I4:%u %I6/%d", ip4_from_u32(n->vpn6.rd >> 16), (u32) (n->vpn6.rd & 0xffff), n->vpn6.prefix, n->vpn6.pxlen);
+ case 2: return bsnprintf(buf, buflen, "2:%u:%u %I6/%d", (u32) (n->vpn6.rd >> 16), (u32) (n->vpn6.rd & 0xffff), n->vpn6.prefix, n->vpn6.pxlen);
+ }
+ return bsnprintf(buf, buflen, "X: %016x %I6/%d", (n->vpn6.rd), n->vpn6.prefix, n->vpn6.pxlen);
case NET_ROA4:
return bsnprintf(buf, buflen, "%I4/%u-%u AS%u", n->roa4.prefix, n->roa4.pxlen, n->roa4.max_pxlen, n->roa4.asn);
case NET_ROA6:
@@ -81,7 +96,7 @@ net_format(const net_addr *N, char *buf, int buflen)
return bsnprintf(buf, buflen, "%u", n->mpls.label);
}
- return 0;
+ bug("unknown network type");
}
ip_addr