diff --git a/configure.ac b/configure.ac index 3e0335c..0d40d6a 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,7 @@ AC_CONFIG_FILES([Makefile lib/bgp/Makefile lib/bmp/Makefile lib/mrt/Makefile - tools/Makefile + lib/openbmp/Makefile + tools/Makefile ]) AC_OUTPUT diff --git a/lib/Makefile.am b/lib/Makefile.am index d5595ed..e3c1683 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -24,13 +24,14 @@ # POSSIBILITY OF SUCH DAMAGE. # -SUBDIRS = bgp bmp mrt +SUBDIRS = bgp bmp mrt openbmp AM_CPPFLAGS = -I$(top_srcdir)/ \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/lib/bgp \ -I$(top_srcdir)/lib/bmp \ - -I$(top_srcdir)/lib/mrt + -I$(top_srcdir)/lib/mrt \ + -I$(top_srcdir)/lib/openbmp include_HEADERS = \ parsebgp.h \ @@ -52,7 +53,8 @@ libparsebgp_la_SOURCES = \ libparsebgp_la_LIBADD = \ $(top_builddir)/lib/bgp/libparsebgp_bgp.la \ $(top_builddir)/lib/bmp/libparsebgp_bmp.la \ - $(top_builddir)/lib/mrt/libparsebgp_mrt.la + $(top_builddir)/lib/mrt/libparsebgp_mrt.la \ + $(top_builddir)/lib/openbmp/libparsebgp_openbmp.la libparsebgp_la_LDFLAGS = -version-info @LIBPARSEBGP_SHLIB_CURRENT@:@LIBPARSEBGP_SHLIB_REVISION@:@LIBPARSEBGP_SHLIB_AGE@ diff --git a/lib/bgp/Makefile.am b/lib/bgp/Makefile.am index ba9ab82..ec45e4a 100644 --- a/lib/bgp/Makefile.am +++ b/lib/bgp/Makefile.am @@ -28,7 +28,8 @@ SUBDIRS = AM_CPPFLAGS = -I$(top_srcdir)/ \ -I$(top_srcdir)/lib \ - -I$(top_srcdir)/lib/bmp + -I$(top_srcdir)/lib/bmp \ + -I$(top_srcdir)/lib/openbmp include_HEADERS = \ parsebgp_bgp.h \ diff --git a/lib/bmp/Makefile.am b/lib/bmp/Makefile.am index fc86e02..08e34ef 100644 --- a/lib/bmp/Makefile.am +++ b/lib/bmp/Makefile.am @@ -29,7 +29,8 @@ SUBDIRS = AM_CPPFLAGS = \ -I$(top_srcdir)/ \ -I$(top_srcdir)/lib \ - -I$(top_srcdir)/lib/bgp + -I$(top_srcdir)/lib/bgp \ + -I$(top_srcdir)/lib/openbmp include_HEADERS = \ parsebgp_bmp.h \ diff --git a/lib/mrt/Makefile.am b/lib/mrt/Makefile.am index 6804b4b..4ded797 100644 --- a/lib/mrt/Makefile.am +++ b/lib/mrt/Makefile.am @@ -29,7 +29,8 @@ SUBDIRS = AM_CPPFLAGS = -I$(top_srcdir)/ \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/lib/bgp \ - -I$(top_srcdir)/lib/bmp + -I$(top_srcdir)/lib/bmp \ + -I$(top_srcdir)/lib/openbmp include_HEADERS = parsebgp_mrt.h diff --git a/lib/openbmp/Makefile.am b/lib/openbmp/Makefile.am new file mode 100644 index 0000000..af815cc --- /dev/null +++ b/lib/openbmp/Makefile.am @@ -0,0 +1,47 @@ +# +# Copyright (C) 2019 The Regents of the University of California. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +SUBDIRS = + +AM_CPPFLAGS = \ + -I$(top_srcdir)/ \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/lib/bgp \ + -I$(top_srcdir)/lib/bmp + +include_HEADERS = \ + parsebgp_openbmp.h \ + parsebgp_openbmp_opts.h + +noinst_LTLIBRARIES = libparsebgp_openbmp.la + +libparsebgp_openbmp_la_SOURCES = \ + parsebgp_openbmp.c \ + parsebgp_openbmp.h \ + parsebgp_openbmp_opts.c \ + parsebgp_openbmp_opts.h + +CLEANFILES = *~ diff --git a/lib/openbmp/parsebgp_openbmp.c b/lib/openbmp/parsebgp_openbmp.c new file mode 100644 index 0000000..7beccf6 --- /dev/null +++ b/lib/openbmp/parsebgp_openbmp.c @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2019 The Regents of the University of California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "parsebgp_utils.h" +#include "parsebgp_openbmp.h" +#include "parsebgp_bmp.h" + +void parsebgp_openbmp_clear_msg(parsebgp_openbmp_msg_t *msg) { + // reset openbmp header values to zero + msg->ver_maj = 0; + msg->ver_min = 0; + msg->flags = 0; + msg->time_sec = 0; + msg->time_usec = 0; + msg->collector_name_len = 0; + memset(msg->collector_name, 0, sizeof(msg->collector_name)); + msg->router_name_len = 0; + memset(msg->router_name, 0, sizeof(msg->router_name)); + + // clear bmp msg too + parsebgp_bmp_clear_msg(msg->bmp_msg); +} + +void parsebgp_openbmp_destroy_msg(parsebgp_openbmp_msg_t *msg) { + // free bmp msg + parsebgp_bmp_destroy_msg(msg->bmp_msg); + + // now free openbmp msg itself + free(msg); +} + +void parsebgp_openbmp_dump_msg(const parsebgp_openbmp_msg_t *msg, int depth) { + // dump openbmp header fields + PARSEBGP_DUMP_INT(depth, "Version major", msg->ver_maj); + PARSEBGP_DUMP_INT(depth, "Version minor", msg->ver_min); + PARSEBGP_DUMP_INT(depth, "Flags", msg->flags); + PARSEBGP_DUMP_INT(depth, "Topic type", msg->topic_type); + PARSEBGP_DUMP_INT(depth, "Time.sec", msg->time_sec); + PARSEBGP_DUMP_INT(depth, "Time.usec", msg->time_usec); + + PARSEBGP_DUMP_INFO(depth, "Collector name" ": %*s\n", + msg->collector_name_len, msg->collector_name); + PARSEBGP_DUMP_INFO(depth, "Router name" ": %*s\n", + msg->router_name_len, msg->router_name); + PARSEBGP_DUMP_IP(depth, "Router IP", msg->router_afi, msg->router_ip); + + // dump bmp msg + parsebgp_bmp_dump_msg(msg->bmp_msg, depth); +} + +parsebgp_error_t parsebgp_openbmp_decode(parsebgp_opts_t *opts, + parsebgp_openbmp_msg_t *msg, + const uint8_t *buf, size_t *buf_len) { + // remember the buf_len + size_t len = *buf_len; + // how many bytes are read so far + size_t nread = 0; + int newln = 0; + uint8_t u8; + uint16_t u16; + uint32_t u32; + int name_len = 0; + + // we want at least a few bytes to do header checks + if (len < 4) { + *buf_len = 0; + return PARSEBGP_PARTIAL_MSG; + } + + // check if buf starts with the magic number + if (memcmp(buf, "OBMP", 4) != 0) { + // it's not a known OpenBMP header, assume that it is raw BMP + *buf_len = 0; + return PARSEBGP_INVALID_MSG; + } + nread += 4; + buf += 4; + + // Confirm the version number + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, msg->ver_maj); + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, msg->ver_min); + if (msg->ver_maj != 1 || msg->ver_min != 7) { + return PARSEBGP_INVALID_MSG; + } + + // skip past the header length and the message length (since we'll parse the + // entire header anyway). + nread += 2 + 4; + buf += 2 + 4; + + // read the flags + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, msg->flags); + // check the flags + // we only care about bmp raw messages, which are always router messages + if (!(msg->flags & 0x80)) { + return PARSEBGP_NOT_IMPLEMENTED; + } + + // check the openbmp topic type + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, u8); + if (u8 != 12) { + // we only want BMP RAW messages, so skip this one + return PARSEBGP_NOT_IMPLEMENTED; + } + msg->topic_type = u8; + + // load the time stamps into the record + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, u32); + msg->time_sec = ntohl(u32); + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, u32); + msg->time_usec = ntohl(u32); + + // skip past the collector hash + nread += 16; + buf += 16; + + // grab the collector admin ID as collector name + // TODO: if there is no admin ID, use the hash + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, u16); + u16 = ntohs(u16); + // maybe truncate the collector name + if (u16 < STR_NAME_LEN) { + name_len = u16; + } else { + name_len = STR_NAME_LEN - 1; + } + // copy the collector name in + if ((len - nread) < u16) { + return PARSEBGP_PARTIAL_MSG; + } + msg->collector_name_len = name_len; + memcpy(msg->collector_name, buf, name_len); + msg->collector_name[name_len] = '\0'; + nread += u16; + buf += u16; + + if ((len - nread) < 32) { + // not enough buffer left for router hash and IP + return PARSEBGP_PARTIAL_MSG; + } + + // skip past the router hash + nread += 16; + buf += 16; + + // grab the router IP + if (msg->flags & 0x40) { // IS_ROUTER_IPV6 + msg->router_afi = PARSEBGP_BGP_AFI_IPV6; + } else { + msg->router_afi = PARSEBGP_BGP_AFI_IPV4; + } + // this marco should automatically increment nread and buf + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, msg->router_ip); + + // router name + // TODO: if there is no name, or it is "default", use the IP + PARSEBGP_DESERIALIZE_VAL(buf, len - nread, nread, u16); + u16 = ntohs(u16); + // maybe truncate the router name + if (u16 < STR_NAME_LEN) { + name_len = u16; + } else { + name_len = STR_NAME_LEN - 1; + } + // copy the router name in + if ((len - nread) < u16) { + return PARSEBGP_PARTIAL_MSG; + } + msg->router_name_len = name_len; + memcpy(msg->router_name, buf, name_len); + msg->router_name[name_len] = '\0'; + nread += u16; + buf += u16; + + // and then ignore the row count + nread += 4; + buf += 4; + + // see whether the raw bmp msg is parsed. + size_t slen = len - nread; + PARSEBGP_MAYBE_MALLOC_ZERO(msg->bmp_msg); + parsebgp_error_t bmp_parse_err = parsebgp_bmp_decode(opts, msg->bmp_msg, buf, &slen); + // return err msg from bmp parsing if any. + if (bmp_parse_err != PARSEBGP_OK) { + return bmp_parse_err; + } + // increment read len + nread += slen; + + // set how many bytes were read to parse this openbmp msg. + *buf_len = nread; + // return an openbmp msg was parsed. + return PARSEBGP_OK; +} diff --git a/lib/openbmp/parsebgp_openbmp.h b/lib/openbmp/parsebgp_openbmp.h new file mode 100644 index 0000000..f2780be --- /dev/null +++ b/lib/openbmp/parsebgp_openbmp.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2019 The Regents of the University of California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PARSEBGP_OPENBMP_H +#define __PARSEBGP_OPENBMP_H + +#include "parsebgp_opts.h" // the header includes all sub type opts including parsebgp_openbmp_opts.h +#include "parsebgp_bgp.h" // BMP encapsulates BGP messages +#include "parsebgp_bmp.h" // OpenBMP encapsulates BMP messages +#include "parsebgp_error.h" // for parsebgp_error_t +#include +#include +#include +#include + +#define STR_NAME_LEN 256 + +typedef struct parsebgp_openbmp_msg { + // OpenBMP version numbers + uint8_t ver_maj, ver_min; + + // OpenBMP msg flags + uint8_t flags; + // + // OpenBMP topic type (collector or raw_bmp) + uint8_t topic_type; + + // Collection time (seconds component) + uint32_t time_sec; + + // Collection time (microseconds component) + uint32_t time_usec; + + // Collector name + int collector_name_len; + char collector_name[STR_NAME_LEN]; + + // Router name + int router_name_len; + char router_name[STR_NAME_LEN]; + + // Router IP + uint8_t router_ip[16]; + // Router IP Address AFI (based on openbmp header flags) + parsebgp_bgp_afi_t router_afi; + + // Parsed bmp msg if full msg parsing is required + parsebgp_bmp_msg_t *bmp_msg; + +} parsebgp_openbmp_msg_t; + +void parsebgp_openbmp_clear_msg(parsebgp_openbmp_msg_t *msg); + +void parsebgp_openbmp_destroy_msg(parsebgp_openbmp_msg_t *msg); + +void parsebgp_openbmp_dump_msg(const parsebgp_openbmp_msg_t *msg, int depth); + +parsebgp_error_t parsebgp_openbmp_decode(parsebgp_opts_t *opts, parsebgp_openbmp_msg_t *msg, + const uint8_t *buf, size_t *len); + +#endif /* __PARSEBGP_OPENBMP_H */ diff --git a/lib/openbmp/parsebgp_openbmp_opts.c b/lib/openbmp/parsebgp_openbmp_opts.c new file mode 100644 index 0000000..e69de29 diff --git a/lib/openbmp/parsebgp_openbmp_opts.h b/lib/openbmp/parsebgp_openbmp_opts.h new file mode 100644 index 0000000..776486f --- /dev/null +++ b/lib/openbmp/parsebgp_openbmp_opts.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 The Regents of the University of California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PARSEBGP_OPENBMP_OPTS_H +#define __PARSEBGP_OPENBMP_OPTS_H + +#include "parsebgp_bgp_common.h" +#include + +/** + * OpenBMP Parsing Options + */ +typedef struct parsebgp_openbmp_opts { + /* placeholder for openbmp opts */ +} parsebgp_openbmp_opts_t; + +/** + * Initialize parser options to default values + * + * @param opts pointer to an opts structure to initialize + */ +void parsebgp_openbmp_opts_init(parsebgp_openbmp_opts_t *opts); + +#endif /* __PARSEBGP_OPENBMP_OPTS_H */ + diff --git a/lib/parsebgp.c b/lib/parsebgp.c index 422a7a8..5b7ed8d 100644 --- a/lib/parsebgp.c +++ b/lib/parsebgp.c @@ -28,6 +28,7 @@ #include "parsebgp_bgp.h" #include "parsebgp_bmp.h" #include "parsebgp_mrt.h" +#include "parsebgp_openbmp.h" #include "parsebgp_utils.h" #include #include @@ -54,6 +55,11 @@ parsebgp_error_t parsebgp_decode(parsebgp_opts_t opts, parsebgp_msg_type_t type, return parsebgp_bgp_decode(&opts, msg->types.bgp, buffer, len); break; + case PARSEBGP_MSG_TYPE_OPENBMP: + PARSEBGP_MAYBE_MALLOC_ZERO(msg->types.openbmp); + return parsebgp_openbmp_decode(&opts, msg->types.openbmp, buffer, len); + break; + default: PARSEBGP_RETURN_INVALID_MSG_ERR; } @@ -90,6 +96,10 @@ void parsebgp_clear_msg(parsebgp_msg_t *msg) parsebgp_bgp_clear_msg(msg->types.bgp); break; + case PARSEBGP_MSG_TYPE_OPENBMP: + parsebgp_openbmp_clear_msg(msg->types.openbmp); + break; + default: // invalid message, give up break; @@ -105,6 +115,7 @@ void parsebgp_destroy_msg(parsebgp_msg_t *msg) parsebgp_mrt_destroy_msg(msg->types.mrt); parsebgp_bmp_destroy_msg(msg->types.bmp); parsebgp_bgp_destroy_msg(msg->types.bgp); + parsebgp_openbmp_destroy_msg(msg->types.openbmp); free(msg); } @@ -127,6 +138,10 @@ void parsebgp_dump_msg(const parsebgp_msg_t *msg) parsebgp_bgp_dump_msg(msg->types.bgp, 1); break; + case PARSEBGP_MSG_TYPE_OPENBMP: + parsebgp_openbmp_dump_msg(msg->types.openbmp, 1); + break; + default: PARSEBGP_DUMP_INFO(0, "UNKNOWN MESSAGE TYPE\n"); break; diff --git a/lib/parsebgp.h.in b/lib/parsebgp.h.in index a96e7c9..ae39115 100644 --- a/lib/parsebgp.h.in +++ b/lib/parsebgp.h.in @@ -30,6 +30,7 @@ #include "parsebgp_bgp.h" #include "parsebgp_bmp.h" #include "parsebgp_mrt.h" +#include "parsebgp_openbmp.h" #include "parsebgp_opts.h" #include #include @@ -46,11 +47,12 @@ typedef enum parsebgp_msg_type { PARSEBGP_MSG_TYPE_BGP = 1, PARSEBGP_MSG_TYPE_BMP = 2, PARSEBGP_MSG_TYPE_MRT = 3, + PARSEBGP_MSG_TYPE_OPENBMP = 4, } parsebgp_msg_type_t; /** Convenience macro to allow iterating over all valid message types */ #define PARSEBGP_FOREACH_MSG_TYPE(iter) \ - for ((iter) = PARSEBGP_MSG_TYPE_BGP; (iter) <= PARSEBGP_MSG_TYPE_MRT; \ + for ((iter) = PARSEBGP_MSG_TYPE_BGP; (iter) <= PARSEBGP_MSG_TYPE_OPENBMP; \ (iter)++) /** Structure into which a message is parsed */ @@ -71,6 +73,9 @@ typedef struct parsebgp_msg { /** Parsed MRT message */ parsebgp_mrt_msg_t *mrt; + /** Parsed OpenBMP message */ + parsebgp_openbmp_msg_t *openbmp; + } types; } parsebgp_msg_t; diff --git a/lib/parsebgp_opts.h b/lib/parsebgp_opts.h index 4fa9120..6886875 100644 --- a/lib/parsebgp_opts.h +++ b/lib/parsebgp_opts.h @@ -29,6 +29,7 @@ #include "parsebgp_bgp_opts.h" #include "parsebgp_bmp_opts.h" +#include "parsebgp_openbmp_opts.h" /** * Parsing Options @@ -89,6 +90,9 @@ typedef struct parsebgp_opts { /** BMP-specific parsing options */ parsebgp_bmp_opts_t bmp; + /** OpenBMP-specific parsing options */ + parsebgp_openbmp_opts_t openbmp; + } parsebgp_opts_t; /** diff --git a/tools/Makefile.am b/tools/Makefile.am index dc01e64..31a30dc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -27,7 +27,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/lib \ -I$(top_srcdir)/lib/bgp \ -I$(top_srcdir)/lib/bmp \ - -I$(top_srcdir)/lib/mrt + -I$(top_srcdir)/lib/mrt \ + -I$(top_srcdir)/lib/openbmp dist_bin_SCRIPTS = diff --git a/tools/parsebgp.c b/tools/parsebgp.c index d3f79e6..f5dfa27 100644 --- a/tools/parsebgp.c +++ b/tools/parsebgp.c @@ -44,6 +44,7 @@ static const char *type_strs[] = { "bgp", // PARSEBGP_MSG_TYPE_BGP "bmp", // PARSEBGP_MSG_TYPE_BMP "mrt", // PARSEBGP_MSG_TYPE_MRT + "openbmp", // PARSEBGP_MSG_TYPE_OPENBMP }; // should messages NOT be dumped to stdout after parsing @@ -182,7 +183,7 @@ static void usage(void) fprintf( stderr, "usage: %s [options] [type:]file [[type:]file...]\n" - " where 'type' is one of 'bmp', 'bgp', or 'mrt'\n" + " where 'type' is one of 'bmp', 'bgp', 'mrt', or 'openbmp'\n" " (only required if using non-standard file extensions)\n" " -4 Force 4-byte ASN parsing\n" " -b Perform shallow BMP parsing\n"