From: Vincent Bernat Date: Thu, 4 Feb 2016 19:16:56 +0000 (+0100) Subject: netlink: merge old attributes with new ones X-Git-Tag: 0.9.1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58e30b5a3f6114007435ee305b4da1b9d413737d;p=thirdparty%2Flldpd.git netlink: merge old attributes with new ones 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. --- diff --git a/src/daemon/netlink.c b/src/daemon/netlink.c index d495f10f..c0d1dcf1 100644 --- a/src/daemon/netlink.c +++ b/src/daemon/netlink.c @@ -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);