Running scripts based on wireless interfaces events

Hi all,
I've written a sniffing application that captures probe request and send them via MQTT to some broker using libpcap and paho-mqtt3cs.

I would like to add some proactive verification to guarantee it's operation. If some process call (like adding new SSID on radio0 using luci) makes my monitor interface goes down I would like some daemon for restarting the application automatically a few seconds later.

Is it possible to achieve this with hotplug/iface scripts by setting my monitor interface name on DEVICE or IFACE? I'd like some directions towards debugging my scripts on the hotplug.d folder as well

Yes, I'd trigger on up/down of your monitor interface.

First would be to write a script that logs the events that you get and their environment so that you understand how the events occur and what you can trigger off of. >> /tmp/some/log/file

For debugging, you can use "printf debugging" or set -x or the like to track the execution.

1 Like

hey @jeff
Based on the doc page for hotplug the events being triggered at the iface are ifup/ifdown and my monitor interface event on dmesg is device mon0 left promiscuous mode. I tried to echo a message to /tmp/log/mylog without success, i've also tried to change the iface, action and devices to trigger in events on eth0, lan and none seem to trigger my script.

#!bin/sh
if [ "$ACTION" = "ifdown" ] && [ "$DEVICE"  = "mon0" ]; then
        echo "Device: $DEVICE went Action: $ACTION" >>  /tmp/log/mylog
fi

I placed under /etc/hotplug.d/iface and save as 99-my-script and add the +x flag using chmod.

am I failing to trigger the event for the hotplug execute its commands or am I making a mistake on the script?

To add to my initial question, how do I guarantee that my hotplug script run when it should?

I'd start with something simple, then base off those results. I'd type in (untested)

#!/bin/sh

printf "-----\n" >> /tmp/log/events
date >> /tmp/log/events
env >> /tmp/log/events

Gl.inet ar150 latest binary 2.64

Has somewhere what you are looking for.

As per the manual ar150 has to be set up via WiFi. If you get into serial console and turn off WiFi (ifconfig wlan0 down) router restarts the interface automatically after 10 15 seconds. Don’t know if the behavior stops after first set up or not

ubus might be of use to you?
https://openwrt.org/docs/techref/ubus

1 Like

Thanks for the suggestion.

Nowadays we're using procd based interface trigger for that (no need for any hotplug scripts). For reference look at "live" examples in the official OpenWrt package repository: https://github.com/openwrt/packages/search?q=procd_add_interface_trigger&type=Code

2 Likes