-/* $OpenBSD: bgpd.h,v 1.479 2024/01/08 15:08:34 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.480 2024/01/10 13:31:09 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
const char *log_rd(uint64_t);
const char *log_ext_subtype(int, uint8_t);
const char *log_reason(const char *);
+const char *log_roa(struct roa *);
+const char *log_aspa(struct aspa_set *);
const char *log_rtr_error(enum rtr_error);
const char *log_policy(enum role);
int aspath_snprint(char *, size_t, void *, uint16_t);
-/* $OpenBSD: printconf.c,v 1.168 2023/08/16 08:26:35 claudio Exp $ */
+/* $OpenBSD: printconf.c,v 1.169 2024/01/10 13:31:09 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
print_roa(struct roa_tree *r)
{
struct roa *roa;
- struct bgpd_addr addr;
if (RB_EMPTY(r))
return;
printf("roa-set {");
RB_FOREACH(roa, roa_tree, r) {
- printf("\n\t");
- addr.aid = roa->aid;
- addr.v6 = roa->prefix.inet6;
- printf("%s/%u", log_addr(&addr), roa->prefixlen);
- if (roa->prefixlen != roa->maxlen)
- printf(" maxlen %u", roa->maxlen);
- printf(" source-as %u", roa->asnum);
- if (roa->expires != 0)
- printf(" expires %lld", (long long)roa->expires);
+ printf("\n\t%s", log_roa(roa));
}
printf("\n}\n\n");
}
print_aspa(struct aspa_tree *a)
{
struct aspa_set *aspa;
- uint32_t i;
if (RB_EMPTY(a))
return;
printf("aspa-set {");
RB_FOREACH(aspa, aspa_tree, a) {
- printf("\n\t");
- printf("customer-as %s", log_as(aspa->as));
- if (aspa->expires != 0)
- printf(" expires %lld", (long long)aspa->expires);
- printf(" provider-as { ");
- for (i = 0; i < aspa->num; i++)
- printf("%s ", log_as(aspa->tas[i]));
- printf("}");
+ printf("\n\t%s", log_aspa(aspa));
}
printf("\n}\n\n");
}
-/* $OpenBSD: util.c,v 1.77 2023/04/17 08:02:21 claudio Exp $ */
+/* $OpenBSD: util.c,v 1.78 2024/01/10 13:31:09 claudio Exp $ */
/*
* Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
return buf;
}
+static const char *
+log_expires(time_t expires)
+{
+ static char buf[32];
+
+ buf[0] = '\0';
+ if (expires != 0)
+ snprintf(buf, sizeof(buf), " expires %lld", (long long)expires);
+ return buf;
+}
+
+const char *
+log_roa(struct roa *roa)
+{
+ static char buf[256];
+ struct bgpd_addr addr = { .aid = roa->aid, .v6 = roa->prefix.inet6 };
+ char maxbuf[32];
+
+ maxbuf[0] = '\0';
+ if (roa->prefixlen != roa->maxlen)
+ snprintf(maxbuf, sizeof(maxbuf), " maxlen %u", roa->maxlen);
+ snprintf(buf, sizeof(buf), "%s/%u%s source-as %u%s", log_addr(&addr),
+ roa->prefixlen, maxbuf, roa->asnum, log_expires(roa->expires));
+ return buf;
+}
+
+const char *
+log_aspa(struct aspa_set *aspa)
+{
+ static char errbuf[256];
+ static char *buf;
+ static size_t len;
+ char asbuf[16];
+ size_t needed;
+ uint32_t i;
+
+ /* include enough space for header and trailer */
+ if ((uint64_t)aspa->num > (SIZE_MAX / sizeof(asbuf) - 72))
+ goto fail;
+ needed = aspa->num * sizeof(asbuf) + 72;
+ if (needed > len) {
+ char *nbuf;
+
+ if ((nbuf = realloc(buf, needed)) == NULL)
+ goto fail;
+ len = needed;
+ buf = nbuf;
+ }
+
+ snprintf(buf, len, "customer-as %s%s provider-as { ",
+ log_as(aspa->as), log_expires(aspa->expires));
+
+ for (i = 0; i < aspa->num; i++) {
+ snprintf(asbuf, sizeof(asbuf), "%s ", log_as(aspa->tas[i]));
+ if (strlcat(buf, asbuf, len) >= len)
+ goto fail;
+ }
+ if (strlcat(buf, "}", len) >= len)
+ goto fail;
+ return buf;
+
+ fail:
+ free(buf);
+ buf = NULL;
+ len = 0;
+ snprintf(errbuf, sizeof(errbuf), "customer-as %s%s provider-as { ... }",
+ log_as(aspa->as), log_expires(aspa->expires));
+ return errbuf;
+}
+
const char *
log_rtr_error(enum rtr_error err)
{