summaryrefslogtreecommitdiff
path: root/bgpd/bgp_network.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2021-04-30 14:55:40 -0400
committerDonald Sharp <sharpd@nvidia.com>2023-08-18 09:29:04 -0400
commit1f32eb30d96ae4c92ed8d03fe3aea95d962b59b1 (patch)
treef6b05f291bb296f28e8edade5c4200565b072bcb /bgpd/bgp_network.c
parentbd6a00e8f7ab48e6ab20673474c6eb1e879cb5c4 (diff)
bgpd: Start abstraction of `struct peer_connection`
BGP tracks connections based upon the peer. But the problem with this is that the doppelganger structure for it is being created. This has introduced a bunch of fragileness in that the peer exists independently of the connections to it. The whole point of the doppelganger structure was to allow BGP to both accept and initiate tcp connections and then when we get one to a `good` state we collapse into the appropriate one. The problem with this is that having 2 peer structures for this creates a situation where we have to make sure we are configing the `right` one and also make sure that we collapse the two independent peer structures into 1 acting peer. This makes no sense let's abstract out the peer into having 2 connection one for incoming connections and one for outgoing connections then we can easily collapse down without having to do crazy stuff. In addition people adding new features don't need to have to go touch a million places in the code. This is the start of this abstraction. In this commit we'll just pull out the fd and input/output buffers into a connection data structure. Future commits will abstract further. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'bgpd/bgp_network.c')
-rw-r--r--bgpd/bgp_network.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 73fe00c7ab..f83b9e8064 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -429,7 +429,7 @@ static void bgp_accept(struct event *thread)
peer1 = peer_lookup_dynamic_neighbor(bgp, &su);
if (peer1) {
/* Dynamic neighbor has been created, let it proceed */
- peer1->fd = bgp_sock;
+ peer1->connection.fd = bgp_sock;
/* Set the user configured MSS to TCP socket */
if (CHECK_FLAG(peer1->flags, PEER_FLAG_TCP_MSS))
@@ -521,10 +521,9 @@ static void bgp_accept(struct event *thread)
}
if (bgp_debug_neighbor_events(peer1))
- zlog_debug(
- "[Event] connection from %s fd %d, active peer status %d fd %d",
- inet_sutop(&su, buf), bgp_sock, peer1->status,
- peer1->fd);
+ zlog_debug("[Event] connection from %s fd %d, active peer status %d fd %d",
+ inet_sutop(&su, buf), bgp_sock, peer1->status,
+ peer1->connection.fd);
if (peer1->doppelganger) {
/* We have an existing connection. Kill the existing one and run
@@ -563,7 +562,7 @@ static void bgp_accept(struct event *thread)
peer->doppelganger = peer1;
peer1->doppelganger = peer;
- peer->fd = bgp_sock;
+ peer->connection.fd = bgp_sock;
frr_with_privs(&bgpd_privs) {
vrf_bind(peer->bgp->vrf_id, bgp_sock, bgp_get_bound_name(peer));
}
@@ -684,13 +683,13 @@ static int bgp_update_source(struct peer *peer)
if (bgp_update_address(ifp, &peer->su, &addr))
return -1;
- ret = sockunion_bind(peer->fd, &addr, 0, &addr);
+ ret = sockunion_bind(peer->connection.fd, &addr, 0, &addr);
}
/* Source is specified with IP address. */
if (peer->update_source)
- ret = sockunion_bind(peer->fd, peer->update_source, 0,
- peer->update_source);
+ ret = sockunion_bind(peer->connection.fd, peer->update_source,
+ 0, peer->update_source);
return ret;
}
@@ -708,11 +707,12 @@ int bgp_connect(struct peer *peer)
return 0;
}
frr_with_privs(&bgpd_privs) {
- /* Make socket for the peer. */
- peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
- bgp_get_bound_name(peer));
+ /* Make socket for the peer. */
+ peer->connection.fd =
+ vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
+ bgp_get_bound_name(peer));
}
- if (peer->fd < 0) {
+ if (peer->connection.fd < 0) {
peer->last_reset = PEER_DOWN_SOCKET_ERROR;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s: Failure to create socket for connection to %s, error received: %s(%d)",
@@ -721,18 +721,18 @@ int bgp_connect(struct peer *peer)
return -1;
}
- set_nonblocking(peer->fd);
+ set_nonblocking(peer->connection.fd);
/* Set the user configured MSS to TCP socket */
if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
- sockopt_tcp_mss_set(peer->fd, peer->tcp_mss);
+ sockopt_tcp_mss_set(peer->connection.fd, peer->tcp_mss);
- bgp_socket_set_buffer_size(peer->fd);
+ bgp_socket_set_buffer_size(peer->connection.fd);
/* Set TCP keepalive when TCP keepalive is enabled */
- bgp_update_setsockopt_tcp_keepalive(peer->bgp, peer->fd);
+ bgp_update_setsockopt_tcp_keepalive(peer->bgp, peer->connection.fd);
- if (bgp_set_socket_ttl(peer, peer->fd) < 0) {
+ if (bgp_set_socket_ttl(peer, peer->connection.fd) < 0) {
peer->last_reset = PEER_DOWN_SOCKET_ERROR;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s: Failure to set socket ttl for connection to %s, error received: %s(%d)",
@@ -742,15 +742,16 @@ int bgp_connect(struct peer *peer)
return -1;
}
- sockopt_reuseaddr(peer->fd);
- sockopt_reuseport(peer->fd);
+ sockopt_reuseaddr(peer->connection.fd);
+ sockopt_reuseport(peer->connection.fd);
#ifdef IPTOS_PREC_INTERNETCONTROL
frr_with_privs(&bgpd_privs) {
if (sockunion_family(&peer->su) == AF_INET)
- setsockopt_ipv4_tos(peer->fd, bm->tcp_dscp);
+ setsockopt_ipv4_tos(peer->connection.fd, bm->tcp_dscp);
else if (sockunion_family(&peer->su) == AF_INET6)
- setsockopt_ipv6_tclass(peer->fd, bm->tcp_dscp);
+ setsockopt_ipv6_tclass(peer->connection.fd,
+ bm->tcp_dscp);
}
#endif
@@ -762,7 +763,7 @@ int bgp_connect(struct peer *peer)
if (!BGP_PEER_SU_UNSPEC(peer))
bgp_md5_set(peer);
- bgp_md5_set_connect(peer->fd, &peer->su, prefixlen,
+ bgp_md5_set_connect(peer->connection.fd, &peer->su, prefixlen,
peer->password);
}
@@ -779,11 +780,11 @@ int bgp_connect(struct peer *peer)
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [Event] Connect start to %s fd %d", peer->host,
- peer->host, peer->fd);
+ peer->host, peer->connection.fd);
/* Connect to the remote peer. */
- return sockunion_connect(peer->fd, &peer->su, htons(peer->port),
- ifindex);
+ return sockunion_connect(peer->connection.fd, &peer->su,
+ htons(peer->port), ifindex);
}
/* After TCP connection is established. Get local address and port. */
@@ -799,10 +800,10 @@ int bgp_getsockname(struct peer *peer)
peer->su_remote = NULL;
}
- peer->su_local = sockunion_getsockname(peer->fd);
+ peer->su_local = sockunion_getsockname(peer->connection.fd);
if (!peer->su_local)
return -1;
- peer->su_remote = sockunion_getpeername(peer->fd);
+ peer->su_remote = sockunion_getpeername(peer->connection.fd);
if (!peer->su_remote)
return -1;