Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

WiFi is disabled if LAN is connected

Sat Mar 08, 2014 9:30 pm

Hi folks,

i have a bit of a headscratcher here.
I'm trying to set up a pi as a wired-to-wifi router for my photovoltaics system as long as I don't have a proper internet connection there.
The routing works fine, even with my phone as an accesspoint.

BUT:
as soon as I plug in a wired network (e.g. my laptop) the WiFi stops.
wpa_cli shows wpa_state=DISCONNECTED.
WiFi does come back if I disconnect the wired network.
Is there a way to prevent this mechanism from kicking in?
The sledge hammer method would be to run a script periodically or when eth0 comes up and reenable the wlan with "wpa_cli reconnect" but I'd like to do it the clean way.

Regards
Aydan

Zachster1996
Posts: 58
Joined: Wed Aug 14, 2013 7:16 am

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 7:10 am

If I recall correctly there is a script in Linux that runs when a network interface is down. You could edit this script to bring down wlan0. However, I'm not sure where this script would be or even if I remember correctly the way that this works.

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 7:24 am

The ifplugd daemon is the culprit.
ifplugd is a daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with on-board network adapters, since it will only configure the interface when a cable is really connected.
See this thread:
http://www.raspberrypi.org/forum/viewto ... 63&t=28335
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 9:40 am

I suppose I'll have to dig into the workings of ifplugd.
Thanks for the pointer.

Regards
Aydan

Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 1:01 pm

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

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 2:08 pm

As you wanted a straightforward solution, why don't you simply remove the ifplugd package?
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 6:23 pm

ripat wrote:As you wanted a straightforward solution, why don't you simply remove the ifplugd package?
Won't that disable hotplugging?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: WiFi is disabled if LAN is connected

Sun Mar 09, 2014 7:27 pm

Aydan wrote:
ripat wrote:As you wanted a straightforward solution, why don't you simply remove the ifplugd package?
Won't that disable hotplugging?
The RPi doesn't really like hot plugging, in some cases the sudden voltage drop will cause a reboot when you plug in a new device.

Removing ifplugd disables the re-routing of your default route to the wireless when the wireless comes active. In my view ifplugd is the most useless piece of software on the planet. I like to be in total control of my network configuration.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Aydan
Posts: 727
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: WiFi is disabled if LAN is connected

Mon Mar 10, 2014 6:24 pm

disabling ifplugd will not allow hotplugging eth0 so i had to leave it on.
I just told it to do nothing when eth0 comes up. not exactly nice but it works.

Regards
Aydan

Return to “Networking and servers”