1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00

use asplain notation in irrd queries

This commit is contained in:
Alexandre Snarskii
2018-11-30 12:40:25 +03:00
parent be9d1ee695
commit f8a32c67c6

View File

@@ -10,6 +10,7 @@
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
@@ -384,33 +385,24 @@ bgpq_pipeline(struct bgpq_expander* b,
static void static void
bgpq_expander_invalidate_asn(struct bgpq_expander* b, const char* q) bgpq_expander_invalidate_asn(struct bgpq_expander* b, const char* q)
{ {
if (!strncmp(q, "!gas", 4) || !strncmp(q, "!6as", 4)) { if (!strncmp(q, "!gas", 4) || !strncmp(q, "!6as", 4)) {
char* eptr; char* eptr;
unsigned long asn = strtoul(q+4, &eptr, 10), asn0, asn1 = 0; unsigned long asn = strtoul(q+4, &eptr, 10), asn0, asn1 = 0;
if (!asn || asn == ULONG_MAX || asn >= 4294967295 || if (!asn || asn == ULONG_MAX || asn >= 4294967295 ||
(eptr && *eptr != '\n' && *eptr != '\r' && *eptr != '.')) { (eptr && *eptr != '\n')) {
sx_report(SX_ERROR, "some problem invalidating asn %s\n", q); sx_report(SX_ERROR, "some problem invalidating asn %s\n", q);
return; return;
}; };
if (eptr && (*eptr == '\r' || *eptr == '\n')) { asn1 = asn % 65536;
asn1 = asn; asn0 = asn / 65536;
asn0 = 0; if (!b->asn32s[asn0] ||
} else if (eptr && *eptr == '.') { !(b->asn32s[asn0][asn1/8] & (0x80 >> (asn1 % 8)))) {
asn0 = asn; sx_report(SX_NOTICE, "strange, invalidating inactive asn %lu(%s)\n",
asn1 = strtoul(eptr+1, &eptr, 10); asn, q);
}; } else {
if (asn >= 65536) { b->asn32s[asn0][asn1/8] &= ~(0x80 >> (asn1 % 8));
asn1 = asn % 65536; };
asn0 = asn / 65536; };
};
if (!b->asn32s[asn0] ||
!(b->asn32s[asn0][asn1/8] & (0x80 >> (asn1 % 8)))) {
sx_report(SX_NOTICE, "strange, invalidating inactive asn %lu(%s)\n",
asn, q);
} else {
b->asn32s[asn0][asn1/8] &= ~(0x80 >> (asn1 % 8));
};
};
}; };
static void static void
@@ -869,7 +861,7 @@ bgpq_expand(struct bgpq_expander* b)
}; };
if(b->generation>=T_PREFIXLIST || b->validate_asns) { if(b->generation>=T_PREFIXLIST || b->validate_asns) {
unsigned i, j, k; uint32_t i, j, k;
STAILQ_FOREACH(mc, &b->rsets, next) { STAILQ_FOREACH(mc, &b->rsets, next) {
if(b->family==AF_INET) { if(b->family==AF_INET) {
bgpq_expand_irrd(b, bgpq_expanded_prefix, NULL, "!i%s,1\n", bgpq_expand_irrd(b, bgpq_expanded_prefix, NULL, "!i%s,1\n",
@@ -886,35 +878,19 @@ bgpq_expand(struct bgpq_expander* b)
if(b->asn32s[k][i]&(0x80>>j)) { if(b->asn32s[k][i]&(0x80>>j)) {
if(b->family==AF_INET6) { if(b->family==AF_INET6) {
if(!pipelining) { if(!pipelining) {
if(k>0) bgpq_expand_irrd(b, bgpq_expanded_v6prefix,
bgpq_expand_irrd(b, bgpq_expanded_v6prefix, NULL, "!6as%" PRIu32 "\n", (k<<16)+i*8+j);
NULL, "!6as%u.%u\r\n", k, i*8+j);
else
bgpq_expand_irrd(b, bgpq_expanded_v6prefix,
NULL,"!6as%u\r\n", i*8+j);
} else { } else {
if(k>0) bgpq_pipeline(b, bgpq_expanded_v6prefix,
bgpq_pipeline(b, bgpq_expanded_v6prefix, NULL, "!6as%" PRIu32 "\n", (k<<16)+i*8+j);
NULL, "!6as%u.%u\r\n", k, i*8+j);
else
bgpq_pipeline(b,bgpq_expanded_v6prefix,
NULL, "!6as%u\r\n", i*8+j);
}; };
} else { } else {
if(!pipelining) { if(!pipelining) {
if(k>0) bgpq_expand_irrd(b, bgpq_expanded_prefix,
bgpq_expand_irrd(b, bgpq_expanded_prefix, NULL, "!gas%" PRIu32 "\n", (k<<16)+i*8+j);
NULL,"!gas%u.%u\n", k, i*8+j);
else
bgpq_expand_irrd(b, bgpq_expanded_prefix,
NULL,"!gas%u\n", i*8+j);
} else { } else {
if(k>0) bgpq_pipeline(b, bgpq_expanded_prefix,
bgpq_pipeline(b, bgpq_expanded_prefix, NULL, "!gas%" PRIu32 "\n", (k<<16)+i*8+j);
NULL, "!gas%u.%u\n", k, i*8+j);
else
bgpq_pipeline(b, bgpq_expanded_prefix,
NULL, "!gas%u\n", i*8+j);
}; };
}; };
}; };