diff options
-rw-r--r-- | pimd/pim_cmd.c | 18 | ||||
-rw-r--r-- | pimd/pim_nht.c | 173 | ||||
-rw-r--r-- | pimd/pim_nht.h | 8 | ||||
-rw-r--r-- | pimd/pim_rp.c | 21 | ||||
-rw-r--r-- | pimd/pim_rpf.c | 22 | ||||
-rw-r--r-- | pimd/pim_zebra.c | 12 |
6 files changed, 134 insertions, 120 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index ae2daf40a..460bbfeae 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -4252,7 +4252,7 @@ DEFUN (show_ip_pim_nexthop_lookup, "Source/RP address\n" "Multicast Group address\n") { - struct pim_nexthop_cache pnc; + struct pim_nexthop_cache *pnc = NULL; struct prefix nht_p; int result = 0; struct in_addr src_addr, grp_addr; @@ -4264,6 +4264,7 @@ DEFUN (show_ip_pim_nexthop_lookup, char grp_str[PREFIX_STRLEN]; int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); + struct pim_rpf rpf; if (!vrf) return CMD_WARNING; @@ -4301,7 +4302,6 @@ DEFUN (show_ip_pim_nexthop_lookup, grp_addr)) return CMD_SUCCESS; - memset(&pnc, 0, sizeof(struct pim_nexthop_cache)); nht_p.family = AF_INET; nht_p.prefixlen = IPV4_MAX_BITLEN; nht_p.u.prefix4 = vif_source; @@ -4310,12 +4310,18 @@ DEFUN (show_ip_pim_nexthop_lookup, grp.u.prefix4 = grp_addr; memset(&nexthop, 0, sizeof(nexthop)); - if (pim_find_or_track_nexthop(vrf->info, &nht_p, NULL, NULL, &pnc)) - result = pim_ecmp_nexthop_search(vrf->info, &pnc, &nexthop, + memset(&rpf, 0, sizeof(struct pim_rpf)); + rpf.rpf_addr.family = AF_INET; + rpf.rpf_addr.prefixlen = IPV4_MAX_BITLEN; + rpf.rpf_addr.u.prefix4 = vif_source; + + pnc = pim_nexthop_cache_find(vrf->info, &rpf); + if (pnc) + result = pim_ecmp_nexthop_search(vrf->info, pnc, &nexthop, &nht_p, &grp, 0); else - result = pim_ecmp_nexthop_lookup(vrf->info, &nexthop, - vif_source, &nht_p, &grp, 0); + result = pim_ecmp_nexthop_lookup(vrf->info, &nexthop, &nht_p, + &grp, 0); if (!result) { vty_out(vty, diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index ac49373da..78152b266 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -418,12 +418,14 @@ int pim_ecmp_nexthop_search(struct pim_instance *pim, struct pim_nexthop *nexthop, struct prefix *src, struct prefix *grp, int neighbor_needed) { - struct pim_neighbor *nbr = NULL; + struct pim_neighbor *nbrs[MULTIPATH_NUM], *nbr; + struct interface *ifps[MULTIPATH_NUM]; struct nexthop *nh_node = NULL; ifindex_t first_ifindex; struct interface *ifp = NULL; uint32_t hash_val = 0, mod_val = 0; uint8_t nh_iter = 0, found = 0; + uint32_t i, num_nbrs = 0; if (!pnc || !pnc->nexthop_num || !nexthop) return 0; @@ -487,16 +489,41 @@ int pim_ecmp_nexthop_search(struct pim_instance *pim, } } } + + /* + * Look up all interfaces and neighbors, + * store for later usage + */ + for (nh_node = pnc->nexthop, i = 0; nh_node; + nh_node = nh_node->next, i++) { + ifps[i] = if_lookup_by_index(nh_node->ifindex, pim->vrf_id); + if (ifps[i]) { + nbrs[i] = pim_neighbor_find(ifps[i], + nh_node->gate.ipv4); + if (nbrs[i] || pim_if_connected_to_source(ifps[i], + + src->u.prefix4)) + num_nbrs++; + } + } if (pim->ecmp_enable) { + uint32_t consider = pnc->nexthop_num; + + if (neighbor_needed && num_nbrs < consider) + consider = num_nbrs; + + if (consider == 0) + return 0; + // PIM ECMP flag is enable then choose ECMP path. hash_val = pim_compute_ecmp_hash(src, grp); - mod_val = hash_val % pnc->nexthop_num; + mod_val = hash_val % consider; } for (nh_node = pnc->nexthop; nh_node && (found == 0); nh_node = nh_node->next) { first_ifindex = nh_node->ifindex; - ifp = if_lookup_by_index(first_ifindex, pim->vrf_id); + ifp = ifps[nh_iter]; if (!ifp) { if (PIM_DEBUG_PIM_NHT) { char addr_str[INET_ADDRSTRLEN]; @@ -532,7 +559,7 @@ int pim_ecmp_nexthop_search(struct pim_instance *pim, if (neighbor_needed && !pim_if_connected_to_source(ifp, src->u.prefix4)) { - nbr = pim_neighbor_find(ifp, nh_node->gate.ipv4); + nbr = nbrs[nh_iter]; if (!nbr && !if_is_loopback(ifp)) { if (PIM_DEBUG_PIM_NHT) zlog_debug( @@ -767,22 +794,23 @@ int pim_parse_nexthop_update(int command, struct zclient *zclient, } int pim_ecmp_nexthop_lookup(struct pim_instance *pim, - struct pim_nexthop *nexthop, struct in_addr addr, - struct prefix *src, struct prefix *grp, - int neighbor_needed) + struct pim_nexthop *nexthop, struct prefix *src, + struct prefix *grp, int neighbor_needed) { struct pim_zlookup_nexthop nexthop_tab[MULTIPATH_NUM]; - struct pim_neighbor *nbr = NULL; + struct pim_neighbor *nbrs[MULTIPATH_NUM], *nbr = NULL; int num_ifindex; - struct interface *ifp; + struct interface *ifps[MULTIPATH_NUM], *ifp; int first_ifindex; int found = 0; uint8_t i = 0; uint32_t hash_val = 0, mod_val = 0; + uint32_t num_nbrs = 0; + char addr_str[PREFIX_STRLEN]; if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); + pim_inet4_dump("<addr?>", src->u.prefix4, addr_str, + sizeof(addr_str)); zlog_debug("%s: Looking up: %s(%s), last lookup time: %lld", __PRETTY_FUNCTION__, addr_str, pim->vrf->name, nexthop->last_lookup_time); @@ -790,44 +818,63 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, memset(nexthop_tab, 0, sizeof(struct pim_zlookup_nexthop) * MULTIPATH_NUM); - num_ifindex = zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, - addr, PIM_NEXTHOP_LOOKUP_MAX); + num_ifindex = + zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, + src->u.prefix4, PIM_NEXTHOP_LOOKUP_MAX); if (num_ifindex < 1) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_warn( "%s: could not find nexthop ifindex for address %s(%s)", __PRETTY_FUNCTION__, addr_str, pim->vrf->name); - } return 0; } + /* + * Look up all interfaces and neighbors, + * store for later usage + */ + for (i = 0; i < num_ifindex; i++) { + ifps[i] = if_lookup_by_index(nexthop_tab[i].ifindex, + pim->vrf_id); + if (ifps[i]) { + nbrs[i] = pim_neighbor_find( + ifps[i], nexthop_tab[i].nexthop_addr.u.prefix4); + if (nbrs[i] + || pim_if_connected_to_source(ifps[i], + src->u.prefix4)) + num_nbrs++; + } + } + // If PIM ECMP enable then choose ECMP path. if (pim->ecmp_enable) { + uint32_t consider = num_ifindex; + + if (neighbor_needed && num_nbrs < consider) + consider = num_nbrs; + + if (consider == 0) + return 0; + hash_val = pim_compute_ecmp_hash(src, grp); - mod_val = hash_val % num_ifindex; + mod_val = hash_val % consider; if (PIM_DEBUG_PIM_NHT_DETAIL) zlog_debug("%s: hash_val %u mod_val %u", __PRETTY_FUNCTION__, hash_val, mod_val); } + i = 0; while (!found && (i < num_ifindex)) { first_ifindex = nexthop_tab[i].ifindex; - ifp = if_lookup_by_index(first_ifindex, pim->vrf_id); + ifp = ifps[i]; if (!ifp) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s %s: could not find interface for ifindex %d (address %s(%s))", __FILE__, __PRETTY_FUNCTION__, first_ifindex, addr_str, pim->vrf->name); - } if (i == mod_val) mod_val++; i++; @@ -835,24 +882,20 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, } if (!ifp->info) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", __PRETTY_FUNCTION__, ifp->name, pim->vrf->name, first_ifindex, addr_str); - } if (i == mod_val) mod_val++; i++; continue; } - if (neighbor_needed && !pim_if_connected_to_source(ifp, addr)) { - nbr = pim_neighbor_find( - ifp, nexthop_tab[i].nexthop_addr.u.prefix4); + if (neighbor_needed + && !pim_if_connected_to_source(ifp, src->u.prefix4)) { + nbr = nbrs[i]; if (PIM_DEBUG_PIM_NHT_DETAIL) zlog_debug("ifp name: %s(%s), pim nbr: %p", ifp->name, pim->vrf->name, nbr); @@ -860,16 +903,11 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (i == mod_val) mod_val++; i++; - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, - addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: NBR not found on input interface %s(%s) (RPF for source %s)", __PRETTY_FUNCTION__, ifp->name, pim->vrf->name, addr_str); - } continue; } } @@ -877,12 +915,10 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (i == mod_val) { if (PIM_DEBUG_PIM_NHT) { char nexthop_str[PREFIX_STRLEN]; - char addr_str[INET_ADDRSTRLEN]; + pim_addr_dump("<nexthop?>", &nexthop_tab[i].nexthop_addr, nexthop_str, sizeof(nexthop_str)); - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); zlog_debug( "%s: found nhop %s for addr %s interface %s(%s) metric %d dist %d", __PRETTY_FUNCTION__, nexthop_str, @@ -898,7 +934,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, nexthop_tab[i].protocol_distance; nexthop->mrib_route_metric = nexthop_tab[i].route_metric; - nexthop->last_lookup = addr; + nexthop->last_lookup = src->u.prefix4; nexthop->last_lookup_time = pim_time_monotonic_usec(); nexthop->nbr = nbr; found = 1; @@ -913,59 +949,36 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, } int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, - struct in_addr addr, struct prefix *src, - struct prefix *grp) + struct prefix *src, struct prefix *grp) { - struct pim_zlookup_nexthop nexthop_tab[MULTIPATH_NUM]; - int num_ifindex; + struct pim_nexthop nhop; int vif_index; - ifindex_t first_ifindex; - uint32_t hash_val = 0, mod_val = 0; + ifindex_t ifindex; + char addr_str[PREFIX_STRLEN]; - memset(nexthop_tab, 0, - sizeof(struct pim_zlookup_nexthop) * MULTIPATH_NUM); - num_ifindex = zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, - addr, PIM_NEXTHOP_LOOKUP_MAX); - if (num_ifindex < 1) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) + pim_inet4_dump("<addr?>", src->u.prefix4, addr_str, + sizeof(addr_str)); + if (!pim_ecmp_nexthop_lookup(pim, &nhop, src, grp, 0)) { + if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: could not find nexthop ifindex for address %s(%s)", __PRETTY_FUNCTION__, addr_str, pim->vrf->name); - } return -1; } - // If PIM ECMP enable then choose ECMP path. - if (pim->ecmp_enable) { - hash_val = pim_compute_ecmp_hash(src, grp); - mod_val = hash_val % num_ifindex; - if (PIM_DEBUG_PIM_NHT_DETAIL) - zlog_debug("%s: hash_val %u mod_val %u", - __PRETTY_FUNCTION__, hash_val, mod_val); - } - - first_ifindex = nexthop_tab[mod_val].ifindex; - - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", addr, addr_str, sizeof(addr_str)); + ifindex = nhop.interface->ifindex; + if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: found nexthop ifindex=%d (interface %s(%s)) for address %s", - __PRETTY_FUNCTION__, first_ifindex, - ifindex2ifname(first_ifindex, pim->vrf_id), + __PRETTY_FUNCTION__, ifindex, + ifindex2ifname(ifindex, pim->vrf_id), pim->vrf->name, addr_str); - } - vif_index = pim_if_find_vifindex_by_ifindex(pim, first_ifindex); + vif_index = pim_if_find_vifindex_by_ifindex(pim, ifindex); if (vif_index < 0) { if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); zlog_debug( "%s: low vif_index=%d(%s) < 1 nexthop for address %s", __PRETTY_FUNCTION__, vif_index, pim->vrf->name, diff --git a/pimd/pim_nht.h b/pimd/pim_nht.h index 77e25dcd7..796fbf973 100644 --- a/pimd/pim_nht.h +++ b/pimd/pim_nht.h @@ -61,13 +61,11 @@ int pim_ecmp_nexthop_search(struct pim_instance *pim, struct pim_nexthop *nexthop, struct prefix *src, struct prefix *grp, int neighbor_needed); int pim_ecmp_nexthop_lookup(struct pim_instance *pim, - struct pim_nexthop *nexthop, struct in_addr addr, - struct prefix *src, struct prefix *grp, - int neighbor_needed); + struct pim_nexthop *nexthop, struct prefix *src, + struct prefix *grp, int neighbor_needed); void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, struct pim_nexthop_cache *pnc, int command); void pim_resolve_upstream_nh(struct pim_instance *pim, struct prefix *nht_p); int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, - struct in_addr addr, struct prefix *src, - struct prefix *grp); + struct prefix *src, struct prefix *grp); #endif diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 7e053d2aa..cc39b0904 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -477,10 +477,9 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, &rp_all->group, 1)) return PIM_RP_NO_PATH; } else { - if (pim_nexthop_lookup( + if (!pim_ecmp_nexthop_lookup( pim, &rp_all->rp.source_nexthop, - rp_all->rp.rpf_addr.u.prefix4, 1) - != 0) + &nht_p, &rp_all->group, 1)) return PIM_RP_NO_PATH; } pim_rp_check_interfaces(pim, rp_all); @@ -556,9 +555,8 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, &nht_p, &rp_info->group, 1)) return PIM_RP_NO_PATH; } else { - if (pim_nexthop_lookup(pim, &rp_info->rp.source_nexthop, - rp_info->rp.rpf_addr.u.prefix4, 1) - != 0) + if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop, + &nht_p, &rp_info->group, 1)) return PIM_RP_NO_PATH; } @@ -687,9 +685,9 @@ void pim_rp_setup(struct pim_instance *pim) "%s: NHT Local Nexthop not found for RP %s ", __PRETTY_FUNCTION__, buf); } - if (pim_nexthop_lookup( - pim, &rp_info->rp.source_nexthop, - rp_info->rp.rpf_addr.u.prefix4, 1) < 0) + if (!pim_ecmp_nexthop_lookup(pim, + &rp_info->rp.source_nexthop, + &nht_p, &rp_info->group, 1)) if (PIM_DEBUG_PIM_NHT_RP) zlog_debug( "Unable to lookup nexthop for rp specified"); @@ -854,8 +852,9 @@ struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group) __PRETTY_FUNCTION__, buf, buf1); } pim_rpf_set_refresh_time(pim); - pim_nexthop_lookup(pim, &rp_info->rp.source_nexthop, - rp_info->rp.rpf_addr.u.prefix4, 1); + pim_ecmp_nexthop_lookup(pim, + &rp_info->rp.source_nexthop, + &nht_p, &rp_info->group, 1); } return (&rp_info->rp); } diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index da14e8b3e..b02102c8f 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -203,6 +203,7 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, struct prefix nht_p; struct pim_nexthop_cache pnc; struct prefix src, grp; + bool neigh_needed = true; saved.source_nexthop = rpf->source_nexthop; saved.rpf_addr = rpf->rpf_addr; @@ -226,23 +227,20 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, grp.prefixlen = IPV4_MAX_BITLEN; grp.u.prefix4 = up->sg.grp; memset(&pnc, 0, sizeof(struct pim_nexthop_cache)); + + if ((up->sg.src.s_addr == INADDR_ANY && I_am_RP(pim, up->sg.grp)) || + PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) + neigh_needed = FALSE; if (pim_find_or_track_nexthop(pim, &nht_p, up, NULL, &pnc)) { if (pnc.nexthop_num) { - if (!pim_ecmp_nexthop_search( - pim, &pnc, &up->rpf.source_nexthop, &src, - &grp, - !PIM_UPSTREAM_FLAG_TEST_FHR(up->flags) - && !PIM_UPSTREAM_FLAG_TEST_SRC_IGMP( - up->flags))) + if (!pim_ecmp_nexthop_search(pim, &pnc, + &up->rpf.source_nexthop, + &src, &grp, neigh_needed)) return PIM_RPF_FAILURE; } } else { - if (!pim_ecmp_nexthop_lookup( - pim, &rpf->source_nexthop, up->upstream_addr, &src, - &grp, - !PIM_UPSTREAM_FLAG_TEST_FHR(up->flags) - && !PIM_UPSTREAM_FLAG_TEST_SRC_IGMP( - up->flags))) + if (!pim_ecmp_nexthop_lookup(pim, &rpf->source_nexthop, &src, + &grp, neigh_needed)) return PIM_RPF_FAILURE; } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index a58dfcdd5..38a29b72a 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -561,7 +561,7 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index) __PRETTY_FUNCTION__, source_str, group_str); } input_iface_vif_index = pim_ecmp_fib_lookup_if_vif_index( - c_oil->pim, vif_source, &src, &grp); + c_oil->pim, &src, &grp); } if (input_iface_vif_index < 1) { @@ -953,8 +953,8 @@ void igmp_source_forward_start(struct pim_instance *pim, } } else input_iface_vif_index = - pim_ecmp_fib_lookup_if_vif_index( - pim, vif_source, &src, &grp); + pim_ecmp_fib_lookup_if_vif_index(pim, &src, + &grp); if (PIM_DEBUG_ZEBRA) { char buf2[INET_ADDRSTRLEN]; @@ -1153,7 +1153,7 @@ void pim_forward_start(struct pim_ifchannel *ch) /* Register addr with Zebra NHT */ nht_p.family = AF_INET; nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4.s_addr = up->upstream_addr.s_addr; + nht_p.u.prefix4 = up->upstream_addr; grp.family = AF_INET; grp.prefixlen = IPV4_MAX_BITLEN; grp.u.prefix4 = up->sg.grp; @@ -1204,8 +1204,8 @@ void pim_forward_start(struct pim_ifchannel *ch) } } else input_iface_vif_index = - pim_ecmp_fib_lookup_if_vif_index( - pim, up->upstream_addr, &src, &grp); + pim_ecmp_fib_lookup_if_vif_index(pim, &src, + &grp); if (input_iface_vif_index < 1) { if (PIM_DEBUG_PIM_TRACE) { |