KNF & renaming

This commit is contained in:
Job Snijders
2021-08-19 20:21:25 +00:00
parent 5ce7d7bfea
commit 80b7dcf4de
3 changed files with 75 additions and 75 deletions

View File

@@ -116,7 +116,7 @@ fixups:
int int
bgpq_expander_add_asset(struct bgpq_expander *b, char *as) bgpq_expander_add_asset(struct bgpq_expander *b, char *as)
{ {
struct sx_slentry *le; struct slentry *le;
if (!b || !as) if (!b || !as)
return 0; return 0;
@@ -131,7 +131,7 @@ bgpq_expander_add_asset(struct bgpq_expander *b, char *as)
int int
bgpq_expander_add_rset(struct bgpq_expander *b, char *rs) bgpq_expander_add_rset(struct bgpq_expander *b, char *rs)
{ {
struct sx_slentry *le; struct slentry *le;
if (!b || !rs) if (!b || !rs)
return 0; return 0;
@@ -261,24 +261,24 @@ bgpq_expander_add_prefix_range(struct bgpq_expander *b, char *prefix)
static int static int
bgpq_expanded_macro(char *as, struct bgpq_expander *ex, bgpq_expanded_macro(char *as, struct bgpq_expander *ex,
struct bgpq_request *req) struct request *req)
{ {
bgpq_expander_add_as(ex, as); bgpq_expander_add_as(ex, as);
return 1; return 1;
} }
struct bgpq_request *bgpq_pipeline(struct bgpq_expander *b, struct request *bgpq_pipeline(struct bgpq_expander *b,
int (*callback)(char *, struct bgpq_expander *b, struct bgpq_request *req), int (*callback)(char *, struct bgpq_expander *b, struct request *req),
void *udata, char *fmt, ...); void *udata, char *fmt, ...);
int bgpq_expand_irrd(struct bgpq_expander *b, int bgpq_expand_irrd(struct bgpq_expander *b,
int (*callback)(char*, struct bgpq_expander *b, struct bgpq_request *req), int (*callback)(char*, struct bgpq_expander *b, struct request *req),
void *udata, char *fmt, ...); void *udata, char *fmt, ...);
static int static int
bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b, bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
struct bgpq_request *req) struct request *req)
{ {
if (!strncasecmp(as, "AS-", 3) || strchr(as, '-') || strchr(as, ':')) { if (!strncasecmp(as, "AS-", 3) || strchr(as, '-') || strchr(as, ':')) {
struct sx_tentry tkey = { .text = as }; struct sx_tentry tkey = { .text = as };
@@ -300,7 +300,7 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
req->depth + 1 < b->maxdepth)) { req->depth + 1 < b->maxdepth)) {
bgpq_expander_add_already(b, as); bgpq_expander_add_already(b, as);
if (pipelining) { if (pipelining) {
struct bgpq_request *req1 = bgpq_pipeline(b, struct request *req1 = bgpq_pipeline(b,
bgpq_expanded_macro_limit, NULL, "!i%s\n", bgpq_expanded_macro_limit, NULL, "!i%s\n",
as); as);
req1->depth = req->depth + 1; req1->depth = req->depth + 1;
@@ -343,7 +343,7 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
static int static int
bgpq_expanded_prefix(char *as, struct bgpq_expander *ex, bgpq_expanded_prefix(char *as, struct bgpq_expander *ex,
struct bgpq_request *req __attribute__((unused))) struct request *req __attribute__((unused)))
{ {
char *d = strchr(as, '^'); char *d = strchr(as, '^');
@@ -357,7 +357,7 @@ bgpq_expanded_prefix(char *as, struct bgpq_expander *ex,
static int static int
bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander *ex, bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander *ex,
struct bgpq_request *req) struct request *req)
{ {
char *d = strchr(prefix, '^'); char *d = strchr(prefix, '^');
@@ -371,16 +371,16 @@ bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander *ex,
int bgpq_pipeline_dequeue(int fd, struct bgpq_expander *b); int bgpq_pipeline_dequeue(int fd, struct bgpq_expander *b);
static struct bgpq_request * static struct request *
bgpq_request_alloc(char *request, int (*callback)(char *, struct bgpq_expander *, request_alloc(char *request, int (*callback)(char *, struct bgpq_expander *,
struct bgpq_request *), void *udata) struct request *), void *udata)
{ {
struct bgpq_request *bp = malloc(sizeof(struct bgpq_request)); struct request *bp = malloc(sizeof(struct request));
if (!bp) if (!bp)
return NULL; return NULL;
memset(bp, 0, sizeof(struct bgpq_request)); memset(bp, 0, sizeof(struct request));
bp->request = strdup(request); bp->request = strdup(request);
bp->offset = 0; bp->offset = 0;
bp->size = strlen(bp->request); bp->size = strlen(bp->request);
@@ -391,7 +391,7 @@ bgpq_request_alloc(char *request, int (*callback)(char *, struct bgpq_expander *
} }
static void static void
bgpq_request_free(struct bgpq_request *req) request_free(struct request *req)
{ {
if (req->request) if (req->request)
free(req->request); free(req->request);
@@ -399,14 +399,14 @@ bgpq_request_free(struct bgpq_request *req)
free(req); free(req);
} }
struct bgpq_request * struct request *
bgpq_pipeline(struct bgpq_expander *b, bgpq_pipeline(struct bgpq_expander *b,
int (*callback)(char *, struct bgpq_expander *, struct bgpq_request *), int (*callback)(char *, struct bgpq_expander *, struct request *),
void *udata, char *fmt, ...) void *udata, char *fmt, ...)
{ {
char request[128]; char request[128];
int ret; int ret;
struct bgpq_request *bp = NULL; struct request *bp = NULL;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@@ -415,11 +415,11 @@ bgpq_pipeline(struct bgpq_expander *b,
SX_DEBUG(debug_expander,"expander: sending %s", request); SX_DEBUG(debug_expander,"expander: sending %s", request);
bp = bgpq_request_alloc(request, callback, udata); bp = request_alloc(request, callback, udata);
if (!bp) { if (!bp) {
sx_report(SX_FATAL,"Unable to allocate %lu bytes: %s\n", sx_report(SX_FATAL,"Unable to allocate %lu bytes: %s\n",
(unsigned long)sizeof(struct bgpq_request), (unsigned long)sizeof(struct request),
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
@@ -487,7 +487,7 @@ static void
bgpq_write(struct bgpq_expander *b) bgpq_write(struct bgpq_expander *b)
{ {
while(!STAILQ_EMPTY(&b->wq)) { while(!STAILQ_EMPTY(&b->wq)) {
struct bgpq_request *req = STAILQ_FIRST(&b->wq); struct 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); req->size-req->offset);
@@ -555,7 +555,7 @@ bgpq_read(struct bgpq_expander *b)
while(!STAILQ_EMPTY(&b->rq)) { while(!STAILQ_EMPTY(&b->rq)) {
int ret = 0; int ret = 0;
char *cres; char *cres;
struct bgpq_request *req = STAILQ_FIRST(&b->rq); struct request *req = STAILQ_FIRST(&b->rq);
SX_DEBUG(debug_expander > 2, "waiting for answer to %s," SX_DEBUG(debug_expander > 2, "waiting for answer to %s,"
"init %i '%.*s'\n", req->request, off, off, response); "init %i '%.*s'\n", req->request, off, off, response);
@@ -725,7 +725,7 @@ have3:
STAILQ_REMOVE_HEAD(&b->rq, next); STAILQ_REMOVE_HEAD(&b->rq, next);
b->piped--; b->piped--;
bgpq_request_free(req); request_free(req);
} }
return 0; return 0;
@@ -733,20 +733,20 @@ have3:
int int
bgpq_expand_irrd(struct bgpq_expander *b, bgpq_expand_irrd(struct bgpq_expander *b,
int (*callback)(char *, struct bgpq_expander *, struct bgpq_request *), int (*callback)(char *, struct bgpq_expander *, struct request *),
void *udata, char *fmt, ...) void *udata, char *fmt, ...)
{ {
char request[128], response[128]; char request[128], response[128];
va_list ap; va_list ap;
ssize_t ret; ssize_t ret;
int off = 0; int off = 0;
struct bgpq_request *req; struct request *req;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(request, sizeof(request), fmt, ap); vsnprintf(request, sizeof(request), fmt, ap);
va_end(ap); va_end(ap);
req = bgpq_request_alloc(request, callback, udata); req = request_alloc(request, callback, udata);
SX_DEBUG(debug_expander, "expander sending: %s", request); SX_DEBUG(debug_expander, "expander sending: %s", request);
@@ -872,7 +872,7 @@ have3:
sx_report(SX_ERROR,"Wrong reply: %s\n", response); sx_report(SX_ERROR,"Wrong reply: %s\n", response);
exit(0); exit(0);
} }
bgpq_request_free(req); request_free(req);
return 0; return 0;
} }
@@ -881,7 +881,7 @@ int
bgpq_expand(struct bgpq_expander *b) bgpq_expand(struct bgpq_expander *b)
{ {
int fd = -1, err, ret, aquery = 0; int fd = -1, err, ret, aquery = 0;
struct sx_slentry *mc; struct slentry *mc;
struct addrinfo hints, *res = NULL, *rp; struct addrinfo hints, *res = NULL, *rp;
struct linger sl; struct linger sl;
@@ -1162,14 +1162,14 @@ expander_freeall(struct bgpq_expander *expander) {
struct sx_tentry *var, *nxt; struct sx_tentry *var, *nxt;
while (!STAILQ_EMPTY(&expander->macroses)) { while (!STAILQ_EMPTY(&expander->macroses)) {
struct sx_slentry *n1 = STAILQ_FIRST(&expander->macroses); struct slentry *n1 = STAILQ_FIRST(&expander->macroses);
STAILQ_REMOVE_HEAD(&expander->macroses, entries); STAILQ_REMOVE_HEAD(&expander->macroses, entries);
free(n1->text); free(n1->text);
free(n1); free(n1);
} }
while (!STAILQ_EMPTY(&expander->rsets)) { while (!STAILQ_EMPTY(&expander->rsets)) {
struct sx_slentry *n1 = STAILQ_FIRST(&expander->rsets); struct slentry *n1 = STAILQ_FIRST(&expander->rsets);
STAILQ_REMOVE_HEAD(&expander->rsets, entries); STAILQ_REMOVE_HEAD(&expander->rsets, entries);
free(n1->text); free(n1->text);
free(n1); free(n1);

View File

@@ -29,19 +29,19 @@
#include "sx_prefix.h" #include "sx_prefix.h"
struct sx_slentry { struct slentry {
STAILQ_ENTRY(sx_slentry) entries; STAILQ_ENTRY(slentry) entries;
char* text; char *text;
}; };
struct sx_slentry* sx_slentry_new(char* text); struct slentry *sx_slentry_new(char *text);
struct sx_tentry { struct sx_tentry {
RB_ENTRY(sx_tentry) entries; RB_ENTRY(sx_tentry) entries;
char* text; char *text;
}; };
struct sx_tentry* sx_tentry_new(char* text); struct sx_tentry *sx_tentry_new(char *text);
typedef enum { typedef enum {
V_CISCO = 0, V_CISCO = 0,
@@ -70,42 +70,42 @@ typedef enum {
struct bgpq_expander; struct bgpq_expander;
struct bgpq_request { struct request {
STAILQ_ENTRY(bgpq_request) next; STAILQ_ENTRY(request) next;
char *request; char *request;
int size, offset; int size, offset;
void *udata; void *udata;
unsigned int depth; unsigned int depth;
int (*callback)(char *, struct bgpq_expander *, int (*callback)(char *, struct bgpq_expander *,
struct bgpq_request *); struct request *);
}; };
struct bgpq_expander { struct bgpq_expander {
struct sx_radix_tree *tree; struct sx_radix_tree *tree;
STAILQ_HEAD(sx_slentries, sx_slentry) macroses, rsets; int family;
RB_HEAD(tentree, sx_tentry) already, stoplist; char *sources;
int family; uint32_t asnumber;
char *sources; int aswidth;
uint32_t asnumber; char *name;
int aswidth; bgpq_vendor_t vendor;
char *name; bgpq_gen_t generation;
bgpq_vendor_t vendor; int identify;
bgpq_gen_t generation; int sequence;
int identify; unsigned int maxdepth;
int sequence; unsigned int cdepth;
unsigned int maxdepth; int validate_asns;
unsigned int cdepth; struct bgpq_prequest *firstpipe, *lastpipe;
int validate_asns; int piped;
unsigned char *asn32s[65536]; char *match;
struct bgpq_prequest *firstpipe, *lastpipe; char *server;
int piped; char *port;
char *match; char *format;
char *server; unsigned int maxlen;
char *port; int fd;
char *format; unsigned char *asn32s[65536];
unsigned int maxlen; STAILQ_HEAD(requests, request) wq, rq;
STAILQ_HEAD(bgpq_requests, bgpq_request) wq, rq; STAILQ_HEAD(slentries, slentry) macroses, rsets;
int fd; RB_HEAD(tentree, sx_tentry) already, stoplist;
}; };
int bgpq_expander_init(struct bgpq_expander *b, int af); int bgpq_expander_init(struct bgpq_expander *b, int af);
@@ -134,5 +134,5 @@ void expander_freeall(struct bgpq_expander *expander);
int sx_maxsockbuf(int s, int dir); int sx_maxsockbuf(int s, int dir);
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY
size_t strlcpy(char* dst, const char* src, size_t size); size_t strlcpy(char *dst, const char *src, size_t size);
#endif #endif

View File

@@ -31,15 +31,15 @@
#include "extern.h" #include "extern.h"
struct sx_slentry * struct slentry *
sx_slentry_new(char *t) sx_slentry_new(char *t)
{ {
struct sx_slentry *e = malloc(sizeof(struct sx_slentry)); struct slentry *e = malloc(sizeof(struct slentry));
if (!e) if (!e)
return NULL; return NULL;
memset(e, 0, sizeof(struct sx_slentry)); memset(e, 0, sizeof(struct slentry));
e->text = strdup(t); e->text = strdup(t);