From 933383cde7adfd440b8f1052bc37ab77601942e7 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 17 Jul 2018 07:02:11 +0000 Subject: [PATCH] Switch to MSG_PROTOCOL_BGP4MP_ET formats for update and state mrt messages. The _ET format adds an additional microsecond time field which makes those message dumps more informative. The various table dumps are not modified since there the time especially between entries plays a secondary role. OK benno@ --- usr.sbin/bgpd/mrt.c | 24 +++++++++++++----------- usr.sbin/bgpd/mrt.h | 15 ++++++++++----- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c index 8a419d5da3f..446ef558a0f 100644 --- a/usr.sbin/bgpd/mrt.c +++ b/usr.sbin/bgpd/mrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.c,v 1.84 2018/02/05 03:55:54 claudio Exp $ */ +/* $OpenBSD: mrt.c,v 1.85 2018/07/17 07:02:11 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -105,7 +105,7 @@ mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, u_int16_t pkglen, if (mrt->type == MRT_ALL_IN || mrt->type == MRT_UPDATE_IN) incoming = 1; - if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP, subtype, + if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP_ET, subtype, pkglen, incoming) == -1) return; @@ -128,7 +128,7 @@ mrt_dump_state(struct mrt *mrt, u_int16_t old_state, u_int16_t new_state, if (peer->capa.neg.as4byte) subtype = BGP4MP_STATE_CHANGE_AS4; - if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP, subtype, + if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP_ET, subtype, 2 * sizeof(short), 0) == -1) return; @@ -684,17 +684,17 @@ int mrt_dump_hdr_se(struct ibuf ** bp, struct peer *peer, u_int16_t type, u_int16_t subtype, u_int32_t len, int swap) { - time_t now; + struct timespec time; - if ((*bp = ibuf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + + if ((*bp = ibuf_dynamic(MRT_ET_HEADER_SIZE, MRT_ET_HEADER_SIZE + MRT_BGP4MP_AS4_IPv6_HEADER_SIZE + len)) == NULL) { log_warn("mrt_dump_hdr_se: ibuf_dynamic error"); return (-1); } - now = time(NULL); + clock_gettime(CLOCK_REALTIME, &time); - DUMP_LONG(*bp, now); + DUMP_LONG(*bp, time.tv_sec); DUMP_SHORT(*bp, type); DUMP_SHORT(*bp, subtype); @@ -702,16 +702,16 @@ mrt_dump_hdr_se(struct ibuf ** bp, struct peer *peer, u_int16_t type, case AF_INET: if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4) - len += MRT_BGP4MP_AS4_IPv4_HEADER_SIZE; + len += MRT_BGP4MP_ET_AS4_IPv4_HEADER_SIZE; else - len += MRT_BGP4MP_IPv4_HEADER_SIZE; + len += MRT_BGP4MP_ET_IPv4_HEADER_SIZE; break; case AF_INET6: if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4) - len += MRT_BGP4MP_AS4_IPv6_HEADER_SIZE; + len += MRT_BGP4MP_ET_AS4_IPv6_HEADER_SIZE; else - len += MRT_BGP4MP_IPv6_HEADER_SIZE; + len += MRT_BGP4MP_ET_IPv6_HEADER_SIZE; break; case 0: goto fail; @@ -721,6 +721,8 @@ mrt_dump_hdr_se(struct ibuf ** bp, struct peer *peer, u_int16_t type, } DUMP_LONG(*bp, len); + /* milisecond field use by the _ET format */ + DUMP_LONG(*bp, time.tv_nsec / 1000); if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4) { diff --git a/usr.sbin/bgpd/mrt.h b/usr.sbin/bgpd/mrt.h index 0656508b981..b3a0afe1b84 100644 --- a/usr.sbin/bgpd/mrt.h +++ b/usr.sbin/bgpd/mrt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.h,v 1.31 2011/09/19 11:19:32 claudio Exp $ */ +/* $OpenBSD: mrt.h,v 1.32 2018/07/17 07:02:11 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -39,6 +39,7 @@ * length field. Which is accounted in the length field. */ #define MRT_HEADER_SIZE 12 +#define MRT_ET_HEADER_SIZE 16 struct mrt_hdr { u_int32_t timestamp; @@ -87,11 +88,15 @@ enum MRT_BGP4MP_SUBTYPES { }; /* size of the BGP4MP headers without payload */ -#define MRT_BGP4MP_IPv4_HEADER_SIZE 16 -#define MRT_BGP4MP_IPv6_HEADER_SIZE 40 +#define MRT_BGP4MP_IPv4_HEADER_SIZE 16 +#define MRT_BGP4MP_IPv6_HEADER_SIZE 40 +#define MRT_BGP4MP_ET_IPv4_HEADER_SIZE 20 +#define MRT_BGP4MP_ET_IPv6_HEADER_SIZE 44 /* 4-byte AS variants of the previous */ -#define MRT_BGP4MP_AS4_IPv4_HEADER_SIZE 20 -#define MRT_BGP4MP_AS4_IPv6_HEADER_SIZE 44 +#define MRT_BGP4MP_AS4_IPv4_HEADER_SIZE 20 +#define MRT_BGP4MP_AS4_IPv6_HEADER_SIZE 44 +#define MRT_BGP4MP_ET_AS4_IPv4_HEADER_SIZE 24 +#define MRT_BGP4MP_ET_AS4_IPv6_HEADER_SIZE 48 /* If the type is PROTOCOL_BGP4MP and the subtype is either BGP4MP_STATE_CHANGE * or BGP4MP_MESSAGE the message consists of a common header plus the payload. -- 2.20.1