Openwrt. Network configuration. Daisy chain.

OpenWrt has reach set of network configuration options so going to write set of articles to learn little bit deeper in the world of networks. Each article will describle some case that you might face during building networks.Here is first article in the set.

Daisy chaining

One of the our customer asked to help with building daisy chain of few devices. Daisy chain is a wiring scheme in which multiple devices are wired together in sequence or in a ring similar to a garland of daisy flowers.

So the task customer wanted to solve was following:

He have set of devices (based on NetSoM) having two physical ethernet interfaces each. They are connected as a garland where one of the interface used to connect to the previous device while second interface used to connect to the next device. Like a garland:

But only one of the device (first one) have physical direct wired connection to the global network (yellow wire on the photo). So the main thing needed to be solve is getting second device connected to the global network too.

How to do that?

Step 1.  Configuration of second device.

Obviously it need to be configured as DHCP client. To do that we configure /etc/config/network in following way:

# cat /etc/config/network

config interface ‘loopback’
option device ‘lo’
option proto ‘static’
option ipaddr ‘127.0.0.1’
option netmask ‘255.0.0.0’

config interface ‘lan’
option ifname ‘eth1’
option proto ‘dhcp’

save changes, exit the file and restart network configuration:

# /etc/init.d/network restart

After that connect it directly to global network (yellow wire):

and make sure it takes IP address:

# ifconfig
eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:55
inet addr:192.168.31.90 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::211:22ff:fe33:4455/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11767 errors:0 dropped:0 overruns:0 frame:0
TX packets:620 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:806589 (787.6 KiB) TX bytes:66067 (64.5 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:892 errors:0 dropped:0 overruns:0 frame:0
TX packets:892 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77633 (75.8 KiB) TX bytes:77633 (75.8 KiB)

than return wiring back to the daisy chain scheme (first photo). Once first device will start to provide access to global network to the second one – it will be able to take IP address by using DHCP protocol.

so let’s switch to the first device.

Step 1.  Configuration of first device.

looks like it need to act as a DHCP client to take IP address for itself and must to provide access for DHCP server for second device. How to do that? OpenWrt has software mechanism to combine multiple network interfaces together  by creating so called device. Some explanation might be found here.

Here how it can be implemented:

# cat /etc/config/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 type ‘bridge’
option name ‘br-lan’
list ports ‘eth0’
list ports ‘eth1’

config interface ‘lan0’
option proto ‘dhcp’
option device ‘br-lan’

Once you restart networking two network interfaces (eth0 and eth1) will act in similar manner as DHCP clients. It will give ability for second device to take IP address too.

Here what you will see for first device:

# ifconfig
br-lan Link encap:Ethernet HWaddr 6A:C6:8E:E9:27:F5
inet addr:192.168.31.228 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::68c6:8eff:fee9:27f5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:338 errors:0 dropped:0 overruns:0 frame:0
TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19998 (19.5 KiB) TX bytes:2478 (2.4 KiB)

eth0 Link encap:Ethernet HWaddr 6A:C6:8E:E9:27:F5
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28317 errors:0 dropped:0 overruns:0 frame:0
TX packets:4527 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2310159 (2.2 MiB) TX bytes:2134364 (2.0 MiB)

eth1 Link encap:Ethernet HWaddr 52:5A:BB:55:25:E3
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:770 errors:0 dropped:0 overruns:0 frame:0
TX packets:14264 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:86499 (84.4 KiB) TX bytes:953059 (930.7 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1095 errors:0 dropped:0 overruns:0 frame:0
TX packets:1095 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:90793 (88.6 KiB) TX bytes:90793 (88.6 KiB)

 

If you not comphortable with console you can perform such configuration using web interface by accessing web page in a browser by IP address of device:

Step 3.  Final changes.

We achieved thing we want – second device able to access global network. The only confusing thing is that devices uses different network configurations. If we will be able to unify it can build as long daisy chain of device we want without worrying about proper sequence of devices with different configurations. Can’t we use configuration of first device for second device too? Yes, we can. Make changes, restart network and make sure that second device took IP address also.

So final version of configuration looks like this:

# cat /etc/config/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 type ‘bridge’
option name ‘br-lan’
list ports ‘eth0’
list ports ‘eth1’

config interface ‘lan0’
option proto ‘dhcp’
option device ‘br-lan’