From 4acfe517d5e3483c090476f4fd4a7e2d41b9abdc Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Sun, 22 Sep 2024 23:52:06 +0200 Subject: [PATCH] Handle vlans --- ubiquiti-edge-router.j2 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ubiquiti-edge-router.j2 b/ubiquiti-edge-router.j2 index ab7828c..9f6c0f3 100644 --- a/ubiquiti-edge-router.j2 +++ b/ubiquiti-edge-router.j2 @@ -7,6 +7,7 @@ {% endif %} {%- for intf in device.interfaces.all() %} +{%- set ifpath = intf.name %} {#- Loopback #} {%- if intf.name == "lo" %}{% set iftype = "loopback" %}{% endif %} @@ -16,6 +17,13 @@ {%- set iftype = "ethernet" %} {%- endif %} +{#- VLANs #} +{%- if intf.type == 'virtual' and intf.parent and intf.mode == 'access' and intf.untagged_vlan is not none %} +{%- if intf.parent.type not in ["virtual", "other", "bridge", "lag"] %}{% set iftype = "ethernet" %}{% endif %} +{#- TODO: add other iftypes #} +{%- set ifpath = "%s vif %d" % (intf.parent.name, intf.untagged_vlan.vid) %} +{%- endif %} + {#- Tunnels #} {%- with term = intf.tunnel_terminations.first() %} {%- if term %} @@ -41,16 +49,16 @@ set interfaces tunnel {{ intf.name }} remote-ip {{ remote_ip.address | ipaddr('a {#- Generic interface config #} {%- if iftype %} {%- if intf.description != '' %} -set interfaces {{ iftype }} {{ intf.name }} description "{{ intf.description | slugify(lower=False, spaces=True, only_ascii=True, extra_chars='()') }}" +set interfaces {{ iftype }} {{ ifpath }} description "{{ intf.description | slugify(lower=False, spaces=True, only_ascii=True, extra_chars='()') }}" {%- endif %} {%- for addr in intf.ip_addresses.all() %} {%- if addr.status == 'dhcp' %} -set interfaces {{ iftype }} {{ intf.name }} address dhcp +set interfaces {{ iftype }} {{ ifpath }} address dhcp {%- elif addr.status == 'slaac' %} -set interfaces {{ iftype }} {{ intf.name }} ipv6 address autoconf +set interfaces {{ iftype }} {{ ifpath }} ipv6 address autoconf {%- else %} -set interfaces {{ iftype }} {{ intf.name }} address {{ addr.address }} +set interfaces {{ iftype }} {{ ifpath }} address {{ addr.address }} {%- endif %} {%- endfor %}