Skip to content

Commit fbe5b8e

Browse files
pandafynemesifiercodesankalp
authored
[feature] OpenWrt: Added support for new bridge syntax #196
Closes #196 Co-authored-by: Federico Capoano <f.capoano@openwisp.io> Co-authored-by: sankalp <sankalp123427@gmail.com>
1 parent abc136b commit fbe5b8e

12 files changed

Lines changed: 2621 additions & 107 deletions

File tree

docs/source/backends/openwrt.rst

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,39 @@ The ``OpenWrt`` backend allows to generate OpenWRT compatible configurations.
1313
and it is the default configuration system installed on `OpenWRT <http://openwrt.org>`_
1414
and its fork `LEDE <https://www.lede-project.org/>`_.
1515

16+
.. important::
17+
18+
OpenWrt introduced a new syntax for defining interfaces in `OpenWrt 21 <https://openwrt.org/releases/21.02/notes-21.02.0#new_network_configuration_syntax_and_boardjson_change>`_.
19+
By default, the netjsonconfig library generates configuration in the new syntax.
20+
If you want to generate configuration in the legacy syntax (OpenWrt <=19), then
21+
set ``dsa=False`` while instantiating object of ``netjsonconfig.OpenWrt`` class.
22+
23+
.. code-block:: python
24+
25+
>>> from netjsonconfig import OpenWrt
26+
>>>
27+
>>> o = OpenWrt(
28+
... config = {
29+
... "interfaces": [
30+
... {
31+
... "name": "eth0",
32+
... "type": "ethernet",
33+
... "addresses": [
34+
... {
35+
... "proto": "dhcp",
36+
... "family": "ipv4"
37+
... }
38+
... ]
39+
... }
40+
... ]
41+
... },
42+
... dsa=False, # This will generate configuration in legacy syntax
43+
... )
44+
45+
The examples present in this documentation only demonstrates configuration
46+
in new syntax. Refer `older documentation versions <https://netjsonconfig.openwisp.org/en/1.0.0a-pre-dsa/backends/openwrt.html>`_
47+
to check examples of old syntax.
48+
1649
Initialization
1750
--------------
1851

@@ -308,6 +341,39 @@ also supports the following custom options for every type of interface:
308341
| ``network`` | string | logical interface name (UCI specific) |
309342
+--------------+---------+-----------------------------------------------+
310343

344+
.. important::
345+
346+
OpenWrt introduced a new syntax for defining interfaces in `OpenWrt 21 <https://openwrt.org/releases/21.02/notes-21.02.0#new_network_configuration_syntax_and_boardjson_change>`_.
347+
By default, the netjsonconfig library generates configuration in the new syntax.
348+
If you want to generate configuration in the legacy syntax (OpenWrt <=19), then
349+
set ``dsa=False`` while instantiating object of ``netjsonconfig.OpenWrt`` class.
350+
351+
.. code-block:: python
352+
353+
>>> from netjsonconfig import OpenWrt
354+
>>>
355+
>>> o = OpenWrt(
356+
... config = {
357+
... "interfaces": [
358+
... {
359+
... "name": "eth0",
360+
... "type": "ethernet",
361+
... "addresses": [
362+
... {
363+
... "proto": "dhcp",
364+
... "family": "ipv4"
365+
... }
366+
... ]
367+
... }
368+
... ]
369+
... },
370+
... dsa=False, # This will generate configuration in legacy syntax
371+
... )
372+
373+
The examples present in this documentation only demonstrates configuration
374+
in new syntax. Refer `older documentation versions <https://netjsonconfig.openwisp.org/en/1.0.0a-pre-dsa/backends/openwrt.html>`_
375+
to check examples of old syntax.
376+
311377
In the following sections some examples of the most common use cases are shown.
312378

313379
Loopback interface example
@@ -530,18 +596,47 @@ Will be rendered as follows::
530596
Bridge settings
531597
---------------
532598

533-
Interfaces of type ``bridge`` can contain a few options that are specific for network bridges:
534-
535-
* ``bridge_members``: interfaces that are members of the bridge
536-
* ``stp``: spanning tree protocol
599+
Interfaces of type ``bridge`` contains options that are specific for network bridges.
537600

538601
The ``OpenWrt`` backend NetJSON extensions for bridge interfaces:
539602

540-
+-------------------+---------+-------------+-------------------------------------------------------------+
541-
| key name | type | default | allowed values |
542-
+===================+=========+=============+=============================================================+
543-
| ``igmp_snooping`` | boolean | ``True`` | sets the ``multicast_snooping`` kernel setting for a bridge |
544-
+-------------------+---------+-------------+-------------------------------------------------------------+
603+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
604+
| key name | type | default | allowed values |
605+
+=============================+=========+===========+=============================================================+
606+
| ``bridge_members`` | list | ``[]`` | list of interface names for creating bridge |
607+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
608+
| ``igmp_snooping`` | boolean | ``False`` | sets the ``multicast_snooping`` kernel setting for a bridge |
609+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
610+
| ``multicast_querier`` | boolean | ``False`` | enables the bridge as a multicast querier |
611+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
612+
| ``query_interval`` | integer | ``12500`` | time interval in centiseconds between multicast general |
613+
| | | | queries |
614+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
615+
| ``query_response_interval`` | integer | ``1000`` | the max response time in centiseconds inserted into |
616+
| | | | the periodic general queries |
617+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
618+
| ``last_member_interval`` | integer | ``100`` | the maximum response time in centiseconds inserted into |
619+
| | | | group-specific queries sent in response to leave |
620+
| | | | group messages. |
621+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
622+
| ``hash_max`` | integer | ``512`` | size of kernel multicast hash table |
623+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
624+
| ``robustness`` | integer | ``2`` | sets Startup Query Count and Last Member Count |
625+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
626+
| ``stp`` | boolean | ``False`` | enables the spanning tree protocol |
627+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
628+
| ``forward_delay`` | integer | ``4`` | time in seconds to spend in listening |
629+
| | | | and learning states (range between 2-30) |
630+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
631+
| ``hello_time`` | integer | ``2`` | time interval in seconds for STP hello packets (range 1-10) |
632+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
633+
| ``priority`` | integer | ``32767`` | sets the STP bridge priority (range 0-65535) |
634+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
635+
| ``ageing_time`` | integer | ``300`` | expiration time in seconds for dynamic MAC |
636+
| | | | entries in the filtering DB" (range 10-1000000) |
637+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
638+
| ``max_age`` | integer | ``20`` | timeout in seconds until topology updates on link loss |
639+
+-----------------------------+---------+-----------+-------------------------------------------------------------+
545640

546641
Bridge interface example
547642
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -563,7 +658,7 @@ The following *configuration dictionary*:
563658
"type": "ethernet"
564659
},
565660
{
566-
"name": "lan_bridge", # will be named "br-lan_bridge" by OpenWRT
661+
"name": "br-lan",
567662
"type": "bridge",
568663
"stp": True, # enable spanning tree protocol
569664
"igmp_snooping": True, # enable imgp snooping
@@ -595,7 +690,16 @@ Will be rendered as follows::
595690
option ifname 'eth0.2'
596691
option proto 'none'
597692

598-
config interface 'lan_bridge'
693+
config device 'device_br_lan'
694+
option igmp_snooping '1'
695+
option name 'br-lan'
696+
list ports 'eth0.1'
697+
list ports 'eth0.2'
698+
option stp '1'
699+
option type 'bridge'
700+
701+
config interface 'br_lan'
702+
option device 'br-lan'
599703
option ifname 'eth0.1 eth0.2'
600704
option igmp_snooping '1'
601705
option ipaddr '172.17.0.2'
@@ -763,7 +867,7 @@ usually the LAN bridge:
763867
"radio": "radio0",
764868
"mode": "access_point",
765869
"ssid": "wifi service",
766-
# "network": ["lan"] this proeprty can be omitted
870+
# "network": ["lan"] this property can be omitted
767871
# but may be overridden if needed
768872
}
769873
},
@@ -796,6 +900,12 @@ Will be rendered as follows::
796900
option ifname 'wlan0'
797901
option proto 'none'
798902

903+
config device 'device_lan'
904+
option name 'lan'
905+
list ports 'eth0'
906+
list ports 'wlan0'
907+
option type 'bridge'
908+
799909
config interface 'lan'
800910
option ifname 'eth0 wlan0'
801911
option proto 'dhcp'
@@ -970,6 +1080,12 @@ UCI output::
9701080
option ifname 'mesh0'
9711081
option proto 'none'
9721082

1083+
config device 'device_lan'
1084+
option name 'lan'
1085+
list ports 'eth0'
1086+
list ports 'mesh0'
1087+
option type 'bridge'
1088+
9731089
config interface 'lan'
9741090
option ifname 'eth0 mesh0'
9751091
option ipaddr '192.168.0.1'
@@ -1092,9 +1208,14 @@ Will result in::
10921208
option ifname 'wlan1'
10931209
option proto 'none'
10941210

1095-
config interface 'br_wds'
1211+
config device 'device_wds_bridge'
1212+
option name 'br-wds'
1213+
list ports 'wlan0'
1214+
list ports 'wlan1'
1215+
option type 'bridge'
1216+
1217+
config interface 'wds_bridge'
10961218
option ifname 'wlan0 wlan1'
1097-
option network 'wds_bridge'
10981219
option proto 'dhcp'
10991220
option type 'bridge'
11001221

netjsonconfig/backends/openwisp/openwisp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class OpenWisp(OpenWrt):
1515
schema = schema
1616
renderer = OpenWrtRenderer
1717

18+
def __init__(
19+
self, config=None, native=None, templates=None, context=None, dsa=False
20+
):
21+
super().__init__(config, native, templates, context, dsa)
22+
1823
def validate(self):
1924
self._sanitize_radios()
2025
super().validate()

netjsonconfig/backends/openwrt/converters/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
class OpenWrtConverter(BaseConverter):
55
_uci_types = []
66

7+
def __init__(self, backend):
8+
super().__init__(backend)
9+
self.dsa = getattr(backend, 'dsa', True)
10+
711
def should_skip_block(self, block):
812
_type = block.get('.type')
913
return not block or (self._uci_types and _type not in self._uci_types)

0 commit comments

Comments
 (0)