diff options
Diffstat (limited to 'bgpd/bgp_network.c')
-rw-r--r-- | bgpd/bgp_network.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index e4984ea46..af5d815d3 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -484,6 +484,9 @@ static void bgp_accept(struct event *thread) /* Dynamic neighbor has been created, let it proceed */ connection1->fd = bgp_sock; + connection1->su_local = sockunion_getsockname(connection1->fd); + connection1->su_remote = sockunion_dup(&su); + if (bgp_set_socket_ttl(connection1) < 0) { peer1->last_reset = PEER_DOWN_SOCKET_ERROR; zlog_err("%s: Unable to set min/max TTL on peer %s (dynamic), error received: %s(%d)", @@ -623,7 +626,10 @@ static void bgp_accept(struct event *thread) peer->doppelganger = peer1; peer1->doppelganger = peer; + connection->fd = bgp_sock; + connection->su_local = sockunion_getsockname(connection->fd); + connection->su_remote = sockunion_dup(&su); if (bgp_set_socket_ttl(connection) < 0) if (bgp_debug_neighbor_events(peer)) @@ -857,24 +863,28 @@ enum connect_result bgp_connect(struct peer_connection *connection) peer->host, connection->fd); /* Connect to the remote peer. */ - return sockunion_connect(connection->fd, &connection->su, - htons(peer->port), ifindex); -} + enum connect_result res; -void bgp_updatesockname(struct peer_connection *connection) -{ - if (connection->su_local) { - sockunion_free(connection->su_local); - connection->su_local = NULL; - } + res = sockunion_connect(connection->fd, &connection->su, htons(peer->port), ifindex); - if (connection->su_remote) { + if (connection->su_remote) sockunion_free(connection->su_remote); - connection->su_remote = NULL; + + connection->su_remote = sockunion_dup(&connection->su); + switch (connection->su.sa.sa_family) { + case AF_INET: + connection->su_remote->sin.sin_port = htons(peer->port); + break; + case AF_INET6: + connection->su_remote->sin6.sin6_port = htons(peer->port); + break; } + if (connection->su_local) + sockunion_free(connection->su_local); connection->su_local = sockunion_getsockname(connection->fd); - connection->su_remote = sockunion_getpeername(connection->fd); + + return res; } /* After TCP connection is established. Get local address and port. */ @@ -882,8 +892,6 @@ int bgp_getsockname(struct peer_connection *connection) { struct peer *peer = connection->peer; - bgp_updatesockname(connection); - if (!bgp_zebra_nexthop_set(connection->su_local, connection->su_remote, &peer->nexthop, peer)) { flog_err(EC_BGP_NH_UPD, |