1
+ {% if not dummy_iface .track_service %}
1
2
auto {{ dummy_iface.ifname | mandatory }}
3
+ {% endif %}
2
4
{#
3
5
Use a namespace variable to track state across scopes: https://stackoverflow.com/a/61342337
4
6
In particular we only want to attach the interface creation pre-up command to the first IP associated with
5
7
an interface, or that command will run multiple times and cause errors.
6
8
Note: this requires Jinja2 2.10+
7
9
#}
8
10
{% set ns = namespace (has_init_line =false ) %}
11
+ {% macro init_lines (dummy_iface ) %}
12
+ {% if not ns .has_init_line %}
13
+ {# Cap MTU at IPv6 minimum as PMTUD setup is tricky... #}
14
+ mtu 1280
15
+ pre-up ip link add {{ dummy_iface.ifname }} type dummy
16
+ {% set ns .has_init_line = true %}
17
+ {% endif %}
18
+ {% endmacro %}
9
19
10
20
{% for ip in dummy_iface .ip 4 %}
11
21
iface {{ dummy_iface.ifname | mandatory }} inet static
@@ -14,11 +24,7 @@ iface {{ dummy_iface.ifname | mandatory }} inet static
14
24
{% set ip = ip | ipaddr ('host' ) %}
15
25
{% endif %}
16
26
address {{ ip }}
17
- {% if not ns .has_init_line %}
18
- mtu 1280
19
- pre-up ip link add {{ dummy_iface.ifname }} type dummy
20
- {% set ns .has_init_line = true %}
21
- {% endif %}
27
+ {{ init_lines(dummy_iface) }}
22
28
{% endfor %}
23
29
24
30
{% for ip in dummy_iface .ip 6 %}
@@ -27,10 +33,6 @@ iface {{ dummy_iface.ifname }} inet6 static
27
33
{% if ip | ipaddr ('address' ) %}
28
34
{% set ip = ip | ipaddr ('host' ) %}
29
35
{% endif %}
30
- mtu 1280
31
36
address {{ ip }}
32
- {% if not ns .has_init_line %}
33
- pre-up ip link add {{ dummy_iface.ifname }} type dummy
34
- {% set ns .has_init_line = true %}
35
- {% endif %}
37
+ {{ init_lines(dummy_iface) }}
36
38
{% endfor %}
0 commit comments