]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
WIP feature/keep-modified-ports
authorVincent Bernat <vincent@bernat.im>
Mon, 12 Mar 2018 23:07:10 +0000 (00:07 +0100)
committerVincent Bernat <vincent@bernat.im>
Mon, 12 Mar 2018 23:07:10 +0000 (00:07 +0100)
Not working.

src/daemon/client.c
src/daemon/lldpd.c
src/lldpd-structs.h
src/marshal.c

index e5547b0f5b787cb411cca130c76ab7d14c599b07..ce481f07556ffac4e94cfe66def292d9021c3692 100644 (file)
@@ -349,6 +349,7 @@ _client_handle_set_port(struct lldpd *cfg,
                port->p_id_len = strlen(set->local_id);
                port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
                port->p_descr_force = 0;
+               port->p_id_force = 1;
        }
        if (set->local_descr) {
                log_debug("rpc", "requested change to Port Description");
index 0f962ebaac08376c75f889ec47d2175f1f2a9a09..e88229cc5dc1f300b01d38fb918546aaea4b1ef7 100644 (file)
@@ -182,19 +182,18 @@ lldpd_alloc_default_local_port(struct lldpd *cfg)
 }
 
 /**
- * Partially serialize a port to get its configuration.
+ * Partially serialize a port to compare it
  */
 static ssize_t
-lldpd_port_serialize_configuration(struct lldpd_port *port, int flags, u_int8_t **output)
+lldpd_port_serialize_partial(struct lldpd_port *port, size_t offset, u_int8_t **output)
 {
        ssize_t output_len;
-       char save[LLDPD_PORT_START_MARKER];
+       char save[offset];
        *output = NULL;
        memcpy(save, port, sizeof(save));
        /* coverity[suspicious_sizeof]
           We intentionally partially memset port */
        memset(port, 0, sizeof(save));
-       port->_p_hardware_flags = flags;
        output_len = lldpd_port_serialize(port, (void**)output);
        memcpy(port, save, sizeof(save));
        return output_len;
@@ -210,10 +209,18 @@ lldpd_port_is_modified(struct lldpd *cfg, struct lldpd_port *port)
        ssize_t len1, len2;
        u_int8_t *out1, *out2;
        int ret = 0;
-       len1 = lldpd_port_serialize_configuration(dflt, 0, &out1);
-       len2 = lldpd_port_serialize_configuration(port, 0, &out2);
+       len1 = lldpd_port_serialize_partial(dflt, LLDPD_PORT_CONFIGURATION_MARKER, &out1);
+       len2 = lldpd_port_serialize_partial(port, LLDPD_PORT_CONFIGURATION_MARKER, &out2);
+       log_debug("localchassis", "len1 = %zd, len2 = %zd", len1, len2);
        if (len1 == -1 || len2 == -1) goto end;
-       if (len1 == len2 && !memcmp(out1, out2, len1)) goto end;
+       if (len1 == len2) {
+               if (!memcmp(out1, out2, len1)) goto end;
+               for (int i = 0; i < len1; i++) {
+                       log_debug("localchassis", "%c %4d %02X %02X",
+                           (out1[i] == out2[i])?' ':'*',
+                           i, out1[i], out2[i]);
+               }
+       }
        ret = 1;
  end:
        free(out1);
@@ -413,9 +420,10 @@ lldpd_reset_timer(struct lldpd *cfg)
                 * change. To do this, we zero out fields that are not
                 * significant, marshal the port, then restore. */
                struct lldpd_port *port = &hardware->h_lport;
+               port->_p_hardware_flags = hardware->h_flags;
                u_int8_t *output = NULL;
-               ssize_t output_len = lldpd_port_serialize_configuration(
-                   port, hardware->h_flags, &output);
+               ssize_t output_len = lldpd_port_serialize_partial(
+                   port, LLDPD_PORT_START_MARKER, &output);
                if (output_len == -1) {
                        log_warnx("localchassis",
                            "unable to serialize local port %s to check for differences",
index 56382d5e37ca2d878e7525bf8ec9a635df7c61f8..059d818fdbfdc94d9e9a031174309d72f52e48a6 100644 (file)
@@ -247,8 +247,6 @@ struct lldpd_port {
        u_int8_t                 p_protocol;   /* Protocol used to get this port */
        u_int8_t                 p_hidden_in:1; /* Considered as hidden for reception */
        u_int8_t                 p_hidden_out:2; /* Considered as hidden for emission */
-       u_int8_t                 p_disable_rx:3; /* Should RX be disabled for this port? */
-       u_int8_t                 p_disable_tx:4; /* Should TX be disabled for this port? */
        /* Important: all fields that should be ignored to check if a port has
         * been changed should be before this mark. */
 #define LLDPD_PORT_START_MARKER (offsetof(struct lldpd_port, _p_hardware_flags))
@@ -257,30 +255,41 @@ struct lldpd_port {
        char                    *p_id;
        int                      p_id_len;
        char                    *p_descr;
-       int                      p_descr_force; /* Description has been forced by user */
        u_int16_t                p_mfs;
        u_int16_t                p_ttl; /* TTL for remote port */
 
 #ifdef ENABLE_DOT3
-       /* Dot3 stuff */
        u_int32_t                p_aggregid;
        struct lldpd_dot3_macphy p_macphy;
-       struct lldpd_dot3_power  p_power;
 #endif
-
 #ifdef ENABLE_LLDPMED
        u_int16_t                p_med_cap_enabled;
-       struct lldpd_med_policy  p_med_policy[LLDP_MED_APPTYPE_LAST];
-       struct lldpd_med_loc     p_med_location[LLDP_MED_LOCFORMAT_LAST];
-       struct lldpd_med_power   p_med_power;
 #endif
-
 #ifdef ENABLE_DOT1
        u_int16_t                p_pvid;
        TAILQ_HEAD(, lldpd_vlan) p_vlans;
        TAILQ_HEAD(, lldpd_ppvid) p_ppvids;
        TAILQ_HEAD(, lldpd_pi)    p_pids;
 #endif
+
+       /* Below is user-controlled */
+
+#define LLDPD_PORT_CONFIGURATION_MARKER (offsetof(struct lldpd_port, p_id_force))
+       int                      p_id_force; /* Port ID has been forced by user */
+       int                      p_descr_force; /* Description has been forced by user */
+       u_int8_t                 p_disable_rx:1; /* Should RX be disabled for this port? */
+       u_int8_t                 p_disable_tx:2; /* Should TX be disabled for this port? */
+
+#ifdef ENABLE_DOT3
+       struct lldpd_dot3_power  p_power;
+#endif
+
+#ifdef ENABLE_LLDPMED
+       struct lldpd_med_policy  p_med_policy[LLDP_MED_APPTYPE_LAST];
+       struct lldpd_med_loc     p_med_location[LLDP_MED_LOCFORMAT_LAST];
+       struct lldpd_med_power   p_med_power;
+#endif
+
 #ifdef ENABLE_CUSTOM
        TAILQ_HEAD(, lldpd_custom) p_custom_list;
 #endif
index 120bfdcad2b494fc0da164cfe9ee034af103944c..b38907ba8a6af513403d5f9f76ba31c9ba0cfa13 100644 (file)
@@ -140,6 +140,7 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input,
                void  *source;
                void  *target = NULL;
                if (current->kind == ignore) {
+                       log_debug("marshal", "ignore from %zu (%zu)", current->offset, current->offset2);
                        memset((unsigned char *)serialized->object + current->offset, 0, current->offset2);
                        continue;
                }
@@ -177,6 +178,7 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input,
                /* Append the result, force alignment to be able to unserialize it */
                padlen = ALIGNOF(struct marshal_serialized);
                padlen = (padlen - (len % padlen)) % padlen;
+               log_debug("marshal", "realloc %lu", len + padlen + sublen);
                new = realloc(serialized, len + padlen + sublen);
                if (!new) {
                        log_warnx("marshal", "unable to allocate more memory to serialize structure %s",