diff --git a/expander.c b/expander.c index bfe9ec0..165fbe7 100644 --- a/expander.c +++ b/expander.c @@ -57,7 +57,7 @@ tentry_cmp(struct sx_tentry *a, struct sx_tentry *b) return strcasecmp(a->text, b->text); } -RB_GENERATE_STATIC(tentree, sx_tentry, entry, tentry_cmp); +RB_GENERATE_STATIC(tentree, sx_tentry, entries, tentry_cmp); int bgpq_expander_init(struct bgpq_expander *b, int af) @@ -122,7 +122,7 @@ bgpq_expander_add_asset(struct bgpq_expander *b, char *as) le = sx_slentry_new(as); - STAILQ_INSERT_TAIL(&b->macroses, le, next); + STAILQ_INSERT_TAIL(&b->macroses, le, entries); return 1; } @@ -140,7 +140,7 @@ bgpq_expander_add_rset(struct bgpq_expander *b, char *rs) if (!le) return 0; - STAILQ_INSERT_TAIL(&b->rsets, le, next); + STAILQ_INSERT_TAIL(&b->rsets, le, entries); return 1; } @@ -472,9 +472,9 @@ static void bgpq_write(struct bgpq_expander *b) { while(!STAILQ_EMPTY(&b->wq)) { - struct bgpq_request* req = STAILQ_FIRST(&b->wq); + struct bgpq_request *req = STAILQ_FIRST(&b->wq); - int ret = write(b->fd, req->request+req->offset, + int ret = write(b->fd, req->request + req->offset, req->size-req->offset); if (ret < 0) { @@ -1023,7 +1023,7 @@ bgpq_expand(struct bgpq_expander *b) if (pipelining) fcntl(fd, F_SETFL, O_NONBLOCK|(fcntl(fd, F_GETFL))); - STAILQ_FOREACH(mc, &b->macroses, next) { + STAILQ_FOREACH(mc, &b->macroses, entries) { if (!b->maxdepth && RB_EMPTY(&b->stoplist)) { if (aquery) bgpq_expand_irrd(b, bgpq_expanded_prefix, b, @@ -1053,7 +1053,7 @@ bgpq_expand(struct bgpq_expander *b) if (b->generation >= T_PREFIXLIST || b->validate_asns) { uint32_t i, j, k; - STAILQ_FOREACH(mc, &b->rsets, next) { + STAILQ_FOREACH(mc, &b->rsets, entries) { if (b->family == AF_INET) bgpq_expand_irrd(b, bgpq_expanded_prefix, NULL, "!i%s,1\n", mc->text); @@ -1159,6 +1159,12 @@ expander_freeall(struct bgpq_expander *expander) { //} // printf("freeing asn32s\n"); + while (!STAILQ_EMPTY(&expander->macroses)) { + struct sx_slentry *n1 = STAILQ_FIRST(&expander->macroses); + STAILQ_REMOVE_HEAD(&expander->macroses, entries); + free(n1); + } + for (int i = 0; i < 65536; i++) { if (expander->asn32s[i] != NULL) { free(expander->asn32s[i]); diff --git a/extern.h b/extern.h index 9b1208f..52722bb 100644 --- a/extern.h +++ b/extern.h @@ -60,9 +60,10 @@ struct bgpq_request { STAILQ_ENTRY(bgpq_request) next; char *request; int size, offset; - int (*callback)(char*, struct bgpq_expander*, struct bgpq_request*); void *udata; unsigned int depth; + int (*callback)(char *, struct bgpq_expander *, + struct bgpq_request *); }; struct bgpq_expander { @@ -93,22 +94,22 @@ struct bgpq_expander { int fd; }; -int bgpq_expander_init(struct bgpq_expander* b, int af); -int bgpq_expander_add_asset(struct bgpq_expander* b, char* set); -int bgpq_expander_add_rset(struct bgpq_expander* b, char* set); -int bgpq_expander_add_as(struct bgpq_expander* b, char* as); -int bgpq_expander_add_prefix(struct bgpq_expander* b, char* prefix); -int bgpq_expander_add_prefix_range(struct bgpq_expander* b, char* prefix); -int bgpq_expander_add_stop(struct bgpq_expander* b, char* object); +int bgpq_expander_init(struct bgpq_expander *b, int af); +int bgpq_expander_add_asset(struct bgpq_expander *b, char *set); +int bgpq_expander_add_rset(struct bgpq_expander *b, char *set); +int bgpq_expander_add_as(struct bgpq_expander *b, char *as); +int bgpq_expander_add_prefix(struct bgpq_expander *b, char *prefix); +int bgpq_expander_add_prefix_range(struct bgpq_expander *b, char *prefix); +int bgpq_expander_add_stop(struct bgpq_expander *b, char *object); -int bgpq_expand(struct bgpq_expander* b); +int bgpq_expand(struct bgpq_expander *b); -int bgpq4_print_prefixlist(FILE* f, struct bgpq_expander* b); -int bgpq4_print_eacl(FILE* f, struct bgpq_expander* b); -int bgpq4_print_aspath(FILE* f, struct bgpq_expander* b); -int bgpq4_print_asset(FILE* f, struct bgpq_expander* b); -int bgpq4_print_oaspath(FILE* f, struct bgpq_expander* b); -int bgpq4_print_route_filter_list(FILE* f, struct bgpq_expander* b); +int bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b); +int bgpq4_print_eacl(FILE *f, struct bgpq_expander *b); +int bgpq4_print_aspath(FILE *f, struct bgpq_expander *b); +int bgpq4_print_asset(FILE *f, struct bgpq_expander *b); +int bgpq4_print_oaspath(FILE *f, struct bgpq_expander *b); +int bgpq4_print_route_filter_list(FILE *f, struct bgpq_expander *b); void sx_radix_node_freeall(struct sx_radix_node *n); void sx_radix_tree_freeall(struct sx_radix_tree *t); diff --git a/main.c b/main.c index 91c2b2d..f949a3a 100644 --- a/main.c +++ b/main.c @@ -700,7 +700,8 @@ main(int argc, char* argv[]) sx_report(SX_ERROR, "Unable to add prefix %s " "(bad prefix or address-family)\n", argv[0]); exit(1); - } else if (ec && !bgpq_expander_add_prefix_range(&expander, argv[0])) { + } else if (ec && !bgpq_expander_add_prefix_range(&expander, + argv[0])) { sx_report(SX_ERROR, "Unable to add prefix-range " "%s (bad range or address-family)\n", argv[0]); diff --git a/sx_slentry.h b/sx_slentry.h index a46a107..90c6aa3 100644 --- a/sx_slentry.h +++ b/sx_slentry.h @@ -31,14 +31,14 @@ #include struct sx_slentry { - STAILQ_ENTRY(sx_slentry) next; + STAILQ_ENTRY(sx_slentry) entries; char* text; }; struct sx_slentry* sx_slentry_new(char* text); struct sx_tentry { - RB_ENTRY(sx_tentry) entry; + RB_ENTRY(sx_tentry) entries; char* text; };