]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
iproute: Set flags and attributes on dump to get IPv6 cached routes to be flushed
authorStefano Brivio <sbrivio@redhat.com>
Tue, 25 Jun 2019 11:41:24 +0000 (13:41 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 26 Jun 2019 21:27:00 +0000 (14:27 -0700)
With a current (5.1) kernel version, IPv6 exception routes can't be listed
(ip -6 route list cache) or flushed (ip -6 route flush cache). Kernel
support for this is being added back. Relevant net-next commits:

  564c91f7e563 fib_frontend, ip6_fib: Select routes or exceptions dump from RTM_F_CLONED
  ef11209d4219 Revert "net/ipv6: Bail early if user only wants cloned entries"
  3401bfb1638e ipv6/route: Don't match on fc_nh_id if not set in ip6_route_del()
  bf9a8a061ddc ipv6/route: Change return code of rt6_dump_route() for partial node dumps
  1e47b4837f3b ipv6: Dump route exceptions if requested
  40cb35d5dc04 ip6_fib: Don't discard nodes with valid routing information in fib6_locate_1()

However, to allow the kernel to filter routes based on the RTM_F_CLONED
flag, we need to make sure this flag is always passed when we want cached
routes to be dumped, and we can also pass table and output interface
attributes to have the kernel filtering on them, if requested by the user.

Use the existing iproute_dump_filter() as a filter for the dump request in
iproute_flush(). This way, 'ip -6 route flush cache' works again.

v2: Instead of creating a separate 'filter' function dealing with
    RTM_F_CACHED only, use the existing iproute_dump_filter() and get
    table and oif kernel filtering for free. Suggested by David Ahern.

Fixes: aba5acdfdb34 ("(Logical change 1.3)")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iproute.c

index 2b3dcc5dbd53fc2318853f40f35c87c81561e5ff..1669e0138259e7afd4c2b142aadc0c572f018f3f 100644 (file)
@@ -1602,6 +1602,30 @@ static int save_route_prep(void)
        return 0;
 }
 
+static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+       struct rtmsg *rtm = NLMSG_DATA(nlh);
+       int err;
+
+       rtm->rtm_protocol = filter.protocol;
+       if (filter.cloned)
+               rtm->rtm_flags |= RTM_F_CLONED;
+
+       if (filter.tb) {
+               err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
+               if (err)
+                       return err;
+       }
+
+       if (filter.oif) {
+               err = addattr32(nlh, reqlen, RTA_OIF, filter.oif);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
 static int iproute_flush(int family, rtnl_filter_t filter_fn)
 {
        time_t start = time(0);
@@ -1624,7 +1648,7 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
        filter.flushe = sizeof(flushb);
 
        for (;;) {
-               if (rtnl_routedump_req(&rth, family, NULL) < 0) {
+               if (rtnl_routedump_req(&rth, family, iproute_dump_filter) < 0) {
                        perror("Cannot send dump request");
                        return -2;
                }
@@ -1664,30 +1688,6 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
        }
 }
 
-static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-       struct rtmsg *rtm = NLMSG_DATA(nlh);
-       int err;
-
-       rtm->rtm_protocol = filter.protocol;
-       if (filter.cloned)
-               rtm->rtm_flags |= RTM_F_CLONED;
-
-       if (filter.tb) {
-               err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
-               if (err)
-                       return err;
-       }
-
-       if (filter.oif) {
-               err = addattr32(nlh, reqlen, RTA_OIF, filter.oif);
-               if (err)
-                       return err;
-       }
-
-       return 0;
-}
-
 static int iproute_list_flush_or_save(int argc, char **argv, int action)
 {
        int dump_family = preferred_family;