Rework where newlines are inserted

This commit is contained in:
Job Snijders
2021-08-18 16:56:13 +00:00
parent 1f7572c2f1
commit bf5f10def9

View File

@@ -31,17 +31,18 @@
#include <sys/select.h>
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <err.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <string.h>
#include <strings.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "extern.h"
@@ -300,9 +301,9 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
bgpq_expander_add_already(b, as);
if (pipelining) {
struct bgpq_request *req1 = bgpq_pipeline(b,
bgpq_expanded_macro_limit, NULL, "!i%s\n",
as);
req1->depth = req->depth+1;
bgpq_expanded_macro_limit, NULL, "!i%s",
as);
req1->depth = req->depth + 1;
} else {
b->cdepth++;
bgpq_expand_irrd(b, bgpq_expanded_macro_limit,
@@ -724,7 +725,7 @@ bgpq_expand_irrd(struct bgpq_expander *b,
{
char request[128], response[128];
va_list ap;
size_t ret;
ssize_t ret;
int off = 0;
struct bgpq_request *req;
@@ -736,12 +737,13 @@ bgpq_expand_irrd(struct bgpq_expander *b,
SX_DEBUG(debug_expander, "expander: sending '%s'\n", request);
ret=write(b->fd, request, strlen(request));
if (ret != strlen(request)) {
sx_report(SX_FATAL,"Partial write to IRRd, only %lu bytes "
"written: %s\n", ret, strerror(errno));
exit(1);
}
if ((ret = write(b->fd, request, strlen(request)) == 0) || ret == -1)
err(1, "write");
// push the button by sending a newline
if ((ret = write(b->fd, "\n", 1) == 0) || ret == -1)
err(1, "write");
memset(response, 0, sizeof(response));
repeat:
@@ -935,7 +937,7 @@ bgpq_expand(struct bgpq_expander *b)
b->fd = fd;
SX_DEBUG(debug_expander, "Sending '!!' to server to request for the"
"connection to remain open\n");
" connection to remain open\n");
if ((ret = write(fd, "!!\n", 3)) != 3) {
sx_report(SX_ERROR, "Partial write of multiple command mode "
"to IRRd: %i bytes, %s\n", ret, strerror(errno));
@@ -1029,20 +1031,20 @@ bgpq_expand(struct bgpq_expander *b)
if (!b->maxdepth && RB_EMPTY(&b->stoplist)) {
if (aquery)
bgpq_expand_irrd(b, bgpq_expanded_prefix, b,
"!a%s%s\n",
"!a%s%s",
b->family == AF_INET ? "4" : "6",
mc->text);
else
bgpq_expand_irrd(b, bgpq_expanded_macro, b,
"!i%s,1\n", mc->text);
"!i%s,1", mc->text);
} else {
bgpq_expander_add_already(b, mc->text);
if (pipelining)
bgpq_pipeline(b, bgpq_expanded_macro_limit,
NULL, "!i%s\n", mc->text);
NULL, "!i%s", mc->text);
else
bgpq_expand_irrd(b, bgpq_expanded_macro_limit,
NULL, "!i%s\n", mc->text);
NULL, "!i%s", mc->text);
}
}
@@ -1058,10 +1060,10 @@ bgpq_expand(struct bgpq_expander *b)
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);
NULL, "!i%s,1", mc->text);
else
bgpq_expand_irrd(b, bgpq_expanded_v6prefix,
NULL, "!i%s,1\n", mc->text);
NULL, "!i%s,1", mc->text);
}
for (k=0; k < sizeof(b->asn32s) / sizeof(unsigned char *); k++) {
if (!b->asn32s[k])
@@ -1072,18 +1074,18 @@ bgpq_expand(struct bgpq_expander *b)
if (b->family == AF_INET6) {
if (!pipelining) {
bgpq_expand_irrd(b, bgpq_expanded_v6prefix,
NULL, "!6as%" PRIu32 "\n", ( k << 16) + i * 8 + j);
NULL, "!6as%" PRIu32, ( k << 16) + i * 8 + j);
} else {
bgpq_pipeline(b, bgpq_expanded_v6prefix,
NULL, "!6as%" PRIu32 "\n", (k << 16) + i * 8 + j);
NULL, "!6as%" PRIu32, (k << 16) + i * 8 + j);
}
} else {
if (!pipelining) {
bgpq_expand_irrd(b, bgpq_expanded_prefix,
NULL, "!gas%" PRIu32 "\n", (k << 16) + i * 8 + j);
NULL, "!gas%" PRIu32, (k << 16) + i * 8 + j);
} else {
bgpq_pipeline(b, bgpq_expanded_prefix,
NULL, "!gas%" PRIu32 "\n", ( k<< 16) + i* 8 + j);
NULL, "!gas%" PRIu32, ( k<< 16) + i* 8 + j);
}
}
}