mirror of https://github.com/aredn/aredn.git
feature: adding support to add tun interfaces dynamically to olsrd
This commit is contained in:
parent
8aa7b84712
commit
cc1f683121
|
@ -94,31 +94,23 @@ sub is_tunnel_active()
|
|||
}
|
||||
|
||||
##########################
|
||||
# Add OLSRD interfaces - called when adding a new client connection
|
||||
# Add OLSRD interfaces
|
||||
##########################
|
||||
sub add_olsrd_interface() {
|
||||
my ($tunnum) = @_;
|
||||
# uci add_list olsrd.interface=vpn${tunnumber}
|
||||
# uci commit vtundsrv
|
||||
sub add_olsrd_interfaces() {
|
||||
my ($tunstart,$tuncount) = @_;
|
||||
|
||||
#config Interface
|
||||
# list interface 'vpn50 vpn51 vpn52 vpn53 vpn54 vpn55 vpn56 vpn57 vpn58 vpn59'
|
||||
# option Ip4Broadcast 255.255.255.255
|
||||
&uci_add_named_section("olsrd","tunnelserver","Interface");
|
||||
|
||||
&uci_set_named_option("olsrd","tunnelserver","Ip4Broadcast","255.255.255.255");
|
||||
|
||||
# delete all interfaces first
|
||||
&uci_delete_named_option("olsrd","tunnelserver","interfaces");
|
||||
|
||||
for (my $i=$tunstart, $i<$tuncount, $i++) {
|
||||
&uci_add_list_named_option("olsrd","tunnelserver","interfaces","tun${i}");
|
||||
}
|
||||
|
||||
|
||||
##########################
|
||||
# Delete OLSRD interfaces - called when deleting a new client connection
|
||||
##########################
|
||||
sub del_olsrd_interface() {
|
||||
my ($tunnum) = @_;
|
||||
# uci delete_list olsrd.interface.vpn${tunnumber}
|
||||
# uci commit vtundsrv
|
||||
|
||||
#config Interface
|
||||
# list interface 'vpn50 vpn51 vpn52 vpn53 vpn54 vpn55 vpn56 vpn57 vpn58 vpn59'
|
||||
# option Ip4Broadcast 255.255.255.255
|
||||
&uci_commit("olsrd");
|
||||
}
|
||||
|
||||
##########################
|
||||
|
@ -128,21 +120,11 @@ sub add_network_interfaces() {
|
|||
|
||||
for (my $tunnum=50; $tunnum<=69; $tunnum++)
|
||||
{
|
||||
system "uci set network.tun${tunnum}=interface";
|
||||
system "uci set network.tun${tunnum}.ifname='tun${tunnum}'";
|
||||
system "uci set network.tun${tunnum}.proto='none'";
|
||||
&uci_add_named_section("network","tun${tunnum}","interface");
|
||||
&uci_set_named_option("network","tun${tunnum}","ifname","tun${tunnum}");
|
||||
&uci_set_named_option("network","tun${tunnum}","proto","none");
|
||||
}
|
||||
system "uci commit network";
|
||||
}
|
||||
|
||||
##########################
|
||||
# Delete OLSRD interfaces - called when deleting a new client connection
|
||||
##########################
|
||||
sub del_olsrd_interface() {
|
||||
my ($tunnum) = @_;
|
||||
# uci delete_list olsrd.interface.vpn${tunnumber}
|
||||
# uci commit vtundsrv
|
||||
#
|
||||
&uci_commit("network");
|
||||
}
|
||||
|
||||
#################################
|
||||
|
@ -156,7 +138,7 @@ sub check_freespace()
|
|||
}
|
||||
|
||||
##########################
|
||||
# Config firewall to allow port 5525 on WAN interface
|
||||
# Config firewall to allow port 5525 on WAN interface - USE UCIFUNC LIB CALLS***********
|
||||
##########################
|
||||
sub open_5525_on_wan() {
|
||||
system "uci add firewall rule >/dev/null 2>&1";
|
||||
|
|
|
@ -116,6 +116,41 @@ sub uci_delete_option()
|
|||
chomp($res);
|
||||
return ($rc,$res);
|
||||
}
|
||||
|
||||
sub uci_add_list_named_option()
|
||||
{
|
||||
my ($config,$sname,$option,$val)=@_;
|
||||
my $cmd=sprintf('uci add_list %s.%s.%s=\'%s\'',$config,$sname,$option,$val);
|
||||
my $rc=$?;
|
||||
return ($rc);
|
||||
}
|
||||
|
||||
sub uci_delete_named_option()
|
||||
{
|
||||
my ($config,$sname,$option)=@_;
|
||||
my $cmd=sprintf('uci delete %s.%s.%s',$config,$sname,$option);
|
||||
my $rc=$?;
|
||||
return ($rc);
|
||||
}
|
||||
|
||||
sub uci_add_named_section()
|
||||
{
|
||||
my ($config,$sname,$stype)=@_;
|
||||
my $cmd=sprintf('uci set %s.%s=%s',$config,$sname,$stype);
|
||||
#uci set olsrd.tunnelserver=Interface
|
||||
my $rc=$?;
|
||||
return ($rc);
|
||||
}
|
||||
|
||||
sub uci_set_named_option()
|
||||
{
|
||||
my ($config,$sname,$option,$val)=@_;
|
||||
my $cmd=sprintf('uci set %s.%s.%s=%s',$config,$sname,$option,$val);
|
||||
#uci set olsrd.tunnelserver.Ip4Broadcast=255.255.255.255
|
||||
my $rc=$?;
|
||||
return ($rc);
|
||||
}
|
||||
|
||||
sub uci_set_indexed_option()
|
||||
{
|
||||
my ($config,$stype,$index,$option,$val)=@_;
|
||||
|
|
|
@ -197,6 +197,9 @@ if($parms{button_save} and not (@cli_err or @serv_err))
|
|||
}
|
||||
unless($debug == 3)
|
||||
{
|
||||
# Regenerate olsrd files and restart olsrd
|
||||
push(@errors,"Problem calling olsrd-config") if system "/usr/local/bin/olsrd-config > /dev/null 2>&1";
|
||||
push(@errors,"Problem restarting olsrd") if system "/etc/init.d/olsrd restart > /dev/null 2>&1";
|
||||
push(@errors,"Problem restaring vtundsrv") if system "/etc/init.d/vtundsrv restart > /dev/null 2>&1";
|
||||
}
|
||||
}
|
||||
|
@ -415,6 +418,8 @@ sub get_client_info()
|
|||
#################################
|
||||
sub save_clients()
|
||||
{
|
||||
my $enabled_count=0;
|
||||
|
||||
for ($i=0; $i < $parms{"client_num"}; $i++) {
|
||||
my $net = $parms{"client${i}_netip"};
|
||||
|
||||
|
@ -446,12 +451,11 @@ sub save_clients()
|
|||
$rc=&uci_set_indexed_option("vtun","client",$i,"node",$vtun_node_name);
|
||||
push(@cli_err,"Problem saving UCI vtun client name (#$i)") if $rc;
|
||||
|
||||
#foreach $var (qw(enabled name passwd))
|
||||
#{
|
||||
# $rc=&uci_set_indexed_option("vtun","client",$i,$var,$parms{"client${i}_$var"});
|
||||
# push(@cli_err,"Problem saving UCI vtun client (#$i)") if $rc;
|
||||
#}
|
||||
$enabled_count++ if $parms{"client${i}_enabled"};
|
||||
}
|
||||
|
||||
# add enabled interfaces to OLSRD
|
||||
&add_olsrd_interfaces(50,$enabled_count) if($enabled_count);
|
||||
}
|
||||
|
||||
#################################
|
||||
|
|
Loading…
Reference in New Issue