diff options
59 files changed, 1847 insertions, 918 deletions
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 5a053a7f34..08caa24a1b 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -63,7 +63,7 @@ void ecommunity_strfree(char **s) XFREE(MTYPE_ECOMMUNITY_STR, *s); } -/* Allocate ecommunities. */ +/* Free ecommunities. */ void ecommunity_free(struct ecommunity **ecom) { if (!(*ecom)) diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 4da3fa8f3b..5f519e84ed 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -5858,16 +5858,15 @@ DEFUN (bgp_evpn_vrf_rt, return CMD_WARNING; } + ecomadd = ecommunity_str2com(argv[2]->arg, ECOMMUNITY_ROUTE_TARGET, 0); + if (!ecomadd) { + vty_out(vty, "%% Malformed Route Target list\n"); + return CMD_WARNING; + } + ecommunity_str(ecomadd); + /* Add/update the import route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this import route-target */ if (!bgp_evpn_rt_matches_existing(bgp->vrf_import_rtl, ecomadd)) bgp_evpn_configure_import_rt_for_vrf(bgp, ecomadd); @@ -5875,14 +5874,6 @@ DEFUN (bgp_evpn_vrf_rt, /* Add/update the export route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_EXPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this export route-target */ if (!bgp_evpn_rt_matches_existing(bgp->vrf_export_rtl, ecomadd)) bgp_evpn_configure_export_rt_for_vrf(bgp, ecomadd); @@ -6107,16 +6098,15 @@ DEFUN (bgp_evpn_vni_rt, return CMD_WARNING; } + ecomadd = ecommunity_str2com(argv[2]->arg, ECOMMUNITY_ROUTE_TARGET, 0); + if (!ecomadd) { + vty_out(vty, "%% Malformed Route Target list\n"); + return CMD_WARNING; + } + ecommunity_str(ecomadd); + /* Add/update the import route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this import route-target */ if (!bgp_evpn_rt_matches_existing(vpn->import_rtl, ecomadd)) evpn_configure_import_rt(bgp, vpn, ecomadd); @@ -6124,14 +6114,6 @@ DEFUN (bgp_evpn_vni_rt, /* Add/update the export route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_EXPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this export route-target */ if (!bgp_evpn_rt_matches_existing(vpn->export_rtl, ecomadd)) evpn_configure_export_rt(bgp, vpn, ecomadd); diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index f8de3b8dc4..43908fcb78 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -677,7 +677,8 @@ static void bgp_llgr_stale_timer_expire(struct thread *thread) * stale routes from the neighbor that it is retaining. */ if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s Long-lived stale timer (%s) expired", peer->host, + zlog_debug("%s(%s) Long-lived stale timer (%s) expired", + peer->host, bgp_peer_hostname(peer), get_afi_safi_str(afi, safi, false)); UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT); @@ -719,8 +720,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s Long-lived set stale community (LLGR_STALE) for: %pFX", - peer->host, &dest->p); + "%s(%s) Long-lived set stale community (LLGR_STALE) for: %pFX", + peer->host, + bgp_peer_hostname(peer), + &dest->p); attr = *pi->attr; bgp_attr_add_llgr_community(&attr); @@ -747,8 +750,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s Long-lived set stale community (LLGR_STALE) for: %pFX", - peer->host, &dest->p); + "%s(%s) Long-lived set stale community (LLGR_STALE) for: %pFX", + peer->host, + bgp_peer_hostname(peer), + &dest->p); attr = *pi->attr; bgp_attr_add_llgr_community(&attr); @@ -772,9 +777,10 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread) peer = THREAD_ARG(thread); if (bgp_debug_neighbor_events(peer)) { - zlog_debug("%s graceful restart timer expired", peer->host); - zlog_debug("%s graceful restart stalepath timer stopped", - peer->host); + zlog_debug("%s(%s) graceful restart timer expired", peer->host, + bgp_peer_hostname(peer)); + zlog_debug("%s(%s) graceful restart stalepath timer stopped", + peer->host, bgp_peer_hostname(peer)); } FOREACH_AFI_SAFI (afi, safi) { @@ -800,8 +806,8 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s Long-lived stale timer (%s) started for %d sec", - peer->host, + "%s(%s) Long-lived stale timer (%s) started for %d sec", + peer->host, bgp_peer_hostname(peer), get_afi_safi_str(afi, safi, false), peer->llgr[afi][safi].stale_time); @@ -836,8 +842,8 @@ static void bgp_graceful_stale_timer_expire(struct thread *thread) peer = THREAD_ARG(thread); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s graceful restart stalepath timer expired", - peer->host); + zlog_debug("%s(%s) graceful restart stalepath timer expired", + peer->host, bgp_peer_hostname(peer)); /* NSF delete stale route */ FOREACH_AFI_SAFI_NSF (afi, safi) @@ -1390,11 +1396,10 @@ int bgp_stop(struct peer *peer) zlog_info( "%%ADJCHANGE: neighbor %s(%s) in vrf %s Down %s", - peer->host, - (peer->hostname) ? peer->hostname : "Unknown", + peer->host, bgp_peer_hostname(peer), vrf ? ((vrf->vrf_id != VRF_DEFAULT) - ? vrf->name - : VRF_DEFAULT_NAME) + ? vrf->name + : VRF_DEFAULT_NAME) : "", peer_down_str[(int)peer->last_reset]); } @@ -1404,17 +1409,19 @@ int bgp_stop(struct peer *peer) BGP_TIMER_OFF(peer->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s graceful restart stalepath timer stopped", - peer->host); + "%s(%s) graceful restart stalepath timer stopped", + peer->host, bgp_peer_hostname(peer)); } if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) { if (bgp_debug_neighbor_events(peer)) { zlog_debug( - "%s graceful restart timer started for %d sec", - peer->host, peer->v_gr_restart); + "%s(%s) graceful restart timer started for %d sec", + peer->host, bgp_peer_hostname(peer), + peer->v_gr_restart); zlog_debug( - "%s graceful restart stalepath timer started for %d sec", - peer->host, peer->bgp->stalepath_time); + "%s(%s) graceful restart stalepath timer started for %d sec", + peer->host, bgp_peer_hostname(peer), + peer->bgp->stalepath_time); } BGP_TIMER_ON(peer->t_gr_restart, bgp_graceful_restart_timer_expire, @@ -1435,8 +1442,8 @@ int bgp_stop(struct peer *peer) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s: route-refresh restart stalepath timer stopped", - peer->host); + "%s(%s) route-refresh restart stalepath timer stopped", + peer->host, bgp_peer_hostname(peer)); } /* If peer reset before receiving EOR, decrement EOR count and @@ -2092,12 +2099,12 @@ static int bgp_establish(struct peer *peer) /* bgp log-neighbor-changes of neighbor Up */ if (CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) { struct vrf *vrf = vrf_lookup_by_id(peer->bgp->vrf_id); - zlog_info( - "%%ADJCHANGE: neighbor %s(%s) in vrf %s Up", peer->host, - (peer->hostname) ? peer->hostname : "Unknown", - vrf ? ((vrf->vrf_id != VRF_DEFAULT) ? vrf->name - : VRF_DEFAULT_NAME) - : ""); + zlog_info("%%ADJCHANGE: neighbor %s(%s) in vrf %s Up", + peer->host, bgp_peer_hostname(peer), + vrf ? ((vrf->vrf_id != VRF_DEFAULT) + ? vrf->name + : VRF_DEFAULT_NAME) + : ""); } /* assign update-group/subgroup */ update_group_adjust_peer_afs(peer); @@ -2182,16 +2189,16 @@ static int bgp_establish(struct peer *peer) BGP_TIMER_OFF(peer->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s graceful restart stalepath timer stopped", - peer->host); + "%s(%s) graceful restart stalepath timer stopped", + peer->host, bgp_peer_hostname(peer)); } } if (peer->t_gr_restart) { BGP_TIMER_OFF(peer->t_gr_restart); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s graceful restart timer stopped", - peer->host); + zlog_debug("%s(%s) graceful restart timer stopped", + peer->host, bgp_peer_hostname(peer)); } /* Reset uptime, turn on keepalives, send current table. */ @@ -2200,8 +2207,18 @@ static int bgp_establish(struct peer *peer) peer->uptime = bgp_clock(); - /* Send route-refresh when ORF is enabled */ + /* Send route-refresh when ORF is enabled. + * Stop Long-lived Graceful Restart timers. + */ FOREACH_AFI_SAFI (afi, safi) { + if (peer->t_llgr_stale[afi][safi]) { + BGP_TIMER_OFF(peer->t_llgr_stale[afi][safi]); + if (bgp_debug_neighbor_events(peer)) + zlog_debug( + "%s Long-lived stale timer stopped for afi/safi: %d/%d", + peer->host, afi, safi); + } + if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)) { if (CHECK_FLAG(peer->af_cap[afi][safi], diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index d768733545..d3ebc0e6a2 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -889,8 +889,9 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) zserv_command_string(command), &bnc->prefix, bnc->bgp->name_pretty); - ret = zclient_send_rnh(zclient, command, &bnc->prefix, exact_match, - resolve_via_default, bnc->bgp->vrf_id); + ret = zclient_send_rnh(zclient, command, &bnc->prefix, SAFI_UNICAST, + exact_match, resolve_via_default, + bnc->bgp->vrf_id); if (ret == ZCLIENT_SEND_FAILURE) { flog_warn(EC_BGP_ZEBRA_SEND, "sendmsg_nexthop: zclient_send_message() failed"); diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 09db041780..424659136e 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -483,8 +483,10 @@ void bgp_generate_updgrp_packets(struct thread *thread) if (bgp_debug_neighbor_events( peer)) zlog_debug( - "%s sending route-refresh (EoRR) for %s/%s", + "%s(%s) sending route-refresh (EoRR) for %s/%s", peer->host, + bgp_peer_hostname( + peer), afi2str(afi), safi2str(safi)); } @@ -913,9 +915,12 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, stream_putc(s, ORF_COMMON_PART_REMOVE_ALL); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %s/%s", - peer->host, orf_type, - (when_to_refresh == REFRESH_DEFER + "%s(%s) sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %s/%s", + peer->host, + bgp_peer_hostname(peer), + orf_type, + (when_to_refresh == + REFRESH_DEFER ? "defer" : "immediate"), iana_afi2str(pkt_afi), @@ -930,9 +935,12 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, ORF_COMMON_PART_DENY); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %s/%s", - peer->host, orf_type, - (when_to_refresh == REFRESH_DEFER + "%s(%s) sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %s/%s", + peer->host, + bgp_peer_hostname(peer), + orf_type, + (when_to_refresh == + REFRESH_DEFER ? "defer" : "immediate"), iana_afi2str(pkt_afi), @@ -949,9 +957,10 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, if (bgp_debug_neighbor_events(peer)) { if (!orf_refresh) - zlog_debug("%s sending REFRESH_REQ for afi/safi: %s/%s", - peer->host, iana_afi2str(pkt_afi), - iana_safi2str(pkt_safi)); + zlog_debug( + "%s(%s) sending REFRESH_REQ for afi/safi: %s/%s", + peer->host, bgp_peer_hostname(peer), + iana_afi2str(pkt_afi), iana_safi2str(pkt_safi)); } /* Add packet to the peer. */ @@ -995,8 +1004,8 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s sending CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s", - peer->host, + "%s(%s) sending CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s", + peer->host, bgp_peer_hostname(peer), action == CAPABILITY_ACTION_SET ? "Advertising" : "Removing", iana_afi2str(pkt_afi), iana_safi2str(pkt_safi)); @@ -1551,8 +1560,9 @@ static void bgp_refresh_stalepath_timer_expire(struct thread *thread) bgp_clear_stale_route(peer, afi, safi); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s: route-refresh (BoRR) timer for %s/%s expired", - peer->host, afi2str(afi), safi2str(safi)); + zlog_debug( + "%s(%s) route-refresh (BoRR) timer expired for afi/safi: %d/%d", + peer->host, bgp_peer_hostname(peer), afi, safi); bgp_timer_set(peer); } @@ -1708,7 +1718,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) peer->host); if (ret && bgp_debug_update(peer, NULL, NULL, 1)) { - zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host, + zlog_debug("%s(%s) rcvd UPDATE w/ attr: %s", peer->host, + bgp_peer_hostname(peer), peer->rcvd_attr_str); peer->rcvd_attr_printed = 1; } @@ -1738,8 +1749,9 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) } if (BGP_DEBUG(update, UPDATE_IN)) - zlog_debug("%s rcvd UPDATE wlen %d attrlen %d alen %d", - peer->host, withdraw_len, attribute_len, update_len); + zlog_debug("%s(%s) rcvd UPDATE wlen %d attrlen %d alen %d", + peer->host, bgp_peer_hostname(peer), withdraw_len, + attribute_len, update_len); /* Parse any given NLRIs */ for (int i = NLRI_UPDATE; i < NLRI_TYPE_MAX; i++) { @@ -2273,18 +2285,18 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) PEER_STATUS_EOR_RECEIVED)) { if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s rcvd route-refresh (BoRR) for %s/%s before EoR", - peer->host, afi2str(afi), - safi2str(safi)); + "%s(%s) rcvd route-refresh (BoRR) for %s/%s before EoR", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); return BGP_PACKET_NOOP; } if (peer->t_refresh_stalepath) { if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s rcvd route-refresh (BoRR) for %s/%s, whereas BoRR already received", - peer->host, afi2str(afi), - safi2str(safi)); + "%s(%s) rcvd route-refresh (BoRR) for %s/%s, whereas BoRR already received", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); return BGP_PACKET_NOOP; } @@ -2312,14 +2324,16 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s rcvd route-refresh (BoRR) for %s/%s, triggering timer for %u seconds", - peer->host, afi2str(afi), safi2str(safi), + "%s(%s) rcvd route-refresh (BoRR) for %s/%s, triggering timer for %u seconds", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi), peer->bgp->stalepath_time); } else if (subtype == BGP_ROUTE_REFRESH_EORR) { if (!peer->t_refresh_stalepath) { zlog_err( - "%s rcvd route-refresh (EoRR) for %s/%s, whereas no BoRR received", - peer->host, afi2str(afi), safi2str(safi)); + "%s(%s) rcvd route-refresh (EoRR) for %s/%s, whereas no BoRR received", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); return BGP_PACKET_NOOP; } @@ -2331,15 +2345,18 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s rcvd route-refresh (EoRR) for %s/%s, stopping BoRR timer", - peer->host, afi2str(afi), safi2str(safi)); + "%s(%s) rcvd route-refresh (EoRR) for %s/%s, stopping BoRR timer", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); if (peer->nsf[afi][safi]) bgp_clear_stale_route(peer, afi, safi); } else { if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s rcvd route-refresh (REQUEST) for %s/%s", - peer->host, afi2str(afi), safi2str(safi)); + zlog_debug( + "%s(%s) rcvd route-refresh (REQUEST) for %s/%s", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); /* In response to a "normal route refresh request" from the * peer, the speaker MUST send a BoRR message. @@ -2354,9 +2371,10 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) PEER_STATUS_EOR_SEND)) { if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s rcvd route-refresh (REQUEST) for %s/%s before EoR", - peer->host, afi2str(afi), - safi2str(safi)); + "%s(%s) rcvd route-refresh (REQUEST) for %s/%s before EoR", + peer->host, + bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); return BGP_PACKET_NOOP; } @@ -2365,9 +2383,9 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s sending route-refresh (BoRR) for %s/%s", - peer->host, afi2str(afi), - safi2str(safi)); + "%s(%s) sending route-refresh (BoRR) for %s/%s", + peer->host, bgp_peer_hostname(peer), + afi2str(afi), safi2str(safi)); /* Set flag Ready-To-Send to know when we can send EoRR * message. diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 3abfa7ebcf..01120ef44a 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -3433,9 +3433,9 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, return false; zlog_info( - "%%MAXPFXEXCEED: No. of %s prefix received from %s %u exceed, limit %u", - get_afi_safi_str(afi, safi, false), peer->host, pcount, - peer->pmax[afi][safi]); + "%%MAXPFXEXCEED: No. of %s prefix received from %s(%s) %u exceed, limit %u", + get_afi_safi_str(afi, safi, false), peer->host, + bgp_peer_hostname(peer), pcount, peer->pmax[afi][safi]); SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); if (CHECK_FLAG(peer->af_flags[afi][safi], @@ -3473,8 +3473,9 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s Maximum-prefix restart timer started for %d secs", - peer->host, peer->v_pmax_restart); + "%s(%s) Maximum-prefix restart timer started for %d secs", + peer->host, bgp_peer_hostname(peer), + peer->v_pmax_restart); BGP_TIMER_ON(peer->t_pmax_restart, bgp_maximum_prefix_restart_timer, @@ -12463,6 +12464,8 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, output_arg, show_flags, rpki_target_state); } else { + struct listnode *node; + struct bgp *abgp; /* show <ip> bgp ipv4 all: AFI_IP, show <ip> bgp ipv6 all: * AFI_IP6 */ @@ -12474,66 +12477,80 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, afi = CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP) ? AFI_IP : AFI_IP6; - FOREACH_SAFI (safi) { - if (!bgp_afi_safi_peer_exists(bgp, afi, safi)) - continue; + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, abgp)) { + FOREACH_SAFI (safi) { + if (!bgp_afi_safi_peer_exists(abgp, afi, + safi)) + continue; - if (uj) { - if (first) - first = false; + if (uj) { + if (first) + first = false; + else + vty_out(vty, ",\n"); + vty_out(vty, "\"%s\":{\n", + get_afi_safi_str(afi, + safi, + true)); + } else + vty_out(vty, + "\nFor address family: %s\n", + get_afi_safi_str( + afi, safi, + false)); + + if (community) + bgp_show_community( + vty, abgp, community, + exact_match, afi, safi, + show_flags); else - vty_out(vty, ",\n"); - vty_out(vty, "\"%s\":{\n", - get_afi_safi_str(afi, safi, - true)); - } else - vty_out(vty, - "\nFor address family: %s\n", - get_afi_safi_str(afi, safi, - false)); - - if (community) - bgp_show_community(vty, bgp, community, - exact_match, afi, - safi, show_flags); - else - bgp_show(vty, bgp, afi, safi, sh_type, - output_arg, show_flags, - rpki_target_state); - if (uj) - vty_out(vty, "}\n"); + bgp_show(vty, abgp, afi, safi, + sh_type, output_arg, + show_flags, + rpki_target_state); + if (uj) + vty_out(vty, "}\n"); + } } } else { /* show <ip> bgp all: for each AFI and SAFI*/ - FOREACH_AFI_SAFI (afi, safi) { - if (!bgp_afi_safi_peer_exists(bgp, afi, safi)) - continue; + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, abgp)) { + FOREACH_AFI_SAFI (afi, safi) { + if (!bgp_afi_safi_peer_exists(abgp, afi, + safi)) + continue; - if (uj) { - if (first) - first = false; - else - vty_out(vty, ",\n"); + if (uj) { + if (first) + first = false; + else + vty_out(vty, ",\n"); - vty_out(vty, "\"%s\":{\n", - get_afi_safi_str(afi, safi, - true)); - } else - vty_out(vty, - "\nFor address family: %s\n", - get_afi_safi_str(afi, safi, - false)); - - if (community) - bgp_show_community(vty, bgp, community, - exact_match, afi, - safi, show_flags); - else - bgp_show(vty, bgp, afi, safi, sh_type, - output_arg, show_flags, - rpki_target_state); - if (uj) - vty_out(vty, "}\n"); + vty_out(vty, "\"%s\":{\n", + get_afi_safi_str(afi, + safi, + true)); + } else + vty_out(vty, + "\nFor address family: %s\n", + get_afi_safi_str( + afi, safi, + false)); + + if (community) + bgp_show_community( + vty, abgp, community, + exact_match, afi, safi, + show_flags); + else + bgp_show(vty, abgp, afi, safi, + sh_type, output_arg, + show_flags, + rpki_target_state); + if (uj) + vty_out(vty, "}\n"); + } } } if (uj) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index dea1433f6d..3600e2f0ec 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -17599,11 +17599,67 @@ static const struct cmd_variable_handler bgp_var_peergroup[] = { {.tokenname = "PGNAME", .completions = bgp_ac_peergroup}, {.completions = NULL} }; +DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp)); + +static struct thread *t_bgp_cfg; + +bool bgp_config_inprocess(void) +{ + return thread_is_scheduled(t_bgp_cfg); +} + +static void bgp_config_finish(struct thread *t) +{ + struct listnode *node; + struct bgp *bgp; + + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) + hook_call(bgp_config_end, bgp); +} + +static void bgp_config_start(void) +{ +#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600 + THREAD_OFF(t_bgp_cfg); + thread_add_timer(bm->master, bgp_config_finish, NULL, + BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg); +} + +/* When we receive a hook the configuration is read, + * we start a timer to make sure we postpone sending + * EoR before route-maps are processed. + * This is especially valid if using `bgp route-map delay-timer`. + */ +static void bgp_config_end(void) +{ +#define BGP_POST_CONFIG_DELAY_SECONDS 1 + uint32_t bgp_post_config_delay = + thread_is_scheduled(bm->t_rmap_update) + ? thread_timer_remain_second(bm->t_rmap_update) + : BGP_POST_CONFIG_DELAY_SECONDS; + + /* If BGP config processing thread isn't running, then + * we can return and rely it's properly handled. + */ + if (!bgp_config_inprocess()) + return; + + THREAD_OFF(t_bgp_cfg); + + /* Start a new timer to make sure we don't send EoR + * before route-maps are processed. + */ + thread_add_timer(bm->master, bgp_config_finish, NULL, + bgp_post_config_delay, &t_bgp_cfg); +} + void bgp_vty_init(void) { cmd_variable_handler_register(bgp_var_neighbor); cmd_variable_handler_register(bgp_var_peergroup); + cmd_init_config_callbacks(bgp_config_start, bgp_config_end); + /* Install bgp top node. */ install_node(&bgp_node); install_node(&bgp_ipv4_unicast_node); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 93026c663a..4b393275d6 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -164,6 +164,7 @@ extern void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp); extern void bgp_config_write_listen(struct vty *vty, struct bgp *bgp); extern void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp); extern int bgp_vty_return(struct vty *vty, int ret); +extern bool bgp_config_inprocess(void); extern struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 38a106359e..22c09a38ac 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1731,6 +1731,8 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, peer->v_routeadv = (peer_sort(peer) == BGP_PEER_IBGP) ? BGP_DEFAULT_IBGP_ROUTEADV : BGP_DEFAULT_EBGP_ROUTEADV; + if (bgp_config_inprocess()) + peer->shut_during_cfg = true; peer = peer_lock(peer); /* bgp peer list reference */ peer->group = group; @@ -2347,15 +2349,15 @@ void peer_nsf_stop(struct peer *peer) if (peer->t_gr_restart) { BGP_TIMER_OFF(peer->t_gr_restart); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s graceful restart timer stopped", - peer->host); + zlog_debug("%s(%s) graceful restart timer stopped", + peer->host, bgp_peer_hostname(peer)); } if (peer->t_gr_stale) { BGP_TIMER_OFF(peer->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s graceful restart stalepath timer stopped", - peer->host); + "%s(%s) graceful restart stalepath timer stopped", + peer->host, bgp_peer_hostname(peer)); } bgp_clear_route_all(peer); } @@ -4294,8 +4296,9 @@ static void peer_flag_modify_action(struct peer *peer, uint32_t flag) BGP_TIMER_OFF(peer->t_pmax_restart); if (bgp_debug_neighbor_events(peer)) zlog_debug( - "%s Maximum-prefix restart timer canceled", - peer->host); + "%s(%s) Maximum-prefix restart timer canceled", + peer->host, + bgp_peer_hostname(peer)); } if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { @@ -7185,8 +7188,9 @@ static bool peer_maximum_prefix_clear_overflow(struct peer *peer) if (peer->t_pmax_restart) { BGP_TIMER_OFF(peer->t_pmax_restart); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s Maximum-prefix restart timer cancelled", - peer->host); + zlog_debug( + "%s(%s) Maximum-prefix restart timer cancelled", + peer->host, bgp_peer_hostname(peer)); } BGP_EVENT_ADD(peer, BGP_Start); return true; @@ -7938,8 +7942,33 @@ void bgp_pthreads_finish(void) frr_pthread_stop_all(); } +static int peer_unshut_after_cfg(struct bgp *bgp) +{ + struct listnode *node; + struct peer *peer; + + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + if (!peer->shut_during_cfg) + continue; + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s: released from config-pending hold", + peer->host); + + peer->shut_during_cfg = false; + if (peer_active(peer) && peer->status != Established) { + if (peer->status != Idle) + BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer, BGP_Start); + } + } + + return 0; +} + void bgp_init(unsigned short instance) { + hook_register(bgp_config_end, peer_unshut_after_cfg); /* allocates some vital data structures used by peer commands in * vty_init */ diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index a9475f39a7..766b0199f4 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -771,6 +771,7 @@ DECLARE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp)); DECLARE_HOOK(bgp_inst_config_write, (struct bgp *bgp, struct vty *vty), (bgp, vty)); +DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp)); /* Thread callback information */ struct afi_safi_info { @@ -1676,6 +1677,8 @@ struct peer { /* Long-lived Graceful Restart */ struct llgr_info llgr[AFI_MAX][SAFI_MAX]; + bool shut_during_cfg; + QOBJ_FIELDS; }; DECLARE_QOBJ_TYPE(peer); @@ -1703,9 +1706,10 @@ DECLARE_QOBJ_TYPE(peer); /* Check if suppress start/restart of sessions to peer. */ #define BGP_PEER_START_SUPPRESSED(P) \ - (CHECK_FLAG((P)->flags, PEER_FLAG_SHUTDOWN) \ - || CHECK_FLAG((P)->sflags, PEER_STATUS_PREFIX_OVERFLOW) \ - || CHECK_FLAG((P)->bgp->flags, BGP_FLAG_SHUTDOWN)) + (CHECK_FLAG((P)->flags, PEER_FLAG_SHUTDOWN) || \ + CHECK_FLAG((P)->sflags, PEER_STATUS_PREFIX_OVERFLOW) || \ + CHECK_FLAG((P)->bgp->flags, BGP_FLAG_SHUTDOWN) || \ + (P)->shut_during_cfg) #define PEER_ROUTE_ADV_DELAY(peer) \ (CHECK_FLAG(peer->thread_flags, PEER_THREAD_SUBGRP_ADV_DELAY)) @@ -2469,6 +2473,11 @@ static inline bool bgp_in_graceful_shutdown(struct bgp *bgp) !!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)); } +static inline const char *bgp_peer_hostname(struct peer *peer) +{ + return peer->hostname ? peer->hostname : "Unknown"; +} + /* For benefit of rfapi */ extern struct peer *peer_new(struct bgp *bgp); diff --git a/doc/user/basic.rst b/doc/user/basic.rst index 4c196cfcfe..ea4b3f41f3 100644 --- a/doc/user/basic.rst +++ b/doc/user/basic.rst @@ -678,6 +678,20 @@ Terminal Mode Commands This command displays FRR's timer data for timers that will pop in the future. +.. clicmd:: show yang operational-data XPATH [{format <json|xml>|translate TRANSLATOR|with-config}] DAEMON + + Display the YANG operational data starting from XPATH. The default + format is JSON, but can be displayed in XML as well. + + Normally YANG operational data are located inside containers marked + as `read-only`. + + Optionally it is also possible to display configuration leaves in + addition to operational data with the option `with-config`. This + option enables the display of configuration leaves with their + currently configured value (if the leaf is optional it will only show + if it was created or has a default value). + .. _common-invocation-options: Common Invocation Options diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 0244f7c583..cd220a4141 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -712,7 +712,7 @@ and this section also helps that case. Create a new locator. If the name of an existing locator is specified, move to specified locator's configuration node to change the settings it. -.. clicmd:: prefix X:X::X:X/M [function-bits-length 32] +.. clicmd:: prefix X:X::X:X/M [func-bits 32] Set the ipv6 prefix block of the locator. SRv6 locator is defined by RFC8986. The actual routing protocol specifies the locator and allocates a @@ -732,7 +732,7 @@ and this section also helps that case. will be ``2001:db8:1:1:1::``) The function bits range is 16bits by default. If operator want to change - function bits range, they can configure with ``function-bits-length`` + function bits range, they can configure with ``func-bits`` option. :: diff --git a/include/linux/mroute.h b/include/linux/mroute.h new file mode 100644 index 0000000000..a0bfdcb53e --- /dev/null +++ b/include/linux/mroute.h @@ -0,0 +1,193 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI__LINUX_MROUTE_H +#define _UAPI__LINUX_MROUTE_H + +#ifdef __LINUX__ +#include <linux/sockios.h> +#include <linux/types.h> +#endif +#include <netinet/in.h> /* For struct in_addr. */ + +/* Based on the MROUTING 3.5 defines primarily to keep + * source compatibility with BSD. + * + * See the mrouted code for the original history. + * + * Protocol Independent Multicast (PIM) data structures included + * Carlos Picoto (cap@di.fc.ul.pt) + */ + +#define MRT_BASE 200 +#define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */ +#define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */ +#define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */ +#define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */ +#define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */ +#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */ +#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */ +#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */ +#define MRT_PIM (MRT_BASE+8) /* enable PIM code */ +#define MRT_TABLE (MRT_BASE+9) /* Specify mroute table ID */ +#define MRT_ADD_MFC_PROXY (MRT_BASE+10) /* Add a (*,*|G) mfc entry */ +#define MRT_DEL_MFC_PROXY (MRT_BASE+11) /* Del a (*,*|G) mfc entry */ +#define MRT_FLUSH (MRT_BASE+12) /* Flush all mfc entries and/or vifs */ +#define MRT_MAX (MRT_BASE+12) + +#ifndef SIOCGETVIFCNT +#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */ +#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1) +#define SIOCGETRPF (SIOCPROTOPRIVATE+2) +#endif + +#ifndef MAXVIFS +#define MAXVIFS 32 +#endif +/* MRT_FLUSH optional flags */ +#define MRT_FLUSH_MFC 1 /* Flush multicast entries */ +#define MRT_FLUSH_MFC_STATIC 2 /* Flush static multicast entries */ +#define MRT_FLUSH_VIFS 4 /* Flush multicast vifs */ +#define MRT_FLUSH_VIFS_STATIC 8 /* Flush static multicast vifs */ + +typedef unsigned long vifbitmap_t; /* User mode code depends on this lot */ +typedef unsigned short vifi_t; +#define ALL_VIFS ((vifi_t)(-1)) + +/* Same idea as select */ + +#define VIFM_SET(n,m) ((m)|=(1<<(n))) +#define VIFM_CLR(n,m) ((m)&=~(1<<(n))) +#define VIFM_ISSET(n,m) ((m)&(1<<(n))) +#define VIFM_CLRALL(m) ((m)=0) +#define VIFM_COPY(mfrom,mto) ((mto)=(mfrom)) +#define VIFM_SAME(m1,m2) ((m1)==(m2)) + +/* Passed by mrouted for an MRT_ADD_VIF - again we use the + * mrouted 3.6 structures for compatibility + */ +struct vifctl { + vifi_t vifc_vifi; /* Index of VIF */ + unsigned char vifc_flags; /* VIFF_ flags */ + unsigned char vifc_threshold; /* ttl limit */ + unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ + union { + struct in_addr vifc_lcl_addr; /* Local interface address */ + int vifc_lcl_ifindex; /* Local interface index */ + }; + struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */ +}; + +#define VIFF_TUNNEL 0x1 /* IPIP tunnel */ +#define VIFF_SRCRT 0x2 /* NI */ +#define VIFF_REGISTER 0x4 /* register vif */ +#define VIFF_USE_IFINDEX 0x8 /* use vifc_lcl_ifindex instead of + vifc_lcl_addr to find an interface */ + +/* Cache manipulation structures for mrouted and PIMd */ +struct mfcctl { + struct in_addr mfcc_origin; /* Origin of mcast */ + struct in_addr mfcc_mcastgrp; /* Group in question */ + vifi_t mfcc_parent; /* Where it arrived */ + unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */ + unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */ + unsigned int mfcc_byte_cnt; + unsigned int mfcc_wrong_if; + int mfcc_expire; +}; + +/* Group count retrieval for mrouted */ +struct sioc_sg_req { + struct in_addr src; + struct in_addr grp; + unsigned long pktcnt; + unsigned long bytecnt; + unsigned long wrong_if; +}; + +/* To get vif packet counts */ +struct sioc_vif_req { + vifi_t vifi; /* Which iface */ + unsigned long icount; /* In packets */ + unsigned long ocount; /* Out packets */ + unsigned long ibytes; /* In bytes */ + unsigned long obytes; /* Out bytes */ +}; + +/* This is the format the mroute daemon expects to see IGMP control + * data. Magically happens to be like an IP packet as per the original + */ +struct igmpmsg { + uint32_t unused1,unused2; + unsigned char im_msgtype; /* What is this */ + unsigned char im_mbz; /* Must be zero */ + unsigned char im_vif; /* Low 8 bits of Interface */ + unsigned char im_vif_hi; /* High 8 bits of Interface */ + struct in_addr im_src,im_dst; +}; + +/* ipmr netlink table attributes */ +enum { + IPMRA_TABLE_UNSPEC, + IPMRA_TABLE_ID, + IPMRA_TABLE_CACHE_RES_QUEUE_LEN, + IPMRA_TABLE_MROUTE_REG_VIF_NUM, + IPMRA_TABLE_MROUTE_DO_ASSERT, + IPMRA_TABLE_MROUTE_DO_PIM, + IPMRA_TABLE_VIFS, + IPMRA_TABLE_MROUTE_DO_WRVIFWHOLE, + __IPMRA_TABLE_MAX +}; +#define IPMRA_TABLE_MAX (__IPMRA_TABLE_MAX - 1) + +/* ipmr netlink vif attribute format + * [ IPMRA_TABLE_VIFS ] - nested attribute + * [ IPMRA_VIF ] - nested attribute + * [ IPMRA_VIFA_xxx ] + */ +enum { + IPMRA_VIF_UNSPEC, + IPMRA_VIF, + __IPMRA_VIF_MAX +}; +#define IPMRA_VIF_MAX (__IPMRA_VIF_MAX - 1) + +/* vif-specific attributes */ +enum { + IPMRA_VIFA_UNSPEC, + IPMRA_VIFA_IFINDEX, + IPMRA_VIFA_VIF_ID, + IPMRA_VIFA_FLAGS, + IPMRA_VIFA_BYTES_IN, + IPMRA_VIFA_BYTES_OUT, + IPMRA_VIFA_PACKETS_IN, + IPMRA_VIFA_PACKETS_OUT, + IPMRA_VIFA_LOCAL_ADDR, + IPMRA_VIFA_REMOTE_ADDR, + IPMRA_VIFA_PAD, + __IPMRA_VIFA_MAX +}; +#define IPMRA_VIFA_MAX (__IPMRA_VIFA_MAX - 1) + +/* ipmr netlink cache report attributes */ +enum { + IPMRA_CREPORT_UNSPEC, + IPMRA_CREPORT_MSGTYPE, + IPMRA_CREPORT_VIF_ID, + IPMRA_CREPORT_SRC_ADDR, + IPMRA_CREPORT_DST_ADDR, + IPMRA_CREPORT_PKT, + IPMRA_CREPORT_TABLE, + __IPMRA_CREPORT_MAX +}; +#define IPMRA_CREPORT_MAX (__IPMRA_CREPORT_MAX - 1) + +/* That's all usermode folks */ + +#define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */ + +/* Pseudo messages used by mrouted */ +#define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */ +#define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */ +#define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */ +#define IGMPMSG_WRVIFWHOLE 4 /* For PIM Register and assert processing */ + +#endif /* _UAPI__LINUX_MROUTE_H */ diff --git a/include/linux/mroute6.h b/include/linux/mroute6.h new file mode 100644 index 0000000000..1fb90ec021 --- /dev/null +++ b/include/linux/mroute6.h @@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI__LINUX_MROUTE6_H +#define _UAPI__LINUX_MROUTE6_H + +#ifdef __LINUX__ +#include <linux/const.h> +#include <linux/types.h> +#include <linux/sockios.h> +#endif +#include <netinet/in.h> /* For struct sockaddr_in6. */ + +/* + * Based on the MROUTING 3.5 defines primarily to keep + * source compatibility with BSD. + * + * See the pim6sd code for the original history. + * + * Protocol Independent Multicast (PIM) data structures included + * Carlos Picoto (cap@di.fc.ul.pt) + * + */ + +#define MRT6_BASE 200 +#define MRT6_INIT (MRT6_BASE) /* Activate the kernel mroute code */ +#define MRT6_DONE (MRT6_BASE+1) /* Shutdown the kernel mroute */ +#define MRT6_ADD_MIF (MRT6_BASE+2) /* Add a virtual interface */ +#define MRT6_DEL_MIF (MRT6_BASE+3) /* Delete a virtual interface */ +#define MRT6_ADD_MFC (MRT6_BASE+4) /* Add a multicast forwarding entry */ +#define MRT6_DEL_MFC (MRT6_BASE+5) /* Delete a multicast forwarding entry */ +#define MRT6_VERSION (MRT6_BASE+6) /* Get the kernel multicast version */ +#define MRT6_ASSERT (MRT6_BASE+7) /* Activate PIM assert mode */ +#define MRT6_PIM (MRT6_BASE+8) /* enable PIM code */ +#define MRT6_TABLE (MRT6_BASE+9) /* Specify mroute table ID */ +#define MRT6_ADD_MFC_PROXY (MRT6_BASE+10) /* Add a (*,*|G) mfc entry */ +#define MRT6_DEL_MFC_PROXY (MRT6_BASE+11) /* Del a (*,*|G) mfc entry */ +#define MRT6_FLUSH (MRT6_BASE+12) /* Flush all mfc entries and/or vifs */ +#define MRT6_MAX (MRT6_BASE+12) + +#ifndef SIOCGETMIFCNT_IN6 +#define SIOCGETMIFCNT_IN6 SIOCPROTOPRIVATE /* IP protocol privates */ +#define SIOCGETSGCNT_IN6 (SIOCPROTOPRIVATE+1) +#define SIOCGETRPF (SIOCPROTOPRIVATE+2) +#endif + +#ifndef MAXMIFS +#define MAXMIFS 32 +#endif +/* MRT6_FLUSH optional flags */ +#define MRT6_FLUSH_MFC 1 /* Flush multicast entries */ +#define MRT6_FLUSH_MFC_STATIC 2 /* Flush static multicast entries */ +#define MRT6_FLUSH_MIFS 4 /* Flushing multicast vifs */ +#define MRT6_FLUSH_MIFS_STATIC 8 /* Flush static multicast vifs */ + +typedef unsigned long mifbitmap_t; /* User mode code depends on this lot */ +typedef unsigned short mifi_t; +#define ALL_MIFS ((mifi_t)(-1)) + +#ifndef IF_SETSIZE +#define IF_SETSIZE 256 +#endif + +typedef uint32_t if_mask; +#define NIFBITS (sizeof(if_mask) * 8) /* bits per mask */ + +typedef struct if_set { + if_mask ifs_bits[__KERNEL_DIV_ROUND_UP(IF_SETSIZE, NIFBITS)]; +} if_set; + +#define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS))) +#define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS))) +#define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS))) +#define IF_COPY(f, t) bcopy(f, t, sizeof(*(f))) +#define IF_ZERO(p) bzero(p, sizeof(*(p))) + +/* + * Passed by mrouted for an MRT_ADD_MIF - again we use the + * mrouted 3.6 structures for compatibility + */ + +struct mif6ctl { + mifi_t mif6c_mifi; /* Index of MIF */ + unsigned char mif6c_flags; /* MIFF_ flags */ + unsigned char vifc_threshold; /* ttl limit */ + __u16 mif6c_pifi; /* the index of the physical IF */ + unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ +}; + +#define MIFF_REGISTER 0x1 /* register vif */ + +/* + * Cache manipulation structures for mrouted and PIMd + */ + +struct mf6cctl { + struct sockaddr_in6 mf6cc_origin; /* Origin of mcast */ + struct sockaddr_in6 mf6cc_mcastgrp; /* Group in question */ + mifi_t mf6cc_parent; /* Where it arrived */ + struct if_set mf6cc_ifset; /* Where it is going */ +}; + +/* + * Group count retrieval for pim6sd + */ + +struct sioc_sg_req6 { + struct sockaddr_in6 src; + struct sockaddr_in6 grp; + unsigned long pktcnt; + unsigned long bytecnt; + unsigned long wrong_if; +}; + +/* + * To get vif packet counts + */ + +struct sioc_mif_req6 { + mifi_t mifi; /* Which iface */ + unsigned long icount; /* In packets */ + unsigned long ocount; /* Out packets */ + unsigned long ibytes; /* In bytes */ + unsigned long obytes; /* Out bytes */ +}; + +/* + * That's all usermode folks + */ + + + +/* + * Structure used to communicate from kernel to multicast router. + * We'll overlay the structure onto an MLD header (not an IPv6 heder like igmpmsg{} + * used for IPv4 implementation). This is because this structure will be passed via an + * IPv6 raw socket, on which an application will only receiver the payload i.e the data after + * the IPv6 header and all the extension headers. (See section 3 of RFC 3542) + */ + +struct mrt6msg { +#define MRT6MSG_NOCACHE 1 +#define MRT6MSG_WRONGMIF 2 +#define MRT6MSG_WHOLEPKT 3 /* used for use level encap */ +#define MRT6MSG_WRMIFWHOLE 4 /* For PIM Register and assert processing */ + __u8 im6_mbz; /* must be zero */ + __u8 im6_msgtype; /* what type of message */ + __u16 im6_mif; /* mif rec'd on */ + __u32 im6_pad; /* padding for 64 bit arch */ + struct in6_addr im6_src, im6_dst; +}; + +/* ip6mr netlink cache report attributes */ +enum { + IP6MRA_CREPORT_UNSPEC, + IP6MRA_CREPORT_MSGTYPE, + IP6MRA_CREPORT_MIF_ID, + IP6MRA_CREPORT_SRC_ADDR, + IP6MRA_CREPORT_DST_ADDR, + IP6MRA_CREPORT_PKT, + __IP6MRA_CREPORT_MAX +}; +#define IP6MRA_CREPORT_MAX (__IP6MRA_CREPORT_MAX - 1) + +#endif /* _UAPI__LINUX_MROUTE6_H */ diff --git a/include/subdir.am b/include/subdir.am index a06a8e5649..f6328ef38e 100644 --- a/include/subdir.am +++ b/include/subdir.am @@ -17,4 +17,6 @@ noinst_HEADERS += \ include/linux/seg6_hmac.h \ include/linux/seg6_iptunnel.h \ include/linux/seg6_local.h \ + include/linux/mroute.h \ + include/linux/mroute6.h \ # end diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index fd05fb94df..b5fce35b1e 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -1400,14 +1400,13 @@ static void spf_adj_list_parse_tlv(struct isis_spftree *spftree, spf_adj_list_parse_lsp(spftree, adj_list, lsp, id, metric); } -static void spf_adj_list_parse_lsp(struct isis_spftree *spftree, - struct list *adj_list, struct isis_lsp *lsp, - const uint8_t *pseudo_nodeid, - uint32_t pseudo_metric) +static void spf_adj_list_parse_lsp_frag(struct isis_spftree *spftree, + struct list *adj_list, + struct isis_lsp *lsp, + const uint8_t *pseudo_nodeid, + uint32_t pseudo_metric) { bool pseudo_lsp = LSP_PSEUDO_ID(lsp->hdr.lsp_id); - struct isis_lsp *frag; - struct listnode *node; struct isis_item *head; struct isis_item_list *te_neighs; @@ -1445,14 +1444,27 @@ static void spf_adj_list_parse_lsp(struct isis_spftree *spftree, } } } +} + + +static void spf_adj_list_parse_lsp(struct isis_spftree *spftree, + struct list *adj_list, struct isis_lsp *lsp, + const uint8_t *pseudo_nodeid, + uint32_t pseudo_metric) +{ + struct isis_lsp *frag; + struct listnode *node; + + spf_adj_list_parse_lsp_frag(spftree, adj_list, lsp, pseudo_nodeid, + pseudo_metric); /* Parse LSP fragments. */ for (ALL_LIST_ELEMENTS_RO(lsp->lspu.frags, node, frag)) { if (!frag->tlvs) continue; - spf_adj_list_parse_lsp(spftree, adj_list, frag, pseudo_nodeid, - pseudo_metric); + spf_adj_list_parse_lsp_frag(spftree, adj_list, frag, + pseudo_nodeid, pseudo_metric); } } diff --git a/lib/northbound.c b/lib/northbound.c index 49adea6d53..2cc7ac6ea1 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -1649,10 +1649,12 @@ static int nb_oper_data_iter_container(const struct nb_node *nb_node, uint32_t flags, nb_oper_data_cb cb, void *arg) { + const struct lysc_node *snode = nb_node->snode; + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY)) return NB_OK; - /* Presence containers. */ + /* Read-only presence containers. */ if (nb_node->cbs.get_elem) { struct yang_data *data; int ret; @@ -1662,15 +1664,24 @@ static int nb_oper_data_iter_container(const struct nb_node *nb_node, /* Presence container is not present. */ return NB_OK; - ret = (*cb)(nb_node->snode, translator, data, arg); + ret = (*cb)(snode, translator, data, arg); if (ret != NB_OK) return ret; } + /* Read-write presence containers. */ + if (CHECK_FLAG(snode->flags, LYS_CONFIG_W)) { + struct lysc_node_container *scontainer; + + scontainer = (struct lysc_node_container *)snode; + if (CHECK_FLAG(scontainer->flags, LYS_PRESENCE) + && !yang_dnode_get(running_config->dnode, xpath)) + return NB_OK; + } + /* Iterate over the child nodes. */ - return nb_oper_data_iter_children(nb_node->snode, xpath, list_entry, - list_keys, translator, false, flags, - cb, arg); + return nb_oper_data_iter_children(snode, xpath, list_entry, list_keys, + translator, false, flags, cb, arg); } static int diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 1e25f6a1e2..56eac9dc32 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -1464,6 +1464,7 @@ DEFPY (show_yang_operational_data, [{\ format <json$json|xml$xml>\ |translate WORD$translator_family\ + |with-config$with_config\ }]", SHOW_STR "YANG information\n" @@ -1473,13 +1474,15 @@ DEFPY (show_yang_operational_data, "JavaScript Object Notation\n" "Extensible Markup Language\n" "Translate operational data\n" - "YANG module translator\n") + "YANG module translator\n" + "Merge configuration data\n") { LYD_FORMAT format; struct yang_translator *translator = NULL; struct ly_ctx *ly_ctx; struct lyd_node *dnode; char *strp; + uint32_t print_options = LYD_PRINT_WITHSIBLINGS; if (xml) format = LYD_XML; @@ -1507,13 +1510,21 @@ DEFPY (show_yang_operational_data, yang_dnode_free(dnode); return CMD_WARNING; } + + if (with_config && yang_dnode_exists(running_config->dnode, xpath)) { + struct lyd_node *config_dnode = + yang_dnode_get(running_config->dnode, xpath); + if (config_dnode != NULL) { + lyd_merge_tree(&dnode, yang_dnode_dup(config_dnode), + LYD_MERGE_DESTRUCT); + print_options |= LYD_PRINT_WD_ALL; + } + } + (void)lyd_validate_all(&dnode, ly_ctx, 0, NULL); /* Display the data. */ - if (lyd_print_mem(&strp, dnode, format, - LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL) - != 0 - || !strp) { + if (lyd_print_mem(&strp, dnode, format, print_options) != 0 || !strp) { vty_out(vty, "%% Failed to display operational data.\n"); yang_dnode_free(dnode); return CMD_WARNING; diff --git a/lib/zclient.c b/lib/zclient.c index f6c5a8af08..0c34214151 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -768,9 +768,9 @@ static void zclient_connect(struct thread *t) } enum zclient_send_status zclient_send_rnh(struct zclient *zclient, int command, - const struct prefix *p, - bool connected, - bool resolve_via_def, vrf_id_t vrf_id) + const struct prefix *p, safi_t safi, + bool connected, bool resolve_via_def, + vrf_id_t vrf_id) { struct stream *s; @@ -779,7 +779,7 @@ enum zclient_send_status zclient_send_rnh(struct zclient *zclient, int command, zclient_create_header(s, command, vrf_id); stream_putc(s, (connected) ? 1 : 0); stream_putc(s, (resolve_via_def) ? 1 : 0); - stream_putw(s, SAFI_UNICAST); + stream_putw(s, safi); stream_putw(s, PREFIX_FAMILY(p)); stream_putc(s, p->prefixlen); switch (PREFIX_FAMILY(p)) { diff --git a/lib/zclient.h b/lib/zclient.h index 092754f602..7e1283d830 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -1071,7 +1071,8 @@ extern enum zclient_send_status zclient_route_send(uint8_t, struct zclient *, struct zapi_route *); extern enum zclient_send_status zclient_send_rnh(struct zclient *zclient, int command, const struct prefix *p, - bool connected, bool resolve_via_default, vrf_id_t vrf_id); + safi_t safi, bool connected, bool resolve_via_default, + vrf_id_t vrf_id); int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, uint32_t api_flags, uint32_t api_message); extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *); diff --git a/m4/.gitignore b/m4/.gitignore index 01a2a593d0..63f9fa78ed 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -3,6 +3,7 @@ !ax_compare_version.m4 !ax_cxx_compile_stdcxx.m4 +!ax_lua.m4 !ax_prog_perl_modules.m4 !ax_pthread.m4 !ax_python.m4 diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index 1220c32783..53b45d6ca3 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -613,7 +613,8 @@ struct ospf6_lsa *ospf6_translated_nssa_refresh(struct ospf6_area *area, return new; } -static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa *lsa) +static void ospf6_abr_translate_nssa(struct ospf6_area *area, + struct ospf6_lsa *lsa) { /* Incoming Type-7 or aggregated Type-7 * @@ -625,7 +626,7 @@ static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa * * Later, any Unapproved Translated Type-5's are flushed/discarded */ - struct ospf6_lsa *old = NULL, *new = NULL; + struct ospf6_lsa *old = NULL; struct ospf6_as_external_lsa *nssa_lsa; struct prefix prefix; struct ospf6_route *match; @@ -661,11 +662,36 @@ static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa * return; } + /* Find the type-5 LSA in the area-range table */ + match = ospf6_route_lookup_bestmatch(&prefix, area->nssa_range_table); + if (match && CHECK_FLAG(match->flag, OSPF6_ROUTE_NSSA_RANGE)) { + if (prefix_same(&prefix, &match->prefix)) { + /* The prefix range is being removed, + * no need to refresh + */ + if + CHECK_FLAG(match->flag, OSPF6_ROUTE_REMOVE) + return; + } else { + if (!CHECK_FLAG(match->flag, OSPF6_ROUTE_REMOVE)) { + if (IS_OSPF6_DEBUG_NSSA) + zlog_debug( + "%s: LSA Id %pI4 suppressed by range %pFX of area %s", + __func__, &lsa->header->id, + &match->prefix, area->name); + /* LSA will be suppressed by area-range command, + * no need to refresh + */ + return; + } + } + } + /* Find the existing AS-External LSA for this prefix */ - match = ospf6_route_lookup(&prefix, ospf6->external_table); + match = ospf6_route_lookup(&prefix, ospf6->route_table); if (match) { - old = ospf6_lsdb_lookup(OSPF6_LSTYPE_AS_EXTERNAL, - match->path.origin.id, ospf6->router_id, + old = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL), + lsa->external_lsa_id, ospf6->router_id, ospf6->lsdb); } @@ -675,20 +701,15 @@ static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6_lsa * return; } - if (old) { + if (old && !OSPF6_LSA_IS_MAXAGE(old)) { if (IS_OSPF6_DEBUG_NSSA) zlog_debug( - "%s : found old translated LSA Id %pI4, refreshing", + "%s : found old translated LSA Id %pI4, skip", __func__, &old->header->id); - /* refresh */ - new = ospf6_translated_nssa_refresh(area, lsa, old); - if (!new) { - if (IS_OSPF6_DEBUG_NSSA) - zlog_debug( - "%s : could not refresh translated LSA Id %pI4", - __func__, &old->header->id); - } + UNSET_FLAG(old->flag, OSPF6_LSA_UNAPPROVED); + return; + } else { /* no existing external route for this LSA Id * originate translated LSA diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 4b37c5bc20..18b1959b9b 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -155,8 +155,8 @@ void ospf6_zebra_import_default_route(struct ospf6 *ospf6, bool unreg) zserv_command_string(command), &prefix, ospf6->vrf_id); - if (zclient_send_rnh(zclient, command, &prefix, false, true, - ospf6->vrf_id) + if (zclient_send_rnh(zclient, command, &prefix, SAFI_UNICAST, false, + true, ospf6->vrf_id) == ZCLIENT_SEND_FAILURE) flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_send_rnh() failed", __func__); diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 48751dfba8..3ad7ca7d1b 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2422,10 +2422,10 @@ void ospf_external_lsa_flush(struct ospf *ospf, uint8_t type, && !(CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))) ospf_nssa_lsa_flush(ospf, p); - /* Sweep LSA from Link State Retransmit List. */ - ospf_ls_retransmit_delete_nbr_as(ospf, lsa); - if (!IS_LSA_MAXAGE(lsa)) { + /* Sweep LSA from Link State Retransmit List. */ + ospf_ls_retransmit_delete_nbr_as(ospf, lsa); + /* Unregister LSA from Refresh queue. */ ospf_refresher_unregister_lsa(ospf, lsa); diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index e4059d05c2..b5dbc4a5a9 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -2053,11 +2053,15 @@ void ospf_sr_config_write_router(struct vty *vty) vty_out(vty, " segment-routing global-block %u %u", OspfSR.srgb.start, upper); - if ((OspfSR.srlb.start != DEFAULT_SRLB_LABEL) - || (OspfSR.srlb.end != DEFAULT_SRLB_END)) + if ((OspfSR.srlb.start != DEFAULT_SRLB_LABEL) || + (OspfSR.srlb.end != DEFAULT_SRLB_END)) { + if ((OspfSR.srgb.start == DEFAULT_SRGB_LABEL) && + (OspfSR.srgb.size == DEFAULT_SRGB_SIZE)) + vty_out(vty, " segment-routing global-block %u %u", + OspfSR.srgb.start, upper); vty_out(vty, " local-block %u %u\n", OspfSR.srlb.start, OspfSR.srlb.end); - else + } else vty_out(vty, "\n"); if (OspfSR.msd != 0) @@ -2663,12 +2667,18 @@ DEFUN (no_sr_prefix_sid, return CMD_WARNING_CONFIG_FAILED; } + osr_debug("SR (%s): Remove Prefix %pFX with index %u", __func__, + (struct prefix *)&srp->prefv4, srp->sid); + /* Get Interface */ ifp = if_lookup_by_index(srp->nhlfe.ifindex, VRF_DEFAULT); if (ifp == NULL) { vty_out(vty, "interface for prefix %s not found.\n", argv[idx]->arg); - return CMD_WARNING_CONFIG_FAILED; + /* silently remove from list */ + listnode_delete(OspfSR.self->ext_prefix, srp); + XFREE(MTYPE_OSPF_SR_PARAMS, srp); + return CMD_SUCCESS; } /* Update Extended Prefix LSA */ @@ -2677,9 +2687,6 @@ DEFUN (no_sr_prefix_sid, return CMD_WARNING; } - osr_debug("SR (%s): Remove Prefix %pFX with index %u", __func__, - (struct prefix *)&srp->prefv4, srp->sid); - /* Delete NHLFE if NO-PHP is set and EXPLICIT NULL not set */ if (CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_NPFLG) && !CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_EFLG)) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index d4245bde7f..a753340476 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -4395,11 +4395,18 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, json_neighbor = json_object_new_object(); ospf_nbr_ism_state_message(nbr, msgbuf, 16); - +#if CONFDATE > 20230321 +CPP_NOTICE("Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter") +#endif json_object_int_add(json_neighbor, "priority", nbr->priority); json_object_string_add(json_neighbor, "state", msgbuf); + json_object_int_add(json_neighbor, + "nbrPriority", + nbr->priority); + json_object_string_add(json_neighbor, + "nbrState", msgbuf); json_object_string_add( json_neighbor, "converged", @@ -4425,6 +4432,10 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, json_object_int_add(json_neighbor, "deadTimeMsecs", time_store); + json_object_int_add( + json_neighbor, + "routerDeadIntervalTimerDueMsec", + time_store); json_object_string_add( json_neighbor, "upTime", ospf_timeval_dump( @@ -4440,22 +4451,41 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, json_object_string_add(json_neighbor, "deadTimeMsecs", "inactive"); + json_object_string_add( + json_neighbor, + "routerDeadIntervalTimerDueMsec", + "inactive"); } json_object_string_addf(json_neighbor, "address", "%pI4", &nbr->src); + json_object_string_addf(json_neighbor, + "ifaceAddress", "%pI4", + &nbr->src); json_object_string_add(json_neighbor, "ifaceName", IF_NAME(oi)); json_object_int_add( json_neighbor, "retransmitCounter", ospf_ls_retransmit_count(nbr)); + json_object_int_add( + json_neighbor, + "linkStateRetransmissionListCounter", + ospf_ls_retransmit_count(nbr)); json_object_int_add(json_neighbor, "requestCounter", ospf_ls_request_count(nbr)); + json_object_int_add( + json_neighbor, + "linkStateRequestListCounter", + ospf_ls_request_count(nbr)); json_object_int_add(json_neighbor, "dbSummaryCounter", ospf_db_summary_count(nbr)); + json_object_int_add( + json_neighbor, + "databaseSummaryListCounter", + ospf_db_summary_count(nbr)); json_object_array_add(json_neigh_array, json_neighbor); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 389d3647d0..496d85fd7b 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -1280,6 +1280,7 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS) { struct zapi_route api; struct prefix_ipv4 p; + struct prefix pgen; unsigned long ifindex; struct in_addr nexthop; struct external_info *ei; @@ -1302,13 +1303,17 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS) if (IPV4_NET127(ntohl(p.prefix.s_addr))) return 0; + pgen.family = p.family; + pgen.prefixlen = p.prefixlen; + pgen.u.prefix4 = p.prefix; + /* Re-destributed route is default route. * Here, route type is used as 'ZEBRA_ROUTE_KERNEL' for * updating ex-info. But in resetting (no default-info * originate)ZEBRA_ROUTE_MAX is used to delete the ex-info. * Resolved this inconsistency by maintaining same route type. */ - if (is_default_prefix4(&p)) + if ((is_default_prefix(&pgen)) && (api.type != ZEBRA_ROUTE_OSPF)) rt_type = DEFAULT_ROUTE; if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index f992588729..da4e3e1bc0 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -485,7 +485,8 @@ void pbr_send_rnh(struct nexthop *nhop, bool reg) break; } - if (zclient_send_rnh(zclient, command, &p, false, false, nhop->vrf_id) + if (zclient_send_rnh(zclient, command, &p, SAFI_UNICAST, false, false, + nhop->vrf_id) == ZCLIENT_SEND_FAILURE) { zlog_warn("%s: Failure to send nexthop to zebra", __func__); } diff --git a/pimd/pim6_mroute_msg.c b/pimd/pim6_mroute_msg.c new file mode 100644 index 0000000000..f34fa5965a --- /dev/null +++ b/pimd/pim6_mroute_msg.c @@ -0,0 +1,196 @@ +/* + * PIM for Quagga + * Copyright (C) 2022 Dell Technologies Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> +#include "log.h" +#include "privs.h" +#include "if.h" +#include "prefix.h" +#include "vty.h" +#include "plist.h" +#include "sockopt.h" +#include "lib_errors.h" +#include "lib/network.h" + +#include "pimd.h" +#include "pim_mroute.h" +#include "pim_oil.h" +#include "pim_str.h" +#include "pim_time.h" +#include "pim_iface.h" +#include "pim_macro.h" +#include "pim_rp.h" +#include "pim_oil.h" +#include "pim_ssm.h" +#include "pim_sock.h" + +int pim_mroute_set(struct pim_instance *pim, int enable) +{ + int err; + int opt, data; + socklen_t data_len = sizeof(data); + static const struct sock_filter filter[] = { + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0), + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 1), + BPF_STMT(BPF_RET | BPF_K, 0xffff), + BPF_STMT(BPF_RET | BPF_K, 0), + }; + + static const struct sock_fprog bpf = { + .len = array_size(filter), + .filter = (struct sock_filter *)filter, + }; + + /* + * We need to create the VRF table for the pim mroute_socket + */ + if (pim->vrf->vrf_id != VRF_DEFAULT) { + frr_with_privs (&pimd_privs) { + + data = pim->vrf->data.l.table_id; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, + MRT6_TABLE, &data, data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO, MRT6_TABLE=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + data, errno, safe_strerror(errno)); + return -1; + } + } + } + + frr_with_privs (&pimd_privs) { + opt = enable ? MRT6_INIT : MRT6_DONE; + /* + * *BSD *cares* about what value we pass down + * here + */ + data = 1; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &data, + data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,%s=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + enable ? "MRT6_INIT" : "MRT6_DONE", data, errno, + safe_strerror(errno)); + return -1; + } + } + + if (enable) { + /* Linux and Solaris IPV6_PKTINFO */ + data = 1; + if (setsockopt(pim->mroute_socket, PIM_IPPROTO, IPV6_RECVPKTINFO, + &data, data_len)) { + zlog_warn( + "Could not set IPV6_PKTINFO on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + } + + setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); + + if (set_nonblocking (pim->mroute_socket) < 0) { + zlog_warn( + "Could not set non blocking on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + + if (enable) { +#if defined linux + int upcalls = MRT6MSG_WRMIFWHOLE; + opt = MRT6_PIM; + + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &upcalls, + sizeof(upcalls)); + if (err) { + zlog_warn( + "Failure to register for WHOLE and WRONGMIF upcalls %d %s", + errno, safe_strerror(errno)); + return -1; + } +#else + zlog_warn( + "PIM-SM will not work properly on this platform, until the ability to receive the WHOLEPKT upcall"); +#endif + if (setsockopt(pim->mroute_socket, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf))) { + zlog_warn("Failure to attach SO_ATTACH_FILTER on fd %d: %d %s", + pim->mroute_socket, errno, safe_strerror(errno)); + } + } + + return 0; +} +static const char *const mrt6msgtype2str[MRT6MSG_WRMIFWHOLE + 1] = { + "<unknown_upcall?>", "NOCACHE", "WRONGMIF", "WHOLEPKT", "WRMIFWHOLE"}; + +int pim_mroute_msg(struct pim_instance *pim, const char *buf, + size_t buf_size, ifindex_t ifindex) +{ + struct interface *ifp; + const struct ip6_hdr *ip6_hdr; + const struct mrt6msg *msg; + + if (buf_size < (int)sizeof(struct ip6_hdr)) + return 0; + + ip6_hdr = (const struct ip6_hdr *)buf; + + if ((ip6_hdr->ip6_vfc & 0xf) == 0) { + msg = (const struct mrt6msg *)buf; + + ifp = pim_if_find_by_vif_index(pim, msg->im6_mif); + + if (!ifp) + return 0; + if (PIM_DEBUG_MROUTE) { + zlog_debug( + "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI6,%pI6) on %s mifi=%d size=%ld", + __func__, mrt6msgtype2str[msg->im6_msgtype], + msg->im6_msgtype, ip6_hdr->ip6_nxt, + pim->mroute_socket, &msg->im6_src, + &msg->im6_dst, ifp->name, msg->im6_mif, + (long int)buf_size); + } + + switch (msg->im6_msgtype) { + case MRT6MSG_WRONGMIF: + return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, + msg); + case MRT6MSG_NOCACHE: + return pim_mroute_msg_nocache(pim->mroute_socket, ifp, + msg); + case MRT6MSG_WHOLEPKT: + return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, + (const char *)msg); + case MRT6MSG_WRMIFWHOLE: + return pim_mroute_msg_wrvifwhole( + pim->mroute_socket, ifp, (const char *)msg); + default: + break; + } + } + + return 0; +} + diff --git a/pimd/pim6_stubs.c b/pimd/pim6_stubs.c index e689c7aca4..818b137abf 100644 --- a/pimd/pim6_stubs.c +++ b/pimd/pim6_stubs.c @@ -54,70 +54,67 @@ void zclient_lookup_free(void) } /* - * packet handling + * PIM register */ -int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, - int pim_msg_size, const char *ifname) -{ - return 0; -} - -int pim_hello_send(struct interface *ifp, uint16_t holdtime) +void pim_register_join(struct pim_upstream *up) { - return -1; } -void pim_hello_restart_now(struct interface *ifp) +void pim_null_register_send(struct pim_upstream *up) { } -void pim_hello_restart_triggered(struct interface *ifp) +void pim_reg_del_on_couldreg_fail(struct interface *ifp) { } -int pim_sock_add(struct interface *ifp) +bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) { - return -1; + return false; } -void pim_sock_delete(struct interface *ifp, const char *delete_message) +void pim_bsm_proc_free(struct pim_instance *pim) { } -/* - * PIM register - */ -void pim_register_join(struct pim_upstream *up) +void pim_bsm_proc_init(struct pim_instance *pim) { } -void pim_null_register_send(struct pim_upstream *up) +struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, + struct prefix *grp) { + return NULL; } -void pim_reg_del_on_couldreg_fail(struct interface *ifp) +void pim_bsm_write_config(struct vty *vty, struct interface *ifp) { } -bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, + uint32_t buf_size, bool no_fwd) { - return false; + return 0; } -void pim_bsm_proc_free(struct pim_instance *pim) +void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src, + struct pim_rpf *rpg, int null_register, + struct pim_upstream *up) { } -void pim_bsm_proc_init(struct pim_instance *pim) +void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src, + pim_addr originator) { } -struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, - struct prefix *grp) +int pim_register_recv(struct interface *ifp, pim_addr dest_addr, + pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size) { - return NULL; + return 0; } -void pim_bsm_write_config(struct vty *vty, struct interface *ifp) +int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size) { + return 0; } diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index e7fff4db6f..cbd44388c1 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -338,6 +338,7 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, uint32_t metric_preference, uint32_t route_metric, uint32_t rpt_bit_flag) { + struct pim_interface *pim_ifp = ifp->info; uint8_t *buf_pastend = pim_msg + buf_size; uint8_t *pim_msg_curr; int pim_msg_size; @@ -380,7 +381,9 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, Add PIM header */ pim_msg_size = pim_msg_curr - pim_msg; - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_ASSERT, false); + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, pim_msg_size, + PIM_MSG_TYPE_ASSERT, false); return pim_msg_size; } diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index 66c37e7aed..0e91773be7 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -718,6 +718,7 @@ static bool pim_bsm_send_intf(uint8_t *buf, int len, struct interface *ifp, static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, uint32_t pim_mtu, pim_addr dst_addr, bool no_fwd) { + struct pim_interface *pim_ifp = ifp->info; struct bsmmsg_grpinfo *grpinfo, *curgrp; uint8_t *firstgrp_ptr; uint8_t *pkt; @@ -836,9 +837,10 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, < (PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN))) { /* No space to fit in more rp, send this pkt */ this_pkt_len = pim_mtu - this_pkt_rem; - pim_msg_build_header(pak_start, this_pkt_len, - PIM_MSG_TYPE_BOOTSTRAP, - no_fwd); + pim_msg_build_header( + pim_ifp->primary_address, dst_addr, + pak_start, this_pkt_len, + PIM_MSG_TYPE_BOOTSTRAP, no_fwd); pim_bsm_send_intf(pak_start, this_pkt_len, ifp, dst_addr); @@ -873,7 +875,8 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, /* Send if we have any unsent packet */ if (pak_pending) { this_pkt_len = pim_mtu - this_pkt_rem; - pim_msg_build_header(pak_start, this_pkt_len, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + pak_start, this_pkt_len, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); pim_bsm_send_intf(pak_start, (pim_mtu - this_pkt_rem), ifp, dst_addr); @@ -920,7 +923,8 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, zlog_debug("%s: pim_bsm_frag_send returned %s", __func__, ret ? "TRUE" : "FALSE"); } else { - pim_msg_build_header(buf, len, PIM_MSG_TYPE_BOOTSTRAP, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + buf, len, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); if (!pim_bsm_send_intf(buf, len, ifp, dst_addr)) { if (PIM_DEBUG_BSM) @@ -999,7 +1003,8 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) } } else { /* Pim header needs to be constructed */ - pim_msg_build_header(bsfrag->data, bsfrag->size, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + bsfrag->data, bsfrag->size, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); ret = pim_bsm_send_intf(bsfrag->data, bsfrag->size, ifp, dst_addr); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 8e0e418a99..4470d05663 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -187,9 +187,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, ifp->info = pim_ifp; -#if PIM_IPV == 4 pim_sock_reset(ifp); -#endif pim_if_add_vif(ifp, ispimreg, is_vxlan_term); pim_ifp->pim->mcast_if_count++; @@ -1751,7 +1749,6 @@ static int pim_ifp_down(struct interface *ifp) */ pim_if_addr_del_all(ifp); -#if PIM_IPV == 4 /* pim_sock_delete() closes the socket, stops read and timer threads, @@ -1760,7 +1757,6 @@ static int pim_ifp_down(struct interface *ifp) if (ifp->info) { pim_sock_delete(ifp, "link down"); } -#endif } if (ifp->info) { diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index 4ac9ef7f51..f8323deda0 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -30,18 +30,7 @@ #include "pim_vxlan_instance.h" #include "pim_oil.h" #include "pim_upstream.h" - -#if defined(HAVE_LINUX_MROUTE_H) -#include <linux/mroute.h> -#else -/* - Below: from <linux/mroute.h> -*/ - -#ifndef MAXVIFS -#define MAXVIFS (256) -#endif -#endif +#include "pim_mroute.h" enum pim_spt_switchover { PIM_SPT_IMMEDIATE, diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 2c11d5d13f..88078dd366 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -488,7 +488,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) group_size = pim_msg_get_jp_group_size(group->sources); if (group_size > packet_left) { - pim_msg_build_header(pim_msg, packet_size, + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, + packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, @@ -544,7 +546,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) grp = (struct pim_jp_groups *)curr_ptr; if (packet_left < sizeof(struct pim_jp_groups) || msg->num_groups == 255) { - pim_msg_build_header(pim_msg, packet_size, + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, + packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, @@ -564,8 +568,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (!new_packet) { // msg->num_groups = htons (msg->num_groups); - pim_msg_build_header(pim_msg, packet_size, - PIM_MSG_TYPE_JOIN_PRUNE, false); + pim_msg_build_header( + pim_ifp->primary_address, qpim_all_pim_routers_addr, + pim_msg, packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, qpim_all_pim_routers_addr, pim_msg, packet_size, diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index bce319b3ad..7fc4f12d27 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -43,121 +43,19 @@ #include "pim_ssm.h" #include "pim_sock.h" #include "pim_vxlan.h" +#include "pim_msg.h" static void mroute_read_on(struct pim_instance *pim); -static int pim_mroute_set(struct pim_instance *pim, int enable) -{ - int err; - int opt, data; - socklen_t data_len = sizeof(data); - long flags; - - /* - * We need to create the VRF table for the pim mroute_socket - */ - if (pim->vrf->vrf_id != VRF_DEFAULT) { - frr_with_privs(&pimd_privs) { - - data = pim->vrf->data.l.table_id; - err = setsockopt(pim->mroute_socket, IPPROTO_IP, - MRT_TABLE, - &data, data_len); - if (err) { - zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s", - __FILE__, __func__, pim->mroute_socket, - data, errno, safe_strerror(errno)); - return -1; - } - - } - } - - frr_with_privs(&pimd_privs) { - opt = enable ? MRT_INIT : MRT_DONE; - /* - * *BSD *cares* about what value we pass down - * here - */ - data = 1; - err = setsockopt(pim->mroute_socket, IPPROTO_IP, - opt, &data, data_len); - if (err) { - zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s", - __FILE__, __func__, pim->mroute_socket, - enable ? "MRT_INIT" : "MRT_DONE", data, errno, - safe_strerror(errno)); - return -1; - } - } - -#if defined(HAVE_IP_PKTINFO) - if (enable) { - /* Linux and Solaris IP_PKTINFO */ - data = 1; - if (setsockopt(pim->mroute_socket, IPPROTO_IP, IP_PKTINFO, - &data, data_len)) { - zlog_warn( - "Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", - pim->mroute_socket, errno, - safe_strerror(errno)); - } - } -#endif - - setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); - - flags = fcntl(pim->mroute_socket, F_GETFL, 0); - if (flags < 0) { - zlog_warn("Could not get flags on socket fd:%d %d %s", - pim->mroute_socket, errno, safe_strerror(errno)); - close(pim->mroute_socket); - return -1; - } - if (fcntl(pim->mroute_socket, F_SETFL, flags | O_NONBLOCK)) { - zlog_warn("Could not set O_NONBLOCK on socket fd:%d %d %s", - pim->mroute_socket, errno, safe_strerror(errno)); - close(pim->mroute_socket); - return -1; - } - - if (enable) { -#if defined linux - int upcalls = IGMPMSG_WRVIFWHOLE; - opt = MRT_PIM; - - err = setsockopt(pim->mroute_socket, IPPROTO_IP, opt, &upcalls, - sizeof(upcalls)); - if (err) { - zlog_warn( - "Failure to register for VIFWHOLE and WRONGVIF upcalls %d %s", - errno, safe_strerror(errno)); - return -1; - } -#else - zlog_warn( - "PIM-SM will not work properly on this platform, until the ability to receive the WRVIFWHOLE upcall"); -#endif - } - - return 0; -} - -#if PIM_IPV == 4 -static const char *const igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { - "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; -static int pim_mroute_msg_nocache(int fd, struct interface *ifp, - const struct igmpmsg *msg) +int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg) { struct pim_interface *pim_ifp = ifp->info; struct pim_upstream *up; struct pim_rpf *rpg; pim_sgaddr sg; - rpg = pim_ifp ? RP(pim_ifp->pim, msg->im_dst) : NULL; + rpg = pim_ifp ? RP(pim_ifp->pim, msg->msg_im_dst) : NULL; /* * If the incoming interface is unknown OR * the Interface type is SSM we don't need to @@ -176,7 +74,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, * If we've received a multicast packet that isn't connected to * us */ - if (!pim_if_connected_to_source(ifp, msg->im_src)) { + if (!pim_if_connected_to_source(ifp, msg->msg_im_src)) { if (PIM_DEBUG_MROUTE_DETAIL) zlog_debug( "%s: Received incoming packet that doesn't originate on our seg", @@ -185,13 +83,14 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, } memset(&sg, 0, sizeof(sg)); - sg.src = msg->im_src; - sg.grp = msg->im_dst; + sg.src = msg->msg_im_src; + sg.grp = msg->msg_im_dst; if (!(PIM_I_am_DR(pim_ifp))) { if (PIM_DEBUG_MROUTE_DETAIL) - zlog_debug("%s: Interface is not the DR blackholing incoming traffic for %pSG", - __func__, &sg); + zlog_debug( + "%s: Interface is not the DR blackholing incoming traffic for %pSG", + __func__, &sg); /* * We are not the DR, but we are still receiving packets @@ -238,22 +137,21 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, - const char *buf) +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf) { struct pim_interface *pim_ifp; pim_sgaddr sg; struct pim_rpf *rpg; - const struct ip *ip_hdr; + const ipv_hdr *ip_hdr; struct pim_upstream *up; pim_ifp = ifp->info; - ip_hdr = (const struct ip *)buf; + ip_hdr = (const ipv_hdr *)buf; memset(&sg, 0, sizeof(sg)); - sg.src = ip_hdr->ip_src; - sg.grp = ip_hdr->ip_dst; + sg.src = IPV_SRC(ip_hdr); + sg.grp = IPV_DST(ip_hdr); up = pim_upstream_find(pim_ifp->pim, &sg); if (!up) { @@ -268,8 +166,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, __func__, NULL); if (!up) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: Unable to create upstream information for %pSG", - __func__, &sg); + zlog_debug( + "%s: Unable to create upstream information for %pSG", + __func__, &sg); return 0; } pim_upstream_keep_alive_timer_start( @@ -283,8 +182,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, return 0; } if (PIM_DEBUG_MROUTE_DETAIL) { - zlog_debug("%s: Unable to find upstream channel WHOLEPKT%pSG", - __func__, &sg); + zlog_debug( + "%s: Unable to find upstream channel WHOLEPKT%pSG", + __func__, &sg); } return 0; } @@ -314,8 +214,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, if (!up->t_rs_timer) { if (pim_is_grp_ssm(pim_ifp->pim, sg.grp)) { if (PIM_DEBUG_PIM_REG) - zlog_debug("%pSG register forward skipped as group is SSM", - &sg); + zlog_debug( + "%pSG register forward skipped as group is SSM", + &sg); return 0; } @@ -327,23 +228,22 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, return 0; } - pim_register_send((uint8_t *)buf + sizeof(struct ip), - ntohs(ip_hdr->ip_len) - sizeof(struct ip), + pim_register_send((uint8_t *)buf + sizeof(ipv_hdr), + ntohs(IPV_LEN(ip_hdr)) - sizeof(ipv_hdr), pim_ifp->primary_address, rpg, 0, up); } return 0; } -static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, - const struct igmpmsg *msg) +int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg) { struct pim_ifchannel *ch; struct pim_interface *pim_ifp; pim_sgaddr sg; memset(&sg, 0, sizeof(sg)); - sg.src = msg->im_src; - sg.grp = msg->im_dst; + sg.src = msg->msg_im_src; + sg.grp = msg->msg_im_dst; /* Send Assert(S,G) on iif as response to WRONGVIF kernel upcall. @@ -358,16 +258,18 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (!ifp) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG could not find input interface for input_vif_index=%d", - __func__, &sg, msg->im_vif); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG could not find input interface for input_vif_index=%d", + __func__, &sg, msg->msg_im_vif); return -1; } pim_ifp = ifp->info; if (!pim_ifp) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG multicast not enabled on interface %s", - __func__, &sg, ifp->name); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG multicast not enabled on interface %s", + __func__, &sg, ifp->name); return -2; } @@ -375,16 +277,17 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (!ch) { pim_sgaddr star_g = sg; if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG could not find channel on interface %s", - __func__, &sg, ifp->name); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG could not find channel on interface %s", + __func__, &sg, ifp->name); star_g.src = PIMADDR_ANY; ch = pim_ifchannel_find(ifp, &star_g); if (!ch) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (*,G)=%pSG could not find channel on interface %s", - __func__, &star_g, - ifp->name); + zlog_debug( + "%s: WRONGVIF (*,G)=%pSG could not find channel on interface %s", + __func__, &star_g, ifp->name); return -3; } } @@ -433,10 +336,9 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, - const char *buf) +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf) { - const struct ip *ip_hdr = (const struct ip *)buf; + const ipv_hdr *ip_hdr = (const ipv_hdr *)buf; struct pim_interface *pim_ifp; struct pim_instance *pim; struct pim_ifchannel *ch; @@ -447,8 +349,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, pim_ifp = ifp->info; memset(&sg, 0, sizeof(sg)); - sg.src = ip_hdr->ip_src; - sg.grp = ip_hdr->ip_dst; + sg.src = IPV_SRC(ip_hdr); + sg.grp = IPV_DST(ip_hdr); ch = pim_ifchannel_find(ifp, &sg); if (ch) { @@ -481,8 +383,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, struct pim_rpf *rpf = RP(pim_ifp->pim, sg.grp); /* No RPF or No RPF interface or No mcast on RPF interface */ - if (!rpf || !rpf->source_nexthop.interface - || !rpf->source_nexthop.interface->info) + if (!rpf || !rpf->source_nexthop.interface || + !rpf->source_nexthop.interface->info) return 0; /* @@ -512,7 +414,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, * bow out of doing a nexthop lookup and * setting the SPTBIT to true */ - if (up->upstream_register.s_addr != INADDR_ANY && + if (!(pim_addr_is_any(up->upstream_register)) && pim_nexthop_lookup(pim_ifp->pim, &source, up->upstream_register, 0)) { pim_register_stop_send(source.interface, &sg, @@ -551,8 +453,9 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, NULL); if (!up) { if (PIM_DEBUG_MROUTE) - zlog_debug("%pSG: WRONGVIF%s unable to create upstream on interface", - &sg, ifp->name); + zlog_debug( + "%pSG: WRONGVIF%s unable to create upstream on interface", + &sg, ifp->name); return -2; } PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); @@ -577,119 +480,6 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg(struct pim_instance *pim, const char *buf, - int buf_size, ifindex_t ifindex) -{ - struct interface *ifp; - const struct ip *ip_hdr; - const struct igmpmsg *msg; - - if (buf_size < (int)sizeof(struct ip)) - return 0; - - ip_hdr = (const struct ip *)buf; - - if (ip_hdr->ip_p == IPPROTO_IGMP) { -#if PIM_IPV == 4 - struct pim_interface *pim_ifp; - struct in_addr ifaddr; - struct gm_sock *igmp; - const struct prefix *connected_src; - - /* We have the IP packet but we do not know which interface this - * packet was - * received on. Find the interface that is on the same subnet as - * the source - * of the IP packet. - */ - ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id); - - if (!ifp || !ifp->info) - return 0; - - connected_src = pim_if_connected_to_source(ifp, ip_hdr->ip_src); - - if (!connected_src && !pim_addr_is_any(ip_hdr->ip_src)) { - if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug("Recv IGMP packet on interface: %s from a non-connected source: %pI4", - ifp->name, &ip_hdr->ip_src); - } - return 0; - } - - pim_ifp = ifp->info; - ifaddr = connected_src ? connected_src->u.prefix4 - : pim_ifp->primary_address; - igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->gm_socket_list, - ifaddr); - - if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug( - "%s(%s): igmp kernel upcall on %s(%p) for %pI4 -> %pI4", - __func__, pim->vrf->name, ifp->name, igmp, - &ip_hdr->ip_src, &ip_hdr->ip_dst); - } - if (igmp) - pim_igmp_packet(igmp, (char *)buf, buf_size); - else if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug( - "No IGMP socket on interface: %s with connected source: %pI4", - ifp->name, &ifaddr); - } -#endif - } else if (ip_hdr->ip_p) { - if (PIM_DEBUG_MROUTE_DETAIL) { - zlog_debug( - "%s: no kernel upcall proto=%d src: %pI4 dst: %pI4 msg_size=%d", - __func__, ip_hdr->ip_p, &ip_hdr->ip_src, &ip_hdr->ip_dst, - buf_size); - } - - } else { - msg = (const struct igmpmsg *)buf; - - ifp = pim_if_find_by_vif_index(pim, msg->im_vif); - - if (!ifp) - return 0; - if (PIM_DEBUG_MROUTE) { - zlog_debug( - "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI4,%pI4) on %s vifi=%d size=%d", - __func__, igmpmsgtype2str[msg->im_msgtype], - msg->im_msgtype, ip_hdr->ip_p, - pim->mroute_socket, &msg->im_src, &msg->im_dst, ifp->name, - msg->im_vif, buf_size); - } - - switch (msg->im_msgtype) { - case IGMPMSG_WRONGVIF: - return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, - msg); - case IGMPMSG_NOCACHE: - return pim_mroute_msg_nocache(pim->mroute_socket, ifp, - msg); - case IGMPMSG_WHOLEPKT: - return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, - (const char *)msg); - case IGMPMSG_WRVIFWHOLE: - return pim_mroute_msg_wrvifwhole( - pim->mroute_socket, ifp, (const char *)msg); - default: - break; - } - } - - return 0; -} -#else /* PIM_IPV != 4 */ - -static int pim_mroute_msg(struct pim_instance *pim, const char *buf, - int buf_size, ifindex_t ifindex) -{ - return 0; -} -#endif /* PIM_IPV != 4 */ - static void mroute_read(struct thread *t) { struct pim_instance *pim; @@ -726,6 +516,8 @@ static void mroute_read(struct thread *t) /* Keep reading */ done: mroute_read_on(pim); + + return; } static void mroute_read_on(struct pim_instance *pim) @@ -745,8 +537,11 @@ int pim_mroute_socket_enable(struct pim_instance *pim) frr_with_privs(&pimd_privs) { +#if PIM_IPV == 4 fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); - +#else + fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); +#endif if (fd < 0) { zlog_warn("Could not create mroute socket: errno=%d: %s", errno, @@ -814,7 +609,7 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, unsigned char flags) { struct pim_interface *pim_ifp = ifp->info; - struct vifctl vc; + pim_vifctl vc; int err; if (PIM_DEBUG_MROUTE) @@ -823,9 +618,10 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, pim_ifp->pim->vrf->name); memset(&vc, 0, sizeof(vc)); - vc.vifc_vifi = pim_ifp->mroute_vif_index; + vc.vc_vifi = pim_ifp->mroute_vif_index; +#if PIM_IPV == 4 #ifdef VIFF_USE_IFINDEX - vc.vifc_lcl_ifindex = ifp->ifindex; + vc.vc_lcl_ifindex = ifp->ifindex; #else if (ifaddr.s_addr == INADDR_ANY) { zlog_warn( @@ -833,24 +629,29 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, __func__); return -1; } - memcpy(&vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vifc_lcl_addr)); + memcpy(&vc.vc_lcl_addr, &ifaddr, sizeof(vc.vc_lcl_addr)); +#endif +#else + vc.vc_pifi = ifp->ifindex; #endif - vc.vifc_flags = flags; - vc.vifc_threshold = PIM_MROUTE_MIN_TTL; - vc.vifc_rate_limit = 0; + vc.vc_flags = flags; + vc.vc_threshold = PIM_MROUTE_MIN_TTL; + vc.vc_rate_limit = 0; +#if PIM_IPV == 4 #ifdef PIM_DVMRP_TUNNEL - if (vc.vifc_flags & VIFF_TUNNEL) { - memcpy(&vc.vifc_rmt_addr, &vif_remote_addr, - sizeof(vc.vifc_rmt_addr)); + if (vc.vc_flags & VIFF_TUNNEL) { + memcpy(&vc.vc_rmt_addr, &vif_remote_addr, + sizeof(vc.vc_rmt_addr)); } #endif +#endif - err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_ADD_VIF, + err = setsockopt(pim_ifp->pim->mroute_socket, PIM_IPPROTO, MRT_ADD_VIF, (void *)&vc, sizeof(vc)); if (err) { zlog_warn( - "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%pPAs,flag=%d): errno=%d: %s", + "%s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_ADD_VIF,vif_index=%d,ifaddr=%pPAs,flag=%d): errno=%d: %s", __func__, pim_ifp->pim->mroute_socket, ifp->ifindex, &ifaddr, flags, errno, safe_strerror(errno)); return -2; @@ -862,7 +663,7 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, int pim_mroute_del_vif(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; - struct vifctl vc; + pim_vifctl vc; int err; if (PIM_DEBUG_MROUTE) @@ -871,13 +672,13 @@ int pim_mroute_del_vif(struct interface *ifp) pim_ifp->pim->vrf->name); memset(&vc, 0, sizeof(vc)); - vc.vifc_vifi = pim_ifp->mroute_vif_index; + vc.vc_vifi = pim_ifp->mroute_vif_index; - err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_DEL_VIF, + err = setsockopt(pim_ifp->pim->mroute_socket, PIM_IPPROTO, MRT_DEL_VIF, (void *)&vc, sizeof(vc)); if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", __FILE__, __func__, pim_ifp->pim->mroute_socket, pim_ifp->mroute_vif_index, errno, safe_strerror(errno)); return -2; @@ -985,20 +786,21 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) && *oil_parent(c_oil) != 0) { *oil_parent(tmp_oil) = 0; } - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, + /* For IPv6 MRT_ADD_MFC is defined to MRT6_ADD_MFC */ + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); if (!err && !c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) && *oil_parent(c_oil) != 0) { *oil_parent(tmp_oil) = *oil_parent(c_oil); - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); } if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_MFC): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_ADD_MFC): errno=%d: %s", __FILE__, __func__, pim->mroute_socket, errno, safe_strerror(errno)); return -2; @@ -1174,12 +976,12 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) return -2; } - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_DEL_MFC, + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_DEL_MFC, &c_oil->oil, sizeof(c_oil->oil)); if (err) { if (PIM_DEBUG_MROUTE) zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_MFC): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_DEL_MFC): errno=%d: %s", __FILE__, __func__, pim->mroute_socket, errno, safe_strerror(errno)); return -2; @@ -1201,6 +1003,7 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) void pim_mroute_update_counters(struct channel_oil *c_oil) { struct pim_instance *pim = c_oil->pim; + pim_sioc_sg_req sgreq; c_oil->cc.oldpktcnt = c_oil->cc.pktcnt; c_oil->cc.oldbytecnt = c_oil->cc.bytecnt; @@ -1219,29 +1022,33 @@ void pim_mroute_update_counters(struct channel_oil *c_oil) return; } -#if PIM_IPV == 4 - struct sioc_sg_req sgreq; memset(&sgreq, 0, sizeof(sgreq)); + +#if PIM_IPV == 4 sgreq.src = *oil_origin(c_oil); sgreq.grp = *oil_mcastgrp(c_oil); - pim_zlookup_sg_statistics(c_oil); - if (ioctl(pim->mroute_socket, SIOCGETSGCNT, &sgreq)) { +#else + sgreq.src = c_oil->oil.mf6cc_origin; + sgreq.grp = c_oil->oil.mf6cc_mcastgrp; + /* TODO Zlookup_sg_statistics for V6 to be added */ +#endif + if (ioctl(pim->mroute_socket, PIM_SIOCGETSGCNT, &sgreq)) { pim_sgaddr sg; sg.src = *oil_origin(c_oil); sg.grp = *oil_mcastgrp(c_oil); - zlog_warn("ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=%pSG: errno=%d: %s", - (unsigned long)SIOCGETSGCNT, &sg, - errno, safe_strerror(errno)); + zlog_warn( + "ioctl(PIM_SIOCGETSGCNT=%lu) failure for (S,G)=%pSG: errno=%d: %s", + (unsigned long)PIM_SIOCGETSGCNT, &sg, errno, + safe_strerror(errno)); return; } c_oil->cc.pktcnt = sgreq.pktcnt; c_oil->cc.bytecnt = sgreq.bytecnt; c_oil->cc.wrong_if = sgreq.wrong_if; -#endif return; } diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h index 14b0a8ccaf..35ba60bf35 100644 --- a/pimd/pim_mroute.h +++ b/pimd/pim_mroute.h @@ -30,153 +30,107 @@ #define __EXTENSIONS__ #endif -#include <netinet/in.h> -#ifdef HAVE_NETINET_IP_MROUTE_H -#include <netinet/ip_mroute.h> -#endif #define PIM_MROUTE_MIN_TTL (1) #if PIM_IPV == 4 + +#include <netinet/in.h> #if defined(HAVE_LINUX_MROUTE_H) #include <linux/mroute.h> #else -/* - Below: from <linux/mroute.h> -*/ - -#ifndef MAXVIFS -#define MAXVIFS (256) +#ifndef VTYSH_EXTRACT_PL +#include "linux/mroute.h" #endif - -#ifndef SIOCGETVIFCNT -#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */ -#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1) -#define SIOCGETRPF (SIOCPROTOPRIVATE+2) #endif -#ifndef MRT_INIT -#define MRT_BASE 200 -#define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */ -#define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */ -#define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */ -#define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */ -#define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */ -#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */ -#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */ -#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */ -#define MRT_PIM (MRT_BASE+8) /* enable PIM code */ -#endif +typedef struct vifctl pim_vifctl; +typedef struct igmpmsg kernmsg; +typedef struct sioc_sg_req pim_sioc_sg_req; -#ifndef MRT_TABLE -#define MRT_TABLE (209) /* Specify mroute table ID */ -#endif +#define vc_vifi vifc_vifi +#define vc_flags vifc_flags +#define vc_threshold vifc_threshold +#define vc_rate_limit vifc_rate_limit +#define vc_lcl_addr vifc_lcl_addr +#define vc_lcl_ifindex vifc_lcl_ifindex +#define vc_rmt_addr vifc_rmt_addr -#ifndef HAVE_VIFI_T -typedef unsigned short vifi_t; -#endif +#define msg_im_vif im_vif +#define msg_im_src im_src +#define msg_im_dst im_dst -#ifndef HAVE_STRUCT_VIFCTL -struct vifctl { - vifi_t vifc_vifi; /* Index of VIF */ - unsigned char vifc_flags; /* VIFF_ flags */ - unsigned char vifc_threshold; /* ttl limit */ - unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ - struct in_addr vifc_lcl_addr; /* Our address */ - struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */ -}; +#ifndef IGMPMSG_WRVIFWHOLE +#define IGMPMSG_WRVIFWHOLE 4 /* For PIM processing */ #endif -#ifndef HAVE_STRUCT_MFCCTL -struct mfcctl { - struct in_addr mfcc_origin; /* Origin of mcast */ - struct in_addr mfcc_mcastgrp; /* Group in question */ - vifi_t mfcc_parent; /* Where it arrived */ - unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */ - unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */ - unsigned int mfcc_byte_cnt; - unsigned int mfcc_wrong_if; - int mfcc_expire; -}; +#ifndef PIM_IPPROTO +#define PIM_IPPROTO IPPROTO_IP +#endif +#ifndef PIM_SIOCGETSGCNT +#define PIM_SIOCGETSGCNT SIOCGETSGCNT #endif -/* - * Group count retrieval for mrouted - */ -/* - struct sioc_sg_req sgreq; - memset(&sgreq, 0, sizeof(sgreq)); - memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src)); - memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp)); - ioctl(mrouter_s4, SIOCGETSGCNT, &sgreq); - */ -#ifndef HAVE_STRUCT_SIOC_SG_REQ -struct sioc_sg_req { - struct in_addr src; - struct in_addr grp; - unsigned long pktcnt; - unsigned long bytecnt; - unsigned long wrong_if; -}; +#else /* PIM_IPV != 4 */ + +#include <netinet/ip6.h> + +#if defined(HAVE_LINUX_MROUTE6_H) +#include <linux/mroute6.h> +#else +#ifndef VTYSH_EXTRACT_PL +#include "linux/mroute6.h" +#endif #endif -/* - * To get vif packet counts - */ -/* - struct sioc_vif_req vreq; - memset(&vreq, 0, sizeof(vreq)); - vreq.vifi = vif_index; - ioctl(mrouter_s4, SIOCGETVIFCNT, &vreq); - */ -#ifndef HAVE_STRUCT_SIOC_VIF_REQ -struct sioc_vif_req { - vifi_t vifi; /* Which iface */ - unsigned long icount; /* In packets */ - unsigned long ocount; /* Out packets */ - unsigned long ibytes; /* In bytes */ - unsigned long obytes; /* Out bytes */ -}; +#ifndef MRT_INIT +#define MRT_BASE MRT6_BASE +#define MRT_INIT MRT6_INIT +#define MRT_DONE MRT6_DONE +#define MRT_ADD_VIF MRT6_ADD_MIF +#define MRT_DEL_VIF MRT6_DEL_MIF +#define MRT_ADD_MFC MRT6_ADD_MFC +#define MRT_DEL_MFC MRT6_DEL_MFC +#define MRT_VERSION MRT6_VERSION +#define MRT_ASSERT MRT6_ASSERT +#define MRT_PIM MRT6_PIM #endif -/* - * Pseudo messages used by mrouted - */ -#ifndef IGMPMSG_NOCACHE -#define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */ -#define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */ -#define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */ +#ifndef PIM_IPPROTO +#define PIM_IPPROTO IPPROTO_IPV6 #endif -#ifndef HAVE_STRUCT_IGMPMSG -struct igmpmsg { - uint32_t unused1, unused2; - unsigned char im_msgtype; /* What is this */ - unsigned char im_mbz; /* Must be zero */ - unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */ - unsigned char unused3; - struct in_addr im_src, im_dst; -}; +#ifndef PIM_SIOCGETSGCNT +#define PIM_SIOCGETSGCNT SIOCGETSGCNT_IN6 #endif -#endif /* HAVE_LINUX_MROUTE_H */ +#ifndef MRT6MSG_WRMIFWHOLE +#define MRT6MSG_WRMIFWHOLE 4 /* For PIM processing */ +#endif -typedef struct mfcctl pim_mfcctl; +typedef struct mif6ctl pim_vifctl; +typedef struct mrt6msg kernmsg; +typedef mifi_t vifi_t; +typedef struct sioc_sg_req6 pim_sioc_sg_req; -#else /* PIM_IPV != 4 */ -#if defined(HAVE_LINUX_MROUTE6_H) -#include <linux/mroute6.h> -#endif +#define vc_vifi mif6c_mifi +#define vc_flags mif6c_flags +#define vc_threshold vifc_threshold +#define vc_pifi mif6c_pifi +#define vc_rate_limit vifc_rate_limit -typedef struct mf6cctl pim_mfcctl; +#define msg_im_vif im6_mif +#define msg_im_src im6_src +#define msg_im_dst im6_dst +#ifndef MAXVIFS #define MAXVIFS IF_SETSIZE #endif -#ifndef IGMPMSG_WRVIFWHOLE -#define IGMPMSG_WRVIFWHOLE 4 /* For PIM processing */ +#define VIFF_REGISTER MIFF_REGISTER #endif + /* Above: from <linux/mroute.h> */ @@ -201,4 +155,11 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name); void pim_mroute_update_counters(struct channel_oil *c_oil); bool pim_mroute_allow_iif_in_oil(struct channel_oil *c_oil, int oif_index); +int pim_mroute_msg(struct pim_instance *pim, const char *buf, size_t buf_size, + ifindex_t ifindex); +int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg); +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf); +int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg); +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf); +int pim_mroute_set(struct pim_instance *pim, int enable); #endif /* PIM_MROUTE_H */ diff --git a/pimd/pim_mroute_msg.c b/pimd/pim_mroute_msg.c new file mode 100644 index 0000000000..7d80488c68 --- /dev/null +++ b/pimd/pim_mroute_msg.c @@ -0,0 +1,239 @@ +/* + * PIM for Quagga + * Copyright (C) 2022 Dell Technologies Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> +#include "log.h" +#include "privs.h" +#include "if.h" +#include "prefix.h" +#include "vty.h" +#include "plist.h" +#include "sockopt.h" +#include "lib_errors.h" +#include "lib/network.h" + +#include "pimd.h" +#include "pim_mroute.h" +#include "pim_oil.h" +#include "pim_str.h" +#include "pim_iface.h" +#include "pim_macro.h" +#include "pim_rp.h" +#include "pim_oil.h" +#include "pim_msg.h" +#include "pim_sock.h" + + +int pim_mroute_set(struct pim_instance *pim, int enable) +{ + int err; + int opt, data; + socklen_t data_len = sizeof(data); + + /* + * We need to create the VRF table for the pim mroute_socket + */ + if (pim->vrf->vrf_id != VRF_DEFAULT) { + frr_with_privs(&pimd_privs) { + + data = pim->vrf->data.l.table_id; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, + MRT_TABLE, &data, data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO, MRT_TABLE=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + data, errno, safe_strerror(errno)); + return -1; + } + + } + } + + frr_with_privs(&pimd_privs) { + opt = enable ? MRT_INIT : MRT_DONE; + /* + * *BSD *cares* about what value we pass down + * here + */ + data = 1; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &data, + data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,%s=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + enable ? "MRT_INIT" : "MRT_DONE", data, errno, + safe_strerror(errno)); + return -1; + } + } + +#if defined(HAVE_IP_PKTINFO) + if (enable) { + /* Linux and Solaris IP_PKTINFO */ + data = 1; + if (setsockopt(pim->mroute_socket, PIM_IPPROTO, IP_PKTINFO, + &data, data_len)) { + zlog_warn( + "Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + } +#endif + + setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); + + if (set_nonblocking (pim->mroute_socket) < 0) { + zlog_warn( + "Could not set non blocking on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + + if (enable) { +#if defined linux + int upcalls = IGMPMSG_WRVIFWHOLE; + opt = MRT_PIM; + + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &upcalls, + sizeof(upcalls)); + if (err) { + zlog_warn( + "Failure to register for VIFWHOLE and WRONGVIF upcalls %d %s", + errno, safe_strerror(errno)); + return -1; + } +#else + zlog_warn( + "PIM-SM will not work properly on this platform, until the ability to receive the WRVIFWHOLE upcall"); +#endif + + } + + return 0; +} + +static const char *const igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { + "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; + + +int pim_mroute_msg(struct pim_instance *pim, const char *buf, + size_t buf_size, ifindex_t ifindex) +{ + struct interface *ifp; + const struct ip *ip_hdr; + const struct igmpmsg *msg; + + if (buf_size < (int)sizeof(struct ip)) + return 0; + + ip_hdr = (const struct ip *)buf; + + if (ip_hdr->ip_p == IPPROTO_IGMP) { + struct pim_interface *pim_ifp; + struct in_addr ifaddr; + struct gm_sock *igmp; + const struct prefix *connected_src; + + /* We have the IP packet but we do not know which interface this + * packet was + * received on. Find the interface that is on the same subnet as + * the source + * of the IP packet. + */ + ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id); + + if (!ifp || !ifp->info) + return 0; + + connected_src = pim_if_connected_to_source(ifp, ip_hdr->ip_src); + + if (!connected_src) { + if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "Recv IGMP packet on interface: %s from a non-connected source: %pI4", + ifp->name, &ip_hdr->ip_src); + } + return 0; + } + + pim_ifp = ifp->info; + ifaddr = connected_src->u.prefix4; + igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->gm_socket_list, + ifaddr); + + if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "%s(%s): igmp kernel upcall on %s(%p) for %pI4 -> %pI4", + __func__, pim->vrf->name, ifp->name, igmp, + &ip_hdr->ip_src, &ip_hdr->ip_dst); + } + if (igmp) + pim_igmp_packet(igmp, (char *)buf, buf_size); + else if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "No IGMP socket on interface: %s with connected source: %pFX", + ifp->name, connected_src); + } + } else if (ip_hdr->ip_p) { + if (PIM_DEBUG_MROUTE_DETAIL) { + zlog_debug( + "%s: no kernel upcall proto=%d src: %pI4 dst: %pI4 msg_size=%ld", + __func__, ip_hdr->ip_p, &ip_hdr->ip_src, + &ip_hdr->ip_dst, (long int)buf_size); + } + + } else { + msg = (const struct igmpmsg *)buf; + + ifp = pim_if_find_by_vif_index(pim, msg->im_vif); + + if (!ifp) + return 0; + if (PIM_DEBUG_MROUTE) { + zlog_debug( + "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI4,%pI4) on %s vifi=%d size=%ld", + __func__, igmpmsgtype2str[msg->im_msgtype], + msg->im_msgtype, ip_hdr->ip_p, + pim->mroute_socket, &msg->im_src, &msg->im_dst, + ifp->name, msg->im_vif, (long int)buf_size); + } + + switch (msg->im_msgtype) { + case IGMPMSG_WRONGVIF: + return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, + msg); + case IGMPMSG_NOCACHE: + return pim_mroute_msg_nocache(pim->mroute_socket, ifp, + msg); + case IGMPMSG_WHOLEPKT: + return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, + (const char *)msg); + case IGMPMSG_WRVIFWHOLE: + return pim_mroute_msg_wrvifwhole( + pim->mroute_socket, ifp, (const char *)msg); + default: + break; + } + } + + return 0; +} diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index a0653e1a57..1eda51417f 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -38,10 +38,36 @@ #include "pim_jp_agg.h" #include "pim_oil.h" -void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type, bool no_fwd) +void pim_msg_build_header(pim_addr src, pim_addr dst, uint8_t *pim_msg, + size_t pim_msg_size, uint8_t pim_msg_type, + bool no_fwd) { struct pim_msg_header *header = (struct pim_msg_header *)pim_msg; + struct iovec iov[2], *iovp = iov; + + /* + * The checksum for Registers is done only on the first 8 bytes of the + * packet, including the PIM header and the next 4 bytes, excluding the + * data packet portion + * + * for IPv6, the pseudoheader upper-level protocol length is also + * truncated, so let's just set it here before everything else. + */ + if (pim_msg_type == PIM_MSG_TYPE_REGISTER) + pim_msg_size = PIM_MSG_REGISTER_LEN; + +#if PIM_IPV == 6 + struct ipv6_ph phdr = { + .src = src, + .dst = dst, + .ulpl = htonl(pim_msg_size), + .next_hdr = IPPROTO_PIM, + }; + + iovp->iov_base = &phdr; + iovp->iov_len = sizeof(phdr); + iovp++; +#endif /* * Write header @@ -51,18 +77,12 @@ void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, header->Nbit = no_fwd; header->reserved = 0; - header->checksum = 0; - /* - * The checksum for Registers is done only on the first 8 bytes of the - * packet, - * including the PIM header and the next 4 bytes, excluding the data - * packet portion - */ - if (pim_msg_type == PIM_MSG_TYPE_REGISTER) - header->checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN); - else - header->checksum = in_cksum(pim_msg, pim_msg_size); + iovp->iov_base = header; + iovp->iov_len = pim_msg_size; + iovp++; + + header->checksum = in_cksumv(iov, iovp - iov); } uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr) diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index 456c356d9f..733210af3a 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -161,10 +161,18 @@ struct pim_encoded_source_ipv6 { typedef struct pim_encoded_ipv4_unicast pim_encoded_unicast; typedef struct pim_encoded_group_ipv4 pim_encoded_group; typedef struct pim_encoded_source_ipv4 pim_encoded_source; +typedef struct ip ipv_hdr; +#define IPV_SRC(ip_hdr) ((ip_hdr))->ip_src +#define IPV_DST(ip_hdr) ((ip_hdr))->ip_dst +#define IPV_LEN(ip_hdr) ((ip_hdr))->ip_len #else typedef struct pim_encoded_ipv6_unicast pim_encoded_unicast; typedef struct pim_encoded_group_ipv6 pim_encoded_group; typedef struct pim_encoded_source_ipv6 pim_encoded_source; +typedef struct ip6_hdr ipv_hdr; +#define IPV_SRC(ip_hdr) ((ip_hdr))->ip6_src +#define IPV_DST(ip_hdr) ((ip_hdr))->ip6_dst +#define IPV_LEN(ip_hdr) ((ip_hdr))->ip6_plen #endif /* clang-format on */ @@ -208,8 +216,9 @@ static inline pim_sgaddr pim_sgaddr_from_iphdr(const void *iphdr) } #endif -void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type, bool no_fwd); +void pim_msg_build_header(pim_addr src, pim_addr dst, uint8_t *pim_msg, + size_t pim_msg_size, uint8_t pim_msg_type, + bool no_fwd); uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr); uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, struct in_addr addr); diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 753857005a..94dcfb8265 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -55,7 +55,7 @@ void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, int ret; p = &(pnc->rpf.rpf_addr); - ret = zclient_send_rnh(zclient, command, p, false, false, + ret = zclient_send_rnh(zclient, command, p, SAFI_UNICAST, false, false, pim->vrf->vrf_id); if (ret == ZCLIENT_SEND_FAILURE) zlog_warn("sendmsg_nexthop: zclient_send_message() failed"); diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index d5e459b44e..5b5cc2c103 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -544,20 +544,27 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, int pim_channel_oil_empty(struct channel_oil *c_oil) { +#if PIM_IPV == 4 + static struct mfcctl null_oil; +#else + static struct mf6cctl null_oil; +#endif + if (!c_oil) return 1; + /* exclude pimreg from the OIL when checking if the inherited_oil is * non-NULL. * pimreg device (in all vrfs) uses a vifi of * 0 (PIM_OIF_PIM_REGISTER_VIF) so we simply mfcc_ttls[0] */ + if (oil_if_has(c_oil, 0)) { #if PIM_IPV == 4 - static pim_mfcctl null_oil; - - return !memcmp(&c_oil->oil.mfcc_ttls[1], &null_oil.mfcc_ttls[1], - sizeof(null_oil.mfcc_ttls) - sizeof(null_oil.mfcc_ttls[0])); + null_oil.mfcc_ttls[0] = 1; #else - CPP_NOTICE("FIXME STUB"); - return false; + IF_SET(0, &null_oil.mf6cc_ifset); #endif + } + + return !oil_if_cmp(&c_oil->oil, &null_oil); } diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h index a52e23351e..68b5ef474e 100644 --- a/pimd/pim_oil.h +++ b/pimd/pim_oil.h @@ -98,7 +98,11 @@ struct channel_oil { struct rb_pim_oil_item oil_rb; - pim_mfcctl oil; +#if PIM_IPV == 4 + struct mfcctl oil; +#else + struct mf6cctl oil; +#endif int installed; int oil_inherited_rescan; int oil_size; @@ -135,6 +139,12 @@ static inline void oil_if_set(struct channel_oil *c_oil, vifi_t ifi, uint8_t set { c_oil->oil.mfcc_ttls[ifi] = set; } + +static inline int oil_if_cmp(struct mfcctl *oil1, struct mfcctl *oil2) +{ + return memcmp(&oil1->mfcc_ttls[0], &oil2->mfcc_ttls[0], + sizeof(oil1->mfcc_ttls)); +} #else static inline pim_addr *oil_origin(struct channel_oil *c_oil) { @@ -163,6 +173,12 @@ static inline void oil_if_set(struct channel_oil *c_oil, mifi_t ifi, bool set) else IF_CLR(ifi, &c_oil->oil.mf6cc_ifset); } + +static inline int oil_if_cmp(struct mf6cctl *oil1, struct mf6cctl *oil2) +{ + return memcmp(&oil1->mf6cc_ifset, &oil2->mf6cc_ifset, + sizeof(oil1->mf6cc_ifset)); +} #endif extern int pim_channel_oil_compare(const struct channel_oil *c1, diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 82f735465a..50bbc0fe18 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -152,6 +152,7 @@ static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, pim_addr addr) int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, pim_sgaddr sg) { + struct iovec iov[2], *iovp = iov; #if PIM_IPV == 4 struct ip *ip_hdr = (struct ip *)buf; size_t ip_hlen; /* ip header length in bytes */ @@ -179,11 +180,26 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, pim_msg = buf + ip_hlen; pim_msg_len = len - ip_hlen; #else + struct ipv6_ph phdr = { + .src = sg.src, + .dst = sg.grp, + .ulpl = htonl(len), + .next_hdr = IPPROTO_PIM, + }; + + iovp->iov_base = &phdr; + iovp->iov_len = sizeof(phdr); + iovp++; + /* NB: header is not included in IPv6 RX */ pim_msg = buf; pim_msg_len = len; #endif + iovp->iov_base = pim_msg; + iovp->iov_len = pim_msg_len; + iovp++; + header = (struct pim_msg_header *)pim_msg; if (pim_msg_len < PIM_PIM_MIN_LEN) { if (PIM_DEBUG_PIM_PACKETS) @@ -215,10 +231,21 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, pim_msg_len, PIM_MSG_REGISTER_LEN); return -1; } + +#if PIM_IPV == 6 + phdr.ulpl = htonl(PIM_MSG_REGISTER_LEN); +#endif /* First 8 byte header checksum */ - checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN); + iovp[-1].iov_len = PIM_MSG_REGISTER_LEN; + checksum = in_cksumv(iov, iovp - iov); + if (checksum != pim_checksum) { - checksum = in_cksum(pim_msg, pim_msg_len); +#if PIM_IPV == 6 + phdr.ulpl = htonl(pim_msg_len); +#endif + iovp[-1].iov_len = pim_msg_len; + + checksum = in_cksumv(iov, iovp - iov); if (checksum != pim_checksum) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -230,7 +257,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, } } } else { - checksum = in_cksum(pim_msg, pim_msg_len); + checksum = in_cksumv(iov, iovp - iov); if (checksum != pim_checksum) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -522,75 +549,62 @@ void pim_sock_reset(struct interface *ifp) pim_ifstat_reset(ifp); } +#if PIM_IPV == 4 static uint16_t ip_id = 0; - +#endif static int pim_msg_send_frame(int fd, char *buf, size_t len, struct sockaddr *dst, size_t salen, const char *ifname) { - struct ip *ip = (struct ip *)buf; - - if (sendto(fd, buf, len, MSG_DONTWAIT, dst, salen) < 0) { - char dst_str[INET_ADDRSTRLEN]; - - switch (errno) { - case EMSGSIZE: { - size_t hdrsize = sizeof(struct ip); - size_t newlen1 = ((len - hdrsize) / 2) & 0xFFF8; - size_t sendlen = newlen1 + hdrsize; - size_t offset = ntohs(ip->ip_off); - - ip->ip_len = htons(sendlen); - ip->ip_off = htons(offset | IP_MF); - if (pim_msg_send_frame(fd, buf, sendlen, dst, salen, - ifname) == 0) { - struct ip *ip2 = (struct ip *)(buf + newlen1); - size_t newlen2 = len - sendlen; - sendlen = newlen2 + hdrsize; - - memcpy(ip2, ip, hdrsize); - ip2->ip_len = htons(sendlen); - ip2->ip_off = htons(offset + (newlen1 >> 3)); - return pim_msg_send_frame(fd, (char *)ip2, - sendlen, dst, salen, - ifname); - } - } + if (sendto(fd, buf, len, MSG_DONTWAIT, dst, salen) >= 0) + return 0; - return -1; - default: - if (PIM_DEBUG_PIM_PACKETS) { - pim_inet4_dump("<dst?>", ip->ip_dst, dst_str, - sizeof(dst_str)); - zlog_warn( - "%s: sendto() failure to %s: iface=%s fd=%d msg_size=%zd: errno=%d: %s", - __func__, dst_str, ifname, fd, len, - errno, safe_strerror(errno)); - } - return -1; - } +#if PIM_IPV == 4 + if (errno == EMSGSIZE) { + struct ip *ip = (struct ip *)buf; + size_t hdrsize = sizeof(struct ip); + size_t newlen1 = ((len - hdrsize) / 2) & 0xFFF8; + size_t sendlen = newlen1 + hdrsize; + size_t offset = ntohs(ip->ip_off); + int ret; + + ip->ip_len = htons(sendlen); + ip->ip_off = htons(offset | IP_MF); + + ret = pim_msg_send_frame(fd, buf, sendlen, dst, salen, ifname); + if (ret) + return ret; + + struct ip *ip2 = (struct ip *)(buf + newlen1); + size_t newlen2 = len - sendlen; + + sendlen = newlen2 + hdrsize; + + memcpy(ip2, ip, hdrsize); + ip2->ip_len = htons(sendlen); + ip2->ip_off = htons(offset + (newlen1 >> 3)); + return pim_msg_send_frame(fd, (char *)ip2, sendlen, dst, salen, + ifname); } +#endif - return 0; + zlog_warn( + "%s: sendto() failure to %pSU: iface=%s fd=%d msg_size=%zd: %m", + __func__, dst, ifname, fd, len); + return -1; } int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname) { - struct sockaddr_in to; socklen_t tolen; unsigned char buffer[10000]; unsigned char *msg_start; uint8_t ttl; struct pim_msg_header *header; - struct ip *ip; memset(buffer, 0, 10000); - int sendlen = sizeof(struct ip) + pim_msg_size; - - msg_start = buffer + sizeof(struct ip); - memcpy(msg_start, pim_msg, pim_msg_size); header = (struct pim_msg_header *)pim_msg; /* @@ -620,7 +634,11 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, break; } - ip = (struct ip *)buffer; +#if PIM_IPV == 4 + struct ip *ip = (struct ip *)buffer; + struct sockaddr_in to = {}; + int sendlen = sizeof(*ip) + pim_msg_size; + ip->ip_id = htons(++ip_id); ip->ip_hl = 5; ip->ip_v = 4; @@ -631,17 +649,34 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, ip->ip_ttl = ttl; ip->ip_len = htons(sendlen); - if (PIM_DEBUG_PIM_PACKETS) { - char dst_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str)); - zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", __func__, - dst_str, ifname, pim_msg_size, header->checksum); - } - - memset(&to, 0, sizeof(to)); to.sin_family = AF_INET; to.sin_addr = dst; tolen = sizeof(to); +#else + struct ip6_hdr *ip = (struct ip6_hdr *)buffer; + struct sockaddr_in6 to = {}; + int sendlen = sizeof(*ip) + pim_msg_size; + + ip->ip6_flow = 0; + ip->ip6_vfc = (6 << 4) | (IPTOS_PREC_INTERNETCONTROL >> 4); + ip->ip6_plen = htons(pim_msg_size); + ip->ip6_nxt = PIM_IP_PROTO_PIM; + ip->ip6_hlim = ttl; + ip->ip6_src = src; + ip->ip6_dst = dst; + + to.sin6_family = AF_INET6; + to.sin6_addr = dst; + tolen = sizeof(to); +#endif + + msg_start = buffer + sizeof(*ip); + memcpy(msg_start, pim_msg, pim_msg_size); + + if (PIM_DEBUG_PIM_PACKETS) + zlog_debug("%s: to %pPA on %s: msg_size=%d checksum=%x", + __func__, &dst, ifname, pim_msg_size, + header->checksum); if (PIM_DEBUG_PIM_PACKETDUMP_SEND) { pim_pkt_dump(__func__, pim_msg, pim_msg_size); @@ -661,20 +696,16 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) pim_ifp = ifp->info; - if (PIM_DEBUG_PIM_HELLO) { - char dst_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr, dst_str, - sizeof(dst_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", - __func__, dst_str, ifp->name, holdtime, - pim_ifp->pim_propagation_delay_msec, + "%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", + __func__, &qpim_all_pim_routers_addr, ifp->name, + holdtime, pim_ifp->pim_propagation_delay_msec, pim_ifp->pim_override_interval_msec, PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPPRESSION( pim_ifp->options), pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id, listcount(ifp->connected)); - } pim_tlv_size = pim_hello_build_tlv( ifp, pim_msg + PIM_PIM_MIN_LEN, @@ -692,7 +723,9 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) assert(pim_msg_size >= PIM_PIM_MIN_LEN); assert(pim_msg_size <= PIM_PIM_BUFSIZE_WRITE); - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_HELLO, false); + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, pim_msg_size, + PIM_MSG_TYPE_HELLO, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, qpim_all_pim_routers_addr, pim_msg, pim_msg_size, diff --git a/pimd/pim_register.c b/pimd/pim_register.c index 7fa36e5a44..45bcad3c26 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -88,7 +88,8 @@ void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, length = pim_encode_addr_ucast(b1, sg->src); b1length += length; - pim_msg_build_header(buffer, b1length + PIM_MSG_REGISTER_STOP_LEN, + pim_msg_build_header(src, originator, buffer, + b1length + PIM_MSG_REGISTER_STOP_LEN, PIM_MSG_TYPE_REG_STOP, false); pinfo = (struct pim_interface *)ifp->info; @@ -261,7 +262,8 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, memcpy(b1, (const unsigned char *)buf, buf_size); - pim_msg_build_header(buffer, buf_size + PIM_MSG_REGISTER_LEN, + pim_msg_build_header(src, rpg->rpf_addr.u.prefix4, buffer, + buf_size + PIM_MSG_REGISTER_LEN, PIM_MSG_TYPE_REGISTER, false); ++pinfo->pim_ifstat_reg_send; diff --git a/pimd/pim_register.h b/pimd/pim_register.h index 0ebef40c58..79c64d995f 100644 --- a/pimd/pim_register.h +++ b/pimd/pim_register.h @@ -35,11 +35,11 @@ int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size); int pim_register_recv(struct interface *ifp, pim_addr dest_addr, pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size); -void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, +void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src, struct pim_rpf *rpg, int null_register, struct pim_upstream *up); -void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, - struct in_addr src, struct in_addr originator); +void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src, + pim_addr originator); void pim_register_join(struct pim_upstream *up); void pim_null_register_send(struct pim_upstream *up); void pim_reg_del_on_couldreg_fail(struct interface *ifp); diff --git a/pimd/subdir.am b/pimd/subdir.am index cda5acb004..ba7bdb3493 100644 --- a/pimd/subdir.am +++ b/pimd/subdir.am @@ -39,6 +39,7 @@ pim_common = \ pimd/pim_neighbor.c \ pimd/pim_nht.c \ pimd/pim_oil.c \ + pimd/pim_pim.c \ pimd/pim_routemap.c \ pimd/pim_rp.c \ pimd/pim_rpf.c \ @@ -72,11 +73,11 @@ pimd_pimd_SOURCES = \ pimd/pim_msdp.c \ pimd/pim_msdp_packet.c \ pimd/pim_msdp_socket.c \ - pimd/pim_pim.c \ pimd/pim_register.c \ pimd/pim_signals.c \ pimd/pim_zlookup.c \ pimd/pim_zpthread.c \ + pimd/pim_mroute_msg.c \ # end nodist_pimd_pimd_SOURCES = \ @@ -90,6 +91,7 @@ pimd_pim6d_SOURCES = \ pimd/pim6_main.c \ pimd/pim6_stubs.c \ pimd/pim6_cmd.c \ + pimd/pim6_mroute_msg.c \ # end nodist_pimd_pim6d_SOURCES = \ diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 52364bff41..b40c2c6228 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -631,7 +631,8 @@ void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import, if (!watch) command = ZEBRA_NEXTHOP_UNREGISTER; - if (zclient_send_rnh(zclient, command, p, connected, false, vrf_id) + if (zclient_send_rnh(zclient, command, p, SAFI_UNICAST, connected, + false, vrf_id) == ZCLIENT_SEND_FAILURE) zlog_warn("%s: Failure to send nexthop to zebra", __func__); } diff --git a/staticd/static_nht.c b/staticd/static_nht.c index e1d6ba15d1..1d87a83c91 100644 --- a/staticd/static_nht.c +++ b/staticd/static_nht.c @@ -101,18 +101,15 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp, } } -void static_nht_update(struct prefix *sp, struct prefix *nhp, - uint32_t nh_num, afi_t afi, vrf_id_t nh_vrf_id) +void static_nht_update(struct prefix *sp, struct prefix *nhp, uint32_t nh_num, + afi_t afi, safi_t safi, vrf_id_t nh_vrf_id) { struct vrf *vrf; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_UNICAST, - vrf, nh_vrf_id); - static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_MULTICAST, - vrf, nh_vrf_id); - } + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + static_nht_update_safi(sp, nhp, nh_num, afi, safi, vrf, + nh_vrf_id); } static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi, @@ -166,16 +163,13 @@ static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi, } } -void static_nht_reset_start(struct prefix *nhp, afi_t afi, vrf_id_t nh_vrf_id) +void static_nht_reset_start(struct prefix *nhp, afi_t afi, safi_t safi, + vrf_id_t nh_vrf_id) { struct vrf *vrf; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - static_nht_reset_start_safi(nhp, afi, SAFI_UNICAST, - vrf, nh_vrf_id); - static_nht_reset_start_safi(nhp, afi, SAFI_MULTICAST, - vrf, nh_vrf_id); - } + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + static_nht_reset_start_safi(nhp, afi, safi, vrf, nh_vrf_id); } static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi, @@ -212,7 +206,7 @@ static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi, route_unlock_node(rn); } -void static_nht_mark_state(struct prefix *sp, vrf_id_t vrf_id, +void static_nht_mark_state(struct prefix *sp, safi_t safi, vrf_id_t vrf_id, enum static_install_states state) { struct vrf *vrf; @@ -226,6 +220,5 @@ void static_nht_mark_state(struct prefix *sp, vrf_id_t vrf_id, if (!vrf || !vrf->info) return; - static_nht_mark_state_safi(sp, afi, SAFI_UNICAST, vrf, state); - static_nht_mark_state_safi(sp, afi, SAFI_MULTICAST, vrf, state); + static_nht_mark_state_safi(sp, afi, safi, vrf, state); } diff --git a/staticd/static_nht.h b/staticd/static_nht.h index 08dba2ebb5..c29acc32ef 100644 --- a/staticd/static_nht.h +++ b/staticd/static_nht.h @@ -37,19 +37,21 @@ extern "C" { * vrf_id -> The vrf the nexthop is in. */ extern void static_nht_update(struct prefix *sp, struct prefix *nhp, - uint32_t nh_num, afi_t afi, vrf_id_t vrf_id); + uint32_t nh_num, afi_t afi, safi_t safi, + vrf_id_t vrf_id); /* * For the given tracked nexthop, nhp, mark all routes that use * this route as in starting state again. */ -extern void static_nht_reset_start(struct prefix *nhp, afi_t afi, +extern void static_nht_reset_start(struct prefix *nhp, afi_t afi, safi_t safi, vrf_id_t nh_vrf_id); /* * For the given prefix, sp, mark it as in a particular state */ -extern void static_nht_mark_state(struct prefix *sp, vrf_id_t vrf_id, +extern void static_nht_mark_state(struct prefix *sp, safi_t safi, + vrf_id_t vrf_id, enum static_install_states state); /* diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index bd293edebc..af153b4bc3 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -44,9 +44,47 @@ #include "static_vty.h" #include "static_debug.h" +DEFINE_MTYPE_STATIC(STATIC, STATIC_NHT_DATA, "Static Nexthop tracking data"); +PREDECL_HASH(static_nht_hash); + +struct static_nht_data { + struct static_nht_hash_item itm; + + struct prefix nh; + safi_t safi; + + vrf_id_t nh_vrf_id; + + uint32_t refcount; + uint8_t nh_num; +}; + +static int static_nht_data_cmp(const struct static_nht_data *nhtd1, + const struct static_nht_data *nhtd2) +{ + if (nhtd1->nh_vrf_id != nhtd2->nh_vrf_id) + return numcmp(nhtd1->nh_vrf_id, nhtd2->nh_vrf_id); + if (nhtd1->safi != nhtd2->safi) + return numcmp(nhtd1->safi, nhtd2->safi); + + return prefix_cmp(&nhtd1->nh, &nhtd2->nh); +} + +static unsigned int static_nht_data_hash(const struct static_nht_data *nhtd) +{ + unsigned int key = 0; + + key = prefix_hash_key(&nhtd->nh); + return jhash_2words(nhtd->nh_vrf_id, nhtd->safi, key); +} + +DECLARE_HASH(static_nht_hash, struct static_nht_data, itm, static_nht_data_cmp, + static_nht_data_hash); + +static struct static_nht_hash_head static_nht_hash[1]; + /* Zebra structure to hold current status. */ struct zclient *zclient; -static struct hash *static_nht_hash; uint32_t zebra_ecmp_count = MULTIPATH_NUM; /* Inteface addition message from zebra. */ @@ -104,31 +142,32 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) struct prefix p; enum zapi_route_notify_owner note; uint32_t table_id; + safi_t safi; - if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, ¬e, - NULL, NULL)) + if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, ¬e, NULL, + &safi)) return -1; switch (note) { case ZAPI_ROUTE_FAIL_INSTALL: - static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED); zlog_warn("%s: Route %pFX failed to install for table: %u", __func__, &p, table_id); break; case ZAPI_ROUTE_BETTER_ADMIN_WON: - static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED); zlog_warn( "%s: Route %pFX over-ridden by better route for table: %u", __func__, &p, table_id); break; case ZAPI_ROUTE_INSTALLED: - static_nht_mark_state(&p, vrf_id, STATIC_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED); break; case ZAPI_ROUTE_REMOVED: - static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED); break; case ZAPI_ROUTE_REMOVE_FAIL: - static_nht_mark_state(&p, vrf_id, STATIC_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED); zlog_warn("%s: Route %pFX failure to remove for table: %u", __func__, &p, table_id); break; @@ -141,15 +180,6 @@ static void zebra_connected(struct zclient *zclient) zclient_send_reg_requests(zclient, VRF_DEFAULT); } -struct static_nht_data { - struct prefix *nh; - - vrf_id_t nh_vrf_id; - - uint32_t refcount; - uint8_t nh_num; -}; - /* API to check whether the configured nexthop address is * one of its local connected address or not. */ @@ -187,17 +217,19 @@ static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS) } memset(&lookup, 0, sizeof(lookup)); - lookup.nh = &matched; + lookup.nh = matched; lookup.nh_vrf_id = vrf_id; + lookup.safi = nhr.safi; - nhtd = hash_lookup(static_nht_hash, &lookup); + nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (nhtd) { nhtd->nh_num = nhr.nexthop_num; - static_nht_reset_start(&matched, afi, nhtd->nh_vrf_id); + static_nht_reset_start(&matched, afi, nhr.safi, + nhtd->nh_vrf_id); static_nht_update(NULL, &matched, nhr.nexthop_num, afi, - nhtd->nh_vrf_id); + nhr.safi, nhtd->nh_vrf_id); } else zlog_err("No nhtd?"); @@ -210,55 +242,50 @@ static void static_zebra_capabilities(struct zclient_capabilities *cap) zebra_ecmp_count = cap->ecmp; } -static unsigned int static_nht_hash_key(const void *data) +static struct static_nht_data * +static_nht_hash_getref(const struct static_nht_data *ref) { - const struct static_nht_data *nhtd = data; - unsigned int key = 0; + struct static_nht_data *nhtd; - key = prefix_hash_key(nhtd->nh); - return jhash_1word(nhtd->nh_vrf_id, key); -} + nhtd = static_nht_hash_find(static_nht_hash, ref); + if (!nhtd) { + nhtd = XCALLOC(MTYPE_STATIC_NHT_DATA, sizeof(*nhtd)); -static bool static_nht_hash_cmp(const void *d1, const void *d2) -{ - const struct static_nht_data *nhtd1 = d1; - const struct static_nht_data *nhtd2 = d2; + prefix_copy(&nhtd->nh, &ref->nh); + nhtd->nh_vrf_id = ref->nh_vrf_id; + nhtd->safi = ref->safi; - if (nhtd1->nh_vrf_id != nhtd2->nh_vrf_id) - return false; + static_nht_hash_add(static_nht_hash, nhtd); + } - return prefix_same(nhtd1->nh, nhtd2->nh); + nhtd->refcount++; + return nhtd; } -static void *static_nht_hash_alloc(void *data) +static bool static_nht_hash_decref(struct static_nht_data *nhtd) { - struct static_nht_data *copy = data; - struct static_nht_data *new; - - new = XMALLOC(MTYPE_TMP, sizeof(*new)); + if (--nhtd->refcount > 0) + return true; - new->nh = prefix_new(); - prefix_copy(new->nh, copy->nh); - new->refcount = 0; - new->nh_num = 0; - new->nh_vrf_id = copy->nh_vrf_id; - - return new; + static_nht_hash_del(static_nht_hash, nhtd); + XFREE(MTYPE_STATIC_NHT_DATA, nhtd); + return false; } -static void static_nht_hash_free(void *data) +static void static_nht_hash_clear(void) { - struct static_nht_data *nhtd = data; + struct static_nht_data *nhtd; - prefix_free(&nhtd->nh); - XFREE(MTYPE_TMP, nhtd); + while ((nhtd = static_nht_hash_pop(static_nht_hash))) + XFREE(MTYPE_STATIC_NHT_DATA, nhtd); } void static_zebra_nht_register(struct static_nexthop *nh, bool reg) { struct static_path *pn = nh->pn; struct route_node *rn = pn->rn; - struct static_nht_data *nhtd, lookup; + struct static_route_info *si = static_route_info_from_rnode(rn); + struct static_nht_data lookup; uint32_t cmd; struct prefix p; afi_t afi = AFI_IP; @@ -294,44 +321,42 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) } memset(&lookup, 0, sizeof(lookup)); - lookup.nh = &p; + lookup.nh = p; lookup.nh_vrf_id = nh->nh_vrf_id; + lookup.safi = si->safi; nh->nh_registered = reg; if (reg) { - nhtd = hash_get(static_nht_hash, &lookup, - static_nht_hash_alloc); - nhtd->refcount++; + struct static_nht_data *nhtd; + + nhtd = static_nht_hash_getref(&lookup); if (nhtd->refcount > 1) { DEBUGD(&static_dbg_route, "Already registered nexthop(%pFX) for %pRN %d", &p, rn, nhtd->nh_num); if (nhtd->nh_num) - static_nht_update(&rn->p, nhtd->nh, - nhtd->nh_num, afi, + static_nht_update(&rn->p, &nhtd->nh, + nhtd->nh_num, afi, si->safi, nh->nh_vrf_id); return; } } else { - nhtd = hash_lookup(static_nht_hash, &lookup); + struct static_nht_data *nhtd; + + nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (!nhtd) return; - - nhtd->refcount--; - if (nhtd->refcount >= 1) + if (static_nht_hash_decref(nhtd)) return; - - hash_release(static_nht_hash, nhtd); - static_nht_hash_free(nhtd); } DEBUGD(&static_dbg_route, "%s nexthop(%pFX) for %pRN", reg ? "Registering" : "Unregistering", &p, rn); - if (zclient_send_rnh(zclient, cmd, &p, false, false, nh->nh_vrf_id) - == ZCLIENT_SEND_FAILURE) + if (zclient_send_rnh(zclient, cmd, &p, si->safi, false, false, + nh->nh_vrf_id) == ZCLIENT_SEND_FAILURE) zlog_warn("%s: Failure to send nexthop to zebra", __func__); } /* @@ -342,6 +367,7 @@ int static_zebra_nh_update(struct static_nexthop *nh) { struct static_path *pn = nh->pn; struct route_node *rn = pn->rn; + struct static_route_info *si = static_route_info_from_rnode(rn); struct static_nht_data *nhtd, lookup = {}; struct prefix p = {}; afi_t afi = AFI_IP; @@ -369,14 +395,15 @@ int static_zebra_nh_update(struct static_nexthop *nh) break; } - lookup.nh = &p; + lookup.nh = p; lookup.nh_vrf_id = nh->nh_vrf_id; + lookup.safi = si->safi; - nhtd = hash_lookup(static_nht_hash, &lookup); + nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (nhtd && nhtd->nh_num) { nh->state = STATIC_START; - static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num, afi, - nh->nh_vrf_id); + static_nht_update(&rn->p, &nhtd->nh, nhtd->nh_num, afi, + si->safi, nh->nh_vrf_id); return 1; } return 0; @@ -531,14 +558,15 @@ void static_zebra_init(void) zclient->zebra_capabilities = static_zebra_capabilities; zclient->zebra_connected = zebra_connected; - static_nht_hash = hash_create(static_nht_hash_key, - static_nht_hash_cmp, - "Static Nexthop Tracking hash"); + static_nht_hash_init(static_nht_hash); } /* static_zebra_stop used by tests/lib/test_grpc.cpp */ void static_zebra_stop(void) { + static_nht_hash_clear(); + static_nht_hash_fini(static_nht_hash); + if (!zclient) return; zclient_stop(zclient); diff --git a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py index eb8561c404..d17aeda3ea 100644 --- a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py +++ b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py @@ -134,6 +134,7 @@ def build_topo(tgen): switch = tgen.add_switch("s4") switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") + def setup_module(mod): "Sets up the pytest environment" tgen = Topogen(build_topo, mod.__name__) @@ -585,10 +586,11 @@ def test_nssa_range(): logger.info("Expecting NSSA range to be added on r3") routes = { "2001:db8:1000::/64": { - "metricType":2, - "metricCost":20, - "metricCostE2":10, - }} + "metricType": 2, + "metricCost": 20, + "metricCostE2": 10, + } + } expect_ospfv3_routes("r3", routes, wait=30, type="external-2", detail=True) # Change the NSSA range cost. @@ -601,10 +603,11 @@ def test_nssa_range(): logger.info("Expecting NSSA range to be updated with new cost") routes = { "2001:db8:1000::/64": { - "metricType":2, - "metricCost":20, - "metricCostE2":1000, - }} + "metricType": 2, + "metricCost": 20, + "metricCostE2": 1000, + } + } expect_ospfv3_routes("r3", routes, wait=30, type="external-2", detail=True) # Configure the NSSA range to not be advertised. @@ -631,12 +634,12 @@ def test_nssa_range(): logger.info("Expecting previously summarized routes to be re-added") routes = { "2001:db8:1000::1/128": { - "metricType":2, - "metricCost":20, + "metricType": 2, + "metricCostE2": 20, }, "2001:db8:1000::2/128": { - "metricType":2, - "metricCost":20, + "metricType": 2, + "metricCostE2": 20, }, } expect_ospfv3_routes("r3", routes, wait=30, type="external-2", detail=True) diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 07819ea76d..228a136b71 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -116,9 +116,9 @@ sub scan_file { } elsif ($file =~ /lib\/plist\.c$/) { if ($defun_array[1] =~ m/ipv6/) { - $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; + $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIM6D|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; } else { - $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; + $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; } } elsif ($file =~ /lib\/if_rmap\.c$/) { diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index ed1f1fb5bb..9e8f73b101 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2955,6 +2955,7 @@ DEFUN (show_yang_operational_data, [{\ format <json|xml>\ |translate WORD\ + |with-config\ }]" DAEMONS_LIST, SHOW_STR "YANG information\n" @@ -2965,6 +2966,7 @@ DEFUN (show_yang_operational_data, "Extensible Markup Language\n" "Translate operational data\n" "YANG module translator\n" + "Merge configuration data\n" DAEMONS_STR) { return show_one_daemon(vty, argv, argc - 1, argv[argc - 1]->text); diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index e94aee5c1a..fd475e4cee 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1215,7 +1215,7 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) p.family); return; } - rnh = zebra_add_rnh(&p, zvrf_id(zvrf), &exist); + rnh = zebra_add_rnh(&p, zvrf_id(zvrf), safi, &exist); if (!rnh) return; diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 4d5336120d..7934a9d206 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -132,13 +132,13 @@ static void zebra_rnh_store_in_routing_table(struct rnh *rnh) route_unlock_node(rn); } -struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists) +struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, safi_t safi, + bool *exists) { struct route_table *table; struct route_node *rn; struct rnh *rnh = NULL; afi_t afi = family2afi(p->family); - safi_t safi = SAFI_UNICAST; if (IS_ZEBRA_DEBUG_NHT) { struct vrf *vrf = vrf_lookup_by_id(vrfid); @@ -345,7 +345,7 @@ void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw, return; addr2hostprefix(pw->af, &pw->nexthop, &nh); - rnh = zebra_add_rnh(&nh, vrf_id, &exists); + rnh = zebra_add_rnh(&nh, vrf_id, SAFI_UNICAST, &exists); if (!rnh) return; @@ -768,7 +768,7 @@ static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, afi_t afi, * of a particular VRF and address-family or a specific prefix. */ void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, - struct prefix *p, safi_t safi) + const struct prefix *p, safi_t safi) { struct route_table *rnh_table; struct route_node *nrn; @@ -802,13 +802,13 @@ void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, } } -void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty, - struct prefix *p) +void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, safi_t safi, + struct vty *vty, const struct prefix *p) { struct route_table *table; struct route_node *rn; - table = get_rnh_table(vrfid, afi, SAFI_UNICAST); + table = get_rnh_table(vrfid, afi, safi); if (!table) { if (IS_ZEBRA_DEBUG_NHT) zlog_debug("print_rnhs: rnh table not found"); @@ -1337,7 +1337,7 @@ static void print_rnh(struct route_node *rn, struct vty *vty) vty_out(vty, "\n"); } -static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi, +static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi, safi_t safi, struct zserv *client) { struct route_table *ntable; @@ -1352,7 +1352,7 @@ static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi, zebra_route_string(client->proto), afi2str(afi)); } - ntable = get_rnh_table(vrf_id, afi, SAFI_UNICAST); + ntable = get_rnh_table(vrf_id, afi, safi); if (!ntable) { zlog_debug("cleanup_rnh_client: rnh table not found"); return -1; @@ -1377,9 +1377,14 @@ static int zebra_client_cleanup_rnh(struct zserv *client) RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { zvrf = vrf->info; if (zvrf) { - zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, client); + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, + SAFI_UNICAST, client); + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, + SAFI_MULTICAST, client); + zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6, + SAFI_UNICAST, client); zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6, - client); + SAFI_MULTICAST, client); } } diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index 27c016ebe6..70eda725c4 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -31,7 +31,7 @@ extern "C" { extern void zebra_rnh_init(void); -extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, +extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, safi_t safi, bool *exists); extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, safi_t safi); @@ -44,9 +44,9 @@ extern void zebra_register_rnh_pseudowire(vrf_id_t, struct zebra_pw *, bool *); extern void zebra_deregister_rnh_pseudowire(vrf_id_t, struct zebra_pw *); extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client); extern void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force, - struct prefix *p, safi_t safi); -extern void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty, - struct prefix *p); + const struct prefix *p, safi_t safi); +extern void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, safi_t safi, + struct vty *vty, const struct prefix *p); extern int rnh_resolve_via_default(struct zebra_vrf *zvrf, int family); diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index ebe0fffcb2..62ce17326c 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -354,8 +354,12 @@ static int zebra_sr_config(struct vty *vty) inet_ntop(AF_INET6, &locator->prefix.prefix, str, sizeof(str)); vty_out(vty, " locator %s\n", locator->name); - vty_out(vty, " prefix %s/%u\n", str, + vty_out(vty, " prefix %s/%u", str, locator->prefix.prefixlen); + if (locator->function_bits_length) + vty_out(vty, " func-bits %u", + locator->function_bits_length); + vty_out(vty, "\n"); vty_out(vty, " exit\n"); vty_out(vty, " !\n"); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 32bbfd6654..22c65e3c0c 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1361,7 +1361,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, DEFPY (show_ip_nht, show_ip_nht_cmd, - "show <ip$ipv4|ipv6$ipv6> <nht|import-check>$type [<A.B.C.D|X:X::X:X>$addr|vrf NAME$vrf_name [<A.B.C.D|X:X::X:X>$addr]|vrf all$vrf_all]", + "show <ip$ipv4|ipv6$ipv6> <nht|import-check>$type [<A.B.C.D|X:X::X:X>$addr|vrf NAME$vrf_name [<A.B.C.D|X:X::X:X>$addr]|vrf all$vrf_all] [mrib$mrib]", SHOW_STR IP_STR IP6_STR @@ -1372,11 +1372,13 @@ DEFPY (show_ip_nht, VRF_CMD_HELP_STR "IPv4 Address\n" "IPv6 Address\n" - VRF_ALL_CMD_HELP_STR) + VRF_ALL_CMD_HELP_STR + "Show Multicast (MRIB) NHT state\n") { afi_t afi = ipv4 ? AFI_IP : AFI_IP6; vrf_id_t vrf_id = VRF_DEFAULT; struct prefix prefix, *p = NULL; + safi_t safi = mrib ? SAFI_MULTICAST : SAFI_UNICAST; if (vrf_all) { struct vrf *vrf; @@ -1385,8 +1387,8 @@ DEFPY (show_ip_nht, RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) if ((zvrf = vrf->info) != NULL) { vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); - zebra_print_rnh_table(zvrf_id(zvrf), afi, vty, - NULL); + zebra_print_rnh_table(zvrf_id(zvrf), afi, safi, + vty, NULL); } return CMD_SUCCESS; } @@ -1400,7 +1402,7 @@ DEFPY (show_ip_nht, return CMD_WARNING; } - zebra_print_rnh_table(vrf_id, afi, vty, p); + zebra_print_rnh_table(vrf_id, afi, safi, vty, p); return CMD_SUCCESS; } |
