]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: add port description override via lldpcli 101/head
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 24 Mar 2015 09:10:49 +0000 (11:10 +0200)
committerAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 24 Mar 2015 09:13:04 +0000 (11:13 +0200)
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
src/client/conf-lldp.c
src/daemon/client.c
src/daemon/interfaces.c
src/lib/atom-private.c
src/lib/lldpctl.h
src/lldpd-structs.c
src/lldpd-structs.h

index 962ce3606e2470356d058c4b6c92878b32cc8766..d8ec83828b54f194639bfb8664e6a5353a39aa3c 100644 (file)
@@ -75,6 +75,7 @@ cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w,
 {
        lldpctl_atom_t *iface;
        const char *id = cmdenv_get(env, "port-id");
+       const char *descr = cmdenv_get(env, "port-descr");
 
        if (!id || !strlen(id)) {
                log_warnx("lldpctl", "no id speficied");
@@ -87,6 +88,10 @@ cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w,
                        log_warnx("lldpctl", "unable to set LLDP PortID."
                          " %s", lldpctl_last_strerror(conn));
                }
+               if (descr && lldpctl_atom_set_str(port, lldpctl_k_port_descr, descr) == NULL) {
+                       log_warnx("lldpctl", "unable to set LLDP Port Description."
+                         " %s", lldpctl_last_strerror(conn));
+               }
                lldpctl_atom_dec_ref(port);
        }
 
@@ -192,16 +197,19 @@ register_commands_configure_lldp(struct cmd_node *configure)
                                NULL, cmd_portid_type,
                                b_map->string);
                } else if (!strcmp(b_map->string, "local")) {
-                       commands_new(
-                               commands_new(
-                                       commands_new(configure_lldp_portid_type,
-                                                    b_map->string, "Local",
-                                                    NULL, NULL, NULL),
-                                       NULL, "PortID",
-                                       NULL, cmd_store_env_value, "port-id"),
+                       struct cmd_node *port_id = commands_new(
+                               commands_new(configure_lldp_portid_type,
+                                            b_map->string, "Local",
+                                            NULL, NULL, NULL),
+                               NULL, "PortID",
+                               NULL, cmd_store_env_value, "port-id");
+                       commands_new(port_id,
                                NEWLINE, NULL,
                                NULL, cmd_portid_type_local,
                                b_map->string);
+                       commands_new(port_id,
+                               NULL, "Port Description",
+                               NULL, cmd_store_env_value_and_pop, "port-descr");
                } else if (!strcmp(b_map->string, "macaddress")) {
                        commands_new(
                                commands_new(configure_lldp_portid_type,
index 7f4b46584e53b8c7191049b0b27f69083a2ffef9..df34f2524c7120691eb55dcddc1bd602dab7eee5 100644 (file)
@@ -300,6 +300,11 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type,
                            port->p_id_len = strlen(set->local_id);
                            port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
                    }
+                   if (set->local_descr) {
+                           log_debug("rpc", "requested change to Port Description");
+                           free(port->p_descr);
+                           port->p_descr = strdup(set->local_descr);
+                   }
 #ifdef ENABLE_LLDPMED
                    if (set->med_policy && set->med_policy->type > 0) {
                            log_debug("rpc", "requested change to MED policy");
@@ -363,6 +368,7 @@ set_port_finished:
        if (!ret) *type = NONE;
        free(set->ifname);
        free(set->local_id);
+       free(set->local_descr);
 #ifdef ENABLE_LLDPMED
        free(set->med_policy);
        if (set->med_location) free(set->med_location->data);
index c43614e724731193aa46fdfc4a160e8e21583f0c..ea6393707d47d542318bb54b015cc14bc955936c 100644 (file)
@@ -466,7 +466,7 @@ interfaces_helper_port_name_desc(struct lldpd *cfg,
        struct lldpd_port *port = &hardware->h_lport;
 
        if (port->p_id_subtype == LLDP_PORTID_SUBTYPE_LOCAL)
-               goto description;
+               return;
 
        /* We need to set the portid to what the client configured.
           This can be done from the CLI.
@@ -495,7 +495,6 @@ interfaces_helper_port_name_desc(struct lldpd *cfg,
                port->p_id_len = ETHER_ADDR_LEN;
        }
 
-description:
        if (iface->alias != NULL && strlen(iface->alias) != 0) {
                /* use the actual alias in the port description */
                log_debug("interfaces", "using alias in description for %s",
index ad725211616fa300a93ff738298d8a2fa79ee589..70c7d1eeafed22b81c204ad69b52cf8d2f5e0fe4 100644 (file)
@@ -848,6 +848,9 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato
        case lldpctl_k_port_id:
                set.local_id = p->port->p_id;
                break;
+       case lldpctl_k_port_descr:
+               set.local_descr = p->port->p_descr;
+               break;
 #ifdef ENABLE_DOT3
        case lldpctl_k_port_dot3_power:
                if (value->type != atom_dot3_power) {
@@ -1046,6 +1049,10 @@ _lldpctl_atom_set_str_port(lldpctl_atom_t *atom, lldpctl_key_t key,
                port->p_id = strdup(value);
                port->p_id_len = strlen(value);
                break;
+       case lldpctl_k_port_descr:
+               free(port->p_descr);
+               port->p_descr = strdup(value);
+               break;
        default:
                SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
                return NULL;
index d42d5efbcfe075df15b5b1eca57fba906705cafc..bf7100769c0141a95703ae388f19926a2f5b2410 100644 (file)
@@ -627,7 +627,7 @@ typedef enum {
        lldpctl_k_port_age,        /**< `(I)`  Age of information, seconds from epoch. */
        lldpctl_k_port_id_subtype, /**< `(IS)` The subtype ID of this port.  */
        lldpctl_k_port_id,         /**< `(BS,WO)` The ID of this port. */
-       lldpctl_k_port_descr,      /**< `(S)` The description of this port. */
+       lldpctl_k_port_descr,      /**< `(S,W)` The description of this port. */
        lldpctl_k_port_hidden,     /**< `(I)` Is this port hidden (or should it be displayed?)? */
 
        lldpctl_k_port_dot3_mfs = 1300,    /**< `(I)` MFS */
index d24f4bf5f9cd893b54e61aa71b11861f0a77ab0c..e06428773be239ff6b4e50e8c5d39f25b8d7f08e 100644 (file)
@@ -161,11 +161,11 @@ lldpd_port_cleanup(struct lldpd_port *port, int all)
 #endif
        /* will set these to NULL so we don't free wrong memory */
 
-       free(port->p_descr);
-       port->p_descr = NULL;
        if (all) {
                free(port->p_id);
                port->p_id = NULL;
+               free(port->p_descr);
+               port->p_descr = NULL;
                free(port->p_lastframe);
                if (port->p_chassis) { /* chassis may not have been attributed, yet */
                        port->p_chassis->c_refcount--;
index 5255707369129b836e8ecbb46eec61d6cd78d8bd..9a692802889f8efa55650dd2294a8a5e17b9720f 100644 (file)
@@ -276,6 +276,7 @@ MARSHAL_END(lldpd_port);
 struct lldpd_port_set {
        char *ifname;
        char *local_id;
+       char *local_descr;
 #ifdef ENABLE_LLDPMED
        struct lldpd_med_policy *med_policy;
        struct lldpd_med_loc    *med_location;
@@ -288,6 +289,7 @@ struct lldpd_port_set {
 MARSHAL_BEGIN(lldpd_port_set)
 MARSHAL_STR(lldpd_port_set, ifname)
 MARSHAL_STR(lldpd_port_set, local_id)
+MARSHAL_STR(lldpd_port_set, local_descr)
 #ifdef ENABLE_LLDPMED
 MARSHAL_POINTER(lldpd_port_set, lldpd_med_policy, med_policy)
 MARSHAL_POINTER(lldpd_port_set, lldpd_med_loc,    med_location)