|
@@ -36,33 +36,60 @@ uci:section('fastd', 'fastd', 'mesh_vpn',
|
|
|
)
|
|
|
uci:delete('fastd', 'mesh_vpn', 'user')
|
|
|
|
|
|
-uci:delete('fastd', 'mesh_vpn_backbone')
|
|
|
-uci:section('fastd', 'peer_group', 'mesh_vpn_backbone',
|
|
|
- {
|
|
|
- enabled = 1,
|
|
|
- net = 'mesh_vpn',
|
|
|
- peer_limit = site.fastd_mesh_vpn.backbone.limit,
|
|
|
- }
|
|
|
-)
|
|
|
|
|
|
-uci:delete_all('fastd', 'peer',
|
|
|
- function(peer)
|
|
|
- return peer.net == 'mesh_vpn' and peer.group == 'mesh_vpn_backbone'
|
|
|
- end
|
|
|
-)
|
|
|
+local add_groups
|
|
|
+
|
|
|
+local function add_peer(group, name, config)
|
|
|
+ uci:section('fastd', 'peer', group .. '_peer_' .. name,
|
|
|
+ {
|
|
|
+ enabled = 1,
|
|
|
+ net = 'mesh_vpn',
|
|
|
+ group = group,
|
|
|
+ key = config.key,
|
|
|
+ remote = config.remotes,
|
|
|
+ }
|
|
|
+ )
|
|
|
+end
|
|
|
|
|
|
-for name, config in pairs(site.fastd_mesh_vpn.backbone.peers) do
|
|
|
- uci:section('fastd', 'peer', 'mesh_vpn_backbone_peer_' .. name,
|
|
|
- {
|
|
|
- enabled = 1,
|
|
|
- net = 'mesh_vpn',
|
|
|
- group = 'mesh_vpn_backbone',
|
|
|
- key = config.key,
|
|
|
- remote = config.remotes,
|
|
|
- }
|
|
|
- )
|
|
|
+local function add_group(name, config, parent)
|
|
|
+ uci:delete('fastd', name)
|
|
|
+ uci:delete_all('fastd', 'peer',
|
|
|
+ function(peer)
|
|
|
+ return (peer.net == 'mesh_vpn' and peer.group == name)
|
|
|
+ end
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+ uci:section('fastd', 'peer_group', name,
|
|
|
+ {
|
|
|
+ enabled = 1,
|
|
|
+ net = 'mesh_vpn',
|
|
|
+ parent = parent,
|
|
|
+ peer_limit = config.limit,
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if config.peers then
|
|
|
+ for peername, peerconfig in pairs(config.peers) do
|
|
|
+ add_peer(name, peername, peerconfig)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ add_groups(name, config.groups, name)
|
|
|
end
|
|
|
|
|
|
+-- declared local above
|
|
|
+function add_groups(prefix, groups, parent)
|
|
|
+ if groups then
|
|
|
+ for name, group in pairs(groups) do
|
|
|
+ add_group(prefix .. '_' .. name, group, parent)
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+add_groups('mesh_vpn', site.fastd_mesh_vpn.groups)
|
|
|
+
|
|
|
+
|
|
|
uci:save('fastd')
|
|
|
uci:commit('fastd')
|
|
|
|