[quagga-dev 1459] link detection on NetBSD

Miles Nordin carton at Ivy.NET
Sat Sep 11 17:36:02 BST 2004


Here is a simple clumsy patch for link detection on NetBSD.
Unfortunately I'm doing less than half the work it would take to
integrate this---really autoconf should probably test for this API,
since I bet it's present on some other BSDs.  The interface is
documented in route(4) RTM_IFINFO and /usr/include/net/if.h.

If OpenBSD/FreeBSD users could alter the #ifdef and test, it might be
helpful.  Remember not all cards support link detection.  On NetBSD,
AFAICT it is only cards with MII and maybe the wi(4) driver that
support it.

--- zebra/kernel_socket.c.orig	2004-09-10 03:54:16.000000000 -0400
+++ zebra/kernel_socket.c	2004-09-10 04:06:29.000000000 -0400
@@ -347,6 +347,11 @@
        */
       ifp->ifindex = ifm->ifm_index;
       ifp->flags = ifm->ifm_flags;
+#ifdef __NetBSD__
+      ifp->link_state = ifm->ifm_data.ifi_link_state;
+#else
+      ifp->link_state = 0;
+#endif
 #if defined(__bsdi__)
       if_kvm_get_mtu (ifp);
 #else
@@ -375,12 +380,18 @@
       if (if_is_up (ifp))
 	{
 	  ifp->flags = ifm->ifm_flags;
+#ifdef __NetBSD__
+          ifp->link_state = ifm->ifm_data.ifi_link_state;
+#endif
 	  if (! if_is_up (ifp))
 	    if_down (ifp);
 	}
       else
 	{
 	  ifp->flags = ifm->ifm_flags;
+#ifdef __NetBSD__
+          ifp->link_state = ifm->ifm_data.ifi_link_state;
+#endif
 	  if (if_is_up (ifp))
 	    if_up (ifp);
 	}
--- lib/if.h.orig	2004-09-10 03:58:00.000000000 -0400
+++ lib/if.h	2004-09-10 04:05:23.000000000 -0400
@@ -89,6 +89,7 @@
   
   /* Interface flags. */
   unsigned long flags;
+  int link_state;
 
   /* Interface metric */
   int metric;
--- lib/if.c.orig	2004-09-10 03:51:44.000000000 -0400
+++ lib/if.c	2004-09-10 04:12:27.000000000 -0400
@@ -341,7 +341,11 @@
 int
 if_is_running (struct interface *ifp)
 {
-  return ifp->flags & IFF_RUNNING;
+  return ifp->flags & IFF_RUNNING 
+#ifdef __NetBSD__
+				  && ifp->link_state != LINK_STATE_DOWN
+#endif
+				 ;
 }
 
 /* Is the interface operative, eg. either UP & RUNNING
@@ -350,7 +354,11 @@
 if_is_operative (struct interface *ifp)
 {
   return ((ifp->flags & IFF_UP) &&
-	  (ifp->flags & IFF_RUNNING || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)));
+	  ((ifp->flags & IFF_RUNNING 
+#ifdef __NetBSD__
+				     && ifp->link_state != LINK_STATE_DOWN
+#endif
+				     )|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)));
 }
 
 /* Is this loopback interface ? */


-- 
Le fascisme est la dictature ouverte de la bourgeoisie.
		-- Georg Dimitrov



More information about the Quagga-dev mailing list