Blame SOURCES/libvirt-util-check-accept_ra-for-all-nexthop-interfaces-of-multipath-routes.patch

9c6c51
From 1e443270387834e84a335ec500cf069172ab261c Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <1e443270387834e84a335ec500cf069172ab261c@dist-git>
9c6c51
From: Laine Stump <laine@laine.org>
9c6c51
Date: Mon, 14 Jan 2019 11:35:05 -0500
9c6c51
Subject: [PATCH] util: check accept_ra for all nexthop interfaces of multipath
9c6c51
 routes
9c6c51
9c6c51
When checking the setting of accept_ra, we have assumed that all
9c6c51
routes have a single nexthop, so the interface of the route would be
9c6c51
in the RTA_OIF attribute of the netlink RTM_NEWROUTE message. But
9c6c51
multipath routes don't have an RTA_OIF; instead, they have an
9c6c51
RTA_MULTIPATH attribute, which is an array of rtnexthop, with each
9c6c51
rtnexthop having an interface. This patch adds a loop to look at the
9c6c51
setting of accept_ra of the interface for every rtnexthop in the
9c6c51
array.
9c6c51
9c6c51
Signed-off-by: Laine Stump <laine@laine.org>
9c6c51
Reviewed-by: Erik Skultety <eskultet@redhat.com>
9c6c51
(cherry picked from commit d40b820c5d3b0c9d5222844110881af66cdbb746)
9c6c51
9c6c51
https://bugzilla.redhat.com/1583131
9c6c51
9c6c51
Conflicts: src/util/virnetdevip.c - more context conflicts due to addition of
9c6c51
        VIR_AUTOPTR and resulting removal of cleanup/error labels upstream.
9c6c51
Signed-off-by: Laine Stump <laine@laine.org>
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/util/virnetdevip.c | 37 +++++++++++++++++++++++++++++++++++++
9c6c51
 1 file changed, 37 insertions(+)
9c6c51
9c6c51
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
9c6c51
index d56f4f05f3..fff41ec498 100644
9c6c51
--- a/src/util/virnetdevip.c
9c6c51
+++ b/src/util/virnetdevip.c
9c6c51
@@ -601,6 +601,43 @@ virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
9c6c51
         goto cleanup;
9c6c51
     }
9c6c51
 
9c6c51
+    /* if no RTA_OIF was found, see if this is a multipath route (one
9c6c51
+     * which has an array of nexthops, each with its own interface)
9c6c51
+     */
9c6c51
+
9c6c51
+    rta_attr = (struct rtattr *)nlmsg_find_attr(resp, sizeof(struct rtmsg), RTA_MULTIPATH);
9c6c51
+    if (rta_attr) {
9c6c51
+        /* The data of the attribute is an array of rtnexthop */
9c6c51
+        struct rtnexthop *nh = RTA_DATA(rta_attr);
9c6c51
+        size_t len = RTA_PAYLOAD(rta_attr);
9c6c51
+
9c6c51
+        /* validate the attribute array length */
9c6c51
+        len = MIN(len, ((char *)resp + NLMSG_PAYLOAD(resp, 0) - (char *)rta_attr));
9c6c51
+
9c6c51
+        while (len >= sizeof(*nh) && len >= nh->rtnh_len) {
9c6c51
+            /* check accept_ra for the interface of each nexthop */
9c6c51
+
9c6c51
+            ifname = virNetDevGetName(nh->rtnh_ifindex);
9c6c51
+
9c6c51
+            if (ifname)
9c6c51
+                accept_ra = virNetDevIPGetAcceptRA(ifname);
9c6c51
+
9c6c51
+            VIR_DEBUG("Checking multipath route nexthop device %s (%d), accept_ra: %d",
9c6c51
+                      ifname, nh->rtnh_ifindex, accept_ra);
9c6c51
+
9c6c51
+            if (!ifname ||
9c6c51
+                (accept_ra != 2 && virNetDevIPCheckIPv6ForwardingAddIF(data, &ifname) < 0)) {
9c6c51
+                goto error;
9c6c51
+            }
9c6c51
+
9c6c51
+            VIR_FREE(ifname); /* in case it wasn't added to the array */
9c6c51
+            data->hasRARoutes = true;
9c6c51
+
9c6c51
+            len -= NLMSG_ALIGN(nh->rtnh_len);
9c6c51
+            nh = RTNH_NEXT(nh);
9c6c51
+        }
9c6c51
+    }
9c6c51
+
9c6c51
  cleanup:
9c6c51
     VIR_FREE(ifname);
9c6c51
     return ret;
9c6c51
-- 
9c6c51
2.20.1
9c6c51