improve default route service to detect connected routers and use the addresses of the first one found
This commit is contained in:
parent
72189a5c28
commit
7d392c43ac
3 changed files with 34 additions and 30 deletions
|
@ -1,10 +1,10 @@
|
|||
import logging
|
||||
from typing import Any, Dict
|
||||
|
||||
import netaddr
|
||||
|
||||
from core import utils
|
||||
from core.configservice.base import ConfigService, ConfigServiceMode
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
GROUP_NAME = "Utility"
|
||||
|
||||
|
@ -24,16 +24,21 @@ class DefaultRouteService(ConfigService):
|
|||
modes = {}
|
||||
|
||||
def data(self) -> Dict[str, Any]:
|
||||
addresses = []
|
||||
for netif in self.node.netifs():
|
||||
if getattr(netif, "control", False):
|
||||
# only add default routes for linked routing nodes
|
||||
routes = []
|
||||
for other_node in self.node.session.nodes.values():
|
||||
if not isinstance(other_node, CoreNode):
|
||||
continue
|
||||
for addr in netif.addrlist:
|
||||
logging.info("default route address: %s", addr)
|
||||
net = netaddr.IPNetwork(addr)
|
||||
if net[1] != net[-2]:
|
||||
addresses.append(net[1])
|
||||
return dict(addresses=addresses)
|
||||
if other_node.type not in ["router", "mdr"]:
|
||||
continue
|
||||
commonnets = self.node.commonnets(other_node)
|
||||
if commonnets:
|
||||
_, _, router_eth = commonnets[0]
|
||||
for x in router_eth.addrlist:
|
||||
addr, prefix = x.split("/")
|
||||
routes.append(addr)
|
||||
break
|
||||
return dict(routes=routes)
|
||||
|
||||
|
||||
class DefaultMulticastRouteService(ConfigService):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue