X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=bgpd%2Frfapi%2Frfapi_import.c;h=c7d64bf1edecb24efb780e66cf30785675ecf856;hb=996c93142d3abfab0f6d6c800474e22a8cfbdbc5;hp=3f427c39031ee336ec05c1b44fda998dadc3c392;hpb=848e7ccac4bd267f94fe96dd3cd84a66b3749803;p=mirror_frr.git diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 3f427c390..c7d64bf1e 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -33,6 +33,7 @@ #include "lib/log.h" #include "lib/skiplist.h" #include "lib/thread.h" +#include "lib/stream.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_ecommunity.h" @@ -40,6 +41,7 @@ #include "bgpd/bgp_route.h" #include "bgpd/bgp_mplsvpn.h" /* prefix_rd2str() */ #include "bgpd/bgp_vnc_types.h" +#include "bgpd/bgp_rd.h" #include "bgpd/rfapi/rfapi.h" #include "bgpd/rfapi/bgp_rfapi_cfg.h" @@ -519,7 +521,7 @@ static struct bgp_info *rfapiBgpInfoCreate(struct attr *attr, struct peer *peer, rfapi_time(&new->extra->vnc.import.create_time); } if (label) - encode_label(*label, &new->extra->label); + encode_label(*label, &new->extra->label[0]); new->type = type; new->sub_type = sub_type; new->peer = peer; @@ -644,10 +646,9 @@ rfapiMonitorMoveShorter(struct route_node *original_vpn_node, int lockoffset) #if DEBUG_MONITOR_MOVE_SHORTER { - char buf[BUFSIZ]; + char buf[PREFIX_STRLEN]; - prefix2str(&original_vpn_node->p, buf, BUFSIZ); - buf[BUFSIZ - 1] = 0; + prefix2str(&original_vpn_node->p, buf, sizeof(buf)); vnc_zlog_debug_verbose("%s: called with node pfx=%s", __func__, buf); } @@ -778,10 +779,9 @@ rfapiMonitorMoveShorter(struct route_node *original_vpn_node, int lockoffset) #if DEBUG_MONITOR_MOVE_SHORTER { - char buf[BUFSIZ]; + char buf[PREFIX_STRLEN]; - prefix2str(&par->p, buf, BUFSIZ); - buf[BUFSIZ - 1] = 0; + prefix2str(&par->p, buf, sizeof(buf)); vnc_zlog_debug_verbose("%s: moved to node pfx=%s", __func__, buf); } @@ -1079,16 +1079,12 @@ int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, uint16_t *tag_id) if (*p++ == ECOMMUNITY_ROUTE_TARGET) { if (encode == ECOMMUNITY_ENCODE_AS4) { - as = (*p++ << 24); - as |= (*p++ << 16); - as |= (*p++ << 8); - as |= (*p++); + p = ptr_get_be32(p, &as); } else if (encode == ECOMMUNITY_ENCODE_AS) { as = (*p++ << 8); as |= (*p++); - p += - 2; /* skip next two, tag/vid - always in lowest bytes */ + p += 2; /* skip next two, tag/vid + always in lowest bytes */ } if (as == bgp->as) { *tag_id = *p++ << 8; @@ -1224,8 +1220,7 @@ static int rfapiVpnBiSamePtUn(struct bgp_info *bi1, struct bgp_info *bi2) switch (pfx_un1.family) { case AF_INET: - if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4, - &pfx_un2.u.prefix4)) + if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4, &pfx_un2.u.prefix4)) return 0; break; case AF_INET6: @@ -1341,7 +1336,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, vo->v.l2addr.local_nve_id = bi->extra->vnc.import.rd.val[1]; /* label comes from MP_REACH_NLRI label */ - vo->v.l2addr.label = decode_label(&bi->extra->label); + vo->v.l2addr.label = decode_label(&bi->extra->label[0]); new->vn_options = vo; @@ -1454,7 +1449,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, __func__, __LINE__, have_vnc_tunnel_un); #endif - if (!have_vnc_tunnel_un && bi && bi->extra) { + if (!have_vnc_tunnel_un && bi->extra) { /* * use cached UN address from ENCAP route */ @@ -1596,10 +1591,9 @@ static int rfapiNhlAddNodeRoutes( } if (!skiplist_search(seen_nexthops, &pfx_vn, NULL)) { #if DEBUG_RETURNED_NHL - char buf[BUFSIZ]; + char buf[PREFIX_STRLEN]; - prefix2str(&pfx_vn, buf, BUFSIZ); - buf[BUFSIZ - 1] = 0; /* guarantee NUL-terminated */ + prefix2str(&pfx_vn, buf, sizeof(buf)); vnc_zlog_debug_verbose( "%s: already put VN/nexthop %s, skip", __func__, buf); @@ -1762,10 +1756,9 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( #if DEBUG_RETURNED_NHL { - char buf[BUFSIZ]; + char buf[PREFIX_STRLEN]; - prefix2str(&rn->p, buf, BUFSIZ); - buf[BUFSIZ - 1] = 0; + prefix2str(&rn->p, buf, sizeof(buf)); vnc_zlog_debug_verbose("%s: called with node pfx=%s", __func__, buf); } @@ -2138,10 +2131,12 @@ static void rfapiItBiIndexAdd(struct route_node *rn, /* Import table VPN node */ assert(bi->extra); { - char buf[BUFSIZ]; - prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ); + char buf[RD_ADDRSTRLEN]; + vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__, - bi, bi->peer, buf); + bi, bi->peer, + prefix_rd2str(&bi->extra->vnc.import.rd, + buf, sizeof(buf))); } sl = RFAPI_RDINDEX_W_ALLOC(rn); @@ -2175,18 +2170,15 @@ static void rfapiItBiIndexDump(struct route_node *rn) for (rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor); !rc; rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor)) { - char buf[BUFSIZ]; - char buf_aux_pfx[BUFSIZ]; + char buf[RD_ADDRSTRLEN]; + char buf_aux_pfx[PREFIX_STRLEN]; - prefix_rd2str(&k->extra->vnc.import.rd, buf, BUFSIZ); - buf_aux_pfx[0] = 0; + prefix_rd2str(&k->extra->vnc.import.rd, buf, sizeof(buf)); if (k->extra->vnc.import.aux_prefix.family) { prefix2str(&k->extra->vnc.import.aux_prefix, - buf_aux_pfx, BUFSIZ); - } else { - strncpy(buf_aux_pfx, "(none)", BUFSIZ); - buf_aux_pfx[BUFSIZ - 1] = 0; - } + buf_aux_pfx, sizeof(buf_aux_pfx)); + } else + strncpy(buf_aux_pfx, "(none)", PREFIX_STRLEN); vnc_zlog_debug_verbose("bi %p, peer %p, rd %s, aux_prefix %s", k, k->peer, buf, buf_aux_pfx); @@ -2210,19 +2202,19 @@ static struct bgp_info *rfapiItBiIndexSearch( #if DEBUG_BI_SEARCH { - char buf[BUFSIZ]; - char buf_aux_pfx[BUFSIZ]; + char buf[RD_ADDRSTRLEN]; + char buf_aux_pfx[PREFIX_STRLEN]; - prefix_rd2str(prd, buf, BUFSIZ); if (aux_prefix) { - prefix2str(aux_prefix, buf_aux_pfx, BUFSIZ); - } else { - strncpy(buf_aux_pfx, "(nil)", BUFSIZ - 1); - buf_aux_pfx[BUFSIZ - 1] = 0; - } + prefix2str(aux_prefix, buf_aux_pfx, + sizeof(buf_aux_pfx)); + } else + strncpy(buf_aux_pfx, "(nil)", sizeof(buf_aux_pfx)); vnc_zlog_debug_verbose("%s want prd=%s, peer=%p, aux_prefix=%s", - __func__, buf, peer, buf_aux_pfx); + __func__, + prefix_rd2str(prd, buf, sizeof(buf)), + peer, buf_aux_pfx); rfapiItBiIndexDump(rn); } #endif @@ -2237,12 +2229,14 @@ static struct bgp_info *rfapiItBiIndexSearch( bi_result = bi_result->next) { #if DEBUG_BI_SEARCH { - char buf[BUFSIZ]; - prefix_rd2str(&bi_result->extra->vnc.import.rd, - buf, BUFSIZ); + char buf[RD_ADDRSTRLEN]; + vnc_zlog_debug_verbose( "%s: bi has prd=%s, peer=%p", __func__, - buf, bi_result->peer); + prefix_rd2str(&bi_result->extra->vnc + .import.rd, + buf, sizeof(buf)), + bi_result->peer); } #endif if (peer == bi_result->peer @@ -2305,10 +2299,12 @@ static void rfapiItBiIndexDel(struct route_node *rn, /* Import table VPN node */ int rc; { - char buf[BUFSIZ]; - prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ); + char buf[RD_ADDRSTRLEN]; + vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__, - bi, bi->peer, buf); + bi, bi->peer, + prefix_rd2str(&bi->extra->vnc.import.rd, + buf, sizeof(buf))); } sl = RFAPI_RDINDEX(rn); @@ -3532,7 +3528,10 @@ void rfapiBgpInfoFilteredImportVPN( * Compare types. Doing so prevents a RFP-originated * route from matching an imported route, for example. */ - assert(bi->type == type); + if (VNC_DEBUG(VERBOSE) && bi->type != type) + /* should be handled by RDs, but warn for now */ + zlog_warn("%s: type mismatch! (bi=%d, arg=%d)", + __func__, bi->type, type); vnc_zlog_debug_verbose("%s: found matching bi", __func__); @@ -3670,9 +3669,9 @@ void rfapiBgpInfoFilteredImportVPN( rfapiCopyUnEncap2VPN(ern->info, info_new); route_unlock_node(ern); /* undo lock in route_note_match */ } else { - char buf[BUFSIZ]; + char buf[PREFIX_STRLEN]; + prefix2str(&vn_prefix, buf, sizeof(buf)); - buf[BUFSIZ - 1] = 0; /* Not a big deal, just means VPN route got here first */ vnc_zlog_debug_verbose("%s: no encap route for vn addr %s", __func__, buf); @@ -3863,6 +3862,20 @@ void rfapiBgpInfoFilteredImportVPN( VNC_ITRCCK; } +static void rfapiBgpInfoFilteredImportBadSafi( + struct rfapi_import_table *import_table, int action, struct peer *peer, + void *rfd, /* set for looped back routes */ + struct prefix *p, + struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ + afi_t afi, struct prefix_rd *prd, + struct attr *attr, /* part of bgp_info */ + u_char type, /* part of bgp_info */ + u_char sub_type, /* part of bgp_info */ + uint32_t *label) /* part of bgp_info */ +{ + vnc_zlog_debug_verbose("%s: Error, bad safi", __func__); +} + static rfapi_bi_filtered_import_f * rfapiBgpInfoFilteredImportFunction(safi_t safi) { @@ -3876,7 +3889,7 @@ rfapiBgpInfoFilteredImportFunction(safi_t safi) default: /* not expected */ zlog_err("%s: bad safi %d", __func__, safi); - return NULL; + return rfapiBgpInfoFilteredImportBadSafi; } } @@ -3932,7 +3945,7 @@ void rfapiProcessUpdate(struct peer *peer, vnc_zlog_debug_verbose( "%s: rfapiEcommunityGetLNI returned %d, lni=%d, attr=%p", __func__, rc, lni, attr); - if (attr && !rc) { + if (!rc) { it = rfapiMacImportTableGet(bgp, lni); rfapiBgpInfoFilteredImportVPN( @@ -3958,9 +3971,6 @@ void rfapiProcessUpdate(struct peer *peer, if (safi == SAFI_MPLS_VPN) { vnc_direct_bgp_rh_add_route(bgp, afi, p, peer, attr); - } - - if (safi == SAFI_MPLS_VPN) { rfapiBgpInfoFilteredImportVPN( bgp->rfapi->it_ce, FIF_ACTION_UPDATE, peer, rfd, p, /* prefix */ @@ -4230,7 +4240,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp, if (bi->extra) label = decode_label( - &bi->extra->label); + &bi->extra->label[0]); (*rfapiBgpInfoFilteredImportFunction( safi))( it, /* which import table */ @@ -4421,10 +4431,10 @@ static void rfapiDeleteRemotePrefixesIt( #if DEBUG_L2_EXTRA { - char buf_pfx[BUFSIZ]; + char buf_pfx[PREFIX_STRLEN]; if (p) { - prefix2str(p, buf_pfx, BUFSIZ); + prefix2str(p, buf_pfx, sizeof(buf_pfx)); } else { buf_pfx[0] = '*'; buf_pfx[1] = 0; @@ -4457,11 +4467,11 @@ static void rfapiDeleteRemotePrefixesIt( struct bgp_info *next; if (VNC_DEBUG(IMPORT_DEL_REMOTE)) { - char p1line[BUFSIZ]; - char p2line[BUFSIZ]; + char p1line[PREFIX_STRLEN]; + char p2line[PREFIX_STRLEN]; - prefix2str(p, p1line, BUFSIZ); - prefix2str(&rn->p, p2line, BUFSIZ); + prefix2str(p, p1line, sizeof(p1line)); + prefix2str(&rn->p, p2line, sizeof(p2line)); vnc_zlog_debug_any("%s: want %s, have %s", __func__, p1line, p2line); } @@ -4470,8 +4480,9 @@ static void rfapiDeleteRemotePrefixesIt( continue; { - char buf_pfx[BUFSIZ]; - prefix2str(&rn->p, buf_pfx, BUFSIZ); + char buf_pfx[PREFIX_STRLEN]; + + prefix2str(&rn->p, buf_pfx, sizeof(buf_pfx)); vnc_zlog_debug_verbose("%s: rn pfx=%s", __func__, buf_pfx); }