Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2384 rebase [simultaneous WiFi-as-hotspot AND WiFi-as-client] #2393

Merged
merged 41 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8669a97
ap0 - split cloning
jvonau Apr 22, 2020
e125537
ap0 - introduce wifi-test.service
jvonau Apr 22, 2020
c6a2140
edit hostapd on the fly
jvonau Apr 22, 2020
575b66f
use the new routine
jvonau Apr 22, 2020
000d4ec
ap0 notes
jvonau Apr 22, 2020
37ed8a6
keep the pids known
jvonau Apr 22, 2020
964a592
service touch-ups
jvonau Apr 22, 2020
4ad83f7
test-wifi touchups
jvonau Apr 22, 2020
842a142
better handling of 2.4/5 on the same ssid
jvonau Apr 22, 2020
359f2b4
br0 online tuning
jvonau Apr 22, 2020
83793e7
running model
jvonau Apr 27, 2020
6fb76de
deal with netplan
jvonau Apr 27, 2020
f150d09
wifi-test needs before networkd
jvonau Apr 27, 2020
9a55fdf
let wifi test start hostapd
jvonau Apr 27, 2020
664b540
update iiab-hotspot-on|off
jvonau Apr 27, 2020
ec7ad92
netplan country= workaround
jvonau Apr 29, 2020
1366bf5
show what is being recoreded in iiab_env_file
jvonau May 4, 2020
c51575f
network main cleanup
jvonau May 4, 2020
b60d495
ubuntu no reboot
jvonau May 4, 2020
1bdd038
raspbian no reboot -- needs testing
jvonau May 4, 2020
7ca4664
flying edit only when different
jvonau May 4, 2020
050722f
ubuntu hook for channel change
jvonau May 4, 2020
60a6484
restart.yml netplan fix needs is_ubuntu
jvonau May 4, 2020
263010c
raspbian - only start clone-wifi if wired gateway is used
jvonau May 4, 2020
c602bac
hostapd.yml reload new services
jvonau May 4, 2020
7fd6fc9
test wifi exit if no ssid is found
jvonau May 4, 2020
25bd5a9
dhcpcd hook refinements
jvonau May 4, 2020
323e5c7
don't use test-wifi for hostapd start
jvonau May 4, 2020
6e21b0b
rpi-next-run sync up
jvonau May 4, 2020
23940fc
past sync up netd-disp2
jvonau May 5, 2020
933ca56
wpa workaround doc'd and moved
jvonau May 5, 2020
8190f4b
runtime - move clone-wifi - adjust services
jvonau May 5, 2020
1b58d71
use iw in place of wpa_cli
jvonau May 6, 2020
2c7a720
test-wifi - exit if ssid is not found or channel is unavailable
jvonau May 6, 2020
35efbe8
hostapd keep a strict starting order
jvonau May 6, 2020
0024a0c
hotspots revised
jvonau May 6, 2020
52c0f2a
too aggressive in dhcpcd's 50-hook
jvonau May 7, 2020
a95d476
rpi wifi-runtime changes
jvonau May 6, 2020
845a961
forget about pre-reboot AP usage
jvonau May 7, 2020
04edaea
raspbian - wifi installs not assigning ip address to br0 in time for …
jvonau May 7, 2020
1193b15
once installed and rebooted br0 will be available
jvonau May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions roles/network/tasks/computed_network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,18 @@
iiab_lan_iface: "{{ user_lan_iface }}"
when: not (user_lan_iface == "auto")

- name: Record IIAB_WAN_DEVICE to {{ iiab_env_file }}
- name: Record IIAB_WAN_DEVICE={{ iiab_wan_iface }} to {{ iiab_env_file }}
lineinfile:
path: "{{ iiab_env_file }}"
regexp: '^IIAB_WAN_DEVICE=*'
line: 'IIAB_WAN_DEVICE={{ iiab_wan_iface }}'
when: not installing #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml

- name: Record IIAB_LAN_DEVICE to {{ iiab_env_file }}
- name: Record IIAB_LAN_DEVICE={{ iiab_lan_iface }} to {{ iiab_env_file }}
lineinfile:
path: "{{ iiab_env_file }}"
regexp: '^IIAB_LAN_DEVICE=*'
line: 'IIAB_LAN_DEVICE={{ iiab_lan_iface }}'
state: present
when: not installing #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml

- name: Add 'computed_network' variable values to {{ iiab_ini_file }}
ini_file:
Expand Down
59 changes: 40 additions & 19 deletions roles/network/tasks/hostapd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@
host_channel: "{{ current_host_channel.stdout }}"
when: current_host_channel.stdout is defined and current_host_channel.stdout != "" and current_host_channel.stdout|int <= 13

- name: Create /etc/hostapd/hostapd.conf from template
- name: Create /etc/hostapd/hostapd.conf and backup .iiab from template
template:
src: hostapd/hostapd.conf.j2
dest: /etc/hostapd/hostapd.conf
owner: root
group: root
mode: 0644
when: discovered_wireless_iface != "none"

- name: Create backup /etc/hostapd/hostapd.conf.iiab from template
template:
src: hostapd/hostapd.conf.j2
dest: /etc/hostapd/hostapd.conf.iiab
owner: root
group: root
mode: 0644
src: "{{ item.src }}"
dest: "{{ item.dest }}"
with_items:
- { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf' }
- { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf.iiab' }
when: discovered_wireless_iface != "none"

- name: Generate new random mac address for ap0
Expand All @@ -45,14 +39,19 @@
set_fact:
ap0_mac_addr: "{{ ap0_mac.stdout }}"

- name: Use custom 'hostapd' systemd service unit file using ap0 when wifi_up_down
- name: Use custom 'hostapd' systemd service unit file using ap0
template:
src: hostapd/hostapd.service.j2
dest: /etc/systemd/system/hostapd.service
owner: root
group: root
mode: 0644
when: discovered_wireless_iface != "none" and wifi_up_down
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
with_items:
- { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service', mode: '0644' }
- { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service', mode: '0644' }
- { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service', mode: '0644'}
- { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi', mode: '0755' }
when: discovered_wireless_iface != "none"

- name: Use custom 'hostapd' systemd service unit file for {{ discovered_wireless_iface }} when not wifi_up_down
template:
Expand Down Expand Up @@ -120,7 +119,7 @@
with_items:
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' }
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' }
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' }
- { src: 'hostapd/netd-disp2', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' }
when: systemd_networkd_active and discovered_wireless_iface != "none" and wifi_up_down

- name: Remove networkd-dispatcher hook wifi_up_down False
Expand All @@ -131,13 +130,35 @@
- { dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' }
- { dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' }
- { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' }
- { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' }
when: systemd_networkd_active and discovered_wireless_iface != "none" and not wifi_up_down

- name: Enable the Access Point 'hostapd' service
systemd:
name: hostapd
enabled: yes
when: hostapd_enabled
when: hostapd_enabled and not wifi_up_down

- name: Disable ap0 related services
systemd:
name: "{{ item }}"
enabled: no
daemon_reload: yes
with_items:
- clone-wifi.service
- wifi-test.service
when: not wifi_up_down

- name: Enable the Access Point 'hostapd' and ap0 related services
systemd:
name: "{{ item }}"
enabled: yes
daemon_reload: yes
with_items:
- hostapd.service
- clone-wifi.service
- wifi-test.service
when: hostapd_enabled and wifi_up_down

- name: Record HOSTAPD_ENABLED to {{ iiab_env_file }}
lineinfile:
Expand Down
55 changes: 17 additions & 38 deletions roles/network/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- include_tasks: detected_network.yml
- name: detected_network
include_tasks: detected_network.yml

- name: IF WIFI IS PRIMARY GATEWAY, PLEASE RUN 'iiab-hotspot-on' MANUALLY
set_fact:
Expand All @@ -11,25 +12,8 @@
# in hostapd.yml for later use by...
# /usr/libexec/iiab-startup.sh, iiab-hotspot-off & iiab-hotspot-on
#
# Separate Idea, Not Without Risks: should WiFi-as-gateway detection logic
# be encapsulated into roles/network/tasks/hostapd.yml in future? Whereas
# today "./runtags hostapd" doesn't exist & "./runtags AP" is UNSUPPORTED!

#- name: RPi - reboot to AP post install - installed via wifi so the services are ready
# set_fact:
# iiab_lan_iface: br0
# iiab_wan_iface: "{{ discovered_wired_iface }}"
# iiab_wireless_lan_iface: "{{ discovered_wireless_iface }}"
# iiab_wired_lan_iface: ""
# when: is_raspbian and discovered_wireless_iface is defined and discovered_wireless_iface == iiab_wan_iface and reboot_to_AP

- include_tasks: computed_network.yml

#- name: RPi - don't reboot to AP post install - installed via wifi - don't blow away current network
# set_fact:
# no_net_restart: True
# hostapd_enabled: False
# when: is_raspbian and discovered_wireless_iface is defined and discovered_wired_iface != iiab_wan_iface
- name: computed_network
include_tasks: computed_network.yml

- name: Configure wondershaper
include_tasks: wondershaper.yml
Expand All @@ -53,42 +37,37 @@
when: is_ubuntu and not is_ubuntu_16

#### Start services

- include_tasks: avahi.yml
- include_tasks: hostapd.yml
- include_tasks: computed_services.yml
- include_tasks: enable_services.yml

- name: avahi
include_tasks: avahi.yml
- name: hostapd
include_tasks: hostapd.yml
- name: computed_services
include_tasks: computed_services.yml
- name: enable_services
include_tasks: enable_services.yml
#### End services

#### Start network layout

- name: Redhat networking
include_tasks: ifcfg_mods.yml
when: is_redhat | bool
#and not installing
#- name: Redhat networking
# include_tasks: ifcfg_mods.yml
# when: is_redhat | bool

- name: NetworkManager in use
include_tasks: NM-debian.yml
when: is_debuntu and network_manager_active
#and not installing

- name: systemd-networkd in use
include_tasks: sysd-netd-debian.yml
when: is_debuntu and systemd_networkd_active
#and not installing

- name: Raspbian uses dhcpcd only with no N-M or SYS-NETD active
include_tasks: rpi_debian.yml
when: is_raspbian
#and not installing

- name: Not RPi, Not NetworkManager, Not systemd-networkd in use
include_tasks: debian.yml
when: (not is_raspbian and not network_manager_active and not systemd_networkd_active and is_debuntu) or is_ubuntu_16
#and not installing

#### end network layout

- include_tasks: restart.yml
when: not installing # REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml
- name: Restart services
include_tasks: restart.yml
28 changes: 15 additions & 13 deletions roles/network/tasks/restart.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#iiab_wireless_lan_iface(wlan0) - wifi_up_down False needs hw
#iiab_wireless_lan_iface(ap0) - wifi_up_down True needs hw
#hostapd_enabled False - set in hostapd.yml to avoid the enable with wifi_up_down False
#no_net_restart: True - main.yml discovered_wireless_iface == iiab_wan_iface
- name: Restart hostapd when WiFi is present but not when using WiFi as gateway
- name: Restart wpa_supplicant service
systemd:
name: hostapd
name: "{{ item }}"
state: restarted
# when: iiab_wireless_lan_iface is defined and hostapd_enabled and discovered_wireless_iface != iiab_wan_iface
# when: hostapd_enabled and iiab_wireless_lan_iface is defined and discovered_wireless_iface == iiab_wireless_lan_iface
when: hostapd_enabled and not no_net_restart
with_items:
- wpa_supplicant
when: wifi_up_down and hostapd_enabled

- name: Reload netplan for Wifi gateway on Ubuntu 18+
shell: netplan apply
when: wifi_up_down and is_ubuntu and netplan.stdout.find("yaml") != -1

- name: Start named service
systemd:
Expand Down Expand Up @@ -72,7 +72,8 @@

- name: Checking if WiFi slave is active
shell: brctl show br0 | grep {{ iiab_wireless_lan_iface }} | wc -l
when: hostapd_enabled and discovered_wireless_iface != iiab_wan_iface and iiab_lan_iface == "br0"
# when: hostapd_enabled and discovered_wireless_iface != iiab_wan_iface and iiab_lan_iface == "br0"
when: hostapd_enabled and iiab_lan_iface == "br0"
register: wifi_slave

- name: Restart hostapd if WiFi slave is inactive
Expand All @@ -82,12 +83,13 @@
when: hostapd_enabled and wifi_slave.stdout is defined and wifi_slave.stdout == 0

#both interfaces.d and systemd-networkd should have br0 available and Appliance lacks br0
#keep an eye on legacy wifi installs where br0 is present but not 'online' with an ip address
#due to hostapd didn't go to a carrier state. All others should get dnsmasq restarted
- name: User choice of dnsmasq or dhcpd - restarting {{ dhcp_service2 }}
systemd:
name: "{{ dhcp_service2 }}"
state: restarted
when: (not no_net_restart) or wifi_up_down
when: (not no_net_restart or (is_ubuntu_20 and wifi_up_down)) or (iiab_stage|int == 9)
#when: (not no_net_restart or (is_ubuntu_20 and wifi_up_down))
#when: (iiab_network_mode != "Appliance") # Sufficient b/c br0 exists thanks to /etc/network/interfaces.d/iiab
#when: iiab_network_mode != "Appliance" and iiab_wan_iface != discovered_wireless_iface
#keep an eye on legacy wifi installs where br0 is present but not 'online' with an ip address
#due to hostapd didn't go to a carrier state. All others should get dnsmasq restarted
28 changes: 20 additions & 8 deletions roles/network/tasks/rpi_debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,28 @@
systemd:
daemon_reload: yes

# now pick up denyinterfaces
- name: Restart dhcpcd
service:
name: dhcpcd
state: restarted
- name: Clone wifi if needed
systemd:
name: clone-wifi
state: started

- name: Restart the networking service if appropriate
service:
systemd:
name: networking
enabled: yes
state: restarted
when: not nobridge is defined # less is better
#when: not nobridge is defined and not no_net_restart

- name: Restart hostapd when WiFi is present but not when using WiFi as gateway
systemd:
name: hostapd
state: restarted
when: hostapd_enabled and (wifi_up_down or not no_net_restart)

#- name: Stop wpa_supplicant on Raspbian
# shell: killall wpa_supplicant

# now pick up denyinterfaces and respawn wpa_supplicant
- name: Restart dhcpcd on Raspbian
systemd:
name: dhcpcd
state: restarted
11 changes: 11 additions & 0 deletions roles/network/tasks/sysd-netd-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@
systemd:
daemon_reload: yes

- name: Clone wifi if needed
systemd:
name: clone-wifi
state: started

- name: Restart the systemd-networkd service
systemd:
name: systemd-networkd
state: restarted

- name: Restart hostapd when WiFi is present but not when using WiFi as gateway$
systemd:
name: hostapd
state: restarted
when: hostapd_enabled and (wifi_up_down or not no_net_restart)
22 changes: 18 additions & 4 deletions roles/network/templates/hostapd/50-hostapd
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ if [ "$interface" = "wlan0" ]; then
# wpa_supplicant wants MHz for frequency= while hostapd wants channel..... whatever
# FREQ=`iw wlan0 info|grep channel|cut -d' ' -f9`
FREQ=`iw wlan0 info|grep channel|cut -d' ' -f2`
syslog info "40-iiab set channel $FREQ"
sed -i -e "s/^channel.*/channel=$FREQ /" /etc/hostapd/hostapd.conf
# will need a reboot for hostapd if the channel changed
FREQ2=""
for result in $FREQ; do
echo "frequency is $result for carrier"
if [ $result -lt 13 ]; then
FREQ2=$result
fi
done
echo "Using $FREQ2 for carrier"
syslog info "50-iiab set channel $FREQ2"
HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'`
echo "Hostapd set for $HOSTAPD"
if [ $FREQ2 -ne $HOSTAPD ] && [ ! -z $FREQ2 ]; then
echo "Editing Hostapd for channel $FREQ2"
cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf
sed -i -e "s/^channel.*/channel=$FREQ /" /etc/hostapd/hostapd.conf
# systemctl restart hostapd
fi
fi
# spams the logging
#syslog info "50-iiab set ap0 spam $REASON"
if [ -e /sys/class/net/ap0 ] && ! [ "$reason" = "ROUTERADVERT" ]; then
if [ -e /sys/class/net/ap0 ] && [ "$reason" = "BOUND" ]; then
syslog info "50-iiab set ap0 up $REASON"
# keeps ap0 up so hostapd works
ip link set ap0 up
Expand Down
10 changes: 10 additions & 0 deletions roles/network/templates/hostapd/README.ap0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
start up order
# network-pre bridge is created
clone-wifi
wpa_supplicant #--dbus version does not start the interface directly
test-wifi # uses dbus to scan the network grabbing the channel alters hostapd.conf if needed
hostapd

# network
wpa_supplicant started by dhcpcd, wpa_supplicant@$IFACE netplan-wpa-$IFACE, or NetworkManager

21 changes: 21 additions & 0 deletions roles/network/templates/hostapd/clone-wifi.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=IIAB ap0 clone wifi device
Wants=network-pre.target
After=network-pre.target
Before=dhcpcd.service
Before=wpa_supplicant.service
Before=wpa_supplicant@{{ discovered_wireless_iface }}.service
Before=network-manager.service
Before=netplan-wpa@{{ discovered_wireless_iface }}.service
Before=hostapd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/sbin/iw phy phy0 interface add ap0 type __ap
ExecStartPre=-/sbin/ip link set ap0 address {{ ap0_mac_addr }}
ExecStart=-/sbin/ip link set ap0 up
ExecStop=-/sbin/iw dev ap0 del

[Install]
WantedBy=multi-user.target