From 17d9ea802c60b9a58f8c0099bff2241e5df4706b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 13 Mar 2018 00:07:10 +0100 Subject: [PATCH] WIP Not working. --- src/daemon/client.c | 1 + src/daemon/lldpd.c | 26 +++++++++++++++++--------- src/lldpd-structs.h | 29 +++++++++++++++++++---------- src/marshal.c | 2 ++ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/daemon/client.c b/src/daemon/client.c index e5547b0f..ce481f07 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -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"); diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 0f962eba..e88229cc 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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", diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 56382d5e..059d818f 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -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 diff --git a/src/marshal.c b/src/marshal.c index 120bfdca..b38907ba 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -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", -- 2.39.5