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',
|
2023-09-23 14:46:45 +00:00
|
|
|
'daisy',
|
2023-09-09 12:11:39 +00:00
|
|
|
]
|
2021-09-29 17:27:13 +00:00
|
|
|
|
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]
|