Netifd proto handler events - How to ifup an interface on event?

I'm trying get netifd to trigger an ifup of an interface for me if it goes down. I'm using ModemManager, so specifically I'm looking for when the interface drops back from the state of "connected" to "registered".

Actually I'm stymied because I do not know where it is possible to put the logic for doing this, other than just writing a separate script or daemon in C. I see that in the handlers there are functions for initialization and teardown. Are these files looped over at all? Is this where to add such functionality? Any tips appreciated.

The "hotplug" events are potentially useful here. There is a caveat that QMI and most of the ways of managing an LTE or similar modem need to poll the device for status changes in my experience; the modem doesn't "poke" the manager that it has lost connectivity.


The iface folder

There are three main environment variables that are passed to each iface hotplug script:

Variable name Description
ACTION Either “ifup” or “ifdown”
INTERFACE Name of the interface which went up or down (e.g. “wan” or “ppp0”)
DEVICE Physical device name which interface went up or down (e.g. “eth0.1” or “br-lan”)

Thanks Jeff!

I had considered hotplug scripts before but didn't know enough about how they worked. I am still unsure exactly what will trigger them, but I think it should work like this: all scripts in the /etc/hotplug.d/iface/ directory are executed in numerical order similar to how scripts in /etc/rc.d/ are, each script performs whatever actions it wants to, and the onus is on each script to not do anything too far beyond it's labelled scope.

With that in mind I put together the following script which seems to be working well enough for me. It seems to get triggered any time something happens on my "mobiledata" interface.

I'm not exactly happy not knowing exactly why it works though, lol

It looks like you've already recognized that your script could cause events that could cause it to be executed again that could cause events ....

You might want to only take action on what is important to you. With the $ACTION, $INTERFACE, and $DEVICE variables, you should be able to only do what you need to when, for example, your wwan interface goes down. At least as I scanned your script, it takes action for up and down both, on every interface on your system.

There are some interesting modem-supervision scripts linked from Though they're written in Perl, they've got some good ideas.

Thanks for pointing that out. Overlooked that $INTERFACE in this context is already in use and I shouldn't have named my interface variable $INTERFACE.