mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-03 05:21:31 +00:00
isisd: use ferr_* functions
Drop redundant checks & use ferr_* to print CLI error messages. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
3155489aa2
commit
64dd3ffe7e
@ -1190,13 +1190,13 @@ void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
|
||||
lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
|
||||
}
|
||||
|
||||
int isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
|
||||
ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
|
||||
{
|
||||
if (circuit->is_passive == passive)
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
|
||||
if (if_is_loopback(circuit->interface) && !passive)
|
||||
return -1;
|
||||
return ferr_cfg_invalid("loopback is always passive");
|
||||
|
||||
if (circuit->state != C_STATE_UP) {
|
||||
circuit->is_passive = passive;
|
||||
@ -1207,30 +1207,33 @@ int isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
|
||||
isis_csm_state_change(ISIS_ENABLE, circuit, area);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
}
|
||||
|
||||
int isis_circuit_metric_set(struct isis_circuit *circuit, int level, int metric)
|
||||
ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
|
||||
int metric)
|
||||
{
|
||||
assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
|
||||
if (metric > MAX_WIDE_LINK_METRIC)
|
||||
return -1;
|
||||
return ferr_cfg_invalid("metric %d too large for wide metric",
|
||||
metric);
|
||||
if (circuit->area && circuit->area->oldmetric
|
||||
&& metric > MAX_NARROW_LINK_METRIC)
|
||||
return -1;
|
||||
return ferr_cfg_invalid("metric %d too large for narrow metric",
|
||||
metric);
|
||||
|
||||
circuit->te_metric[level - 1] = metric;
|
||||
circuit->metric[level - 1] = metric;
|
||||
|
||||
if (circuit->area)
|
||||
lsp_regenerate_schedule(circuit->area, level, 0);
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
}
|
||||
|
||||
int isis_circuit_passwd_unset(struct isis_circuit *circuit)
|
||||
ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
|
||||
{
|
||||
memset(&circuit->passwd, 0, sizeof(circuit->passwd));
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
}
|
||||
|
||||
static int isis_circuit_passwd_set(struct isis_circuit *circuit,
|
||||
@ -1239,50 +1242,50 @@ static int isis_circuit_passwd_set(struct isis_circuit *circuit,
|
||||
int len;
|
||||
|
||||
if (!passwd)
|
||||
return -1;
|
||||
return ferr_code_bug("no circuit password given");
|
||||
|
||||
len = strlen(passwd);
|
||||
if (len > 254)
|
||||
return -1;
|
||||
return ferr_code_bug(
|
||||
"circuit password too long (max 254 chars)");
|
||||
|
||||
circuit->passwd.len = len;
|
||||
strncpy((char *)circuit->passwd.passwd, passwd, 255);
|
||||
circuit->passwd.type = passwd_type;
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
}
|
||||
|
||||
int isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
|
||||
const char *passwd)
|
||||
ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
|
||||
const char *passwd)
|
||||
{
|
||||
return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
|
||||
passwd);
|
||||
}
|
||||
|
||||
int isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
|
||||
const char *passwd)
|
||||
ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
|
||||
const char *passwd)
|
||||
{
|
||||
return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
|
||||
passwd);
|
||||
}
|
||||
|
||||
struct cmd_node interface_node = {
|
||||
INTERFACE_NODE, "%s(config-if)# ", 1,
|
||||
};
|
||||
|
||||
int isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
|
||||
ferr_r isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
|
||||
{
|
||||
if (circuit->circ_type == circ_type)
|
||||
return ferr_ok();
|
||||
|
||||
/* Changing the network type to/of loopback or unknown interfaces
|
||||
* is not supported. */
|
||||
if (circ_type == CIRCUIT_T_UNKNOWN || circ_type == CIRCUIT_T_LOOPBACK
|
||||
|| circuit->circ_type == CIRCUIT_T_LOOPBACK) {
|
||||
if (circuit->circ_type != circ_type)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
return ferr_cfg_invalid(
|
||||
"cannot change network type on unknown interface");
|
||||
}
|
||||
|
||||
if (circuit->circ_type == circ_type)
|
||||
return 0;
|
||||
|
||||
if (circuit->state != C_STATE_UP) {
|
||||
circuit->circ_type = circ_type;
|
||||
circuit->circ_type_config = circ_type;
|
||||
@ -1290,14 +1293,15 @@ int isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
|
||||
struct isis_area *area = circuit->area;
|
||||
if (circ_type == CIRCUIT_T_BROADCAST
|
||||
&& !if_is_broadcast(circuit->interface))
|
||||
return -1;
|
||||
return ferr_cfg_reality(
|
||||
"cannot configure non-broadcast interface for broadcast operation");
|
||||
|
||||
isis_csm_state_change(ISIS_DISABLE, circuit, area);
|
||||
circuit->circ_type = circ_type;
|
||||
circuit->circ_type_config = circ_type;
|
||||
isis_csm_state_change(ISIS_ENABLE, circuit, area);
|
||||
}
|
||||
return 0;
|
||||
return ferr_ok();
|
||||
}
|
||||
|
||||
int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "if.h"
|
||||
#include "qobj.h"
|
||||
#include "prefix.h"
|
||||
#include "ferr.h"
|
||||
|
||||
#include "isis_constants.h"
|
||||
#include "isis_common.h"
|
||||
@ -178,18 +179,18 @@ struct isis_circuit *isis_circuit_create(struct isis_area *area,
|
||||
struct interface *ifp);
|
||||
void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
|
||||
bool ipv6_router);
|
||||
int isis_circuit_passive_set(struct isis_circuit *circuit, bool passive);
|
||||
ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive);
|
||||
void isis_circuit_is_type_set(struct isis_circuit *circuit, int is_type);
|
||||
int isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type);
|
||||
ferr_r isis_circuit_circ_type_set (struct isis_circuit *circuit, int circ_type);
|
||||
|
||||
int isis_circuit_metric_set(struct isis_circuit *circuit, int level,
|
||||
int metric);
|
||||
ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
|
||||
int metric);
|
||||
|
||||
int isis_circuit_passwd_unset(struct isis_circuit *circuit);
|
||||
int isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
|
||||
const char *passwd);
|
||||
int isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
|
||||
const char *passwd);
|
||||
ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit);
|
||||
ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
|
||||
const char *passwd);
|
||||
ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
|
||||
const char *passwd);
|
||||
|
||||
int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
|
||||
bool enabled);
|
||||
|
@ -164,7 +164,8 @@ DEFUN (isis_passive,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
isis_circuit_passive_set(circuit, 1);
|
||||
CMD_FERR_RETURN(isis_circuit_passive_set(circuit, 1),
|
||||
"Cannot set passive: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -179,12 +180,8 @@ DEFUN (no_isis_passive,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
if (if_is_loopback(circuit->interface)) {
|
||||
vty_out(vty, "Can't set no passive for loopback interface\n");
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
isis_circuit_passive_set(circuit, 0);
|
||||
CMD_FERR_RETURN(isis_circuit_passive_set(circuit, 0),
|
||||
"Cannot set no passive: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -301,7 +298,8 @@ DEFUN (isis_passwd,
|
||||
int idx_encryption = 2;
|
||||
int idx_word = 3;
|
||||
struct isis_circuit *circuit = isis_circuit_lookup(vty);
|
||||
int rv;
|
||||
ferr_r rv;
|
||||
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
@ -311,11 +309,8 @@ DEFUN (isis_passwd,
|
||||
else
|
||||
rv = isis_circuit_passwd_cleartext_set(circuit,
|
||||
argv[idx_word]->arg);
|
||||
if (rv) {
|
||||
vty_out(vty, "Too long circuit password (>254)\n");
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
CMD_FERR_RETURN(rv, "Failed to set circuit password: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -333,8 +328,8 @@ DEFUN (no_isis_passwd,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
isis_circuit_passwd_unset(circuit);
|
||||
|
||||
CMD_FERR_RETURN(isis_circuit_passwd_unset(circuit),
|
||||
"Failed to unset circuit password: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -507,8 +502,10 @@ DEFUN (isis_metric,
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_1, met);
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_2, met);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_1, met),
|
||||
"Failed to set L1 metric: $ERR");
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_2, met),
|
||||
"Failed to set L2 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -525,8 +522,12 @@ DEFUN (no_isis_metric,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC);
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_1,
|
||||
DEFAULT_CIRCUIT_METRIC),
|
||||
"Failed to set L1 metric: $ERR");
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_2,
|
||||
DEFAULT_CIRCUIT_METRIC),
|
||||
"Failed to set L2 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -546,28 +547,8 @@ DEFUN (isis_metric_l1,
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
met = atoi(argv[idx_number]->arg);
|
||||
|
||||
/* RFC3787 section 5.1 */
|
||||
if (circuit->area && circuit->area->oldmetric == 1
|
||||
&& met > MAX_NARROW_LINK_METRIC) {
|
||||
vty_out(vty,
|
||||
"Invalid metric %d - should be <0-63> "
|
||||
"when narrow metric type enabled\n",
|
||||
met);
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
/* RFC4444 */
|
||||
if (circuit->area && circuit->area->newmetric == 1
|
||||
&& met > MAX_WIDE_LINK_METRIC) {
|
||||
vty_out(vty,
|
||||
"Invalid metric %d - should be <0-16777215> "
|
||||
"when wide metric type enabled\n",
|
||||
met);
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_1, met);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_1, met),
|
||||
"Failed to set L1 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -585,7 +566,9 @@ DEFUN (no_isis_metric_l1,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_1,
|
||||
DEFAULT_CIRCUIT_METRIC),
|
||||
"Failed to set L1 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -605,28 +588,8 @@ DEFUN (isis_metric_l2,
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
met = atoi(argv[idx_number]->arg);
|
||||
|
||||
/* RFC3787 section 5.1 */
|
||||
if (circuit->area && circuit->area->oldmetric == 1
|
||||
&& met > MAX_NARROW_LINK_METRIC) {
|
||||
vty_out(vty,
|
||||
"Invalid metric %d - should be <0-63> "
|
||||
"when narrow metric type enabled\n",
|
||||
met);
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
/* RFC4444 */
|
||||
if (circuit->area && circuit->area->newmetric == 1
|
||||
&& met > MAX_WIDE_LINK_METRIC) {
|
||||
vty_out(vty,
|
||||
"Invalid metric %d - should be <0-16777215> "
|
||||
"when wide metric type enabled\n",
|
||||
met);
|
||||
return CMD_WARNING_CONFIG_FAILED;
|
||||
}
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_2, met);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_2, met),
|
||||
"Failed to set L2 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@ -644,7 +607,9 @@ DEFUN (no_isis_metric_l2,
|
||||
if (!circuit)
|
||||
return CMD_ERR_NO_MATCH;
|
||||
|
||||
isis_circuit_metric_set(circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC);
|
||||
CMD_FERR_RETURN(isis_circuit_metric_set(circuit, IS_LEVEL_2,
|
||||
DEFAULT_CIRCUIT_METRIC),
|
||||
"Failed to set L2 metric: $ERR");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user