0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 02:01:55 +00:00

VPN address parser fix, better display of invalid values

This commit is contained in:
Jan Moskyto Matejka 2016-02-19 13:59:55 +01:00
parent ac10ab7e19
commit 312a70e2ef
2 changed files with 11 additions and 5 deletions

View File

@ -125,7 +125,12 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
[02]:{DIGIT}+:{DIGIT}+ { [02]:{DIGIT}+:{DIGIT}+ {
char *e; char *e;
unsigned long int l; unsigned long int l;
cf_lval.i64 = ((u64)(yytext[0] - '0')) << 48;
if (yytext[0] == '0')
cf_lval.i64 = 0;
else
cf_lval.i64 = 0x2000000000000ULL;
errno = 0; errno = 0;
l = strtoul(yytext+2, &e, 10); l = strtoul(yytext+2, &e, 10);
if (e && (*e != ':') || errno == ERANGE || (yytext[0] == '0') && (l >= (1<<16))) if (e && (*e != ':') || errno == ERANGE || (yytext[0] == '0') && (l >= (1<<16)))

View File

@ -43,6 +43,7 @@ int
net_format(const net_addr *N, char *buf, int buflen) net_format(const net_addr *N, char *buf, int buflen)
{ {
net_addr_union *n = (void *) N; net_addr_union *n = (void *) N;
buf[0] = 0;
switch (n->n.type) switch (n->n.type)
{ {
@ -57,24 +58,24 @@ net_format(const net_addr *N, char *buf, int buflen)
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 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); 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 0; 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. */ /* XXX: RD format is specified for VPN4; not found any for VPN6, reusing the same as for VPN4. */
case NET_VPN6: case NET_VPN6:
switch (n->vpn4.rd >> 48) 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 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 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); 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 0; return bsnprintf(buf, buflen, "X: %016x %I6/%d", (n->vpn6.rd), n->vpn6.prefix, n->vpn6.pxlen);
case NET_ROA4: 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); 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: case NET_ROA6:
return bsnprintf(buf, buflen, "%I6/%u-%u AS%u", n->roa6.prefix, n->roa6.pxlen, n->roa6.max_pxlen, n->roa6.asn); return bsnprintf(buf, buflen, "%I6/%u-%u AS%u", n->roa6.prefix, n->roa6.pxlen, n->roa6.max_pxlen, n->roa6.asn);
} }
return 0; bug("unknown network type");
} }
ip_addr ip_addr