# wpa_supplicant/dhcpcd won't get an IP when run during boot

## amoe

It's quite difficult to explain what's going on here.  However, I'll have a go.

I use wpa_supplicant with an orinoco_pci card to connect to a network using 64-bit WEP.

I use dhcpcd to get an IP as per the Gentoo wireless guide.

When I boot my machine, wpa_supplicant starts from /etc/init.d/net.eth0.  I can see because it spews a lot of errors to the screen:

```
ioctl[SIOCSIWAUTH]: Operation not supported

WEXT auth param 7 value 0x1 - ioctl[SIOCSIWENCODEEXT]: Operation not supported

ioctl[SIOCSIWENCODEEXT]: Operation not supported

ioctl[SIOCSIWENCODE]: Invalid argument

ioctl[SIOCSIWENCODEEXT]: Operation not supported

ioctl[SIOCSIWENCODE]: Invalid argument

ioctl[SIOCSIWENCODEEXT]: Operation not supported

ioctl[SIOCSIWENCODE]: Invalid argument

ioctl[SIOCSIWAUTH]: Operation not supported

WEXT auth param 4 value 0x0 - ioctl[SIOCSIWAUTH]: Operation not supported
```

However, it starts fine, and goes to the background.  Running wpa_cli after boot produces the following:

```
Selected interface 'eth0'

Interactive mode

> status

bssid=00:14:6c:d4:aa:12

ssid=konata-chan

id=0

pairwise_cipher=WEP-40

group_cipher=WEP-40

key_mgmt=NONE

wpa_state=COMPLETED
```

So as you can see it's associated, however, there's no IP address yet:

```
root@moaner # ping 192.168.1.1

connect: Network is unreachable
```

So I try to restart the interface:

```
root@moaner # /etc/init.d/net.eth0 restart
```

Exactly the same output as before, with the bizarre errors.  But now, I open wpa_cli:

```
> status

bssid=00:14:6c:d4:aa:12

ssid=konata-chan

id=0

pairwise_cipher=WEP-40

group_cipher=WEP-40

key_mgmt=NONE

wpa_state=COMPLETED

ip_address=192.168.1.5

root@moaner # ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=5.68ms
```

As you can see, it got an IP address fine.  This is reproducible boot after boot.  My question is: why am I having to do this?  Why does the machine not just get an IP address when /etc/init.d/net.eth0 is first run, at boot time?

Thanks for any help.

----------

## d2_racing

I have this problem too, I start manually my wireless too with /etc/init.d/net.wlan0 start.

Maybe with baselayout 2, this problem will be solve.

----------

## hampel

Since my network comes up just fine, heres my /etc/conf.d/net:

```
michael@pluto ~ $ cat /etc/conf.d/net

# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

modules=( "wpa_supplicant" )

wpa_supplicant_wlan0="-Dwext"

wpa_timeout_wlan0=5

iface_wlan0="dhcp"

```

I'm using an Intel 3945 though... you might have to change the driver line to your needs...

FYI: Using an "almost stable" system (all stable except some apps)

----------

## d2_racing

A timeout, didn't know that we can tweak that  :Razz: 

----------

## hampel

its the most important part  :Wink: 

you know about "ifplugd"? Nice tool that checks first if a ethernet cable is pluged into your ethernetcard _before_ it tries to get a ip adress...

----------

## Goverp

Interesting - sometime in the past month or two, ntp-client's not been getting the time on  my system.  It looks like the same issue - net.eth0 returned before the network was ready.  I thought it was a DNS issue, put it down to me "optimising" my boot time by installing OpenRC and baselayout2, and enabling parallel init scripts.   If you're hitting this with WPA supplicant, I wonder if something else has changed.  I've no timeout in my conf.d/net script, and never needed one before.

----------

## d2_racing

I think that networkmanager can handle these kind of thing.

----------

## hampel

if your are looking for a GUI, there's also 

 *Quote:*   

> enceladus michael # eix wicd
> 
> * net-misc/wicd
> 
>      Available versions:  1.5.2 1.5.4 ~1.5.6 ~1.5.7-r1 ~1.5.8 ~1.5.9
> ...

 

which comes with an init-script

----------

## UberLord

 *amoe wrote:*   

> As you can see, it got an IP address fine.  This is reproducible boot after boot.  My question is: why am I having to do this?  Why does the machine not just get an IP address when /etc/init.d/net.eth0 is first run, at boot time?

 

The main issue is this - the existing scripts are a kludge that sometimes don't work (disclaimer - they always worked for me).

The solution is this - launch wpa_supplicant and dhcpcd-4.99 as separate daemons. When wpa_supplicant assoicates, it will notify the kernel that the link is up and dhcpcd will then attempt to get an address. However, there are no init scripts for this yes, although I will be making them available soon.

This does NOT solve the problem of the network devices having a working IP address at boot. A possible solution would be to create /etc/dhcpcd.exit-hook to ensure that ntp-date is first run at boot. Something like this

```

start_ntp_date()

{

   [ -e /var/run/ntp-date.lock ] && return

   printf "">/var/run/ntpd-date.lock

   /etc/init.d/ntp-date --quiet start

}

case "${reason}" in

BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)       start_ntp_date;;

esac

```

That hook also works for dhcpcd-4.x in portage.

----------

## amoe

I have now tried setting the timeout value, and it didn't make any difference.  I enclose /etc/conf.d/net below:

```
config_eth0=( "dhcp" )

modules=( "wpa_supplicant" )

wpa_supplicant_eth0="-Dwext"
```

d2_racing: do you mean that NetworkManager is a possible solution to my original problem, or one of the follow-ups?

Thanks for your help, everyone.

----------

## d2_racing

I think that networkmanager can solve your problem.

----------

## SlashBeast

Or wicd.

----------

## d2_racing

In fact  :Razz: 

The wifi connection is started when your WM is running, so you cannot have some weird wpa or driver timeout problem.

----------

## UberLord

How does that ensure that ntp-date is run after wicd or NetworkManager brings up a connection AND ensure it only does it once?

----------

## d2_racing

Start manually the ntp service once you have a running Wifi.

I have no idea actually....

----------

## SlashBeast

 *d2_racing wrote:*   

> In fact 
> 
> The wifi connection is started when your WM is running, so you cannot have some weird wpa or driver timeout problem.

 

If you use wicd, wifi is started at boot (when service wicd is started), I dont use dhcp for my home wifi and i have internet connection after 1-2s after starting wicd.

----------

## d2_racing

I think that networkmanager only start the Wifi when you are log in....

----------

