Browse Source

zebra: Fix route deletion on *BSD

Fix for not handling RTM_CHANGE correctly.  This patch change it to
delete/add instead.  Using RTM_CHANGE on kernels where it works is better,
but is left as an exercise for developer who has access and will to fix it
on *BSD.

[ed note: collaboration with Martin Winter]
Timo Teräs 3 years ago
parent
commit
d849e23b1c
1 changed files with 21 additions and 22 deletions
  1. 21 22
      zebra/rt_socket.c

+ 21 - 22
zebra/rt_socket.c

@@ -68,7 +68,7 @@ sin_masklen (struct in_addr mask)
 
 /* Interface between zebra message and rtm message. */
 static int
-kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family)
+kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib)
 
 {
   struct sockaddr_in *mask = NULL;
@@ -245,7 +245,7 @@ sin6_masklen (struct in6_addr mask)
 
 /* Interface between zebra message and rtm message. */
 static int
-kernel_rtm_ipv6 (int cmd, struct prefix *p, struct rib *rib, int family)
+kernel_rtm_ipv6 (int cmd, struct prefix *p, struct rib *rib)
 {
   struct sockaddr_in6 *mask;
   struct sockaddr_in6 sin_dest, sin_mask, sin_gate;
@@ -363,33 +363,32 @@ kernel_rtm_ipv6 (int cmd, struct prefix *p, struct rib *rib, int family)
 
 #endif
 
+static int
+kernel_rtm (int cmd, struct prefix *p, struct rib *rib)
+{
+  switch (PREFIX_FAMILY(p))
+    {
+    case AF_INET:
+      return kernel_rtm_ipv4 (cmd, p, rib);
+    case AF_INET6:
+      return kernel_rtm_ipv6 (cmd, p, rib);
+    }
+  return 0;
+}
+
 int
 kernel_route_rib (struct prefix *p, struct rib *old, struct rib *new)
 {
-  struct rib *rib;
-  int route = 0, cmd;
-
-  if (!old && new)
-    cmd = RTM_ADD;
-  else if (old && !new)
-    cmd = RTM_DELETE;
-  else
-    cmd = RTM_CHANGE;
-
-  rib = new ? new : old;
+  int route = 0;
 
   if (zserv_privs.change(ZPRIVS_RAISE))
     zlog (NULL, LOG_ERR, "Can't raise privileges");
 
-  switch (PREFIX_FAMILY(p))
-    {
-    case AF_INET:
-      route = kernel_rtm_ipv4 (cmd, p, rib, AF_INET);
-      break;
-    case AF_INET6:
-      route = kernel_rtm_ipv6 (cmd, p, rib, AF_INET6);
-      break;
-    }
+  if (old)
+    route |= kernel_rtm (RTM_DELETE, p, old);
+
+  if (new)
+    route |= kernel_rtm (RTM_ADD, p, new);
 
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");