[prev in list] [next in list] [prev in thread] [next in thread] 

List:       quagga-dev
Subject:    [quagga-dev 5092] Freebsd and link-detect
From:       Ingo Flaschberger <if () xip ! at>
Date:       2007-10-04 19:15:19
Message-ID: alpine.LFD.0.9999.0710042112110.11743 () filebunker ! xip ! at
[Download RAW message or body]

hey,

I have written a patch to support link-detect at FreeBSD.

As I was not shure whats the best implementation, I decided to follow the 
last suggesting in quagga mailinglist in 2004:
http://osdir.com/ml/network.quagga.devel/2004-09/msg00035.html

Patch attached, applies to quagga 0.99.9 and tested at freebsd current.

Kind regards
         ingo flaschberger

["freebsd_linkdetect.diff" (TEXT/PLAIN)]

--- lib/zebra.h_org	Mon Aug 13 18:35:12 2007
+++ lib/zebra.h	Thu Oct  4 19:15:41 2007
@@ -86,6 +86,11 @@
 #endif /* HAVE_INTTYPES_H */
 
 /* machine dependent includes */
+#ifdef __FreeBSD__
+#include <net/if_media.h>
+#endif /* __FreeBSD__ */
+
+/* machine dependent includes */
 #ifdef SUNOS_5
 #include <strings.h>
 #endif /* SUNOS_5 */
--- zebra/ioctl.c_org	Thu Oct  4 19:16:23 2007
+++ zebra/ioctl.c	Thu Oct  4 19:19:59 2007
@@ -42,6 +42,15 @@
   strncpy (ifreq->ifr_name, ifp->name, IFNAMSIZ);
 }
 
+#ifdef __FreeBSD__
+/* clear and set interface name string for media status*/
+void
+ifmreq_set_name (struct ifmediareq *ifmr, struct interface *ifp)
+{
+  strncpy (ifmr->ifm_name, ifp->name, IFNAMSIZ);
+}
+#endif /* __FreeBSD__ */
+
 /* call ioctl system call */
 int
 if_ioctl (u_long request, caddr_t buffer)
@@ -344,6 +353,9 @@
 {
   int ret;
   struct ifreq ifreq;
+#ifdef __FreeBSD__
+  struct ifmediareq ifmr;
+#endif
 
   ifreq_set_name (&ifreq, ifp);
 
@@ -353,6 +365,28 @@
       zlog_err("if_ioctl(SIOCGIFFLAGS) failed: %s", safe_strerror(errno));
       return;
     }
+
+#ifdef __FreeBSD__ /* FreeBSD link detect */
+  (void) memset(&ifmr, 0, sizeof(ifmr));
+  ifmreq_set_name (&ifmr, ifp);
+
+  ret = if_ioctl (SIOCGIFMEDIA, (caddr_t) &ifmr);
+  if (ret < 0)
+    {
+      zlog_err("if_ioctl(SIOCGIFMEDIA) failed: %s", safe_strerror(errno));
+      return;
+    }
+  if ((ifmr.ifm_status & IFM_ACTIVE) || (ifmr.ifm_status & IFM_ACTIVE))
+    {
+      zlog_err("check: active");
+      SET_FLAG( ifreq.ifr_flags, IFF_RUNNING);
+    }
+  else
+    {
+      zlog_err("check: no carrier");
+      UNSET_FLAG( ifreq.ifr_flags, IFF_RUNNING);
+    }
+#endif
 
   if_flags_update (ifp, (ifreq.ifr_flags & 0x0000ffff));
 }
--- zebra/kernel_socket.c_org	Thu Oct  4 19:21:21 2007
+++ zebra/kernel_socket.c	Thu Oct  4 19:25:58 2007
@@ -427,6 +427,17 @@
        * structure with ifindex IFINDEX_INTERNAL.
        */
       ifp->ifindex = ifm->ifm_index;
+
+#ifdef __FreeBSD__ /* FreeBSD link detect */
+      if (ifm->ifm_data.ifi_link_state == LINK_STATE_UP)
+        {
+          SET_FLAG( ifm->ifm_flags, IFF_RUNNING);
+        }
+      else
+        {
+          UNSET_FLAG( ifm->ifm_flags, IFF_RUNNING);
+        }
+#endif
       if_flags_update (ifp, ifm->ifm_flags);
 #if defined(__bsdi__)
       if_kvm_get_mtu (ifp);
@@ -454,6 +465,16 @@
           return -1;
         }
       
+#ifdef __FreeBSD__ /* FreeBSD link detect */
+      if (ifm->ifm_data.ifi_link_state == LINK_STATE_UP)
+        {
+          SET_FLAG( ifm->ifm_flags, IFF_RUNNING);
+        }
+      else
+        {
+          UNSET_FLAG( ifm->ifm_flags, IFF_RUNNING);
+        }
+#endif
       /* update flags and handle operative->inoperative transition, if any */
       if_flags_update (ifp, ifm->ifm_flags);
       


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
http://lists.quagga.net/mailman/listinfo/quagga-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic