set interface up before monitoring
author"Luc Saillard <luc@saillard.org>"
Sun Jun 15 10:06:44 2008 +0200 (2 months ago)
changeset 83d50bc9040307
parent 821b9d1ca06642
child 84c0b083d6c5b5
set interface up before monitoring
src/plugins/net.c
--- a/src/plugins/net.c Sun Jun 15 08:55:11 2008 +0200
+++ b/src/plugins/net.c Sun Jun 15 10:06:44 2008 +0200
@@ -91,6 +91,44 @@ net_interface_get_flags(int fd, const ch
/*
+ * Use SIOCSIFFLAGS to set interface status
+ *
+ * @param fd The socket connected to the kernel
+ * @param iface
+ * @return -1 error
+ * 0 link down
+ * 1 link up
+ */
+static int
+net_interface_set_up_flag(int fd, const char *iface)
+{
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1)
+ {
+ trace("SIOCGIFFLAGS failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if ((ifr.ifr_flags & IFF_UP) == IFF_UP)
+ return 1;
+
+ ifr.ifr_flags |= IFF_UP;
+
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) == -1)
+ {
+ trace("SIOCGIFFLAGS failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/*
* Use SIOCGIFADDR to get interface ip address
*
* @param fd The socket connected to the kernel
@@ -222,8 +260,6 @@ net_monitor(int fd, const char *iface)
trace("not monitoring loopback interface\n");
return -1;
}
-
- old_status = net_interface_get_beat_status(fd, iface);
if ( (flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING) )
{
@@ -234,7 +270,13 @@ net_monitor(int fd, const char *iface)
ifup(iface);
}
}
-
+ else if ((flags & IFF_UP) == 0)
+ {
+ /* Put the interface up, to be able to monitor it */
+ net_interface_set_up_flag(fd, iface);
+ }
+
+ old_status = net_interface_get_beat_status(fd, iface);
while (1)
{