Skip to content

Commit

Permalink
templates: check 15 character limit for bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
Noki committed Aug 15, 2023
1 parent 0d82ff8 commit ea94a5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions roles/cfg_openwrt/templates/common/config/network.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config interface 'loopback'
{% for network in networks %}
{% set name = network['name'] if 'name' in network else network['role'] %}
{% set port = ('switch0' if dsa_ports is defined else int_port) + '.' + network['vid']|string %}
{% set bridge_name = 'br-' + name %}
{% set bridge_needed = name in wifi_networks or network.get('mesh_ap') == inventory_hostname or (role == 'corerouter' and 'tunnel_wan_ip' in network) %}
{% set port_needed = not (role == 'corerouter' and network.get('mesh_ap') == inventory_hostname) %}

Expand All @@ -31,7 +32,11 @@ config interface 'loopback'
%}
config interface '{{ name }}'
{% if port_needed %}
option device '{{ ('br-' + name) if bridge_needed else port }}'
{% if bridge_needed %}
option device '{{ (bridge_name if bridge_name | length <= 15) | mandatory('The generated inteface name exceeds the 15 characters limit of the linux kernel. Try to shorten the name to resolve this.') }}'
{% else %}
option device '{{ port }}'
{% endif %}
{% endif %}
{% if network.get('enforce_client_isolation') and role == 'corerouter' and
not bridge_needed %}
Expand Down Expand Up @@ -70,7 +75,7 @@ config interface '{{ name }}'

{% if port_needed and bridge_needed %}
config device
option name 'br-{{ name }}'
option name '{{ (bridge_name if bridge_name | length <= 15) | mandatory('The generated inteface name exceeds the 15 characters limit of the linux kernel. Try to shorten the name to resolve this.') }}'
option type 'bridge'
{% if network.get('enforce_client_isolation') and role == 'corerouter' %}
option macaddr '02:00:00:00:00:01'
Expand Down
2 changes: 1 addition & 1 deletion roles/cfg_openwrt/templates/common/config/wireless.j2
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ config wifi-iface '{{ wd_id }}_if{{ loop.index0 }}'
{% if 'mcast_rate' in iface %}
option mcast_rate '{{ iface['mcast_rate'] }}'
{% endif %}
option network '{{ (mesh_net['name'] if mesh_net['name'] | length < 15) | mandatory('Network name is longer than 15 characters') }}'
option network '{{ (mesh_net['name'] if mesh_net['name'] | length <= 15) | mandatory('The generated inteface name exceeds the 15 characters limit of the linux kernel. Try to shorten the name to resolve this.') }}'
{% endif %}
{% endif %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#jinja2: trim_blocks: "true", lstrip_blocks: "true"
{% for network in networks | selectattr('tunnel_wan_ip', 'defined') %}
{% set name = network['name'] if 'name' in network else network['role'] %}
{% set bridge_name = 'br-' + name %}
config tunnelmanager '{{ name }}'
option interface 'br-{{ name }}'
option interface '{{ (bridge_name if bridge_name | length <= 15) | mandatory('The generated inteface name exceeds the 15 characters limit of the linux kernel. Try to shorten the name to resolve this.') }}'
option namespace '{{ network['tunnel_namespace']|default(name) }}'
option mtu '{{ network['tunnel_mtu']|default(1412) }}'
option uplink_ip '{{ network['tunnel_wan_ip'] }}'
Expand Down

0 comments on commit ea94a5a

Please sign in to comment.