wan_network file
Background
- If central management is activated for the device, the device attempts to reach the controller via various routes.
- OpenWrt uses configuration files located in the /etc/config directory to configure the device accordingly.
- The network file is used to define the network configuration of the device.
- Since we can include the MESHdesk package on virtually any device running OpenWrt, we need to customize the means of reaching the controller to make it work on that particular device.
- For example, some devices only have one Ethernet port.
- Others may have multiple Ethernet ports, a certain number of which are grouped together and used as the LAN side and typically a single one is assigned to the WAN port.
- For this we create the file /etc/MESHdesk/configs/wan_network.
- This file must be unique for the specific device on which the MESHdesk package is installed.
- This file is used during startup to replace the /etc/config/network file so that the device can reach the controller.
- This configuration will also be changed after the device has received its final configuration from the controller (or fall back to the last known good configuration if the controller cannot be reached)
- The unique part of the wan_network file concerns the configuration of the Ethernet ports. Devices can be categorized into three types.
- Devices with standard eth0 and/or eth1 ports. (This is typically Atheros-based hardware)
- Devices with a single eth0 port in combination with swconfig to create VLANs to split the physical ports of the device. (This is typically older Mediatek-based hardware)
- New DSA-like configuration with names like wan, lan1, lan2, lan3, etc. for the ports. (This is typical for newer Mediatek devices)
Next we will unpack examples of each of these types
- When looking at these sample files, remember that we want to use the device section called br-lan as a bridge.
- Traditionally, the LAN ports are a part of it.
- However, we are now configuring it so that the WAN port becomes part of the device instead of the LAN ports.
Devices with standard eth0 and or eth1 ports
- This includes most Atheros and IPQ-based devices.
- Let us have a look at the wan_network file of the GL iNet AR300M.
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'eth1' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp'
- We have swapped eth0 and eth1 as ports of br-lan. Plain and simple.
- There is no wan interface defined.
- Devices with a single port do not need to be swapped because only one port is available.
- Here is an excerpt from the original /etc/config/network file for you to compare.
- network
.... config device option name 'br-lan' option type 'bridge' list ports 'eth0' config interface 'lan' option device 'br-lan' option proto 'static' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option ip6assign '60' config interface 'wan' option device 'eth1' option proto 'dhcp' ....
Devices which use swconfig
- These are usually older Mediatek-based devices (MT7620 / 7628 etc.)
- Let us take a look at the files from a Xiaomi 4A 110M
- Look at the default /etc/config/network file.
- network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config globals 'globals' option ula_prefix 'auto' config device option name 'br-lan' option type 'bridge' list ports 'eth0.1' config interface 'lan' option device 'br-lan' option proto 'static' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option ip6assign '60' config device option name 'eth0.2' option macaddr '9c:9d:7e:f6:22:1c' config interface 'wan' option device 'eth0.2' option proto 'dhcp' config interface 'wan6' option device 'eth0.2' option proto 'dhcpv6' config switch option name 'switch0' option reset '1' option enable_vlan '1' config switch_vlan option device 'switch0' option vlan '1' option ports '4 2 6t' config switch_vlan option device 'switch0' option vlan '2' option ports '0 6t'
- Next look at the /etc/MESHdesk/configs/wan_network file that is derived from it.
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'eth0.1' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp' config switch option name 'switch0' option reset '1' option enable_vlan '1' config switch_vlan option device 'switch0' option vlan '1' option ports '0 6t' config switch_vlan option device 'switch0' option vlan '2' option ports '4 2 6t'
- We have taken the sections of the switch configuration from /etc/config/network and simply swapped vlan nr 1 and vlan nr 2.
- This means that eth0.1 is now on the WAN port.
- client_0 and client_1 interface sections can always be kept as is.
- The br-lan section of the device is now actually the WAN port. (Switch configuration allows us to support hardware with a single Ethernet port and make complex bridge configurations if required)
DSA enabled devices
- This includes newer Mediatek-based devices such as those using the MT7621 chipset.
- This time the Xiaomi 4A Gigabit Edition. This board does not have any switch sections and is much simpler.
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'wan' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp'
- Here you can see that there are no switch sections and we have added the wan port to br-lan (while removing the various lan ports). Plain and simple.
- Here is a snippet from the original /etc/config/network file for you to compare.
- network
.... config device option name 'br-lan' option type 'bridge' list ports 'lan1' list ports 'lan2' list ports 'lan3' list ports 'lan4' config interface 'lan' option device 'br-lan' option proto 'static' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option ip6assign '60' config interface 'wan' option device 'wan' option proto 'dhcp' ....
- This brings us to the end of the detailed discussion of the /etc/MESHdesk/configs/wan_network file.
- Make sure that this file is customized to work on your hardware.
Some Hardware Info
Xiaomi 4C
- wan_network
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'eth0.1' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp' config switch option name 'switch0' option reset '1' option enable_vlan '1' config switch_vlan option device 'switch0' option vlan '2' option ports '4 2 6t' config switch_vlan option device 'switch0' option vlan '1' option ports '1 6t'
- hardware section
- meshdesk
config hardware 'xiaomi_4c' option morse_led '/sys/class/leds/blue:power/brightness' option internet_led '/sys/class/leds/yellow:power/brightness' option wifi_led 'led0'
Xiaomi 4A 100M
- wan_network
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'eth0.1' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp' config switch option name 'switch0' option reset '1' option enable_vlan '1' config switch_vlan option device 'switch0' option vlan '1' option ports '0 6t' config switch_vlan option device 'switch0' option vlan '2' option ports '4 2 6t'
- hardware section
- meshdesk
config hardware 'xiaomi_4a_100' option morse_led '/sys/class/leds/blue:power/brightness' option internet_led '/sys/class/leds/yellow:power/brightness' option wifi_led 'led0'
Totolink X500R (WiFi6)
- wan_network
- wan_network
config interface 'loopback' option device 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config device option name 'br-lan' option type 'bridge' list ports 'wan' config interface 'lan' option device 'br-lan' option proto 'dhcp' config interface 'client_0' option proto 'dhcp' config interface 'client_1' option proto 'dhcp'
- hardware section
- meshdesk
config hardware 't_x5000r' option morse_led '/sys/class/leds/blue:sys/brightness' option internet_led '/dev/null' option wifi_led 'dev:null'