From b02bec0a992331cddef9c424651185e3698cb589 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Fri, 7 Sep 2018 15:12:43 +0000 Subject: [PATCH] virt_ptp --- templates/netifs.json.j2 | 2 +- templates/network-interface-debian.j2 | 39 +++++++++++---------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/templates/netifs.json.j2 b/templates/netifs.json.j2 index 0955079..2f419a0 100644 --- a/templates/netifs.json.j2 +++ b/templates/netifs.json.j2 @@ -1,7 +1,7 @@ [ {% if netifs is defined %} {% for netif in netifs %} -{% if netifs[netif].type == "ethernet" or ( netifs[netif].type == "virt" and virt_type=="qemu" ) or netifs[netif].type == "bridge" %} +{% if netifs[netif].type == "ethernet" or netifs[netif].type == "virt" or netifs[netif].type == "virt_ptp" or netifs[netif].type == "bridge" %} "{{netif}}", {% endif %} {% endfor %} diff --git a/templates/network-interface-debian.j2 b/templates/network-interface-debian.j2 index 6544d51..ab09632 100644 --- a/templates/network-interface-debian.j2 +++ b/templates/network-interface-debian.j2 @@ -5,46 +5,37 @@ {% set dev = netifs[netif].device | default( 'enx' + netifs[netif].mac | regex_replace(':') ) %} auto {{dev}} -{% if netifs[netif].type == "virt" and hostvars[virt_host].netifs[netifs[netif].virt_host_netif].type == "virt_pointopoint" %} +{% if netifs[netif].type == "virt_ptp" %} # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}} + +# ipv4 {% set ips_ipv4 = netifs[netif] | json_query("ips[].ip") | ipv4("address") %} {% set ips_ipv4_first = ips_ipv4 | first %} {% set ips_ipv4 = ips_ipv4 | difference(ips_ipv4_first) %} -{% set virt_pointopoint_ips_ipv4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") %} -{% set virt_pointopoint_ips_ipv4_first = virt_pointopoint_ips_ipv4 | first %} -{% set virt_pointopoint_ips_ipv4 = virt_pointopoint_ips_ipv4 | difference(virt_pointopoint_ips_ipv4_first) %} -{% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %} -{% set ips_ipv6_first = ips_ipv6 | first %} -{% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %} -{% set virt_pointopoint_ips_ipv6 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv6("address") %} -{% set virt_pointopoint_ips_ipv6_first = virt_pointopoint_ips_ipv6 | first %} -{% set virt_pointopoint_ips_ipv6 = virt_pointopoint_ips_ipv6 | difference(virt_pointopoint_ips_ipv6_first) %} +{% set gateway4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") | first %} iface {{ dev }} inet static address {{ ips_ipv4_first }} netmask 255.255.255.255 - pointopoint {{ virt_pointopoint_ips_ipv4_first }} - gateway {{ virt_pointopoint_ips_ipv4_first }} -{% for ptpip in virt_pointopoint_ips_ipv4 %} - post-up /sbin/ip -family inet route add {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }} - pre-down /sbin/ip -family inet route del {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }} -{% endfor %} + pointopoint {{ gateway4 }} + gateway {{ gateway4 }} + {% for ip in ips_ipv4 %} iface {{ dev }} inet static address {{ ip }} netmask 32 {% endfor %} + +# ipv6 +{% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %} +{% set ips_ipv6_first = ips_ipv6 | first %} +{% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %} + iface {{ dev }} inet6 static address {{ ips_ipv6_first }} netmask 128 - post-up /sbin/ip -family inet6 route add {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }} - post-up /sbin/ip -family inet6 route add default via {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }} - pre-down /sbin/ip -family inet6 route del default via {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }} - pre-down /sbin/ip -family inet6 route del {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }} -{% for ptpip in virt_pointopoint_ips_ipv6 %} - post-up /sbin/ip -family inet6 route add {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }} - pre-down /sbin/ip -family inet6 route del {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }} -{% endfor %} + gateway {{ hostvars[virt_host].netifs[netifs[netif].virt_host_netif].ll6 }} + {% for ip in ips_ipv6 %} iface {{ dev }} inet6 static address {{ ip }}