2021-09-29 17:27:13 +00:00
|
|
|
from ipaddress import IPv4Network
|
|
|
|
|
|
|
|
AS_NUMBERS = {
|
|
|
|
# 4290xxxxxx
|
|
|
|
'home': 4290000138,
|
|
|
|
'htz-cloud': 4290000137,
|
2023-09-09 12:11:39 +00:00
|
|
|
'ionos': 4290000002,
|
2023-09-23 13:15:28 +00:00
|
|
|
'glauca': 4290207960,
|
2021-09-29 17:27:13 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 12:11:39 +00:00
|
|
|
WG_AUTOGEN_NODES = [
|
|
|
|
# only ever append to this list. If a node vanishes, set its name to
|
|
|
|
# `None`. You may remove nodes from the end of this, though it's not
|
|
|
|
# recommended to do so.
|
|
|
|
|
|
|
|
None, # fkusei-locutus never used this
|
|
|
|
'home.router',
|
|
|
|
'htz-cloud.wireguard',
|
|
|
|
'icinga2',
|
2024-09-14 16:29:55 +00:00
|
|
|
None, # daisy
|
2023-09-09 12:11:39 +00:00
|
|
|
]
|
2021-09-29 17:27:13 +00:00
|
|
|
|
2023-12-10 13:48:24 +00:00
|
|
|
WG_AUTOGEN_SETTINGS = {
|
|
|
|
# special settings to apply when peering with a specific node
|
|
|
|
'home.router': {
|
2023-12-10 15:57:19 +00:00
|
|
|
'firewall': {'versatel'},
|
2023-12-10 14:20:05 +00:00
|
|
|
'no_autoconnect': True,
|
2023-12-10 13:48:24 +00:00
|
|
|
'persistent_keepalive': False,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-09 12:11:39 +00:00
|
|
|
def get_subnet_for_connection(repo, peer_a, peer_b):
|
|
|
|
assert peer_a in WG_AUTOGEN_NODES
|
|
|
|
assert peer_b in WG_AUTOGEN_NODES
|
2021-09-29 17:27:13 +00:00
|
|
|
|
2023-09-09 12:11:39 +00:00
|
|
|
pos_peer_a = WG_AUTOGEN_NODES.index(peer_a)
|
|
|
|
pos_peer_b = WG_AUTOGEN_NODES.index(peer_b)
|
2021-09-29 17:27:13 +00:00
|
|
|
|
|
|
|
vpn_subnet = list(IPv4Network('169.254.0.0/16').subnets(new_prefix=24))[pos_peer_a]
|
|
|
|
return list(IPv4Network(vpn_subnet).subnets(new_prefix=31))[pos_peer_b]
|