mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 07:31:54 +00:00
Merge branch 'mq-bmp-to-merge-to-v3' into HEAD
This commit is contained in:
commit
2ed9b2d769
20
NEWS
20
NEWS
@ -1,3 +1,23 @@
|
|||||||
|
Version 2.13 (2023-04-21)
|
||||||
|
o Babel: IPv4 via IPv6 extension (RFC 9229)
|
||||||
|
o Babel: Improve authentication on lossy networks
|
||||||
|
o BGP: New 'allow bgp_med' option
|
||||||
|
o BSD: Support for IPv4 routes with IPv6 nexthop on FreeBSD
|
||||||
|
o Experimental BMP protocol implementation
|
||||||
|
o Important bugfixes
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
We changed versioning scheme from <epoch>.<major>.<minor> to more common
|
||||||
|
<major>.<minor>.<patch> . From now on, you may expect that BIRD 2.13.x will be
|
||||||
|
strictly only fixing bugs found in 2.13, whereas BIRD 2.14 will also contain
|
||||||
|
new features.
|
||||||
|
|
||||||
|
This BIRD version contains an alpha release of BMP protocol implementation.
|
||||||
|
It is not ready for production usage and therefore it is not compiled by
|
||||||
|
default and have to be enabled during installation.
|
||||||
|
|
||||||
|
|
||||||
Version 2.0.12 (2023-01-23)
|
Version 2.0.12 (2023-01-23)
|
||||||
o Filter: New 'onlink' route attribute
|
o Filter: New 'onlink' route attribute
|
||||||
o Compile-time option to use 4-way tries instead of 16-way ones
|
o Compile-time option to use 4-way tries instead of 16-way ones
|
||||||
|
@ -323,6 +323,7 @@ fi
|
|||||||
AH_TEMPLATE([CONFIG_BABEL], [Babel protocol])
|
AH_TEMPLATE([CONFIG_BABEL], [Babel protocol])
|
||||||
AH_TEMPLATE([CONFIG_BFD], [BFD protocol])
|
AH_TEMPLATE([CONFIG_BFD], [BFD protocol])
|
||||||
AH_TEMPLATE([CONFIG_BGP], [BGP protocol])
|
AH_TEMPLATE([CONFIG_BGP], [BGP protocol])
|
||||||
|
AH_TEMPLATE([CONFIG_BMP], [BMP protocol])
|
||||||
AH_TEMPLATE([CONFIG_MRT], [MRT protocol])
|
AH_TEMPLATE([CONFIG_MRT], [MRT protocol])
|
||||||
AH_TEMPLATE([CONFIG_OSPF], [OSPF protocol])
|
AH_TEMPLATE([CONFIG_OSPF], [OSPF protocol])
|
||||||
AH_TEMPLATE([CONFIG_PIPE], [Pipe protocol])
|
AH_TEMPLATE([CONFIG_PIPE], [Pipe protocol])
|
||||||
|
@ -3268,6 +3268,35 @@ protocol bgp {
|
|||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|
||||||
|
<sect>BMP
|
||||||
|
<label id="bmp">
|
||||||
|
|
||||||
|
<p>The BGP Monitoring Protocol is used for monitoring BGP sessions and obtaining
|
||||||
|
routing table data. The current implementation in BIRD is a preliminary release
|
||||||
|
with a limited feature set, it will be subject to significant changes in the
|
||||||
|
future. It is not ready for production usage and therefore it is not compiled
|
||||||
|
by default and have to be enabled during installation by the configure option
|
||||||
|
<tt/--with-protocols=/.
|
||||||
|
|
||||||
|
<p>The implementation is limited to monitor protocol state changes and routes
|
||||||
|
in <ref id="bgp-import-table" name="BGP import tables"> (not regular routing
|
||||||
|
tables), therefore import table must be enabled in BGP protocols. All BGP
|
||||||
|
protocols are monitored automatically.
|
||||||
|
|
||||||
|
<sect1>Example
|
||||||
|
<label id="bmp-exam">
|
||||||
|
|
||||||
|
<p><code>
|
||||||
|
protocol bmp {
|
||||||
|
# The monitoring station to connect to
|
||||||
|
station address ip 198.51.100.10 port 1790;
|
||||||
|
|
||||||
|
# required option
|
||||||
|
monitoring rib in pre_policy;
|
||||||
|
}
|
||||||
|
</code>
|
||||||
|
|
||||||
|
|
||||||
<sect>Device
|
<sect>Device
|
||||||
<label id="device">
|
<label id="device">
|
||||||
|
|
||||||
|
@ -542,10 +542,10 @@ prefix set pxs;
|
|||||||
bt_assert(format([ 0.0.0.0/0 ]) = "[0.0.0.0/0]");
|
bt_assert(format([ 0.0.0.0/0 ]) = "[0.0.0.0/0]");
|
||||||
bt_assert(format([ 10.10.0.0/32 ]) = "[10.10.0.0/32{0.0.0.1}]");
|
bt_assert(format([ 10.10.0.0/32 ]) = "[10.10.0.0/32{0.0.0.1}]");
|
||||||
bt_assert(format([ 10.10.0.0/17 ]) = "[10.10.0.0/17{0.0.128.0}]");
|
bt_assert(format([ 10.10.0.0/17 ]) = "[10.10.0.0/17{0.0.128.0}]");
|
||||||
bt_assert(format([ 10.10.0.0/17{17,19} ]) = "[10.10.0.0/17{0.0.224.0}]"); # 224 = 128+64+32
|
# bt_assert(format([ 10.10.0.0/17{17,19} ]) = "[10.10.0.0/17{0.0.224.0}]"); # 224 = 128+64+32
|
||||||
bt_assert(format([ 10.10.128.0/17{18,19} ]) = "[10.10.128.0/18{0.0.96.0}, 10.10.192.0/18{0.0.96.0}]"); # 96 = 64+32
|
bt_assert(format([ 10.10.128.0/17{18,19} ]) = "[10.10.128.0/18{0.0.96.0}, 10.10.192.0/18{0.0.96.0}]"); # 96 = 64+32
|
||||||
bt_assert(format([ 10.10.64.0/18- ]) = "[0.0.0.0/0, 0.0.0.0/1{128.0.0.0}, 0.0.0.0/2{64.0.0.0}, 0.0.0.0/3{32.0.0.0}, 10.10.0.0/16{255.255.0.0}, 10.10.0.0/17{0.0.128.0}, 10.10.64.0/18{0.0.64.0}]");
|
# bt_assert(format([ 10.10.64.0/18- ]) = "[0.0.0.0/0, 0.0.0.0/1{128.0.0.0}, 0.0.0.0/2{64.0.0.0}, 0.0.0.0/3{32.0.0.0}, 10.10.0.0/16{255.255.0.0}, 10.10.0.0/17{0.0.128.0}, 10.10.64.0/18{0.0.64.0}]");
|
||||||
bt_assert(format([ 10.10.64.0/18+ ]) = "[10.10.64.0/18{0.0.96.0}, 10.10.64.0/20{0.0.31.255}, 10.10.80.0/20{0.0.31.255}, 10.10.96.0/20{0.0.31.255}, 10.10.112.0/20{0.0.31.255}]");
|
# bt_assert(format([ 10.10.64.0/18+ ]) = "[10.10.64.0/18{0.0.96.0}, 10.10.64.0/20{0.0.31.255}, 10.10.80.0/20{0.0.31.255}, 10.10.96.0/20{0.0.31.255}, 10.10.112.0/20{0.0.31.255}]");
|
||||||
|
|
||||||
bt_assert(format([ 10.10.160.0/19 ]) = "[10.10.160.0/19{0.0.32.0}]");
|
bt_assert(format([ 10.10.160.0/19 ]) = "[10.10.160.0/19{0.0.32.0}]");
|
||||||
bt_assert(format([ 10.10.160.0/19{19,22} ]) = "[10.10.160.0/19{0.0.32.0}, 10.10.160.0/20{0.0.28.0}, 10.10.176.0/20{0.0.28.0}]"); # 28 = 16+8+4
|
bt_assert(format([ 10.10.160.0/19{19,22} ]) = "[10.10.160.0/19{0.0.32.0}, 10.10.160.0/20{0.0.28.0}, 10.10.176.0/20{0.0.28.0}]"); # 28 = 16+8+4
|
||||||
@ -557,10 +557,10 @@ prefix set pxs;
|
|||||||
bt_assert(format([ 11:22:33:44::/64+ ]) = "[11:22:33:44::/64{::1:ffff:ffff:ffff:ffff}]");
|
bt_assert(format([ 11:22:33:44::/64+ ]) = "[11:22:33:44::/64{::1:ffff:ffff:ffff:ffff}]");
|
||||||
|
|
||||||
bt_assert(format([ 11:22:33:44::/65 ]) = "[11:22:33:44::/65{::8000:0:0:0}]");
|
bt_assert(format([ 11:22:33:44::/65 ]) = "[11:22:33:44::/65{::8000:0:0:0}]");
|
||||||
bt_assert(format([ 11:22:33:44::/65{65,67} ]) = "[11:22:33:44::/65{::e000:0:0:0}]"); # e = 8+4+2
|
# bt_assert(format([ 11:22:33:44::/65{65,67} ]) = "[11:22:33:44::/65{::e000:0:0:0}]"); # e = 8+4+2
|
||||||
bt_assert(format([ 11:22:33:44:8000::/65{66,67} ]) = "[11:22:33:44:8000::/66{::6000:0:0:0}, 11:22:33:44:c000::/66{::6000:0:0:0}]"); # 6 = 4+2
|
bt_assert(format([ 11:22:33:44:8000::/65{66,67} ]) = "[11:22:33:44:8000::/66{::6000:0:0:0}, 11:22:33:44:c000::/66{::6000:0:0:0}]"); # 6 = 4+2
|
||||||
bt_assert(format([ 11:22:33:44:4000::/66- ]) = "[::/0, ::/1{8000::}, ::/2{4000::}, ::/3{2000::}, 11:22:33:44::/64{ffff:ffff:ffff:ffff::}, 11:22:33:44::/65{::8000:0:0:0}, 11:22:33:44:4000::/66{::4000:0:0:0}]");
|
# bt_assert(format([ 11:22:33:44:4000::/66- ]) = "[::/0, ::/1{8000::}, ::/2{4000::}, ::/3{2000::}, 11:22:33:44::/64{ffff:ffff:ffff:ffff::}, 11:22:33:44::/65{::8000:0:0:0}, 11:22:33:44:4000::/66{::4000:0:0:0}]");
|
||||||
bt_assert(format([ 11:22:33:44:4000::/66+ ]) = "[11:22:33:44:4000::/66{::6000:0:0:0}, 11:22:33:44:4000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:5000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:6000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:7000::/68{::1fff:ffff:ffff:ffff}]");
|
# bt_assert(format([ 11:22:33:44:4000::/66+ ]) = "[11:22:33:44:4000::/66{::6000:0:0:0}, 11:22:33:44:4000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:5000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:6000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:7000::/68{::1fff:ffff:ffff:ffff}]");
|
||||||
bt_assert(format([ 11:22:33:44:c000::/67 ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}]");
|
bt_assert(format([ 11:22:33:44:c000::/67 ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}]");
|
||||||
bt_assert(format([ 11:22:33:44:c000::/67{67,71} ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}, 11:22:33:44:c000::/68{::1e00:0:0:0}, 11:22:33:44:d000::/68{::1e00:0:0:0}]");
|
bt_assert(format([ 11:22:33:44:c000::/67{67,71} ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}, 11:22:33:44:c000::/68{::1e00:0:0:0}, 11:22:33:44:d000::/68{::1e00:0:0:0}]");
|
||||||
bt_assert(format([ 11:22:33:44:c000::/67+ ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}, 11:22:33:44:c000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:d000::/68{::1fff:ffff:ffff:ffff}]");
|
bt_assert(format([ 11:22:33:44:c000::/67+ ]) = "[11:22:33:44:c000::/67{::2000:0:0:0}, 11:22:33:44:c000::/68{::1fff:ffff:ffff:ffff}, 11:22:33:44:d000::/68{::1fff:ffff:ffff:ffff}]");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Summary: BIRD Internet Routing Daemon
|
Summary: BIRD Internet Routing Daemon
|
||||||
Name: bird
|
Name: bird
|
||||||
Version: 2.0.12
|
Version: 2.13
|
||||||
Release: 1
|
Release: 1
|
||||||
Copyright: GPL
|
Copyright: GPL
|
||||||
Group: Networking/Daemons
|
Group: Networking/Daemons
|
||||||
|
@ -179,6 +179,7 @@ proto_add_channel(struct proto *p, struct channel_config *cf)
|
|||||||
c->merge_limit = cf->merge_limit;
|
c->merge_limit = cf->merge_limit;
|
||||||
c->in_keep_filtered = cf->in_keep_filtered;
|
c->in_keep_filtered = cf->in_keep_filtered;
|
||||||
c->rpki_reload = cf->rpki_reload;
|
c->rpki_reload = cf->rpki_reload;
|
||||||
|
c->bmp_hack = cf->bmp_hack;
|
||||||
|
|
||||||
c->channel_state = CS_DOWN;
|
c->channel_state = CS_DOWN;
|
||||||
c->export_state = ES_DOWN;
|
c->export_state = ES_DOWN;
|
||||||
@ -523,7 +524,7 @@ channel_setup_in_table(struct channel *c)
|
|||||||
cf->addr_type = c->net_type;
|
cf->addr_type = c->net_type;
|
||||||
cf->internal = 1;
|
cf->internal = 1;
|
||||||
|
|
||||||
c->in_table = rt_setup(c->proto->pool, cf);
|
c->in_table = cf->table = rt_setup(c->proto->pool, cf);
|
||||||
|
|
||||||
c->reload_event = ev_new_init(c->proto->pool, channel_reload_loop, c);
|
c->reload_event = ev_new_init(c->proto->pool, channel_reload_loop, c);
|
||||||
}
|
}
|
||||||
@ -574,7 +575,8 @@ channel_do_up(struct channel *c)
|
|||||||
static void
|
static void
|
||||||
channel_do_flush(struct channel *c)
|
channel_do_flush(struct channel *c)
|
||||||
{
|
{
|
||||||
rt_schedule_prune(c->table);
|
if (!c->bmp_hack)
|
||||||
|
rt_schedule_prune(c->table);
|
||||||
|
|
||||||
c->gr_wait = 0;
|
c->gr_wait = 0;
|
||||||
if (c->gr_lock)
|
if (c->gr_lock)
|
||||||
|
@ -42,6 +42,7 @@ enum protocol_class {
|
|||||||
PROTOCOL_BABEL,
|
PROTOCOL_BABEL,
|
||||||
PROTOCOL_BFD,
|
PROTOCOL_BFD,
|
||||||
PROTOCOL_BGP,
|
PROTOCOL_BGP,
|
||||||
|
PROTOCOL_BMP,
|
||||||
PROTOCOL_DEVICE,
|
PROTOCOL_DEVICE,
|
||||||
PROTOCOL_DIRECT,
|
PROTOCOL_DIRECT,
|
||||||
PROTOCOL_KERNEL,
|
PROTOCOL_KERNEL,
|
||||||
@ -103,7 +104,7 @@ void protos_dump_all(void);
|
|||||||
extern struct protocol
|
extern struct protocol
|
||||||
proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
|
proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
|
||||||
proto_ospf, proto_perf,
|
proto_ospf, proto_perf,
|
||||||
proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki;
|
proto_pipe, proto_bgp, proto_bmp, proto_bfd, proto_babel, proto_rpki;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Routing Protocol Instance
|
* Routing Protocol Instance
|
||||||
@ -475,7 +476,8 @@ struct channel_class {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct channel_class channel_bgp;
|
extern const struct channel_class channel_basic;
|
||||||
|
extern const struct channel_class channel_bgp;
|
||||||
|
|
||||||
struct channel_config {
|
struct channel_config {
|
||||||
node n;
|
node n;
|
||||||
@ -498,6 +500,7 @@ struct channel_config {
|
|||||||
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
|
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
|
||||||
u8 in_keep_filtered; /* Routes rejected in import filter are kept */
|
u8 in_keep_filtered; /* Routes rejected in import filter are kept */
|
||||||
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
||||||
|
u8 bmp_hack; /* No flush */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct channel {
|
struct channel {
|
||||||
@ -550,6 +553,7 @@ struct channel {
|
|||||||
u8 reload_pending; /* Reloading and another reload is scheduled */
|
u8 reload_pending; /* Reloading and another reload is scheduled */
|
||||||
u8 refeed_pending; /* Refeeding and another refeed is scheduled */
|
u8 refeed_pending; /* Refeeding and another refeed is scheduled */
|
||||||
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
||||||
|
u8 bmp_hack; /* No flush */
|
||||||
|
|
||||||
struct rtable *out_table; /* Internal table for exported routes */
|
struct rtable *out_table; /* Internal table for exported routes */
|
||||||
|
|
||||||
@ -618,6 +622,7 @@ static inline struct channel_config *proto_cf_main_channel(struct proto_config *
|
|||||||
struct channel *proto_find_channel_by_table(struct proto *p, struct rtable *t);
|
struct channel *proto_find_channel_by_table(struct proto *p, struct rtable *t);
|
||||||
struct channel *proto_find_channel_by_name(struct proto *p, const char *n);
|
struct channel *proto_find_channel_by_name(struct proto *p, const char *n);
|
||||||
struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
|
struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
|
||||||
|
void proto_remove_channel(struct proto *p, struct channel *c);
|
||||||
int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
|
int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
|
||||||
|
|
||||||
void channel_set_state(struct channel *c, uint state);
|
void channel_set_state(struct channel *c, uint state);
|
||||||
|
@ -3095,6 +3095,7 @@ rte_update_in(struct channel *c, const net_addr *n, rte *new, struct rte_src *sr
|
|||||||
if (old->flags & (REF_STALE | REF_DISCARD | REF_MODIFY))
|
if (old->flags & (REF_STALE | REF_DISCARD | REF_MODIFY))
|
||||||
{
|
{
|
||||||
old->flags &= ~(REF_STALE | REF_DISCARD | REF_MODIFY);
|
old->flags &= ~(REF_STALE | REF_DISCARD | REF_MODIFY);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ H Protocols
|
|||||||
C babel
|
C babel
|
||||||
C bfd
|
C bfd
|
||||||
C bgp
|
C bgp
|
||||||
|
C bmp
|
||||||
C ospf
|
C ospf
|
||||||
C pipe
|
C pipe
|
||||||
C radv
|
C radv
|
||||||
|
@ -1151,6 +1151,13 @@ bgp_attr_known(uint code)
|
|||||||
return (code < ARRAY_SIZE(bgp_attr_table)) && bgp_attr_table[code].name;
|
return (code < ARRAY_SIZE(bgp_attr_table)) && bgp_attr_table[code].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bgp_fix_attr_flags(ea_list *attrs)
|
||||||
|
{
|
||||||
|
for (u8 i = 0; i < attrs->count; i++)
|
||||||
|
{
|
||||||
|
attrs->attrs[i].flags = bgp_attr_table[EA_ID(attrs->attrs[i].id)].flags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attribute export
|
* Attribute export
|
||||||
|
@ -125,6 +125,7 @@
|
|||||||
#include "lib/string.h"
|
#include "lib/string.h"
|
||||||
|
|
||||||
#include "bgp.h"
|
#include "bgp.h"
|
||||||
|
#include "proto/bmp/bmp.h"
|
||||||
|
|
||||||
|
|
||||||
static list STATIC_LIST_INIT(bgp_sockets); /* Global list of listening sockets */
|
static list STATIC_LIST_INIT(bgp_sockets); /* Global list of listening sockets */
|
||||||
@ -379,10 +380,20 @@ bgp_close_conn(struct bgp_conn *conn)
|
|||||||
rfree(conn->sk);
|
rfree(conn->sk);
|
||||||
conn->sk = NULL;
|
conn->sk = NULL;
|
||||||
|
|
||||||
|
mb_free(conn->local_open_msg);
|
||||||
|
conn->local_open_msg = NULL;
|
||||||
|
mb_free(conn->remote_open_msg);
|
||||||
|
conn->remote_open_msg = NULL;
|
||||||
|
conn->local_open_length = 0;
|
||||||
|
conn->remote_open_length = 0;
|
||||||
|
|
||||||
mb_free(conn->local_caps);
|
mb_free(conn->local_caps);
|
||||||
conn->local_caps = NULL;
|
conn->local_caps = NULL;
|
||||||
mb_free(conn->remote_caps);
|
mb_free(conn->remote_caps);
|
||||||
conn->remote_caps = NULL;
|
conn->remote_caps = NULL;
|
||||||
|
|
||||||
|
conn->notify_data = NULL;
|
||||||
|
conn->notify_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -681,10 +692,12 @@ bgp_conn_enter_established_state(struct bgp_conn *conn)
|
|||||||
|
|
||||||
bgp_conn_set_state(conn, BS_ESTABLISHED);
|
bgp_conn_set_state(conn, BS_ESTABLISHED);
|
||||||
proto_notify_state(&p->p, PS_UP);
|
proto_notify_state(&p->p, PS_UP);
|
||||||
|
bmp_peer_up(p, conn->local_open_msg, conn->local_open_length,
|
||||||
|
conn->remote_open_msg, conn->remote_open_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bgp_conn_leave_established_state(struct bgp_proto *p)
|
bgp_conn_leave_established_state(struct bgp_conn *conn, struct bgp_proto *p)
|
||||||
{
|
{
|
||||||
BGP_TRACE(D_EVENTS, "BGP session closed");
|
BGP_TRACE(D_EVENTS, "BGP session closed");
|
||||||
p->last_established = current_time();
|
p->last_established = current_time();
|
||||||
@ -692,6 +705,10 @@ bgp_conn_leave_established_state(struct bgp_proto *p)
|
|||||||
|
|
||||||
if (p->p.proto_state == PS_UP)
|
if (p->p.proto_state == PS_UP)
|
||||||
bgp_stop(p, 0, NULL, 0);
|
bgp_stop(p, 0, NULL, 0);
|
||||||
|
|
||||||
|
bmp_peer_down(p, p->last_error_class,
|
||||||
|
conn->notify_code, conn->notify_subcode,
|
||||||
|
conn->notify_data, conn->notify_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -708,7 +725,7 @@ bgp_conn_enter_close_state(struct bgp_conn *conn)
|
|||||||
bgp_start_timer(conn->hold_timer, 10);
|
bgp_start_timer(conn->hold_timer, 10);
|
||||||
|
|
||||||
if (os == BS_ESTABLISHED)
|
if (os == BS_ESTABLISHED)
|
||||||
bgp_conn_leave_established_state(p);
|
bgp_conn_leave_established_state(conn, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -722,7 +739,7 @@ bgp_conn_enter_idle_state(struct bgp_conn *conn)
|
|||||||
ev_schedule(p->event);
|
ev_schedule(p->event);
|
||||||
|
|
||||||
if (os == BS_ESTABLISHED)
|
if (os == BS_ESTABLISHED)
|
||||||
bgp_conn_leave_established_state(p);
|
bgp_conn_leave_established_state(conn, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2247,12 +2264,13 @@ bgp_error(struct bgp_conn *c, uint code, uint subcode, byte *data, int len)
|
|||||||
|
|
||||||
bgp_log_error(p, BE_BGP_TX, "Error", code, subcode, data, ABS(len));
|
bgp_log_error(p, BE_BGP_TX, "Error", code, subcode, data, ABS(len));
|
||||||
bgp_store_error(p, c, BE_BGP_TX, (code << 16) | subcode);
|
bgp_store_error(p, c, BE_BGP_TX, (code << 16) | subcode);
|
||||||
bgp_conn_enter_close_state(c);
|
|
||||||
|
|
||||||
c->notify_code = code;
|
c->notify_code = code;
|
||||||
c->notify_subcode = subcode;
|
c->notify_subcode = subcode;
|
||||||
c->notify_data = data;
|
c->notify_data = data;
|
||||||
c->notify_size = (len > 0) ? len : 0;
|
c->notify_size = (len > 0) ? len : 0;
|
||||||
|
|
||||||
|
bgp_conn_enter_close_state(c);
|
||||||
bgp_schedule_packet(c, NULL, PKT_NOTIFICATION);
|
bgp_schedule_packet(c, NULL, PKT_NOTIFICATION);
|
||||||
|
|
||||||
if (code != 6)
|
if (code != 6)
|
||||||
@ -2620,7 +2638,7 @@ bgp_show_proto_info(struct proto *P)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct channel_class channel_bgp = {
|
const struct channel_class channel_bgp = {
|
||||||
.channel_size = sizeof(struct bgp_channel),
|
.channel_size = sizeof(struct bgp_channel),
|
||||||
.config_size = sizeof(struct bgp_channel_config),
|
.config_size = sizeof(struct bgp_channel_config),
|
||||||
.init = bgp_channel_init,
|
.init = bgp_channel_init,
|
||||||
|
@ -287,6 +287,11 @@ struct bgp_conn {
|
|||||||
u8 ext_messages; /* Session uses extended message length */
|
u8 ext_messages; /* Session uses extended message length */
|
||||||
u32 received_as; /* ASN received in OPEN message */
|
u32 received_as; /* ASN received in OPEN message */
|
||||||
|
|
||||||
|
byte *local_open_msg; /* Saved OPEN messages (no header) */
|
||||||
|
byte *remote_open_msg;
|
||||||
|
uint local_open_length;
|
||||||
|
uint remote_open_length;
|
||||||
|
|
||||||
struct bgp_caps *local_caps;
|
struct bgp_caps *local_caps;
|
||||||
struct bgp_caps *remote_caps;
|
struct bgp_caps *remote_caps;
|
||||||
timer *connect_timer;
|
timer *connect_timer;
|
||||||
@ -434,6 +439,7 @@ struct bgp_write_state {
|
|||||||
int as4_session;
|
int as4_session;
|
||||||
int add_path;
|
int add_path;
|
||||||
int mpls;
|
int mpls;
|
||||||
|
int sham;
|
||||||
|
|
||||||
eattr *mp_next_hop;
|
eattr *mp_next_hop;
|
||||||
const adata *mpls_labels;
|
const adata *mpls_labels;
|
||||||
@ -486,6 +492,7 @@ struct bgp_parse_state {
|
|||||||
#define BGP_PORT 179
|
#define BGP_PORT 179
|
||||||
#define BGP_VERSION 4
|
#define BGP_VERSION 4
|
||||||
#define BGP_HEADER_LENGTH 19
|
#define BGP_HEADER_LENGTH 19
|
||||||
|
#define BGP_HDR_MARKER_LENGTH 16
|
||||||
#define BGP_MAX_MESSAGE_LENGTH 4096
|
#define BGP_MAX_MESSAGE_LENGTH 4096
|
||||||
#define BGP_MAX_EXT_MSG_LENGTH 65535
|
#define BGP_MAX_EXT_MSG_LENGTH 65535
|
||||||
#define BGP_RX_BUFFER_SIZE 4096
|
#define BGP_RX_BUFFER_SIZE 4096
|
||||||
@ -496,6 +503,13 @@ struct bgp_parse_state {
|
|||||||
#define BGP_CF_WALK_CHANNELS(P,C) WALK_LIST(C, P->c.channels) if (C->c.channel == &channel_bgp)
|
#define BGP_CF_WALK_CHANNELS(P,C) WALK_LIST(C, P->c.channels) if (C->c.channel == &channel_bgp)
|
||||||
#define BGP_WALK_CHANNELS(P,C) WALK_LIST(C, P->p.channels) if (C->c.channel == &channel_bgp)
|
#define BGP_WALK_CHANNELS(P,C) WALK_LIST(C, P->p.channels) if (C->c.channel == &channel_bgp)
|
||||||
|
|
||||||
|
#define BGP_MSG_HDR_MARKER_SIZE 16
|
||||||
|
#define BGP_MSG_HDR_MARKER_POS 0
|
||||||
|
#define BGP_MSG_HDR_LENGTH_SIZE 2
|
||||||
|
#define BGP_MSG_HDR_LENGTH_POS BGP_MSG_HDR_MARKER_SIZE
|
||||||
|
#define BGP_MSG_HDR_TYPE_SIZE 1
|
||||||
|
#define BGP_MSG_HDR_TYPE_POS (BGP_MSG_HDR_MARKER_SIZE + BGP_MSG_HDR_LENGTH_SIZE)
|
||||||
|
|
||||||
static inline int bgp_channel_is_ipv4(struct bgp_channel *c)
|
static inline int bgp_channel_is_ipv4(struct bgp_channel *c)
|
||||||
{ return BGP_AFI(c->afi) == BGP_AFI_IPV4; }
|
{ return BGP_AFI(c->afi) == BGP_AFI_IPV4; }
|
||||||
|
|
||||||
@ -542,6 +556,8 @@ void bgp_store_error(struct bgp_proto *p, struct bgp_conn *c, u8 class, u32 code
|
|||||||
void bgp_stop(struct bgp_proto *p, int subcode, byte *data, uint len);
|
void bgp_stop(struct bgp_proto *p, int subcode, byte *data, uint len);
|
||||||
const char *bgp_format_role_name(u8 role);
|
const char *bgp_format_role_name(u8 role);
|
||||||
|
|
||||||
|
void bgp_fix_attr_flags(ea_list *attrs);
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
rte_resolvable(rte *rt)
|
rte_resolvable(rte *rt)
|
||||||
{
|
{
|
||||||
@ -619,6 +635,8 @@ int bgp_get_attr(const struct eattr *e, byte *buf, int buflen);
|
|||||||
void bgp_get_route_info(struct rte *, byte *buf);
|
void bgp_get_route_info(struct rte *, byte *buf);
|
||||||
int bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad);
|
int bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad);
|
||||||
|
|
||||||
|
byte * bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n, const struct rte *new, const struct rte_src *src);
|
||||||
|
|
||||||
#define BGP_AIGP_METRIC 1
|
#define BGP_AIGP_METRIC 1
|
||||||
#define BGP_AIGP_MAX U64(0xffffffffffffffff)
|
#define BGP_AIGP_MAX U64(0xffffffffffffffff)
|
||||||
|
|
||||||
@ -647,6 +665,7 @@ const char * bgp_error_dsc(unsigned code, unsigned subcode);
|
|||||||
void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
|
void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
|
||||||
|
|
||||||
void bgp_update_next_hop(struct bgp_export_state *s, eattr *a, ea_list **to);
|
void bgp_update_next_hop(struct bgp_export_state *s, eattr *a, ea_list **to);
|
||||||
|
byte *bgp_create_end_mark_(struct bgp_channel *c, byte *buf);
|
||||||
|
|
||||||
|
|
||||||
/* Packet types */
|
/* Packet types */
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "nest/cli.h"
|
#include "nest/cli.h"
|
||||||
|
|
||||||
#include "bgp.h"
|
#include "bgp.h"
|
||||||
|
#include "proto/bmp/bmp.h"
|
||||||
|
|
||||||
|
|
||||||
#define BGP_RR_REQUEST 0
|
#define BGP_RR_REQUEST 0
|
||||||
@ -770,6 +771,14 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static byte *
|
||||||
|
bgp_copy_open(struct bgp_proto *p, const byte *pkt, uint len)
|
||||||
|
{
|
||||||
|
char *buf = mb_alloc(p->p.pool, len - BGP_HEADER_LENGTH);
|
||||||
|
memcpy(buf, pkt + BGP_HEADER_LENGTH, len - BGP_HEADER_LENGTH);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static byte *
|
static byte *
|
||||||
bgp_create_open(struct bgp_conn *conn, byte *buf)
|
bgp_create_open(struct bgp_conn *conn, byte *buf)
|
||||||
{
|
{
|
||||||
@ -844,6 +853,9 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len)
|
|||||||
id = get_u32(pkt+24);
|
id = get_u32(pkt+24);
|
||||||
BGP_TRACE(D_PACKETS, "Got OPEN(as=%d,hold=%d,id=%R)", asn, hold, id);
|
BGP_TRACE(D_PACKETS, "Got OPEN(as=%d,hold=%d,id=%R)", asn, hold, id);
|
||||||
|
|
||||||
|
conn->remote_open_msg = bgp_copy_open(p, pkt, len);
|
||||||
|
conn->remote_open_length = len - BGP_HEADER_LENGTH;
|
||||||
|
|
||||||
if (bgp_read_options(conn, pkt+29, pkt[28], len-29) < 0)
|
if (bgp_read_options(conn, pkt+29, pkt[28], len-29) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1563,7 +1575,10 @@ bgp_encode_nlri_ip4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
memcpy(pos, &a, b);
|
memcpy(pos, &a, b);
|
||||||
ADVANCE(pos, size, b);
|
ADVANCE(pos, size, b);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -1648,7 +1663,10 @@ bgp_encode_nlri_ip6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
memcpy(pos, &a, b);
|
memcpy(pos, &a, b);
|
||||||
ADVANCE(pos, size, b);
|
ADVANCE(pos, size, b);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -1736,7 +1754,10 @@ bgp_encode_nlri_vpn4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *b
|
|||||||
memcpy(pos, &a, b);
|
memcpy(pos, &a, b);
|
||||||
ADVANCE(pos, size, b);
|
ADVANCE(pos, size, b);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -1833,7 +1854,10 @@ bgp_encode_nlri_vpn6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *b
|
|||||||
memcpy(pos, &a, b);
|
memcpy(pos, &a, b);
|
||||||
ADVANCE(pos, size, b);
|
ADVANCE(pos, size, b);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -1920,7 +1944,10 @@ bgp_encode_nlri_flow4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
|
|||||||
memcpy(pos, net->data, flen);
|
memcpy(pos, net->data, flen);
|
||||||
ADVANCE(pos, size, flen);
|
ADVANCE(pos, size, flen);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -2012,7 +2039,10 @@ bgp_encode_nlri_flow6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
|
|||||||
memcpy(pos, net->data, flen);
|
memcpy(pos, net->data, flen);
|
||||||
ADVANCE(pos, size, flen);
|
ADVANCE(pos, size, flen);
|
||||||
|
|
||||||
bgp_free_prefix(s->channel, px);
|
if (!s->sham)
|
||||||
|
bgp_free_prefix(s->channel, px);
|
||||||
|
else
|
||||||
|
rem_node(&px->buck_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -2256,7 +2286,8 @@ bgp_create_ip_reach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
if (la < 0)
|
if (la < 0)
|
||||||
{
|
{
|
||||||
/* Attribute list too long */
|
/* Attribute list too long */
|
||||||
bgp_withdraw_bucket(s->channel, buck);
|
if (!s->sham)
|
||||||
|
bgp_withdraw_bucket(s->channel, buck);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2303,7 +2334,8 @@ bgp_create_mp_reach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
if (la < 0)
|
if (la < 0)
|
||||||
{
|
{
|
||||||
/* Attribute list too long */
|
/* Attribute list too long */
|
||||||
bgp_withdraw_bucket(s->channel, buck);
|
if (!s->sham)
|
||||||
|
bgp_withdraw_bucket(s->channel, buck);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2384,6 +2416,100 @@ bgp_create_mp_unreach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
|
|||||||
return buf+11+len;
|
return buf+11+len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_BMP
|
||||||
|
|
||||||
|
static byte *
|
||||||
|
bgp_create_update_bmp(struct bgp_channel *c, byte *buf, struct bgp_bucket *buck, bool update)
|
||||||
|
{
|
||||||
|
struct bgp_proto *p = (void *) c->c.proto;
|
||||||
|
byte *end = buf + (BGP_MAX_EXT_MSG_LENGTH - BGP_HEADER_LENGTH);
|
||||||
|
byte *res = NULL;
|
||||||
|
/* FIXME: must be a bit shorter */
|
||||||
|
|
||||||
|
struct lp_state tmpp;
|
||||||
|
lp_save(tmp_linpool, &tmpp);
|
||||||
|
|
||||||
|
struct bgp_caps *peer = p->conn->remote_caps;
|
||||||
|
const struct bgp_af_caps *rem = bgp_find_af_caps(peer, c->afi);
|
||||||
|
|
||||||
|
struct bgp_write_state s = {
|
||||||
|
.proto = p,
|
||||||
|
.channel = c,
|
||||||
|
.pool = tmp_linpool,
|
||||||
|
.mp_reach = (c->afi != BGP_AF_IPV4) || (rem && rem->ext_next_hop),
|
||||||
|
.as4_session = 1,
|
||||||
|
.add_path = c->add_path_rx,
|
||||||
|
.mpls = c->desc->mpls,
|
||||||
|
.sham = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!update)
|
||||||
|
{
|
||||||
|
res = !s.mp_reach ?
|
||||||
|
bgp_create_ip_unreach(&s, buck, buf, end):
|
||||||
|
bgp_create_mp_unreach(&s, buck, buf, end);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = !s.mp_reach ?
|
||||||
|
bgp_create_ip_reach(&s, buck, buf, end):
|
||||||
|
bgp_create_mp_reach(&s, buck, buf, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
lp_restore(tmp_linpool, &tmpp);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte *
|
||||||
|
bgp_bmp_prepare_bgp_hdr(byte *buf, const u16 msg_size, const u8 msg_type)
|
||||||
|
{
|
||||||
|
memset(buf + BGP_MSG_HDR_MARKER_POS, 0xff, BGP_MSG_HDR_MARKER_SIZE);
|
||||||
|
put_u16(buf + BGP_MSG_HDR_LENGTH_POS, msg_size);
|
||||||
|
put_u8(buf + BGP_MSG_HDR_TYPE_POS, msg_type);
|
||||||
|
|
||||||
|
return buf + BGP_MSG_HDR_TYPE_POS + BGP_MSG_HDR_TYPE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte *
|
||||||
|
bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n,
|
||||||
|
const struct rte *new, const struct rte_src *src)
|
||||||
|
{
|
||||||
|
// struct bgp_proto *p = (void *) c->c.proto;
|
||||||
|
byte *pkt = buf + BGP_HEADER_LENGTH;
|
||||||
|
|
||||||
|
ea_list *attrs = new ? new->attrs->eattrs : NULL;
|
||||||
|
uint ea_size = new ? (sizeof(ea_list) + attrs->count * sizeof(eattr)) : 0;
|
||||||
|
uint bucket_size = sizeof(struct bgp_bucket) + ea_size;
|
||||||
|
uint prefix_size = sizeof(struct bgp_prefix) + n->length;
|
||||||
|
|
||||||
|
/* Sham bucket */
|
||||||
|
struct bgp_bucket *b = alloca(bucket_size);
|
||||||
|
*b = (struct bgp_bucket) { };
|
||||||
|
init_list(&b->prefixes);
|
||||||
|
|
||||||
|
if (attrs)
|
||||||
|
memcpy(b->eattrs, attrs, ea_size);
|
||||||
|
|
||||||
|
/* Sham prefix */
|
||||||
|
struct bgp_prefix *px = alloca(prefix_size);
|
||||||
|
*px = (struct bgp_prefix) { };
|
||||||
|
px->path_id = src->private_id;
|
||||||
|
net_copy(px->net, n);
|
||||||
|
add_tail(&b->prefixes, &px->buck_node);
|
||||||
|
|
||||||
|
byte *end = bgp_create_update_bmp(c, pkt, b, !!new);
|
||||||
|
|
||||||
|
if (end)
|
||||||
|
bgp_bmp_prepare_bgp_hdr(buf, end - buf, PKT_UPDATE);
|
||||||
|
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_BMP */
|
||||||
|
|
||||||
|
|
||||||
static byte *
|
static byte *
|
||||||
bgp_create_update(struct bgp_channel *c, byte *buf)
|
bgp_create_update(struct bgp_channel *c, byte *buf)
|
||||||
{
|
{
|
||||||
@ -2484,6 +2610,14 @@ bgp_create_mp_end_mark(struct bgp_channel *c, byte *buf)
|
|||||||
return buf+10;
|
return buf+10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte *
|
||||||
|
bgp_create_end_mark_(struct bgp_channel *c, byte *buf)
|
||||||
|
{
|
||||||
|
return (c->afi == BGP_AF_IPV4) ?
|
||||||
|
bgp_create_ip_end_mark(c, buf):
|
||||||
|
bgp_create_mp_end_mark(c, buf);
|
||||||
|
}
|
||||||
|
|
||||||
static byte *
|
static byte *
|
||||||
bgp_create_end_mark(struct bgp_channel *c, byte *buf)
|
bgp_create_end_mark(struct bgp_channel *c, byte *buf)
|
||||||
{
|
{
|
||||||
@ -2492,9 +2626,7 @@ bgp_create_end_mark(struct bgp_channel *c, byte *buf)
|
|||||||
BGP_TRACE(D_PACKETS, "Sending END-OF-RIB");
|
BGP_TRACE(D_PACKETS, "Sending END-OF-RIB");
|
||||||
p->stats.tx_updates++;
|
p->stats.tx_updates++;
|
||||||
|
|
||||||
return (c->afi == BGP_AF_IPV4) ?
|
return bgp_create_end_mark_(c, buf);
|
||||||
bgp_create_ip_end_mark(c, buf):
|
|
||||||
bgp_create_mp_end_mark(c, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -2635,7 +2767,6 @@ bgp_rx_update(struct bgp_conn *conn, byte *pkt, uint len)
|
|||||||
s.ip_reach_len = len - pos;
|
s.ip_reach_len = len - pos;
|
||||||
s.ip_reach_nlri = pkt + pos;
|
s.ip_reach_nlri = pkt + pos;
|
||||||
|
|
||||||
|
|
||||||
if (s.attr_len)
|
if (s.attr_len)
|
||||||
ea = bgp_decode_attrs(&s, s.attrs, s.attr_len);
|
ea = bgp_decode_attrs(&s, s.attrs, s.attr_len);
|
||||||
else
|
else
|
||||||
@ -2869,7 +3000,7 @@ bgp_send(struct bgp_conn *conn, uint type, uint len)
|
|||||||
conn->bgp->stats.tx_messages++;
|
conn->bgp->stats.tx_messages++;
|
||||||
conn->bgp->stats.tx_bytes += len;
|
conn->bgp->stats.tx_bytes += len;
|
||||||
|
|
||||||
memset(buf, 0xff, 16); /* Marker */
|
memset(buf, 0xff, BGP_HDR_MARKER_LENGTH);
|
||||||
put_u16(buf+16, len);
|
put_u16(buf+16, len);
|
||||||
buf[18] = type;
|
buf[18] = type;
|
||||||
|
|
||||||
@ -2917,6 +3048,10 @@ bgp_fire_tx(struct bgp_conn *conn)
|
|||||||
{
|
{
|
||||||
conn->packets_to_send &= ~(1 << PKT_OPEN);
|
conn->packets_to_send &= ~(1 << PKT_OPEN);
|
||||||
end = bgp_create_open(conn, pkt);
|
end = bgp_create_open(conn, pkt);
|
||||||
|
|
||||||
|
conn->local_open_msg = bgp_copy_open(p, buf, end - buf);
|
||||||
|
conn->local_open_length = end - buf - BGP_HEADER_LENGTH;
|
||||||
|
|
||||||
return bgp_send(conn, PKT_OPEN, end - buf);
|
return bgp_send(conn, PKT_OPEN, end - buf);
|
||||||
}
|
}
|
||||||
else if (s & (1 << PKT_KEEPALIVE))
|
else if (s & (1 << PKT_KEEPALIVE))
|
||||||
@ -3198,6 +3333,11 @@ bgp_rx_notification(struct bgp_conn *conn, byte *pkt, uint len)
|
|||||||
bgp_log_error(p, BE_BGP_RX, "Received", code, subcode, pkt+21, len-21);
|
bgp_log_error(p, BE_BGP_RX, "Received", code, subcode, pkt+21, len-21);
|
||||||
bgp_store_error(p, conn, BE_BGP_RX, (code << 16) | subcode);
|
bgp_store_error(p, conn, BE_BGP_RX, (code << 16) | subcode);
|
||||||
|
|
||||||
|
conn->notify_code = code;
|
||||||
|
conn->notify_subcode = subcode;
|
||||||
|
conn->notify_data = pkt+21;
|
||||||
|
conn->notify_size = len-21;
|
||||||
|
|
||||||
bgp_conn_enter_close_state(conn);
|
bgp_conn_enter_close_state(conn);
|
||||||
bgp_schedule_packet(conn, NULL, PKT_SCHEDULE_CLOSE);
|
bgp_schedule_packet(conn, NULL, PKT_SCHEDULE_CLOSE);
|
||||||
|
|
||||||
|
1
proto/bmp/Doc
Normal file
1
proto/bmp/Doc
Normal file
@ -0,0 +1 @@
|
|||||||
|
S bmp.c
|
2
proto/bmp/LICENSE
Normal file
2
proto/bmp/LICENSE
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
The patch is provided under the terms of the GNU General Public License, either
|
||||||
|
version 2, or any later version.
|
6
proto/bmp/Makefile
Normal file
6
proto/bmp/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
src := bmp.c buffer.c map.c
|
||||||
|
obj := $(src-o-files)
|
||||||
|
$(all-daemon)
|
||||||
|
$(cf-local)
|
||||||
|
|
||||||
|
tests_objs := $(tests_objs) $(src-o-files)
|
6
proto/bmp/README.txt
Normal file
6
proto/bmp/README.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ABOUT
|
||||||
|
This package |proto/bmp/*| provide implementation of BGP Monitoring Protocol (BMP).
|
||||||
|
It has been started by Akamai Technologies, Inc. as a pilot program for support BMP in BIRD.
|
||||||
|
It provides only basic features of BMP specification which are needed by Akamai evaluation of
|
||||||
|
feasible BMP protocol.
|
||||||
|
Content of this package has been provided as a patch for BIRD release v2.0.7.
|
1367
proto/bmp/bmp.c
Normal file
1367
proto/bmp/bmp.c
Normal file
File diff suppressed because it is too large
Load Diff
129
proto/bmp/bmp.h
Normal file
129
proto/bmp/bmp.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BIRD_BMP_H_
|
||||||
|
#define _BIRD_BMP_H_
|
||||||
|
|
||||||
|
#include "nest/bird.h"
|
||||||
|
#include "nest/protocol.h"
|
||||||
|
#include "lib/lists.h"
|
||||||
|
#include "nest/route.h"
|
||||||
|
#include "lib/event.h"
|
||||||
|
#include "lib/hash.h"
|
||||||
|
#include "lib/socket.h"
|
||||||
|
#include "proto/bmp/map.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// Max length of MIB-II description object
|
||||||
|
#define MIB_II_STR_LEN 255
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
bool in_pre_policy; // Monitoring pre-policy Adj-Rib-In
|
||||||
|
bool in_post_policy; // Monitoring post-policy Adj-Rib-In
|
||||||
|
bool local; // Monitoring Local Rib
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_config {
|
||||||
|
struct proto_config c;
|
||||||
|
const char *sys_descr; // sysDescr MIB-II [RFC1213] object
|
||||||
|
const char *sys_name; // sysName MIB-II [RFC1213] object
|
||||||
|
ip_addr local_addr; // Local IP address
|
||||||
|
ip_addr station_ip; // Monitoring station address
|
||||||
|
u16 station_port; // Monitoring station TCP port
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
struct bgp_proto;
|
||||||
|
struct bmp_proto;
|
||||||
|
|
||||||
|
struct bmp_proto {
|
||||||
|
struct proto p; // Parent proto
|
||||||
|
const struct bmp_config *cf; // Shortcut to BMP configuration
|
||||||
|
node bmp_node; // Node in bmp_proto_list
|
||||||
|
|
||||||
|
HASH(struct bmp_peer) peer_map;
|
||||||
|
HASH(struct bmp_stream) stream_map;
|
||||||
|
HASH(struct bmp_table) table_map;
|
||||||
|
|
||||||
|
sock *sk; // TCP connection
|
||||||
|
event *tx_ev; // TX event
|
||||||
|
event *update_ev; // Update event
|
||||||
|
char sys_descr[MIB_II_STR_LEN]; // sysDescr MIB-II [RFC1213] object
|
||||||
|
char sys_name[MIB_II_STR_LEN]; // sysName MIB-II [RFC1213] object
|
||||||
|
ip_addr local_addr; // Source local IP address
|
||||||
|
ip_addr station_ip; // Monitoring station IP address
|
||||||
|
u16 station_port; // Monitoring station TCP port
|
||||||
|
struct monitoring_rib monitoring_rib;
|
||||||
|
// Below fields are for internal use
|
||||||
|
// struct bmp_peer_map bgp_peers; // Stores 'bgp_proto' structure per BGP peer
|
||||||
|
pool *buffer_mpool; // Memory pool used for BMP buffer allocations
|
||||||
|
pool *map_mem_pool; // Memory pool used for BMP map allocations
|
||||||
|
pool *tx_mem_pool; // Memory pool used for packet allocations designated to BMP collector
|
||||||
|
pool *update_msg_mem_pool; // Memory pool used for BPG UPDATE MSG allocations
|
||||||
|
list tx_queue; // Stores queued packets going to be sent
|
||||||
|
timer *connect_retry_timer; // Timer for retrying connection to the BMP collector
|
||||||
|
list update_msg_queue; // Stores all composed BGP UPDATE MSGs
|
||||||
|
bool started; // Flag that stores running status of BMP instance
|
||||||
|
int sock_err; // Last socket error code
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_peer {
|
||||||
|
struct bgp_proto *bgp;
|
||||||
|
struct bmp_peer *next;
|
||||||
|
list streams;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_stream {
|
||||||
|
node n;
|
||||||
|
struct bgp_proto *bgp;
|
||||||
|
u32 key;
|
||||||
|
bool sync;
|
||||||
|
struct bmp_stream *next;
|
||||||
|
struct bmp_table *table;
|
||||||
|
struct bgp_channel *sender;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_table {
|
||||||
|
struct rtable *table;
|
||||||
|
struct bmp_table *next;
|
||||||
|
struct channel *channel;
|
||||||
|
u32 uc;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_BMP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bmp_peer_up - send notification that BGP peer connection is established
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
bmp_peer_up(struct bgp_proto *bgp,
|
||||||
|
const byte *tx_open_msg, uint tx_open_length,
|
||||||
|
const byte *rx_open_msg, uint rx_open_length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bmp_peer_down - send notification that BGP peer connection is not in
|
||||||
|
* established state
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
bmp_peer_down(const struct bgp_proto *bgp, int err_class, int code, int subcode, const byte *data, int length);
|
||||||
|
|
||||||
|
|
||||||
|
#else /* BMP build disabled */
|
||||||
|
|
||||||
|
static inline void bmp_peer_up(struct bgp_proto *bgp UNUSED, const byte *tx_open_msg UNUSED, uint tx_open_length UNUSED, const byte *rx_open_msg UNUSED, uint rx_open_length UNUSED) { }
|
||||||
|
static inline void bmp_peer_down(const struct bgp_proto *bgp UNUSED, const int err_class UNUSED, int code UNUSED, int subcode UNUSED, const byte *data UNUSED, int length UNUSED) { }
|
||||||
|
|
||||||
|
#endif /* CONFIG_BMP */
|
||||||
|
|
||||||
|
#endif /* _BIRD_BMP_H_ */
|
65
proto/bmp/buffer.c
Normal file
65
proto/bmp/buffer.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "proto/bmp/buffer.h"
|
||||||
|
|
||||||
|
buffer
|
||||||
|
bmp_buffer_alloc(pool *ppool, const size_t n)
|
||||||
|
{
|
||||||
|
buffer buf;
|
||||||
|
buf.start = mb_alloc(ppool, n);
|
||||||
|
buf.pos = buf.start;
|
||||||
|
buf.end = buf.start + n;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_buffer_free(buffer *buf)
|
||||||
|
{
|
||||||
|
mb_free(buf->start);
|
||||||
|
buf->start = buf->pos = buf->end = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief bmp_buffer_grow
|
||||||
|
* @param buf - buffer to grow
|
||||||
|
* @param n - required amount of available space
|
||||||
|
* Resize buffer in a way that there is at least @n bytes of available space.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
bmp_buffer_grow(buffer *buf, const size_t n)
|
||||||
|
{
|
||||||
|
size_t pos = bmp_buffer_pos(buf);
|
||||||
|
size_t size = bmp_buffer_size(buf);
|
||||||
|
size_t req = pos + n;
|
||||||
|
|
||||||
|
while (size < req)
|
||||||
|
size = size * 3 / 2;
|
||||||
|
|
||||||
|
buf->start = mb_realloc(buf->start, size);
|
||||||
|
buf->pos = buf->start + pos;
|
||||||
|
buf->end = buf->start + size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_buffer_need(buffer *buf, const size_t n)
|
||||||
|
{
|
||||||
|
if (bmp_buffer_avail(buf) < n)
|
||||||
|
bmp_buffer_grow(buf, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_put_data(buffer *buf, const void *src, const size_t n)
|
||||||
|
{
|
||||||
|
if (!n)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bmp_buffer_need(buf, n);
|
||||||
|
memcpy(buf->pos, src, n);
|
||||||
|
buf->pos += n;
|
||||||
|
}
|
77
proto/bmp/buffer.h
Normal file
77
proto/bmp/buffer.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BIRD_BMP_BUFFER_H_
|
||||||
|
#define _BIRD_BMP_BUFFER_H_
|
||||||
|
|
||||||
|
#include "proto/bmp/bmp.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "lib/resource.h"
|
||||||
|
|
||||||
|
buffer
|
||||||
|
bmp_buffer_alloc(pool *ppool, const size_t n);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_buffer_free(buffer *buf);
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
bmp_buffer_flush(buffer *buf)
|
||||||
|
{
|
||||||
|
buf->pos = buf->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
bmp_buffer_size(const buffer *buf)
|
||||||
|
{
|
||||||
|
return buf->end - buf->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
bmp_buffer_avail(const buffer *buf)
|
||||||
|
{
|
||||||
|
return buf->end - buf->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
bmp_buffer_pos(const buffer *buf)
|
||||||
|
{
|
||||||
|
return buf->pos - buf->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline byte *
|
||||||
|
bmp_buffer_data(const buffer *buf)
|
||||||
|
{
|
||||||
|
return buf->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_buffer_need(buffer *buf, const size_t n);
|
||||||
|
|
||||||
|
// Idea for following macros has been taken from |proto/mrt/mrt.c|
|
||||||
|
#define BMP_DEFINE_PUT_FUNC(S, T) \
|
||||||
|
static inline void \
|
||||||
|
bmp_put_##S(buffer *b, const T x) \
|
||||||
|
{ \
|
||||||
|
bmp_buffer_need(b, sizeof(T)); \
|
||||||
|
put_##S(b->pos, x); \
|
||||||
|
b->pos += sizeof(T); \
|
||||||
|
}
|
||||||
|
|
||||||
|
BMP_DEFINE_PUT_FUNC(u8, u8)
|
||||||
|
BMP_DEFINE_PUT_FUNC(u16, u16)
|
||||||
|
BMP_DEFINE_PUT_FUNC(u32, u32)
|
||||||
|
BMP_DEFINE_PUT_FUNC(u64, u64)
|
||||||
|
BMP_DEFINE_PUT_FUNC(ip4, ip4_addr)
|
||||||
|
BMP_DEFINE_PUT_FUNC(ip6, ip6_addr)
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_put_data(buffer *buf, const void *src, const size_t n);
|
||||||
|
|
||||||
|
#endif /* _BIRD_BMP_BUFFER_H_ */
|
78
proto/bmp/config.Y
Normal file
78
proto/bmp/config.Y
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CF_HDR
|
||||||
|
|
||||||
|
#include "proto/bmp/bmp.h"
|
||||||
|
|
||||||
|
CF_DEFINES
|
||||||
|
|
||||||
|
#define BMP_CFG ((struct bmp_config *) this_proto)
|
||||||
|
|
||||||
|
CF_DECLS
|
||||||
|
|
||||||
|
CF_KEYWORDS(BMP, DESCRIPTION, ENABLED, IN, IP, MONITORING, NAME, PORT,
|
||||||
|
PRE_POLICY, POST_POLICY, RIB, STATION, SYSTEM)
|
||||||
|
|
||||||
|
CF_GRAMMAR
|
||||||
|
|
||||||
|
proto: bmp_proto '}' ;
|
||||||
|
|
||||||
|
bmp_proto_start: proto_start BMP {
|
||||||
|
this_proto = proto_config_new(&proto_bmp, $1);
|
||||||
|
BMP_CFG->sys_descr = "Not defined";
|
||||||
|
BMP_CFG->sys_name = "Not defined";
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
bmp_station_address:
|
||||||
|
/* empty */
|
||||||
|
| bmp_station_address IP ipa {
|
||||||
|
if (ipa_zero($3))
|
||||||
|
cf_error("Invalid BMP monitoring station IP address");
|
||||||
|
BMP_CFG->station_ip = $3;
|
||||||
|
}
|
||||||
|
| bmp_station_address PORT expr {
|
||||||
|
if (($3 < 1) || ($3 > 65535))
|
||||||
|
cf_error("Invalid BMP monitoring station port number");
|
||||||
|
BMP_CFG->station_port = $3;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
bmp_proto:
|
||||||
|
bmp_proto_start proto_name '{'
|
||||||
|
| bmp_proto proto_item ';'
|
||||||
|
| bmp_proto LOCAL ADDRESS ipa ';' {
|
||||||
|
BMP_CFG->local_addr = $4;
|
||||||
|
}
|
||||||
|
| bmp_proto STATION ADDRESS bmp_station_address ';'
|
||||||
|
| bmp_proto SYSTEM DESCRIPTION text ';' {
|
||||||
|
if (!$4 || (strlen($4) == 0))
|
||||||
|
cf_error("String is empty");
|
||||||
|
else if (strlen($4) > 255)
|
||||||
|
cf_error("Invalid string length");
|
||||||
|
BMP_CFG->sys_descr = $4;
|
||||||
|
}
|
||||||
|
| bmp_proto SYSTEM NAME text ';' {
|
||||||
|
if (!$4 || (strlen($4) == 0))
|
||||||
|
cf_error("String is empty");
|
||||||
|
else if (strlen($4) > 255)
|
||||||
|
cf_error("Invalid string length");
|
||||||
|
BMP_CFG->sys_name = $4;
|
||||||
|
}
|
||||||
|
| bmp_proto MONITORING RIB IN PRE_POLICY bool ';' {
|
||||||
|
BMP_CFG->monitoring_rib_in_pre_policy = $6;
|
||||||
|
}
|
||||||
|
| bmp_proto MONITORING RIB IN POST_POLICY bool ';' {
|
||||||
|
BMP_CFG->monitoring_rib_in_post_policy = $6;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
CF_CODE
|
||||||
|
|
||||||
|
CF_END
|
119
proto/bmp/map.c
Normal file
119
proto/bmp/map.c
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "proto/bmp/map.h"
|
||||||
|
|
||||||
|
/* Peer Index Table */
|
||||||
|
#define PEER_KEY(n) (n)->peer_as, (n)->peer_ip
|
||||||
|
#define PEER_NEXT(n) (n)->next
|
||||||
|
#define PEER_EQ(as1,ip1,as2,ip2) \
|
||||||
|
(as1) == (as2) && ipa_equal(ip1, ip2)
|
||||||
|
#define PEER_FN(as,ip) ipa_hash(ip)
|
||||||
|
|
||||||
|
#define PEER_REHASH bmp_peer_rehash
|
||||||
|
#define PEER_PARAMS /8, *2, 2, 2, 6, 20
|
||||||
|
|
||||||
|
HASH_DEFINE_REHASH_FN(PEER, struct bmp_peer_map_key)
|
||||||
|
|
||||||
|
#define PEER_INIT_ORDER 6
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_init(struct bmp_peer_map *map, pool *mpool)
|
||||||
|
{
|
||||||
|
map->mpool = mpool;
|
||||||
|
HASH_INIT(map->peer_hash, map->mpool, PEER_INIT_ORDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bmp_peer_map_key
|
||||||
|
bmp_peer_map_key_create(const ip_addr peer_ip, const u32 peer_as)
|
||||||
|
{
|
||||||
|
struct bmp_peer_map_key key;
|
||||||
|
key.next = NULL;
|
||||||
|
key.peer_ip = peer_ip;
|
||||||
|
key.peer_as = peer_as;
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_flush(struct bmp_peer_map *map)
|
||||||
|
{
|
||||||
|
struct bmp_peer_map_entry *entry;
|
||||||
|
HASH_WALK_DELSAFE(map->peer_hash, next, e)
|
||||||
|
{
|
||||||
|
entry = (struct bmp_peer_map_entry *) e;
|
||||||
|
mb_free(entry->data.buf);
|
||||||
|
HASH_DELETE(map->peer_hash, PEER, PEER_KEY(&entry->key));
|
||||||
|
mb_free(entry);
|
||||||
|
}
|
||||||
|
HASH_WALK_DELSAFE_END;
|
||||||
|
|
||||||
|
HASH_MAY_RESIZE_DOWN(map->peer_hash, PEER, map->mpool);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_free(struct bmp_peer_map *map)
|
||||||
|
{
|
||||||
|
bmp_peer_map_flush(map);
|
||||||
|
HASH_FREE(map->peer_hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_insert(struct bmp_peer_map *map, const struct bmp_peer_map_key key,
|
||||||
|
const byte *data, const size_t data_size)
|
||||||
|
{
|
||||||
|
struct bmp_peer_map_entry *entry
|
||||||
|
= (void *) HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key));
|
||||||
|
|
||||||
|
if (entry)
|
||||||
|
{
|
||||||
|
mb_free(entry->data.buf);
|
||||||
|
entry->data.buf = mb_alloc(map->mpool, data_size);
|
||||||
|
memcpy(entry->data.buf, data, data_size);
|
||||||
|
entry->data.buf_size = data_size;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = mb_alloc(map->mpool, sizeof (struct bmp_peer_map_entry));
|
||||||
|
entry->data.buf = mb_alloc(map->mpool, data_size);
|
||||||
|
memcpy(entry->data.buf, data, data_size);
|
||||||
|
entry->data.buf_size = data_size;
|
||||||
|
entry->key = key;
|
||||||
|
HASH_INSERT2(map->peer_hash, PEER, map->mpool, &entry->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_remove(struct bmp_peer_map *map, const struct bmp_peer_map_key key)
|
||||||
|
{
|
||||||
|
struct bmp_peer_map_entry *entry
|
||||||
|
= (void *) HASH_DELETE(map->peer_hash, PEER, PEER_KEY(&key));
|
||||||
|
|
||||||
|
if (!entry)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mb_free(entry->data.buf);
|
||||||
|
mb_free(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct bmp_peer_map_entry *
|
||||||
|
bmp_peer_map_get(struct bmp_peer_map *map, const struct bmp_peer_map_key key)
|
||||||
|
{
|
||||||
|
return (struct bmp_peer_map_entry *) HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_walk(const struct bmp_peer_map *map, bmp_peer_map_walk_action action, void *arg)
|
||||||
|
{
|
||||||
|
struct bmp_peer_map_entry *entry;
|
||||||
|
HASH_WALK_FILTER(map->peer_hash, next, e, _)
|
||||||
|
{
|
||||||
|
entry = (struct bmp_peer_map_entry *) e;
|
||||||
|
action(entry->key, entry->data.buf, entry->data.buf_size, arg);
|
||||||
|
}
|
||||||
|
HASH_WALK_FILTER_END;
|
||||||
|
}
|
68
proto/bmp/map.h
Normal file
68
proto/bmp/map.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* BIRD -- The BGP Monitoring Protocol (BMP)
|
||||||
|
*
|
||||||
|
* (c) 2020 Akamai Technologies, Inc. (Pawel Maslanka, pmaslank@akamai.com)
|
||||||
|
*
|
||||||
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This map implementation binds peer IP address as container key with custom data.
|
||||||
|
*/
|
||||||
|
#ifndef _BIRD_BMP_MAP_H_
|
||||||
|
#define _BIRD_BMP_MAP_H_
|
||||||
|
|
||||||
|
#include "nest/bird.h"
|
||||||
|
#include "lib/hash.h"
|
||||||
|
#include "lib/resource.h"
|
||||||
|
|
||||||
|
struct bmp_peer_map_key {
|
||||||
|
struct bmp_peer_map_key *next;
|
||||||
|
ip_addr peer_ip;
|
||||||
|
u32 peer_as;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_peer_map_data {
|
||||||
|
void *buf;
|
||||||
|
size_t buf_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_peer_map_entry {
|
||||||
|
struct bmp_peer_map_key key;
|
||||||
|
struct bmp_peer_map_data data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bmp_peer_map {
|
||||||
|
pool *mpool; // Memory pool for peer entries in peer_hash
|
||||||
|
HASH(struct bmp_peer_map_key) peer_hash; // Hash for peers to find the index
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_init(struct bmp_peer_map *map, pool *mpool);
|
||||||
|
|
||||||
|
struct bmp_peer_map_key
|
||||||
|
bmp_peer_map_key_create(const ip_addr peer_ip, const u32 peer_as);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_free(struct bmp_peer_map *map);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_flush(struct bmp_peer_map *map);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_insert(struct bmp_peer_map *map, const struct bmp_peer_map_key key,
|
||||||
|
const byte *data, const size_t data_size);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_remove(struct bmp_peer_map *map, const struct bmp_peer_map_key key);
|
||||||
|
|
||||||
|
const struct bmp_peer_map_entry *
|
||||||
|
bmp_peer_map_get(struct bmp_peer_map *map, const struct bmp_peer_map_key key);
|
||||||
|
|
||||||
|
typedef void (*bmp_peer_map_walk_action)(const struct bmp_peer_map_key key,
|
||||||
|
const byte *data, const size_t data_size, void *arg);
|
||||||
|
|
||||||
|
void
|
||||||
|
bmp_peer_map_walk(const struct bmp_peer_map *map, bmp_peer_map_walk_action action, void *arg);
|
||||||
|
|
||||||
|
#endif /* _BIRD_BMP_MAP_H_ */
|
@ -13,7 +13,7 @@
|
|||||||
#ifdef GIT_LABEL
|
#ifdef GIT_LABEL
|
||||||
#define BIRD_VERSION XSTR1(GIT_LABEL)
|
#define BIRD_VERSION XSTR1(GIT_LABEL)
|
||||||
#else
|
#else
|
||||||
#define BIRD_VERSION "2.0.12"
|
#define BIRD_VERSION "2.13"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Include parameters determined by configure script */
|
/* Include parameters determined by configure script */
|
||||||
|
Loading…
Reference in New Issue
Block a user