summaryrefslogtreecommitdiffstats
path: root/src/vty
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-09-17 13:13:52 +0200
committerpespin <pespin@sysmocom.de>2019-10-07 13:14:14 +0000
commit0cbe8f01003ca71209c12eacac3abaeb9a7df862 (patch)
tree7b867229dd5492857a010b3da4c850c47d887f31 /src/vty
parent4ad3cb1044df8538f8014e8e2ac6d1dc0dc0c451 (diff)
tdef: Introduce min_val and max_val fields
This is useful for timers expected to have a range of valid or expected values. Validation is done at runtime when timer values are set by the app or by the user through the VTY. Related: OS#4190 Change-Id: I4661ac41c29a009a1d5fc57d87aaee6041c7d1b2
Diffstat (limited to 'src/vty')
-rw-r--r--src/vty/tdef_vty.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/vty/tdef_vty.c b/src/vty/tdef_vty.c
index eb05c3c5..4549a61c 100644
--- a/src/vty/tdef_vty.c
+++ b/src/vty/tdef_vty.c
@@ -115,12 +115,22 @@ unsigned long osmo_tdef_vty_parse_val_arg(const char *val_arg, unsigned long def
*/
int osmo_tdef_vty_set_cmd(struct vty *vty, struct osmo_tdef *tdefs, const char **args)
{
+ unsigned long new_val;
const char *T_arg = args[0];
const char *val_arg = args[1];
struct osmo_tdef *t = osmo_tdef_vty_parse_T_arg(vty, tdefs, T_arg);
if (!t)
return CMD_WARNING;
- t->val = osmo_tdef_vty_parse_val_arg(val_arg, t->default_val);
+ new_val = osmo_tdef_vty_parse_val_arg(val_arg, t->default_val);
+
+ if (!osmo_tdef_val_in_range(t, new_val)) {
+ char range_str[64];
+ osmo_tdef_range_str_buf(range_str, sizeof(range_str), t);
+ vty_out(vty, "%% Timer " OSMO_T_FMT " value %lu is out of range %s%s",
+ OSMO_T_FMT_ARGS(t->T), new_val, range_str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ t->val = new_val;
return CMD_SUCCESS;
}
@@ -161,18 +171,29 @@ int osmo_tdef_vty_show_cmd(struct vty *vty, struct osmo_tdef *tdefs, const char
*/
void osmo_tdef_vty_out_one_va(struct vty *vty, struct osmo_tdef *t, const char *prefix_fmt, va_list va)
{
+ char range_str[64];
+
if (!t) {
vty_out(vty, "%% Error: no such timer%s", VTY_NEWLINE);
return;
}
if (prefix_fmt)
vty_out_va(vty, prefix_fmt, va);
- vty_out(vty, OSMO_T_FMT " = %lu%s%s\t%s (default: %lu%s%s)%s",
- OSMO_T_FMT_ARGS(t->T), t->val,
- t->unit == OSMO_TDEF_CUSTOM ? "" : " ", t->unit == OSMO_TDEF_CUSTOM ? "" : osmo_tdef_unit_name(t->unit),
- t->desc, t->default_val,
- t->unit == OSMO_TDEF_CUSTOM ? "" : " ", t->unit == OSMO_TDEF_CUSTOM ? "" : osmo_tdef_unit_name(t->unit),
- VTY_NEWLINE);
+
+ vty_out(vty, OSMO_T_FMT " = %lu", OSMO_T_FMT_ARGS(t->T), t->val);
+ if (t->unit != OSMO_TDEF_CUSTOM)
+ vty_out(vty, " %s", osmo_tdef_unit_name(t->unit));
+
+ vty_out(vty, "\t%s (default: %lu", t->desc, t->default_val);
+ if (t->unit != OSMO_TDEF_CUSTOM)
+ vty_out(vty, " %s", osmo_tdef_unit_name(t->unit));
+
+ if (t->min_val || t->max_val) {
+ osmo_tdef_range_str_buf(range_str, sizeof(range_str), t);
+ vty_out(vty, ", range: %s", range_str);
+ }
+
+ vty_out(vty, ")%s", VTY_NEWLINE);
}
/*! Write to VTY the current status of one timer.