From: Vincent Bernat Date: Wed, 7 Sep 2011 09:07:29 +0000 (+0200) Subject: Fix key/value output was incorrect when an interface name contains a dot. X-Git-Tag: 0.5.5~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=84e06882c89cab7d5782700565a332ef81ccbbf3;p=thirdparty%2Flldpd.git Fix key/value output was incorrect when an interface name contains a dot. When a dot was present in an interface name, the output of `lldpctl -f keyvalue` was incorrect with something like this: lldp.vif2.vif4.vif5.vif6.vif7.0.via=LLDP lldp.vif2.vif4.vif5.vif6.vif7.0.rid=2 We fix this by using `\1` as a separator instead of `.` when building the key. `\1` is replaced by `.` before printing. When parsing the output, the interface name should be determined from the first time it is used in a line like `lldp.vif2.0.via=LLDP`. --- diff --git a/CHANGELOG b/CHANGELOG index be39c176..19e90ac3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +lldpd (0.5.5) + * Fixes: + + Key/value output was incorrect when a dot was present in + interface names. This is fixed but it is preferable to use XML + output since the parsing is more difficult in this case. + lldpd (0.5.4) * Features: + Get OS information from /etc/os-release if available. Patch from diff --git a/src/kv_writer.c b/src/kv_writer.c index efc8ec77..ab7a87cd 100644 --- a/src/kv_writer.c +++ b/src/kv_writer.c @@ -22,6 +22,8 @@ #include "writer.h" #include "lldpd.h" +#define SEP '.' + struct kv_writer_private { FILE * fh; char * prefix; @@ -38,7 +40,7 @@ kv_start(struct writer *w , const char *tag, const char *descr) if ((newprefix = malloc(s+1)) == NULL) fatal(NULL); if (strlen(p->prefix) > 0) - snprintf(newprefix, s+1, "%s.%s", p->prefix, tag); + snprintf(newprefix, s+1, "%s\1%s", p->prefix, tag); else snprintf(newprefix, s+1, "%s", tag); free(p->prefix); @@ -49,7 +51,12 @@ void kv_data(struct writer *w, const char *data) { struct kv_writer_private *p = w->priv; - fprintf(p->fh, "%s=%s\n", p->prefix, data); + char *key = strdup(p->prefix); + char *dot; + if (!key) fatal(NULL); + while ((dot = strchr(key, '\1')) != NULL) *dot=SEP; + fprintf(p->fh, "%s=%s\n", key, data); + free(key); } void @@ -58,7 +65,7 @@ kv_end(struct writer *w) struct kv_writer_private *p = w->priv; char *dot; - if ((dot = strrchr(p->prefix, '.')) == NULL) + if ((dot = strrchr(p->prefix, '\1')) == NULL) p->prefix[0] = '\0'; else *dot = '\0';