diff --git a/bundles/wide-dhcp6c/files/dhcp6c.conf b/bundles/wide-dhcp6c/files/dhcp6c.conf new file mode 100644 index 0000000..05ec14c --- /dev/null +++ b/bundles/wide-dhcp6c/files/dhcp6c.conf @@ -0,0 +1,17 @@ +interface ${source} { + send ia-pd 0; +}; + +id-assoc pd 0 { +% for iface, subnet_id in sorted(targets.items()): + prefix-interface ${iface} { + sla-len ${subnet_len}; + sla-id ${subnet_id}; + ifid ${subnet_id}; + }; +% endfor +}; + +profile default { + information-only; +}; diff --git a/bundles/wide-dhcp6c/files/ip-down b/bundles/wide-dhcp6c/files/ip-down new file mode 100644 index 0000000..ec060ee --- /dev/null +++ b/bundles/wide-dhcp6c/files/ip-down @@ -0,0 +1,10 @@ +#!/bin/bash + +systemctl stop wide-dhcpv6-client + +% for interface, subnet_id in sorted(targets.items()): +for IP in $(ip -6 addr show dev ${interface} | grep inet6 | awk '{print $2}' | grep -vF 'fe80::') +do + ip -6 addr del $IP dev ${interface} +done +% endfor diff --git a/bundles/wide-dhcp6c/files/ip-up b/bundles/wide-dhcp6c/files/ip-up new file mode 100644 index 0000000..ee8bc91 --- /dev/null +++ b/bundles/wide-dhcp6c/files/ip-up @@ -0,0 +1,11 @@ +#!/bin/bash + +INTERFACE=$1 + +if [[ "$INTERFACE" != "${source}" ]] +then + echo "wide-dhcp6c is not configured to work on $INTERFACE" + exit 0 +fi + +systemctl start wide-dhcpv6-client diff --git a/bundles/wide-dhcp6c/files/wide-dhcpv6-client.service b/bundles/wide-dhcp6c/files/wide-dhcpv6-client.service new file mode 100644 index 0000000..f7c8747 --- /dev/null +++ b/bundles/wide-dhcp6c/files/wide-dhcpv6-client.service @@ -0,0 +1,10 @@ +[Unit] +Description=WIDE-DHCPv6-Client +After=network-online.target + +[Service] +PIDFile=/run/dhcp6c.pid +ExecStart=/usr/sbin/dhcp6c -c /etc/wide-dhcpv6/dhcp6c.conf -p /run/dhcp6c.pid -f ${source} + +[Install] +WantedBy=default.target diff --git a/bundles/wide-dhcp6c/items.py b/bundles/wide-dhcp6c/items.py new file mode 100644 index 0000000..5dc7a1f --- /dev/null +++ b/bundles/wide-dhcp6c/items.py @@ -0,0 +1,58 @@ +if node.metadata.get('wide-dhcp6c', {}).get('integrate-with-pppd', False): + files['/etc/ppp/ip-up.d/wide-dhcp6c'] = { + 'source': 'ip-up', + 'content_type': 'mako', + 'context': { + 'source': node.metadata['wide-dhcp6c']['source'], + }, + 'mode': '0755', + } + files['/etc/ppp/ip-down.d/wide-dhcp6c'] = { + 'source': 'ip-down', + 'content_type': 'mako', + 'context': { + 'targets': node.metadata['wide-dhcp6c']['targets'], + }, + 'mode': '0755', + } + + # Will be started and stopped by pppd. + should_be_running = None + should_be_enabled = False +else: + should_be_running = True + should_be_enabled = True + +files['/etc/wide-dhcpv6/dhcp6c.conf'] = { + 'content_type': 'mako', + 'context': { + 'source': node.metadata['wide-dhcp6c']['source'], + 'targets': node.metadata['wide-dhcp6c']['targets'], + 'subnet_len': node.metadata['wide-dhcp6c']['subnet_len'], + }, + 'triggers': { + 'svc_systemd:wide-dhcpv6-client:restart', + }, +} + +files['/etc/systemd/system/wide-dhcpv6-client.service'] = { + 'content_type': 'mako', + 'context': { + 'source': node.metadata['wide-dhcp6c']['source'], + }, + 'triggers': { + 'action:systemd-reload', + 'svc_systemd:wide-dhcpv6-client:restart', + }, +} + +svc_systemd = { + 'wide-dhcpv6-client': { + 'running': should_be_running, + 'enabled': should_be_enabled, + 'needs': { + 'file:/etc/systemd/system/wide-dhcpv6-client.service', + 'file:/etc/wide-dhcpv6/dhcp6c.conf', + }, + }, +} diff --git a/bundles/wide-dhcp6c/metadata.py b/bundles/wide-dhcp6c/metadata.py new file mode 100644 index 0000000..ffa4e9d --- /dev/null +++ b/bundles/wide-dhcp6c/metadata.py @@ -0,0 +1,18 @@ +defaults = { + 'apt': { + 'packages': { + 'wide-dhcpv6-client': {}, + }, + }, + 'iptables': { + 'bundle_rules': { + 'wide-dhcp6c': [ + 'ip6tables -A INPUT -p udp -s ff00::/12 -j ACCEPT', + 'ip6tables -A INPUT -p udp -s fe80::/10 -j ACCEPT', + ], + }, + }, + 'wide-dhcp6c': { + 'subnet_len': '8', + }, +} diff --git a/nodes/home/router.py b/nodes/home/router.py index 1df1b55..58eaf09 100644 --- a/nodes/home/router.py +++ b/nodes/home/router.py @@ -6,6 +6,7 @@ nodes['home.router'] = { 'iptables', 'pppd', 'dhcpd', + 'wide-dhcp6c', }, 'groups': set(), 'metadata': { @@ -74,6 +75,13 @@ nodes['home.router'] = { 'cpu': 2, 'ram': 2, }, + 'wide-dhcp6c': { + 'integrate-with-pppd': True, + 'source': 'ppp0', + 'targets': { + 'enp1s0.42': '1', + }, + }, }, 'os': 'debian', 'os_version': (10,),