mirror of
https://github.com/bgp/bgpq4
synced 2025-02-28 08:53:11 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30110bad46 | ||
|
|
5507267c63 | ||
|
|
ab683d75d5 | ||
|
|
fb955c0521 | ||
|
|
4661fab181 |
1
.github/images/rockylinux/rockylinux:9.Dockerfile
vendored
Symbolic link
1
.github/images/rockylinux/rockylinux:9.Dockerfile
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../centos.Dockerfile
|
||||
1
.github/images/ubuntu:jammy.Dockerfile
vendored
Symbolic link
1
.github/images/ubuntu:jammy.Dockerfile
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
debian.Dockerfile
|
||||
6
.github/workflows/matrixbuild.yml
vendored
6
.github/workflows/matrixbuild.yml
vendored
@@ -12,17 +12,19 @@ jobs:
|
||||
- debian:bookworm
|
||||
- debian:bullseye
|
||||
- debian:buster
|
||||
- ubuntu:jammy
|
||||
- ubuntu:focal
|
||||
- ubuntu:bionic
|
||||
- fedora/fedora:37
|
||||
- fedora/fedora:36
|
||||
- fedora/fedora:35
|
||||
- fedora/fedora:34
|
||||
- centos/centos:stream9
|
||||
- centos/centos:stream8
|
||||
- centos/centos:7
|
||||
- rockylinux/rockylinux:9
|
||||
- rockylinux/rockylinux:8
|
||||
- alpine:edge
|
||||
- alpine:3.15
|
||||
- alpine:3.16
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Run build on ${{matrix.dockerenv}}
|
||||
|
||||
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
||||
1.6 (2022-09-07)
|
||||
- Fix a bug in address prefix range parsing
|
||||
|
||||
1.5 (2022-07-25)
|
||||
- Add support for the new Junos as-path-origins feature
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ bgpq_expander_add_prefix(struct bgpq_expander *b, char *prefix)
|
||||
sx_radix_tree_insert(b->tree, p);
|
||||
|
||||
if (p)
|
||||
sx_prefix_destroy(p);
|
||||
sx_prefix_free(p);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1113,7 +1113,7 @@ sx_radix_node_freeall(struct sx_radix_node *n) {
|
||||
if (n->payload)
|
||||
free(n->payload);
|
||||
|
||||
sx_prefix_destroy(n->prefix);
|
||||
sx_prefix_free(n->prefix);
|
||||
|
||||
free(n);
|
||||
}
|
||||
|
||||
121
sx_prefix.c
121
sx_prefix.c
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -38,13 +39,13 @@
|
||||
int debug_aggregation = 0;
|
||||
extern int debug_expander;
|
||||
|
||||
struct sx_prefix*
|
||||
struct sx_prefix *
|
||||
sx_prefix_alloc(struct sx_prefix *p)
|
||||
{
|
||||
struct sx_prefix *sp = malloc(sizeof(struct sx_prefix));
|
||||
struct sx_prefix *sp;
|
||||
|
||||
if (!sp)
|
||||
return NULL;
|
||||
if ((sp = malloc(sizeof(struct sx_prefix))) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
if (p)
|
||||
memcpy(sp, p, sizeof(struct sx_prefix));
|
||||
@@ -55,7 +56,7 @@ sx_prefix_alloc(struct sx_prefix *p)
|
||||
}
|
||||
|
||||
void
|
||||
sx_prefix_destroy(struct sx_prefix *p)
|
||||
sx_prefix_free(struct sx_prefix *p)
|
||||
{
|
||||
if (p)
|
||||
free(p);
|
||||
@@ -64,15 +65,16 @@ sx_prefix_destroy(struct sx_prefix *p)
|
||||
void
|
||||
sx_radix_node_destroy(struct sx_radix_node *n)
|
||||
{
|
||||
if (n) {
|
||||
if (n->payload)
|
||||
free(n->payload);
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
if (n->prefix)
|
||||
free(n->prefix);
|
||||
if (n->payload)
|
||||
free(n->payload);
|
||||
|
||||
free(n);
|
||||
}
|
||||
if (n->prefix)
|
||||
free(n->prefix);
|
||||
|
||||
free(n);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -140,7 +142,7 @@ sx_prefix_parse(struct sx_prefix *p, int af, char *text)
|
||||
c = strchr(mtext,'/');
|
||||
|
||||
if (c) {
|
||||
char* eod;
|
||||
char *eod;
|
||||
*c = 0;
|
||||
masklen = strtol(c + 1, &eod, 10);
|
||||
if (eod && eod[0] && !isspace(eod[0])) {
|
||||
@@ -257,25 +259,19 @@ sx_prefix_setbit(struct sx_prefix *p, int n)
|
||||
|
||||
|
||||
static int
|
||||
sx_radix_tree_insert_specifics(struct sx_radix_tree *t, struct sx_prefix *p,
|
||||
sx_radix_tree_insert_specifics(struct sx_radix_tree *t, struct sx_prefix p,
|
||||
unsigned min, unsigned max)
|
||||
{
|
||||
struct sx_prefix *np;
|
||||
np = sx_prefix_alloc(p);
|
||||
if (p.masklen >= min)
|
||||
sx_radix_tree_insert(t, &p);
|
||||
|
||||
if (np->masklen >= min) {
|
||||
struct sx_radix_node *nn = sx_radix_tree_insert(t, np);
|
||||
sx_prefix_destroy(np);
|
||||
np = nn->prefix;
|
||||
}
|
||||
|
||||
if (np->masklen + 1 > max)
|
||||
if (p.masklen + 1 > max)
|
||||
return 1;
|
||||
|
||||
np->masklen += 1;
|
||||
sx_radix_tree_insert_specifics(t, np, min, max);
|
||||
sx_prefix_setbit(np, np->masklen);
|
||||
sx_radix_tree_insert_specifics(t, np, min, max);
|
||||
p.masklen += 1;
|
||||
sx_radix_tree_insert_specifics(t, p, min, max);
|
||||
sx_prefix_setbit(&p, p.masklen);
|
||||
sx_radix_tree_insert_specifics(t, p, min, max);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -284,18 +280,16 @@ int
|
||||
sx_prefix_range_parse(struct sx_radix_tree *tree, int af, unsigned int maxlen,
|
||||
char *text)
|
||||
{
|
||||
char *d = strchr(text, '^');
|
||||
struct sx_prefix *p;
|
||||
struct sx_prefix p;
|
||||
unsigned long min, max = 0;
|
||||
|
||||
p = sx_prefix_alloc(NULL);
|
||||
char *d = strchr(text, '^');
|
||||
|
||||
if (!d || !d[1])
|
||||
return 0;
|
||||
|
||||
*d = 0;
|
||||
|
||||
if (!sx_prefix_parse(p, 0, text)) {
|
||||
if (!sx_prefix_parse(&p, 0, text)) {
|
||||
sx_report(SX_ERROR, "Unable to parse prefix %s^%s\n", text,
|
||||
d + 1);
|
||||
return 0;
|
||||
@@ -303,23 +297,23 @@ sx_prefix_range_parse(struct sx_radix_tree *tree, int af, unsigned int maxlen,
|
||||
|
||||
*d = '^';
|
||||
|
||||
if (af && p->family != af) {
|
||||
if (af && p.family != af) {
|
||||
sx_report(SX_ERROR, "Ignoring prefix %s, wrong af %i\n", text,
|
||||
p->family);
|
||||
p.family);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (maxlen && p->masklen > maxlen) {
|
||||
if (maxlen && p.masklen > maxlen) {
|
||||
SX_DEBUG(debug_expander, "Ignoring prefix %s, masklen %i > max"
|
||||
" masklen %u\n", text, p->masklen, maxlen);
|
||||
" masklen %u\n", text, p.masklen, maxlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (d[1] == '-') {
|
||||
min = p->masklen + 1;
|
||||
min = p.masklen + 1;
|
||||
max = maxlen;
|
||||
} else if (d[1] == '+') {
|
||||
min = p->masklen;
|
||||
min = p.masklen;
|
||||
max = maxlen;
|
||||
} else if (isdigit(d[1])) {
|
||||
char *dm = NULL;
|
||||
@@ -336,9 +330,9 @@ sx_prefix_range_parse(struct sx_radix_tree *tree, int af, unsigned int maxlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (min < p->masklen) {
|
||||
if (min < p.masklen) {
|
||||
sx_report(SX_ERROR, "Invalid prefix-range %s: min %lu < "
|
||||
"masklen %u\n", text, min, p->masklen);
|
||||
"masklen %u\n", text, min, p.masklen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -377,7 +371,7 @@ sx_prefix_new(int af, char *text)
|
||||
return NULL;
|
||||
|
||||
if (!sx_prefix_parse(p, af, text)) {
|
||||
sx_prefix_destroy(p);
|
||||
sx_prefix_free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -519,13 +513,13 @@ sx_prefix_jsnprintf(struct sx_prefix *p, char *rbuffer, int srb)
|
||||
return snprintf(rbuffer, srb, "%s\\/%i", buffer, p->masklen);
|
||||
}
|
||||
|
||||
struct sx_radix_tree*
|
||||
struct sx_radix_tree *
|
||||
sx_radix_tree_new(int af)
|
||||
{
|
||||
struct sx_radix_tree *rt = malloc(sizeof(struct sx_radix_tree));
|
||||
struct sx_radix_tree *rt;
|
||||
|
||||
if (!rt)
|
||||
return NULL;
|
||||
if ((rt = malloc(sizeof(struct sx_radix_tree))) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
memset(rt, 0, sizeof(struct sx_radix_tree));
|
||||
rt->family = af;
|
||||
@@ -539,13 +533,13 @@ sx_radix_tree_empty(struct sx_radix_tree *t)
|
||||
return t->head == NULL;
|
||||
}
|
||||
|
||||
struct sx_radix_node*
|
||||
struct sx_radix_node *
|
||||
sx_radix_node_new(struct sx_prefix *prefix)
|
||||
{
|
||||
struct sx_radix_node *rn = malloc(sizeof(struct sx_radix_node));
|
||||
struct sx_radix_node *rn;
|
||||
|
||||
if (!rn)
|
||||
return NULL;
|
||||
if ((rn = malloc(sizeof(struct sx_radix_node))) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
memset(rn, 0, sizeof(struct sx_radix_node));
|
||||
|
||||
@@ -582,7 +576,7 @@ sx_prefix_eqbits(struct sx_prefix *a, struct sx_prefix *b)
|
||||
return b->masklen;
|
||||
}
|
||||
|
||||
struct sx_prefix*
|
||||
struct sx_prefix *
|
||||
sx_prefix_overlay(struct sx_prefix *p, int n)
|
||||
{
|
||||
struct sx_prefix *sp = sx_prefix_alloc(p);
|
||||
@@ -668,7 +662,7 @@ next:
|
||||
}
|
||||
|
||||
|
||||
struct sx_radix_node*
|
||||
struct sx_radix_node *
|
||||
sx_radix_tree_lookup(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
||||
{
|
||||
unsigned int eb;
|
||||
@@ -725,18 +719,18 @@ next:
|
||||
char pbuffer[128], cbuffer[128];
|
||||
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
||||
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
||||
printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n",
|
||||
printf("Unreachable point... eb=%i, prefix=%s, chead=%s\n",
|
||||
eb, pbuffer, cbuffer);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct sx_radix_node*
|
||||
struct sx_radix_node *
|
||||
sx_radix_tree_insert(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
||||
{
|
||||
unsigned int eb;
|
||||
struct sx_radix_node **candidate=NULL, *chead;
|
||||
unsigned int eb;
|
||||
struct sx_radix_node *chead, **candidate = NULL;
|
||||
|
||||
if (!tree || !prefix)
|
||||
return NULL;
|
||||
@@ -752,7 +746,7 @@ sx_radix_tree_insert(struct sx_radix_tree *tree, struct sx_prefix *prefix)
|
||||
candidate = &tree->head;
|
||||
chead = tree->head;
|
||||
|
||||
next:
|
||||
next:
|
||||
eb = sx_prefix_eqbits(prefix, chead->prefix);
|
||||
if (eb < prefix->masklen && eb < chead->prefix->masklen) {
|
||||
struct sx_prefix *neoRoot = sx_prefix_alloc(prefix);
|
||||
@@ -761,7 +755,7 @@ next:
|
||||
neoRoot->masklen = eb;
|
||||
sx_prefix_adjust_masklen(neoRoot);
|
||||
rn=sx_radix_node_new(neoRoot);
|
||||
sx_prefix_destroy(neoRoot);
|
||||
sx_prefix_free(neoRoot);
|
||||
neoRoot = rn->prefix;
|
||||
if (!rn) {
|
||||
sx_report(SX_ERROR,"Unable to create node: %s\n",
|
||||
@@ -785,11 +779,10 @@ next:
|
||||
return ret;
|
||||
} else if (eb == prefix->masklen && eb < chead->prefix->masklen) {
|
||||
struct sx_radix_node *ret = sx_radix_node_new(prefix);
|
||||
if (sx_prefix_isbitset(chead->prefix, eb + 1)) {
|
||||
if (sx_prefix_isbitset(chead->prefix, eb + 1))
|
||||
ret->r = chead;
|
||||
} else {
|
||||
else
|
||||
ret->l = chead;
|
||||
}
|
||||
ret->parent = chead->parent;
|
||||
chead->parent = ret;
|
||||
*candidate = ret;
|
||||
@@ -826,7 +819,7 @@ next:
|
||||
char pbuffer[128], cbuffer[128];
|
||||
sx_prefix_snprintf(prefix, pbuffer, sizeof(pbuffer));
|
||||
sx_prefix_snprintf(chead->prefix, cbuffer, sizeof(cbuffer));
|
||||
printf("Unreachible point... eb=%i, prefix=%s, chead=%s\n", eb,
|
||||
printf("Unreachable point... eb=%i, prefix=%s, chead=%s\n", eb,
|
||||
pbuffer, cbuffer);
|
||||
abort();
|
||||
}
|
||||
@@ -848,7 +841,7 @@ sx_radix_node_fprintf(struct sx_radix_node *node, void *udata)
|
||||
|
||||
int
|
||||
sx_radix_node_foreach(struct sx_radix_node *node,
|
||||
void (*func)(struct sx_radix_node*, void*), void *udata)
|
||||
void (*func)(struct sx_radix_node *, void *), void *udata)
|
||||
{
|
||||
func(node, udata);
|
||||
|
||||
@@ -1055,7 +1048,7 @@ sx_radix_tree_aggregate(struct sx_radix_tree *tree)
|
||||
static void
|
||||
setGlueUpTo(struct sx_radix_node *node, void *udata)
|
||||
{
|
||||
unsigned refine = *(unsigned*)udata;
|
||||
unsigned refine = *(unsigned *)udata;
|
||||
|
||||
if (node && node->prefix->masklen <= refine)
|
||||
node->isGlue = 1;
|
||||
@@ -1115,7 +1108,7 @@ sx_radix_tree_refine(struct sx_radix_tree *tree, unsigned refine)
|
||||
static void
|
||||
setGlueFrom(struct sx_radix_node *node, void *udata)
|
||||
{
|
||||
unsigned refine = *(unsigned*)udata;
|
||||
unsigned refine = *(unsigned *)udata;
|
||||
|
||||
if (node && node->prefix->masklen <= refine)
|
||||
node->isGlue = 1;
|
||||
|
||||
@@ -68,7 +68,7 @@ struct sx_radix_node *sx_radix_tree_lookup_exact(struct sx_radix_tree *tree,
|
||||
struct sx_prefix *prefix);
|
||||
|
||||
struct sx_prefix *sx_prefix_alloc(struct sx_prefix *p);
|
||||
void sx_prefix_destroy(struct sx_prefix *p);
|
||||
void sx_prefix_free(struct sx_prefix *p);
|
||||
void sx_radix_node_destroy(struct sx_radix_node *p);
|
||||
void sx_prefix_adjust_masklen(struct sx_prefix *p);
|
||||
struct sx_prefix *sx_prefix_new(int af, char *text);
|
||||
|
||||
Reference in New Issue
Block a user