summaryrefslogtreecommitdiff
path: root/proto/bgp/bgp.c
diff options
context:
space:
mode:
Diffstat (limited to 'proto/bgp/bgp.c')
-rw-r--r--proto/bgp/bgp.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index 1ae56397..0a2e8f5a 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -380,10 +380,20 @@ bgp_close_conn(struct bgp_conn *conn)
rfree(conn->sk);
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);
conn->local_caps = NULL;
mb_free(conn->remote_caps);
conn->remote_caps = NULL;
+
+ conn->notify_data = NULL;
+ conn->notify_size = 0;
}
@@ -682,10 +692,12 @@ bgp_conn_enter_established_state(struct bgp_conn *conn)
bgp_conn_set_state(conn, BS_ESTABLISHED);
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
-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");
p->last_established = current_time();
@@ -693,6 +705,10 @@ bgp_conn_leave_established_state(struct bgp_proto *p)
if (p->p.proto_state == PS_UP)
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
@@ -709,7 +725,7 @@ bgp_conn_enter_close_state(struct bgp_conn *conn)
bgp_start_timer(conn->hold_timer, 10);
if (os == BS_ESTABLISHED)
- bgp_conn_leave_established_state(p);
+ bgp_conn_leave_established_state(conn, p);
}
void
@@ -723,7 +739,7 @@ bgp_conn_enter_idle_state(struct bgp_conn *conn)
ev_schedule(p->event);
if (os == BS_ESTABLISHED)
- bgp_conn_leave_established_state(p);
+ bgp_conn_leave_established_state(conn, p);
}
/**
@@ -867,10 +883,7 @@ bgp_graceful_restart_timeout(timer *t)
}
}
else
- {
bgp_stop(p, 0, NULL, 0);
- bmp_peer_down(p, BE_NONE, NULL, 0);
- }
}
static void
@@ -994,10 +1007,7 @@ bgp_sock_err(sock *sk, int err)
if (err)
BGP_TRACE(D_EVENTS, "Connection lost (%M)", err);
else
- {
BGP_TRACE(D_EVENTS, "Connection closed");
- bmp_peer_down(p, BE_SOCKET, NULL, 0);
- }
if ((conn->state == BS_ESTABLISHED) && p->gr_ready)
bgp_handle_graceful_restart(p);
@@ -1322,7 +1332,6 @@ 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, 0);
}
}
else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP))
@@ -1334,7 +1343,6 @@ 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, 0);
}
}
else
@@ -1376,7 +1384,6 @@ 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, 0);
}
}
}
@@ -1705,10 +1712,6 @@ bgp_init(struct proto_config *CF)
P->rte_modify = bgp_rte_modify_stale;
P->rte_igp_metric = bgp_rte_igp_metric;
-#ifdef CONFIG_BMP
- P->rte_update_in_notify = bgp_rte_update_in_notify;
-#endif
-
p->cf = cf;
p->is_internal = (cf->local_as == cf->remote_as);
p->is_interior = p->is_internal || cf->confederation_member;
@@ -2261,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_store_error(p, c, BE_BGP_TX, (code << 16) | subcode);
- bgp_conn_enter_close_state(c);
c->notify_code = code;
c->notify_subcode = subcode;
c->notify_data = data;
c->notify_size = (len > 0) ? len : 0;
+
+ bgp_conn_enter_close_state(c);
bgp_schedule_packet(c, NULL, PKT_NOTIFICATION);
if (code != 6)
@@ -2634,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),
.config_size = sizeof(struct bgp_channel_config),
.init = bgp_channel_init,