]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - sysdep/linux/netlink.c
Fixes longstanding issue with interfaces staying in IF_TMP_DOWN.
[thirdparty/bird.git] / sysdep / linux / netlink.c
index d1b203ef65ea6e483049c8f98ce06a739bfa58ca..7063e2ca57dd3735442715875b9a3ce3d8f89d81 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <stdio.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
@@ -436,12 +437,16 @@ nl_parse_link(struct nlmsghdr *h, int scan)
        f.flags |= IF_MULTIACCESS | IF_BROADCAST | IF_MULTICAST;
       else
        f.flags |= IF_MULTIACCESS;      /* NBMA */
-      if_update(&f);
+
+      ifi = if_update(&f);
+
+      if (!scan)
+       if_end_partial_update(ifi);
     }
 }
 
 static void
-nl_parse_addr(struct nlmsghdr *h)
+nl_parse_addr(struct nlmsghdr *h, int scan)
 {
   struct ifaddrmsg *i;
   struct rtattr *a[IFA_ANYCAST+1];
@@ -541,10 +546,14 @@ nl_parse_addr(struct nlmsghdr *h)
       ifi->index, ifi->name,
       new ? "added" : "removed",
       ifa.ip, ifa.flags, ifa.prefix, ifa.pxlen, ifa.brd, ifa.opposite);
+
   if (new)
     ifa_update(&ifa);
   else
     ifa_delete(&ifa);
+
+  if (!scan)
+    if_end_partial_update(ifi);
 }
 
 void
@@ -564,7 +573,7 @@ kif_do_scan(struct kif_proto *p UNUSED)
   nl_request_dump(RTM_GETADDR);
   while (h = nl_get_scan())
     if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR)
-      nl_parse_addr(h);
+      nl_parse_addr(h, 1);
     else
       log(L_DEBUG "nl_scan_ifaces: Unknown packet received (type=%d)", h->nlmsg_type);
 
@@ -804,7 +813,7 @@ nl_parse_route(struct nlmsghdr *h, int scan)
   net *net = net_get(p->p.table, dst, i->rtm_dst_len);
 
   rta ra = {
-    .proto = &p->p,
+    .src= p->p.main_source,
     .source = RTS_INHERIT,
     .scope = SCOPE_UNIVERSE,
     .cast = RTC_UNICAST
@@ -843,9 +852,11 @@ nl_parse_route(struct nlmsghdr *h, int scan)
          memcpy(&ra.gw, RTA_DATA(a[RTA_GATEWAY]), sizeof(ra.gw));
          ipa_ntoh(ra.gw);
 
+#ifdef IPV6
          /* Silently skip strange 6to4 routes */
          if (ipa_in_net(ra.gw, IPA_NONE, 96))
            return;
+#endif
 
          ng = neigh_find2(&p->p, &ra.gw, ra.iface,
                           (i->rtm_flags & RTNH_F_ONLINK) ? NEF_ONLINK : 0);
@@ -859,19 +870,6 @@ nl_parse_route(struct nlmsghdr *h, int scan)
       else
        {
          ra.dest = RTD_DEVICE;
-
-         /*
-          * In Linux IPv6, 'native' device routes have proto
-          * RTPROT_BOOT and not RTPROT_KERNEL (which they have in
-          * IPv4 and which is expected). We cannot distinguish
-          * 'native' and user defined device routes, so we ignore all
-          * such device routes and for consistency, we have the same
-          * behavior in IPv4. Anyway, users should use RTPROT_STATIC
-          * for their 'alien' routes.
-          */
-
-         if (i->rtm_protocol == RTPROT_BOOT)
-           src = KRT_SRC_KERNEL;
        }
 
       break;
@@ -977,7 +975,7 @@ nl_async_msg(struct nlmsghdr *h)
     case RTM_NEWADDR:
     case RTM_DELADDR:
       DBG("KRT: Received async address notification (%d)\n", h->nlmsg_type);
-      nl_parse_addr(h);
+      nl_parse_addr(h, 0);
       break;
     default:
       DBG("KRT: Received unknown async notification (%d)\n", h->nlmsg_type);
@@ -1038,11 +1036,9 @@ nl_open_async(void)
   sock *sk;
   struct sockaddr_nl sa;
   int fd;
-  static int nl_open_tried = 0;
 
-  if (nl_open_tried)
+  if (nl_async_sk)
     return;
-  nl_open_tried = 1;
 
   DBG("KRT: Opening async netlink socket\n");
 
@@ -1063,18 +1059,18 @@ nl_open_async(void)
   if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0)
     {
       log(L_ERR "Unable to bind asynchronous rtnetlink socket: %m");
+      close(fd);
       return;
     }
 
+  nl_async_rx_buffer = xmalloc(NL_RX_SIZE);
+
   sk = nl_async_sk = sk_new(krt_pool);
   sk->type = SK_MAGIC;
   sk->rx_hook = nl_async_hook;
   sk->fd = fd;
   if (sk_open(sk))
     bug("Netlink: sk_open failed");
-
-  if (!nl_async_rx_buffer)
-    nl_async_rx_buffer = xmalloc(NL_RX_SIZE);
 }
 
 /*
@@ -1084,19 +1080,18 @@ nl_open_async(void)
 static u8 nl_cf_table[(NL_NUM_TABLES+7) / 8];
 
 void
-krt_sys_start(struct krt_proto *p, int first)
+krt_sys_start(struct krt_proto *p)
 {
   nl_table_map[KRT_CF->sys.table_id] = p;
-  if (first)
-    {
-      nl_open();
-      nl_open_async();
-    }
+
+  nl_open();
+  nl_open_async();
 }
 
 void
-krt_sys_shutdown(struct krt_proto *p UNUSED, int last UNUSED)
+krt_sys_shutdown(struct krt_proto *p UNUSED)
 {
+  nl_table_map[KRT_CF->sys.table_id] = NULL;
 }
 
 int