Zbigniew Jędrzejewski-Szmek 399a2a
From cbc0484a42adf93bdd6897f93b15b0eaeb3077f6 Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 399a2a
From: Richard Maw <richard.maw@codethink.co.uk>
Zbigniew Jędrzejewski-Szmek 399a2a
Date: Thu, 12 Mar 2015 18:14:58 +0000
Zbigniew Jędrzejewski-Szmek 399a2a
Subject: [PATCH] networkd: Begin with serial number 1 for netlink requests
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
"Notifications are of informal nature and no reply is expected, therefore the
Zbigniew Jędrzejewski-Szmek 399a2a
sequence number is typically set to 0."[1]
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
If networkd is started soon after recent netlink activity, then there
Zbigniew Jędrzejewski-Szmek 399a2a
will be messages with sequence number 0 in the buffer.
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
The first thing networkd does is to request a dump of all the links. If
Zbigniew Jędrzejewski-Szmek 399a2a
it uses sequence number 0 for this, then it may confuse the dump request's
Zbigniew Jędrzejewski-Szmek 399a2a
response with that of a notification.
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
This will result in it failing to properly enumerate all the links,
Zbigniew Jędrzejewski-Szmek 399a2a
but more importantly, when it comes to enumerate all the addresses, it
Zbigniew Jędrzejewski-Szmek 399a2a
will still have the link dump in progress, so the address enumeration
Zbigniew Jędrzejewski-Szmek 399a2a
will fail with -EBUSY.
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
[1]: http://www.infradead.org/~tgr/libnl/doc/core.html#core_msg_types
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
[tomegun: sequence -> serial]
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
(cherry picked from commit d422e52a3523ad0955bec4f9fbed46e234d28590)
Zbigniew Jędrzejewski-Szmek 399a2a
---
Zbigniew Jędrzejewski-Szmek 399a2a
 src/libsystemd/sd-rtnl/sd-rtnl.c | 5 +++++
Zbigniew Jędrzejewski-Szmek 399a2a
 1 file changed, 5 insertions(+)
Zbigniew Jędrzejewski-Szmek 399a2a
Zbigniew Jędrzejewski-Szmek 399a2a
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
Zbigniew Jędrzejewski-Szmek 399a2a
index ae49c77e01..7cdcc5d96a 100644
Zbigniew Jędrzejewski-Szmek 399a2a
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
Zbigniew Jędrzejewski-Szmek 399a2a
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
Zbigniew Jędrzejewski-Szmek 399a2a
@@ -61,6 +61,11 @@ static int sd_rtnl_new(sd_rtnl **ret) {
Zbigniew Jędrzejewski-Szmek 399a2a
                             sizeof(struct nlmsghdr), sizeof(uint8_t)))
Zbigniew Jędrzejewski-Szmek 399a2a
                 return -ENOMEM;
Zbigniew Jędrzejewski-Szmek 399a2a
 
Zbigniew Jędrzejewski-Szmek 399a2a
+        /* Change notification responses have sequence 0, so we must
Zbigniew Jędrzejewski-Szmek 399a2a
+         * start our request sequence numbers at 1, or we may confuse our
Zbigniew Jędrzejewski-Szmek 399a2a
+         * responses with notifications from the kernel */
Zbigniew Jędrzejewski-Szmek 399a2a
+        rtnl->serial = 1;
Zbigniew Jędrzejewski-Szmek 399a2a
+
Zbigniew Jędrzejewski-Szmek 399a2a
         *ret = rtnl;
Zbigniew Jędrzejewski-Szmek 399a2a
         rtnl = NULL;
Zbigniew Jędrzejewski-Szmek 399a2a