Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More found connection conversion issues #17385

Merged
Merged
46 changes: 18 additions & 28 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
from_peer->addpath_paths_limit[afi][safi];
}

if (bgp_getsockname(peer) < 0) {
if (bgp_getsockname(keeper) < 0) {
flog_err(EC_LIB_SOCKET,
"%%bgp_getsockname() failed for %s peer %s fd %d (from_peer fd %d)",
(CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)
Expand All @@ -277,7 +277,7 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
return NULL;
}
if (going_away->status > Active) {
if (bgp_getsockname(from_peer) < 0) {
if (bgp_getsockname(going_away) < 0) {
flog_err(EC_LIB_SOCKET,
"%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)",

Expand Down Expand Up @@ -325,8 +325,8 @@ void bgp_timer_set(struct peer_connection *connection)
/* First entry point of peer's finite state machine. In Idle
status start timer is on unless peer is shutdown or peer is
inactive. All other timer must be turned off */
if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(peer)
|| peer->bgp->vrf_id == VRF_UNKNOWN) {
if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(connection) ||
peer->bgp->vrf_id == VRF_UNKNOWN) {
EVENT_OFF(connection->t_start);
} else {
BGP_TIMER_ON(connection->t_start, bgp_start_timer,
Expand Down Expand Up @@ -1694,11 +1694,11 @@ bgp_connect_success(struct peer_connection *connection)
return bgp_stop(connection);
}

if (bgp_getsockname(peer) < 0) {
if (bgp_getsockname(connection) < 0) {
flog_err_sys(EC_LIB_SOCKET,
"%s: bgp_getsockname(): failed for peer %s, fd %d",
__func__, peer->host, connection->fd);
bgp_notify_send(peer->connection, BGP_NOTIFY_FSM_ERR,
bgp_notify_send(connection, BGP_NOTIFY_FSM_ERR,
bgp_fsm_error_subcode(connection->status));
bgp_writes_on(connection);
return BGP_FSM_FAILURE;
Expand Down Expand Up @@ -1740,11 +1740,11 @@ bgp_connect_success_w_delayopen(struct peer_connection *connection)
return bgp_stop(connection);
}

if (bgp_getsockname(peer) < 0) {
if (bgp_getsockname(connection) < 0) {
flog_err_sys(EC_LIB_SOCKET,
"%s: bgp_getsockname(): failed for peer %s, fd %d",
__func__, peer->host, connection->fd);
bgp_notify_send(peer->connection, BGP_NOTIFY_FSM_ERR,
bgp_notify_send(connection, BGP_NOTIFY_FSM_ERR,
bgp_fsm_error_subcode(connection->status));
bgp_writes_on(connection);
return BGP_FSM_FAILURE;
Expand Down Expand Up @@ -1807,12 +1807,14 @@ bgp_connect_fail(struct peer_connection *connection)
/* 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)
static void bgp_connect_in_progress_update_connection(struct peer_connection *connection)
{
bgp_updatesockname(peer);
struct peer *peer = connection->peer;

bgp_updatesockname(peer, connection);
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);
peer->su_remote = sockunion_dup(&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)
Expand Down Expand Up @@ -1916,7 +1918,7 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
__func__, peer->connection->fd);
return BGP_FSM_FAILURE;
}
bgp_connect_in_progress_update_connection(peer);
bgp_connect_in_progress_update_connection(connection);

/*
* - when the socket becomes ready, poll() will signify POLLOUT
Expand Down Expand Up @@ -2745,10 +2747,7 @@ static void bgp_gr_update_mode_of_all_peers(struct bgp *bgp,

peer->last_reset = PEER_DOWN_CAPABILITY_CHANGE;

if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status))
bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
else
if (!peer_notify_config_change(peer->connection))
bgp_session_reset_safe(peer, &nnode);
} else {
group = peer->group;
Expand All @@ -2768,10 +2767,7 @@ static void bgp_gr_update_mode_of_all_peers(struct bgp *bgp,

member->last_reset = PEER_DOWN_CAPABILITY_CHANGE;

if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status))
bgp_notify_send(member->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
else
if (!peer_notify_config_change(member->connection))
bgp_session_reset(member);
}
}
Expand Down Expand Up @@ -2973,21 +2969,15 @@ unsigned int bgp_peer_gr_action(struct peer *peer, enum peer_mode old_state,
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
peer->last_reset = PEER_DOWN_CAPABILITY_CHANGE;

if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status))
bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
else
if (!peer_notify_config_change(peer->connection))
bgp_session_reset(peer);
} else {
group = peer->group;
for (ALL_LIST_ELEMENTS(group->peer, node, nnode, member)) {
member->last_reset = PEER_DOWN_CAPABILITY_CHANGE;
bgp_peer_move_to_gr_mode(member, new_state);

if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status))
bgp_notify_send(member->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
else
if (!peer_notify_config_change(member->connection))
bgp_session_reset(member);
}
}
Expand Down
18 changes: 10 additions & 8 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static void bgp_accept(struct event *thread)
bgp_fsm_change_status(connection1, Active);
EVENT_OFF(connection1->t_start);

if (peer_active(peer1)) {
if (peer_active(peer1->connection)) {
if (CHECK_FLAG(peer1->flags,
PEER_FLAG_TIMER_DELAYOPEN))
BGP_EVENT_ADD(connection1,
Expand Down Expand Up @@ -557,7 +557,7 @@ static void bgp_accept(struct event *thread)
}

/* Check that at least one AF is activated for the peer. */
if (!peer_active(peer1)) {
if (!peer_active(connection1)) {
if (bgp_debug_neighbor_events(peer1))
zlog_debug(
"%s - incoming conn rejected - no AF activated for peer",
Expand Down Expand Up @@ -658,7 +658,7 @@ static void bgp_accept(struct event *thread)
bgp_event_update(connection1, TCP_connection_closed);
}

if (peer_active(peer)) {
if (peer_active(peer->connection)) {
if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN))
BGP_EVENT_ADD(connection, TCP_connection_open_w_delay);
else
Expand Down Expand Up @@ -861,7 +861,7 @@ enum connect_result bgp_connect(struct peer_connection *connection)
htons(peer->port), ifindex);
}

void bgp_updatesockname(struct peer *peer)
void bgp_updatesockname(struct peer *peer, struct peer_connection *connection)
{
if (peer->su_local) {
sockunion_free(peer->su_local);
Expand All @@ -873,14 +873,16 @@ void bgp_updatesockname(struct peer *peer)
peer->su_remote = NULL;
}

peer->su_local = sockunion_getsockname(peer->connection->fd);
peer->su_remote = sockunion_getpeername(peer->connection->fd);
peer->su_local = sockunion_getsockname(connection->fd);
peer->su_remote = sockunion_getpeername(connection->fd);
}

/* After TCP connection is established. Get local address and port. */
int bgp_getsockname(struct peer *peer)
int bgp_getsockname(struct peer_connection *connection)
{
bgp_updatesockname(peer);
struct peer *peer = connection->peer;

bgp_updatesockname(peer, peer->connection);

if (!bgp_zebra_nexthop_set(peer->su_local, peer->su_remote,
&peer->nexthop, peer)) {
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern int bgp_socket(struct bgp *bgp, unsigned short port,
extern void bgp_close_vrf_socket(struct bgp *bgp);
extern void bgp_close(void);
extern enum connect_result bgp_connect(struct peer_connection *connection);
extern int bgp_getsockname(struct peer *peer);
extern void bgp_updatesockname(struct peer *peer);
extern int bgp_getsockname(struct peer_connection *connection);
extern void bgp_updatesockname(struct peer *peer, struct peer_connection *connection);

extern int bgp_md5_set_prefix(struct bgp *bgp, struct prefix *p,
const char *password);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)
!peer_established(peer->connection) &&
!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) {
connection = peer->connection;
if (peer_active(peer))
if (peer_active(connection))
BGP_EVENT_ADD(connection, BGP_Stop);
BGP_EVENT_ADD(connection, BGP_Start);
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ static int bgp_open_receive(struct peer_connection *connection,
return BGP_Stop;

/* Get sockname. */
if (bgp_getsockname(peer) < 0) {
if (bgp_getsockname(connection) < 0) {
flog_err_sys(EC_LIB_SOCKET,
"%s: bgp_getsockname() failed for peer: %s",
__func__, peer->host);
Expand Down
23 changes: 8 additions & 15 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,7 @@ DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
*/
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status))
bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
peer_notify_config_change(peer->connection);
}

return CMD_SUCCESS;
Expand All @@ -2965,9 +2963,7 @@ DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
*/
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status))
bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
peer_notify_config_change(peer->connection);
}

return CMD_SUCCESS;
Expand Down Expand Up @@ -5100,10 +5096,7 @@ static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;

/* v6only flag changed. Reset bgp seesion */
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status))
bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
else
if (!peer_notify_config_change(peer->connection))
bgp_session_reset(peer);
}

Expand Down Expand Up @@ -5264,7 +5257,7 @@ DEFUN (no_neighbor,
* interface. */
if (peer->ifp)
bgp_zebra_terminate_radv(peer->bgp, peer);
peer_notify_unconfig(peer);
peer_notify_unconfig(peer->connection);
peer_delete(peer);
return CMD_SUCCESS;
}
Expand Down Expand Up @@ -5300,10 +5293,10 @@ DEFUN (no_neighbor,
if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
bgp_zebra_terminate_radv(peer->bgp, peer);

peer_notify_unconfig(peer);
peer_notify_unconfig(peer->connection);
peer_delete(peer);
if (other && other->connection->status != Deleted) {
peer_notify_unconfig(other);
peer_notify_unconfig(other->connection);
peer_delete(other);
}
}
Expand Down Expand Up @@ -5338,7 +5331,7 @@ DEFUN (no_neighbor_interface_config,
/* Request zebra to terminate IPv6 RAs on this interface. */
if (peer->ifp)
bgp_zebra_terminate_radv(peer->bgp, peer);
peer_notify_unconfig(peer);
peer_notify_unconfig(peer->connection);
peer_delete(peer);
} else {
vty_out(vty, "%% Create the bgp interface first\n");
Expand Down Expand Up @@ -5746,7 +5739,7 @@ DEFUN (no_neighbor_set_peer_group,
if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
bgp_zebra_terminate_radv(peer->bgp, peer);

peer_notify_unconfig(peer);
peer_notify_unconfig(peer->connection);
ret = peer_delete(peer);

return bgp_vty_return(vty, ret);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp)
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) &&
!peer_established(peer->connection)) {
if (peer_active(peer))
if (peer_active(peer->connection))
BGP_EVENT_ADD(peer->connection, BGP_Stop);
BGP_EVENT_ADD(peer->connection, BGP_Start);
}
Expand Down
Loading
Loading