From 3c646545987118cc442c51e20c474a0382567418 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Thu, 17 Feb 2022 10:14:04 -0800 Subject: [PATCH] services: fix missing configurations for ospfv2 in config services --- .../configservices/quaggaservices/services.py | 50 ++++++++++++++++--- .../usr/local/etc/quagga/Quagga.conf | 10 ++-- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/daemon/core/configservices/quaggaservices/services.py b/daemon/core/configservices/quaggaservices/services.py index fba892b4..a4ee157d 100644 --- a/daemon/core/configservices/quaggaservices/services.py +++ b/daemon/core/configservices/quaggaservices/services.py @@ -7,7 +7,8 @@ from core.configservice.base import ConfigService, ConfigServiceMode from core.emane.nodes import EmaneNet from core.nodes.base import CoreNodeBase from core.nodes.interface import DEFAULT_MTU, CoreInterface -from core.nodes.network import WlanNode +from core.nodes.network import PtpNet, WlanNode +from core.nodes.physical import Rj45Node logger = logging.getLogger(__name__) GROUP: str = "Quagga" @@ -55,6 +56,20 @@ def get_router_id(node: CoreNodeBase) -> str: return "0.0.0.0" +def rj45_check(iface: CoreInterface) -> bool: + """ + Helper to detect whether interface is connected an external RJ45 + link. + """ + if iface.net: + for peer_iface in iface.net.get_ifaces(): + if peer_iface == iface: + continue + if isinstance(peer_iface.node, Rj45Node): + return True + return False + + class Zebra(ConfigService): name: str = "zebra" group: str = GROUP @@ -105,7 +120,13 @@ class Zebra(ConfigService): ip4s.append(str(ip4)) for ip6 in iface.ip6s: ip6s.append(str(ip6)) - ifaces.append((iface, ip4s, ip6s, iface.control)) + configs = [] + if not iface.control: + for service in services: + config = service.quagga_iface_config(iface) + if config: + configs.append(config.split("\n")) + ifaces.append((iface, ip4s, ip6s, configs)) return dict( quagga_bin_search=quagga_bin_search, @@ -156,17 +177,32 @@ class Ospfv2(QuaggaService, ConfigService): ipv4_routing: bool = True def quagga_iface_config(self, iface: CoreInterface) -> str: - if has_mtu_mismatch(iface): - return "ip ospf mtu-ignore" - else: - return "" + has_mtu = has_mtu_mismatch(iface) + has_rj45 = rj45_check(iface) + is_ptp = isinstance(iface.net, PtpNet) + data = dict(has_mtu=has_mtu, is_ptp=is_ptp, has_rj45=has_rj45) + text = """ + % if has_mtu: + ip ospf mtu-ignore + % endif + % if has_rj45: + <% return STOP_RENDERING %> + % endif + % if is_ptp: + ip ospf network point-to-point + % endif + ip ospf hello-interval 2 + ip ospf dead-interval 6 + ip ospf retransmit-interval 5 + """ + return self.render_text(text, data) def quagga_config(self) -> str: router_id = get_router_id(self.node) addresses = [] for iface in self.node.get_ifaces(control=False): for ip4 in iface.ip4s: - addresses.append(str(ip4.ip)) + addresses.append(str(ip4)) data = dict(router_id=router_id, addresses=addresses) text = """ router ospf diff --git a/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf b/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf index 1d69838f..b7916f96 100644 --- a/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf +++ b/daemon/core/configservices/quaggaservices/templates/usr/local/etc/quagga/Quagga.conf @@ -1,4 +1,4 @@ -% for iface, ip4s, ip6s, is_control in ifaces: +% for iface, ip4s, ip6s, configs in ifaces: interface ${iface.name} % if want_ip4: % for addr in ip4s: @@ -10,13 +10,11 @@ interface ${iface.name} ipv6 address ${addr} % endfor % endif - % if not is_control: - % for service in services: - % for line in service.quagga_iface_config(iface).split("\n"): + % for config in configs: + % for line in config: ${line} - % endfor % endfor - % endif + % endfor ! % endfor