diff options
81 files changed, 2213 insertions, 1102 deletions
@@ -59,7 +59,7 @@ lists: For chat, we currently use [Slack](https://frrouting.slack.com). You can join by clicking the "Slack" link under the -[Participate](https://frrouting.org/#participate) section of our website. +[Participate](https://frrouting.org/community) section of our website. Contributing diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 98c5d21196..00fb58e576 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -60,21 +60,10 @@ static void babel_interface_free (babel_interface_nfo *bi); static vector babel_enable_if; /* enable interfaces (by cmd). */ -int -babel_interface_up (ZAPI_CALLBACK_ARGS) +int babel_ifp_up(struct interface *ifp) { - struct stream *s = NULL; - struct interface *ifp = NULL; - debugf(BABEL_DEBUG_IF, "receive a 'interface up'"); - s = zclient->ibuf; - ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */ - - if (ifp == NULL) { - return 0; - } - interface_recalculate(ifp); return 0; } @@ -1235,11 +1224,6 @@ DEFUN (show_babel_parameters, return CMD_SUCCESS; } -int babel_ifp_up(struct interface *ifp) -{ - return 0; -} - void babel_if_init(void) { diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index a96b63cac6..2f246e61d8 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2572,6 +2572,16 @@ bgp_attr_srv6_service_data(struct bgp_attr_parser_args *args) args->total); } + if (length < BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_STRUCTURE_LENGTH) { + flog_err( + EC_BGP_ATTR_LEN, + "Malformed SRv6 Service Data Sub-Sub-TLV attribute - insufficient data (need %u, have %hu remaining in UPDATE)", + BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_STRUCTURE_LENGTH, + length); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, + args->total); + } + if (type == BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_STRUCTURE) { loc_block_len = stream_getc(peer->curr); loc_node_len = stream_getc(peer->curr); diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 96c34f9196..48d3706ec5 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -1619,6 +1619,8 @@ static void bmp_targets_put(struct bmp_targets *bt) struct bmp *bmp; struct bmp_active *ba; + THREAD_OFF(bt->t_stats); + frr_each_safe (bmp_actives, &bt->actives, ba) bmp_active_put(ba); @@ -1929,6 +1931,28 @@ static struct cmd_node bmp_node = { .prompt = "%s(config-bgp-bmp)# " }; +static void bmp_targets_autocomplete(vector comps, struct cmd_token *token) +{ + struct bgp *bgp; + struct bmp_targets *target; + struct listnode *node; + + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) { + struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp); + + if (!bmpbgp) + continue; + + frr_each_safe (bmp_targets, &bmpbgp->targets, target) + vector_set(comps, + XSTRDUP(MTYPE_COMPLETION, target->name)); + } +} + +static const struct cmd_variable_handler bmp_targets_var_handlers[] = { + {.tokenname = "BMPTARGETS", .completions = bmp_targets_autocomplete}, + {.completions = NULL}}; + #define BMP_STR "BGP Monitoring Protocol\n" #ifndef VTYSH_EXTRACT_PL @@ -2422,6 +2446,9 @@ static int bgp_bmp_init(struct thread_master *tm) { install_node(&bmp_node); install_default(BMP_NODE); + + cmd_variable_handler_register(bmp_targets_var_handlers); + install_element(BGP_NODE, &bmp_targets_cmd); install_element(BGP_NODE, &no_bmp_targets_cmd); 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_mh.c b/bgpd/bgp_evpn_mh.c index 2296bd773c..ed3716f601 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -3132,8 +3132,6 @@ void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi *es_evi, struct bgp *bgp_vrf) es_vrf = bgp_evpn_es_vrf_find(es, bgp_vrf); if (!es_vrf) es_vrf = bgp_evpn_es_vrf_create(es, bgp_vrf); - if (!es_vrf) - return; es_evi->es_vrf = es_vrf; ++es_vrf->ref_cnt; @@ -3781,11 +3779,8 @@ int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni) if (CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL)) /* dup */ return 0; - } else { + } else es_evi = bgp_evpn_es_evi_new(es, vpn); - if (!es_evi) - return -1; - } bgp_evpn_es_evi_local_info_set(es_evi); @@ -3837,13 +3832,8 @@ int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn, } es_evi = bgp_evpn_es_evi_find(es, vpn); - if (!es_evi) { + if (!es_evi) es_evi = bgp_evpn_es_evi_new(es, vpn); - if (!es_evi) { - bgp_evpn_es_free(es, __func__); - return -1; - } - } ead_es = !!p->prefix.ead_addr.eth_tag; bgp_evpn_es_evi_vtep_add(bgp, es_evi, p->prefix.ead_addr.ip.ipaddr_v4, diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index fd30cc2db3..763408782f 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -316,12 +316,6 @@ static inline int is_export_rt_configured(struct bgpevpn *vpn) return (CHECK_FLAG(vpn->flags, VNI_FLAG_EXPRT_CFGD)); } -static inline int is_vni_param_configured(struct bgpevpn *vpn) -{ - return (is_rd_configured(vpn) || is_import_rt_configured(vpn) - || is_export_rt_configured(vpn)); -} - static inline void encode_es_rt_extcomm(struct ecommunity_val *eval, struct ethaddr *mac) { 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 f755089bba..43908fcb78 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -2207,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_route.c b/bgpd/bgp_route.c index 7762af1b34..01120ef44a 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -12464,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 */ @@ -12475,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; - - if (uj) { - if (first) - first = false; - else - vty_out(vty, ",\n"); + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, abgp)) { + FOREACH_AFI_SAFI (afi, safi) { + if (!bgp_afi_safi_peer_exists(abgp, afi, + safi)) + continue; - 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 (uj) { + if (first) + first = false; + else + vty_out(vty, ",\n"); - 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) @@ -13962,6 +13978,8 @@ DEFPY (show_ip_bgp_instance_neighbor_advertised_route, int idx = 0; bool first = true; uint16_t show_flags = 0; + struct listnode *node; + struct bgp *abgp; if (uj) { argc--; @@ -14013,42 +14031,52 @@ DEFPY (show_ip_bgp_instance_neighbor_advertised_route, || CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6)) { 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; - else - vty_out(vty, ",\n"); - vty_out(vty, "\"%s\":", - get_afi_safi_str(afi, safi, true)); - } else - vty_out(vty, "\nFor address family: %s\n", - get_afi_safi_str(afi, safi, false)); + if (uj) { + if (first) + first = false; + else + vty_out(vty, ",\n"); + vty_out(vty, "\"%s\":", + get_afi_safi_str(afi, safi, + true)); + } else + vty_out(vty, + "\nFor address family: %s\n", + get_afi_safi_str(afi, safi, + false)); - peer_adj_routes(vty, peer, afi, safi, type, rmap_name, - show_flags); + peer_adj_routes(vty, peer, afi, safi, type, + rmap_name, show_flags); + } } } else { - 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"); - vty_out(vty, "\"%s\":", - get_afi_safi_str(afi, safi, true)); - } else - vty_out(vty, "\nFor address family: %s\n", - get_afi_safi_str(afi, safi, false)); + if (uj) { + if (first) + first = false; + else + vty_out(vty, ",\n"); + vty_out(vty, "\"%s\":", + get_afi_safi_str(afi, safi, + true)); + } else + vty_out(vty, + "\nFor address family: %s\n", + get_afi_safi_str(afi, safi, + false)); - peer_adj_routes(vty, peer, afi, safi, type, rmap_name, - show_flags); + peer_adj_routes(vty, peer, afi, safi, type, + rmap_name, show_flags); + } } } if (uj) 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/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_circuit.c b/isisd/isis_circuit.c index da75f196ba..c7bf1e2012 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -312,8 +312,10 @@ void isis_circuit_add_addr(struct isis_circuit *circuit, 0); #ifdef EXTREME_DEBUG - zlog_debug("Added IP address %pFX to circuit %s", - connected->address, circuit->interface->name); + if (IS_DEBUG_EVENTS) + zlog_debug("Added IP address %pFX to circuit %s", + connected->address, + circuit->interface->name); #endif /* EXTREME_DEBUG */ } if (connected->address->family == AF_INET6) { @@ -350,8 +352,10 @@ void isis_circuit_add_addr(struct isis_circuit *circuit, 0); #ifdef EXTREME_DEBUG - zlog_debug("Added IPv6 address %pFX to circuit %s", - connected->address, circuit->interface->name); + if (IS_DEBUG_EVENTS) + zlog_debug("Added IPv6 address %pFX to circuit %s", + connected->address, + circuit->interface->name); #endif /* EXTREME_DEBUG */ } @@ -681,9 +685,11 @@ int isis_circuit_up(struct isis_circuit *circuit) ETH_ALEN); } #ifdef EXTREME_DEGUG - zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s", - circuit->interface->ifindex, ISO_MTU(circuit), - snpa_print(circuit->u.bc.snpa)); + if (IS_DEBUG_EVENTS) + zlog_debug( + "isis_circuit_if_add: if_id %d, isomtu %d snpa %s", + circuit->interface->ifindex, ISO_MTU(circuit), + snpa_print(circuit->u.bc.snpa)); #endif /* EXTREME_DEBUG */ circuit->u.bc.adjdb[0] = list_new(); diff --git a/isisd/isis_pfpacket.c b/isisd/isis_pfpacket.c index 20224c73a1..d58cd1c5bc 100644 --- a/isisd/isis_pfpacket.c +++ b/isisd/isis_pfpacket.c @@ -101,11 +101,13 @@ static int isis_multicast_join(int fd, int registerto, int if_num) mreq.mr_type = PACKET_MR_ALLMULTI; } #ifdef EXTREME_DEBUG - zlog_debug( - "isis_multicast_join(): fd=%d, reg_to=%d, if_num=%d, address = %02x:%02x:%02x:%02x:%02x:%02x", - fd, registerto, if_num, mreq.mr_address[0], mreq.mr_address[1], - mreq.mr_address[2], mreq.mr_address[3], mreq.mr_address[4], - mreq.mr_address[5]); + if (IS_DEBUG_EVENTS) + zlog_debug( + "isis_multicast_join(): fd=%d, reg_to=%d, if_num=%d, address = %02x:%02x:%02x:%02x:%02x:%02x", + fd, registerto, if_num, mreq.mr_address[0], + mreq.mr_address[1], mreq.mr_address[2], + mreq.mr_address[3], mreq.mr_address[4], + mreq.mr_address[5]); #endif /* EXTREME_DEBUG */ if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(struct packet_mreq))) { diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index d5b02f3881..b5fce35b1e 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -511,10 +511,12 @@ static struct isis_vertex *isis_spf_add_root(struct isis_spftree *spftree) isis_vertex_queue_append(&spftree->paths, vertex); #ifdef EXTREME_DEBUG - zlog_debug("ISIS-SPF: added this IS %s %s depth %d dist %d to PATHS", - vtype2string(vertex->type), - vid2string(vertex, buff, sizeof(buff)), vertex->depth, - vertex->d_N); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: added this IS %s %s depth %d dist %d to PATHS", + vtype2string(vertex->type), + vid2string(vertex, buff, sizeof(buff)), vertex->depth, + vertex->d_N); #endif /* EXTREME_DEBUG */ return vertex; @@ -629,11 +631,13 @@ isis_spf_add2tent(struct isis_spftree *spftree, enum vertextype vtype, void *id, } #ifdef EXTREME_DEBUG - zlog_debug( - "ISIS-SPF: add to TENT %s %s %s depth %d dist %d adjcount %d", - print_sys_hostname(vertex->N.id), vtype2string(vertex->type), - vid2string(vertex, buff, sizeof(buff)), vertex->depth, - vertex->d_N, listcount(vertex->Adj_N)); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: add to TENT %s %s %s depth %d dist %d adjcount %d", + print_sys_hostname(vertex->N.id), + vtype2string(vertex->type), + vid2string(vertex, buff, sizeof(buff)), vertex->depth, + vertex->d_N, listcount(vertex->Adj_N)); #endif /* EXTREME_DEBUG */ isis_vertex_queue_insert(&spftree->tents, vertex); @@ -721,10 +725,12 @@ static void process_N(struct isis_spftree *spftree, enum vertextype vtype, vertex = isis_find_vertex(&spftree->paths, id, vtype); if (vertex) { #ifdef EXTREME_DEBUG - zlog_debug( - "ISIS-SPF: process_N %s %s %s dist %d already found from PATH", - print_sys_hostname(vertex->N.id), vtype2string(vtype), - vid2string(vertex, buff, sizeof(buff)), dist); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: process_N %s %s %s dist %d already found from PATH", + print_sys_hostname(vertex->N.id), + vtype2string(vtype), + vid2string(vertex, buff, sizeof(buff)), dist); #endif /* EXTREME_DEBUG */ assert(dist >= vertex->d_N); return; @@ -735,12 +741,15 @@ static void process_N(struct isis_spftree *spftree, enum vertextype vtype, if (vertex) { /* 1) */ #ifdef EXTREME_DEBUG - zlog_debug( - "ISIS-SPF: process_N %s %s %s dist %d parent %s adjcount %d", - print_sys_hostname(vertex->N.id), vtype2string(vtype), - vid2string(vertex, buff, sizeof(buff)), dist, - (parent ? print_sys_hostname(parent->N.id) : "null"), - (parent ? listcount(parent->Adj_N) : 0)); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: process_N %s %s %s dist %d parent %s adjcount %d", + print_sys_hostname(vertex->N.id), + vtype2string(vtype), + vid2string(vertex, buff, sizeof(buff)), dist, + (parent ? print_sys_hostname(parent->N.id) + : "null"), + (parent ? listcount(parent->Adj_N) : 0)); #endif /* EXTREME_DEBUG */ if (vertex->d_N == dist) { struct listnode *node; @@ -778,9 +787,11 @@ static void process_N(struct isis_spftree *spftree, enum vertextype vtype, } #ifdef EXTREME_DEBUG - zlog_debug("ISIS-SPF: process_N add2tent %s %s dist %d parent %s", - print_sys_hostname(id), vtype2string(vtype), dist, - (parent ? print_sys_hostname(parent->N.id) : "null")); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: process_N add2tent %s %s dist %d parent %s", + print_sys_hostname(id), vtype2string(vtype), dist, + (parent ? print_sys_hostname(parent->N.id) : "null")); #endif /* EXTREME_DEBUG */ isis_spf_add2tent(spftree, vtype, id, dist, depth, NULL, psid, parent); @@ -839,8 +850,9 @@ lspfragloop: } #ifdef EXTREME_DEBUG - zlog_debug("ISIS-SPF: process_lsp %s", - print_sys_hostname(lsp->hdr.lsp_id)); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug("ISIS-SPF: process_lsp %s", + print_sys_hostname(lsp->hdr.lsp_id)); #endif /* EXTREME_DEBUG */ if (no_overload) { @@ -1388,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; @@ -1433,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); } } @@ -1477,10 +1501,12 @@ static void add_to_paths(struct isis_spftree *spftree, isis_vertex_queue_append(&spftree->paths, vertex); #ifdef EXTREME_DEBUG - zlog_debug("ISIS-SPF: added %s %s %s depth %d dist %d to PATHS", - print_sys_hostname(vertex->N.id), vtype2string(vertex->type), - vid2string(vertex, buff, sizeof(buff)), vertex->depth, - vertex->d_N); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug("ISIS-SPF: added %s %s %s depth %d dist %d to PATHS", + print_sys_hostname(vertex->N.id), + vtype2string(vertex->type), + vid2string(vertex, buff, sizeof(buff)), + vertex->depth, vertex->d_N); #endif /* EXTREME_DEBUG */ } @@ -1647,10 +1673,12 @@ static void isis_spf_loop(struct isis_spftree *spftree, vertex = isis_vertex_queue_pop(&spftree->tents); #ifdef EXTREME_DEBUG - zlog_debug( - "ISIS-SPF: get TENT node %s %s depth %d dist %d to PATHS", - print_sys_hostname(vertex->N.id), - vtype2string(vertex->type), vertex->depth, vertex->d_N); + if (IS_DEBUG_SPF_EVENTS) + zlog_debug( + "ISIS-SPF: get TENT node %s %s depth %d dist %d to PATHS", + print_sys_hostname(vertex->N.id), + vtype2string(vertex->type), vertex->depth, + vertex->d_N); #endif /* EXTREME_DEBUG */ add_to_paths(spftree, vertex); @@ -239,7 +239,7 @@ void zlog_backtrace(int priority) { #ifdef HAVE_LIBUNWIND char buf[100]; - unw_cursor_t cursor; + unw_cursor_t cursor = {}; unw_context_t uc; unw_word_t ip, off, sp; Dl_info dlinfo; diff --git a/lib/monotime.h b/lib/monotime.h index 15b6933955..89616c5427 100644 --- a/lib/monotime.h +++ b/lib/monotime.h @@ -81,9 +81,9 @@ static inline time_t monotime(struct timeval *tvo) return ts.tv_sec; } -#define ONE_DAY_SECOND 60*60*24 -#define ONE_WEEK_SECOND ONE_DAY_SECOND*7 -#define ONE_YEAR_SECOND ONE_DAY_SECOND*365 +#define ONE_DAY_SECOND (60 * 60 * 24) +#define ONE_WEEK_SECOND (ONE_DAY_SECOND * 7) +#define ONE_YEAR_SECOND (ONE_DAY_SECOND * 365) /* the following two return microseconds, not time_t! * 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/subdir.am b/lib/subdir.am index b505e235ca..d1df9cb3d9 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -523,6 +523,11 @@ lib/clippy-command_parse.$(OBJEXT): lib/command_lex.h lib/lib_clippy-command_lex.$(OBJEXT): lib/command_parse.h lib/lib_clippy-command_parse.$(OBJEXT): lib/command_lex.h +DISTCLEANFILES += lib/command_lex.h \ + lib/command_lex.c \ + lib/command_parse.h \ + lib/command_parse.c + rt_enabled = if BABELD @@ -2033,6 +2033,7 @@ static int vtysh_do_pass_fd(struct vty *vty) struct cmsghdr *cmh = CMSG_FIRSTHDR(&mh); ssize_t ret; + memset(&u.buf, 0, sizeof(u.buf)); cmh->cmsg_level = SOL_SOCKET; cmh->cmsg_type = SCM_RIGHTS; cmh->cmsg_len = CMSG_LEN(sizeof(int)); 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/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/pathd/path_cli.c b/pathd/path_cli.c index bfeea8c3db..4775aa36fb 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -527,7 +527,7 @@ DEFPY(srte_segment_list_segment, srte_segment_list_segment_cmd, adj_src_ipv4, adj_dst_ipv4, adj_src_ipv6, adj_dst_ipv6, adj_src_ipv4_str, adj_dst_ipv4_str, - adj_dst_ipv6_str, adj_src_ipv6_str); + adj_src_ipv6_str, adj_dst_ipv6_str); if (status != CMD_SUCCESS) return status; } else { 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_cmd.c b/pimd/pim6_cmd.c index e3130b1564..7b3e04fdc0 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -448,6 +448,180 @@ DEFPY (no_ipv6_pim_rp_prefix_list, return pim_process_no_rp_plist_cmd(vty, rp_str, plist); } +DEFPY (interface_ipv6_mld_join, + interface_ipv6_mld_join_cmd, + "ipv6 mld join X:X::X:X$group [X:X::X:X$source]", + IPV6_STR + IFACE_MLD_STR + "MLD join multicast group\n" + "Multicast group address\n" + "Source address\n") +{ + char xpath[XPATH_MAXLEN]; + + if (source_str) { + if (IPV6_ADDR_SAME(&source, &in6addr_any)) { + vty_out(vty, "Bad source address %s\n", source_str); + return CMD_WARNING_CONFIG_FAILED; + } + } else + source_str = "::"; + + snprintf(xpath, sizeof(xpath), FRR_GMP_JOIN_XPATH, "frr-routing:ipv6", + group_str, source_str); + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY (interface_no_ipv6_mld_join, + interface_no_ipv6_mld_join_cmd, + "no ipv6 mld join X:X::X:X$group [X:X::X:X$source]", + NO_STR + IPV6_STR + IFACE_MLD_STR + "MLD join multicast group\n" + "Multicast group address\n" + "Source address\n") +{ + char xpath[XPATH_MAXLEN]; + + if (source_str) { + if (IPV6_ADDR_SAME(&source, &in6addr_any)) { + vty_out(vty, "Bad source address %s\n", source_str); + return CMD_WARNING_CONFIG_FAILED; + } + } else + source_str = "::"; + + snprintf(xpath, sizeof(xpath), FRR_GMP_JOIN_XPATH, "frr-routing:ipv6", + group_str, source_str); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY (interface_ipv6_mld, + interface_ipv6_mld_cmd, + "ipv6 mld", + IPV6_STR + IFACE_MLD_STR) +{ + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld, + interface_no_ipv6_mld_cmd, + "no ipv6 mld", + NO_STR + IPV6_STR + IFACE_MLD_STR) +{ + const struct lyd_node *pim_enable_dnode; + char pim_if_xpath[XPATH_MAXLEN + 64]; + + snprintf(pim_if_xpath, sizeof(pim_if_xpath), + "%s/frr-pim:pim/address-family[address-family='%s']", + VTY_CURR_XPATH, "frr-routing:ipv6"); + + pim_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, + FRR_PIM_ENABLE_XPATH, VTY_CURR_XPATH, + "frr-routing:ipv6"); + if (!pim_enable_dnode) { + nb_cli_enqueue_change(vty, pim_if_xpath, NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + } else { + if (!yang_dnode_get_bool(pim_enable_dnode, ".")) { + nb_cli_enqueue_change(vty, pim_if_xpath, NB_OP_DESTROY, + NULL); + nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + } else + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, + "false"); + } + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_ipv6_mld_version, + interface_ipv6_mld_version_cmd, + "ipv6 mld version (1-2)$version", + IPV6_STR + IFACE_MLD_STR + "MLD version\n" + "MLD version number\n") +{ + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + nb_cli_enqueue_change(vty, "./mld-version", NB_OP_MODIFY, version_str); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld_version, + interface_no_ipv6_mld_version_cmd, + "no ipv6 mld version [(1-2)]", + NO_STR + IPV6_STR + IFACE_MLD_STR + "MLD version\n" + "MLD version number\n") +{ + nb_cli_enqueue_change(vty, "./mld-version", NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_ipv6_mld_query_interval, + interface_ipv6_mld_query_interval_cmd, + "ipv6 mld query-interval (1-65535)$q_interval", + IPV6_STR + IFACE_MLD_STR + IFACE_MLD_QUERY_INTERVAL_STR + "Query interval in seconds\n") +{ + const struct lyd_node *pim_enable_dnode; + + pim_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, + FRR_PIM_ENABLE_XPATH, VTY_CURR_XPATH, + "frr-routing:ipv6"); + if (!pim_enable_dnode) { + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + } else { + if (!yang_dnode_get_bool(pim_enable_dnode, ".")) + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, + "true"); + } + + nb_cli_enqueue_change(vty, "./query-interval", NB_OP_MODIFY, + q_interval_str); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld_query_interval, + interface_no_ipv6_mld_query_interval_cmd, + "no ipv6 mld query-interval [(1-65535)]", + NO_STR + IPV6_STR + IFACE_MLD_STR + IFACE_MLD_QUERY_INTERVAL_STR + IGNORED_IN_NO_STR) +{ + nb_cli_enqueue_change(vty, "./query-interval", NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + void pim_cmd_init(void) { if_cmd_init(pim_interface_config_write); @@ -491,4 +665,13 @@ void pim_cmd_init(void) install_element(VRF_NODE, &ipv6_pim_rp_prefix_list_cmd); install_element(CONFIG_NODE, &no_ipv6_pim_rp_prefix_list_cmd); install_element(VRF_NODE, &no_ipv6_pim_rp_prefix_list_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_join_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_join_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_version_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_version_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_query_interval_cmd); + install_element(INTERFACE_NODE, + &interface_no_ipv6_mld_query_interval_cmd); } 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 d2e299a007..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); @@ -1271,7 +1276,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, return true; } -int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, uint32_t buf_size, bool no_fwd) { struct bsm_hdr *bshdr; @@ -1371,7 +1376,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, } #if PIM_IPV == 4 - if (ip_hdr->ip_dst.s_addr == qpim_all_pim_routers_addr.s_addr) + if (!pim_addr_cmp(sg->grp, qpim_all_pim_routers_addr)) #else if (0) #endif @@ -1380,18 +1385,16 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, * match RPF towards the BSR's IP address, or they have * no-forward set */ - if (!no_fwd - && !pim_nht_bsr_rpf_check(pim, bshdr->bsr_addr.addr, ifp, - ip_hdr->ip_src)) { + if (!no_fwd && !pim_nht_bsr_rpf_check(pim, bshdr->bsr_addr.addr, + ifp, sg->src)) { if (PIM_DEBUG_BSM) zlog_debug( - "BSM check: RPF to BSR %s is not %pI4%%%s", - bsr_str, &ip_hdr->ip_src, ifp->name); + "BSM check: RPF to BSR %s is not %pPA%%%s", + bsr_str, &sg->src, ifp->name); pim->bsm_dropped++; return -1; } - } else if (if_address_is_local(&ip_hdr->ip_dst, AF_INET, - pim->vrf->vrf_id)) { + } else if (if_address_is_local(&sg->grp, PIM_AF, pim->vrf->vrf_id)) { /* Unicast BSM received - if ucast bsm not enabled on * the interface, drop it */ diff --git a/pimd/pim_bsm.h b/pimd/pim_bsm.h index fceabef9e6..910067109e 100644 --- a/pimd/pim_bsm.h +++ b/pimd/pim_bsm.h @@ -207,11 +207,8 @@ void pim_bsm_proc_init(struct pim_instance *pim); void pim_bsm_proc_free(struct pim_instance *pim); void pim_bsm_clear(struct pim_instance *pim); void pim_bsm_write_config(struct vty *vty, struct interface *ifp); -int pim_bsm_process(struct interface *ifp, - struct ip *ip_hdr, - uint8_t *buf, - uint32_t buf_size, - bool no_fwd); +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, + uint32_t buf_size, bool no_fwd); bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp); struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, struct prefix *grp); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 98fa4c4882..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++; @@ -1282,6 +1280,7 @@ static int igmp_join_sock(const char *ifname, ifindex_t ifindex, return join_fd; } +#if PIM_IPV == 4 static struct gm_join *igmp_join_new(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) @@ -1320,7 +1319,9 @@ static struct gm_join *igmp_join_new(struct interface *ifp, return ij; } +#endif /* PIM_IPV == 4 */ +#if PIM_IPV == 4 ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) { @@ -1362,7 +1363,7 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, return ferr_ok(); } - +#endif /* PIM_IPV == 4 */ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) @@ -1748,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, @@ -1757,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_igmp.c b/pimd/pim_igmp.c index aa6b30c624..57c4cdc470 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -131,12 +131,27 @@ void igmp_source_forward_reevaluate_all(struct pim_instance *pim) struct listnode *srcnode; struct gm_source *src; - /* scan group sources */ - for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, - srcnode, src)) { - igmp_source_forward_reevaluate_one(pim, src); - } /* scan group sources */ - } /* scan igmp groups */ + /* + * RFC 4604 + * section 2.2.1 + * EXCLUDE mode does not apply to SSM addresses, + * and an SSM-aware router will ignore + * MODE_IS_EXCLUDE and CHANGE_TO_EXCLUDE_MODE + * requests in the SSM range. + */ + if (pim_is_grp_ssm(pim, grp->group_addr) && + grp->group_filtermode_isexcl) { + igmp_group_delete(grp); + } else { + /* scan group sources */ + for (ALL_LIST_ELEMENTS_RO( + grp->group_source_list, srcnode, + src)) { + igmp_source_forward_reevaluate_one(pim, + src); + } /* scan group sources */ + } + } /* scan igmp groups */ RB_FOREACH_SAFE (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb, ch_temp) { 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_nb_config.c b/pimd/pim_nb_config.c index 2fabee5dfd..7fe7c0395f 100644 --- a/pimd/pim_nb_config.c +++ b/pimd/pim_nb_config.c @@ -348,6 +348,7 @@ static bool is_pim_interface(const struct lyd_node *dnode) return false; } +#if PIM_IPV == 4 static int pim_cmd_igmp_start(struct interface *ifp) { struct pim_interface *pim_ifp; @@ -376,12 +377,14 @@ static int pim_cmd_igmp_start(struct interface *ifp) return NB_OK; } +#endif /* PIM_IPV == 4 */ /* * CLI reconfiguration affects the interface level (struct pim_interface). * This function propagates the reconfiguration to every active socket * for that interface. */ +#if PIM_IPV == 4 static void igmp_sock_query_interval_reconfig(struct gm_sock *igmp) { struct interface *ifp; @@ -406,6 +409,7 @@ static void igmp_sock_query_interval_reconfig(struct gm_sock *igmp) */ igmp_startup_mode_on(igmp); } +#endif static void igmp_sock_query_reschedule(struct gm_sock *igmp) { @@ -436,6 +440,7 @@ static void igmp_sock_query_reschedule(struct gm_sock *igmp) } } +#if PIM_IPV == 4 static void change_query_interval(struct pim_interface *pim_ifp, int query_interval) { @@ -449,6 +454,7 @@ static void change_query_interval(struct pim_interface *pim_ifp, igmp_sock_query_reschedule(igmp); } } +#endif static void change_query_max_response_time(struct pim_interface *pim_ifp, int query_max_response_time_dsec) @@ -2550,6 +2556,7 @@ int lib_interface_gmp_address_family_destroy(struct nb_cb_destroy_args *args) int lib_interface_gmp_address_family_enable_modify( struct nb_cb_modify_args *args) { +#if PIM_IPV == 4 struct interface *ifp; bool igmp_enable; struct pim_interface *pim_ifp; @@ -2597,7 +2604,9 @@ int lib_interface_gmp_address_family_enable_modify( pim_if_delete(ifp); } } - +#else + /* TBD Depends on MLD data structure changes */ +#endif /* PIM_IPV == 4 */ return NB_OK; } @@ -2671,6 +2680,7 @@ int lib_interface_gmp_address_family_mld_version_modify( case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TBD depends on MLD data structure changes */ break; } @@ -2697,6 +2707,7 @@ int lib_interface_gmp_address_family_mld_version_destroy( int lib_interface_gmp_address_family_query_interval_modify( struct nb_cb_modify_args *args) { +#if PIM_IPV == 4 struct interface *ifp; int query_interval; @@ -2710,7 +2721,9 @@ int lib_interface_gmp_address_family_query_interval_modify( query_interval = yang_dnode_get_uint16(args->dnode, NULL); change_query_interval(ifp->info, query_interval); } - +#else + /* TBD Depends on MLD data structure changes */ +#endif return NB_OK; } @@ -2802,6 +2815,7 @@ int lib_interface_gmp_address_family_robustness_variable_modify( int lib_interface_gmp_address_family_static_group_create( struct nb_cb_create_args *args) { +#if PIM_IPV == 4 struct interface *ifp; struct ipaddr source_addr; struct ipaddr group_addr; @@ -2844,7 +2858,9 @@ int lib_interface_gmp_address_family_static_group_create( return NB_ERR_INCONSISTENCY; } } - +#else + /* TBD Depends on MLD data structure changes */ +#endif /* PIM_IPV == 4 */ return NB_OK; } diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 3babddd877..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"); @@ -279,7 +279,7 @@ void pim_nht_bsr_del(struct pim_instance *pim, struct in_addr addr) } bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, - struct interface *src_ifp, struct in_addr src_ip) + struct interface *src_ifp, pim_addr src_ip) { struct pim_nexthop_cache *pnc = NULL; struct pim_nexthop_cache lookup; diff --git a/pimd/pim_nht.h b/pimd/pim_nht.h index 568c2eb232..d51f622ece 100644 --- a/pimd/pim_nht.h +++ b/pimd/pim_nht.h @@ -76,6 +76,6 @@ void pim_nht_bsr_add(struct pim_instance *pim, struct in_addr bsr_addr); void pim_nht_bsr_del(struct pim_instance *pim, struct in_addr bsr_addr); /* RPF(bsr_addr) == src_ip%src_ifp? */ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, - struct interface *src_ifp, struct in_addr src_ip); + struct interface *src_ifp, pim_addr src_ip); #endif 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 535448f013..50bbc0fe18 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -138,31 +138,34 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message) } /* For now check dst address for hello, assrt and join/prune is all pim rtr */ -static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, in_addr_t addr) +static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, pim_addr addr) { if ((type == PIM_MSG_TYPE_HELLO) || (type == PIM_MSG_TYPE_ASSERT) || (type == PIM_MSG_TYPE_JOIN_PRUNE)) { - if (addr != qpim_all_pim_routers_addr.s_addr) + if (pim_addr_cmp(addr, qpim_all_pim_routers_addr)) return false; } return true; } -int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) +int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, + pim_sgaddr sg) { - struct ip *ip_hdr; + 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 */ - char src_str[INET_ADDRSTRLEN]; - char dst_str[INET_ADDRSTRLEN]; +#endif uint8_t *pim_msg; - int pim_msg_len; + uint32_t pim_msg_len = 0; uint16_t pim_checksum; /* received checksum */ uint16_t checksum; /* computed checksum */ struct pim_neighbor *neigh; struct pim_msg_header *header; bool no_fwd; +#if PIM_IPV == 4 if (len < sizeof(*ip_hdr)) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -171,11 +174,31 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) return -1; } - ip_hdr = (struct ip *)buf; ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */ + sg = pim_sgaddr_from_iphdr(ip_hdr); 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) { @@ -208,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( @@ -223,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( @@ -235,43 +269,29 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } if (PIM_DEBUG_PIM_PACKETS) { - pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, - sizeof(src_str)); - pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, - sizeof(dst_str)); zlog_debug( - "Recv PIM %s packet from %s to %s on %s: ttl=%d pim_version=%d pim_msg_size=%d checksum=%x", - pim_pim_msgtype2str(header->type), src_str, dst_str, - ifp->name, ip_hdr->ip_ttl, header->ver, pim_msg_len, - checksum); - if (PIM_DEBUG_PIM_PACKETDUMP_RECV) { + "Recv PIM %s packet from %pPA to %pPA on %s: pim_version=%d pim_msg_size=%d checksum=%x", + pim_pim_msgtype2str(header->type), &sg.src, &sg.grp, + ifp->name, header->ver, pim_msg_len, checksum); + if (PIM_DEBUG_PIM_PACKETDUMP_RECV) pim_pkt_dump(__func__, pim_msg, pim_msg_len); - } } - if (!pim_pkt_dst_addr_ok(header->type, ip_hdr->ip_dst.s_addr)) { - char dst_str[INET_ADDRSTRLEN]; - char src_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, - sizeof(dst_str)); - pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, - sizeof(src_str)); + if (!pim_pkt_dst_addr_ok(header->type, sg.grp)) { zlog_warn( - "%s: Ignoring Pkt. Unexpected IP destination %s for %s (Expected: all_pim_routers_addr) from %s", - __func__, dst_str, pim_pim_msgtype2str(header->type), - src_str); + "%s: Ignoring Pkt. Unexpected IP destination %pPA for %s (Expected: all_pim_routers_addr) from %pPA", + __func__, &sg.grp, pim_pim_msgtype2str(header->type), + &sg.src); return -1; } switch (header->type) { case PIM_MSG_TYPE_HELLO: - return pim_hello_recv(ifp, ip_hdr->ip_src, - pim_msg + PIM_MSG_HEADER_LEN, + return pim_hello_recv(ifp, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_REGISTER: - return pim_register_recv(ifp, ip_hdr->ip_dst, ip_hdr->ip_src, + return pim_register_recv(ifp, sg.grp, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; @@ -280,38 +300,37 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_JOIN_PRUNE: - neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); + neigh = pim_neighbor_find(ifp, sg.src); if (!neigh) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", + "%s %s: non-hello PIM message type=%d from non-neighbor %pPA on %s", __FILE__, __func__, header->type, - src_str, ifp->name); + &sg.src, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); - return pim_joinprune_recv(ifp, neigh, ip_hdr->ip_src, + return pim_joinprune_recv(ifp, neigh, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_ASSERT: - neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); + neigh = pim_neighbor_find(ifp, sg.src); if (!neigh) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", + "%s %s: non-hello PIM message type=%d from non-neighbor %pPA on %s", __FILE__, __func__, header->type, - src_str, ifp->name); + &sg.src, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); - return pim_assert_recv(ifp, neigh, ip_hdr->ip_src, + return pim_assert_recv(ifp, neigh, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_BOOTSTRAP: - return pim_bsm_process(ifp, ip_hdr, pim_msg, pim_msg_len, - no_fwd); + return pim_bsm_process(ifp, &sg, pim_msg, pim_msg_len, no_fwd); break; default: @@ -348,6 +367,8 @@ static void pim_sock_read(struct thread *t) pim_ifp = ifp->info; while (cont) { + pim_sgaddr sg; + len = pim_socket_recvfromto(fd, buf, sizeof(buf), &from, &fromlen, &to, &tolen, &ifindex); if (len < 0) { @@ -377,7 +398,15 @@ static void pim_sock_read(struct thread *t) ifindex); goto done; } - int fail = pim_pim_packet(ifp, buf, len); +#if PIM_IPV == 4 + sg.src = ((struct sockaddr_in *)&from)->sin_addr; + sg.grp = ((struct sockaddr_in *)&to)->sin_addr; +#else + sg.src = ((struct sockaddr_in6 *)&from)->sin6_addr; + sg.grp = ((struct sockaddr_in6 *)&to)->sin6_addr; +#endif + + int fail = pim_pim_packet(ifp, buf, len, sg); if (fail) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug("%s: pim_pim_packet() return=%d", @@ -520,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; /* @@ -618,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; @@ -629,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); @@ -659,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, @@ -690,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_pim.h b/pimd/pim_pim.h index 1931e8cee8..822d8a18fa 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -54,7 +54,8 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message); void pim_hello_restart_now(struct interface *ifp); void pim_hello_restart_triggered(struct interface *ifp); -int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len); +int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, + pim_sgaddr sg); int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname); 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/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index da903bd980..afa7e37da1 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -212,7 +212,7 @@ static void ssmpingd_delete(struct ssmpingd_sock *ss) if (close(ss->sock_fd)) { zlog_warn( - "%s: failure closing ssmpingd sock_fd=%d for source %pI4: errno=%d: %s", + "%s: failure closing ssmpingd sock_fd=%d for source %pPA: errno=%d: %s", __func__, ss->sock_fd, &ss->source_addr, errno, safe_strerror(errno)); /* warning only */ @@ -262,7 +262,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (len < 0) { zlog_warn( - "%s: failure receiving ssmping for source %pI4 on fd=%d: errno=%d: %s", + "%s: failure receiving ssmping for source %pPA on fd=%d: errno=%d: %s", __func__, &ss->source_addr, ss->sock_fd, errno, safe_strerror(errno)); return -1; @@ -272,7 +272,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (buf[0] != PIM_SSMPINGD_REQUEST) { zlog_warn( - "%s: bad ssmping type=%d from %pSUp to %pSUp on interface %s ifindex=%d fd=%d src=%pI4", + "%s: bad ssmping type=%d from %pSUp to %pSUp on interface %s ifindex=%d fd=%d src=%pPA", __func__, buf[0], &from, &to, ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, &ss->source_addr); @@ -281,7 +281,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (PIM_DEBUG_SSMPINGD) { zlog_debug( - "%s: recv ssmping from %pSUp, to %pSUp, on interface %s ifindex=%d fd=%d src=%pI4", + "%s: recv ssmping from %pSUp, to %pSUp, on interface %s ifindex=%d fd=%d src=%pPA", __func__, &from, &to, ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, &ss->source_addr); } @@ -330,7 +330,7 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, sock_fd = ssmpingd_socket(source_addr, /* port: */ 4321, /* mTTL: */ 64); if (sock_fd < 0) { - zlog_warn("%s: ssmpingd_socket() failure for source %pI4", + zlog_warn("%s: ssmpingd_socket() failure for source %pPA", __func__, &source_addr); return 0; } diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index a7d5986655..a0dea63b79 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -264,7 +264,7 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) struct ssmpingd_sock *ss; ++writes; for (ALL_LIST_ELEMENTS_RO(pim->ssmpingd_list, node, ss)) { - vty_out(vty, "%sip ssmpingd %pI4\n", spaces, + vty_out(vty, "%sip ssmpingd %pPA\n", spaces, &ss->source_addr); ++writes; } 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/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py index 3ec31f3fa8..36cde06c3e 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py @@ -2102,6 +2102,14 @@ def test_ospfv3_type5_summary_tc46_p0(request): ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) step("Verify that originally advertised routes are withdraw from there" " peer.") + output = tgen.gears["r0"].vtysh_cmd( + "show ipv6 ospf6 database as-external json", isjson=True + ) + + output = tgen.gears["r1"].vtysh_cmd( + "show ipv6 ospf6 database as-external json", isjson=True + ) + input_dict = { "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]} } @@ -2113,14 +2121,6 @@ def test_ospfv3_type5_summary_tc46_p0(request): tc_name, result ) - output = tgen.gears["r0"].vtysh_cmd( - "show ipv6 ospf6 database as-external json", isjson=True - ) - - output = tgen.gears["r1"].vtysh_cmd( - "show ipv6 ospf6 database as-external json", isjson=True - ) - result = verify_rib( tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False ) diff --git a/tools/frrinit.sh.in b/tools/frrinit.sh.in index e41f2706e0..df5f0853da 100644 --- a/tools/frrinit.sh.in +++ b/tools/frrinit.sh.in @@ -77,7 +77,7 @@ reload) # systemd doesn't set WATCHDOG_USEC for reload commands. watchfrr_pidfile="$V_PATH/watchfrr.pid" watchfrr_pid="`cat \"$watchfrr_pidfile\"`" - watchfrr_cmdline="`strings /proc/$watchfrr_pid/cmdline`" + watchfrr_cmdline="`tr '\0' '\n' < /proc/$watchfrr_pid/cmdline`" if [ -d "/proc/$watchfrr_pid" ]; then wdt="`tr '\0' '\n' < /proc/$watchfrr_pid/environ | grep '^WATCHDOG_USEC='`" wdt="${wdt#WATCHDOG_USEC=}" 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/if_netlink.c b/zebra/if_netlink.c index fca03e55bf..873aea236d 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -103,7 +103,7 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, EC_LIB_INTERFACE, "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!", ifi_index, oifp->name, ifp->name); - if_delete_update(oifp); + if_delete_update(&oifp); } } if_set_index(ifp, ifi_index); @@ -2144,7 +2144,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) else if (IS_ZEBRA_IF_VXLAN(ifp)) zebra_l2_vxlanif_del(ifp); - if_delete_update(ifp); + if_delete_update(&ifp); /* If VRF, delete the VRF structure itself. */ if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) diff --git a/zebra/interface.c b/zebra/interface.c index 69d611e583..a70326ebb3 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -806,9 +806,10 @@ static void if_delete_connected(struct interface *ifp) } /* Handle an interface delete event */ -void if_delete_update(struct interface *ifp) +void if_delete_update(struct interface **pifp) { struct zebra_if *zif; + struct interface *ifp = *pifp; if (if_is_up(ifp)) { flog_err( @@ -871,7 +872,7 @@ void if_delete_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("interface %s is being deleted from the system", ifp->name); - if_delete(&ifp); + if_delete(pifp); } } diff --git a/zebra/interface.h b/zebra/interface.h index 4b06603e7f..c6930ce816 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -492,7 +492,7 @@ extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp, struct in6_addr *address, int add); extern void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp); -extern void if_delete_update(struct interface *ifp); +extern void if_delete_update(struct interface **ifp); extern void if_add_update(struct interface *ifp); extern void if_up(struct interface *ifp, bool install_connected); extern void if_down(struct interface *); diff --git a/zebra/ioctl.c b/zebra/ioctl.c index 9b6aaf1d85..a895ed9410 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -136,7 +136,7 @@ static int if_ioctl_ipv6(unsigned long request, caddr_t buffer) void if_get_metric(struct interface *ifp) { #ifdef SIOCGIFMETRIC - struct ifreq ifreq; + struct ifreq ifreq = {}; ifreq_set_name(&ifreq, ifp); @@ -153,7 +153,7 @@ void if_get_metric(struct interface *ifp) /* get interface MTU */ void if_get_mtu(struct interface *ifp) { - struct ifreq ifreq; + struct ifreq ifreq = {}; ifreq_set_name(&ifreq, ifp); @@ -410,8 +410,8 @@ int if_unset_prefix_ctx(const struct zebra_dplane_ctx *ctx) void if_get_flags(struct interface *ifp) { int ret; - struct ifreq ifreqflags; - struct ifreq ifreqdata; + struct ifreq ifreqflags = {}; + struct ifreq ifreqdata = {}; ifreq_set_name(&ifreqflags, ifp); ifreq_set_name(&ifreqdata, ifp); diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 0dd76e3253..35f3274c65 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1016,6 +1016,18 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), return err; } + /* + * What is the right thing to do? The kernel + * is telling us that the dump request was interrupted + * and we more than likely are out of luck and have + * missed data from the kernel. At this point in time + * lets just note that this is happening. + */ + if (h->nlmsg_flags & NLM_F_DUMP_INTR) + flog_err( + EC_ZEBRA_NETLINK_BAD_SEQUENCE, + "netlink recvmsg: The Dump request was interrupted"); + /* OK we got netlink message. */ if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 6583af0a54..d6ca92f54e 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -159,6 +159,9 @@ const struct message rtm_type_str[] = {{RTM_ADD, "RTM_ADD"}, #ifdef RTM_IFANNOUNCE {RTM_IFANNOUNCE, "RTM_IFANNOUNCE"}, #endif /* RTM_IFANNOUNCE */ +#ifdef RTM_IEEE80211 + {RTM_IEEE80211, "RTM_IEEE80211"}, +#endif {0}}; static const struct message rtm_flag_str[] = {{RTF_UP, "UP"}, @@ -450,12 +453,13 @@ static int ifan_read(struct if_announcemsghdr *ifan) if_get_metric(ifp); if_add_update(ifp); } else if (ifp != NULL && ifan->ifan_what == IFAN_DEPARTURE) - if_delete_update(ifp); - - if_get_flags(ifp); - if_get_mtu(ifp); - if_get_metric(ifp); + if_delete_update(&ifp); + if (ifp) { + if_get_flags(ifp); + if_get_mtu(ifp); + if_get_metric(ifp); + } if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("%s: interface %s index %d", __func__, ifan->ifan_name, ifan->ifan_index); @@ -722,10 +726,10 @@ int ifm_read(struct if_msghdr *ifm) * will still behave correctly if run on a platform * without */ - if_delete_update(ifp); + if_delete_update(&ifp); } #endif /* RTM_IFANNOUNCE */ - if (if_is_up(ifp)) { + if (ifp && if_is_up(ifp)) { #if defined(__bsdi__) if_kvm_get_mtu(ifp); #else @@ -735,14 +739,16 @@ int ifm_read(struct if_msghdr *ifm) } } + if (ifp) { #ifdef HAVE_NET_RT_IFLIST - ifp->stats = ifm->ifm_data; + ifp->stats = ifm->ifm_data; #endif /* HAVE_NET_RT_IFLIST */ - ifp->speed = ifm->ifm_data.ifi_baudrate / 1000000; + ifp->speed = ifm->ifm_data.ifi_baudrate / 1000000; - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: interface %s index %d", __func__, ifp->name, - ifp->ifindex); + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: interface %s index %d", __func__, + ifp->name, ifp->ifindex); + } return 0; } @@ -1405,7 +1411,10 @@ static void kernel_read(struct thread *thread) #endif /* RTM_IFANNOUNCE */ default: if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("Unprocessed RTM_type: %d", rtm->rtm_type); + zlog_debug( + "Unprocessed RTM_type: %s(%d)", + lookup_msg(rtm_type_str, rtm->rtm_type, NULL), + rtm->rtm_type); break; } } 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_evpn_mac.c b/zebra/zebra_evpn_mac.c index 1a1cbaa948..46d789bc34 100644 --- a/zebra/zebra_evpn_mac.c +++ b/zebra/zebra_evpn_mac.c @@ -2479,9 +2479,13 @@ void zebra_evpn_mac_gw_macip_add(struct interface *ifp, if (zvrf && zvrf->zns) local_ns_id = zvrf->zns->ns_id; - mac = zebra_evpn_mac_lookup(zevpn, macaddr); - if (!mac) - mac = zebra_evpn_mac_add(zevpn, macaddr); + if (!*macp) { + mac = zebra_evpn_mac_lookup(zevpn, macaddr); + if (!mac) + mac = zebra_evpn_mac_add(zevpn, macaddr); + *macp = mac; + } else + mac = *macp; /* Set "local" forwarding info. */ zebra_evpn_mac_clear_fwd_info(mac); @@ -2494,8 +2498,6 @@ void zebra_evpn_mac_gw_macip_add(struct interface *ifp, mac->fwd_info.local.ifindex = ifp->ifindex; mac->fwd_info.local.ns_id = local_ns_id; mac->fwd_info.local.vid = vlan_id; - - *macp = mac; } void zebra_evpn_mac_svi_del(struct interface *ifp, struct zebra_evpn *zevpn) @@ -2548,7 +2550,6 @@ void zebra_evpn_mac_svi_add(struct interface *ifp, struct zebra_evpn *zevpn) ? true : false; - mac = NULL; zebra_evpn_mac_gw_macip_add(ifp, zevpn, NULL, &mac, &macaddr, 0, false); new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); diff --git a/zebra/zebra_evpn_mac.h b/zebra/zebra_evpn_mac.h index 6a8ec1d2e1..b727ac1f98 100644 --- a/zebra/zebra_evpn_mac.h +++ b/zebra/zebra_evpn_mac.h @@ -124,8 +124,8 @@ struct zebra_mac { /* List of neigh associated with this mac */ struct list *neigh_list; - /* list of hosts pointing to this remote RMAC */ - struct host_rb_tree_entry host_rb; + /* List of nexthop associated with this RMAC */ + struct list *nh_list; /* Duplicate mac detection */ uint32_t dad_count; diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 7cb1906895..af6046c9ad 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -179,7 +179,7 @@ static int zebra_ns_delete(char *name) } UNSET_FLAG(ifp->flags, IFF_UP); - if_delete_update(ifp); + if_delete_update(&ifp); } ns = (struct ns *)vrf->ns_ctxt; 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_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; } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 6a3b1bfbe3..13e1f63457 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -62,6 +62,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, ZL3VNI, "L3 VNI hash"); DEFINE_MTYPE_STATIC(ZEBRA, L3VNI_MAC, "EVPN L3VNI MAC"); DEFINE_MTYPE_STATIC(ZEBRA, L3NEIGH, "EVPN Neighbor"); DEFINE_MTYPE_STATIC(ZEBRA, ZVXLAN_SG, "zebra VxLAN multicast group"); +DEFINE_MTYPE_STATIC(ZEBRA, EVPN_VTEP, "zebra VxLAN VTEP IP"); DEFINE_HOOK(zebra_rmac_update, (struct zebra_mac * rmac, struct zebra_l3vni *zl3vni, bool delete, @@ -198,6 +199,37 @@ static uint32_t rb_host_count(struct host_rb_tree_entry *hrbe) return count; } +static int l3vni_rmac_nh_list_cmp(void *p1, void *p2) +{ + const struct ipaddr *vtep_ip1 = p1; + const struct ipaddr *vtep_ip2 = p2; + + return !ipaddr_cmp(vtep_ip1, vtep_ip2); +} + +static void l3vni_rmac_nh_free(struct ipaddr *vtep_ip) +{ + XFREE(MTYPE_EVPN_VTEP, vtep_ip); +} + +static void l3vni_rmac_nh_list_nh_delete(struct zebra_l3vni *zl3vni, + struct zebra_mac *zrmac, + struct ipaddr *vtep_ip) +{ + struct listnode *node = NULL, *nnode = NULL; + struct ipaddr *vtep = NULL; + + for (ALL_LIST_ELEMENTS(zrmac->nh_list, node, nnode, vtep)) { + if (ipaddr_cmp(vtep, vtep_ip) == 0) + break; + } + + if (node) { + l3vni_rmac_nh_free(vtep); + list_delete_node(zrmac->nh_list, node); + } +} + /* * Print neighbors for all EVPN. */ @@ -366,35 +398,25 @@ static void zl3vni_print_nh(struct zebra_neigh *n, struct vty *vty, static void zl3vni_print_rmac(struct zebra_mac *zrmac, struct vty *vty, json_object *json) { - char buf1[ETHER_ADDR_STRLEN]; - char buf2[PREFIX_STRLEN]; - json_object *json_hosts = NULL; - struct host_rb_entry *hle; + struct listnode *node = NULL; + struct ipaddr *vtep = NULL; + json_object *json_nhs = NULL; if (!json) { - vty_out(vty, "MAC: %s\n", - prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); + vty_out(vty, "MAC: %pEA\n", &zrmac->macaddr); vty_out(vty, " Remote VTEP: %pI4\n", &zrmac->fwd_info.r_vtep_ip); - vty_out(vty, " Refcount: %d\n", rb_host_count(&zrmac->host_rb)); - vty_out(vty, " Prefixes:\n"); - RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) - vty_out(vty, " %pFX\n", &hle->p); } else { - json_hosts = json_object_new_array(); - json_object_string_add( - json, "routerMac", - prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); + json_nhs = json_object_new_array(); + json_object_string_addf(json, "routerMac", "%pEA", + &zrmac->macaddr); json_object_string_addf(json, "vtepIp", "%pI4", &zrmac->fwd_info.r_vtep_ip); - json_object_int_add(json, "refCount", - rb_host_count(&zrmac->host_rb)); - RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) - json_object_array_add( - json_hosts, - json_object_new_string(prefix2str( - &hle->p, buf2, sizeof(buf2)))); - json_object_object_add(json, "prefixList", json_hosts); + for (ALL_LIST_ELEMENTS_RO(zrmac->nh_list, node, vtep)) { + json_object_array_add(json_nhs, json_object_new_stringf( + "%pIA", vtep)); + } + json_object_object_add(json, "nexthops", json_nhs); } } @@ -1169,7 +1191,9 @@ static struct zebra_mac *zl3vni_rmac_add(struct zebra_l3vni *zl3vni, zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc); assert(zrmac); - RB_INIT(host_rb_tree_entry, &zrmac->host_rb); + zrmac->nh_list = list_new(); + zrmac->nh_list->cmp = (int (*)(void *, void *))l3vni_rmac_nh_list_cmp; + zrmac->nh_list->del = (void (*)(void *))l3vni_rmac_nh_free; SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE); SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC); @@ -1183,14 +1207,9 @@ static struct zebra_mac *zl3vni_rmac_add(struct zebra_l3vni *zl3vni, static int zl3vni_rmac_del(struct zebra_l3vni *zl3vni, struct zebra_mac *zrmac) { struct zebra_mac *tmp_rmac; - struct host_rb_entry *hle; - while (!RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) { - hle = RB_ROOT(host_rb_tree_entry, &zrmac->host_rb); - - RB_REMOVE(host_rb_tree_entry, &zrmac->host_rb, hle); - XFREE(MTYPE_HOST_PREFIX, hle); - } + /* free the list of nh list*/ + list_delete(&zrmac->nh_list); tmp_rmac = hash_release(zl3vni->rmac_table, zrmac); XFREE(MTYPE_L3VNI_MAC, tmp_rmac); @@ -1291,10 +1310,10 @@ static int zl3vni_rmac_uninstall(struct zebra_l3vni *zl3vni, /* handle rmac add */ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni, const struct ethaddr *rmac, - const struct ipaddr *vtep_ip, - const struct prefix *host_prefix) + const struct ipaddr *vtep_ip) { struct zebra_mac *zrmac = NULL; + struct ipaddr *vtep = NULL; zrmac = zl3vni_rmac_lookup(zl3vni, rmac); if (!zrmac) { @@ -1303,13 +1322,18 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni, zrmac = zl3vni_rmac_add(zl3vni, rmac); if (!zrmac) { zlog_debug( - "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA, prefix %pFX", - rmac, zl3vni->vni, vtep_ip, host_prefix); + "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA", + rmac, zl3vni->vni, vtep_ip); return -1; } memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info)); zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; + vtep = XCALLOC(MTYPE_EVPN_VTEP, sizeof(struct ipaddr)); + memcpy(vtep, vtep_ip, sizeof(struct ipaddr)); + if (!listnode_add_sort_nodup(zrmac->nh_list, (void *)vtep)) + XFREE(MTYPE_EVPN_VTEP, vtep); + /* Send RMAC for FPM processing */ hook_call(zebra_rmac_update, zrmac, zl3vni, false, "new RMAC added"); @@ -1320,18 +1344,21 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni, &vtep_ip->ipaddr_v4)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA, prefix %pFX", + "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA", zl3vni->vni, &zrmac->fwd_info.r_vtep_ip, - vtep_ip, rmac, host_prefix); + vtep_ip, rmac); zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; + vtep = XCALLOC(MTYPE_EVPN_VTEP, sizeof(struct ipaddr)); + memcpy(vtep, vtep_ip, sizeof(struct ipaddr)); + if (!listnode_add_sort_nodup(zrmac->nh_list, (void *)vtep)) + XFREE(MTYPE_EVPN_VTEP, vtep); + /* install rmac in kernel */ zl3vni_rmac_install(zl3vni, zrmac); } - rb_find_or_add_host(&zrmac->host_rb, host_prefix); - return 0; } @@ -1339,20 +1366,59 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni, /* handle rmac delete */ static void zl3vni_remote_rmac_del(struct zebra_l3vni *zl3vni, struct zebra_mac *zrmac, - struct prefix *host_prefix) + struct ipaddr *vtep_ip) { - rb_delete_host(&zrmac->host_rb, host_prefix); + struct ipaddr ipv4_vtep; - if (RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) { - /* uninstall from kernel */ - zl3vni_rmac_uninstall(zl3vni, zrmac); + if (!zl3vni_nh_lookup(zl3vni, vtep_ip)) { + memset(&ipv4_vtep, 0, sizeof(struct ipaddr)); + ipv4_vtep.ipa_type = IPADDR_V4; + if (vtep_ip->ipa_type == IPADDR_V6) + ipv4_mapped_ipv6_to_ipv4(&vtep_ip->ipaddr_v6, + &ipv4_vtep.ipaddr_v4); + else + memcpy(&(ipv4_vtep.ipaddr_v4), &vtep_ip->ipaddr_v4, + sizeof(struct in_addr)); - /* Send RMAC for FPM processing */ - hook_call(zebra_rmac_update, zrmac, zl3vni, true, - "RMAC deleted"); + /* remove nh from rmac's list */ + l3vni_rmac_nh_list_nh_delete(zl3vni, zrmac, &ipv4_vtep); + /* delete nh is same as current selected, fall back to + * one present in the list + */ + if (IPV4_ADDR_SAME(&zrmac->fwd_info.r_vtep_ip, + &ipv4_vtep.ipaddr_v4) && + listcount(zrmac->nh_list)) { + struct ipaddr *vtep; + + vtep = listgetdata(listhead(zrmac->nh_list)); + zrmac->fwd_info.r_vtep_ip = vtep->ipaddr_v4; + if (IS_ZEBRA_DEBUG_VXLAN) + zlog_debug( + "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA", + zl3vni->vni, &ipv4_vtep, + &zrmac->fwd_info.r_vtep_ip, + &zrmac->macaddr); + + /* install rmac in kernel */ + zl3vni_rmac_install(zl3vni, zrmac); + } + + if (!listcount(zrmac->nh_list)) { + /* uninstall from kernel */ + zl3vni_rmac_uninstall(zl3vni, zrmac); - /* del the rmac entry */ - zl3vni_rmac_del(zl3vni, zrmac); + /* Send RMAC for FPM processing */ + hook_call(zebra_rmac_update, zrmac, zl3vni, true, + "RMAC deleted"); + + if (IS_ZEBRA_DEBUG_VXLAN) + zlog_debug( + "L3VNI %u RMAC %pEA vtep_ip %pIA delete", + zl3vni->vni, &zrmac->macaddr, vtep_ip); + + /* del the rmac entry */ + zl3vni_rmac_del(zl3vni, zrmac); + } } } @@ -2235,7 +2301,7 @@ void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac, * add the rmac - remote rmac to be installed is against the ipv4 * nexthop address */ - zl3vni_remote_rmac_add(zl3vni, rmac, &ipv4_vtep, host_prefix); + zl3vni_remote_rmac_add(zl3vni, rmac, &ipv4_vtep); } /* handle evpn vrf route delete */ @@ -2262,8 +2328,7 @@ void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, /* delete the rmac entry */ if (zrmac) - zl3vni_remote_rmac_del(zl3vni, zrmac, host_prefix); - + zl3vni_remote_rmac_del(zl3vni, zrmac, vtep_ip); } void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, @@ -2297,7 +2362,7 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, vty_out(vty, "{}\n"); else vty_out(vty, - "%% Requested RMAC doesn't exist in L3-VNI %u", + "%% Requested RMAC doesn't exist in L3-VNI %u\n", l3vni); return; } |
