From b38a50fc95730825ceac08e0a5ee9db6e8d32729 Mon Sep 17 00:00:00 2001 From: Farid MIHOUB Date: Thu, 24 Aug 2023 10:23:01 +0200 Subject: [PATCH 1/2] pathd: add no command for pce/pce-config sub-commands Add "no" command for pcep pce/pce-config sub-commands, this will mainly restart configured options to default values. Signed-off-by: Farid Mihoub --- pathd/path_pcep_cli.c | 47 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index 6c660a3d08..a4b5fe0f74 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -741,7 +741,7 @@ 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; @@ -756,12 +756,12 @@ static int path_pcep_cli_peer_sr_draft07(struct vty *vty) return CMD_ERR_NO_MATCH; } - pce_config->draft07 = true; + pce_config->draft07 = reset ? DEFAULT_SR_DRAFT07 : true; 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; @@ -776,13 +776,14 @@ static int path_pcep_cli_peer_pce_initiated(struct vty *vty) return CMD_ERR_NO_MATCH; } - pce_config->pce_initiated = true; + pce_config->pce_initiated = reset ? DEFAULT_PCE_INITIATED : true; 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; @@ -797,8 +798,11 @@ static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty, 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)); return CMD_SUCCESS; } @@ -841,7 +845,8 @@ 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; if (vty->node == PCEP_PCE_NODE) { @@ -855,6 +860,12 @@ static int path_pcep_cli_peer_source_address(struct vty *vty, 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; @@ -1810,27 +1821,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 +1864,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 +1875,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, From 3b7c33ae74c057612da084d04ea8b2310cc768b1 Mon Sep 17 00:00:00 2001 From: Farid Mihoub Date: Wed, 30 Aug 2023 14:32:43 +0200 Subject: [PATCH 2/2] pathd: reset pcc peer connection when pce options modified Reset the PCC peer connection to take into account new changes of the PCE options. Signed-off-by: Farid Mihoub --- pathd/path_pcep_cli.c | 84 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index a4b5fe0f74..9880081f35 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -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); @@ -744,12 +745,13 @@ static int path_pcep_cli_show_srte_pcep_pce(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 = ¤t_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 = ¤t_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 { @@ -758,18 +760,24 @@ static int path_pcep_cli_peer_sr_draft07(struct vty *vty, bool reset) 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, bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_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 = ¤t_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 { @@ -778,6 +786,11 @@ static int path_pcep_cli_peer_pce_initiated(struct vty *vty, bool reset) 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; } @@ -786,12 +799,13 @@ static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty, bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_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 = ¤t_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 { @@ -804,6 +818,11 @@ static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty, 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; } @@ -849,11 +868,13 @@ static int path_pcep_cli_peer_source_address(struct vty *vty, bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_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 = ¤t_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 { @@ -881,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; } @@ -921,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 = ¤t_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 = ¤t_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 { @@ -963,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; } @@ -993,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)