[pkg-wpa-devel] [PATCH] add event hysteresis
Kel Modderman
kelrin at tpg.com.au
Sun Sep 24 13:53:58 UTC 2006
Jason, how does the following patch look to you?
Note, I used date instead of touch, simply because I'm aiming to use
only /bin:/sbin if possible. It assumes that wpa_lock crap has already been
removed.
Thanks, Kel.
Index: functions.sh
===================================================================
--- functions.sh (revision 721)
+++ functions.sh (working copy)
@@ -27,6 +27,7 @@
WPA_CLI_PNAME="wpa_cli"
WPA_CLI_PIDFILE="/var/run/wpa_action.$IFACE.pid"
WPA_CLI_LOGFILE="/var/log/wpa_action.log"
+WPA_CLI_TIMESTAMP="/var/run/wpa_action.$IFACE.timestamp"
# default ctrl_interface socket directory
if [ -z "$WPA_CTRL_DIR" ]; then
@@ -661,6 +662,35 @@
}
#####################################################################
+## hysteresis checking
+# Networking tools such as dhcp clients used with ifupdown can
+# synthesize artificial ACTION events, particuarly just after a
+# DISCONNECTED event is encountered immediately after a CONNECTED
+# event. This can lead to infinite event loops, and in extreme cases
+# has the potential to cause system instability.
+#
+wpa_hysteresis_event () {
+ echo "$(date +%s)" > "$WPA_CLI_TIMESTAMP"
+}
+
+wpa_hysteresis_check () {
+ if [ -f "$WPA_CLI_TIMESTAMP" ]; then
+ local TIME="$(date +%s)" TIMESTAMP TIMEWAIT
+ # current time minus 4 second event buffer
+ TIMEWAIT=$(($TIME-4))
+ # get time of last event
+ TIMESTAMP=$(cat $WPA_CLI_TIMESTAMP)
+ # compare values, allowing new action to be processed
+ # only if last action was more than 4 seconds ago
+ if [ "$TIMEWAIT" -le "$TIMESTAMP" ]; then
+ echo "Ignoring $WPA_ACTION event, too soon after previous event"
+ return 1
+ fi
+ fi
+ return 0
+}
+
+#####################################################################
## identify ifupdown files
# Identify ifupdown core files, so that state of the interface can be
# checked. This is the weakest part of the wpa_action roaming scheme,
Index: wpa_action.sh
===================================================================
--- wpa_action.sh (revision 721)
+++ wpa_action.sh (working copy)
@@ -38,16 +38,19 @@
case "$WPA_ACTION" in
"CONNECTED")
wpa_log_init
+ wpa_hysteresis_check || exit 1
wpa_log_action
wpa_log_environment
if ifupdown_check; then
ifup
fi
+ wpa_hysteresis_event
wpa_cli status
;;
"DISCONNECTED")
wpa_log_init
+ wpa_hysteresis_check || exit 1
wpa_log_action
wpa_log_environment
if ifupdown_check; then
More information about the Pkg-wpa-devel
mailing list