From 9f4db40ff68f45c611a84772bc79f58813ad3ef1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 15 Jul 2020 17:07:11 +0200 Subject: network: allow multiple overlays per segment (WIP) --- roles/vm/host/network/templates/interfaces.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'roles/vm/host/network/templates/interfaces.j2') diff --git a/roles/vm/host/network/templates/interfaces.j2 b/roles/vm/host/network/templates/interfaces.j2 index fe57a024..004c1f96 100644 --- a/roles/vm/host/network/templates/interfaces.j2 +++ b/roles/vm/host/network/templates/interfaces.j2 @@ -60,7 +60,7 @@ iface {{ interface.name }} inet6 static {% endfor %} -{% for parent in network.vlans | default({}) | list | sort %} +{% for parent in (network.vlans | default({}) | list | sort) %} ## vlan interfaces @ {{ parent }} {% for vlan in network.vlans[parent] %} -- cgit v1.2.3 From e60581e1c8adeb7363c0c00d272db898d64dad51 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 20 Jul 2020 23:26:25 +0200 Subject: vm/host network using ifconfig includes --- .../vm/host/network/templates/bridge-interfaces.j2 | 44 ++++++++++------------ roles/vm/host/network/templates/interfaces.j2 | 43 +++++++++------------ .../vm/host/network/templates/interfaces/simple.j2 | 11 ++++++ .../host/network/templates/interfaces/simple6.j2 | 10 +++++ 4 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 roles/vm/host/network/templates/interfaces/simple.j2 create mode 100644 roles/vm/host/network/templates/interfaces/simple6.j2 (limited to 'roles/vm/host/network/templates/interfaces.j2') diff --git a/roles/vm/host/network/templates/bridge-interfaces.j2 b/roles/vm/host/network/templates/bridge-interfaces.j2 index c0519737..4d80db4c 100644 --- a/roles/vm/host/network/templates/bridge-interfaces.j2 +++ b/roles/vm/host/network/templates/bridge-interfaces.j2 @@ -2,46 +2,40 @@ {% set bridge = item.value %} {% set interface = (network.interfaces | selectattr('name', 'eq', bridge_name) | first | default({})) %} auto {{ bridge_name }} -{% if 'address' in interface %} -iface {{ bridge_name }} inet static - address {{ interface.address | ipaddr('address') }} - netmask {{ interface.address | ipaddr('netmask') }} -{% if 'gateway' in interface %} - gateway {{ interface.gateway }} -{% endif %} -{% else %} -iface {{ bridge_name }} inet manual -{% endif %} -{% if 'interfaces' in bridge and (bridge.interfaces | length) > 0 %} - bridge_ports {{ bridge.interfaces | join(' ') }} -{% else %} - bridge_ports none -{% endif %} +iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'manual') }} + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf + bridge_ports {{ bridge.interfaces | default(['none']) | join(' ') }} bridge_stp off bridge_waitport 0 bridge_fd 0 - up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra - up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf up modprobe br_netfilter up /sbin/sysctl net.bridge.bridge-nf-call-iptables=0 up /sbin/sysctl net.bridge.bridge-nf-call-ip6tables=0 up /sbin/sysctl net.bridge.bridge-nf-call-arptables=0 -{% if 'address' in interface and 'prefix' in bridge %} -{% if 'nat' in bridge and bridge.nat %} +{% if 'address' in interface %} + address {{ interface.address | ipaddr('address') }} + netmask {{ interface.address | ipaddr('netmask') }} +{% if 'gateway' in interface %} + gateway {{ interface.gateway }} +{% endif %} +{% if 'prefix' in bridge %} +{% if 'nat' in bridge and bridge.nat %} up echo 1 > /proc/sys/net/ipv4/conf/$IFACE/forwarding up echo 1 > /proc/sys/net/ipv4/conf/{{ ansible_default_ipv4.interface }}/forwarding up /sbin/iptables -t nat -A POSTROUTING -o {{ ansible_default_ipv4.interface }} -s {{ bridge.prefix }} -j SNAT --to {{ ansible_default_ipv4.address }} -{% endif %} -{% for overlay_name in (bridge.overlays | default({}) | list | sort) %} +{% endif %} +{% for overlay_name in (bridge.overlays | default({}) | list | sort) %} {% set overlay = bridge.overlays[overlay_name] %} -{% for dest, offset in (overlay.offsets | dictsort(by='value')) %} +{% for dest, offset in (overlay.offsets | dictsort(by='value')) %} up /bin/ip route add {{ (overlay.prefix | ipaddr(offset)).split('/')[0] }}/32 via {{ (bridge.prefix | ipaddr(bridge.offsets[dest])).split('/')[0] }} # {{ dest }} -{% endfor %} +{% endfor %} up /bin/ip route add unreachable {{ overlay.prefix }} down /sbin/ip route del {{ overlay.prefix }} -{% endfor %} -{% if 'nat' in bridge and bridge.nat %} +{% endfor %} +{% if 'nat' in bridge and bridge.nat %} down /sbin/iptables -t nat -D POSTROUTING -o {{ ansible_default_ipv4.interface }} -s {{ bridge.prefix }} -j SNAT --to {{ ansible_default_ipv4.address }} +{% endif %} {% endif %} {% endif %} {% if 'address6' in interface %} diff --git a/roles/vm/host/network/templates/interfaces.j2 b/roles/vm/host/network/templates/interfaces.j2 index 004c1f96..6daa22bd 100644 --- a/roles/vm/host/network/templates/interfaces.j2 +++ b/roles/vm/host/network/templates/interfaces.j2 @@ -22,39 +22,20 @@ iface {{ interface }} inet manual {% set tmp = network.interfaces | selectattr('name', 'eq', bond.name) | list %} auto {{ bond.name }} iface {{ bond.name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static') }} + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf bond-mode {{ bond.mode }} bond-slaves {{ bond.slaves | sort | join(' ') }} {% for option in (bond.options | default({}) | list | sort) %} bond-{{ option }} {{ bond.options[option] }} {% endfor %} - up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra - up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf {% if (tmp | length) > 0 %} {% set interface = tmp | first %} - address {{ interface.address | ipaddr('address') }} - netmask {{ interface.address | ipaddr('netmask') }} -{% if 'gateway' in interface %} - gateway {{ interface.gateway }} -{% endif %} -{% for route in interface.static_routes | default([]) %} - up /bin/ip route add {{ route.destination }} via {{ route.gateway }} -{% endfor %} -{% for route in interface.static_routes | default([]) | reverse %} - down /bin/ip route del {{ route.destination }} via {{ route.gateway }} -{% endfor %} +{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %} {% if 'address6' in interface %} iface {{ interface.name }} inet6 static - address {{ interface.address6 }} -{% if 'gateway6' in interface %} - gateway {{ interface.gateway6 }} -{% endif %} -{% for route in interface.static_routes6 | default([]) %} - up /bin/ip -6 route add {{ route.destination }} via {{ route.gateway }} -{% endfor %} -{% for route in interface.static_routes6 | default([]) | reverse %} - down /bin/ip -6 route del {{ route.destination }} via {{ route.gateway }} -{% endfor %} +{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %} {% endif %} {% endif %} @@ -64,11 +45,21 @@ iface {{ interface.name }} inet6 static ## vlan interfaces @ {{ parent }} {% for vlan in network.vlans[parent] %} -auto {{ parent }}.{{ vlan }} -iface {{ parent }}.{{ vlan }} inet manual +{% set interface_name = parent+'.'+(vlan | string) %} +{% set tmp = network.interfaces | selectattr('name', 'eq', interface_name) | list %} +auto {{ interface_name }} +iface {{ interface_name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static') }} up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf -{# TODO: add interface config like above if (network.interfaces | selectattr('name', 'eq', 'parent+'.'+vlan') | list) > 0 ... #} +{% if (tmp | length) > 0 %} +{% set interface = tmp | first %} +{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %} +{% if 'address6' in interface %} + +iface {{ interface.name }} inet6 static +{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %} +{% endif %} +{% endif %} {% endfor %} diff --git a/roles/vm/host/network/templates/interfaces/simple.j2 b/roles/vm/host/network/templates/interfaces/simple.j2 new file mode 100644 index 00000000..c5b7dadc --- /dev/null +++ b/roles/vm/host/network/templates/interfaces/simple.j2 @@ -0,0 +1,11 @@ + address {{ interface.address | ipaddr('address') }} + netmask {{ interface.address | ipaddr('netmask') }} +{% if 'gateway' in interface %} + gateway {{ interface.gateway }} +{% endif %} +{% for route in interface.static_routes | default([]) %} + up /bin/ip route add {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %} +{% endfor %} +{% for route in interface.static_routes | default([]) | reverse %} + down /bin/ip route del {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %} +{% endfor %} diff --git a/roles/vm/host/network/templates/interfaces/simple6.j2 b/roles/vm/host/network/templates/interfaces/simple6.j2 new file mode 100644 index 00000000..37fda07a --- /dev/null +++ b/roles/vm/host/network/templates/interfaces/simple6.j2 @@ -0,0 +1,10 @@ + address {{ interface.address6 }} +{% if 'gateway6' in interface %} + gateway {{ interface.gateway6 }} +{% endif %} +{% for route in interface.static_routes6 | default([]) %} + up /bin/ip -6 route add {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %} +{% endfor %} +{% for route in interface.static_routes6 | default([]) | reverse %} + down /bin/ip -6 route del {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %} +{% endfor %} -- cgit v1.2.3