bgpd: fix misc cli ranges & config writes

* Ranges for some MED were 2^32 - 2 instead of 2^32 - 1
* Use correct printf specifiers for unsigned values
* Some drive-by CLI collapsing and simplification

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2017-06-16 18:03:34 +00:00
parent 62e4232010
commit 4668a15109
2 changed files with 40 additions and 61 deletions

View File

@ -1249,7 +1249,7 @@ DEFUN (bgp_maxmed_admin,
DEFUN (bgp_maxmed_admin_medv,
bgp_maxmed_admin_medv_cmd,
"bgp max-med administrative (0-4294967294)",
"bgp max-med administrative (0-4294967295)",
BGP_STR
"Advertise routes with max-med\n"
"Administratively applied, for an indefinite period\n"
@ -1259,7 +1259,7 @@ DEFUN (bgp_maxmed_admin_medv,
int idx_number = 3;
bgp->v_maxmed_admin = 1;
VTY_GET_INTEGER ("max-med admin med-value", bgp->maxmed_admin_value, argv[idx_number]->arg);
bgp->maxmed_admin_value = strtoul (argv[idx_number]->arg, NULL, 10);
bgp_maxmed_update(bgp);
@ -1268,7 +1268,7 @@ DEFUN (bgp_maxmed_admin_medv,
DEFUN (no_bgp_maxmed_admin,
no_bgp_maxmed_admin_cmd,
"no bgp max-med administrative [(0-4294967294)]",
"no bgp max-med administrative [(0-4294967295)]",
NO_STR
BGP_STR
"Advertise routes with max-med\n"
@ -1285,24 +1285,7 @@ DEFUN (no_bgp_maxmed_admin,
DEFUN (bgp_maxmed_onstartup,
bgp_maxmed_onstartup_cmd,
"bgp max-med on-startup (5-86400)",
BGP_STR
"Advertise routes with max-med\n"
"Effective on a startup\n"
"Time (seconds) period for max-med\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx_number = 3;
VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
bgp_maxmed_update(bgp);
return CMD_SUCCESS;
}
DEFUN (bgp_maxmed_onstartup_medv,
bgp_maxmed_onstartup_medv_cmd,
"bgp max-med on-startup (5-86400) (0-4294967294)",
"bgp max-med on-startup (5-86400) [(0-4294967295)]",
BGP_STR
"Advertise routes with max-med\n"
"Effective on a startup\n"
@ -1310,10 +1293,15 @@ DEFUN (bgp_maxmed_onstartup_medv,
"Max MED value to be used\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx_number = 3;
int idx_number_2 = 4;
VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
VTY_GET_INTEGER ("max-med on-startup med-value", bgp->maxmed_onstartup_value, argv[idx_number_2]->arg);
int idx = 0;
argv_find (argv, argc, "(5-86400)", &idx);
bgp->v_maxmed_onstartup = strtoul (argv[idx]->arg, NULL, 10);
if (argv_find (argv, argc, "(0-4294967295)", &idx))
bgp->maxmed_onstartup_value = strtoul (argv[idx]->arg, NULL, 10);
else
bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
bgp_maxmed_update(bgp);
return CMD_SUCCESS;
@ -1321,7 +1309,7 @@ DEFUN (bgp_maxmed_onstartup_medv,
DEFUN (no_bgp_maxmed_onstartup,
no_bgp_maxmed_onstartup_cmd,
"no bgp max-med on-startup [(5-86400) [(0-4294967294)]]",
"no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
NO_STR
BGP_STR
"Advertise routes with max-med\n"
@ -1490,25 +1478,11 @@ DEFUN (no_bgp_wpkt_quanta,
return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
}
static int
bgp_coalesce_config_vty (struct vty *vty, const char *num, char set)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
if (set)
VTY_GET_INTEGER_RANGE ("coalesce-time", bgp->coalesce_time, num,
0, 4294967295);
else
bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
return CMD_SUCCESS;
}
int
bgp_config_write_coalesce_time (struct vty *vty, struct bgp *bgp)
{
if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
vty_out (vty, " coalesce-time %d%s",
vty_out (vty, " coalesce-time %u%s",
bgp->coalesce_time, VTY_NEWLINE);
return 0;
@ -1521,8 +1495,12 @@ DEFUN (bgp_coalesce_time,
"Subgroup coalesce timer\n"
"Subgroup coalesce timer value (in ms)\n")
{
int idx_number = 1;
return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 1);
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx = 0;
argv_find (argv, argc, "(0-4294967295)", &idx);
bgp->coalesce_time = strtoul (argv[idx]->arg, NULL, 10);
return CMD_SUCCESS;
}
DEFUN (no_bgp_coalesce_time,
@ -1532,8 +1510,10 @@ DEFUN (no_bgp_coalesce_time,
"Subgroup coalesce timer\n"
"Subgroup coalesce timer value (in ms)\n")
{
int idx_number = 2;
return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 0);
VTY_DECLVAR_CONTEXT(bgp, bgp);
bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
return CMD_SUCCESS;
}
/* Maximum-paths configuration */
@ -10993,7 +10973,6 @@ bgp_vty_init (void)
install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
install_element (BGP_NODE, &bgp_maxmed_onstartup_medv_cmd);
/* bgp disable-ebgp-connected-nh-check */
install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);

View File

@ -6798,7 +6798,7 @@ bgp_config_write_peer_global (struct vty *vty, struct bgp *bgp,
((! peer_group_active (peer) && peer->v_routeadv != BGP_DEFAULT_EBGP_ROUTEADV) ||
(peer_group_active (peer) && peer->v_routeadv != g_peer->v_routeadv)))
{
vty_out (vty, " neighbor %s advertisement-interval %d%s",
vty_out (vty, " neighbor %s advertisement-interval %u%s",
addr, peer->v_routeadv, VTY_NEWLINE);
}
@ -6807,7 +6807,7 @@ bgp_config_write_peer_global (struct vty *vty, struct bgp *bgp,
((! peer_group_active (peer) && (peer->keepalive != BGP_DEFAULT_KEEPALIVE || peer->holdtime != BGP_DEFAULT_HOLDTIME)) ||
(peer_group_active (peer) && (peer->keepalive != g_peer->keepalive || peer->holdtime != g_peer->holdtime))))
{
vty_out (vty, " neighbor %s timers %d %d%s", addr,
vty_out (vty, " neighbor %s timers %u %u%s", addr,
peer->keepalive, peer->holdtime, VTY_NEWLINE);
}
@ -6816,7 +6816,7 @@ bgp_config_write_peer_global (struct vty *vty, struct bgp *bgp,
(peer_group_active (peer) && peer->connect != g_peer->connect)))
{
vty_out (vty, " neighbor %s timers connect %d%s", addr,
vty_out (vty, " neighbor %s timers connect %u%s", addr,
peer->connect, VTY_NEWLINE);
}
@ -7159,11 +7159,11 @@ bgp_config_write_peer_af (struct vty *vty, struct bgp *bgp,
" neighbor %s maximum-prefix %lu",
addr, peer->pmax[afi][safi]);
if (peer->pmax_threshold[afi][safi] != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
vty_out (vty, " %d", peer->pmax_threshold[afi][safi]);
vty_out (vty, " %u", peer->pmax_threshold[afi][safi]);
if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
vty_out (vty, " warning-only");
if (peer->pmax_restart[afi][safi])
vty_out (vty, " restart %d", peer->pmax_restart[afi][safi]);
vty_out (vty, " restart %u", peer->pmax_restart[afi][safi]);
vty_out (vty, "%s", VTY_NEWLINE);
}
@ -7226,7 +7226,7 @@ bgp_config_write_peer_af (struct vty *vty, struct bgp *bgp,
if (peer->weight[afi][safi])
{
afi_header_vty_out (vty, afi, safi, write,
" neighbor %s weight %d%s",
" neighbor %s weight %lu%s",
addr, peer->weight[afi][safi], VTY_NEWLINE);
}
}
@ -7371,7 +7371,7 @@ bgp_config_write (struct vty *vty)
}
if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
vty_out (vty, "bgp route-map delay-timer %d%s", bm->rmap_update_timer,
vty_out (vty, "bgp route-map delay-timer %u%s", bm->rmap_update_timer,
VTY_NEWLINE);
/* BGP configuration. */
@ -7422,7 +7422,7 @@ bgp_config_write (struct vty *vty)
/* BGP default local-preference. */
if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
vty_out (vty, " bgp default local-preference %d%s",
vty_out (vty, " bgp default local-preference %u%s",
bgp->default_local_pref, VTY_NEWLINE);
/* BGP default show-hostname */
@ -7434,7 +7434,7 @@ bgp_config_write (struct vty *vty)
/* BGP default subgroup-pkt-queue-max. */
if (bgp->default_subgroup_pkt_queue_max != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
vty_out (vty, " bgp default subgroup-pkt-queue-max %d%s",
vty_out (vty, " bgp default subgroup-pkt-queue-max %u%s",
bgp->default_subgroup_pkt_queue_max, VTY_NEWLINE);
/* BGP client-to-client reflection. */
@ -7484,16 +7484,16 @@ bgp_config_write (struct vty *vty)
if (bgp->v_maxmed_onstartup != BGP_MAXMED_ONSTARTUP_UNCONFIGURED)
{
vty_out (vty, " bgp max-med on-startup %d", bgp->v_maxmed_onstartup);
vty_out (vty, " bgp max-med on-startup %u", bgp->v_maxmed_onstartup);
if (bgp->maxmed_onstartup_value != BGP_MAXMED_VALUE_DEFAULT)
vty_out (vty, " %d", bgp->maxmed_onstartup_value);
vty_out (vty, " %u", bgp->maxmed_onstartup_value);
vty_out (vty, "%s", VTY_NEWLINE);
}
if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED)
{
vty_out (vty, " bgp max-med administrative");
if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
vty_out (vty, " %d", bgp->maxmed_admin_value);
vty_out (vty, " %u", bgp->maxmed_admin_value);
vty_out (vty, "%s", VTY_NEWLINE);
}
@ -7505,10 +7505,10 @@ bgp_config_write (struct vty *vty)
/* BGP graceful-restart. */
if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
vty_out (vty, " bgp graceful-restart stalepath-time %d%s",
vty_out (vty, " bgp graceful-restart stalepath-time %u%s",
bgp->stalepath_time, VTY_NEWLINE);
if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
vty_out (vty, " bgp graceful-restart restart-time %d%s",
vty_out (vty, " bgp graceful-restart restart-time %u%s",
bgp->restart_time, VTY_NEWLINE);
if (bgp_flag_check (bgp, BGP_FLAG_GRACEFUL_RESTART))
vty_out (vty, " bgp graceful-restart%s", VTY_NEWLINE);
@ -7567,7 +7567,7 @@ bgp_config_write (struct vty *vty)
/* BGP timers configuration. */
if (bgp->default_keepalive != BGP_DEFAULT_KEEPALIVE
&& bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
vty_out (vty, " timers bgp %d %d%s", bgp->default_keepalive,
vty_out (vty, " timers bgp %u %u%s", bgp->default_keepalive,
bgp->default_holdtime, VTY_NEWLINE);
/* peer-group */