From 441e2078708f7380e77031b710bd7e2650a99c3f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 13 Aug 2023 17:24:21 +0200 Subject: [PATCH] Add a user-configurable name for each interface This name is subsequently used in all related log lines, VTY output, etc. instead of the auto-genreated "IF%u" string with the interface number. --- src/v5le_vty.c | 37 ++++++++++++++++++++++++++++++++++++- src/v5x_data.c | 4 ++++ src/v5x_internal.h | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/v5le_vty.c b/src/v5le_vty.c index 74293b7..39e9e1e 100644 --- a/src/v5le_vty.c +++ b/src/v5le_vty.c @@ -185,7 +185,8 @@ DEFUN(show_interface, show_interface_cmd, return CMD_WARNING; } - vty_out(vty, "Interface %d %s:%s", v5if->id, (v5if->dialect == V5X_DIALECT_V51) ? "V5.1" : "V5.2", VTY_NEWLINE); + vty_out(vty, "Interface %d %s %s:%s", v5if->id, v5if->name ? v5if->name : "(unnamed)", + (v5if->dialect == V5X_DIALECT_V51) ? "V5.1" : "V5.2", VTY_NEWLINE); vty_out(vty, " Trigger system restart: %s%s", (v5if->mgmt->auto_restart) ? "automatic" : "manual", VTY_NEWLINE); vty_out(vty, " Trigger data links: %s%s", (v5if->mgmt->do_est) ? "yes" : "no", VTY_NEWLINE); vty_out(vty, " Enable PSTN datalink: %s statup)%s", (v5if->mgmt->pstn_enable_early) ? "early (before" : "late (after", VTY_NEWLINE); @@ -694,6 +695,32 @@ DEFUN(cfg_no_interface, cfg_no_interface_cmd, return CMD_SUCCESS; } +DEFUN(cfg_name, cfg_name_cmd, + "name NAME", + "Set a descriptive name for this interface") +{ + struct v5x_interface *v5if = vty->index; + + if (!osmo_identifier_valid(argv[0])) { + vty_out(vty, "%% Name is not a valid identifier.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + osmo_talloc_replace_string(v5if, &v5if->name, argv[0]); + return CMD_SUCCESS; +} + +DEFUN(cfg_no_name, cfg_no_name_cmd, + "no name", + NO_STR "Remove the descriptive name for this interface") +{ + struct v5x_interface *v5if = vty->index; + + talloc_free(v5if->name); + v5if->name = NULL; + return CMD_SUCCESS; +} + DEFUN(cfg_auto_restart, cfg_auto_restart_cmd, "auto-restart", "Automatically restart interface in case of failure") @@ -1164,6 +1191,8 @@ static void config_write_interface_v51(struct vty *vty, struct v5x_interface *v5 vty_out(vty, "!%s", VTY_NEWLINE); v5l = llist_first_entry(&v5if->links, struct v5x_link, list); vty_out(vty, "interface %d v5.1%s", v5if->id, VTY_NEWLINE); + if (v5if->name) + vty_out(vty, " name %s%s", v5if->name, VTY_NEWLINE); vty_out(vty, " %sauto-restart%s", (v5if->mgmt->auto_restart) ? "" : "no ", VTY_NEWLINE); vty_out(vty, " %sestablish%s", (v5if->mgmt->do_est) ? "" : "no ", VTY_NEWLINE); vty_out(vty, " pstn-enable %s %s", (v5if->mgmt->pstn_enable_early) ? "early" : "late", VTY_NEWLINE); @@ -1183,6 +1212,8 @@ static void config_write_interface_v52(struct vty *vty, struct v5x_interface *v5 vty_out(vty, "!%s", VTY_NEWLINE); vty_out(vty, "interface %d v5.2%s", v5if->id, VTY_NEWLINE); + if (v5if->name) + vty_out(vty, " name %s%s", v5if->name, VTY_NEWLINE); vty_out(vty, " %sauto-restart%s", (v5if->mgmt->auto_restart) ? "" : "no ", VTY_NEWLINE); vty_out(vty, " %sestablish%s", (v5if->mgmt->do_est) ? "" : "no ", VTY_NEWLINE); vty_out(vty, " pstn-enable %s %s", (v5if->mgmt->pstn_enable_early) ? "early" : "late", VTY_NEWLINE); @@ -1249,6 +1280,8 @@ int v5le_vty_init(void) install_element(CONFIG_NODE, &cfg_no_interface_cmd); install_node(&config_interface_node_v51, config_write_interfaces); install_node(&config_interface_node_v52, NULL); + install_element(CONFIG_INTERFACE_NODE_V51, &cfg_name_cmd); + install_element(CONFIG_INTERFACE_NODE_V51, &cfg_no_name_cmd); install_element(CONFIG_INTERFACE_NODE_V51, &cfg_auto_restart_cmd); install_element(CONFIG_INTERFACE_NODE_V51, &cfg_no_auto_restart_cmd); install_element(CONFIG_INTERFACE_NODE_V51, &cfg_establish_cmd); @@ -1264,6 +1297,8 @@ int v5le_vty_init(void) install_element(CONFIG_INTERFACE_NODE_V51, &cfg_port_isdn_cmd_v51); install_element(CONFIG_INTERFACE_NODE_V51, &cfg_port_isdn_cmd); install_element(CONFIG_INTERFACE_NODE_V51, &cfg_no_port_isdn_cmd); + install_element(CONFIG_INTERFACE_NODE_V52, &cfg_name_cmd); + install_element(CONFIG_INTERFACE_NODE_V52, &cfg_no_name_cmd); install_element(CONFIG_INTERFACE_NODE_V52, &cfg_auto_restart_cmd); install_element(CONFIG_INTERFACE_NODE_V52, &cfg_no_auto_restart_cmd); install_element(CONFIG_INTERFACE_NODE_V52, &cfg_establish_cmd); diff --git a/src/v5x_data.c b/src/v5x_data.c index 05066ba..020f450 100644 --- a/src/v5x_data.c +++ b/src/v5x_data.c @@ -572,6 +572,10 @@ struct v5x_link *v5x_link_find_id(struct v5x_interface *v5if, uint8_t id) const char *v5x_interface_name(const struct v5x_interface *v5if) { static char buf[16]; + + if (v5if->name) + return v5if->name; + snprintf(buf, sizeof(buf), "IF%u", v5if->id); return buf; } diff --git a/src/v5x_internal.h b/src/v5x_internal.h index 6140c56..a66f3f3 100644 --- a/src/v5x_internal.h +++ b/src/v5x_internal.h @@ -211,6 +211,7 @@ struct v5x_link { struct v5x_interface { struct llist_head list; /* instance.interfaces */ struct v5x_instance *instance; /* back-pointer */ + char *name; /* user-configurable name */ enum v5x_dialect dialect; uint32_t id, id_remote; /* interface id */ uint8_t variant, variant_remote; /* provisioning variant */