diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index af2ef4c839da..f83e68a9348f 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -1807,6 +1807,22 @@ static enum bgp_fsm_state_progress bgp_connect_fail(struct peer *peer) return bgp_stop(peer); } +/* after connect is called(), getpeername is able to return + * port and address on non established streams + */ +static void bgp_connect_in_progress_update_connection(struct peer *peer) +{ + bgp_getsockname(peer); + if (!peer->su_remote && !BGP_CONNECTION_SU_UNSPEC(peer->connection)) { + /* if connect initiated, then dest port and dest addresses are well known */ + peer->su_remote = sockunion_dup(&peer->connection->su); + if (sockunion_family(peer->su_remote) == AF_INET) + peer->su_remote->sin.sin_port = htons(peer->port); + else if (sockunion_family(peer->su_remote) == AF_INET6) + peer->su_remote->sin6.sin6_port = htons(peer->port); + } +} + /* This function is the first starting point of all BGP connection. It * try to connect to remote peer with non-blocking IO. */ @@ -1925,6 +1941,8 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer) peer->fd); return BGP_FSM_FAILURE; } + bgp_connect_in_progress_update_connection(peer); + /* * - when the socket becomes ready, poll() will signify POLLOUT * - if it fails to connect, poll() will signify POLLHUP diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 34c9763f8670..16eb603a5ddb 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -811,12 +811,17 @@ int bgp_getsockname(struct peer *peer) peer->su_remote = NULL; } +<<<<<<< HEAD peer->su_local = sockunion_getsockname(peer->fd); if (!peer->su_local) return -1; peer->su_remote = sockunion_getpeername(peer->fd); if (!peer->su_remote) return -1; +======= + peer->su_local = sockunion_getsockname(peer->connection->fd); + peer->su_remote = sockunion_getpeername(peer->connection->fd); +>>>>>>> ba71303099 (bgpd: remove useless control checks about TCP connection) if (!bgp_zebra_nexthop_set(peer->su_local, peer->su_remote, &peer->nexthop, peer)) {