return 1;
}
+static int
+cmd_portdescr_type(struct lldpctl_conn_t *conn, struct writer *w,
+ struct cmd_env *env, const void *arg)
+{
+ const char *value_str = arg;
+ int value = -1;
+
+ log_debug("lldpctl", "lldp port description source");
+
+ lldpctl_atom_t *config = lldpctl_get_configuration(conn);
+ if (config == NULL) {
+ log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
+ lldpctl_last_strerror(conn));
+ return 0;
+ }
+
+ for (lldpctl_map_t *b_map =
+ lldpctl_key_get_map(lldpctl_k_config_lldp_portdescr_type);
+ b_map->string; b_map++) {
+ if (!strcmp(b_map->string, value_str)) {
+ value = b_map->value;
+ break;
+ }
+ }
+
+ if (value == -1) {
+ log_warnx("lldpctl", "invalid value");
+ lldpctl_atom_dec_ref(config);
+ return 0;
+ }
+
+ if (lldpctl_atom_set_int(config, lldpctl_k_config_lldp_portdescr_type, value) ==
+ NULL) {
+ log_warnx("lldpctl",
+ "unable to set port description source. %s",
+ lldpctl_last_strerror(conn));
+ lldpctl_atom_dec_ref(config);
+ return 0;
+ }
+
+ log_info("lldpctl", "port description source set to %s", value_str);
+ lldpctl_atom_dec_ref(config);
+
+ return 1;
+}
+
static int
cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w,
struct cmd_env *env, const void *arg)
b_map->string);
}
+ /* Configure port description source */
+ struct cmd_node *configure_lldp_portdescr_type =
+ commands_new(configure_lldp, "portdescription-source",
+ "Port description source", NULL, NULL, NULL);
+ for (lldpctl_map_t *b_map =
+ lldpctl_key_get_map(lldpctl_k_config_lldp_portdescr_type);
+ b_map->string; b_map++) {
+ commands_new(commands_new(configure_lldp_portdescr_type,
+ b_map->string, b_map->string, NULL, NULL, NULL),
+ NEWLINE, "Set port description source", NULL,
+ cmd_portdescr_type, b_map->string);
+ }
+
/* Now handle the various portid subtypes we can configure. */
struct cmd_node *configure_lldp_portid_type = commands_new(configure_lldp,
"portidsubtype", "LLDP PortID TLV Subtype", NULL, NULL, NULL);
lldpctl_k_config_bond_slave_src_mac_type));
tag_datatag(w, "lldp-portid-type", "Port ID TLV subtype for LLDP frames",
lldpctl_atom_get_str(configuration, lldpctl_k_config_lldp_portid_type));
+ tag_datatag(w, "lldp-portdescr-type",
+ "Port description source for LLDP frames",
+ lldpctl_atom_get_str(configuration,
+ lldpctl_k_config_lldp_portdescr_type));
tag_datatag(w, "lldp-agent-type", "Agent type",
lldpctl_atom_get_str(configuration, lldpctl_k_config_lldp_agent_type));
cfg->g_config.c_lldp_agent_type = config->c_lldp_agent_type;
levent_update_now(cfg);
}
+ if (CHANGED(c_lldp_portdescr_type) &&
+ config->c_lldp_portdescr_type >= LLDP_PORTDESCR_SRC_AUTO &&
+ config->c_lldp_portdescr_type <= LLDP_PORTDESCR_SRC_MAX) {
+ log_debug("rpc", "change lldp port description source to %d",
+ config->c_lldp_portdescr_type);
+ cfg->g_config.c_lldp_portdescr_type = config->c_lldp_portdescr_type;
+ levent_update_now(cfg);
+ }
/* Pause/resume */
if (CHANGED(c_paused)) {
log_debug("rpc", "client asked to %s lldpd",
int has_alias = (iface->alias != NULL && strlen(iface->alias) != 0 &&
strncmp("lldpd: ", iface->alias, 7));
int portid_type = cfg->g_config.c_lldp_portid_type;
+ int portdescr_type = cfg->g_config.c_lldp_portdescr_type;
if (portid_type == LLDP_PORTID_SUBTYPE_IFNAME ||
(portid_type == LLDP_PORTID_SUBTYPE_UNKNOWN && has_alias) ||
(port->p_id_subtype == LLDP_PORTID_SUBTYPE_LOCAL && has_alias)) {
if (port->p_descr_force == 0) {
/* use the actual alias in the port description */
- log_debug("interfaces", "using alias in description for %s",
- hardware->h_ifname);
free(port->p_descr);
- if (has_alias) {
+ if (portdescr_type != LLDP_PORTDESCR_SRC_IFNAME && has_alias) {
+ log_debug("interfaces", "using alias in description for %s",
+ hardware->h_ifname);
port->p_descr = strdup(iface->alias);
} else {
/* We don't have anything else to put here and for CDP
- * with need something non-NULL */
+ * with need something non-NULL even if alias is requested */
+ log_debug("interfaces", "using ifname in description for %s",
+ hardware->h_ifname);
port->p_descr = strdup(hardware->h_ifname);
}
}
}
if (port->p_descr_force == 0) {
- /* use the ifname in the port description until alias is set */
- log_debug("interfaces", "using ifname in description for %s",
- hardware->h_ifname);
+ /* use the actual alias in the port description
+ * if requested and set */
free(port->p_descr);
- port->p_descr = strdup(hardware->h_ifname);
+ if (portdescr_type == LLDP_PORTDESCR_SRC_ALIAS && has_alias) {
+ log_debug("interfaces", "using alias in description for %s",
+ hardware->h_ifname);
+ port->p_descr = strdup(iface->alias);
+ } else {
+ log_debug("interfaces", "using ifname in description for %s",
+ hardware->h_ifname);
+ port->p_descr = strdup(hardware->h_ifname);
+ }
}
}
}
},
};
+static struct atom_map lldp_portdescr_map = {
+ .key = lldpctl_k_config_lldp_portdescr_type,
+ .map = {
+ { LLDP_PORTDESCR_SRC_AUTO, "auto"},
+ { LLDP_PORTDESCR_SRC_IFNAME, "ifname"},
+ { LLDP_PORTDESCR_SRC_ALIAS, "alias"},
+ { 0, NULL},
+ },
+};
+
ATOM_MAP_REGISTER(bond_slave_src_mac_map, 1);
ATOM_MAP_REGISTER(lldp_portid_map, 2);
ATOM_MAP_REGISTER(lldp_agent_map, 3);
+ATOM_MAP_REGISTER(lldp_portdescr_map, 4);
static int
_lldpctl_atom_new_config(lldpctl_atom_t *atom, va_list ap)
return map_lookup(lldp_portid_map.map, c->config->c_lldp_portid_type);
case lldpctl_k_config_lldp_agent_type:
return map_lookup(lldp_agent_map.map, c->config->c_lldp_agent_type);
+ case lldpctl_k_config_lldp_portdescr_type:
+ return map_lookup(lldp_portdescr_map.map, c->config->c_lldp_portdescr_type);
default:
SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
return NULL;
return c->config->c_tx_hold;
case lldpctl_k_config_max_neighbors:
return c->config->c_max_neighbors;
+ case lldpctl_k_config_lldp_portid_type:
+ return c->config->c_lldp_portid_type;
default:
return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
}
config.c_lldp_agent_type = value;
c->config->c_lldp_agent_type = value;
break;
+ case lldpctl_k_config_lldp_portdescr_type:
+ config.c_lldp_portdescr_type = value;
+ c->config->c_lldp_portdescr_type = value;
+ break;
default:
SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
return NULL;
lldpctl_k_config_lldp_agent_type, /**< `(I,WO)` LLDP agent type */
lldpctl_k_config_max_neighbors, /**< `(I,WO)`Maximum number of neighbors per
port. */
+ lldpctl_k_config_lldp_portdescr_type, /**< `(I,WO)` LLDP port description source */
lldpctl_k_custom_tlvs = 5000, /**< `(AL)` custom TLVs */
lldpctl_k_custom_tlvs_clear, /**< `(WO)` clear list of custom TLVs */
#define LLDP_PORTID_SUBTYPE_LOCAL 7
#define LLDP_PORTID_SUBTYPE_MAX LLDP_PORTID_SUBTYPE_LOCAL
+/* Port description source type */
+#define LLDP_PORTDESCR_SRC_AUTO 0
+#define LLDP_PORTDESCR_SRC_IFNAME 1
+#define LLDP_PORTDESCR_SRC_ALIAS 2
+#define LLDP_PORTDESCR_SRC_MAX LLDP_PORTDESCR_SRC_ALIAS
+
/* Operational MAU Type field. See:
* https://www.iana.org/assignments/ianamau-mib/ianamau-mib */
#define LLDP_DOT3_MAU_AUI 1
slaves */
int c_lldp_portid_type; /* The PortID type */
int c_lldp_agent_type; /* The agent type */
+ int c_lldp_portdescr_type; /* The port description source type */
};
MARSHAL_BEGIN(lldpd_config)
MARSHAL_STR(lldpd_config, c_mgmt_pattern)