pygui: update to account for already used mac addresses that may collide with auto assigned addresses

This commit is contained in:
Blake Harnden 2021-01-13 10:50:16 -08:00
parent 878d943ee3
commit 4007dc331b
2 changed files with 14 additions and 4 deletions

View file

@ -451,7 +451,7 @@ class CoreClient:
self.client.add_session_server(self.session.id, server.name, server.address)
def start_session(self) -> Tuple[bool, List[str]]:
self.ifaces_manager.reset_mac()
self.ifaces_manager.set_macs([x.link for x in self.links.values()])
nodes = [x.to_proto() for x in self.session.nodes.values()]
links = []
asymmetric_links = []

View file

@ -56,16 +56,17 @@ class InterfaceManager:
self.current_mac: Optional[EUI] = None
self.current_subnets: Optional[Subnets] = None
self.used_subnets: Dict[Tuple[IPNetwork, IPNetwork], Subnets] = {}
self.used_macs: Set[str] = set()
def update_ips(self, ip4: str, ip6: str) -> None:
self.reset()
self.ip4_subnets = IPNetwork(f"{ip4}/{self.ip4_mask}")
self.ip6_subnets = IPNetwork(f"{ip6}/{self.ip6_mask}")
def reset_mac(self) -> None:
self.current_mac = self.mac
def next_mac(self) -> str:
while str(self.current_mac) in self.used_macs:
value = self.current_mac.value + 1
self.current_mac = EUI(value, dialect=netaddr.mac_unix_expanded)
mac = str(self.current_mac)
value = self.current_mac.value + 1
self.current_mac = EUI(value, dialect=netaddr.mac_unix_expanded)
@ -114,6 +115,15 @@ class InterfaceManager:
subnets.used_indexes.discard(index)
self.current_subnets = None
def set_macs(self, links: List[Link]) -> None:
self.current_mac = self.mac
self.used_macs.clear()
for link in links:
if link.iface1:
self.used_macs.add(link.iface1.mac)
if link.iface2:
self.used_macs.add(link.iface2.mac)
def joined(self, links: List[Link]) -> None:
ifaces = []
for link in links: