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 2 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("%s (dynamic neighbor) deleted", peer->host);
}
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 ("%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 ("%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 ("%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
23 changes: 21 additions & 2 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ bgp_accept (struct thread *thread)

peer1 = peer_lookup (NULL, &su);


Copy link
Contributor

Choose a reason for hiding this comment

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

Probably it's better to remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Have updated accordingly.

/*
* Close incoming connection from directly connected EBGP peers until we receive
interface_up message from zebra
Expand All @@ -243,14 +244,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