]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Netlink: Use route replace for IPv4
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 15 Jul 2019 14:23:18 +0000 (16:23 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 15 Jul 2019 14:23:18 +0000 (16:23 +0200)
Use route replace netlink op instead of delete+add netlink ops for kernel
IPv4 route replace. This avoids some packetloss during route replace.
Still use the old behavior for IPv6, as some kernel bugs are hidden in
IPv6 ECMP handling.

sysdep/linux/netlink.c

index 6e3fe48893330a1805ad08b6c939cea74260eaf5..85067bf5e33aa3a42ad6a038a794d381f136e223 100644 (file)
@@ -69,6 +69,7 @@
 #define RTA_ENCAP  22
 #endif
 
+#define krt_ipv4(p) ((p)->af == AF_INET)
 #define krt_ecmp6(p) ((p)->af == AF_INET6)
 
 const int rt_default_ecmp = 16;
@@ -1368,27 +1369,43 @@ nl_delete_rte(struct krt_proto *p, rte *e)
   return err;
 }
 
+static inline int
+nl_replace_rte(struct krt_proto *p, rte *e)
+{
+  rta *a = e->attrs;
+  return nl_send_route(p, e, NL_OP_REPLACE, a->dest, &(a->nh));
+}
+
+
 void
 krt_replace_rte(struct krt_proto *p, net *n, rte *new, rte *old)
 {
   int err = 0;
 
   /*
-   * We could use NL_OP_REPLACE, but route replace on Linux has some problems:
+   * We use NL_OP_REPLACE for IPv4, it has an issue with not checking for
+   * matching rtm_protocol, but that is OK when dedicated priority is used.
    *
-   * 1) Does not check for matching rtm_protocol
-   * 2) Has broken semantics for IPv6 ECMP
-   * 3) Crashes some kernel version when used for IPv6 ECMP
+   * We do not use NL_OP_REPLACE for IPv6, as it has broken semantics for ECMP
+   * and with some kernel versions ECMP replace crashes kernel. Would need more
+   * testing and checks for kernel versions.
    *
-   * So we use NL_OP_DELETE and then NL_OP_ADD. We also do not trust the old
-   * route value, so we do not try to optimize IPv6 ECMP reconfigurations.
+   * For IPv6, we use NL_OP_DELETE and then NL_OP_ADD. We also do not trust the
+   * old route value, so we do not try to optimize IPv6 ECMP reconfigurations.
    */
 
-  if (old)
-    nl_delete_rte(p, old);
+  if (krt_ipv4(p) && old && new)
+  {
+    err = nl_replace_rte(p, new);
+  }
+  else
+  {
+    if (old)
+      nl_delete_rte(p, old);
 
-  if (new)
-    err = nl_add_rte(p, new);
+    if (new)
+      err = nl_add_rte(p, new);
+  }
 
   if (err < 0)
     n->n.flags |= KRF_SYNC_ERROR;