bundles/systemd-networkd: fix bridge-in-bridge-setup on home.nas not working properly
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-10-11 20:46:07 +02:00
parent 2662fa5976
commit 61e5591628
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 55 additions and 12 deletions

View file

@ -0,0 +1,7 @@
[Match]
Name=${bridge}
[Network]
% for vlan in sorted(vlans):
VLAN=${bridge}.${vlan}
% endfor

View file

@ -47,7 +47,7 @@ for interface, config in node.metadata['interfaces'].items():
if '.' in interface: if '.' in interface:
vlan_id = int(interface.split('.')[1]) vlan_id = int(interface.split('.')[1])
vlan_hex = '%02x' % (vlan_id % 255) vlan_hex = '%02x' % (vlan_id % 255)
files['/etc/systemd/network/60-iface-{}.netdev'.format(interface)] = { files[f'/etc/systemd/network/{interface}.netdev'] = {
'source': 'template-iface-vlan.netdev', 'source': 'template-iface-vlan.netdev',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -62,9 +62,8 @@ for interface, config in node.metadata['interfaces'].items():
'svc_systemd:systemd-networkd:restart', 'svc_systemd:systemd-networkd:restart',
}, },
} }
weight = 61
elif interface.startswith('dummy'): elif interface.startswith('dummy'):
files[f'/etc/systemd/network/60-iface-{interface}.netdev'] = { files[f'/etc/systemd/network/{interface}.netdev'] = {
'source': 'template-dummy.netdev', 'source': 'template-dummy.netdev',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -77,12 +76,9 @@ for interface, config in node.metadata['interfaces'].items():
'svc_systemd:systemd-networkd:restart', 'svc_systemd:systemd-networkd:restart',
}, },
} }
weight = 61
else:
weight = 50
if not config.get('ignore', False): if not config.get('ignore', False):
files['/etc/systemd/network/{}-iface-{}.network'.format(weight, interface)] = { files[f'/etc/systemd/network/{interface}.network'] = {
'source': template, 'source': template,
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -98,7 +94,7 @@ for interface, config in node.metadata['interfaces'].items():
} }
for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items(): for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items():
files['/etc/systemd/network/20-bond-{}.netdev'.format(bond)] = { files[f'/etc/systemd/network/{bond}.netdev'] = {
'source': 'template-bond.netdev', 'source': 'template-bond.netdev',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -113,7 +109,8 @@ for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items():
'svc_systemd:systemd-networkd:restart', 'svc_systemd:systemd-networkd:restart',
}, },
} }
files['/etc/systemd/network/21-bond-{}.network'.format(bond)] = {
files[f'/etc/systemd/network/{bond}.network'] = {
'source': 'template-bond.network', 'source': 'template-bond.network',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -129,7 +126,12 @@ for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items():
} }
for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items(): for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items():
files['/etc/systemd/network/30-bridge-{}.netdev'.format(brname)] = { filename = '{}-match-{}'.format(
brname,
'-'.join(sorted(config['match'])),
)
files[f'/etc/systemd/network/{brname}.netdev'] = {
'source': 'template-bridge.netdev', 'source': 'template-bridge.netdev',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -142,7 +144,8 @@ for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items():
'svc_systemd:systemd-networkd:restart', 'svc_systemd:systemd-networkd:restart',
}, },
} }
files['/etc/systemd/network/31-bridge-{}.network'.format(brname)] = {
files[f'/etc/systemd/network/{filename}.network'] = {
'source': 'template-bridge.network', 'source': 'template-bridge.network',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -157,6 +160,22 @@ for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items():
}, },
} }
if config.get('vlans', set()):
files[f'/etc/systemd/network/{brname}.network'] = {
'source': 'template-bridge-vlan.network',
'content_type': 'mako',
'context': {
'bridge': brname,
'vlans': config.get('vlans', set()),
},
'needed_by': {
'svc_systemd:systemd-networkd',
},
'triggers': {
'svc_systemd:systemd-networkd:restart',
},
}
svc_systemd = { svc_systemd = {
'systemd-networkd': {}, 'systemd-networkd': {},
} }

View file

@ -11,12 +11,14 @@ defaults = {
@metadata_reactor.provides( @metadata_reactor.provides(
'interfaces', 'interfaces',
'systemd-networkd/bridges',
) )
def add_vlan_infos_to_interface(metadata): def add_vlan_infos_to_interface(metadata):
interfaces = {} interfaces = {}
bridges = {}
for iface in metadata.get('interfaces', {}): for iface in metadata.get('interfaces', {}):
if not '.' in iface: if '.' not in iface:
continue continue
interface,vlan = iface.split('.') interface,vlan = iface.split('.')
@ -24,6 +26,21 @@ def add_vlan_infos_to_interface(metadata):
interfaces.setdefault(interface, {}).setdefault('vlans', set()) interfaces.setdefault(interface, {}).setdefault('vlans', set())
interfaces[interface]['vlans'].add(vlan) interfaces[interface]['vlans'].add(vlan)
for bridge, config in metadata.get('systemd-networkd/bridges', {}).items():
for iface in config.get('match', {}):
if '.' not in iface:
continue
interface,vlan = iface.split('.')
bridges.setdefault(interface, {}).setdefault('vlans', set())
bridges[interface]['vlans'].add(vlan)
interfaces.setdefault(iface, {'ignore': True})
return { return {
'interfaces': interfaces, 'interfaces': interfaces,
'systemd-networkd': {
'bridges': bridges,
},
} }