I just tried to write a script that checks if the interfaces (eth0, wlan0) are in the same subnet before bringing down the wlan interface.
I did this by modifying /etc/wpa_supplicant/action_wpa.sh to call a script that checks for the subnet.
The script works, the script gets called, but the eth0 interface doesn't have an IP yet. so I added a wait loop, but this blocks the interface from getting an IP

now I'm fresh out of ideas what to do.
here's the scripts:
action_wpa.sh
Code: Select all
#!/bin/sh
# Action script to enable/disable wpa-roam interfaces in reaction to
# ifplugd events.
#
# Copyright: Copyright (c) 2008-2010, Kel Modderman <kel@otaku42.de>
# License: GPL-2
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
if [ ! -x /sbin/wpa_action ]; then
exit 0
fi
# ifplugd(8) - <iface> <action>
#
# If an ifplugd managed interface is brought up, disconnect any
# wpa-roam managed interfaces so that only one "roaming" interface
# remains active on the system.
IFPLUGD_IFACE="${1}"
case "${2}" in
up)
COMMAND=disconnect
;;
down)
COMMAND=reconnect
;;
*)
echo "$0: unknown arguments: ${@}" >&2
exit 1
;;
esac
for CTRL in /var/run/wpa_supplicant/*; do
[ -S "${CTRL}" ] || continue
IFACE="${CTRL#/var/run/wpa_supplicant/}"
# skip if ifplugd is managing this interface
if [ "${IFPLUGD_IFACE}" = "${IFACE}" ]; then
continue
fi
this is the part I added:
Code: Select all
# ignore if the interfaces use different subnets (no roaming)
if [ "$2" = "up" ]; then
/etc/wpa_supplicant/action_wpa_check_subnet.sh $IFACE $IFPLUGD_IFACE
fi
if [ $? -eq 0 ]; then
echo leave $IFACE up
continue
else
echo bring $IFACE down
fi
Code: Select all
if wpa_action "${IFACE}" check; then
wpa_cli -i "${IFACE}" "${COMMAND}"
fi
done
and my check script:
action_wpa_check_subnet.sh
Code: Select all
#!/bin/bash
#check if interface 1 and interface 2 use the same subnet. if so return 1 else return 0
IFACE1="$1"
IFACE2="$2"
echo checking $IFACE1 against $IFACE2
get_addr () {
#echo determine IP addr for $1
ADDR=$(LC_MESSAGES=C ifconfig $1 | grep "inet addr" | awk '{ if ( $1 == "inet" ) { print $2 } }' | cut -d: -f2)
#echo $ADDR
}
get_mask (){
MASK=$(LC_MESSAGES=C ifconfig $1 | grep "inet addr" | awk '{ print $4 }' | cut -d: -f2)
#echo $MASK
}
#wait for IPs or time out
TIMEOUT=30
for (( i=0; i<$TIMEOUT; i++))
do
IP1=$(get_addr $IFACE1)
echo $IP1
if [ ! -z $IP1 ]; then
MASK1=$(get_mask $IFACE1)
break
fi
sleep 1
done
for (( i=0; i<$TIMEOUT; i++))
do
IP2=$(get_addr $IFACE2)
echo $IP2
if [ ! -z $IP1 ]; then
MASK2=$(get_mask $IFACE2)
break
fi
sleep 1
done
echo $IP1:$MASK1 $IP2:$MASK2
if [ "$MASK1" == "$MASK2" ]; then
#echo identical masks
#echo checking IPs
for i in 1 2 3 4
do
#echo checking byte $i of IP
if [ "$(echo $MASK1 | cut -d. -f$i)" == "255" ]; then
echo "$(echo $IP1 | cut -d. -f$i)"
echo "$(echo $IP2 | cut -d. -f$i)"
if [ "$(echo $IP1 | cut -d. -f$i)" != "$(echo $IP2 | cut -d. -f$i)" ]; then
#echo different subnets
exit 0
#else
# echo checking next byte
fi
else
#echo mask has ended
break
fi
done
#echo same subnet
exit 1
else
#echo different masks, most likely different subnets
exit 0
fi
exit 0
I find it extremely strange that the script would block the acquisition of the IP address for the interface being brought up.
Regards
Aydan