mirror of
https://github.com/Telecominfraproject/ols-ucentral-schema.git
synced 2025-11-02 19:18:05 +00:00
renderer: add support for rendering IPv6 schema properties
Also consolidate existing IPv4 interface config while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
committed by
John Crispin
parent
b98b153a54
commit
e2590c3338
@@ -168,6 +168,16 @@ let ethernet = {
|
|||||||
return sort(keys(matched));
|
return sort(keys(matched));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
is_single_config: function(interface) {
|
||||||
|
let ipv4_mode = interface.ipv4 ? interface.ipv4.addressing : 'none';
|
||||||
|
let ipv6_mode = interface.ipv6 ? interface.ipv6.addressing : 'none';
|
||||||
|
|
||||||
|
return (
|
||||||
|
(ipv4_mode == 'none') || (ipv6_mode == 'none') ||
|
||||||
|
(ipv4_mode == 'static' && ipv6_mode == 'static')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
calculate_name: function(interface) {
|
calculate_name: function(interface) {
|
||||||
let vid = interface.vlan ? interface.vlan.id : '';
|
let vid = interface.vlan ? interface.vlan.id : '';
|
||||||
|
|
||||||
@@ -177,13 +187,19 @@ let ethernet = {
|
|||||||
calculate_names: function(interface) {
|
calculate_names: function(interface) {
|
||||||
let name = this.calculate_name(interface);
|
let name = this.calculate_name(interface);
|
||||||
|
|
||||||
let ipv4_mode = interface.ipv4 ? interface.ipv4.addressing : 'none';
|
return this.is_single_config(interface) ? [ name ] : [ name + '_4', name + '_6' ];
|
||||||
let ipv6_mode = interface.ipv6 ? interface.ipv6.addressing : 'none';
|
},
|
||||||
|
|
||||||
return (
|
calculate_ipv4_name: function(interface) {
|
||||||
(ipv4_mode == 'none') || (ipv6_mode == 'none') ||
|
let name = this.calculate_name(interface);
|
||||||
(ipv4_mode == 'static' && ipv6_mode == 'static')
|
|
||||||
) ? [ name ] : [ name + '_4', name + '_6' ];
|
return this.is_single_config(interface) ? name : name + '_4';
|
||||||
|
},
|
||||||
|
|
||||||
|
calculate_ipv6_name: function(interface) {
|
||||||
|
let name = this.calculate_name(interface);
|
||||||
|
|
||||||
|
return this.is_single_config(interface) ? name : name + '_6';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{%
|
{%
|
||||||
|
let has_downstream_relays = false;
|
||||||
|
|
||||||
// Skip interfaces previously marked as conflicting.
|
// Skip interfaces previously marked as conflicting.
|
||||||
if (interface.conflicting) {
|
if (interface.conflicting) {
|
||||||
warn("Skipping conflicting interface declaration");
|
warn("Skipping conflicting interface declaration");
|
||||||
@@ -22,6 +24,12 @@
|
|||||||
warn("Multiple interfaces with same role and VLAN ID defined, ignoring conflicting interface");
|
warn("Multiple interfaces with same role and VLAN ID defined, ignoring conflicting interface");
|
||||||
other_interface.conflicting = true;
|
other_interface.conflicting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (other_interface.role == 'downstream' &&
|
||||||
|
other_interface.ipv6 &&
|
||||||
|
other_interface.ipv6.dhcpv6 &&
|
||||||
|
other_interface.ipv6.dhcpv6.mode == 'relay')
|
||||||
|
has_downstream_relays = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a downstream interface with a vlan has a matching upstream interface
|
// check if a downstream interface with a vlan has a matching upstream interface
|
||||||
@@ -58,10 +66,6 @@
|
|||||||
// two logical interfaces due to different protocols.
|
// two logical interfaces due to different protocols.
|
||||||
let ipv4_mode = interface.ipv4 ? interface.ipv4.addressing : 'none';
|
let ipv4_mode = interface.ipv4 ? interface.ipv4.addressing : 'none';
|
||||||
let ipv6_mode = interface.ipv6 ? interface.ipv6.addressing : 'none';
|
let ipv6_mode = interface.ipv6 ? interface.ipv6.addressing : 'none';
|
||||||
let use_automatic = (
|
|
||||||
(ipv4_mode == 'none') || (ipv6_mode == 'none') ||
|
|
||||||
(ipv4_mode == 'static' && ipv6_mode == 'static')
|
|
||||||
);
|
|
||||||
|
|
||||||
// If no metric is defined explicitly, any upstream interfaces will default
|
// If no metric is defined explicitly, any upstream interfaces will default
|
||||||
// to 5 and downstream interfaces will default to 10
|
// to 5 and downstream interfaces will default to 10
|
||||||
@@ -91,19 +95,21 @@
|
|||||||
// All none L2/3 tunnel require a vlan inside their bridge
|
// All none L2/3 tunnel require a vlan inside their bridge
|
||||||
include("interface/bridge-vlan.uc", { interface, name, eth_ports, this_vid, bridgedev });
|
include("interface/bridge-vlan.uc", { interface, name, eth_ports, this_vid, bridgedev });
|
||||||
|
|
||||||
if (use_automatic) {
|
include("interface/common.uc", {
|
||||||
include("interface/ip-auto.uc", { interface, name, this_vid, location, netdev, ipv4_mode, ipv6_mode });
|
name, this_vid, netdev,
|
||||||
} else {
|
ipv4_mode, ipv4: interface.ipv4 || {},
|
||||||
if (ipv4_mode != 'none')
|
ipv6_mode, ipv6: interface.ipv6 || {}
|
||||||
include("interface/ipv4.uc", { interface, name, this_vid, location, netdev, ipv4_mode });
|
});
|
||||||
if (ipv6_mode != 'none')
|
|
||||||
include("interface/ipv6.uc", { interface, name, this_vid, location, netdev, ipv6_mode });
|
|
||||||
}
|
|
||||||
|
|
||||||
include('interface/firewall.uc');
|
include('interface/firewall.uc');
|
||||||
|
|
||||||
if (interface.ipv4)
|
if (interface.ipv4 || interface.ipv6) {
|
||||||
include('interface/dhcp.uc');
|
include('interface/dhcp.uc', {
|
||||||
|
ipv4: interface.ipv4 || {},
|
||||||
|
ipv6: interface.ipv6 || {},
|
||||||
|
has_downstream_relays
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (let i, ssid in interface.ssids) {
|
for (let i, ssid in interface.ssids) {
|
||||||
|
|||||||
29
renderer/templates/interface/common.uc
Normal file
29
renderer/templates/interface/common.uc
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% let afnames = ethernet.calculate_names(interface) %}
|
||||||
|
{% for (let afidx, afname in afnames): %}
|
||||||
|
set network.{{ afname }}=interface
|
||||||
|
set network.{{ afname }}.ucentral_name={{ s(interface.name) }}
|
||||||
|
set network.{{ afname }}.ucentral_path={{ s(location) }}
|
||||||
|
set network.{{ afname }}.ifname={{ netdev }}
|
||||||
|
set network.{{ afname }}.metric={{ interface.metric }}
|
||||||
|
set network.{{ afname }}.type={{ interface.type }}
|
||||||
|
{% if (ipv4_mode == 'static' || ipv6_mode == 'static'): %}
|
||||||
|
set network.{{ afname }}.proto=static
|
||||||
|
{% elif ((length(afnames) == 1 || afidx == 0) && ipv4_mode == 'dynamic'): %}
|
||||||
|
set network.{{ afname }}.proto=dhcp
|
||||||
|
{% elif ((length(afnames) == 1 || afidx == 1) && ipv6_mode == 'dynamic'): %}
|
||||||
|
set network.{{ afname }}.proto=dhcpv6
|
||||||
|
{% else %}
|
||||||
|
set network.{{ afname }}.proto=none
|
||||||
|
{% endif %}
|
||||||
|
{% if (interface.role == "downstream" && interface.vlan): %}
|
||||||
|
add network rule
|
||||||
|
set network.@rule[-1].in={{ afname }}
|
||||||
|
set network.@rule[-1].lookup={{ interface.vlan.id }}
|
||||||
|
{% endif %}
|
||||||
|
{% if ((length(afnames) == 1 && ipv4_mode != 'none') || (afidx == 0 && ipv4_mode != 'none')): %}
|
||||||
|
{% include('ipv4.uc', { name: afname }) %}
|
||||||
|
{% endif %}
|
||||||
|
{% if ((length(afnames) == 1 && ipv6_mode != 'none') || (afidx == 1 && ipv6_mode != 'none')): %}
|
||||||
|
{% include('ipv6.uc', { name: afname }) %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
@@ -1,11 +1,40 @@
|
|||||||
{% let name = ethernet.calculate_name(interface) %}
|
{% let name = ethernet.calculate_ipv4_name(interface) %}
|
||||||
{% let dhcp = interface.ipv4.dhcp || { ignore: 1 } %}
|
{% let dhcp = ipv4.dhcp || { ignore: 1 } %}
|
||||||
|
{% let dhcpv6 = ipv6.dhcpv6 || { ignore: 1 } %}
|
||||||
set dhcp.{{ name }}=dhcp
|
set dhcp.{{ name }}=dhcp
|
||||||
set dhcp.{{ name }}.interface={{ s(name) }}
|
set dhcp.{{ name }}.interface={{ s(name) }}
|
||||||
set dhcp.{{ name }}.start={{ dhcp.lease_first }}
|
set dhcp.{{ name }}.start={{ dhcp.lease_first }}
|
||||||
set dhcp.{{ name }}.limit={{ dhcp.lease_count }}
|
set dhcp.{{ name }}.limit={{ dhcp.lease_count }}
|
||||||
set dhcp.{{ name }}.leasetime={{ dhcp.lease_time }}
|
set dhcp.{{ name }}.leasetime={{ dhcp.lease_time }}
|
||||||
set dhcp.{{ name }}.ignore={{ b(dhcp.ignore) }}
|
set dhcp.{{ name }}.ignore={{ b(dhcp.ignore) }}
|
||||||
|
{% if (interface.role != 'upstream'): %}
|
||||||
|
{% if (dhcpv6.mode == 'hybrid'): %}
|
||||||
|
set dhcp.{{ name }}.ra=server
|
||||||
|
set dhcp.{{ name }}.dhcpv6=server
|
||||||
|
set dhcp.{{ name }}.ndp=disabled
|
||||||
|
{% elif (dhcpv6.mode == 'stateful'): %}
|
||||||
|
set dhcp.{{ name }}.ra=disabled
|
||||||
|
set dhcp.{{ name }}.dhcpv6=server
|
||||||
|
set dhcp.{{ name }}.ndp=disabled
|
||||||
|
{% elif (dhcpv6.mode == 'stateless'): %}
|
||||||
|
set dhcp.{{ name }}.ra=server
|
||||||
|
set dhcp.{{ name }}.dhcpv6=disabled
|
||||||
|
set dhcp.{{ name }}.ndp=disabled
|
||||||
|
{% elif (dhcpv6.mode == 'relay'): %}
|
||||||
|
set dhcp.{{ name }}.ra=relay
|
||||||
|
set dhcp.{{ name }}.dhcpv6=relay
|
||||||
|
set dhcp.{{ name }}.ndp=relay
|
||||||
|
{% else %}
|
||||||
|
set dhcp.{{ name }}.ra=disabled
|
||||||
|
set dhcp.{{ name }}.dhcpv6=disabled
|
||||||
|
set dhcp.{{ name }}.ndp=disabled
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
set dhcp.{{ name }}.master={{ b(has_downstream_relays) }}
|
||||||
|
set dhcp.{{ name }}.ra={{ has_downstream_relays ? 'relay' : 'disabled' }}
|
||||||
|
set dhcp.{{ name }}.dhcpv6={{ has_downstream_relays ? 'relay' : 'disabled' }}
|
||||||
|
set dhcp.{{ name }}.ndp={{ has_downstream_relays ? 'relay' : 'disabled' }}
|
||||||
|
{% endif %}
|
||||||
{% for (let lease in interface.ipv4.dhcp_leases): %}
|
{% for (let lease in interface.ipv4.dhcp_leases): %}
|
||||||
add dhcp host
|
add dhcp host
|
||||||
set dhcp.@host[-1].hostname={{ lease.hostname }}
|
set dhcp.@host[-1].hostname={{ lease.hostname }}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
set network.{{ name }}=interface
|
|
||||||
set network.{{ name }}.ucentral_name={{ s(interface.name) }}
|
|
||||||
set network.{{ name }}.ucentral_path={{ s(location) }}
|
|
||||||
set network.{{ name }}.ifname={{ netdev }}
|
|
||||||
set network.{{ name }}.metric={{ interface.metric }}
|
|
||||||
set network.{{ name }}.type={{ interface.type }}
|
|
||||||
{% if (ipv4_mode == 'none' && ipv6_mode == 'none'): %}
|
|
||||||
set network.{{ name }}.proto=none
|
|
||||||
{% elif (ipv4_mode == 'static'): %}
|
|
||||||
set network.{{ name }}.proto=static
|
|
||||||
set network.{{ name }}.ipaddr={{ ipcalc.generate_prefix(state, interface.ipv4.subnet) }}
|
|
||||||
{% elif (ipv6_mode == 'static'): %}
|
|
||||||
set network.{{ name }}.proto=static
|
|
||||||
set network.{{ name }}.ip6addr={{ ipcalc.generate_prefix(state, interface.ipv6.subnet) }}
|
|
||||||
{% elif (ipv4_mode == 'dynamic'): %}
|
|
||||||
set network.{{ name }}.proto=dhcp
|
|
||||||
{% for (let dns in interface.ipv4.use_dns): %}
|
|
||||||
add_list network.{{ name }}.dns={{ dns }}
|
|
||||||
{% endfor %}
|
|
||||||
set network.{{ name }}.peerdns={{ b(!length(interface.ipv4.use_dns)) }}
|
|
||||||
{% else %}
|
|
||||||
set network.{{ name }}.proto=dhcpv6
|
|
||||||
{% endif %}
|
|
||||||
{% if (interface.role == 'upstream' && interface.vlan): %}
|
|
||||||
set network.{{ name }}.ip4table={{ this_vid }}
|
|
||||||
set network.{{ name }}.ip6table={{ this_vid }}
|
|
||||||
{% endif %}
|
|
||||||
{% if (interface.role == "downstream" && interface.vlan): %}
|
|
||||||
add network rule
|
|
||||||
set network.@rule[-1].in={{ name }}
|
|
||||||
set network.@rule[-1].lookup={{ interface.vlan.id }}
|
|
||||||
{% endif %}
|
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
set network.{{name}}=interface_4
|
|
||||||
set network.{{ name }}_4.ucentral_name={{ s(interface.name) }}
|
|
||||||
set network.{{ name }}_4.ucentral_path={{ s(location) }}
|
|
||||||
set network.{{ name }}_4.ifname={{ netdev }}
|
|
||||||
set network.{{ name }}_4.metric={{ interface.metric }}
|
|
||||||
{% if (interface.role == 'upstream' && interface.vlan): %}
|
{% if (interface.role == 'upstream' && interface.vlan): %}
|
||||||
set network.{{ name }}_4.ip4table={{ this_vid }}
|
set network.{{ name }}.ip4table={{ this_vid }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if (ipv4_mode == 'static'): %}
|
{% if (ipv4_mode == 'static'): %}
|
||||||
set network.{{ name }}_4.proto=static
|
set network.{{ name }}.ipaddr={{ ipcalc.generate_prefix(state, ipv4.subnet, false) }}
|
||||||
set network.{{ name }}_4.ipaddr={{ ipcalc.generate_prefix(state, interface.ipv4.subnet) }}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
set network.{{ name }}_4.proto=dhcp
|
set network.{{ name }}.peerdns={{ b(!length(ipv4.use_dns)) }}
|
||||||
{% endif %}
|
{% for (let dns in ipv4.use_dns): %}
|
||||||
|
add_list network.{{ name }}.dns={{ dns }}
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
set network.{{name}}=interface_6
|
|
||||||
set network.{{ name }}_6.ucentral_name={{ s(interface.name) }}
|
|
||||||
set network.{{ name }}_6.ucentral_path={{ s(location) }}
|
|
||||||
set network.{{ name }}_6.ifname={{ netdev }}
|
|
||||||
set network.{{ name }}_6.metric={{ interface.metric }}
|
|
||||||
{% if (interface.role == 'upstream' && interface.vlan): %}
|
{% if (interface.role == 'upstream' && interface.vlan): %}
|
||||||
set network.{{ name }}_6.ip6table={{ this_vid }}
|
set network.{{ name }}.ip6table={{ this_vid }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if (ipv6_mode == 'static'): %}
|
{% if (ipv6_mode == 'static'): %}
|
||||||
set network.{{ name }}_6.proto=static
|
set network.{{ name }}.ip6addr={{ ipcalc.generate_prefix(state, ipv6.subnet, true) }}
|
||||||
set network.{{ name }}_6.ipaddr={{ ipcalc.generate_prefix(state, interface.ipv6.subnet) }}
|
set network.{{ name }}.ip6gw={{ ipv6.gateway }}
|
||||||
|
set network.{{ name }}.ip6assign={{ ipv6.prefix_size }}
|
||||||
{% else %}
|
{% else %}
|
||||||
set network.{{ name }}_6.proto=dhcp
|
set network.{{ name }}.reqprefix={{ ipv6.prefix_size || 'auto' }}
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user