pimd: Implement autorp mapping agent CLI

Also exposes BSR cand_addrsel methods for use in AutoRP.

Signed-off-by: Nathan Bahr <nbahr@atcorp.com>
This commit is contained in:
Nathan Bahr 2024-11-01 19:11:14 +00:00
parent bd9331e0ae
commit a060c72530
5 changed files with 152 additions and 178 deletions

View file

@ -1769,14 +1769,14 @@ static inline pim_addr if_highest_addr(pim_addr cur, struct interface *ifp)
return cur; return cur;
} }
static void cand_addrsel_clear(struct cand_addrsel *asel) void cand_addrsel_clear(struct cand_addrsel *asel)
{ {
asel->run = false; asel->run = false;
asel->run_addr = PIMADDR_ANY; asel->run_addr = PIMADDR_ANY;
} }
/* returns whether address or active changed */ /* returns whether address or active changed */
static bool cand_addrsel_update(struct cand_addrsel *asel, struct vrf *vrf) bool cand_addrsel_update(struct cand_addrsel *asel, struct vrf *vrf)
{ {
bool is_any = false, prev_run = asel->run; bool is_any = false, prev_run = asel->run;
struct interface *ifp = NULL; struct interface *ifp = NULL;

View file

@ -64,7 +64,7 @@ enum cand_addr {
CAND_ADDR_EXPLICIT, CAND_ADDR_EXPLICIT,
}; };
/* used separately for Cand-RP and Cand-BSR */ /* used separately for Cand-RP, Cand-BSR, and AutoRP mapping agent */
struct cand_addrsel { struct cand_addrsel {
bool cfg_enable; bool cfg_enable;
enum cand_addr cfg_mode : 8; enum cand_addr cfg_mode : 8;
@ -369,6 +369,9 @@ void pim_cand_rp_trigger(struct bsm_scope *scope);
void pim_cand_rp_grp_add(struct bsm_scope *scope, const prefix_pim *p); void pim_cand_rp_grp_add(struct bsm_scope *scope, const prefix_pim *p);
void pim_cand_rp_grp_del(struct bsm_scope *scope, const prefix_pim *p); void pim_cand_rp_grp_del(struct bsm_scope *scope, const prefix_pim *p);
void cand_addrsel_clear(struct cand_addrsel *asel);
bool cand_addrsel_update(struct cand_addrsel *asel, struct vrf *vrf);
void pim_cand_addrs_changed(void); void pim_cand_addrs_changed(void);
int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf, int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,

View file

@ -2822,65 +2822,49 @@ DEFPY (show_ip_pim_rp_vrf_all,
DEFPY (show_ip_pim_autorp, DEFPY (show_ip_pim_autorp,
show_ip_pim_autorp_cmd, show_ip_pim_autorp_cmd,
"show ip pim [vrf NAME] autorp [json$json]", "show ip pim [vrf <NAME|all>] autorp [discovery|candidate|mapping-agent]$component [json$json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
PIM_STR PIM_STR
VRF_CMD_HELP_STR VRF_CMD_HELP_STR
"All VRF's\n"
"PIM AutoRP information\n" "PIM AutoRP information\n"
"RP Discovery details\n"
"Candidate RP details\n"
"Mapping Agent details\n"
JSON_STR) JSON_STR)
{ {
json_object *json_parent = NULL;
struct vrf *v; struct vrf *v;
json_object *json_parent = NULL;
v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
if (!v || !v->info) {
if (!json)
vty_out(vty, "%% Unable to find pim instance\n");
return CMD_WARNING;
}
if (json) if (json)
json_parent = json_object_new_object(); json_parent = json_object_new_object();
pim_autorp_show_autorp(vty, v->info, json_parent); if (vrf && strmatch(vrf, "all")) {
json_object *json_vrf = NULL;
if (json) RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
vty_json(vty, json_parent); if (!v || !v->info)
continue;
return CMD_SUCCESS;
}
DEFPY (show_ip_pim_autorp_vrf_all,
show_ip_pim_autorp_vrf_all_cmd,
"show ip pim vrf all autorp [json$json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM AutoRP information\n"
JSON_STR)
{
struct vrf *vrf;
json_object *json_parent = NULL;
json_object *json_vrf = NULL;
if (json)
json_parent = json_object_new_object();
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (vrf->info) {
if (!json)
vty_out(vty, "VRF: %s\n", vrf->name);
else
json_vrf = json_object_new_object();
pim_autorp_show_autorp(vty, vrf->info, json_vrf);
if (json) if (json)
json_object_object_add(json_parent, vrf->name, json_vrf = json_object_new_object();
json_vrf); else
vty_out(vty, "VRF: %s\n", v->name);
pim_autorp_show_autorp(vty, v->info, component, json_vrf);
if (json)
json_object_object_add(json_parent, v->name, json_vrf);
} }
} else {
v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
if (!v || !v->info) {
if (!json)
vty_out(vty, "%% Unable to find pim instance\n");
return CMD_WARNING;
}
pim_autorp_show_autorp(vty, v->info, component, json_parent);
} }
if (json) if (json)
@ -4609,13 +4593,17 @@ DEFPY (pim_autorp_announce_rp,
"Prefix list\n" "Prefix list\n"
"List name\n") "List name\n")
{ {
return pim_process_autorp_candidate_rp_cmd(vty, no, rpaddr_str, (grp_str ? grp : NULL), if (grp_str && (!pim_addr_is_multicast(grp->prefix) || grp->prefixlen < 4)) {
plist); vty_out(vty, "%% group prefix %pFX is not a valid multicast range\n", grp);
return CMD_WARNING_CONFIG_FAILED;
}
return pim_process_autorp_candidate_rp_cmd(vty, no, rpaddr_str, grp_str, plist);
} }
DEFPY (pim_autorp_announce_scope_int, DEFPY (pim_autorp_announce_scope_int,
pim_autorp_announce_scope_int_cmd, pim_autorp_announce_scope_int_cmd,
"[no] autorp announce ![{scope (1-255) | interval (1-65535) | holdtime (0-65535)}]", "[no] autorp announce {scope (1-255) | interval (1-65535) | holdtime (0-65535)}",
NO_STR NO_STR
"AutoRP\n" "AutoRP\n"
"AutoRP Candidate RP announcement\n" "AutoRP Candidate RP announcement\n"
@ -4626,11 +4614,44 @@ DEFPY (pim_autorp_announce_scope_int,
"Announcement holdtime\n" "Announcement holdtime\n"
"Time in seconds\n") "Time in seconds\n")
{ {
return pim_process_autorp_announce_scope_int_cmd(vty, no, scope_str, return pim_process_autorp_announce_scope_int_cmd(vty, no, scope_str, interval_str,
interval_str,
holdtime_str); holdtime_str);
} }
DEFPY (pim_autorp_send_rp_discovery,
pim_autorp_send_rp_discovery_cmd,
"[no] autorp send-rp-discovery [source <address A.B.C.D | interface IFNAME | loopback$loopback | any$any>]",
NO_STR
"AutoRP\n"
"Enable AutoRP mapping agent\n"
"Specify AutoRP discovery source\n"
"Local address\n"
IP_ADDR_STR
"Local Interface (uses highest address)\n"
IFNAME_STR
"Highest loopback address (default)\n"
"Highest address of any interface\n")
{
return pim_process_autorp_send_rp_discovery_cmd(vty, no, any, loopback, ifname, address_str);
}
DEFPY (pim_autorp_send_rp_discovery_scope_int,
pim_autorp_send_rp_discovery_scope_int_cmd,
"[no] autorp send-rp-discovery {scope (0-255) | interval (1-65535) | holdtime (0-65535)}",
NO_STR
"AutoRP\n"
"Enable AutoRP mapping agent\n"
"Packet scope (TTL)\n"
"TTL value\n"
"Discovery TX interval\n"
"Time in seconds\n"
"Announcement holdtime\n"
"Time in seconds\n")
{
return pim_process_autorp_send_rp_discovery_scope_int_cmd(vty, no, scope_str, interval_str,
holdtime_str);
}
DEFPY (pim_bsr_candidate_bsr, DEFPY (pim_bsr_candidate_bsr,
pim_bsr_candidate_bsr_cmd, pim_bsr_candidate_bsr_cmd,
"[no] bsr candidate-bsr [{priority (0-255)|source <address A.B.C.D|interface IFNAME|loopback$loopback|any$any>}]", "[no] bsr candidate-bsr [{priority (0-255)|source <address A.B.C.D|interface IFNAME|loopback$loopback|any$any>}]",
@ -8855,6 +8876,8 @@ void pim_cmd_init(void)
install_element(PIM_NODE, &pim_autorp_discovery_cmd); install_element(PIM_NODE, &pim_autorp_discovery_cmd);
install_element(PIM_NODE, &pim_autorp_announce_rp_cmd); install_element(PIM_NODE, &pim_autorp_announce_rp_cmd);
install_element(PIM_NODE, &pim_autorp_announce_scope_int_cmd); install_element(PIM_NODE, &pim_autorp_announce_scope_int_cmd);
install_element(PIM_NODE, &pim_autorp_send_rp_discovery_cmd);
install_element(PIM_NODE, &pim_autorp_send_rp_discovery_scope_int_cmd);
install_element(PIM_NODE, &no_pim_ssm_prefix_list_cmd); install_element(PIM_NODE, &no_pim_ssm_prefix_list_cmd);
install_element(PIM_NODE, &no_pim_ssm_prefix_list_name_cmd); install_element(PIM_NODE, &no_pim_ssm_prefix_list_name_cmd);
install_element(PIM_NODE, &pim_ssm_prefix_list_cmd); install_element(PIM_NODE, &pim_ssm_prefix_list_cmd);
@ -9010,7 +9033,6 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ip_pim_rp_cmd); install_element(VIEW_NODE, &show_ip_pim_rp_cmd);
install_element(VIEW_NODE, &show_ip_pim_rp_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_pim_rp_vrf_all_cmd);
install_element(VIEW_NODE, &show_ip_pim_autorp_cmd); install_element(VIEW_NODE, &show_ip_pim_autorp_cmd);
install_element(VIEW_NODE, &show_ip_pim_autorp_vrf_all_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_cmd); install_element(VIEW_NODE, &show_ip_pim_bsr_cmd);
install_element(VIEW_NODE, &show_ip_multicast_cmd); install_element(VIEW_NODE, &show_ip_multicast_cmd);
install_element(VIEW_NODE, &show_ip_multicast_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_multicast_vrf_all_cmd);

View file

@ -630,139 +630,88 @@ int pim_process_no_autorp_cmd(struct vty *vty)
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, const char *rpaddr_str,
const char *rpaddr_str, const char *grp, const char *plist)
const struct prefix_ipv4 *grp,
const char *plist)
{ {
char xpath[XPATH_MAXLEN];
char grpstr[64];
if (no) { if (no) {
if ((grp && !is_default_prefix((const struct prefix *)grp)) || plist) { if (grp || plist) {
/* If any single values are set, only destroy those */ /* If any single values are set, only destroy those */
if (grp && !is_default_prefix((const struct prefix *)grp)) { if (grp)
snprintfrr(xpath, sizeof(xpath), nb_cli_enqueue_change(vty, "./group", NB_OP_DESTROY, NULL);
"%s/candidate-rp-list[rp-address='%s']/group", if (plist)
FRR_PIM_AUTORP_XPATH, rpaddr_str); nb_cli_enqueue_change(vty, "./prefix-list", NB_OP_DESTROY, NULL);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, } else
NULL);
}
if (plist) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/prefix-list",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
} else {
/* No values set, remove the entire RP */ /* No values set, remove the entire RP */
snprintfrr(xpath, sizeof(xpath), nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
"%s/candidate-rp-list[rp-address='%s']",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
}
} else { } else {
if ((grp && !is_default_prefix((const struct prefix *)grp)) || plist) { nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
snprintfrr(xpath, sizeof(xpath), if (grp)
"%s/candidate-rp-list[rp-address='%s']", nb_cli_enqueue_change(vty, "./group", NB_OP_MODIFY, grp);
FRR_PIM_AUTORP_XPATH, rpaddr_str); if (plist)
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); nb_cli_enqueue_change(vty, "./prefix-list", NB_OP_MODIFY, plist);
if (grp && !is_default_prefix((const struct prefix *)grp)) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/group",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
prefix2str(grp, grpstr,
sizeof(grpstr)));
}
if (plist) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/prefix-list",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
plist);
}
} else {
return CMD_WARNING_CONFIG_FAILED;
}
} }
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, "%s/candidate-rp-list[rp-address='%s']",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
} }
int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no, int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no, const char *scope,
const char *scope, const char *interval, const char *holdtime)
const char *interval,
const char *holdtime)
{ {
char xpath[XPATH_MAXLEN]; /* At least one value is required, so set/delete anything defined */
enum nb_operation op = (no ? NB_OP_DESTROY : NB_OP_MODIFY);
if (scope)
nb_cli_enqueue_change(vty, "./announce-scope", op, scope);
if (interval)
nb_cli_enqueue_change(vty, "./announce-interval", op, interval);
if (holdtime)
nb_cli_enqueue_change(vty, "./announce-holdtime", op, holdtime);
return nb_cli_apply_changes(vty, "%s", FRR_PIM_AUTORP_XPATH);
}
int pim_process_autorp_send_rp_discovery_cmd(struct vty *vty, bool no, bool any, bool loopback,
const char *ifname, const char *addr)
{
/* Just take any "no" version of this command as disable the mapping agent */
nb_cli_enqueue_change(vty, "./send-rp-discovery", NB_OP_MODIFY, (no ? "false" : "true"));
if (no) { if (no) {
if (scope || interval || holdtime) { nb_cli_enqueue_change(vty, "./if-any", NB_OP_DESTROY, NULL);
/* If any single values are set, only destroy those */ nb_cli_enqueue_change(vty, "./interface", NB_OP_DESTROY, NULL);
if (scope) { nb_cli_enqueue_change(vty, "./address", NB_OP_DESTROY, NULL);
snprintfrr(xpath, sizeof(xpath), "%s/%s", nb_cli_enqueue_change(vty, "./if-loopback", NB_OP_DESTROY, NULL);
FRR_PIM_AUTORP_XPATH,
"announce-scope");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
if (interval) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
if (holdtime) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
} else {
/* No values set, remove all */
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-scope");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
}
} else { } else {
if (scope || interval || holdtime) { /* Enabling mapping agent. Loopback is default, so any non-no for of the command will
if (scope) { * enable the mapping agent.
snprintfrr(xpath, sizeof(xpath), "%s/%s", */
FRR_PIM_AUTORP_XPATH, if (any)
"announce-scope"); nb_cli_enqueue_change(vty, "./if-any", NB_OP_CREATE, NULL);
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, else if (ifname)
scope); nb_cli_enqueue_change(vty, "./interface", NB_OP_MODIFY, ifname);
} else if (addr)
if (interval) { nb_cli_enqueue_change(vty, "./address", NB_OP_MODIFY, addr);
snprintfrr(xpath, sizeof(xpath), "%s/%s", else
FRR_PIM_AUTORP_XPATH, nb_cli_enqueue_change(vty, "./if-loopback", NB_OP_CREATE, NULL);
"announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
interval);
}
if (holdtime) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
holdtime);
}
} else {
return CMD_WARNING_CONFIG_FAILED;
}
} }
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, "%s/%s", FRR_PIM_AUTORP_XPATH, "mapping-agent");
}
int pim_process_autorp_send_rp_discovery_scope_int_cmd(struct vty *vty, bool no, const char *scope,
const char *interval, const char *holdtime)
{
/* At least one value is required, so only set/delete the values specified */
enum nb_operation op = (no ? NB_OP_DESTROY : NB_OP_MODIFY);
if (scope)
nb_cli_enqueue_change(vty, "./discovery-scope", op, scope);
if (interval)
nb_cli_enqueue_change(vty, "./discovery-interval", op, interval);
if (holdtime)
nb_cli_enqueue_change(vty, "./discovery-holdtime", op, holdtime);
return nb_cli_apply_changes(vty, "%s/%s", FRR_PIM_AUTORP_XPATH, "mapping-agent");
} }
bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match) bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match)

View file

@ -37,14 +37,14 @@ int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
const char *prefix_list); const char *prefix_list);
int pim_process_autorp_cmd(struct vty *vty); int pim_process_autorp_cmd(struct vty *vty);
int pim_process_no_autorp_cmd(struct vty *vty); int pim_process_no_autorp_cmd(struct vty *vty);
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, const char *rpaddr_str,
const char *rpaddr_str, const char *grp, const char *plist);
const struct prefix_ipv4 *grp, int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no, const char *scope,
const char *plist); const char *interval, const char *holdtime);
int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no, int pim_process_autorp_send_rp_discovery_cmd(struct vty *vty, bool no, bool any, bool loopback,
const char *scope, const char *ifname, const char *addr);
const char *interval, int pim_process_autorp_send_rp_discovery_scope_int_cmd(struct vty *vty, bool no, const char *scope,
const char *holdtime); const char *interval, const char *holdtime);
int pim_process_ip_pim_cmd(struct vty *vty); int pim_process_ip_pim_cmd(struct vty *vty);
int pim_process_no_ip_pim_cmd(struct vty *vty); int pim_process_no_ip_pim_cmd(struct vty *vty);
int pim_process_ip_pim_passive_cmd(struct vty *vty, bool enable); int pim_process_ip_pim_passive_cmd(struct vty *vty, bool enable);