Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

[Dynamic Neighbor]: add patch to support dynamic neighbor configuration. #14

Merged
merged 6 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ bgp_stop (struct peer *peer)
safi_t safi;
char orf_name[BUFSIZ];

if (peer_dynamic_neighbor(peer) &&
!(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE)))
{
if (BGP_DEBUG (events, EVENTS))
{
zlog_debug("BGP stop: %s (dynamic neighbor) deleted", peer->host);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> zlog_info

check line 467: neighbor down event is logged as info level, this is also neighbor down event, should also logged as info level.

}
peer_delete (peer);
return -1;
}

/* Can't do this in Clearing; events are used for state transitions */
if (peer->status != Clearing)
{
Expand Down Expand Up @@ -588,6 +599,17 @@ bgp_stop_with_error (struct peer *peer)
if (peer->v_start >= (60 * 2))
peer->v_start = (60 * 2);

if (peer_dynamic_neighbor(peer))
{
if (BGP_DEBUG (events, EVENTS))
{
zlog_debug ("BGP stop with error: %s (dynamic neighbor) deleted", peer->host);
}

peer_delete (peer);
return -1;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic can be merged into bgp_stop() as bgp_stop already has similar logic. We should enable code re-use.

bgp_stop (peer);

return 0;
Expand All @@ -609,6 +631,17 @@ bgp_stop_with_notify (struct peer *peer, u_char code, u_char sub_code)
return -1;
}

if (peer_dynamic_neighbor(peer))
{
if (BGP_DEBUG (events, EVENTS))
{
zlog_debug ("BGP stop with notify: %s (dynamic neighbor) deleted", peer->host);
}

peer_delete (peer);
return -1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should move into bgp_stop()


/* Clear start timer value to default. */
peer->v_start = BGP_INIT_START_TIMER;

Expand Down Expand Up @@ -656,6 +689,17 @@ bgp_connect_success (struct peer *peer)
static int
bgp_connect_fail (struct peer *peer)
{
if (peer_dynamic_neighbor(peer))
{
if (BGP_DEBUG (events, EVENTS))
{
zlog_debug ("BGP connection fail: %s (dynamic neighbor) deleted", peer->host);
}

peer_delete (peer);
return -1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move into bgp_stop().


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same code 4 times. Probably it's better to introduce a static function here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is used to provide log info if debug_event is enabled. They are not exactly the same. So adding more detailed log info now for better troubleshooting.

bgp_stop (peer);
return 0;
}
Expand Down
22 changes: 20 additions & 2 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,32 @@ bgp_accept (struct thread *thread)

if (BGP_DEBUG (events, EVENTS))
zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));


if (! peer1)
{
peer1 = peer_lookup_dynamic_neighbor (NULL, &su);
if (peer1)
{
/* Dynamic neighbor has been created, let it proceed */
peer1->fd = bgp_sock;
bgp_fsm_change_status(peer1, Active);
BGP_TIMER_OFF(peer1->t_start); /* created in peer_create() */

if (peer_active (peer1))
BGP_EVENT_ADD (peer1, TCP_connection_open);

return 0;
}
}

/* Check remote IP address */
if (! peer1 || peer1->status == Idle)
{
if (BGP_DEBUG (events, EVENTS))
{
if (! peer1)
zlog_debug ("[Event] BGP connection IP address %s is not configured",
zlog_debug ("[Event] BGP connection IP address %s rejected - not configured"
" and not valid for dynamic",
inet_sutop (&su, buf));
else
zlog_debug ("[Event] BGP connection IP address %s is Idle state",
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,10 @@ bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
}

/* Dynamic peers will just close their connection. */
if (peer_dynamic_neighbor (peer))
return 1;

/* restart timer start */
if (peer->pmax_restart[afi][safi])
{
Expand Down
Loading