]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: add & use bgp packet dump hook
authorDavid Lamparter <equinox@diac24.net>
Wed, 24 Apr 2019 15:19:09 +0000 (17:19 +0200)
committerDavid Lamparter <equinox@diac24.net>
Wed, 3 Jul 2019 14:58:26 +0000 (16:58 +0200)
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>
bgpd/bgp_dump.c
bgpd/bgp_dump.h
bgpd/bgp_fsm.c
bgpd/bgp_packet.c
bgpd/bgp_packet.h

index 751140850a3303e18b8f309138331426484a55fb..d12c0b6c751303b3eb8f969276e4e44e9a3ddb7c 100644 (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)
index f73081b2e204d7168ac77007bd9b7b8dd1c59fa5..5ec0561b05a2d26fdb08f48430f2b75575a832de 100644 (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 */
index dd765731dcabc02f158327c1836ae6b2ac466031..4348e6b240c68185c80a7745b58d88d1d551dbe8 100644 (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;
                }
index e907c6a10de8a9ff13def6db7c8ccf2c8655b2d7..da00c7b3fe2ce8cec5d2578d0cba79d28c9b85ab 100644 (file)
 #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;
index 06a190585b3d2c283a897858beb9952c6cb2c088..91031589a7d47bfc54e5a8962dce34f66a417ee7 100644 (file)
 #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