diff options
Diffstat (limited to 'usr.sbin/bgpctl')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 104 | ||||
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.h | 18 | ||||
-rw-r--r-- | usr.sbin/bgpctl/mrtparser.c | 159 | ||||
-rw-r--r-- | usr.sbin/bgpctl/mrtparser.h | 48 | ||||
-rw-r--r-- | usr.sbin/bgpctl/output.c | 76 | ||||
-rw-r--r-- | usr.sbin/bgpctl/output_json.c | 4 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.c | 46 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.h | 14 |
8 files changed, 235 insertions, 234 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 619e5b52965..b5896ae6866 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.274 2022/02/04 12:01:33 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.275 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -54,9 +54,9 @@ void show_mrt_dump(struct mrt_rib *, struct mrt_peer *, void *); void network_mrt_dump(struct mrt_rib *, struct mrt_peer *, void *); void show_mrt_state(struct mrt_bgp_state *, void *); void show_mrt_msg(struct mrt_bgp_msg *, void *); -const char *msg_type(u_int8_t); +const char *msg_type(uint8_t); void network_bulk(struct parse_result *); -int match_aspath(void *, u_int16_t, struct filter_as *); +int match_aspath(void *, uint16_t, struct filter_as *); struct imsgbuf *ibuf; struct mrt_parser show_mrt = { show_mrt_dump, show_mrt_state, show_mrt_msg }; @@ -624,7 +624,7 @@ fmt_monotime(time_t t) } const char * -fmt_fib_flags(u_int16_t flags) +fmt_fib_flags(uint16_t flags) { static char buf[8]; @@ -665,7 +665,7 @@ fmt_fib_flags(u_int16_t flags) } const char * -fmt_origin(u_int8_t origin, int sum) +fmt_origin(uint8_t origin, int sum) { switch (origin) { case ORIGIN_IGP: @@ -680,7 +680,7 @@ fmt_origin(u_int8_t origin, int sum) } const char * -fmt_flags(u_int8_t flags, int sum) +fmt_flags(uint8_t flags, int sum) { static char buf[80]; char flagstr[5]; @@ -723,7 +723,7 @@ fmt_flags(u_int8_t flags, int sum) } const char * -fmt_ovs(u_int8_t validation_state, int sum) +fmt_ovs(uint8_t validation_state, int sum) { switch (validation_state) { case ROA_INVALID: @@ -747,7 +747,7 @@ fmt_mem(long long num) } const char * -fmt_errstr(u_int8_t errcode, u_int8_t subcode) +fmt_errstr(uint8_t errcode, uint8_t subcode) { static char errbuf[256]; const char *errstr = NULL; @@ -814,7 +814,7 @@ fmt_errstr(u_int8_t errcode, u_int8_t subcode) } const char * -fmt_attr(u_int8_t type, int flags) +fmt_attr(uint8_t type, int flags) { #define CHECK_FLAGS(s, t, m) \ if (((s) & ~(ATTR_DEFMASK | (m))) != (t)) pflags = 1 @@ -909,7 +909,7 @@ fmt_attr(u_int8_t type, int flags) } const char * -fmt_community(u_int16_t a, u_int16_t v) +fmt_community(uint16_t a, uint16_t v) { static char buf[12]; @@ -936,7 +936,7 @@ fmt_community(u_int16_t a, u_int16_t v) } const char * -fmt_large_community(u_int32_t d1, u_int32_t d2, u_int32_t d3) +fmt_large_community(uint32_t d1, uint32_t d2, uint32_t d3) { static char buf[33]; @@ -945,14 +945,14 @@ fmt_large_community(u_int32_t d1, u_int32_t d2, u_int32_t d3) } const char * -fmt_ext_community(u_int8_t *data) +fmt_ext_community(uint8_t *data) { static char buf[32]; - u_int64_t ext; + uint64_t ext; struct in_addr ip; - u_int32_t as4, u32; - u_int16_t as2, u16; - u_int8_t type, subtype; + uint32_t as4, u32; + uint16_t as2, u16; + uint8_t type, subtype; type = data[0]; subtype = data[1]; @@ -1057,7 +1057,7 @@ network_bulk(struct parse_result *res) char *line = NULL; size_t linesize = 0; ssize_t linelen; - u_int8_t len; + uint8_t len; FILE *f; if ((f = fdopen(STDIN_FILENO, "r")) == NULL) @@ -1108,7 +1108,7 @@ show_mrt_dump_neighbors(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) { struct mrt_peer_entry *p; struct in_addr ina; - u_int16_t i; + uint16_t i; ina.s_addr = htonl(mp->bgp_id); printf("view: %s BGP ID: %s Number of peers: %u\n\n", @@ -1132,7 +1132,7 @@ show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) struct ctl_show_rib_request *req = arg; struct mrt_rib_entry *mre; time_t now; - u_int16_t i, j; + uint16_t i, j; memset(&res, 0, sizeof(res)); res.flags = req->flags; @@ -1214,7 +1214,7 @@ network_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) struct mrt_rib_entry *mre; struct ibuf *msg; time_t now; - u_int16_t i, j; + uint16_t i, j; /* can't announce more than one path so ignore add-path */ if (mr->add_path) @@ -1315,10 +1315,10 @@ show_mrt_state(struct mrt_bgp_state *ms, void *arg) } static void -print_afi(u_char *p, u_int8_t len) +print_afi(u_char *p, uint8_t len) { - u_int16_t afi; - u_int8_t safi, aid; + uint16_t afi; + uint8_t safi, aid; if (len != 4) { printf("bad length"); @@ -1340,7 +1340,7 @@ print_afi(u_char *p, u_int8_t len) } static void -print_capability(u_int8_t capa_code, u_char *p, u_int8_t len) +print_capability(uint8_t capa_code, u_char *p, uint8_t len) { switch (capa_code) { case CAPA_MP: @@ -1357,7 +1357,7 @@ print_capability(u_int8_t capa_code, u_char *p, u_int8_t len) case CAPA_AS4BYTE: printf("4-byte AS num capability: "); if (len == 4) { - u_int32_t as; + uint32_t as; memcpy(&as, p, sizeof(as)); as = ntohl(as); printf("AS %u", as); @@ -1378,7 +1378,7 @@ print_capability(u_int8_t capa_code, u_char *p, u_int8_t len) } static void -print_notification(u_int8_t errcode, u_int8_t subcode) +print_notification(uint8_t errcode, uint8_t subcode) { const char *suberrname = NULL; int uk = 0; @@ -1435,10 +1435,10 @@ print_notification(u_int8_t errcode, u_int8_t subcode) } static int -show_mrt_capabilities(u_char *p, u_int16_t len) +show_mrt_capabilities(u_char *p, uint16_t len) { - u_int16_t totlen = len; - u_int8_t capa_code, capa_len; + uint16_t totlen = len; + uint8_t capa_code, capa_len; while (len > 2) { memcpy(&capa_code, p, sizeof(capa_code)); @@ -1465,10 +1465,10 @@ show_mrt_capabilities(u_char *p, u_int16_t len) } static void -show_mrt_open(u_char *p, u_int16_t len) +show_mrt_open(u_char *p, uint16_t len) { - u_int8_t version, optparamlen; - u_int16_t short_as, holdtime; + uint16_t short_as, holdtime; + uint8_t version, optparamlen; struct in_addr bgpid; /* length check up to optparamlen already happened */ @@ -1498,7 +1498,7 @@ show_mrt_open(u_char *p, u_int16_t len) return; } while (len > 2) { - u_int8_t op_type, op_len; + uint8_t op_type, op_len; int r; memcpy(&op_type, p, sizeof(op_type)); @@ -1532,10 +1532,10 @@ show_mrt_open(u_char *p, u_int16_t len) } static void -show_mrt_notification(u_char *p, u_int16_t len) +show_mrt_notification(u_char *p, uint16_t len) { - u_int16_t i; - u_int8_t errcode, subcode; + uint16_t i; + uint8_t errcode, subcode; size_t reason_len; char reason[REASON_LEN]; @@ -1595,13 +1595,13 @@ show_mrt_notification(u_char *p, u_int16_t len) /* XXX this function does not handle JSON output */ static void -show_mrt_update(u_char *p, u_int16_t len, int reqflags, int addpath) +show_mrt_update(u_char *p, uint16_t len, int reqflags, int addpath) { struct bgpd_addr prefix; int pos; - u_int32_t pathid; - u_int16_t wlen, alen; - u_int8_t prefixlen; + uint32_t pathid; + uint16_t wlen, alen; + uint8_t prefixlen; if (len < sizeof(wlen)) { printf("bad length"); @@ -1660,8 +1660,8 @@ show_mrt_update(u_char *p, u_int16_t len, int reqflags, int addpath) printf("\n"); /* alen attributes here */ while (alen > 3) { - u_int8_t flags; - u_int16_t attrlen; + uint8_t flags; + uint16_t attrlen; flags = p[0]; /* type = p[1]; */ @@ -1714,12 +1714,12 @@ show_mrt_update(u_char *p, u_int16_t len, int reqflags, int addpath) void show_mrt_msg(struct mrt_bgp_msg *mm, void *arg) { - static const u_int8_t marker[MSGSIZE_HEADER_MARKER] = { + static const uint8_t marker[MSGSIZE_HEADER_MARKER] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; u_char *p; - u_int16_t len; - u_int8_t type; + uint16_t len; + uint8_t type; struct ctl_show_rib_request *req = arg; printf("%s %s[%u] -> ", fmt_time(&mm->time), @@ -1802,7 +1802,7 @@ show_mrt_msg(struct mrt_bgp_msg *mm, void *arg) } const char * -msg_type(u_int8_t type) +msg_type(uint8_t type) { if (type >= sizeof(msgtypenames)/sizeof(msgtypenames[0])) return "BAD"; @@ -1810,13 +1810,13 @@ msg_type(u_int8_t type) } int -match_aspath(void *data, u_int16_t len, struct filter_as *f) +match_aspath(void *data, uint16_t len, struct filter_as *f) { - u_int8_t *seg; + uint8_t *seg; int final; - u_int16_t seg_size; - u_int8_t i, seg_len; - u_int32_t as = 0; + uint16_t seg_size; + uint8_t i, seg_len; + uint32_t as = 0; if (f->type == AS_EMPTY) { if (len == 0) @@ -1838,7 +1838,7 @@ match_aspath(void *data, u_int16_t len, struct filter_as *f) for (; len >= 6; len -= seg_size, seg += seg_size) { seg_len = seg[1]; - seg_size = 2 + sizeof(u_int32_t) * seg_len; + seg_size = 2 + sizeof(uint32_t) * seg_len; final = (len == seg_size); diff --git a/usr.sbin/bgpctl/bgpctl.h b/usr.sbin/bgpctl/bgpctl.h index 6ccdf4ba35d..5486cc720c9 100644 --- a/usr.sbin/bgpctl/bgpctl.h +++ b/usr.sbin/bgpctl/bgpctl.h @@ -45,15 +45,15 @@ time_t get_monotime(time_t); char *fmt_peer(const char *, const struct bgpd_addr *, int); const char *fmt_timeframe(time_t); const char *fmt_monotime(time_t); -const char *fmt_fib_flags(u_int16_t); -const char *fmt_origin(u_int8_t, int); -const char *fmt_flags(u_int8_t, int); -const char *fmt_ovs(u_int8_t, int); +const char *fmt_fib_flags(uint16_t); +const char *fmt_origin(uint8_t, int); +const char *fmt_flags(uint8_t, int); +const char *fmt_ovs(uint8_t, int); const char *fmt_auth_method(enum auth_method); const char *fmt_mem(long long); -const char *fmt_errstr(u_int8_t, u_int8_t); -const char *fmt_attr(u_int8_t, int); -const char *fmt_community(u_int16_t, u_int16_t); -const char *fmt_large_community(u_int32_t, u_int32_t, u_int32_t); -const char *fmt_ext_community(u_int8_t *); +const char *fmt_errstr(uint8_t, uint8_t); +const char *fmt_attr(uint8_t, int); +const char *fmt_community(uint16_t, uint16_t); +const char *fmt_large_community(uint32_t, uint32_t, uint32_t); +const char *fmt_ext_community(uint8_t *); const char *fmt_set_type(struct ctl_show_set *); diff --git a/usr.sbin/bgpctl/mrtparser.c b/usr.sbin/bgpctl/mrtparser.c index 5a0d39eb533..9e77739c196 100644 --- a/usr.sbin/bgpctl/mrtparser.c +++ b/usr.sbin/bgpctl/mrtparser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrtparser.c,v 1.16 2021/09/22 18:17:49 claudio Exp $ */ +/* $OpenBSD: mrtparser.c,v 1.17 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2011 Claudio Jeker <claudio@openbsd.org> * @@ -38,18 +38,17 @@ int mrt_parse_dump(struct mrt_hdr *, void *, struct mrt_peer **, struct mrt_rib **); int mrt_parse_dump_mp(struct mrt_hdr *, void *, struct mrt_peer **, struct mrt_rib **, int); -int mrt_extract_attr(struct mrt_rib_entry *, u_char *, int, u_int8_t, - int); +int mrt_extract_attr(struct mrt_rib_entry *, u_char *, int, uint8_t, int); void mrt_free_peers(struct mrt_peer *); void mrt_free_rib(struct mrt_rib *); void mrt_free_bgp_state(struct mrt_bgp_state *); void mrt_free_bgp_msg(struct mrt_bgp_msg *); -u_char *mrt_aspath_inflate(void *, u_int16_t, u_int16_t *); -int mrt_extract_addr(void *, u_int, struct bgpd_addr *, u_int8_t); -int mrt_extract_prefix(void *, u_int, u_int8_t, struct bgpd_addr *, - u_int8_t *, int); +u_char *mrt_aspath_inflate(void *, uint16_t, uint16_t *); +int mrt_extract_addr(void *, u_int, struct bgpd_addr *, uint8_t); +int mrt_extract_prefix(void *, u_int, uint8_t, struct bgpd_addr *, + uint8_t *, int); struct mrt_bgp_state *mrt_parse_state(struct mrt_hdr *, void *, int); struct mrt_bgp_msg *mrt_parse_msg(struct mrt_hdr *, void *, int); @@ -267,9 +266,9 @@ mrt_parse_v2_peer(struct mrt_hdr *hdr, void *msg) { struct mrt_peer_entry *peers = NULL; struct mrt_peer *p; - u_int8_t *b = msg; - u_int32_t bid, as4; - u_int16_t cnt, i, as2; + uint8_t *b = msg; + uint32_t bid, as4; + uint16_t cnt, i, as2; u_int len = ntohl(hdr->length); if (len < 8) /* min msg size */ @@ -317,9 +316,9 @@ mrt_parse_v2_peer(struct mrt_hdr *hdr, void *msg) if ((peers = calloc(cnt, sizeof(struct mrt_peer_entry))) == NULL) err(1, "calloc"); for (i = 0; i < cnt; i++) { - u_int8_t type; + uint8_t type; - if (len < sizeof(u_int8_t) + sizeof(u_int32_t)) + if (len < sizeof(uint8_t) + sizeof(uint32_t)) goto fail; type = *b++; len -= 1; @@ -369,11 +368,11 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, void *msg, int verbose) { struct mrt_rib_entry *entries = NULL; struct mrt_rib *r; - u_int8_t *b = msg; + uint8_t *b = msg; u_int len = ntohl(hdr->length); - u_int32_t snum, path_id = 0; - u_int16_t cnt, i, afi; - u_int8_t safi, aid; + uint32_t snum, path_id = 0; + uint16_t cnt, i, afi; + uint8_t safi, aid; int ret; if (len < sizeof(snum) + 1) @@ -464,9 +463,9 @@ mrt_parse_v2_rib(struct mrt_hdr *hdr, void *msg, int verbose) if ((entries = calloc(cnt, sizeof(struct mrt_rib_entry))) == NULL) err(1, "calloc"); for (i = 0; i < cnt; i++) { - u_int32_t otm; - u_int16_t pix, alen; - if (len < 2 * sizeof(u_int16_t) + sizeof(u_int32_t)) + uint32_t otm; + uint16_t pix, alen; + if (len < 2 * sizeof(uint16_t) + sizeof(uint32_t)) goto fail; /* peer index */ memcpy(&pix, b, sizeof(pix)); @@ -520,9 +519,9 @@ mrt_parse_dump(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, struct mrt_peer *p; struct mrt_rib *r; struct mrt_rib_entry *re; - u_int8_t *b = msg; + uint8_t *b = msg; u_int len = ntohl(hdr->length); - u_int16_t asnum, alen; + uint16_t asnum, alen; if (*pp == NULL) { *pp = calloc(1, sizeof(struct mrt_peer)); @@ -544,15 +543,15 @@ mrt_parse_dump(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, r->nentries = 1; r->entries = re; - if (len < 2 * sizeof(u_int16_t)) + if (len < 2 * sizeof(uint16_t)) goto fail; /* view */ - b += sizeof(u_int16_t); - len -= sizeof(u_int16_t); + b += sizeof(uint16_t); + len -= sizeof(uint16_t); /* seqnum */ - memcpy(&r->seqnum, b, sizeof(u_int16_t)); - b += sizeof(u_int16_t); - len -= sizeof(u_int16_t); + memcpy(&r->seqnum, b, sizeof(uint16_t)); + b += sizeof(uint16_t); + len -= sizeof(uint16_t); r->seqnum = ntohs(r->seqnum); switch (ntohs(hdr->subtype)) { @@ -569,7 +568,7 @@ mrt_parse_dump(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, len -= sizeof(struct in6_addr); break; } - if (len < 2 * sizeof(u_int32_t) + 2 * sizeof(u_int16_t) + 2) + if (len < 2 * sizeof(uint32_t) + 2 * sizeof(uint16_t) + 2) goto fail; r->prefixlen = *b++; len -= 1; @@ -577,9 +576,9 @@ mrt_parse_dump(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, b += 1; len -= 1; /* originated */ - memcpy(&re->originated, b, sizeof(u_int32_t)); - b += sizeof(u_int32_t); - len -= sizeof(u_int32_t); + memcpy(&re->originated, b, sizeof(uint32_t)); + b += sizeof(uint32_t); + len -= sizeof(uint32_t); re->originated = ntohl(re->originated); /* peer ip */ switch (ntohs(hdr->subtype)) { @@ -627,16 +626,16 @@ mrt_parse_dump_mp(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, struct mrt_peer *p; struct mrt_rib *r; struct mrt_rib_entry *re; - u_int8_t *b = msg; + uint8_t *b = msg; u_int len = ntohl(hdr->length); - u_int16_t asnum, alen, afi; - u_int8_t safi, nhlen, aid; + uint16_t asnum, alen, afi; + uint8_t safi, nhlen, aid; int ret; /* just ignore the microsec field for _ET header for now */ if (ntohs(hdr->type) == MSG_PROTOCOL_BGP4MP_ET) { - b = (char *)b + sizeof(u_int32_t); - len -= sizeof(u_int32_t); + b = (char *)b + sizeof(uint32_t); + len -= sizeof(uint32_t); } if (*pp == NULL) { @@ -659,19 +658,19 @@ mrt_parse_dump_mp(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, r->nentries = 1; r->entries = re; - if (len < 4 * sizeof(u_int16_t)) + if (len < 4 * sizeof(uint16_t)) goto fail; /* source AS */ - b += sizeof(u_int16_t); - len -= sizeof(u_int16_t); + b += sizeof(uint16_t); + len -= sizeof(uint16_t); /* dest AS */ memcpy(&asnum, b, sizeof(asnum)); b += sizeof(asnum); len -= sizeof(asnum); p->peers->asnum = ntohs(asnum); /* iface index */ - b += sizeof(u_int16_t); - len -= sizeof(u_int16_t); + b += sizeof(uint16_t); + len -= sizeof(uint16_t); /* afi */ memcpy(&afi, b, sizeof(afi)); b += sizeof(afi); @@ -706,15 +705,15 @@ mrt_parse_dump_mp(struct mrt_hdr *hdr, void *msg, struct mrt_peer **pp, break; } - if (len < 2 * sizeof(u_int16_t) + 2 * sizeof(u_int32_t)) + if (len < 2 * sizeof(uint16_t) + 2 * sizeof(uint32_t)) goto fail; /* view + status */ - b += 2 * sizeof(u_int16_t); - len -= 2 * sizeof(u_int16_t); + b += 2 * sizeof(uint16_t); + len -= 2 * sizeof(uint16_t); /* originated */ - memcpy(&re->originated, b, sizeof(u_int32_t)); - b += sizeof(u_int32_t); - len -= sizeof(u_int32_t); + memcpy(&re->originated, b, sizeof(uint32_t)); + b += sizeof(uint32_t); + len -= sizeof(uint32_t); re->originated = ntohl(re->originated); /* afi */ @@ -770,13 +769,13 @@ fail: } int -mrt_extract_attr(struct mrt_rib_entry *re, u_char *a, int alen, u_int8_t aid, +mrt_extract_attr(struct mrt_rib_entry *re, u_char *a, int alen, uint8_t aid, int as4) { struct mrt_attr *ap; - u_int32_t tmp; - u_int16_t attr_len; - u_int8_t type, flags, *attr; + uint32_t tmp; + uint16_t attr_len; + uint8_t type, flags, *attr; do { if (alen < 3) @@ -864,21 +863,21 @@ mrt_extract_attr(struct mrt_rib_entry *re, u_char *a, int alen, u_int8_t aid, sizeof(struct in6_addr)); break; case AID_VPN_IPv4: - if (attr_len < sizeof(u_int64_t) + + if (attr_len < sizeof(uint64_t) + sizeof(struct in_addr)) return (-1); re->nexthop.aid = aid; - memcpy(&tmp, a + 1 + sizeof(u_int64_t), + memcpy(&tmp, a + 1 + sizeof(uint64_t), sizeof(tmp)); re->nexthop.v4.s_addr = tmp; break; case AID_VPN_IPv6: - if (attr_len < sizeof(u_int64_t) + + if (attr_len < sizeof(uint64_t) + sizeof(struct in6_addr)) return (-1); re->nexthop.aid = aid; memcpy(&re->nexthop.v6, - a + 1 + sizeof(u_int64_t), + a + 1 + sizeof(uint64_t), sizeof(struct in6_addr)); break; } @@ -927,7 +926,7 @@ mrt_free_peers(struct mrt_peer *p) void mrt_free_rib(struct mrt_rib *r) { - u_int16_t i, j; + uint16_t i, j; for (i = 0; i < r->nentries && r->entries; i++) { for (j = 0; j < r->entries[i].nattrs; j++) @@ -954,19 +953,19 @@ mrt_free_bgp_msg(struct mrt_bgp_msg *m) } u_char * -mrt_aspath_inflate(void *data, u_int16_t len, u_int16_t *newlen) +mrt_aspath_inflate(void *data, uint16_t len, uint16_t *newlen) { - u_int8_t *seg, *nseg, *ndata; - u_int16_t seg_size, olen, nlen; - u_int8_t seg_len; + uint8_t *seg, *nseg, *ndata; + uint16_t seg_size, olen, nlen; + uint8_t seg_len; /* first calculate the length of the aspath */ seg = data; nlen = 0; for (olen = len; olen > 0; olen -= seg_size, seg += seg_size) { seg_len = seg[1]; - seg_size = 2 + sizeof(u_int16_t) * seg_len; - nlen += 2 + sizeof(u_int32_t) * seg_len; + seg_size = 2 + sizeof(uint16_t) * seg_len; + nlen += 2 + sizeof(uint32_t) * seg_len; if (seg_size > olen) return NULL; @@ -993,9 +992,9 @@ mrt_aspath_inflate(void *data, u_int16_t len, u_int16_t *newlen) } int -mrt_extract_addr(void *msg, u_int len, struct bgpd_addr *addr, u_int8_t aid) +mrt_extract_addr(void *msg, u_int len, struct bgpd_addr *addr, uint8_t aid) { - u_int8_t *b = msg; + uint8_t *b = msg; memset(addr, 0, sizeof(*addr)); switch (aid) { @@ -1012,29 +1011,29 @@ mrt_extract_addr(void *msg, u_int len, struct bgpd_addr *addr, u_int8_t aid) memcpy(&addr->v6, b, sizeof(struct in6_addr)); return sizeof(struct in6_addr); case AID_VPN_IPv4: - if (len < sizeof(u_int64_t) + sizeof(struct in_addr)) + if (len < sizeof(uint64_t) + sizeof(struct in_addr)) return (-1); addr->aid = aid; /* XXX labelstack and rd missing */ - memcpy(&addr->v4, b + sizeof(u_int64_t), + memcpy(&addr->v4, b + sizeof(uint64_t), sizeof(struct in_addr)); - return (sizeof(u_int64_t) + sizeof(struct in_addr)); + return (sizeof(uint64_t) + sizeof(struct in_addr)); case AID_VPN_IPv6: - if (len < sizeof(u_int64_t) + sizeof(struct in6_addr)) + if (len < sizeof(uint64_t) + sizeof(struct in6_addr)) return (-1); addr->aid = aid; /* XXX labelstack and rd missing */ - memcpy(&addr->v6, b + sizeof(u_int64_t), + memcpy(&addr->v6, b + sizeof(uint64_t), sizeof(struct in6_addr)); - return (sizeof(u_int64_t) + sizeof(struct in6_addr)); + return (sizeof(uint64_t) + sizeof(struct in6_addr)); default: return (-1); } } int -mrt_extract_prefix(void *msg, u_int len, u_int8_t aid, - struct bgpd_addr *prefix, u_int8_t *prefixlen, int verbose) +mrt_extract_prefix(void *msg, u_int len, uint8_t aid, + struct bgpd_addr *prefix, uint8_t *prefixlen, int verbose) { int r; @@ -1066,12 +1065,12 @@ mrt_parse_state(struct mrt_hdr *hdr, void *msg, int verbose) { struct timespec t; struct mrt_bgp_state *s; - u_int8_t *b = msg; + uint8_t *b = msg; u_int len = ntohl(hdr->length); - u_int32_t sas, das, usec; - u_int16_t tmp16, afi; + uint32_t sas, das, usec; + uint16_t tmp16, afi; int r; - u_int8_t aid; + uint8_t aid; t.tv_sec = ntohl(hdr->timestamp); t.tv_nsec = 0; @@ -1174,12 +1173,12 @@ mrt_parse_msg(struct mrt_hdr *hdr, void *msg, int verbose) { struct timespec t; struct mrt_bgp_msg *m; - u_int8_t *b = msg; + uint8_t *b = msg; u_int len = ntohl(hdr->length); - u_int32_t sas, das, usec; - u_int16_t tmp16, afi; + uint32_t sas, das, usec; + uint16_t tmp16, afi; int r, addpath = 0; - u_int8_t aid; + uint8_t aid; t.tv_sec = ntohl(hdr->timestamp); t.tv_nsec = 0; diff --git a/usr.sbin/bgpctl/mrtparser.h b/usr.sbin/bgpctl/mrtparser.h index 4a1b2e9e35f..3a235a587ea 100644 --- a/usr.sbin/bgpctl/mrtparser.h +++ b/usr.sbin/bgpctl/mrtparser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mrtparser.h,v 1.4 2021/07/27 07:42:37 claudio Exp $ */ +/* $OpenBSD: mrtparser.h,v 1.5 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2011 Claudio Jeker <claudio@openbsd.org> * @@ -20,15 +20,15 @@ /* data structures for the MSG_TABLE_DUMP_V2 format */ struct mrt_peer_entry { struct bgpd_addr addr; - u_int32_t bgp_id; - u_int32_t asnum; + uint32_t bgp_id; + uint32_t asnum; }; struct mrt_peer { char *view; struct mrt_peer_entry *peers; - u_int32_t bgp_id; - u_int16_t npeers; + uint32_t bgp_id; + uint16_t npeers; }; struct mrt_attr { @@ -41,22 +41,22 @@ struct mrt_rib_entry { struct mrt_attr *attrs; struct bgpd_addr nexthop; time_t originated; - u_int32_t local_pref; - u_int32_t med; - u_int32_t path_id; - u_int16_t peer_idx; - u_int16_t aspath_len; - u_int16_t nattrs; - u_int8_t origin; + uint32_t local_pref; + uint32_t med; + uint32_t path_id; + uint16_t peer_idx; + uint16_t aspath_len; + uint16_t nattrs; + uint8_t origin; }; struct mrt_rib { struct mrt_rib_entry *entries; struct bgpd_addr prefix; - u_int32_t seqnum; - u_int16_t nentries; - u_int8_t prefixlen; - u_int8_t add_path; + uint32_t seqnum; + uint16_t nentries; + uint8_t prefixlen; + uint8_t add_path; }; /* data structures for the BGP4MP MESSAGE and STATE types */ @@ -64,20 +64,20 @@ struct mrt_bgp_state { struct timespec time; struct bgpd_addr src; struct bgpd_addr dst; - u_int32_t src_as; - u_int32_t dst_as; - u_int16_t old_state; - u_int16_t new_state; + uint32_t src_as; + uint32_t dst_as; + uint16_t old_state; + uint16_t new_state; }; struct mrt_bgp_msg { struct timespec time; struct bgpd_addr src; struct bgpd_addr dst; - u_int32_t src_as; - u_int32_t dst_as; - u_int16_t msg_len; - u_int8_t add_path; + uint32_t src_as; + uint32_t dst_as; + uint16_t msg_len; + uint8_t add_path; void *msg; }; diff --git a/usr.sbin/bgpctl/output.c b/usr.sbin/bgpctl/output.c index 22c7dcce26b..5f71dbc19c9 100644 --- a/usr.sbin/bgpctl/output.c +++ b/usr.sbin/bgpctl/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.19 2021/07/30 09:45:52 claudio Exp $ */ +/* $OpenBSD: output.c,v 1.20 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -134,8 +134,8 @@ show_summary(struct peer *p) static void show_neighbor_capa_mp(struct capabilities *capa) { - int comma; - u_int8_t i; + int comma; + uint8_t i; printf(" Multiprotocol extensions: "); for (i = 0, comma = 0; i < AID_MAX; i++) @@ -151,7 +151,7 @@ show_neighbor_capa_add_path(struct capabilities *capa) { const char *mode; int comma; - u_int8_t i; + uint8_t i; printf(" Add-path: "); for (i = 0, comma = 0; i < AID_MAX; i++) { @@ -177,8 +177,8 @@ show_neighbor_capa_add_path(struct capabilities *capa) static void show_neighbor_capa_restart(struct capabilities *capa) { - int comma; - u_int8_t i; + int comma; + uint8_t i; printf(" Graceful Restart"); if (capa->grestart.timeout) @@ -242,11 +242,11 @@ show_neighbor_msgstats(struct peer *p) static void show_neighbor_full(struct peer *p, struct parse_result *res) { - const char *errstr; - struct in_addr ina; - char *s; - int hascapamp, hascapaap; - u_int8_t i; + const char *errstr; + struct in_addr ina; + char *s; + int hascapamp, hascapaap; + uint8_t i; if ((p->conf.remote_addr.aid == AID_INET && p->conf.remote_masklen != 32) || @@ -455,7 +455,7 @@ show_timer(struct ctl_timer *t) static void show_fib(struct kroute_full *kf) { - char *p; + char *p; if (asprintf(&p, "%s/%u", log_addr(&kf->prefix), kf->prefixlen) == -1) err(1, NULL); @@ -480,9 +480,9 @@ show_fib_table(struct ktable *kt) static void show_nexthop(struct ctl_show_nexthop *nh) { - struct kroute *k; - struct kroute6 *k6; - char *s; + struct kroute *k; + struct kroute6 *k6; + char *s; printf("%s %-15s ", nh->valid ? "*" : " ", log_addr(&nh->addr)); if (!nh->krvalid) { @@ -548,8 +548,8 @@ show_communities(u_char *data, size_t len, struct parse_result *res) { struct community c; size_t i; - u_int64_t ext; - u_int8_t type = 0; + uint64_t ext; + uint8_t type = 0; if (len % sizeof(c)) return; @@ -574,19 +574,19 @@ show_communities(u_char *data, size_t len, struct parse_result *res) fmt_large_community(c.data1, c.data2, c.data3)); break; case COMMUNITY_TYPE_EXT: - ext = (u_int64_t)c.data3 << 48; + ext = (uint64_t)c.data3 << 48; switch (c.data3 >> 8) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: case EXT_COMMUNITY_NON_TRANS_OPAQUE: - ext |= ((u_int64_t)c.data1 & 0xffff) << 32; - ext |= (u_int64_t)c.data2; + ext |= ((uint64_t)c.data1 & 0xffff) << 32; + ext |= (uint64_t)c.data2; break; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: - ext |= (u_int64_t)c.data1 << 16; - ext |= (u_int64_t)c.data2 & 0xffff; + ext |= (uint64_t)c.data1 << 16; + ext |= (uint64_t)c.data2 & 0xffff; break; } ext = htobe64(ext); @@ -600,10 +600,10 @@ show_communities(u_char *data, size_t len, struct parse_result *res) } static void -show_community(u_char *data, u_int16_t len) +show_community(u_char *data, uint16_t len) { - u_int16_t a, v; - u_int16_t i; + uint16_t a, v; + uint16_t i; if (len & 0x3) { printf("bad length"); @@ -623,10 +623,10 @@ show_community(u_char *data, u_int16_t len) } static void -show_large_community(u_char *data, u_int16_t len) +show_large_community(u_char *data, uint16_t len) { - u_int32_t a, l1, l2; - u_int16_t i; + uint32_t a, l1, l2; + uint16_t i; if (len % 12) { printf("bad length"); @@ -648,9 +648,9 @@ show_large_community(u_char *data, u_int16_t len) } static void -show_ext_community(u_char *data, u_int16_t len) +show_ext_community(u_char *data, uint16_t len) { - u_int16_t i; + uint16_t i; if (len & 0x7) { printf("bad length"); @@ -672,9 +672,9 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath) struct in_addr id; struct bgpd_addr prefix; char *aspath; - u_int32_t as, pathid; - u_int16_t alen, ioff, short_as, afi; - u_int8_t flags, type, safi, aid, prefixlen; + uint32_t as, pathid; + uint16_t alen, ioff, short_as, afi; + uint8_t flags, type, safi, aid, prefixlen; int i, pos, e2, e4; if (len < 3) { @@ -691,7 +691,7 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath) warnx("Too short BGP attrbute"); return; } - memcpy(&alen, data+2, sizeof(u_int16_t)); + memcpy(&alen, data+2, sizeof(uint16_t)); alen = ntohs(alen); data += 4; len -= 4; @@ -748,7 +748,7 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath) case ATTR_MED: case ATTR_LOCALPREF: if (alen == 4) { - u_int32_t val; + uint32_t val; memcpy(&val, data, sizeof(val)); val = ntohl(val); printf("%u", val); @@ -810,7 +810,7 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath) if (type == ATTR_MP_REACH_NLRI) { struct bgpd_addr nexthop; - u_int8_t nhlen; + uint8_t nhlen; if (len == 0) goto bad_len; nhlen = *data++; @@ -829,14 +829,14 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath) if (nhlen != 12) goto bad_len; nexthop.aid = AID_INET; - memcpy(&nexthop.v4, data + sizeof(u_int64_t), + memcpy(&nexthop.v4, data + sizeof(uint64_t), sizeof(nexthop.v4)); break; case AID_VPN_IPv6: if (nhlen != 24) goto bad_len; nexthop.aid = AID_INET6; - memcpy(&nexthop.v6, data + sizeof(u_int64_t), + memcpy(&nexthop.v6, data + sizeof(uint64_t), sizeof(nexthop.v6)); break; default: diff --git a/usr.sbin/bgpctl/output_json.c b/usr.sbin/bgpctl/output_json.c index 8a0441ba551..4fba5234892 100644 --- a/usr.sbin/bgpctl/output_json.c +++ b/usr.sbin/bgpctl/output_json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output_json.c,v 1.12 2021/07/27 07:42:37 claudio Exp $ */ +/* $OpenBSD: output_json.c,v 1.13 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org> @@ -543,7 +543,7 @@ static void json_do_large_community(u_char *data, uint16_t len) { uint32_t a, l1, l2; - u_int16_t i; + uint16_t i; if (len % 12) { json_do_printf("error", "bad length"); diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c index f1a85519958..bf0b6c01a6c 100644 --- a/usr.sbin/bgpctl/parser.c +++ b/usr.sbin/bgpctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.107 2021/08/09 08:24:36 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.108 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -494,7 +494,7 @@ const struct token *match_token(int *argc, char **argv[], void show_valid_args(const struct token []); int parse_addr(const char *, struct bgpd_addr *); -int parse_asnum(const char *, size_t, u_int32_t *); +int parse_asnum(const char *, size_t, uint32_t *); int parse_number(const char *, struct parse_result *, enum token_type); void parsecommunity(struct community *c, int type, char *s); void parseextcommunity(struct community *c, const char *t, char *s); @@ -610,7 +610,8 @@ match_token(int *argc, char **argv[], const struct token table[]) } break; case PREFIX: - if (parse_prefix(word, wordlen, &res.addr, &res.prefixlen)) { + if (parse_prefix(word, wordlen, &res.addr, + &res.prefixlen)) { match++; t = &table[i]; } @@ -718,7 +719,7 @@ match_token(int *argc, char **argv[], const struct token table[]) if (word != NULL && wordlen > 0) { char *p = strdup(word); struct community ext; - u_int64_t rd; + uint64_t rd; if (p == NULL) err(1, NULL); @@ -728,19 +729,19 @@ match_token(int *argc, char **argv[], const struct token table[]) switch (ext.data3 >> 8) { case EXT_COMMUNITY_TRANS_TWO_AS: rd = (0ULL << 48); - rd |= ((u_int64_t)ext.data1 & 0xffff) + rd |= ((uint64_t)ext.data1 & 0xffff) << 32; - rd |= (u_int64_t)ext.data2; + rd |= (uint64_t)ext.data2; break; case EXT_COMMUNITY_TRANS_IPV4: rd = (1ULL << 48); - rd |= (u_int64_t)ext.data1 << 16; - rd |= (u_int64_t)ext.data2 & 0xffff; + rd |= (uint64_t)ext.data1 << 16; + rd |= (uint64_t)ext.data2 & 0xffff; break; case EXT_COMMUNITY_TRANS_FOUR_AS: rd = (2ULL << 48); - rd |= (u_int64_t)ext.data1 << 16; - rd |= (u_int64_t)ext.data2 & 0xffff; + rd |= (uint64_t)ext.data1 << 16; + rd |= (uint64_t)ext.data2 & 0xffff; break; default: errx(1, "bad encoding of rd"); @@ -929,7 +930,8 @@ parse_addr(const char *word, struct bgpd_addr *addr) } int -parse_prefix(const char *word, size_t wordlen, struct bgpd_addr *addr, u_int8_t *prefixlen) +parse_prefix(const char *word, size_t wordlen, struct bgpd_addr *addr, + uint8_t *prefixlen) { char *p, *ps; const char *errstr; @@ -982,11 +984,11 @@ parse_prefix(const char *word, size_t wordlen, struct bgpd_addr *addr, u_int8_t } int -parse_asnum(const char *word, size_t wordlen, u_int32_t *asnum) +parse_asnum(const char *word, size_t wordlen, uint32_t *asnum) { const char *errstr; char *dot, *parseword; - u_int32_t uval, uvalh = 0; + uint32_t uval, uvalh = 0; if (word == NULL) return (0); @@ -1081,7 +1083,7 @@ parse_number(const char *word, struct parse_result *r, enum token_type type) } static void -getcommunity(char *s, int large, u_int32_t *val, u_int32_t *flag) +getcommunity(char *s, int large, uint32_t *val, uint32_t *flag) { long long max = USHRT_MAX; const char *errstr; @@ -1106,8 +1108,8 @@ getcommunity(char *s, int large, u_int32_t *val, u_int32_t *flag) } static void -setcommunity(struct community *c, u_int32_t as, u_int32_t data, - u_int32_t asflag, u_int32_t dataflag) +setcommunity(struct community *c, uint32_t as, uint32_t data, + uint32_t asflag, uint32_t dataflag) { c->flags = COMMUNITY_TYPE_BASIC; c->flags |= asflag << 8; @@ -1121,7 +1123,7 @@ static void parselargecommunity(struct community *c, char *s) { char *p, *q; - u_int32_t dflag1, dflag2, dflag3; + uint32_t dflag1, dflag2, dflag3; if ((p = strchr(s, ':')) == NULL) errx(1, "Bad community syntax"); @@ -1145,7 +1147,7 @@ void parsecommunity(struct community *c, int type, char *s) { char *p; - u_int32_t as, data, asflag, dataflag; + uint32_t as, data, asflag, dataflag; if (type == COMMUNITY_TYPE_LARGE) { parselargecommunity(c, s); @@ -1209,12 +1211,12 @@ parsesubtype(const char *name, int *type, int *subtype) } static int -parseextvalue(int type, char *s, u_int32_t *v, u_int32_t *flag) +parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag) { const char *errstr; char *p; struct in_addr ip; - u_int32_t uvalh, uval; + uint32_t uvalh, uval; if (type != -1) { /* nothing */ @@ -1282,8 +1284,8 @@ parseextcommunity(struct community *c, const char *t, char *s) { const struct ext_comm_pairs *cp; char *p, *ep; - u_int64_t ullval; - u_int32_t uval, uval2, dflag1 = 0, dflag2 = 0; + uint64_t ullval; + uint32_t uval, uval2, dflag1 = 0, dflag2 = 0; int type = 0, subtype = 0; if (strcmp(t, "*") == 0 && strcmp(s, "*") == 0) { diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h index 397bd9bc896..89634a2bc11 100644 --- a/usr.sbin/bgpctl/parser.h +++ b/usr.sbin/bgpctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.41 2021/08/09 08:24:36 claudio Exp $ */ +/* $OpenBSD: parser.h,v 1.42 2022/02/06 09:52:32 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -68,19 +68,19 @@ struct parse_result { char rib[PEER_DESCR_LEN]; char reason[REASON_LEN]; const char *ext_comm_subtype; - u_int64_t rd; + uint64_t rd; int flags; int is_group; u_int rtableid; - u_int32_t pathid; + uint32_t pathid; enum actions action; - u_int8_t validation_state; - u_int8_t prefixlen; - u_int8_t aid; + uint8_t validation_state; + uint8_t prefixlen; + uint8_t aid; int mrtfd; }; __dead void usage(void); struct parse_result *parse(int, char *[]); int parse_prefix(const char *, size_t, struct bgpd_addr *, - u_int8_t *); + uint8_t *); |