Local DHCP daemon fails to start properly during reboot with WiFi interface in hostap mode.

Observable behaviour​

Client WiFi devices cannot obtain their IP addresses when connecting to a FreeBSD-13.0 server acting as an access point (hostap).
Client devices run Win8.1 and various Androids, but the exact client software seems irrelevant to the problem.

Suspected technical reason​

Local DHCP daemon, dhcpd, fails to start properly during reboot with WiFi interface in hostap mode.

Details​

I have a FreeBSD-13.0 server with two Ethernet interfaces (em0, igb0) and one WiFi interface (QCNFA222 card as ath0 -> wlan0). I have configured it as a wireless access point. It runs, among other things, a DHCP server for its wired and wireless clients. DHCP server seems to work just fine when started manually like shown below, with a few seconds interval between commands:

# service hostapd start
# service dhcpd start

However, dhcpd fails to listen on wlan0 interface if I run these very same commands quickly. It also fails to listen on wlan0 during system automatic boot or reboot.

Reading /var/log/all.log suggested that it could be due to wlan0 interface being temporarily down at the time when dhcpd is started. I've experimented a bit and found out that hostapd, when started, does indeed put wlan0 interface down and brings it back up much much later, sometimes after as long as 5 seconds. No wonder dhcpd can't bind to it...

My Questions​

  1. Is my guess correct? Is hostapd bringing the interface down really the root cause of the problem?
  2. What am I doing wrong? What should I do to make sure that wlan0 interface is up when startup scripts are starting DHCP daemon?

Files​

Here are relevant (to my best judgement) excertps from logs and configs. My comments are preceeded with #, skipped lines are replaced with [...], exact IP addresses are redacted. Immediate cause of the problem is marked red.

/etc/rc.conf
Code:
ifconfig_em0="DHCP"
ifconfig_igb0="inet Y.Y.Y.Y netmask 255.255.255.0"
wlans_ath0="wlan0"
create_args_wlan0="wlanmode hostap   country RU regdomain NONE mode 11g channel any mediaopt hostap -pureg -apbridge"
ifconfig_wlan0="HOSTAP inet X.X.X.X netmask 255.255.255.0"

/etc/hostapd.conf
Code:
interface=wlan0
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
ssid=ZZZZ
country_code=RU
wpa=2
wpa_psk_file=/etc/hostapd.wpa_psk
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP

/var/log/all.log
Rich (BB code):
# em0 is the upstream link configured by DHCP client.
kernel: Starting dhclient.
kernel: em0: no link ...
[...]
kernel: em0: link state changed to UP
kernel:  got link
kernel: DHCPREQUEST on em0 to 255.255.255.255 port 67
kernel: igb0: link state changed to UP
kernel: DHCPREQUEST on em0 to 255.255.255.255 port 67
kernel: DHCPACK from S.S.S.S
kernel: bound to Z.Z.Z.Z -- renewal in 1800 seconds.

# Proceed to initialize other interfaces
kernel: Starting Network: lo0 igb0 em0 wlan0.
[...]
kernel: wlan0: flags=8c43<UP,BROADCAST,RUNNING,OACTIVE,SIMPLEX,MULTICAST> metric 0 mtu 1500
kernel:       ether MM:MM:MM:MM:MM:MM
kernel:       inet X.X.X.X netmask 0xffffff00 broadcast X.X.X.255
kernel:       groups: wlan
kernel:       ssid "" channel 5 (2432 MHz 11g)
kernel:       regdomain NONE country RU indoor ecm authmode OPEN privacy OFF
kernel:       txpower 30 scanvalid 60 protmode CTS wme burst -apbridge dtimperiod 1
kernel:       -dfs bintval 0
kernel:       parent interface: ath0
kernel:       media: IEEE 802.11 Wireless Ethernet autoselect mode 11g <hostap>
kernel:       status: no carrier
kernel:       nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

# Then hostapd is started.
kernel: Starting hostapd.
kernel: Configuration file: /etc/hostapd.conf
kernel: wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
[...]

# And finally DHCPD starts and fails.
# I suppose the error message is a bit misleading since wlan0 does have an IP address statically assigned right from its creation.
kernel: Starting dhcpd.
kernel: Can't listen on wlan0 - it has no IP address.
kernel: Listening on igb0 (Y.Y.Y.Y).
 
Did you ever figure this out? I am getting the same problem. One more piece of information - I have no carrier on the interface but it does have an IP address contrary to what dhcpd reports.

I am starting to suspect a bad wifi card.
 
Back
Top