summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-06-18 21:15:15 +0100
committerRoy Marples <roy@marples.name>2020-06-18 21:15:15 +0100
commit009dc39be56be9b2fae857e64aa55c20f2842d13 (patch)
tree6085381f2e63161a8aa72f49eaac34f255f970be /src/if.c
parent3f9355273c90c21bb1fdaa8bac9776f8195301b2 (diff)
downloaddhcpcd-009dc39be56be9b2fae857e64aa55c20f2842d13.tar.xz
dhcpcd: Add an option to poll the interface carrier state
Only to be used if the interface does not report carrier state changes for whatever reason.
Diffstat (limited to 'src/if.c')
-rw-r--r--src/if.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/if.c b/src/if.c
index 9e158a9c..04a48c3b 100644
--- a/src/if.c
+++ b/src/if.c
@@ -64,7 +64,9 @@
#include <syslog.h>
#include <unistd.h>
+#define ELOOP_QUEUE ELOOP_IF
#include "common.h"
+#include "eloop.h"
#include "dev.h"
#include "dhcp.h"
#include "dhcp6.h"
@@ -661,6 +663,30 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
return ifs;
}
+static void
+if_poll(void *arg)
+{
+ struct interface *ifp = arg;
+ unsigned int flags = ifp->flags;
+ int carrier;
+
+ carrier = if_carrier(ifp); /* if_carrier will update ifp->flags */
+ if (ifp->carrier != carrier || ifp->flags != flags)
+ dhcpcd_handlecarrier(ifp->ctx, carrier, ifp->flags, ifp->name);
+
+ if (ifp->options->poll != 0 || ifp->carrier != LINK_UP)
+ if_pollinit(ifp);
+}
+
+int
+if_pollinit(struct interface *ifp)
+{
+ unsigned long msec;
+
+ msec = ifp->options->poll != 0 ? ifp->options->poll : IF_POLL_UP;
+ return eloop_timeout_add_msec(ifp->ctx->eloop, msec, if_poll, ifp);
+}
+
/*
* eth0.100:2 OR eth0i100:2 (seems to be NetBSD xvif(4) only)
*