]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
netlink: merge old attributes with new ones
authorVincent Bernat <vincent@bernat.im>
Thu, 4 Feb 2016 19:16:56 +0000 (20:16 +0100)
committerVincent Bernat <vincent@bernat.im>
Thu, 4 Feb 2016 19:26:18 +0000 (20:26 +0100)
It seems that netlink won't advertise all attributes each time. At least
type can be not advertised in a netlink message. Copy the appropriate
attributes from the old ones when they are missing and we know they
can't change or be absent.

src/daemon/netlink.c

index d495f10f060fa7d33bcbd2f6865dfbe61fc65efc..c0d1dcf1fcd5001de1d00684c46f2da2c168bfd3 100644 (file)
@@ -322,6 +322,31 @@ netlink_parse_address(struct nlmsghdr *msg,
        return 0;
 }
 
+/**
+ * Merge an old interface with a new one.
+ *
+ * Some properties may be absent in the new interface that should be copied over
+ * from the old one.
+ */
+void
+netlink_merge(struct interfaces_device *old, struct interfaces_device *new)
+{
+       if (new->alias == NULL) {
+               new->alias = old->alias;
+               old->alias = NULL;
+       }
+       if (new->address == NULL) {
+               new->address = old->address;
+               old->address = NULL;
+       }
+       if (new->mtu == 0)
+               new->mtu = old->mtu;
+       if (new->type == 0)
+               new->type = old->type;
+       if (new->vlanid == 0)
+               new->vlanid = old->vlanid;
+}
+
 /**
  * Receive netlink answer from the kernel.
  *
@@ -402,6 +427,7 @@ netlink_recv(int s,
                                                } else {
                                                        log_debug("netlink", "interface %s/%s is updated",
                                                            ifdold->name, ifdnew->name);
+                                                       netlink_merge(ifdold, ifdnew);
                                                        TAILQ_INSERT_AFTER(ifs, ifdold, ifdnew, next);
                                                        TAILQ_REMOVE(ifs, ifdold, next);
                                                        interfaces_free_device(ifdold);