net/frr: Fix STATIC template interface issue, use isEmpty() in validation (#5019)

* net/frr: Fix STATIC template interface issue, use isEmpty() in validation

* Properly safeguard optional parameters
This commit is contained in:
Monviech 2025-11-13 10:37:42 +01:00 committed by GitHub
parent 68505ed357
commit 355309551b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View file

@ -48,7 +48,7 @@ class STATICd extends BaseModel
continue;
}
$key = $route->__reference;
if (!empty((string)$route->network) && !empty((string)$route->gateway)) {
if (!$route->network->isEmpty() && !$route->gateway->isEmpty()) {
$net_proto = str_contains($route->network, ':') ? 'inet6' : 'inet';
$gw_proto = str_contains($route->gateway, ':') ? 'inet6' : 'inet';
if ($net_proto != $gw_proto) {
@ -57,10 +57,10 @@ class STATICd extends BaseModel
);
}
}
if (empty((string)$route->gateway) && empty((string)$route->interfacename)) {
if ($route->gateway->isEmpty() && $route->interfacename->isEmpty()) {
$messages->appendMessage(
new Message(
gettext("When no interface is provided, at least a gateway must be offered"),
gettext("Either an interface or a gateway is required."),
$key . ".gateway"
)
);

View file

@ -2,7 +2,18 @@
{% if not helpers.empty('OPNsense.quagga.static.enabled') %}
{% for route in helpers.toList('OPNsense.quagga.static.routes.route') %}
{% if route.enabled == '1' %}
{% if ':' in route.network %}ipv6{% else %}ip{% endif %} route {{ route.network }} {{ route.gateway|default('')}} {{ helpers.physical_interface(route.interfacename) }}
{%- if ':' in route.network %}
ipv6
{%- else %}
ip
{%- endif %}
route {{ route.network }}
{%- if route.gateway %}
{{ route.gateway}}
{%- endif %}
{%- if route.interfacename %}
{{ helpers.physical_interface(route.interfacename) }}
{%- endif +%}
{% endif %}
{% endfor %}
{% endif %}