]> git.puffer.fish Git - mirror/frr.git/commitdiff
[zebra] Make BSD link-state deal more gracefully with GIFMEDIA ioctl error
authorPaul Jakma <paul.jakma@sun.com>
Tue, 1 Jul 2008 18:24:58 +0000 (18:24 +0000)
committerPaul Jakma <paul.jakma@sun.com>
Tue, 1 Jul 2008 18:24:58 +0000 (18:24 +0000)
2008-07-01 Paul Jakma <paul.jakma@sun.com>

* ioctl.c: (if_get_flags) Deal more gracefully with failure
  of the BSD link-state SIOCGIFMEDIA ioctl, as some interfaces
  apparently don't implement it (e.g. tun).
  Also, make BSD link-state checking be conditional on the
  'link-detect' interface configuration flag, as it should be.
  Fixes bug #465.

zebra/ChangeLog
zebra/ioctl.c

index 6483f2c7445926b0001ddde152e7bd504250a7c2..341c42a4088963d96cc2074fabdf9f59a0a6e2ac 100644 (file)
@@ -1,3 +1,12 @@
+2008-07-01 Paul Jakma <paul.jakma@sun.com>
+
+       * ioctl.c: (if_get_flags) Deal more gracefully with failure
+         of the BSD link-state SIOCGIFMEDIA ioctl, as some interfaces
+         apparently don't implement it (e.g. tun).
+         Also, make BSD link-state checking be conditional on the 
+         'link-detect' interface configuration flag, as it should be.
+         Fixes bug #465.
+
 2008-06-02 Denis Ovsienko
 
        * connected.c: (connected_up_ipv4, connected_down_ipv4,
index d536771a1147211c96e32aaa0f65a05d594e9cbf..5cf9e7b0531890464e6860453b9ac4ea6d5628d5 100644 (file)
@@ -362,22 +362,29 @@ if_get_flags (struct interface *ifp)
       return;
     }
 #ifdef HAVE_BSD_LINK_DETECT /* Detect BSD link-state at start-up */
-  (void) memset(&ifmr, 0, sizeof(ifmr));
-  strncpy (&ifmr.ifm_name, ifp->name, IFNAMSIZ);
-  if (if_ioctl(SIOCGIFMEDIA, (caddr_t) &ifmr) < 0)
-    {
-      zlog_err("if_ioctl(SIOCGIFMEDIA) failed: %s", safe_strerror(errno));
-      return;
-    }
-  if (ifmr.ifm_status & IFM_AVALID) /* Link state is valid */
+
+  /* Per-default, IFF_RUNNING is held high, unless link-detect says
+   * otherwise - we abuse IFF_RUNNING inside zebra as a link-state flag,
+   * following practice on Linux and Solaris kernels
+   */
+  SET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
+  
+  if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
     {
-      if (ifmr.ifm_status & IFM_ACTIVE)
-       SET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
-      else
-       UNSET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
-    }
-  else /* Force always up */
-    SET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
+      (void) memset(&ifmr, 0, sizeof(ifmr));
+      strncpy (&ifmr.ifm_name, ifp->name, IFNAMSIZ);
+      
+      /* Seems not all interfaces implement this ioctl */
+      if (if_ioctl(SIOCGIFMEDIA, (caddr_t) &ifmr) < 0)
+        zlog_err("if_ioctl(SIOCGIFMEDIA) failed: %s", safe_strerror(errno));
+      else if (ifmr.ifm_status & IFM_AVALID) /* Link state is valid */
+        {
+          if (ifmr.ifm_status & IFM_ACTIVE)
+            SET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
+          else
+            UNSET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
+        }
+  }
 #endif /* HAVE_BSD_LINK_DETECT */
 
   if_flags_update (ifp, (ifreq.ifr_flags & 0x0000ffff));