Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
versatile networking wlan0/eth0
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Pilsner
Tux's lil' helper
Tux's lil' helper


Joined: 14 Mar 2008
Posts: 89

PostPosted: Fri May 13, 2011 1:16 pm    Post subject: versatile networking wlan0/eth0 Reply with quote

Hello, gents.
I am using laptop both at home and at work and those are 2 different environments in terms of networking. At home I connect with WiFi, while at work I use wired Ethernet. Both networks assign addresses via DHCP. Now, the issue is that at home I have pretty long system startup delays because of DHCP on eth0 waiting for carrier and then timing out.
Is it possible to make network setup in "/etc/conf.d/net" or in other place so that wlan0 only starts at home and eth0 only starts at work?
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 13, 2011 1:44 pm    Post subject: Reply with quote

Take a look at sys-apps/ifplugd. It's mentioned in the Handbook as a solution to this type of problem.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Pilsner
Tux's lil' helper
Tux's lil' helper


Joined: 14 Mar 2008
Posts: 89

PostPosted: Fri May 13, 2011 2:12 pm    Post subject: Reply with quote

Thanks. This should be what I needed. I'll try to install it and test at home.
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Fri May 13, 2011 3:43 pm    Post subject: Reply with quote

I once got the impression (perhaps even from Uberlord himself, here on a forum thread) that as of dhcpcd-5.x netplug/ifplugd wasn't necessary, dhcpcd could avoid the no-link-beat timeout all by itself.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 996

PostPosted: Fri May 13, 2011 11:10 pm    Post subject: Reply with quote

That would be nice, since after migrating to OpenRC, it looks like ifplugd is not doing the interface down function properly. I'm still stuck with a default route even if I unplug the cable..Which wreaks havoc if I e.g. activate my wireless after that.
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1931

PostPosted: Fri May 13, 2011 11:33 pm    Post subject: Reply with quote

Now that we're all on OpenRC, if your network setup is simple (just DHCP), remove net.eth0 and net.wlan0 and instead add dhcpcd and wpa_supplicant to the default runlevel. This would cause netowork to start up instantly, and it will connect to the right thing (wired if available, wireless otherwise).
_________________
“And even in authoritarian countries, information networks are helping people discover new facts and making governments more accountable.”– Hillary Clinton, Jan. 21, 2010
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 996

PostPosted: Sat May 14, 2011 8:18 am    Post subject: Reply with quote

Etal wrote:
Now that we're all on OpenRC, if your network setup is simple (just DHCP), remove net.eth0 and net.wlan0 and instead add dhcpcd and wpa_supplicant to the default runlevel. This would cause netowork to start up instantly, and it will connect to the right thing (wired if available, wireless otherwise).


Well, it's not simple as such; I don't want e.g. sshd to start when I'm on wireless, but only when I'm with wired. I've so far used postup() scripts for this.

Also, OpenRC migration guide (http://www.gentoo.org/doc/en/openrc-migration.xml) doesn't say anything about such features.
Back to top
View user's profile Send private message
ddriver
n00b
n00b


Joined: 24 Feb 2005
Posts: 67

PostPosted: Mon May 23, 2011 12:39 am    Post subject: Reply with quote

Etal wrote:
Now that we're all on OpenRC, if your network setup is simple (just DHCP), remove net.eth0 and net.wlan0 and instead add dhcpcd and wpa_supplicant to the default runlevel. This would cause netowork to start up instantly, and it will connect to the right thing (wired if available, wireless otherwise).


Is this a valid thing to do?

I've been struggling with wireless interfaces dropping the wpa_supplicant process when I change SSID. I added these services to the default level and it seemed to fix it. Then I did the same to another box that has some static addresses configured and it totally screwed it. It assigned DHCP addresses to the interfaces before the static ones, then added a second interface to them, e.g. eth0:1 and gave these the static addresses from /etc/conf.d/net.

Seems that openrc isn't as stable as we would hope.
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Mon May 23, 2011 1:33 pm    Post subject: How o put wpa_supplicant in default runlevel Reply with quote

Etal wrote:
... and instead add dhcpcd and wpa_supplicant to the default runlevel. ...

Could you please explain how to do this with wpa_supplicant?
My /etc/init.d/ does not have a script for wpa_supplicant.
I am using net-wireless/wpa-supplicant-0.7.3-r2.
Back to top
View user's profile Send private message
ddriver
n00b
n00b


Joined: 24 Feb 2005
Posts: 67

PostPosted: Mon May 23, 2011 2:06 pm    Post subject: Reply with quote

My /etc/init.d/ does have a script for wpa_supplicant. Strange that yours doesn't. I am on the same version.

I suspect that the package installs differently depending on whether openrc has already been installed. I have a couple of machines where I have reinstalled wpa_supplicant since the openrc upgrade and they have this file. equery belongs shows the file as belonging to net-wireless/wpa_supplicant-0.7.3-r2. Another machine that had wpa_supplicant installed pre-openrc doesn't have the file.

Try reinstalling wpa_supplicant and see whether the file appears.

In any case I don't think it is generally a good idea to add dhcpcd or wpa_supplicant to the default runlevel. dhcpcd causes breakage for interfaces with static IP addresses and wpa_supplicant causes breakages on interfaces used for hostapd.
Back to top
View user's profile Send private message
ddriver
n00b
n00b


Joined: 24 Feb 2005
Posts: 67

PostPosted: Mon May 23, 2011 2:28 pm    Post subject: Reply with quote

I can also add that my original problem of wpa_supplicant dying when the SSID is changed also goes away when wpa_supplicant is re-emerged.

Makes you wonder how many other packages need re-installing after upgrading to baselayout2/openrc.
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Mon May 23, 2011 2:42 pm    Post subject: Reply with quote

I have ifplugd and I do not start wpa_supplicant on boot automatiocally ( neither net.wlan0 nor wpa_supplicant are added to run levels). Instead I start wireless through acpi even generated by Fn-F5 when I need it. Haven't had problems yet, although I just realised that I have not used wired on that laptop since upgrading to Openrc, so maybe iflpugd is misbehaving now.

Overtime wpa_supplicant.conf accumulated configs of maby 20 places I use often, inlcuding my local airport, so in most cases connection is seamless.
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 996

PostPosted: Mon May 23, 2011 3:05 pm    Post subject: Reply with quote

dmpogo wrote:
I have ifplugd and I do not start wpa_supplicant on boot automatiocally ( neither net.wlan0 nor wpa_supplicant are added to run levels). Instead I start wireless through acpi even generated by Fn-F5 when I need it. Haven't had problems yet, although I just realised that I have not used wired on that laptop since upgrading to Openrc, so maybe iflpugd is misbehaving now.

Overtime wpa_supplicant.conf accumulated configs of maby 20 places I use often, inlcuding my local airport, so in most cases connection is seamless.


Could you post your acpi script? I have been using similar method, but sort of ran into problems (it's not working reliably - sometimes nothing happens no matter if I press fn-f5 - probably the service is in some sort of starting/stopping state and refuses to move on). Mine is basically the following - I'm unloading and reloading the module due to the fact that sometimes suspend/resume borks my wireless driver and I can thus reload it easily.

Code:
#!/bin/sh
if ! iwconfig wlan 2>&1 > /dev/null ; then
  modprobe iwlagn
fi

if rc-status -Cau | grep net.wlan | grep stop > /dev/null ; then
  /etc/init.d/net.wlan start &
else
  /etc/init.d/net.wlan stop
  rmmod iwlagn
fi
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Mon May 23, 2011 3:33 pm    Post subject: How to configure for properly working netplug? Reply with quote

Before migrating to Baselayout2 everything worked fine. I have sys-apps/netplug and it automatically brought up net.eth0 and down net.wlan0 when I inserted the cable. Also, net.wlan0 was brought up and net.eth0 down when the cable was unplugged. On boot, dependant on rfkill status, net.wlan0 was started or backgrounded. In runlevel there is net.wlan0 but not net.eth0 nor wpa_supplicant or dhcpcd.

After migration to Baselayout2 everything seemed to work fine because I forgot to test net.eth0. With present settings, wireless comes up on boot but netplug does no longer switch to net eth0. It only kills net.wlan0.

BTW, this is my /etc/init.d/net:
/etc/init.d/net wrote:
# /etc/conf.d/net:

modules="wpa_supplicant"

modules_eth0="ifconfig"
config_eth0="dhcp"
dhcpcd_eth0="-t 20"

modules_wlan0="wpa_supplicant"
config_wlan0="dhcp"
dhcpcd_wlan0="-t 20"
wpa_supplicant_wlan0="-Dwext"

So, what configuration do we need to make netplug / ifplugd to work as it should?
What needs to really be in runlevel, what rc_depend_strict="?" and rc_hotplug="?"
It shouldn't be that difficult to get back a properly working configuration.

I already tested with wpa_supplicant and dhcpcd in runlevel, but this only caused problems and didn't really help :-(
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Mon May 23, 2011 3:36 pm    Post subject: Reply with quote

Do you have the /etc/init.d/net.eth0 symlink in place? The baselayout2 upgrade deletes it, and it needs to be added back manually. On most of my systems I was prepared and took care of it. On my main server, I missed it because net.tun0 and net.eth1 were both there, on a quick glance I failed to notice that net.wth0 wasn't.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Mon May 23, 2011 4:26 pm    Post subject: Reply with quote

Re acpi script

The snippet in acpi script that handles Fn-F5 is
Code:


.....
X_USER=`who | sed -ne "s/^\([^[:space:]]*\)[[:space:]]*:0.*/\1/p"`
if [ -n "$X_USER" ]; then
   export DISPLAY=":0.0"
   export XAUTHORITY=/home/${X_USER}/.Xauthority
fi

function x_info () {
        if [ -n "$XAUTHORITY" ]; then
                echo $1 | osd_cat -d 3 -p bottom -A center -o -50 -s 2 -c $2 -f
-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1
        fi
}

.................

       00001005)
                # Fn-F5 starts-stops wireless services (semi-standard)
                # without the handler wlan will just be toggled with RFKILL
                # In my network config wlan stop comes with disabling radio
                status=`/etc/init.d/net.wlan0 status`
                status=${status#* status:}
                if   [ $status == started ] ; then
                        /etc/init.d/net.wlan0 --quiet stop
                elif [ $status == stopped ] ; then
                     if [ `cat ${THINKPAD_ACPI_DIR}/hotkey_radio_sw` == 1 ] ; then
                        /etc/init.d/net.wlan0 --quiet start
                    else
                       x_info "Radio Switch in the back is off" red
                    fi
                elif [ $status == inactive ] ; then
                     # This perhaps can arise if there are no AP's
                     /etc/init.d/net.wlan0 --quiet stop &
                     message="Stopping inactive WLAN. No AP's or a hang ?"
                     x_info "$message" red
                     logger "$message"
                fi
                ;;


The check on hotkey_radio_sw is from the days when hardware switch on the back did not actually switch wlan, just generated event.
Now it works properly and this check could have been omitted

This is coupled with the following /etc/conf.d/net

Code:

modules=( "ifconfig" )

config_eth0=( "dhcp" )
dhcp_eth0=( "release nontp" )
dhcpcd_eth0=( "-q -t 20" )

config_wlan0=( "dhcp" )
dhcp_wlan0=( "release nontp" )
dhcpcd_wlan0=( "-q -t 60" )

modules=( "wpa_supplicant" )
wpa_supplicant_wlan0="-Dwext -c /etc/wpa_supplicant/wpa_supplicant.conf"

#ifplugd_wlan0=( "--api-mode=wlan" )

preup() {
        if [ ${IFACE} == 'wlan0' ] && [ -x /usr/bin/wpa_gui ]; then
           X_USER=`who | sed -ne "s/^\([^[:space:]]*\)[[:space:]]*:0.*/\1/p"`
           if [ -n "$X_USER" ]; then
              export DISPLAY=":0.0"
              export XAUTHORITY=/home/${X_USER}/.Xauthority
              pgrep wpa_gui || /usr/bin/wpa_gui -t &
           else
              einfo "No X server is running for wpa_gui"
           fi
        fi
        return 0
}

postdown() {
        if [ ${IFACE} == 'wlan0' ]; then
           killall wpa_gui
        fi
        return 0
}

Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Mon May 23, 2011 5:15 pm    Post subject: Reply with quote

depontius wrote:
Do you have the /etc/init.d/net.eth0 symlink in place?
Of course. both /etc/init.d/net.wlan0 and /etc/init.d/eth0 are there, created manually. And from these only net.eth0 is in runlevel.
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 996

PostPosted: Tue May 24, 2011 11:10 am    Post subject: Reply with quote

Ok, so in /etc/conf.d/net you are only starting and stopping wpa_gui, no other magic happens there?

I haven't minded wpa_gui (since it's minimized to system tray most of the time anyway).

I'll try your script out, might work better than my meager attempts..
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Tue May 24, 2011 1:19 pm    Post subject: Reply with quote

Zarhan wrote:
Ok, so in /etc/conf.d/net you are only starting and stopping wpa_gui, no other magic happens there?

I haven't minded wpa_gui (since it's minimized to system tray most of the time anyway).

I'll try your script out, might work better than my meager attempts..


Yes, I actually realised it just now. In the earlier incarnation I used to insert and remove the iwlagn module (actually, before it was iwlagn), since it was "hanging" sometimes.

My main logic was that I want one key control of the wlan, and do not want wlan on by default, because I often launch my laptop who knows where, in the airport, on a plane, so unfamiliar. So I did not want to associating with anything unless I told so.
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 996

PostPosted: Tue May 24, 2011 2:17 pm    Post subject: Reply with quote

dmpogo wrote:

My main logic was that I want one key control of the wlan, and do not want wlan on by default, because I often launch my laptop who knows where, in the airport, on a plane, so unfamiliar. So I did not want to associating with anything unless I told so.


Yeah, my use-case is similar.

Code:
if [ `cat ${THINKPAD_ACPI_DIR}/hotkey_radio_sw` == 1 ] ; then


I don't think this one works at least for me. I changed it to

Code:
if [ rfkill list wlan | grep "Hard blocked: no" ] ; then


Also, still getting some weird behavior, sometimes the scripts get stuck ("net.wlan is being stopped by something else"). Oh well...
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1931

PostPosted: Tue May 24, 2011 2:41 pm    Post subject: Reply with quote

Why would you put wpa_gui in the init script? That's completely not the place for it.

You know you can just add it to your DE/WM's autostart?

(You can control it as a user if you add "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel" into /etc/wpa_supplicant/wpa_supplicant.conf)
_________________
“And even in authoritarian countries, information networks are helping people discover new facts and making governments more accountable.”– Hillary Clinton, Jan. 21, 2010
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Tue May 24, 2011 2:50 pm    Post subject: Reply with quote

Etal wrote:
Why would you put wpa_gui in the init script? That's completely not the place for it.

You know you can just add it to your DE/WM's autostart?

(You can control it as a user if you add "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel" into /etc/wpa_supplicant/wpa_supplicant.conf)


I'll be happy to consider better way !

autostart is not good enough, because first of all I sometimes switch between DE's, and secondly, I switch on/off wlan more often than I start/stop DE.
I need something to start/stop wpa_gui when I start/stop wlan, which is done by Fn-F5 in my case.

You are right that pre/post_up was primarily used to reload kernel module when it used to hang, while gui functionality was a bonus, so it is perhaps strange it is left there. Overall I dislike letting DE manage my hardware (networks, hibernation, power levels), but here we talk gui, so that may make sense.
But, at least I have it working for all the users (and my wife uses this laptop sometimes) without having to tweak it :)
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Tue May 24, 2011 4:19 pm    Post subject: Reply with quote

Etal wrote:
Why would you put wpa_gui in the init script? That's completely not the place for it.

You know you can just add it to your DE/WM's autostart?

(You can control it as a user if you add "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel" into /etc/wpa_supplicant/wpa_supplicant.conf)


Having looked, actually I indeed can put wpa_gui anywhere, from wpa_cli.sh to acpi script itself. I'll think what would be that I like more :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum