summaryrefslogtreecommitdiffstats
path: root/src/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-05-02 21:25:57 +0100
committerRoy Marples <roy@marples.name>2019-05-02 21:25:57 +0100
commit6a5b0466ccae3f25169ffca928dc359c5fea4fbc (patch)
treebd2d8c89a0c12b2d6967d3272654ec272d2671d6 /src/dhcpcd.c
parenta8b066e85fbcd3543f3232bb808ef864e41c6438 (diff)
downloaddhcpcd-6a5b0466ccae3f25169ffca928dc359c5fea4fbc.tar.xz
BSD: Simplify carrier detection once more.
RTM_IFINFO messages now send the un-molested link status to the main carrier handler which no longer polls on LINK_UNKNOWN. Instead, we check carrier status directly, which if unsupported we instead interface flags. This is 2019, all interface drivers should report link status correctly via RTM_IFINFO messages and trying to constantly work around this is error prone and time consuming.
Diffstat (limited to 'src/dhcpcd.c')
-rw-r--r--src/dhcpcd.c69
1 files changed, 10 insertions, 59 deletions
diff --git a/src/dhcpcd.c b/src/dhcpcd.c
index fa5d5d59..ecff2e57 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -653,25 +653,6 @@ configure_interface(struct interface *ifp, int argc, char **argv,
}
static void
-dhcpcd_pollup(void *arg)
-{
- struct interface *ifp = arg;
- int carrier;
-
- carrier = if_carrier(ifp); /* will set ifp->flags */
- if (carrier == LINK_UP && !(ifp->flags & IFF_UP)) {
- struct timespec tv;
-
- tv.tv_sec = 0;
- tv.tv_nsec = IF_POLL_UP * NSEC_PER_MSEC;
- eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcpcd_pollup, ifp);
- return;
- }
-
- dhcpcd_handlecarrier(ifp->ctx, carrier, ifp->flags, ifp->name);
-}
-
-static void
dhcpcd_initstate2(struct interface *ifp, unsigned long long options)
{
struct if_options *ifo;
@@ -724,35 +705,19 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
!ifp->active)
return;
- switch(carrier) {
- case LINK_UNKNOWN:
- carrier = if_carrier(ifp); /* will set ifp->flags */
- break;
- case LINK_UP:
- /* we have a carrier! Still need to check for IFF_UP */
- if (flags & IFF_UP)
+ if (carrier == LINK_UNKNOWN) {
+ if (ifp->wireless) {
+ carrier = LINK_DOWN;
ifp->flags = flags;
- else {
- /* So we need to poll for IFF_UP as there is no
- * kernel notification when it's set. */
- dhcpcd_pollup(ifp);
- return;
- }
- break;
- default:
+ } else
+ carrier = if_carrier(ifp);
+ } else
ifp->flags = flags;
- }
-
- /* If we here, we don't need to poll for IFF_UP any longer
- * if generated by a kernel event. */
- eloop_timeout_delete(ifp->ctx->eloop, dhcpcd_pollup, ifp);
+ if (carrier == LINK_UNKNOWN)
+ carrier = (ifp->flags & (IFF_UP | IFF_RUNNING)) ==
+ (IFF_UP & IFF_RUNNING) ? LINK_UP : LINK_DOWN;
- if (carrier == LINK_UNKNOWN) {
- if (errno != ENOTTY && errno != ENXIO) {
- /* Don't log an error if interface departed */
- logerr("%s: %s", ifp->name, __func__);
- }
- } else if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
+ if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
if (ifp->carrier != LINK_DOWN) {
if (ifp->carrier == LINK_UP)
loginfox("%s: carrier lost", ifp->name);
@@ -987,20 +952,6 @@ dhcpcd_prestartinterface(void *arg)
)
logerr("%s: %s", __func__, ifp->name);
- if (ifp->options->options & DHCPCD_LINK &&
- ifp->carrier == LINK_UNKNOWN)
- {
- int carrier;
-
- if ((carrier = if_carrier(ifp)) != LINK_UNKNOWN) {
- dhcpcd_handlecarrier(ifp->ctx, carrier,
- ifp->flags, ifp->name);
- return;
- }
- loginfox("%s: unknown carrier, waiting for interface flags",
- ifp->name);
- }
-
dhcpcd_startinterface(ifp);
}