summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2017-03-28 17:35:32 +0200
committerJan Moskyto Matejka <mq@ucw.cz>2017-03-28 17:35:32 +0200
commit2282030b2a4fb07805a0cd8b82a9aab73b7586d8 (patch)
treea094b4731e7d1c32f0757e99df2aa6db59317d94
parentef57b70fa51687865e5823c0af2df2c6de338215 (diff)
Simpler format of VPN RD
-rw-r--r--conf/cf-lex.l39
-rw-r--r--lib/net.c9
2 files changed, 41 insertions, 7 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index fb3d59e4..db847d37 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -123,6 +123,37 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
cf_include(start, end-start);
}
+{DIGIT}+:{DIGIT}+ {
+ unsigned long int l, len1, len2;
+ char *e;
+
+ errno = 0;
+ l = strtoul(yytext, &e, 10);
+ if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
+ cf_error("ASN out of range");
+
+ if (l >> 16)
+ {
+ len1 = 32;
+ len2 = 16;
+ cf_lval.i64 = (2ULL << 48) | (((u64) l) << len2);
+ }
+ else
+ {
+ len1 = 16;
+ len2 = 32;
+ cf_lval.i64 = 0 | (((u64) l) << len2);
+ }
+
+ errno = 0;
+ l = strtoul(e+1, &e, 10);
+ if (e && *e || (errno == ERANGE) || (l >> len2))
+ cf_error("Number out of range");
+ cf_lval.i64 |= l;
+
+ return VPN_RD;
+}
+
[02]:{DIGIT}+:{DIGIT}+ {
unsigned long int l, len1, len2;
char *e;
@@ -155,17 +186,17 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
return VPN_RD;
}
-1:{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+:{DIGIT}+ {
+{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+:{DIGIT}+ {
unsigned long int l;
ip4_addr ip4;
char *e;
cf_lval.i64 = 1ULL << 48;
- e = strchr(yytext+2, ':');
+ e = strchr(yytext, ':');
*e++ = '\0';
- if (!ip4_pton(yytext+2, &ip4))
- cf_error("Invalid IPv4 address %s in Route Distinguisher", yytext+2);
+ if (!ip4_pton(yytext, &ip4))
+ cf_error("Invalid IPv4 address %s in Route Distinguisher", yytext);
cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
errno = 0;
diff --git a/lib/net.c b/lib/net.c
index c29ed299..e6053812 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -59,9 +59,12 @@ rd_format(const u64 rd, char *buf, int buflen)
{
switch (rd >> 48)
{
- case 0: return bsnprintf(buf, buflen, "0:%u:%u", (u32) (rd >> 32), (u32) rd);
- case 1: return bsnprintf(buf, buflen, "1:%I4:%u", ip4_from_u32(rd >> 16), (u32) (rd & 0xffff));
- case 2: return bsnprintf(buf, buflen, "2:%u:%u", (u32) (rd >> 16), (u32) (rd & 0xffff));
+ case 0: return bsnprintf(buf, buflen, "%u:%u", (u32) (rd >> 32), (u32) rd);
+ case 1: return bsnprintf(buf, buflen, "%I4:%u", ip4_from_u32(rd >> 16), (u32) (rd & 0xffff));
+ case 2: if (((u32) (rd >> 16)) >> 16)
+ return bsnprintf(buf, buflen, "%u:%u", (u32) (rd >> 16), (u32) (rd & 0xffff));
+ else
+ return bsnprintf(buf, buflen, "2:%u:%u", (u32) (rd >> 16), (u32) (rd & 0xffff));
default: return bsnprintf(buf, buflen, "X:%08x:%08x", (u32) (rd >> 32), (u32) rd);
}
}