Code Monkey home page Code Monkey logo

Comments (6)

arsv avatar arsv commented on May 20, 2024

Could you try running it with this patch?
https://gist.github.com/arsv/ba776748c44e5763af2ff9b93fe70b6f

ifi->ifi_flags & IFF_RUNNING) ? "Up" : "Down"

That's exactly what ifmon monitors:

int gotcarrier = (msg->flags & IFF_RUNNING);

Also afaik there's no such thing as cable detection, at least at userspace level. It only detects carrier. The cable is unplugged, or cable is plugged but the router is off — it's the same state, "no-carrier".

The problem is not that it cannot detect router-off condition, it can. Rapid changes in carrier state are most likely the problem.

from minibase.

bkauler avatar bkauler commented on May 20, 2024

The situation in the first post, with cable plugged in and router turned off. 'ifmon' with the traces patch is running. Now turn on the router:

carrier up on eth0
carrier rising edge
fork 5365 conf-request eth0
+++ conf-request eth0
dhcp: discover: ETIMEDOUT
exit 5365 65280
carrier down on eth0
carrier falling edge
carrier up on eth0
carrier rising edge
fork 5427 conf-request eth0
+++ conf-request eth0
dhcp: discover: ETIMEDOUT
exit 5427 65280

...interesting, is is calling conf-request. Now, unplug the cable:

carrier down on eth0
carrier falling edge

Now plug in the cable:

carrier up on eth0
carrier rising edge
fork 6286 conf-request eth0
+++ conf-request eth0
+++ dhcp-gw 192.168.1.1
+++ dhcp-dns 192.168.43.1 168.126.63.2
exit 6286 0
assuming discontinuous mode dhcp

...and now online!

from minibase.

arsv avatar arsv commented on May 20, 2024

Ah, I see. The router brings up carrier early but cannot respond to DHCP requests until much later in its boot process. The initial configuration attempt times out before the router boots up, and ifmon never re-tries.

So my current idea on this is to increase re-send timeout and the number of allowed re-sends for dhcp, let it try for several seconds maybe, and also probably add a command to ifctl to force a re-try. Neither is a good solution, but I don't think there's any way for ifmon to know that the router is finally ready.

This may be a valid reason to introduce per-profile dhcp scripts, at least as an option.

from minibase.

bkauler avatar bkauler commented on May 20, 2024

Yes, it will need a fix, even if not optimal, as I think this is probably a common situation, the user forgetting to turn on the modem/router, or having to reset it.

from minibase.

bkauler avatar bkauler commented on May 20, 2024

I have a workaround, not elegant, but it works. In /etc/net/conf-request, I inserted a call to script /sbin/dhcp-delayed:

#!/bin/sh
IF="$1"
echo "+++ conf-request ${IF}"
dhcp-delayed ${IF} & #fallback
dhcp ${IF} request

Content of /sbin/dhcp-delayed:

#!/bin/sh
IF="$1"
PIDS=$(pidof dhcp-delayed | wc -w) #get 2 when only one running.
[ $PIDS -gt 2 ] && exit
sleep 40
DNS="$(dhcp ${IF} show | grep '^dns ')"
[ "$DNS" ] && exit
echo "Attempting delayed execution: dhcp ${IF} request"
dhcp $IF request

Pretty simple, dhcp-delayed waits long enough so that all the carrier up/downs have finished, and if the "dhcp $IF request" has not succeeded, does it again.

I don't know if anything like this can be put into ifmon, but anyway, the script works for me. 40 seconds is just long enough, might be better to increase it a bit.

from minibase.

arsv avatar arsv commented on May 20, 2024

Currently dhcp keeps re-trying for 5s. Which is about as high as it should be for this mode of operation. I thought it was lower but turns out I changed the timeout some time ago. Timeouts around 40s call for a different solution. A script like this is very host-specific, I cannot just hard-code some large time constant and expect it to work well for everyone.

I checked a couple of other implementations, dhcpcd retries for 30s by default and udhcpd from Busybox for 20s. That's already high enough to be configurable (prompting per-profile scripts) yet probably too low to handle your case.

Not sure what's the proper solution here. dhcp is designed around the assumption that it can be a short-running tool. And that should be enough for the vast majority of cases, per my understanding of the DHCP protocol. DHCP makes no provisions for servers suddenly appearing long after the clients sent all their requests.

Your script is actually a good idea, but it can be simplified further.
conf-request:

#!/bin/sh
dhcp-delayed $1

dhcp-delayed:

#!/bin/sh
dhcp $1 request && exit 0
sleep 40
dhcp $1 request

Your own custom double-request dhcp client.

from minibase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.