2013-09-30 19:29:52 +00:00
|
|
|
my $cfg = $CONFIG->{fastd_mesh_vpn};
|
|
|
|
my $backbone = $cfg->{backbone};
|
|
|
|
|
|
|
|
my $add_methods = '';
|
|
|
|
for (@{$cfg->{methods}}) {
|
2013-10-03 16:41:45 +00:00
|
|
|
$add_methods .= "uci add_list fastd.mesh_vpn.method='$_'\n";
|
2013-09-30 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $set_peer_limit;
|
|
|
|
if ($backbone->{limit}) {
|
2013-10-03 16:41:45 +00:00
|
|
|
$set_peer_limit = "uci_set fastd mesh_vpn_backbone peer_limit '$backbone->{limit}'\n";
|
2013-09-30 19:29:52 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-10-03 16:41:45 +00:00
|
|
|
$set_peer_limit = "uci_remove fastd mesh_vpn_backbone peer_limit\n";
|
2013-09-30 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print <<END;
|
|
|
|
#/bin/sh
|
|
|
|
|
2013-10-03 16:41:45 +00:00
|
|
|
. /lib/functions.sh
|
|
|
|
. /lib/gluon/functions/sysconfig.sh
|
2013-09-30 19:29:52 +00:00
|
|
|
|
2013-10-03 16:41:45 +00:00
|
|
|
uci_add fastd fastd mesh_vpn
|
|
|
|
|
|
|
|
uci_remove fastd mesh_vpn config
|
|
|
|
uci_remove fastd mesh_vpn config_peer_dir
|
|
|
|
|
|
|
|
uci_set fastd mesh_vpn syslog_level 'verbose'
|
|
|
|
uci_set fastd mesh_vpn interface 'mesh-vpn'
|
|
|
|
uci_set fastd mesh_vpn mode 'tap'
|
|
|
|
uci_set fastd mesh_vpn mtu '$cfg->{mtu}'
|
|
|
|
|
|
|
|
uci_remove fastd mesh_vpn method
|
2013-09-30 19:29:52 +00:00
|
|
|
$add_methods
|
2013-10-03 16:41:45 +00:00
|
|
|
|
|
|
|
uci_remove fastd mesh_vpn_backbone
|
|
|
|
uci_add fastd peer_group mesh_vpn_backbone
|
|
|
|
uci_set fastd mesh_vpn_backbone enabled '1'
|
|
|
|
uci_set fastd mesh_vpn_backbone net 'mesh_vpn'
|
2013-09-30 19:29:52 +00:00
|
|
|
$set_peer_limit
|
|
|
|
END
|
|
|
|
|
|
|
|
foreach my $name (sort keys %{$backbone->{peers}}) {
|
|
|
|
my $peer = $backbone->{peers}->{$name};
|
|
|
|
print <<EOF;
|
2013-10-03 16:41:45 +00:00
|
|
|
uci_remove fastd 'mesh_vpn_backbone_peer_$name'
|
|
|
|
uci_add fastd peer 'mesh_vpn_backbone_peer_$name'
|
|
|
|
uci_set fastd 'mesh_vpn_backbone_peer_$name' enabled '1'
|
|
|
|
uci_set fastd 'mesh_vpn_backbone_peer_$name' net 'mesh_vpn'
|
|
|
|
uci_set fastd 'mesh_vpn_backbone_peer_$name' group 'mesh_vpn_backbone'
|
|
|
|
uci_set fastd 'mesh_vpn_backbone_peer_$name' key '$peer->{key}'
|
2013-09-30 19:29:52 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
for (@{$peer->{remotes}}) {
|
2013-10-03 16:41:45 +00:00
|
|
|
print "uci add_list fastd.mesh_vpn_backbone_peer_$name.remote='$_'\n";
|
2013-09-30 19:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 16:41:45 +00:00
|
|
|
print <<'END';
|
2013-09-30 19:29:52 +00:00
|
|
|
|
2013-10-03 16:41:45 +00:00
|
|
|
uci_add network interface mesh_vpn
|
|
|
|
uci_set network mesh_vpn ifname 'mesh-vpn'
|
|
|
|
uci_set network mesh_vpn proto 'batadv'
|
|
|
|
uci_set network mesh_vpn mesh 'bat0'
|
2014-01-13 00:03:08 +00:00
|
|
|
uci_set network mesh_vpn mesh_no_rebroadcast '1'
|
2013-10-03 16:04:03 +00:00
|
|
|
|
2013-10-03 16:41:45 +00:00
|
|
|
mainaddr=$(sysconfig primary_mac)
|
|
|
|
oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS"
|
|
|
|
b2mask=0x02
|
|
|
|
vpnaddr=$(printf "%02x:%s:%s:%02x:%s:%s" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $6)
|
|
|
|
uci_set network mesh_vpn macaddr "$vpnaddr"
|
|
|
|
|
|
|
|
uci_commit fastd
|
|
|
|
uci_commit network
|
2013-09-30 19:29:52 +00:00
|
|
|
END
|