Merge pull request #14350 from FRIDM636/pcep-no-commands

pathd: add no command for pce/pce-config options
This commit is contained in:
Russ White 2023-09-19 10:08:43 -04:00 committed by GitHub
commit 078dc7bd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,6 +52,7 @@ static int pcep_cli_pce_config_write(struct vty *vty);
static int pcep_cli_pcep_pce_config_write(struct vty *vty);
/* Internal Util Function declarations */
static void reset_pcc_peer(const char *peer_name);
static struct pce_opts_cli *pcep_cli_find_pce(const char *pce_name);
static bool pcep_cli_add_pce(struct pce_opts_cli *pce_opts_cli);
static struct pce_opts_cli *pcep_cli_create_pce_opts(const char *name);
@ -741,64 +742,86 @@ static int path_pcep_cli_show_srte_pcep_pce(struct vty *vty,
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_sr_draft07(struct vty *vty)
static int path_pcep_cli_peer_sr_draft07(struct vty *vty, bool reset)
{
struct pcep_config_group_opts *pce_config = NULL;
struct pce_opts *pce_opts = &current_pce_opts_g->pce_opts;
bool pce_in_use = false;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = &current_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name);
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
pce_config->draft07 = true;
pce_config->draft07 = reset ? DEFAULT_SR_DRAFT07 : true;
if (pce_in_use) {
vty_out(vty, "%% PCE in use, resetting pcc peer session...\n");
reset_pcc_peer(pce_opts->pce_name);
}
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_pce_initiated(struct vty *vty)
static int path_pcep_cli_peer_pce_initiated(struct vty *vty, bool reset)
{
struct pcep_config_group_opts *pce_config = NULL;
struct pce_opts *pce_opts = &current_pce_opts_g->pce_opts;
bool pce_in_use = false;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = &current_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name);
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
pce_config->pce_initiated = true;
pce_config->pce_initiated = reset ? DEFAULT_PCE_INITIATED : true;
if (pce_in_use) {
vty_out(vty, "%% PCE in use, resetting pcc peer session...\n");
reset_pcc_peer(pce_opts->pce_name);
}
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty,
const char *tcp_md5_auth)
const char *tcp_md5_auth,
bool reset)
{
struct pcep_config_group_opts *pce_config = NULL;
struct pce_opts *pce_opts = &current_pce_opts_g->pce_opts;
bool pce_in_use = false;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = &current_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name);
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
strlcpy(pce_config->tcp_md5_auth, tcp_md5_auth,
sizeof(pce_config->tcp_md5_auth));
if (reset)
pce_config->tcp_md5_auth[0] = '\0';
else
strlcpy(pce_config->tcp_md5_auth, tcp_md5_auth,
sizeof(pce_config->tcp_md5_auth));
if (pce_in_use) {
vty_out(vty, "%% PCE in use, resetting pcc peer session...\n");
reset_pcc_peer(pce_opts->pce_name);
}
return CMD_SUCCESS;
}
@ -841,20 +864,29 @@ static int path_pcep_cli_peer_source_address(struct vty *vty,
struct in_addr *ip,
const char *ipv6_str,
struct in6_addr *ipv6,
const char *port_str, long port)
const char *port_str, long port,
bool reset)
{
struct pcep_config_group_opts *pce_config = NULL;
struct pce_opts *pce_opts = &current_pce_opts_g->pce_opts;
bool pce_in_use = false;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = &current_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name);
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
if (reset) {
pce_config->source_ip.ipa_type = IPADDR_NONE;
pce_config->source_port = 0;
return CMD_SUCCESS;
}
/* Handle the optional source IP */
if (ipv6_str != NULL) {
pce_config->source_ip.ipa_type = IPADDR_V6;
@ -870,6 +902,11 @@ static int path_pcep_cli_peer_source_address(struct vty *vty,
PCEP_VTYSH_INT_ARG_CHECK(port_str, port, pce_config->source_port, 0,
65535);
if (pce_in_use) {
vty_out(vty, "%% PCE in use, resetting pcc peer session...\n");
reset_pcc_peer(pce_opts->pce_name);
}
return CMD_SUCCESS;
}
@ -910,11 +947,13 @@ static int path_pcep_cli_peer_timers(
const char *delegation_timeout_str, long delegation_timeout)
{
struct pcep_config_group_opts *pce_config = NULL;
struct pce_opts *pce_opts = &current_pce_opts_g->pce_opts;
bool pce_in_use = false;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = &current_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name);
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
@ -952,6 +991,11 @@ static int path_pcep_cli_peer_timers(
PCEP_VTYSH_INT_ARG_CHECK(delegation_timeout_str, delegation_timeout,
pce_config->delegation_timeout_seconds, 0, 61);
if (pce_in_use) {
vty_out(vty, "%% PCE in use, resetting pcc peer session...\n");
reset_pcc_peer(pce_opts->pce_name);
}
return CMD_SUCCESS;
}
@ -982,6 +1026,37 @@ static int path_pcep_cli_pcc_pcc_msd(struct vty *vty, const char *msd_str,
return CMD_SUCCESS;
}
void reset_pcc_peer(const char *peer_name)
{
struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(peer_name);
/* Remove the pcc peer */
pcep_cli_remove_pce_connection(&pce_opts_cli->pce_opts);
struct pce_opts *pce_opts_copy =
XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts));
memcpy(pce_opts_copy, &pce_opts_cli->pce_opts, sizeof(struct pce_opts));
pcep_ctrl_remove_pcc(pcep_g->fpt, pce_opts_copy);
/* Re-add the pcc peer */
pcep_cli_merge_pcep_pce_config_options(pce_opts_cli);
pcep_cli_add_pce_connection(&pce_opts_cli->pce_opts);
/* Update the pcc_opts */
struct pcc_opts *pcc_opts_copy =
XMALLOC(MTYPE_PCEP, sizeof(struct pcc_opts));
memcpy(&pcc_opts_copy->addr,
&pce_opts_cli->pce_opts.config_opts.source_ip,
sizeof(pcc_opts_copy->addr));
pcc_opts_copy->msd = pcc_msd_g;
pcc_opts_copy->port = pce_opts_cli->pce_opts.config_opts.source_port;
pcep_ctrl_update_pcc_options(pcep_g->fpt, pcc_opts_copy);
/* Update the pce_opts */
pce_opts_copy = XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts));
memcpy(pce_opts_copy, &pce_opts_cli->pce_opts, sizeof(struct pce_opts));
pcep_ctrl_update_pce_options(pcep_g->fpt, pce_opts_copy);
}
static int path_pcep_cli_pcc_pcc_peer(struct vty *vty, const char *peer_name,
const char *precedence_str,
long precedence)
@ -1810,27 +1885,30 @@ DEFPY(pcep_cli_show_srte_pcep_pce,
DEFPY(pcep_cli_peer_sr_draft07,
pcep_cli_peer_sr_draft07_cmd,
"sr-draft07",
"[no] sr-draft07",
NO_STR
"Configure PCC to send PCEP Open with SR draft07\n")
{
return path_pcep_cli_peer_sr_draft07(vty);
return path_pcep_cli_peer_sr_draft07(vty, no);
}
DEFPY(pcep_cli_peer_pce_initiated,
pcep_cli_peer_pce_initiated_cmd,
"pce-initiated",
"[no] pce-initiated",
NO_STR
"Configure PCC to accept PCE initiated LSPs\n")
{
return path_pcep_cli_peer_pce_initiated(vty);
return path_pcep_cli_peer_pce_initiated(vty, no);
}
DEFPY(pcep_cli_peer_tcp_md5_auth,
pcep_cli_peer_tcp_md5_auth_cmd,
"tcp-md5-auth WORD",
"[no] tcp-md5-auth WORD",
NO_STR
"Configure PCC TCP-MD5 RFC2385 Authentication\n"
"TCP-MD5 Authentication string\n")
{
return path_pcep_cli_peer_tcp_md5_auth(vty, tcp_md5_auth);
return path_pcep_cli_peer_tcp_md5_auth(vty, tcp_md5_auth, no);
}
DEFPY(pcep_cli_peer_address,
@ -1850,7 +1928,8 @@ DEFPY(pcep_cli_peer_address,
DEFPY(pcep_cli_peer_source_address,
pcep_cli_peer_source_address_cmd,
"source-address [ip A.B.C.D | ipv6 X:X::X:X] [port (1024-65535)]",
"[no] source-address [ip A.B.C.D | ipv6 X:X::X:X] [port (1024-65535)]",
NO_STR
"PCE source IP Address configuration\n"
"PCE source IPv4 address\n"
"PCE source IPv4 address value\n"
@ -1860,7 +1939,7 @@ DEFPY(pcep_cli_peer_source_address,
"Source PCE server port value\n")
{
return path_pcep_cli_peer_source_address(vty, ip_str, &ip, ipv6_str,
&ipv6, port_str, port);
&ipv6, port_str, port, no);
}
DEFPY(pcep_cli_peer_pcep_pce_config_ref,