2020-11-13 21:11:56 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
2020-11-13 22:30:21 +00:00
|
|
|
'isc-dhcp-server': {},
|
2020-11-13 21:11:56 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-17 08:12:32 +00:00
|
|
|
'bash_aliases': {
|
2021-03-26 08:27:52 +00:00
|
|
|
'leases': 'sudo dhcp-lease-list | tail -n +4 | sort -k 2,2',
|
2021-01-17 08:12:32 +00:00
|
|
|
},
|
2020-11-13 21:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'dhcpd/fixed_allocations',
|
|
|
|
)
|
2020-11-13 21:11:56 +00:00
|
|
|
def get_static_allocations(metadata):
|
|
|
|
allocations = {}
|
2020-11-15 12:23:24 +00:00
|
|
|
for rnode in repo.nodes:
|
|
|
|
if rnode.metadata.get('location', '') != metadata.get('location', ''):
|
|
|
|
continue
|
|
|
|
|
2021-02-12 19:37:36 +00:00
|
|
|
for iface_name, iface_config in rnode.metadata.get('interfaces', {}).items():
|
|
|
|
if iface_config.get('dhcp', False):
|
2021-01-07 21:14:17 +00:00
|
|
|
try:
|
2021-02-12 19:37:36 +00:00
|
|
|
allocations[f'{rnode.name}_{iface_name}'] = {
|
|
|
|
'ipv4': sorted(iface_config['ips'])[0],
|
|
|
|
'mac': iface_config['mac'],
|
2021-01-07 21:14:17 +00:00
|
|
|
}
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2020-11-15 11:07:02 +00:00
|
|
|
|
2020-11-13 21:11:56 +00:00
|
|
|
return {
|
|
|
|
'dhcpd': {
|
|
|
|
'fixed_allocations': allocations,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:01:14 +00:00
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
2021-12-14 13:03:13 +00:00
|
|
|
'nftables/rules/10-dhcpd',
|
2021-01-07 17:44:38 +00:00
|
|
|
)
|
2021-06-03 11:59:15 +00:00
|
|
|
def nftables(metadata):
|
2021-02-12 19:37:36 +00:00
|
|
|
rules = set()
|
2021-06-03 11:59:15 +00:00
|
|
|
for iface in node.metadata.get('dhcpd/subnets', {}):
|
2021-12-14 13:03:13 +00:00
|
|
|
rules.add(f'inet filter input udp dport {{ 67, 68 }} iif {iface} accept')
|
2020-11-15 11:01:14 +00:00
|
|
|
|
|
|
|
return {
|
2021-06-03 11:59:15 +00:00
|
|
|
'nftables': {
|
|
|
|
'rules': {
|
2021-12-14 13:03:13 +00:00
|
|
|
# can't use port_rules here, because we're generating interface based rules.
|
|
|
|
'10-dhcpd': sorted(rules),
|
2020-11-15 11:01:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|