diff options
author | Donald Sharp <sharpd@nvidia.com> | 2023-09-08 18:02:05 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@nvidia.com> | 2023-09-10 14:31:25 +0200 |
commit | 0c3a70c64430448c43fe12bf0ac044488352697c (patch) | |
tree | a7fd805ffc7837e50380258b639f0a921b5d79e2 | |
parent | bgpd: Convert bgp_network.c to use peer_connection (diff) | |
download | frr-0c3a70c64430448c43fe12bf0ac044488352697c.tar.xz frr-0c3a70c64430448c43fe12bf0ac044488352697c.zip |
bgpd: Move the peer->su to connection->su
The sockunion is per connection. So let's move it over.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
-rw-r--r-- | bgpd/bgp_bfd.c | 54 | ||||
-rw-r--r-- | bgpd/bgp_bmp.c | 10 | ||||
-rw-r--r-- | bgpd/bgp_dump.c | 30 | ||||
-rw-r--r-- | bgpd/bgp_fsm.c | 14 | ||||
-rw-r--r-- | bgpd/bgp_memory.c | 1 | ||||
-rw-r--r-- | bgpd/bgp_memory.h | 1 | ||||
-rw-r--r-- | bgpd/bgp_network.c | 66 | ||||
-rw-r--r-- | bgpd/bgp_nexthop.c | 8 | ||||
-rw-r--r-- | bgpd/bgp_nht.c | 66 | ||||
-rw-r--r-- | bgpd/bgp_open.c | 10 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 22 | ||||
-rw-r--r-- | bgpd/bgp_routemap.c | 12 | ||||
-rw-r--r-- | bgpd/bgp_snmp_bgp4.c | 35 | ||||
-rw-r--r-- | bgpd/bgp_snmp_bgp4v2.c | 82 | ||||
-rw-r--r-- | bgpd/bgp_updgrp.c | 14 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 30 | ||||
-rw-r--r-- | bgpd/bgpd.c | 143 | ||||
-rw-r--r-- | bgpd/bgpd.h | 9 | ||||
-rw-r--r-- | bgpd/rfapi/rfapi_import.c | 5 |
19 files changed, 343 insertions, 269 deletions
diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 6bc1c094f..21864cf1a 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -163,36 +163,35 @@ void bgp_peer_bfd_update_source(struct peer *p) /* Update peer's source/destination addresses. */ bfd_sess_addresses(session, &family, &src.v6, &dst.v6); if (family == AF_INET) { - if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr) - || p->su.sin.sin_addr.s_addr != dst.v4.s_addr) { + if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr) || + p->connection->su.sin.sin_addr.s_addr != dst.v4.s_addr) { if (BGP_DEBUG(bfd, BFD_LIB)) - zlog_debug( - "%s: address [%pI4->%pI4] to [%pI4->%pI4]", - __func__, &src.v4, &dst.v4, - source ? &source->sin.sin_addr - : &src.v4, - &p->su.sin.sin_addr); - - bfd_sess_set_ipv4_addrs( - session, source ? &source->sin.sin_addr : NULL, - &p->su.sin.sin_addr); + zlog_debug("%s: address [%pI4->%pI4] to [%pI4->%pI4]", + __func__, &src.v4, &dst.v4, + source ? &source->sin.sin_addr + : &src.v4, + &p->connection->su.sin.sin_addr); + + bfd_sess_set_ipv4_addrs(session, + source ? &source->sin.sin_addr + : NULL, + &p->connection->su.sin.sin_addr); changed = true; } } else { - if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6))) - || memcmp(&p->su.sin6, &dst.v6, sizeof(dst.v6))) { + if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6))) || + memcmp(&p->connection->su.sin6, &dst.v6, sizeof(dst.v6))) { if (BGP_DEBUG(bfd, BFD_LIB)) - zlog_debug( - "%s: address [%pI6->%pI6] to [%pI6->%pI6]", - __func__, &src.v6, &dst.v6, - source ? &source->sin6.sin6_addr - : &src.v6, - &p->su.sin6.sin6_addr); + zlog_debug("%s: address [%pI6->%pI6] to [%pI6->%pI6]", + __func__, &src.v6, &dst.v6, + source ? &source->sin6.sin6_addr + : &src.v6, + &p->connection->su.sin6.sin6_addr); bfd_sess_set_ipv6_addrs(session, source ? &source->sin6.sin6_addr : NULL, - &p->su.sin6.sin6_addr); + &p->connection->su.sin6.sin6_addr); changed = true; } } @@ -284,16 +283,17 @@ void bgp_peer_configure_bfd(struct peer *p, bool manual) bgp_peer_bfd_reset(p); /* Configure session with basic BGP peer data. */ - if (p->su.sa.sa_family == AF_INET) + if (p->connection->su.sa.sa_family == AF_INET) bfd_sess_set_ipv4_addrs(p->bfd_config->session, p->su_local ? &p->su_local->sin.sin_addr : NULL, - &p->su.sin.sin_addr); + &p->connection->su.sin.sin_addr); else - bfd_sess_set_ipv6_addrs( - p->bfd_config->session, - p->su_local ? &p->su_local->sin6.sin6_addr : NULL, - &p->su.sin6.sin6_addr); + bfd_sess_set_ipv6_addrs(p->bfd_config->session, + p->su_local + ? &p->su_local->sin6.sin6_addr + : NULL, + &p->connection->su.sin6.sin6_addr); bfd_sess_set_vrf(p->bfd_config->session, p->bgp->vrf_id); bfd_sess_set_hop_count(p->bfd_config->session, diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index c0f9a9a73..727080291 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -264,7 +264,7 @@ static void bmp_per_peer_hdr(struct stream *s, struct peer *peer, stream_putc(s, BMP_PEER_TYPE_GLOBAL_INSTANCE); /* Peer Flags */ - if (peer->su.sa.sa_family == AF_INET6) + if (peer->connection->su.sa.sa_family == AF_INET6) SET_FLAG(flags, BMP_PEER_FLAG_V); else UNSET_FLAG(flags, BMP_PEER_FLAG_V); @@ -275,13 +275,13 @@ static void bmp_per_peer_hdr(struct stream *s, struct peer *peer, stream_put(s, &peer_distinguisher[0], 8); /* Peer Address */ - if (peer->su.sa.sa_family == AF_INET6) - stream_put(s, &peer->su.sin6.sin6_addr, 16); - else if (peer->su.sa.sa_family == AF_INET) { + if (peer->connection->su.sa.sa_family == AF_INET6) + stream_put(s, &peer->connection->su.sin6.sin6_addr, 16); + else if (peer->connection->su.sa.sa_family == AF_INET) { stream_putl(s, 0); stream_putl(s, 0); stream_putl(s, 0); - stream_put_in_addr(s, &peer->su.sin.sin_addr); + stream_put_in_addr(s, &peer->connection->su.sin.sin_addr); } else { stream_putl(s, 0); stream_putl(s, 0); diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 3b5fbf368..529713ee3 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -246,14 +246,15 @@ static void bgp_dump_routes_index_table(struct bgp *bgp) /* Walk down all peers */ for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + int family = sockunion_family(&peer->connection->su); /* Peer's type */ - if (sockunion_family(&peer->su) == AF_INET) { + if (family == AF_INET) { stream_putc( obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4 + TABLE_DUMP_V2_PEER_INDEX_TABLE_IP); - } else if (sockunion_family(&peer->su) == AF_INET6) { + } else if (family == AF_INET6) { stream_putc( obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4 @@ -264,10 +265,13 @@ static void bgp_dump_routes_index_table(struct bgp *bgp) stream_put_in_addr(obuf, &peer->remote_id); /* Peer's IP address */ - if (sockunion_family(&peer->su) == AF_INET) { - stream_put_in_addr(obuf, &peer->su.sin.sin_addr); - } else if (sockunion_family(&peer->su) == AF_INET6) { - stream_write(obuf, (uint8_t *)&peer->su.sin6.sin6_addr, + if (family == AF_INET) { + stream_put_in_addr(obuf, + &peer->connection->su.sin.sin_addr); + } else if (family == AF_INET6) { + stream_write(obuf, + (uint8_t *)&peer->connection->su.sin6 + .sin6_addr, IPV6_MAX_BYTELEN); } @@ -468,24 +472,26 @@ static void bgp_dump_common(struct stream *obuf, struct peer *peer, stream_putw(obuf, peer->local_as); } - if (peer->su.sa.sa_family == AF_INET) { + if (peer->connection->su.sa.sa_family == AF_INET) { stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0); stream_putw(obuf, AFI_IP); - stream_put(obuf, &peer->su.sin.sin_addr, IPV4_MAX_BYTELEN); + stream_put(obuf, &peer->connection->su.sin.sin_addr, + IPV4_MAX_BYTELEN); if (peer->su_local) stream_put(obuf, &peer->su_local->sin.sin_addr, IPV4_MAX_BYTELEN); else stream_put(obuf, empty, IPV4_MAX_BYTELEN); - } else if (peer->su.sa.sa_family == AF_INET6) { + } else if (peer->connection->su.sa.sa_family == AF_INET6) { /* Interface Index and Address family. */ stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0); stream_putw(obuf, AFI_IP6); /* Source IP Address and Destination IP Address. */ - stream_put(obuf, &peer->su.sin6.sin6_addr, IPV6_MAX_BYTELEN); + stream_put(obuf, &peer->connection->su.sin6.sin6_addr, + IPV6_MAX_BYTELEN); if (peer->su_local) stream_put(obuf, &peer->su_local->sin6.sin6_addr, @@ -532,10 +538,10 @@ static void bgp_dump_packet_func(struct bgp_dump *bgp_dump, struct peer *peer, /* If dump file pointer is disabled return immediately. */ if (bgp_dump->fp == NULL) return; - if (peer->su.sa.sa_family == AF_INET) { + if (peer->connection->su.sa.sa_family == AF_INET) { addpath_capable = bgp_addpath_encode_rx(peer, AFI_IP, SAFI_UNICAST); - } else if (peer->su.sa.sa_family == AF_INET6) { + } else if (peer->connection->su.sa.sa_family == AF_INET6) { addpath_capable = bgp_addpath_encode_rx(peer, AFI_IP6, SAFI_UNICAST); } diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index ccebe6b79..d4b1df175 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -93,9 +93,11 @@ int bgp_peer_reg_with_nht(struct peer *peer) && !CHECK_FLAG(peer->bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) connected = 1; - return bgp_find_or_add_nexthop( - peer->bgp, peer->bgp, family2afi(peer->su.sa.sa_family), - SAFI_UNICAST, NULL, peer, connected, NULL); + return bgp_find_or_add_nexthop(peer->bgp, peer->bgp, + family2afi( + peer->connection->su.sa.sa_family), + SAFI_UNICAST, NULL, peer, connected, + NULL); } static void peer_xfer_stats(struct peer *peer_dst, struct peer *peer_src) @@ -1551,7 +1553,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection) peer_delete(peer); ret = BGP_FSM_FAILURE_AND_DELETE; } else { - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(connection); } return ret; } @@ -1797,9 +1799,9 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection) struct peer *peer = connection->peer; int status; - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(connection); - if (peer->su.sa.sa_family == AF_UNSPEC) { + if (connection->su.sa.sa_family == AF_UNSPEC) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "%s [FSM] Unable to get neighbor's IP address, waiting...", diff --git a/bgpd/bgp_memory.c b/bgpd/bgp_memory.c index edaaef602..5c3067f96 100644 --- a/bgpd/bgp_memory.c +++ b/bgpd/bgp_memory.c @@ -17,6 +17,7 @@ DEFINE_MGROUP(BGPD, "bgpd"); DEFINE_MTYPE(BGPD, BGP, "BGP instance"); DEFINE_MTYPE(BGPD, BGP_LISTENER, "BGP listen socket details"); DEFINE_MTYPE(BGPD, BGP_PEER, "BGP peer"); +DEFINE_MTYPE(BGPD, BGP_PEER_CONNECTION, "BGP peer connection"); DEFINE_MTYPE(BGPD, BGP_PEER_HOST, "BGP peer hostname"); DEFINE_MTYPE(BGPD, BGP_PEER_IFNAME, "BGP peer ifname"); DEFINE_MTYPE(BGPD, PEER_GROUP, "Peer group"); diff --git a/bgpd/bgp_memory.h b/bgpd/bgp_memory.h index 1256eafd0..7acb41eeb 100644 --- a/bgpd/bgp_memory.h +++ b/bgpd/bgp_memory.h @@ -13,6 +13,7 @@ DECLARE_MGROUP(BGPD); DECLARE_MTYPE(BGP); DECLARE_MTYPE(BGP_LISTENER); DECLARE_MTYPE(BGP_PEER); +DECLARE_MTYPE(BGP_PEER_CONNECTION); DECLARE_MTYPE(BGP_PEER_HOST); DECLARE_MTYPE(BGP_PEER_IFNAME); DECLARE_MTYPE(PEER_GROUP); diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 5ade9d82a..3e252a06f 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -35,7 +35,7 @@ extern struct zebra_privs_t bgpd_privs; -static char *bgp_get_bound_name(struct peer *peer); +static char *bgp_get_bound_name(struct peer_connection *connection); void bgp_dump_listener_info(struct vty *vty) { @@ -132,9 +132,9 @@ static int bgp_md5_set_password(struct peer_connection *connection, frr_with_privs(&bgpd_privs) { for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) if (listener->su.sa.sa_family == - peer->su.sa.sa_family) { + connection->su.sa.sa_family) { uint16_t prefixlen = - peer->su.sa.sa_family == AF_INET + connection->su.sa.sa_family == AF_INET ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN; @@ -151,8 +151,8 @@ static int bgp_md5_set_password(struct peer_connection *connection, continue; ret = bgp_md5_set_socket(listener->fd, - &peer->su, prefixlen, - password); + &connection->su, + prefixlen, password); break; } } @@ -225,7 +225,7 @@ int bgp_set_socket_ttl(struct peer_connection *connection) struct peer *peer = connection->peer; if (!peer->gtsm_hops) { - ret = sockopt_ttl(peer->su.sa.sa_family, connection->fd, + ret = sockopt_ttl(connection->su.sa.sa_family, connection->fd, peer->ttl); if (ret) { flog_err( @@ -239,7 +239,8 @@ int bgp_set_socket_ttl(struct peer_connection *connection) with the outgoing ttl. Therefore setting both. */ - ret = sockopt_ttl(peer->su.sa.sa_family, connection->fd, MAXTTL); + ret = sockopt_ttl(connection->su.sa.sa_family, connection->fd, + MAXTTL); if (ret) { flog_err( EC_LIB_SOCKET, @@ -247,7 +248,7 @@ int bgp_set_socket_ttl(struct peer_connection *connection) __func__, &peer->remote_id, errno); return ret; } - ret = sockopt_minttl(peer->su.sa.sa_family, connection->fd, + ret = sockopt_minttl(connection->su.sa.sa_family, connection->fd, MAXTTL + 1 - peer->gtsm_hops); if (ret) { flog_err( @@ -570,7 +571,8 @@ static void bgp_accept(struct event *thread) peer1->doppelganger = peer; connection->fd = bgp_sock; frr_with_privs(&bgpd_privs) { - vrf_bind(peer->bgp->vrf_id, bgp_sock, bgp_get_bound_name(peer)); + vrf_bind(peer->bgp->vrf_id, bgp_sock, + bgp_get_bound_name(peer->connection)); } bgp_peer_reg_with_nht(peer); bgp_fsm_change_status(connection, Active); @@ -611,24 +613,23 @@ static void bgp_accept(struct event *thread) } /* BGP socket bind. */ -static char *bgp_get_bound_name(struct peer *peer) +static char *bgp_get_bound_name(struct peer_connection *connection) { - if (!peer) - return NULL; + struct peer *peer = connection->peer; if ((peer->bgp->vrf_id == VRF_DEFAULT) && !peer->ifname && !peer->conf_if) return NULL; - if (peer->su.sa.sa_family != AF_INET - && peer->su.sa.sa_family != AF_INET6) + if (connection->su.sa.sa_family != AF_INET && + connection->su.sa.sa_family != AF_INET6) return NULL; // unexpected /* For IPv6 peering, interface (unnumbered or link-local with interface) * takes precedence over VRF. For IPv4 peering, explicit interface or * VRF are the situations to bind. */ - if (peer->su.sa.sa_family == AF_INET6 && peer->conf_if) + if (connection->su.sa.sa_family == AF_INET6 && peer->conf_if) return peer->conf_if; if (peer->ifname) @@ -672,11 +673,12 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst, } /* Update source selection. */ -static int bgp_update_source(struct peer *peer) +static int bgp_update_source(struct peer_connection *connection) { struct interface *ifp; union sockunion addr; int ret = 0; + struct peer *peer = connection->peer; sockunion_init(&addr); @@ -686,16 +688,16 @@ static int bgp_update_source(struct peer *peer) if (!ifp) return -1; - if (bgp_update_address(ifp, &peer->su, &addr)) + if (bgp_update_address(ifp, &connection->su, &addr)) return -1; - ret = sockunion_bind(peer->connection->fd, &addr, 0, &addr); + ret = sockunion_bind(connection->fd, &addr, 0, &addr); } /* Source is specified with IP address. */ if (peer->update_source) - ret = sockunion_bind(peer->connection->fd, peer->update_source, - 0, peer->update_source); + ret = sockunion_bind(connection->fd, peer->update_source, 0, + peer->update_source); return ret; } @@ -709,16 +711,16 @@ int bgp_connect(struct peer_connection *connection) assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_READS_ON)); ifindex_t ifindex = 0; - if (peer->conf_if && BGP_PEER_SU_UNSPEC(peer)) { + if (peer->conf_if && BGP_CONNECTION_SU_UNSPEC(connection)) { if (bgp_debug_neighbor_events(peer)) zlog_debug("Peer address not learnt: Returning from connect"); return 0; } frr_with_privs(&bgpd_privs) { /* Make socket for the peer. */ - connection->fd = vrf_sockunion_socket(&peer->su, - peer->bgp->vrf_id, - bgp_get_bound_name(peer)); + connection->fd = + vrf_sockunion_socket(&connection->su, peer->bgp->vrf_id, + bgp_get_bound_name(connection)); } if (connection->fd < 0) { peer->last_reset = PEER_DOWN_SOCKET_ERROR; @@ -755,27 +757,27 @@ int bgp_connect(struct peer_connection *connection) #ifdef IPTOS_PREC_INTERNETCONTROL frr_with_privs(&bgpd_privs) { - if (sockunion_family(&peer->su) == AF_INET) + if (sockunion_family(&connection->su) == AF_INET) setsockopt_ipv4_tos(connection->fd, bm->tcp_dscp); - else if (sockunion_family(&peer->su) == AF_INET6) + else if (sockunion_family(&connection->su) == AF_INET6) setsockopt_ipv6_tclass(connection->fd, bm->tcp_dscp); } #endif if (peer->password) { - uint16_t prefixlen = peer->su.sa.sa_family == AF_INET + uint16_t prefixlen = peer->connection->su.sa.sa_family == AF_INET ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN; - if (!BGP_PEER_SU_UNSPEC(peer)) + if (!BGP_CONNECTION_SU_UNSPEC(connection)) bgp_md5_set(connection); - bgp_md5_set_connect(connection->fd, &peer->su, prefixlen, + bgp_md5_set_connect(connection->fd, &connection->su, prefixlen, peer->password); } /* Update source bind. */ - if (bgp_update_source(peer) < 0) { + if (bgp_update_source(connection) < 0) { peer->last_reset = PEER_DOWN_SOCKET_ERROR; return connect_error; } @@ -790,8 +792,8 @@ int bgp_connect(struct peer_connection *connection) peer->host, connection->fd); /* Connect to the remote peer. */ - return sockunion_connect(connection->fd, &peer->su, htons(peer->port), - ifindex); + return sockunion_connect(connection->fd, &connection->su, + htons(peer->port), ifindex); } /* After TCP connection is established. Get local address and port. */ diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 729f5e6bb..d8a52c62b 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -595,7 +595,7 @@ bool bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) p.family = AF_INET; p.prefixlen = IPV4_MAX_BITLEN; - p.u.prefix4 = peer->su.sin.sin_addr; + p.u.prefix4 = peer->connection->su.sin.sin_addr; dest2 = bgp_node_match(peer->bgp->connected_table[AFI_IP], &p); if (!dest2) { @@ -628,7 +628,7 @@ bool bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) p.family = AF_INET6; p.prefixlen = IPV6_MAX_BITLEN; - p.u.prefix6 = peer->su.sin6.sin6_addr; + p.u.prefix6 = peer->connection->su.sin6.sin6_addr; dest2 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p); if (!dest2) { @@ -670,7 +670,7 @@ bool bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, if (paf->peer == exclude) continue; - p.u.prefix6 = paf->peer->su.sin6.sin6_addr; + p.u.prefix6 = paf->peer->connection->su.sin6.sin6_addr; dest2 = bgp_node_match(bgp->connected_table[AFI_IP6], &p); if (dest1 == dest2) { bgp_dest_unlock_node(dest1); @@ -712,7 +712,7 @@ bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, if (paf->peer == exclude) continue; - p.u.prefix4 = paf->peer->su.sin.sin_addr; + p.u.prefix4 = paf->peer->connection->su.sin.sin_addr; dest2 = bgp_node_match(bgp->connected_table[AFI_IP], &p); if (dest1 == dest2) { diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 8bc5846b2..60d6f74e1 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -173,20 +173,21 @@ void bgp_replace_nexthop_by_peer(struct peer *from, struct peer *to) afi_t afi; ifindex_t ifindex = 0; - if (!sockunion2hostprefix(&from->su, &pp)) + if (!sockunion2hostprefix(&from->connection->su, &pp)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (from->conf_if && IN6_IS_ADDR_LINKLOCAL(&from->su.sin6.sin6_addr)) - ifindex = from->su.sin6.sin6_scope_id; + if (from->conf_if && + IN6_IS_ADDR_LINKLOCAL(&from->connection->su.sin6.sin6_addr)) + ifindex = from->connection->su.sin6.sin6_scope_id; afi = family2afi(pp.family); bncp = bnc_find(&from->bgp->nexthop_cache_table[afi], &pp, 0, ifindex); - if (!sockunion2hostprefix(&to->su, &pt)) + if (!sockunion2hostprefix(&to->connection->su, &pt)) return; /* @@ -194,8 +195,9 @@ void bgp_replace_nexthop_by_peer(struct peer *from, struct peer *to) * tagged into this fun */ ifindex = 0; - if (to->conf_if && IN6_IS_ADDR_LINKLOCAL(&to->su.sin6.sin6_addr)) - ifindex = to->su.sin6.sin6_scope_id; + if (to->conf_if && + IN6_IS_ADDR_LINKLOCAL(&to->connection->su.sin6.sin6_addr)) + ifindex = to->connection->su.sin6.sin6_scope_id; bnct = bnc_find(&to->bgp->nexthop_cache_table[afi], &pt, 0, ifindex); if (bnct != bncp) @@ -240,10 +242,10 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) { struct prefix p; struct bgp_nexthop_cache *bnc; - afi_t afi = family2afi(peer->su.sa.sa_family); + afi_t afi = family2afi(peer->connection->su.sa.sa_family); ifindex_t ifindex = 0; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { /* * In scenarios where unnumbered BGP session is brought * down by shutting down the interface before unconfiguring @@ -261,8 +263,8 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) * tagged into this fun */ if (afi == AFI_IP6 && - IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&peer->bgp->nexthop_cache_table[afi], &p, 0, ifindex); } @@ -327,9 +329,11 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, * the ifindex. */ if (afi == AFI_IP6 && - IN6_IS_ADDR_LINKLOCAL(&pi->peer->su.sin6.sin6_addr) && - IPV6_ADDR_SAME(&pi->peer->su.sin6.sin6_addr, &p.u.prefix6)) - ifindex = pi->peer->su.sin6.sin6_scope_id; + IN6_IS_ADDR_LINKLOCAL( + &pi->peer->connection->su.sin6.sin6_addr) && + IPV6_ADDR_SAME(&pi->peer->connection->su.sin6.sin6_addr, + &p.u.prefix6)) + ifindex = pi->peer->connection->su.sin6.sin6_scope_id; if (!is_bgp_static_route && orig_prefix && prefix_same(&p, orig_prefix)) { @@ -351,8 +355,8 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, * tagged into this fun */ if (afi == AFI_IP6 && peer->conf_if && - IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) { - ifindex = peer->su.sin6.sin6_scope_id; + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) { + ifindex = peer->connection->su.sin6.sin6_scope_id; if (ifindex == 0) { if (BGP_DEBUG(nht, NHT)) { zlog_debug( @@ -363,7 +367,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, } } - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { if (BGP_DEBUG(nht, NHT)) { zlog_debug( "%s: Attempting to register with unknown AFI %d (not %d or %d)", @@ -519,14 +523,15 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer) * nodes of V6 nexthop cache to find the bnc, it is * currently not being called here. */ - if (!sockunion2hostprefix(&peer->su, &p)) + if (!sockunion2hostprefix(&peer->connection->su, &p)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (afi == AFI_IP6 && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)], &p, 0, ifindex); if (!bnc) { @@ -869,17 +874,18 @@ void bgp_nht_interface_events(struct peer *peer) struct prefix p; ifindex_t ifindex = 0; - if (!IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) + if (!IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) return; - if (!sockunion2hostprefix(&peer->su, &p)) + if (!sockunion2hostprefix(&peer->connection->su, &p)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; table = &bgp->nexthop_cache_table[AFI_IP6]; bnc = bnc_find(table, &p, 0, ifindex); @@ -1469,7 +1475,7 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer) return; bgp = peer->bgp; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); return; @@ -1481,8 +1487,9 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer) * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&bgp->nexthop_cache_table[AFI_IP6], &p, 0, ifindex); if (!bnc) @@ -1518,7 +1525,7 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) bgp = peer->bgp; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); return; @@ -1530,8 +1537,9 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&bgp->nexthop_cache_table[AFI_IP6], &p, 0, ifindex); if (!bnc) diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 9bfc06ec3..da70f67c1 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -1712,11 +1712,11 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, * supporting RFC-5549 for * Link-Local peering only */ - if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) - && peer->su.sa.sa_family == AF_INET6 - && afi == AFI_IP - && (safi == SAFI_UNICAST || safi == SAFI_MPLS_VPN - || safi == SAFI_LABELED_UNICAST)) { + if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) && + peer->connection->su.sa.sa_family == AF_INET6 && + afi == AFI_IP && + (safi == SAFI_UNICAST || safi == SAFI_MPLS_VPN || + safi == SAFI_LABELED_UNICAST)) { /* RFC 5549 Extended Next Hop Encoding */ SET_FLAG(peer->cap, PEER_CAP_ENHE_ADV); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 0ae621071..bdd99d29b 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9340,7 +9340,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p, if (json_paths) json_object_string_addf(json_path, "peerId", "%pSU", - &path->peer->su); + &path->peer->connection->su); /* Print aspath */ if (attr->aspath) { @@ -9960,7 +9960,7 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer, json_peer); else json_object_object_addf(json_adv_to, json_peer, "%pSU", - &peer->su); + &peer->connection->su); } else { if (*first) { vty_out(vty, "%s", header); @@ -9974,12 +9974,12 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer, peer->conf_if); else vty_out(vty, " %s(%pSU)", peer->hostname, - &peer->su); + &peer->connection->su); } else { if (peer->conf_if) vty_out(vty, " %s", peer->conf_if); else - vty_out(vty, " %pSU", &peer->su); + vty_out(vty, " %pSU", &peer->connection->su); } } } @@ -10405,7 +10405,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, if (json_paths) { json_object_string_addf(json_peer, "peerId", "%pSU", - &path->peer->su); + &path->peer->connection->su); json_object_string_addf(json_peer, "routerId", "%pI4", &path->peer->remote_id); @@ -10440,7 +10440,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, path->peer->host); else vty_out(vty, " from %pSU", - &path->peer->su); + &path->peer->connection->su); } if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) @@ -14792,8 +14792,8 @@ static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer, if (safi == SAFI_LABELED_UNICAST) safi = SAFI_UNICAST; - return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, show_flags, - RPKI_NOT_BEING_USED); + return bgp_show(vty, peer->bgp, afi, safi, type, &peer->connection->su, + show_flags, RPKI_NOT_BEING_USED); } /* @@ -15068,8 +15068,8 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, /* Check source address. * Note: for aggregate route, peer can have unspec af type. */ - if (pinfo->sub_type != BGP_ROUTE_AGGREGATE - && !sockunion2hostprefix(&peer->su, &q)) + if (pinfo->sub_type != BGP_ROUTE_AGGREGATE && + !sockunion2hostprefix(&peer->connection->su, &q)) return 0; dest = bgp_node_match(bgp_distance_table[afi][safi], &q); @@ -15545,7 +15545,7 @@ static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg) struct vty *vty = arg; struct peer *peer = bucket->data; - vty_out(vty, "\tPeer: %s %pSU\n", peer->host, &peer->su); + vty_out(vty, "\tPeer: %s %pSU\n", peer->host, &peer->connection->su); } DEFUN (show_bgp_listeners, diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index c1057b719..274df5197 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -282,14 +282,14 @@ route_match_peer(void *rule, const struct prefix *prefix, void *object) } if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (sockunion_same(su, &peer->su)) + if (sockunion_same(su, &peer->connection->su)) return RMAP_MATCH; return RMAP_NOMATCH; } else { group = peer->group; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { - if (sockunion_same(su, &peer->su)) + if (sockunion_same(su, &peer->connection->su)) return RMAP_MATCH; } return RMAP_NOMATCH; @@ -574,11 +574,11 @@ route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object) path = object; peer = path->peer; - if (!peer || sockunion_family(&peer->su) != AF_INET) + if (!peer || sockunion_family(&peer->connection->su) != AF_INET) return RMAP_NOMATCH; p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; + p.prefix = peer->connection->su.sin.sin_addr; p.prefixlen = IPV4_MAX_BITLEN; alist = access_list_lookup(AFI_IP, (char *)rule); @@ -927,11 +927,11 @@ route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix, path = object; peer = path->peer; - if (!peer || sockunion_family(&peer->su) != AF_INET) + if (!peer || sockunion_family(&peer->connection->su) != AF_INET) return RMAP_NOMATCH; p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; + p.prefix = peer->connection->su.sin.sin_addr; p.prefixlen = IPV4_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP, (char *)rule); diff --git a/bgpd/bgp_snmp_bgp4.c b/bgpd/bgp_snmp_bgp4.c index 0d5b06da1..0c391b621 100644 --- a/bgpd/bgp_snmp_bgp4.c +++ b/bgpd/bgp_snmp_bgp4.c @@ -83,10 +83,10 @@ static struct peer *peer_lookup_addr_ipv4(struct in_addr *src) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) + if (sockunion_family(&peer->connection->su) != AF_INET) continue; - if (sockunion2ip(&peer->su) == src->s_addr) + if (sockunion2ip(&peer->connection->su) == src->s_addr) return peer; } } @@ -104,22 +104,22 @@ static struct peer *bgp_peer_lookup_next(struct in_addr *src) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) + if (sockunion_family(&peer->connection->su) != AF_INET) continue; - if (ntohl(sockunion2ip(&peer->su)) <= + if (ntohl(sockunion2ip(&peer->connection->su)) <= ntohl(src->s_addr)) continue; if (!next_peer || - ntohl(sockunion2ip(&next_peer->su)) > - ntohl(sockunion2ip(&peer->su))) { + ntohl(sockunion2ip(&next_peer->connection->su)) > + ntohl(sockunion2ip(&peer->connection->su))) { next_peer = peer; } } } if (next_peer) { - src->s_addr = sockunion2ip(&next_peer->su); + src->s_addr = sockunion2ip(&next_peer->connection->su); return next_peer; } @@ -417,7 +417,8 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], if (dest) { for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) - if (sockunion_same(&path->peer->su, &su)) + if (sockunion_same(&path->peer->connection->su, + &su)) return path; bgp_dest_unlock_node(dest); @@ -467,15 +468,18 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) { - if (path->peer->su.sin.sin_family == AF_INET && + if (path->peer->connection->su.sin.sin_family == + AF_INET && ntohl(paddr.s_addr) < - ntohl(path->peer->su.sin.sin_addr - .s_addr)) { + ntohl(path->peer->connection->su.sin + .sin_addr.s_addr)) { if (min) { - if (ntohl(path->peer->su.sin + if (ntohl(path->peer->connection + ->su.sin .sin_addr .s_addr) < - ntohl(min->peer->su.sin + ntohl(min->peer->connection + ->su.sin .sin_addr .s_addr)) min = path; @@ -497,7 +501,8 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], *offset = rn_p->prefixlen; offset++; oid_copy_in_addr(offset, - &min->peer->su.sin.sin_addr); + &min->peer->connection->su.sin + .sin_addr); addr->prefix = rn_p->u.prefix4; addr->prefixlen = rn_p->prefixlen; @@ -535,7 +540,7 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[], switch (v->magic) { case BGP4PATHATTRPEER: /* 1 */ - return SNMP_IPADDRESS(path->peer->su.sin.sin_addr); + return SNMP_IPADDRESS(path->peer->connection->su.sin.sin_addr); case BGP4PATHATTRIPADDRPREFIXLEN: /* 2 */ return SNMP_INTEGER(addr.prefixlen); case BGP4PATHATTRIPADDRPREFIX: /* 3 */ diff --git a/bgpd/bgp_snmp_bgp4v2.c b/bgpd/bgp_snmp_bgp4v2.c index 5e77a9297..cfafae55d 100644 --- a/bgpd/bgp_snmp_bgp4v2.c +++ b/bgpd/bgp_snmp_bgp4v2.c @@ -43,14 +43,16 @@ static struct peer *peer_lookup_all_vrf(struct ipaddr *addr) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - switch (sockunion_family(&peer->su)) { + switch (sockunion_family(&peer->connection->su)) { case AF_INET: - if (IPV4_ADDR_SAME(&peer->su.sin.sin_addr, + if (IPV4_ADDR_SAME(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr)) return peer; break; case AF_INET6: - if (IPV6_ADDR_SAME(&peer->su.sin6.sin6_addr, + if (IPV6_ADDR_SAME(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr)) return peer; break; @@ -74,38 +76,47 @@ static struct peer *peer_lookup_all_vrf_next(struct ipaddr *addr, oid *offset, for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - sa_family_t peer_family = sockunion_family(&peer->su); + sa_family_t peer_family = + sockunion_family(&peer->connection->su); if (peer_family != family) continue; - switch (sockunion_family(&peer->su)) { + switch (peer_family) { case AF_INET: oid2in_addr(offset, IN_ADDR_SIZE, &addr->ip._v4_addr); - if (IPV4_ADDR_CMP(&peer->su.sin.sin_addr, + if (IPV4_ADDR_CMP(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr) < 0 || - IPV4_ADDR_SAME(&peer->su.sin.sin_addr, + IPV4_ADDR_SAME(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr)) continue; if (!next_peer || - IPV4_ADDR_CMP(&next_peer->su.sin.sin_addr, - &peer->su.sin.sin_addr) > 0) + IPV4_ADDR_CMP(&next_peer->connection->su.sin + .sin_addr, + &peer->connection->su.sin + .sin_addr) > 0) next_peer = peer; break; case AF_INET6: oid2in6_addr(offset, &addr->ip._v6_addr); - if (IPV6_ADDR_CMP(&peer->su.sin6.sin6_addr, + if (IPV6_ADDR_CMP(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr) < 0 || - IPV6_ADDR_SAME(&peer->su.sin6.sin6_addr, + IPV6_ADDR_SAME(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr)) continue; if (!next_peer || - IPV6_ADDR_CMP(&next_peer->su.sin6.sin6_addr, - &peer->su.sin6.sin6_addr) > 0) + IPV6_ADDR_CMP(&next_peer->connection->su + .sin6.sin6_addr, + &peer->connection->su.sin6 + .sin6_addr) > 0) next_peer = peer; break; @@ -158,13 +169,15 @@ static struct peer *bgpv2PeerTable_lookup(struct variable *v, oid name[], if (peer == NULL) return NULL; - switch (sockunion_family(&peer->su)) { + switch (sockunion_family(&peer->connection->su)) { case AF_INET: - oid_copy_in_addr(offset, &peer->su.sin.sin_addr); + oid_copy_in_addr(offset, + &peer->connection->su.sin.sin_addr); *length = afi_len + namelen; return peer; case AF_INET6: - oid_copy_in6_addr(offset, &peer->su.sin6.sin6_addr); + oid_copy_in6_addr(offset, + &peer->connection->su.sin6.sin6_addr); *length = afi_len + namelen; return peer; default: @@ -467,7 +480,8 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, if (dest) { for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) - if (sockunion_same(&path->peer->su, &su)) + if (sockunion_same(&path->peer->connection->su, + &su)) return path; bgp_dest_unlock_node(dest); @@ -532,27 +546,29 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) { sa_family_t path_family = - sockunion_family(&path->peer->su); + sockunion_family(&path->peer->connection->su); if (path_family == AF_INET && IPV4_ADDR_CMP(&paddr.ip._v4_addr, - &path->peer->su.sin.sin_addr) < 0) { + &path->peer->connection->su.sin + .sin_addr) < 0) { if (!min || (min && - IPV4_ADDR_CMP( - &path->peer->su.sin.sin_addr, - &min->peer->su.sin.sin_addr) < 0)) + IPV4_ADDR_CMP(&path->peer->connection->su + .sin.sin_addr, + &min->peer->connection->su + .sin.sin_addr) < 0)) min = path; } else if (path_family == AF_INET6 && - IPV6_ADDR_CMP( - &paddr.ip._v6_addr, - &path->peer->su.sin6.sin6_addr) < - 0) { + IPV6_ADDR_CMP(&paddr.ip._v6_addr, + &path->peer->connection->su + .sin6.sin6_addr) < 0) { if (!min || (min && - IPV6_ADDR_CMP( - &path->peer->su.sin6.sin6_addr, - &min->peer->su.sin6.sin6_addr) < + IPV6_ADDR_CMP(&path->peer->connection->su + .sin6.sin6_addr, + &min->peer->connection->su + .sin6.sin6_addr) < 0)) min = path; } @@ -578,11 +594,13 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, /* Encode peer's IP into OID */ if (family == AF_INET) { oid_copy_in_addr(offset, - &min->peer->su.sin.sin_addr); + &min->peer->connection->su.sin + .sin_addr); addr->u.prefix4 = rn_p->u.prefix4; } else { - oid_copy_in6_addr( - offset, &min->peer->su.sin6.sin6_addr); + oid_copy_in6_addr(offset, + &min->peer->connection->su + .sin6.sin6_addr); addr->u.prefix6 = rn_p->u.prefix6; } diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 77192b42b..e47ea8aa8 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -279,6 +279,8 @@ static void *updgrp_hash_alloc(void *p) updgrp = XCALLOC(MTYPE_BGP_UPDGRP, sizeof(struct update_group)); memcpy(updgrp, in, sizeof(struct update_group)); updgrp->conf = XCALLOC(MTYPE_BGP_PEER, sizeof(struct peer)); + updgrp->conf->connection = XCALLOC(MTYPE_BGP_PEER_CONNECTION, + sizeof(struct peer_connection)); conf_copy(updgrp->conf, in->conf, in->afi, in->safi); return updgrp; } @@ -634,7 +636,7 @@ static bool updgrp_hash_cmp(const void *p1, const void *p2) if ((CHECK_FLAG(pe1->flags, PEER_FLAG_LONESOUL) || CHECK_FLAG(pe1->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)) && - !sockunion_same(&pe1->su, &pe2->su)) + !sockunion_same(&pe1->connection->su, &pe2->connection->su)) return false; return true; @@ -987,13 +989,18 @@ static struct update_group *update_group_find(struct peer_af *paf) struct update_group *updgrp; struct update_group tmp; struct peer tmp_conf; + struct peer_connection tmp_connection; if (!peer_established((PAF_PEER(paf))->connection)) return NULL; memset(&tmp, 0, sizeof(tmp)); memset(&tmp_conf, 0, sizeof(tmp_conf)); + memset(&tmp_connection, 0, sizeof(struct peer_connection)); + tmp.conf = &tmp_conf; + tmp_conf.connection = &tmp_connection; + peer2_updgrp_copy(&tmp, paf); updgrp = hash_lookup(paf->peer->bgp->update_groups[paf->afid], &tmp); @@ -1006,10 +1013,14 @@ static struct update_group *update_group_create(struct peer_af *paf) struct update_group *updgrp; struct update_group tmp; struct peer tmp_conf; + struct peer_connection tmp_connection; memset(&tmp, 0, sizeof(tmp)); memset(&tmp_conf, 0, sizeof(tmp_conf)); + memset(&tmp_connection, 0, sizeof(tmp_connection)); + tmp.conf = &tmp_conf; + tmp_conf.connection = &tmp_connection; peer2_updgrp_copy(&tmp, paf); updgrp = hash_get(paf->peer->bgp->update_groups[paf->afid], &tmp, @@ -1039,6 +1050,7 @@ static void update_group_delete(struct update_group *updgrp) XFREE(MTYPE_BGP_PEER_IFNAME, updgrp->conf->ifname); + XFREE(MTYPE_BGP_PEER_CONNECTION, updgrp->conf->connection); XFREE(MTYPE_BGP_PEER, updgrp->conf); XFREE(MTYPE_BGP_UPDGRP, updgrp); } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 4f7e2f58a..f6db3fb36 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -11884,10 +11884,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, if (peer->conf_if) json_object_string_add(json_peer, "idType", "interface"); - else if (peer->su.sa.sa_family == AF_INET) + else if (peer->connection->su.sa.sa_family == AF_INET) json_object_string_add(json_peer, "idType", "ipv4"); - else if (peer->su.sa.sa_family == AF_INET6) + else if (peer->connection->su.sa.sa_family == AF_INET6) json_object_string_add(json_peer, "idType", "ipv6"); json_object_object_add(json_peers, peer->host, @@ -12746,10 +12746,10 @@ static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p, if (p->conf_if) { if (json) json_object_string_addf(json, "neighborAddr", "%pSU", - &p->su); + &p->connection->su); else vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if, - &p->su); + &p->connection->su); } else { snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag, p->host); @@ -13417,19 +13417,19 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (!use_json) { if (p->conf_if) /* Configured interface name. */ vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if, - &p->su); + &p->connection->su); else /* Configured IP address. */ vty_out(vty, "BGP neighbor is %s%s, ", dn_flag, p->host); } if (use_json) { - if (p->conf_if && BGP_PEER_SU_UNSPEC(p)) + if (p->conf_if && BGP_CONNECTION_SU_UNSPEC(p->connection)) json_object_string_add(json_neigh, "bgpNeighborAddr", "none"); - else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p)) + else if (p->conf_if && !BGP_CONNECTION_SU_UNSPEC(p->connection)) json_object_string_addf(json_neigh, "bgpNeighborAddr", - "%pSU", &p->su); + "%pSU", &p->connection->su); asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation); @@ -13558,7 +13558,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (dn_flag[0]) { struct prefix prefix, *range = NULL; - if (sockunion2hostprefix(&(p->su), &prefix)) + if (sockunion2hostprefix(&p->connection->su, + &prefix)) range = peer_group_lookup_dynamic_neighbor_range( p->group, &prefix); @@ -13577,7 +13578,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (dn_flag[0]) { struct prefix prefix, *range = NULL; - if (sockunion2hostprefix(&(p->su), &prefix)) + if (sockunion2hostprefix(&p->connection->su, + &prefix)) range = peer_group_lookup_dynamic_neighbor_range( p->group, &prefix); @@ -15267,7 +15269,7 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp, json_neighbor); } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection->su, su)) { found = true; bgp_show_peer_gr_status(vty, peer, json_neighbor); @@ -15337,7 +15339,7 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, json); } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection->su, su)) { find = 1; bgp_show_peer(vty, peer, use_json, json); @@ -15359,7 +15361,9 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, break; } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection + ->su, + su)) { find = 1; bgp_show_peer(vty, peer, use_json, json); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 40f229e5b..a518137f3 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -80,7 +80,6 @@ #include "bgp_trace.h" DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)"); -DEFINE_MTYPE_STATIC(BGPD, BGP_PEER_CONNECTION, "BGP Connection information"); DEFINE_QOBJ_TYPE(bgp_master); DEFINE_QOBJ_TYPE(bgp); DEFINE_QOBJ_TYPE(peer); @@ -948,13 +947,13 @@ int peer_cmp(struct peer *p1, struct peer *p2) } else return strcmp(p1->group->name, p2->group->name); - return sockunion_cmp(&p1->su, &p2->su); + return sockunion_cmp(&p1->connection->su, &p2->connection->su); } static unsigned int peer_hash_key_make(const void *p) { const struct peer *peer = p; - return sockunion_hash(&peer->su); + return sockunion_hash(&peer->connection->su); } static bool peer_hash_same(const void *p1, const void *p2) @@ -962,9 +961,9 @@ static bool peer_hash_same(const void *p1, const void *p2) const struct peer *peer1 = p1; const struct peer *peer2 = p2; - return (sockunion_same(&peer1->su, &peer2->su) - && CHECK_FLAG(peer1->flags, PEER_FLAG_CONFIG_NODE) - == CHECK_FLAG(peer2->flags, PEER_FLAG_CONFIG_NODE)); + return (sockunion_same(&peer1->connection->su, &peer2->connection->su) && + CHECK_FLAG(peer1->flags, PEER_FLAG_CONFIG_NODE) == + CHECK_FLAG(peer2->flags, PEER_FLAG_CONFIG_NODE)); } void peer_flag_inherit(struct peer *peer, uint64_t flag) @@ -1220,7 +1219,8 @@ static void peer_free(struct peer *peer) /* Free connected nexthop, if present */ if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE) && !peer_dynamic_neighbor(peer)) - bgp_delete_connected_nexthop(family2afi(peer->su.sa.sa_family), + bgp_delete_connected_nexthop(family2afi(peer->connection->su.sa + .sa_family), peer); FOREACH_AFI_SAFI (afi, safi) { @@ -1605,7 +1605,7 @@ void peer_xfer_config(struct peer *peer_dst, struct peer *peer_src) peer_dst->ttl = peer_src->ttl; } -static int bgp_peer_conf_if_to_su_update_v4(struct peer *peer, +static int bgp_peer_conf_if_to_su_update_v4(struct peer_connection *connection, struct interface *ifp) { struct connected *ifc; @@ -1620,44 +1620,43 @@ static int bgp_peer_conf_if_to_su_update_v4(struct peer *peer, if (ifc->address && (ifc->address->family == AF_INET)) { prefix_copy(&p, CONNECTED_PREFIX(ifc)); if (p.prefixlen == 30) { - peer->su.sa.sa_family = AF_INET; + connection->su.sa.sa_family = AF_INET; addr = ntohl(p.u.prefix4.s_addr); if (addr % 4 == 1) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr + 1); else if (addr % 4 == 2) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr - 1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su.sin.sin_len = + connection->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; } else if (p.prefixlen == 31) { - peer->su.sa.sa_family = AF_INET; + connection->su.sa.sa_family = AF_INET; addr = ntohl(p.u.prefix4.s_addr); if (addr % 2 == 0) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr + 1); else - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr - 1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su.sin.sin_len = + connection->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; - } else if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s: IPv4 interface address is not /30 or /31, v4 session not started", - peer->conf_if); + } else if (bgp_debug_neighbor_events(connection->peer)) + zlog_debug("%s: IPv4 interface address is not /30 or /31, v4 session not started", + connection->peer->conf_if); } } return 0; } -static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, +static bool bgp_peer_conf_if_to_su_update_v6(struct peer_connection *connection, struct interface *ifp) { struct nbr_connected *ifc_nbr; @@ -1665,13 +1664,13 @@ static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, /* Have we learnt the peer's IPv6 link-local address? */ if (ifp->nbr_connected && (ifc_nbr = listnode_head(ifp->nbr_connected))) { - peer->su.sa.sa_family = AF_INET6; - memcpy(&peer->su.sin6.sin6_addr, &ifc_nbr->address->u.prefix, - sizeof(struct in6_addr)); + connection->su.sa.sa_family = AF_INET6; + memcpy(&connection->su.sin6.sin6_addr, + &ifc_nbr->address->u.prefix, sizeof(struct in6_addr)); #ifdef SIN6_LEN - peer->su.sin6.sin6_len = sizeof(struct sockaddr_in6); + connection->su.sin6.sin6_len = sizeof(struct sockaddr_in6); #endif - peer->su.sin6.sin6_scope_id = ifp->ifindex; + connection->su.sin6.sin6_scope_id = ifp->ifindex; return true; } @@ -1683,13 +1682,14 @@ static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, * learnt/derived peer address. If the address has changed, update the * password on the listen socket, if needed. */ -void bgp_peer_conf_if_to_su_update(struct peer *peer) +void bgp_peer_conf_if_to_su_update(struct peer_connection *connection) { struct interface *ifp; int prev_family; int peer_addr_updated = 0; struct listnode *node; union sockunion old_su; + struct peer *peer = connection->peer; /* * This function is only ever needed when FRR an interface @@ -1699,9 +1699,9 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) if (!peer->conf_if) return; - old_su = peer->su; + old_su = connection->su; - prev_family = peer->su.sa.sa_family; + prev_family = connection->su.sa.sa_family; if ((ifp = if_lookup_by_name(peer->conf_if, peer->bgp->vrf_id))) { peer->ifp = ifp; /* If BGP unnumbered is not "v6only", we first see if we can @@ -1710,7 +1710,8 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) */ if (!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) peer_addr_updated = - bgp_peer_conf_if_to_su_update_v4(peer, ifp); + bgp_peer_conf_if_to_su_update_v4(connection, + ifp); /* If "v6only" or we can't derive peer's IPv4 address, see if * we've @@ -1720,7 +1721,8 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) */ if (!peer_addr_updated) peer_addr_updated = - bgp_peer_conf_if_to_su_update_v6(peer, ifp); + bgp_peer_conf_if_to_su_update_v6(connection, + ifp); } /* If we could derive the peer address, we may need to install the * password @@ -1732,20 +1734,21 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) if (peer_addr_updated) { if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD) && prev_family == AF_UNSPEC) - bgp_md5_set(peer->connection); + bgp_md5_set(connection); } else { if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD) && prev_family != AF_UNSPEC) - bgp_md5_unset(peer->connection); - peer->su.sa.sa_family = AF_UNSPEC; - memset(&peer->su.sin6.sin6_addr, 0, sizeof(struct in6_addr)); + bgp_md5_unset(connection); + connection->su.sa.sa_family = AF_UNSPEC; + memset(&connection->su.sin6.sin6_addr, 0, + sizeof(struct in6_addr)); } /* * If they are the same, nothing to do here, move along */ - if (!sockunion_same(&old_su, &peer->su)) { - union sockunion new_su = peer->su; + if (!sockunion_same(&old_su, &connection->su)) { + union sockunion new_su = connection->su; struct bgp *bgp = peer->bgp; /* @@ -1774,11 +1777,11 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) * scan through looking for a matching * su if needed. */ - peer->su = old_su; + connection->su = old_su; hash_release(peer->bgp->peerhash, peer); listnode_delete(peer->bgp->peer, peer); - peer->su = new_su; + connection->su = new_su; (void)hash_get(peer->bgp->peerhash, peer, hash_alloc_intern); listnode_add_sort(peer->bgp->peer, peer); @@ -1845,13 +1848,13 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, if (conf_if) { peer->conf_if = XSTRDUP(MTYPE_PEER_CONF_IF, conf_if); if (su) - peer->su = *su; + peer->connection->su = *su; else - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(peer->connection); XFREE(MTYPE_BGP_PEER_HOST, peer->host); peer->host = XSTRDUP(MTYPE_BGP_PEER_HOST, conf_if); } else if (su) { - peer->su = *su; + peer->connection->su = *su; sockunion2str(su, buf, SU_ADDRSTRLEN); XFREE(MTYPE_BGP_PEER_HOST, peer->host); peer->host = XSTRDUP(MTYPE_BGP_PEER_HOST, buf); @@ -1890,7 +1893,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, active = peer_active(peer); if (!active) { - if (peer->su.sa.sa_family == AF_UNSPEC) + if (peer->connection->su.sa.sa_family == AF_UNSPEC) peer->last_reset = PEER_DOWN_NBR_ADDR; else peer->last_reset = PEER_DOWN_NOAFI_ACTIVATED; @@ -2648,9 +2651,10 @@ int peer_delete(struct peer *peer) /* Password configuration */ if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD)) { XFREE(MTYPE_PEER_PASSWORD, peer->password); - if (!accept_peer && !BGP_PEER_SU_UNSPEC(peer) - && !CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) - && !CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_NEIGHBOR)) + if (!accept_peer && + !BGP_CONNECTION_SU_UNSPEC(peer->connection) && + !CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) && + !CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_NEIGHBOR)) bgp_md5_unset(peer->connection); } @@ -2862,7 +2866,7 @@ static void peer_group2peer_config_copy(struct peer_group *group, PEER_STR_ATTR_INHERIT(peer, group, password, MTYPE_PEER_PASSWORD); - if (!BGP_PEER_SU_UNSPEC(peer)) + if (!BGP_CONNECTION_SU_UNSPEC(peer->connection)) bgp_md5_set(peer->connection); /* update-source apply */ @@ -3089,8 +3093,8 @@ int peer_group_listen_range_del(struct peer_group *group, struct prefix *range) if (!peer_dynamic_neighbor(peer)) continue; - if (sockunion2hostprefix(&peer->su, &prefix2) - && prefix_match(prefix, &prefix2)) { + if (sockunion2hostprefix(&peer->connection->su, &prefix2) && + prefix_match(prefix, &prefix2)) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "Deleting dynamic neighbor %s group %s upon delete of listen range %pFX", @@ -4121,8 +4125,11 @@ struct peer *peer_lookup(struct bgp *bgp, union sockunion *su) { struct peer *peer = NULL; struct peer tmp_peer; + struct peer_connection connection; + memset(&connection, 0, sizeof(struct peer_connection)); memset(&tmp_peer, 0, sizeof(struct peer)); + tmp_peer.connection = &connection; /* * We do not want to find the doppelganger peer so search for the peer @@ -4131,7 +4138,7 @@ struct peer *peer_lookup(struct bgp *bgp, union sockunion *su) */ SET_FLAG(tmp_peer.flags, PEER_FLAG_CONFIG_NODE); - tmp_peer.su = *su; + connection.su = *su; if (bgp != NULL) { peer = hash_lookup(bgp->peerhash, &tmp_peer); @@ -4365,7 +4372,7 @@ bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf, /* If peer is configured at least one address family return 1. */ bool peer_active(struct peer *peer) { - if (BGP_PEER_SU_UNSPEC(peer)) + if (BGP_CONNECTION_SU_UNSPEC(peer->connection)) return false; if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] @@ -6572,7 +6579,7 @@ int peer_password_set(struct peer *peer, const char *password) * Attempt to install password on socket and skip peer-group * mechanics. */ - if (BGP_PEER_SU_UNSPEC(peer)) + if (BGP_CONNECTION_SU_UNSPEC(peer->connection)) return BGP_SUCCESS; return (bgp_md5_set(peer->connection) >= 0) ? BGP_SUCCESS @@ -6606,7 +6613,7 @@ int peer_password_set(struct peer *peer, const char *password) bgp_session_reset(member); /* Attempt to install password on socket. */ - if (!BGP_PEER_SU_UNSPEC(member) && + if (!BGP_CONNECTION_SU_UNSPEC(member->connection) && bgp_md5_set(member->connection) < 0) ret = BGP_ERR_TCPSIG_FAILED; } @@ -6652,7 +6659,7 @@ int peer_password_unset(struct peer *peer) bgp_session_reset(peer); /* Attempt to uninstall password on socket. */ - if (!BGP_PEER_SU_UNSPEC(peer)) + if (!BGP_CONNECTION_SU_UNSPEC(peer->connection)) bgp_md5_unset(peer->connection); /* Skip peer-group mechanics for regular peers. */ return 0; @@ -6679,7 +6686,7 @@ int peer_password_unset(struct peer *peer) bgp_session_reset(member); /* Attempt to uninstall password on socket. */ - if (!BGP_PEER_SU_UNSPEC(member)) + if (!BGP_CONNECTION_SU_UNSPEC(member->connection)) bgp_md5_unset(member->connection); } @@ -7876,13 +7883,13 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) peer->gtsm_hops = gtsm_hops; if (peer->connection->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa.sa_family, peer->connection->fd, MAXTTL + 1 - gtsm_hops); if ((peer->connection->status < Established) && peer->doppelganger && (peer->doppelganger->connection->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa.sa_family, peer->doppelganger->connection->fd, MAXTTL + 1 - gtsm_hops); } else { @@ -7890,6 +7897,8 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) group->conf->gtsm_hops = gtsm_hops; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, gpeer)) { + struct peer_connection *connection = + gpeer->connection; gpeer->gtsm_hops = group->conf->gtsm_hops; /* Change setting of existing peer @@ -7900,16 +7909,16 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) * no session then do nothing (will get * handled by next connection) */ - if (gpeer->connection->fd >= 0 && + if (connection->fd >= 0 && gpeer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) - sockopt_minttl(gpeer->su.sa.sa_family, - gpeer->connection->fd, + sockopt_minttl(connection->su.sa.sa_family, + connection->fd, MAXTTL + 1 - gpeer->gtsm_hops); - if ((gpeer->connection->status < Established) && + if ((connection->status < Established) && gpeer->doppelganger && (gpeer->doppelganger->connection->fd >= 0)) - sockopt_minttl(gpeer->su.sa.sa_family, + sockopt_minttl(connection->su.sa.sa_family, gpeer->doppelganger ->connection->fd, MAXTTL + 1 - gtsm_hops); @@ -7945,13 +7954,13 @@ int peer_ttl_security_hops_unset(struct peer *peer) ret = peer_ebgp_multihop_unset(peer); else { if (peer->connection->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa.sa_family, peer->connection->fd, 0); if ((peer->connection->status < Established) && peer->doppelganger && (peer->doppelganger->connection->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa.sa_family, peer->doppelganger->connection->fd, 0); } @@ -7963,13 +7972,15 @@ int peer_ttl_security_hops_unset(struct peer *peer) ret = peer_ebgp_multihop_unset(peer); else { if (peer->connection->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa + .sa_family, peer->connection->fd, 0); if ((peer->connection->status < Established) && peer->doppelganger && (peer->doppelganger->connection->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, + sockopt_minttl(peer->connection->su.sa + .sa_family, peer->doppelganger ->connection->fd, 0); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 1fc7e02a6..012a11ec0 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1156,6 +1156,10 @@ struct peer_connection { struct event *t_process_packet; struct event *t_process_packet_error; + union sockunion su; +#define BGP_CONNECTION_SU_UNSPEC(connection) \ + (connection->su.sa.sa_family == AF_UNSPEC) + /* Thread flags */ _Atomic uint32_t thread_flags; #define PEER_THREAD_WRITES_ON (1U << 0) @@ -1240,8 +1244,7 @@ struct peer { char *desc; /* Description of the peer. */ unsigned short port; /* Destination port for peer */ char *host; /* Printable address of the peer. */ - union sockunion su; /* Sockunion address of the peer. */ -#define BGP_PEER_SU_UNSPEC(peer) (peer->su.sa.sa_family == AF_UNSPEC) + time_t uptime; /* Last Up/Down time */ time_t readtime; /* Last read time */ time_t resettime; /* Last reset time */ @@ -2168,7 +2171,7 @@ extern void bgp_set_evpn(struct bgp *bgp); extern struct peer *peer_lookup(struct bgp *, union sockunion *); extern struct peer *peer_lookup_by_conf_if(struct bgp *, const char *); extern struct peer *peer_lookup_by_hostname(struct bgp *, const char *); -extern void bgp_peer_conf_if_to_su_update(struct peer *); +extern void bgp_peer_conf_if_to_su_update(struct peer_connection *connection); extern int peer_group_listen_range_del(struct peer_group *, struct prefix *); extern struct peer_group *peer_group_lookup(struct bgp *, const char *); extern struct peer_group *peer_group_get(struct bgp *, const char *); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 27f7c88d7..a93e186f8 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -3729,8 +3729,9 @@ void rfapiBgpInfoFilteredImportVPN( prefix_same(&pfx_un, &un_prefix)) { /* compare */ un_match = 1; } - if (!RFAPI_LOCAL_BI(bpi) && !RFAPI_LOCAL_BI(info_new) - && sockunion_same(&bpi->peer->su, &info_new->peer->su)) { + if (!RFAPI_LOCAL_BI(bpi) && !RFAPI_LOCAL_BI(info_new) && + sockunion_same(&bpi->peer->connection->su, + &info_new->peer->connection->su)) { /* old & new are both remote, same peer */ remote_peer_match = 1; } |