This commit is contained in:
mwiegand 2021-06-25 02:31:48 +02:00
parent 1e39b64a36
commit 40183b9e36
2 changed files with 35 additions and 28 deletions

View file

@ -20,27 +20,38 @@ defaults = {
'systemd-networkd/networks', 'systemd-networkd/networks',
) )
def systemd_networkd_networks(metadata): def systemd_networkd_networks(metadata):
wg0 = {
'Match': {
'Name': 'wg0',
},
'Address': {
'Address': metadata.get('wireguard/my_ip'),
},
'Route': {
'Destination': str(ip_interface(metadata.get('wireguard/my_ip')).network),
'GatewayOnlink': 'yes',
},
'Network': {
'DHCP': 'no',
'IPForward': 'yes',
'IPMasquerade': 'yes',
'IPv6AcceptRA': 'no',
},
}
for peer in metadata.get('wireguard/peers').values():
for route in peer.get('route', []):
wg0.update({
f'Route#{route}': {
'Gateway': str(ip_interface(metadata.get('wireguard/my_ip')).ip),
'Destination': route,
}
})
return { return {
'systemd-networkd': { 'systemd-networkd': {
'networks': { 'networks': {
'wg0': { 'wg0': wg0,
'Match': {
'Name': 'wg0',
},
'Address': {
'Address': metadata.get('wireguard/my_ip'),
},
'Route': {
'Destination': str(ip_interface(metadata.get('wireguard/my_ip')).network),
'GatewayOnlink': 'yes',
},
'Network': {
'DHCP': 'no',
'IPForward': 'yes',
'IPMasquerade': 'yes',
'IPv6AcceptRA': 'no',
},
},
}, },
}, },
} }

View file

@ -85,16 +85,12 @@
# ip r add 10.0.0.0/24 via 172.19.136.2 dev wg0 # ip r add 10.0.0.0/24 via 172.19.136.2 dev wg0
'my_ip': '172.19.136.2/22', 'my_ip': '172.19.136.2/22',
'peers': { 'peers': {
'home.server': {}, 'home.server': {
}, 'route': [
}, '10.0.0.0/24',
'systemd-networkd': { '10.0.2.0/24',
'networks': { '10.0.9.0/24',
'wg0': { ]
'Route#10.0.0.0/24': {
'Gateway': '172.19.136.2',
'Destination': '10.0.0.0/24',
},
}, },
}, },
}, },