]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Fix key/value output was incorrect when an interface name contains a dot.
authorVincent Bernat <bernat@luffy.cx>
Wed, 7 Sep 2011 09:07:29 +0000 (11:07 +0200)
committerVincent Bernat <bernat@luffy.cx>
Wed, 7 Sep 2011 09:07:29 +0000 (11:07 +0200)
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`.

CHANGELOG
src/kv_writer.c

index be39c176123976ebbfeac426f84e9bdc8fbee592..19e90ac35725962e63d1d00919307e7c966512b7 100644 (file)
--- 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
index efc8ec7746d841153e67bf0cb46809103e614533..ab7a87cd3dfa21a6af164c9a60875705ddfbc126 100644 (file)
@@ -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';