You are not logged in.

#1 2021-05-02 18:02:04

allafesta
Member
Registered: 2021-05-02
Posts: 6

Start wpa_supplicant and dhcpcd only on available interfaces at boot

Hi all
I installed Arch on my laptop and it is working great. I generally connect to the internet using wpa_supplicant and dhcpcd via wifi. However during the week I stay at my uni dorm and need to connect to the internet using a wired connection with IEEE802.1X authentication. Configuring this connection to start at boot has been a problem.

My laptop does not have an ethernet port. I use a usb-c thunderbolt dongle which I generally leave at my dorm. The interface for this wired connection is listed as enp56s0u1u4. For convenience I enabled:

wpa_supplicant-wired@enp56s0u1u4.service 
dhcpcd@enp56s0u1u4.service 

When the dongle is not plugged in the interface enp56s0u1u4 does not show up. This causes my laptop to take two minutes to boot, I assume because it is looking for this interface and not finding it. When I disable above services the long waiting time is gone and everything works fine.

Is there a way to start wpa_supplicant and dhcpcd only if the interface and a configuration file is detected? Can I just write my own script and enable that at boot or is that generally ill adviced? Or is there a better way to set up my network connections in this case? I would not like to have to enable and disable these services every time I arrive at my dorm/home.

Thanks

Last edited by allafesta (2021-05-02 18:05:13)

Offline

#2 2021-05-02 19:11:52

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,302

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

For the dhcpcd service see: https://wiki.archlinux.org/title/Dhcpcd … ow_startup and make an override to remove the -w option. For wpa_supplicant maybe changing the Requires= of the unit file to a Requisite=  would stop the inherent delay from happening.

Last edited by V1del (2021-05-02 19:20:53)

Online

#3 2021-05-02 22:21:45

allafesta
Member
Registered: 2021-05-02
Posts: 6

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

Changing Requires to Requisite in the wpa_supplicant-wired@ unit file definitely speeds up the boot time. I cannot confirm that I will still automatically connect to my dorm internet at present, since I'm at home for a couple of weeks.

I already did the wiki trick but I seem to have misunderstood it: is it correct that I only need to make a dhcpcd@.service.d and not a dhcpcd@interface.service.d for every interface? Either way, this does not seem to solve the problem: enabling dhcpcd@enp56s0u1u4 still yields a 2 minute boot time. Disabling it again and deleting the no-wait configs in the dhcpcd directory gives a boot time of only a couple of seconds (but slower than when the no-wait conf is enabled).

I think the issue with dhcpcd is similar to the problem with wpa_supplicant. However the dhcpcd unit file uses BindsTo, and I do not know whether Requisite would give good behavior since it does not include the stop functionality (as far as my limited understanding goes).

Offline

#4 2021-05-03 05:54:32

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,285

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

Why don't you use a general dhcpcd along a https://wiki.archlinux.org/title/Dhcpcd … supplicant hook?
This way it'll only try to use the enp56s0u1u4 NIC when it's there and invoke wpa_supplicant configs as they're needed.

Offline

#5 2021-05-03 07:00:26

allafesta
Member
Registered: 2021-05-02
Posts: 6

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

I tried that when connecting to my dorm network for the first time and found that that did not work. The wiki says 'launches wpa_supplicant on wireless interfaces', and the connection did not work if I did not explicitly specify the wired flag to wpa_supplicant. I have both a wpa_supplicant-wired-enp56s0u1u4 and a wpa_supplicant-enp56s0u1u4 conf file (identical) so for both wpa_supplicant-wired@enp56s0u1u4 and wpa_supplicant@enp56s0u1u4 the correct conf file should have been loaded.

Offline

#6 2021-05-03 07:50:54

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,285

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

env config value, https://man.archlinux.org/man/core/dhcp … .conf.5.en
But that won't fit w/ the actual wifi device - you'd hve to adjust the hook (it's a bash script) to use -wired configs and auto-select the driver to "wired" in wpa_supplicant_start

Offline

#7 2021-05-03 08:13:38

allafesta
Member
Registered: 2021-05-02
Posts: 6

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

hmm, I will look into it though I can't say I'm very familiar with bash (yet). I will post an update when I've made progress, or said progress is disturbingly lacking.

Offline

#8 2021-09-13 10:39:05

allafesta
Member
Registered: 2021-05-02
Posts: 6

Re: Start wpa_supplicant and dhcpcd only on available interfaces at boot

Sorry if this is considered necrobumping, but I think I solved my problem. Add the following lines to /etc/dhcpcd.conf:

 
interface interface_name 
env ifwireless=0
env wpa_supplicant_driver=wired

In /usr/share/dhcpcd/hooks/xx-wpa_supplicant change the if statement at the bottom of the file from

if [ "$ifwireless" = "1" ] && \
    type wpa_supplicant >/dev/null 2>&1 && \
    type wpa_cli >/dev/null 2>&1

to

([ "$ifwireless" = "1" ] || [ "$interface" == "interface_name" ]) && \
    type wpa_supplicant >/dev/null 2>&1 && \
    type wpa_cli >/dev/null 2>&1

Disable all wpa_supplicant services and dhcpcd services except for the generic dhcpcd service (which runs on all interfaces).

Offline

Board footer

Powered by FluxBB