[Olsr-dev] [PATCH v1 9/9] all: use the getInterfaceLinkState function

Ferry Huberts (spam-protected)
Wed Feb 10 14:35:48 CET 2016


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c                | 5 +++++
 src/linux/kernel_routes_nl.c | 2 +-
 src/linux/net.c              | 5 +++++
 src/unix/ifnet.c             | 4 ++--
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/gateway.c b/src/gateway.c
index 1a34bfb..3e5b233 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -24,6 +24,7 @@
 #include "gateway.h"
 #include "egressTypes.h"
 #include "egressFile.h"
+#include "ifnet.h"
 
 #include <assert.h>
 #include <linux/rtnetlink.h>
@@ -1681,6 +1682,10 @@ static bool isInterfaceUp(int if_index) {
     return false;
   }
 
+  if (getInterfaceLinkState(name) == LINKSTATE_DOWN) {
+    return false;
+  }
+
   memset(&ifr, 0, sizeof(struct ifreq));
   strscpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
 
diff --git a/src/linux/kernel_routes_nl.c b/src/linux/kernel_routes_nl.c
index ca69182..fab4a03 100644
--- a/src/linux/kernel_routes_nl.c
+++ b/src/linux/kernel_routes_nl.c
@@ -129,7 +129,7 @@ static void netlink_process_link(struct nlmsghdr *h)
   }
 
   oif = ifaceName ? olsrif_ifwithname(ifaceName) : NULL;
-  up = ((ifi->ifi_flags & IFF_UP) != 0);
+  up = (getInterfaceLinkState(ifaceName) != LINKSTATE_DOWN) && ((ifi->ifi_flags & IFF_UP) != 0);
 
   if (!iface && up) {
     if (oif) {
diff --git a/src/linux/net.c b/src/linux/net.c
index 144139d..d361320 100644
--- a/src/linux/net.c
+++ b/src/linux/net.c
@@ -51,6 +51,7 @@
 #include "../olsr.h"
 #include "../log.h"
 #include "kernel_tunnel.h"
+#include "ifnet.h"
 
 #include <net/if.h>
 
@@ -707,6 +708,10 @@ bool olsr_if_isup(const char * dev)
 {
   struct ifreq ifr;
 
+  if (!dev || (getInterfaceLinkState(dev) == LINKSTATE_DOWN)) {
+    return false;
+  }
+
   memset(&ifr, 0, sizeof(ifr));
   strscpy(ifr.ifr_name, dev, IFNAMSIZ);
 
diff --git a/src/unix/ifnet.c b/src/unix/ifnet.c
index e475b9d..6d83206 100644
--- a/src/unix/ifnet.c
+++ b/src/unix/ifnet.c
@@ -167,7 +167,7 @@ chk_if_changed(struct olsr_if *iface)
    * First check if the interface is set DOWN
    */
 
-  if ((ifp->int_flags & IFF_UP) == 0) {
+  if ((getInterfaceLinkState(iface->name) == LINKSTATE_DOWN) || (ifp->int_flags & IFF_UP) == 0) {
     OLSR_PRINTF(1, "\tInterface %s not up and running - removing it...\n", iface->name);
     goto remove_interface;
   }
@@ -532,7 +532,7 @@ chk_if_up(struct olsr_if *iface, int debuglvl __attribute__ ((unused)))
 
   ifs.int_flags = ifr.ifr_flags;
 
-  if ( (ifs.int_flags & IFF_UP) == 0) {
+  if ((getInterfaceLinkState(iface->name) == LINKSTATE_DOWN) || ((ifs.int_flags & IFF_UP) == 0)) {
     OLSR_PRINTF(debuglvl, "\tInterface not up & running - skipping it...\n");
     return 0;
   }
-- 
2.5.0




More information about the Olsr-dev mailing list