# [SOLVED] wpa_supplicant and dhcpcd

## DZoom

Hi,

upon starting my laptop wpa_supplicant and dhcpcd are loaded in runlevel default.

after i log in as a user i don't have access to the internet.

after restarting the dhcpcd service everything works fine.

to me the problem seems to be the the order in which dhcpcd and wpa_supplicant are loaded; as everything works fine after restarting dhcpcd by hand.

my /etc/conf.d/net looks like this:

```
config_eth0="dhcp"

config_wlan0="dhcp"

modules="wpa_supplicant"

```

what am i missing?Last edited by DZoom on Fri Jun 08, 2012 9:42 pm; edited 2 times in total

----------

## radius

I don't think you need dhcpcd in any runlevel.

```
$ rc-status -a

Runlevel: default

 syslog-ng                                                         [  started  ]

 acpid                                                             [  started  ]

 dbus                                                              [  started  ]

 udev-postmount                                                    [  started  ]

 laptop_mode                                                       [  started  ]

 net.wlan0                                                         [  started  ]

 netmount                                                          [  started  ]

 vixie-cron                                                        [  started  ]

 local                                                             [  started  ]

Runlevel: sysinit

 dmesg                                                             [  started  ]

 udev                                                              [  started  ]

 devfs                                                             [  started  ]

Runlevel: boot

 hwclock                                                           [  started  ]

 modules                                                           [  started  ]

 lvm                                                               [  started  ]

 fsck                                                              [  started  ]

 root                                                              [  started  ]

 mtab                                                              [  started  ]

 localmount                                                        [  started  ]

 sysctl                                                            [  started  ]

 bootmisc                                                          [  started  ]

 swap                                                              [  started  ]

 net.lo                                                            [  started  ]

 hostname                                                          [  started  ]

 procfs                                                            [  started  ]

 alsasound                                                         [  started  ]

 urandom                                                           [  started  ]

 termencoding                                                      [  started  ]

 keymaps                                                           [  started  ]

Runlevel: shutdown

 killprocs                                                         [  stopped  ]

 savecache                                                         [  stopped  ]

 mount-ro                                                          [  stopped  ]

Dynamic Runlevel: hotplugged

Dynamic Runlevel: needed

 sysfs                                                             [  started  ]

Dynamic Runlevel: manual

```

As you can see, I also use wpa_supplicant (net.wlan0), but I don't have dhcpcd in any runlevel.

Also I don't think you need config_eth0="dhcp" and config_wlan0="dhcp" in /etc/conf.d/net. I only have the following lines in /etc/conf.d/net file

```
modules="wpa_supplicant"

wpa_supplicant_wlan0="-Dwext"

```

----------

## DZoom

 *radius wrote:*   

> I don't think you need dhcpcd in any runlevel.
> 
> [...]

 

do you use any other service that provides a dhcp of its own? or is it just started as a dependency by wpa_supplicant?

do you use a wired lan from time to time?

the latter i do from time to time; getting my IP via dhcp; so why shouldn't i need eth0 in my /etc/conf.d/net ?

---

still, i'll try some of your suggestion as soon as i get home tonight...

EDIT:

i don't have a net.wlan0 service i could add to the default runlevel

not starting dhcpcd in runlevel default didn't change anything.

my /etc/conf.d/net now looks like this:

```
config_eth0="dhcp"

#config_wlan0="dhcp"

modules="wpa_supplicant"

```

i have to restart the dhcpcd manually and everything works fine.

so how can i solve this dependency-issue?!

----------

## radius

 *DZoom wrote:*   

> do you use any other service that provides a dhcp of its own? or is it just started as a dependency by wpa_supplicant?
> 
> do you use a wired lan from time to time?
> 
> the latter i do from time to time; getting my IP via dhcp; so why shouldn't i need eth0 in my /etc/conf.d/net ?
> ...

 

Actually, wpa_supplicant takes care of everything. It doesn't even start /etc/conf.d/dhcpcd. However, it does use dhcpcd.

```
$ /etc/init.d/dhcpcd status

 * status: stopped
```

Sorry, I failed to realize that you must be using eth0 because you had it in the net file. I don't use eth0 with wlan0. You should first try removing dhcpcd from any runlevel before editing the net file. Services that require dhcpcd will use it automatically.

If simply removing dhcpcd does not work, when you need wired network, you can start dhcpcd manually, or you can do the following.

/etc/conf.d/net

```
wpa_supplicant_wlan0="-Dwext -c/etc/wpa_supplicant/wpa_supplicant.conf"

wpa_supplicant_eth0="-Dwired -c/etc/wpa_supplicant/wpa_supplicant_wired.conf"
```

So, now you can edit wpa_supplicant file for wireless configuration and wpa_supplicant_wired.conf for wired configuration. So, you can start net.wlan0 when you need wireless and net.eth0 when you need wired. I haven't tried it, but it should work.

Edit:

If you don't have net.wlan0, then how do you start wpa_supplicant?

I did the following to get net.wlan0. The instructions are from the install handbook.

```
# cd /etc/init.d/

# ln -s net.lo net.wlan0
```

As you can see, net.wlan0 is simply symlink to net.lo. You can do the same for net.eth0

----------

## DZoom

wpa_supplicant was simply started in the default runlevel.

with the following changes a made a small step in the right direction - but still have some challenges ahead:

* i created the symlink from net.wlan0 to net.lo (though i'm wondering where in the handbook this step is described?)

* i removed net.eth0 from runlevel default

* i removed wpa_supplicant from runlevel default

* i removed dhcpcd from runlevel default

i also edited my /etc/conf.d/net to contain just the following:

```
modules="wpa_supplicant"

config_wlan0="dhcp"

```

and finally i rebooted.

this gives me a working wifi-interface, but no working eth0 (yet). planning on maybe using ifplugd...

anyway, my main concern right now are the following two messages occuring during startup:

```
*   Starting wpa_supplicant on wlan0 ...

rfkill: Cannot open RFKILL control device

 [ ok ]

 *   Starting wpa_cli on wlan0 ...

 [ ok ]

 *   Backgrounding ... ...

 * WARNING: net.wlan0 has started, but is inactive

 * WARNING: netmount is scheduled to start when net.wlan0 has started
```

1. what is rfkill? i installed it, but i don't what it is, should do, is necessary for, and why wpa_supplicant complains about not being able to open a control device for it?

2. are those warning of any relevance? the first doesn't really make sense to me: the device is started and can be used immediatly. and if it's not used, it's inactive. but that should be an info to a user - not a warning? the second i don't get at all. i can't remember enabling/installing/using any netmount-related stuff...

radius, so far i really appreciate your help: thanks.

would be nice if you could go on leading the right way...

EDIT

I re-added net.eth0 to runlevel default added the following line to /etc/conf.d/net and rebooted:

```
config_eth0="dhcp"

```

as soon as i plug in a network cable, it is recognized and i receive an ip via dhcp.

same goes after booting when i have no cable plugged in, but a known wifi is in range: i get connected and receive an ip.

if both conditions are met i get two ips; one for each device.

at the moment no need for additional tools like ifplugd.

the rfkill-message seems to be meaningless for me as a macbook pro (8,1) owner...

the warnings seem to have disappeared; though i must say i manually removed netmount from runlevel default as i didn't know what my system would need it for anyway.Last edited by DZoom on Fri Jun 08, 2012 9:40 pm; edited 1 time in total

----------

## radius

I'm glad you were able to solve it.

 *DZoom wrote:*   

> i created the symlink from net.wlan0 to net.lo (though i'm wondering where in the handbook this step is described?)
> 
> 

 

It is in this page under "Automatically Start Networking at Boot". However, it is net.eth0 in the handbook, not net.wlan0.

----------

## khayyam

DZoom ...

 *DZoom wrote:*   

> 1. what is rfkill? i installed it, but i don't what it is, should do, is necessary for, and why wpa_supplicant complains about not being able to open a control device for it?

 

There are, perhaps confusingly, two components to 'rfkill', the useland tool you emerged, which is used for enabling/disabling wireless deivies (controling "RF switches") and a kernel "RF switch subsystem", which provides the machanism for accessing these switches on wireless, bluetooth, etc, devices. If you have a /dev/rfkill then you have the latter enabled in your kernel (CONFIG_RFKILL=y). I assume from the error that this is not enabled, hence the warning, but the card will work with or without it, so its not critical.

 *DZoom wrote:*   

> 2. are those warning of any relevance? the first doesn't really make sense to me: the device is started and can be used immediatly. and if it's not used, it's inactive. but that should be an info to a user - not a warning? the second i don't get at all. i can't remember enabling/installing/using any netmount-related stuff...

 

Both errors are non critical, the latter is simply telling you that the interface has started but that negociation hasn't yet completed, and rather than wait for the negociation to complete it alerts you to the fact and carry's on with the boot process, leaving the task of bringing the interface up to whatever is configured to do so, in the background.

 *DZoom wrote:*   

> the rfkill-message seems to be meaningless for me as a macbook pro (8,1) owner...

 

Being a "macbook pro owner" or the message being "meaningless" doesn't change the fact that it happens for a reason.

 *DZoom wrote:*   

> the warnings seem to have disappeared; though i must say i manually removed netmount from runlevel default as i didn't know what my system would need it for anyway.

 

netmount doesn't do anything unless configured, its in the run-level by default as filesystems are required to boot, and so if someone configures, say NFS, its recognised at boot, and so mounted. In your case, it doesn't matter either way, but again, there is a rational behind it.

As for your initial problem, let /etc/init.d/net.${IFACE} handle each device, and configure them via /etc/conf.d/net. This will start wpa_supplicant, dhcpcd, etc, as needed/configured, so there is no need to add them to any run-level.

I prefer that wpa_supplicant not handle eth0, but this is only because I want it gone if wlan0 is down (should I need to have the card in moniter, ad-hoc, or master, mode). You can selectively define how each device is to be managed (again in /etc/conf.d/net) eg:

```
rc_need_eth0="iptables"

modules_eth0="!plugged"

config_eth0="192.168.2.222/24"

routes_eth0="default via 192.168.2.254"

dns_servers_eth0="127.0.0.1"

rc_need_wlan0="iptables"

modules_wlan0="!plugged wpa_supplicant"

wpa_supplicant_wlan0="-Dwext"

wpa_timeout_wlan0="15"

dhcp_wlan0="release nontp nonis nosendhost nodns"

dhcpcd_wlan0="-h myhostname -I myhostname"

dns_servers_wlan0="127.0.0.1"
```

We provide the switches with with wpa_supplicant, dhcp, etc, is to be configured, the DNS server to query, etc.

You can also use "preup()", "postup()", "postdown()" to configure other things to happen as and when a network interface is run, eg:

```
postup() {

if [[ ${IFACE} != "lo" ]] ; then

    if [[ -z $(/usr/bin/mailq | awk '$4 ~/empty/') ]] ; then

        TIMEOUT="10"

        while [[ ${TIMEOUT} -gt 0 && -z "$(ip route show 0.0.0.0/0)" ]] ; do

            let TIMEOUT=${TIMEOUT}-1 ; sleep 1

        done 

        if [[ ${TIMEOUT} -eq 0 ]] ; then

            echo "" | mail -s "Mail flush deferred: $(date)" postmaster

            return 1

        else

            /usr/sbin/postfix flush

        fi

    fi        

fi
```

This checks to see if I have any mail que'd (mail that I might have sent when I was offline), and if so check the interface is asigned an address (and therefore online) and "flush" the mail, if there is any problem sending the mail then let 'postmaster' (me) know about it.

I find gentoo's method of handling network configuration both intuative and flexable, the fact there is a wpa_supplicant init might be confusing but its there incase this needs to be run seperately, in your case its best to let /etc/int.d/net handle it, so your mistake was to think that wpa_supplicant was needed in the run-level in order to use wpa_supplicant.

Anyhow ... hopefully some of this helps in understanding what happened and why ...

best ... khay

----------

