bgpd: add & use bgp packet dump hook

The MRT dump code is already hooked in at the right places to write out
packets;  the BMP code needs exactly the same access so let's make this
a hook.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2019-04-24 17:19:09 +02:00
parent 2b9bcf306d
commit 584470fb5f
5 changed files with 24 additions and 7 deletions

View File

@ -37,6 +37,7 @@
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_dump.h"
#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_packet.h"
enum bgp_dump_type {
BGP_DUMP_ALL,
@ -555,7 +556,8 @@ static void bgp_dump_packet_func(struct bgp_dump *bgp_dump, struct peer *peer,
}
/* Called from bgp_packet.c when BGP packet is received. */
void bgp_dump_packet(struct peer *peer, int type, struct stream *packet)
static int bgp_dump_packet(struct peer *peer, uint8_t type, bgp_size_t size,
struct stream *packet)
{
/* bgp_dump_all. */
bgp_dump_packet_func(&bgp_dump_all, peer, packet);
@ -563,6 +565,7 @@ void bgp_dump_packet(struct peer *peer, int type, struct stream *packet)
/* bgp_dump_updates. */
if (type == BGP_MSG_UPDATE)
bgp_dump_packet_func(&bgp_dump_updates, peer, packet);
return 0;
}
static unsigned int bgp_dump_parse_time(const char *str)
@ -862,6 +865,8 @@ void bgp_dump_init(void)
install_element(CONFIG_NODE, &dump_bgp_all_cmd);
install_element(CONFIG_NODE, &no_dump_bgp_all_cmd);
hook_register(bgp_packet_dump, bgp_dump_packet);
}
void bgp_dump_finish(void)

View File

@ -52,6 +52,5 @@
extern void bgp_dump_init(void);
extern void bgp_dump_finish(void);
extern void bgp_dump_state(struct peer *, int, int);
extern void bgp_dump_packet(struct peer *, int, struct stream *);
#endif /* _QUAGGA_BGP_DUMP_H */

View File

@ -184,9 +184,11 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
EC_BGP_PKT_PROCESS,
"[%s] Dropping pending packet on connection transfer:",
peer->host);
uint16_t type = stream_getc_from(peer->curr,
BGP_MARKER_SIZE + 2);
bgp_dump_packet(peer, type, peer->curr);
/* there used to be a bgp_packet_dump call here, but
* that's extremely confusing since there's no way to
* identify the packet in MRT dumps or BMP as dropped
* due to connection transfer.
*/
stream_free(peer->curr);
peer->curr = NULL;
}

View File

@ -63,6 +63,11 @@
#include "bgpd/bgp_keepalives.h"
#include "bgpd/bgp_flowspec.h"
DEFINE_HOOK(bgp_packet_dump,
(struct peer *peer, uint8_t type, bgp_size_t size,
struct stream *s),
(peer, type, size, s))
/**
* Sets marker and type fields for a BGP message.
*
@ -2242,8 +2247,7 @@ int bgp_process_packet(struct thread *thread)
size = stream_getw(peer->curr);
type = stream_getc(peer->curr);
/* BGP packet dump function. */
bgp_dump_packet(peer, type, peer->curr);
hook_call(bgp_packet_dump, peer, type, size, peer->curr);
/* adjust size to exclude the marker + length + type */
size -= BGP_HEADER_SIZE;

View File

@ -21,6 +21,13 @@
#ifndef _QUAGGA_BGP_PACKET_H
#define _QUAGGA_BGP_PACKET_H
#include "hook.h"
DECLARE_HOOK(bgp_packet_dump,
(struct peer *peer, uint8_t type, bgp_size_t size,
struct stream *s),
(peer, type, size, s))
#define BGP_NLRI_LENGTH 1U
#define BGP_TOTAL_ATTR_LEN 2U
#define BGP_UNFEASIBLE_LEN 2U