0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-16 18:35:19 +00:00

BMP: Minor cleanups

Remove redundant 'disable' option, simplify IP address serialization,
and remove useless macros.
This commit is contained in:
Ondrej Zajicek (work) 2021-03-28 15:36:59 +02:00 committed by Ondrej Zajicek
parent a995ed4386
commit 4adebdf198
5 changed files with 14 additions and 59 deletions

View File

@ -869,7 +869,7 @@ bgp_graceful_restart_timeout(timer *t)
else
{
bgp_stop(p, 0, NULL, 0);
bmp_peer_down(p, BE_NONE, NULL, BMP_PEER_DOWN_NULL_PKT_SIZE);
bmp_peer_down(p, BE_NONE, NULL, 0);
}
}
@ -996,7 +996,7 @@ bgp_sock_err(sock *sk, int err)
else
{
BGP_TRACE(D_EVENTS, "Connection closed");
bmp_peer_down(p, BE_SOCKET, NULL, BMP_PEER_DOWN_NULL_PKT_SIZE);
bmp_peer_down(p, BE_SOCKET, NULL, 0);
}
if ((conn->state == BS_ESTABLISHED) && p->gr_ready)
@ -1322,7 +1322,7 @@ bgp_neigh_notify(neighbor *n)
bgp_store_error(p, NULL, BE_MISC, BEM_NEIGHBOR_LOST);
/* Perhaps also run bgp_update_startup_delay(p)? */
bgp_stop(p, 0, NULL, 0);
bmp_peer_down(p, BE_MISC, NULL, BMP_PEER_DOWN_NULL_PKT_SIZE);
bmp_peer_down(p, BE_MISC, NULL, 0);
}
}
else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP))
@ -1334,7 +1334,7 @@ bgp_neigh_notify(neighbor *n)
if (ps == PS_UP)
bgp_update_startup_delay(p);
bgp_stop(p, 0, NULL, 0);
bmp_peer_down(p, BE_MISC, NULL, BMP_PEER_DOWN_NULL_PKT_SIZE);
bmp_peer_down(p, BE_MISC, NULL, 0);
}
}
else
@ -1376,7 +1376,7 @@ bgp_bfd_notify(struct bfd_request *req)
if (ps == PS_UP)
bgp_update_startup_delay(p);
bgp_stop(p, 0, NULL, 0);
bmp_peer_down(p, BE_MISC, NULL, BMP_PEER_DOWN_NULL_PKT_SIZE);
bmp_peer_down(p, BE_MISC, NULL, 0);
}
}
}

View File

@ -671,7 +671,6 @@ byte * bgp_create_end_mark(struct bgp_channel *c, byte *buf);
#define PKT_ROUTE_REFRESH 0x05 /* [RFC2918] */
#define PKT_BEGIN_REFRESH 0x1e /* Dummy type for BoRR packet [RFC7313] */
#define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */
#define PKT_BMP_MSG 0x20 /* BGP Monitoring Protocol message [RFC7854] */
/* Attributes */

View File

@ -377,12 +377,12 @@ bmp_sock_err(sock *sk, int err)
log(L_WARN "[BMP:%s] Socket error: %M", conn->bmp->p.name, err);
}
static void
bmp_put_ip4_addr_with_padding(buffer *stream, const ip4_addr addr)
static inline void
bmp_put_ipa(buffer *stream, const ip_addr addr)
{
byte padding[BMP_PADDING_IP4_ADDR_SIZE] = { 0x00 };
bmp_put_data(stream, padding, BMP_PADDING_IP4_ADDR_SIZE);
bmp_put_ip4(stream, addr);
bmp_put_ip6(stream, ipa_is_ip4(addr) ?
ip6_build(0,0,0, ipa_to_u32(addr)) :
ipa_to_ip6(addr));
}
static void
@ -434,15 +434,7 @@ bmp_per_peer_hdr_serialize(buffer *stream, const bool is_global_instance_peer,
bmp_put_u8(stream, peer_flags);
// TODO: Provide appropriate peer Route Distinguisher if applicable
bmp_put_u64(stream, 0x00); // 0x00 - Not supported peer distinguisher
if (ipa_is_ip4(peer_addr))
{
bmp_put_ip4_addr_with_padding(stream, ipa_to_ip4(peer_addr));
}
else
{
bmp_put_ip6(stream, ipa_to_ip6(peer_addr));
}
bmp_put_ipa(stream, peer_addr);
bmp_put_u32(stream, peer_as);
bmp_put_u32(stream, peer_bgp_id);
bmp_put_u32(stream, ts_sec);
@ -478,15 +470,7 @@ bmp_peer_up_notif_msg_serialize(buffer *stream, const bool is_peer_global,
bmp_per_peer_hdr_serialize(stream, is_peer_global,
true /* TODO: Hardcoded pre-policy Adj-RIB-In */, as4_support, remote_addr,
peer_as, peer_bgp_id, 0, 0); // 0, 0 - No timestamp provided
if (ipa_is_ip4(local_addr))
{
bmp_put_ip4_addr_with_padding(stream, ipa_to_ip4(local_addr));
}
else
{
bmp_put_ip6(stream, ipa_to_ip6(local_addr));
}
bmp_put_ipa(stream, local_addr);
bmp_put_u16(stream, local_port);
bmp_put_u16(stream, remote_port);
bmp_set_initial_bgp_hdr(stream, sent_msg_size, PKT_OPEN);
@ -1115,7 +1099,6 @@ bmp_init(struct proto_config *CF)
p->station_port = cf->station_port;
strcpy(p->sys_descr, cf->sys_descr);
strcpy(p->sys_name, cf->sys_name);
p->disabled = cf->disabled;
p->monitoring_rib.in_pre_policy = cf->monitoring_rib_in_pre_policy;
p->monitoring_rib.in_post_policy = cf->monitoring_rib_in_post_policy;
p->monitoring_rib.local = cf->monitoring_rib_local;
@ -1128,17 +1111,6 @@ bmp_start(struct proto *P)
{
struct bmp_proto *p = (void *) P;
if (p->disabled)
{
g_bmp = NULL;
return PS_DOWN;
}
if (p->disabled)
{
return PS_DOWN;
}
p->conn = mb_allocz(P->pool, sizeof (struct bmp_conn));
p->conn->bmp = p;
bmp_setup_socket(p->conn);

View File

@ -23,12 +23,6 @@
// Max length of MIB-II description object
#define MIB_II_STR_LEN 255
enum bmp_peer_down {
// Value of packet size of 'pkt_size' argument of bmp_peer_down() function
// used for pointing out that there was not any packet to pass
BMP_PEER_DOWN_NULL_PKT_SIZE = 0
};
// The following fields of this structure controls whether there will be put
// specific routes into Route Monitoring message and send to BMP collector
struct monitoring_rib {
@ -43,7 +37,6 @@ struct bmp_config {
const char *sys_name; // sysName MIB-II [RFC1213] object
ip_addr station_ip; // Monitoring station address
u16 station_port; // Monitoring station TCP port
bool disabled; // Manually disabled
bool monitoring_rib_in_pre_policy; // Route monitoring pre-policy Adj-Rib-In
bool monitoring_rib_in_post_policy; // Route monitoring post-policy Adj-Rib-In
bool monitoring_rib_local; // Route monitoring Local Rib
@ -82,10 +75,8 @@ struct bmp_proto {
char sys_name[MIB_II_STR_LEN]; // sysName MIB-II [RFC1213] object
ip_addr station_ip; // Monitoring station IP address
u16 station_port; // Monitoring station TCP port
bool disabled; // Manually disabled
struct monitoring_rib monitoring_rib;
// Below fields are for internal use
int station_socket; // Socket associated with the BMP collector
struct bmp_peer_map bgp_peers; // Stores 'bgp_proto' structure per BGP peer
struct bmp_peer_open_msg peer_open_msg; // Stores sent and received BGP OPEN MSG per BGP peer
pool *buffer_mpool; // Memory pool used for BMP buffer allocations

View File

@ -25,7 +25,6 @@ proto: bmp_proto '}' ;
bmp_proto_start: proto_start BMP {
this_proto = proto_config_new(&proto_bmp, $1);
BMP_CFG->disabled = false;
BMP_CFG->station_ip = IPA_NONE4;
BMP_CFG->station_port = 0;
BMP_CFG->sys_descr = "Not defined";
@ -39,9 +38,8 @@ bmp_proto_start: proto_start BMP {
bmp_station_address:
/* empty */
| bmp_station_address IP ipa {
if (!BMP_CFG->disabled)
if (ipa_zero($3))
cf_error("Invalid BMP monitoring station IP address");
if (ipa_zero($3))
cf_error("Invalid BMP monitoring station IP address");
BMP_CFG->station_ip = $3;
}
| bmp_station_address PORT expr {
@ -54,9 +52,6 @@ bmp_station_address:
bmp_proto:
bmp_proto_start proto_name '{'
| bmp_proto proto_item ';'
| bmp_proto ENABLED bool ';' {
BMP_CFG->disabled = $3;
}
| bmp_proto STATION ADDRESS bmp_station_address ';'
| bmp_proto SYSTEM DESCRIPTION text ';' {
if (!$4 || (strlen($4) == 0))
@ -81,8 +76,6 @@ bmp_proto:
| bmp_proto MONITORING RIB LOCAL bool ';' {
BMP_CFG->monitoring_rib_local = $5;
}
| bmp_proto DISABLED bool ';' {
BMP_CFG->disabled = $3; }
;
CF_CODE