summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-02-03 19:21:44 -0600
committerJohn Southworth <john.southworth@vyatta.com>2011-02-03 19:21:44 -0600
commit5db06eea839ef18cc090570af0227059c3bd51b7 (patch)
tree6151a6f5a5a53965ba66364a752a5918c19c6f0f /lib
parent8886c248e9bbbd4fb102870a628ab187a9f45d79 (diff)
downloadvyatta-cfg-vpn-5db06eea839ef18cc090570af0227059c3bd51b7.tar.gz
vyatta-cfg-vpn-5db06eea839ef18cc090570af0227059c3bd51b7.zip
Initial additions to support local and remote protoport in general instead of just for GRE
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Vyatta/VPN/Util.pm45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/Vyatta/VPN/Util.pm b/lib/Vyatta/VPN/Util.pm
index e57d5f9..23ba63d 100755
--- a/lib/Vyatta/VPN/Util.pm
+++ b/lib/Vyatta/VPN/Util.pm
@@ -27,7 +27,7 @@ use strict;
use warnings;
our @EXPORT = qw(rsa_get_local_key_file LOCAL_KEY_FILE_DEFAULT rsa_get_local_pubkey
- is_vpn_running vpn_debug enableICMP);
+ is_vpn_running vpn_debug enableICMP is_tcp_udp get_protocols conv_protocol);
use base qw(Exporter);
use Vyatta::Config;
@@ -40,6 +40,49 @@ sub is_vpn_running {
return ( -e '/var/run/pluto.ctl');
}
+sub get_protocols {
+ my $cmd = "sudo cat /etc/protocols |";
+ open(PROTOCOLS, $cmd);
+ my @protocols = [];
+ while(<PROTOCOLS>){
+ push (@protocols, $_);
+ }
+ my %protohash = ();
+ foreach my $line (@protocols) {
+ next if ($line =~ /^\#/);
+ if ($line =~ /(\S+)\s+(\d+)\s+(\S+)\s+\#(.*)/){
+ my ($name, $number, $desc) = ($1,$2,$4);
+ if (not exists $protohash{$number}){
+ $protohash{$number} = {
+ _name => $name,
+ _number => $number,
+ _desc => $desc
+ };
+ }
+ }
+ }
+ return %protohash;
+}
+
+sub conv_protocol {
+ my $proto = pop(@_);
+ my %protohash = get_protocols();
+ foreach my $key (keys %protohash){
+ if ("$key" == "$proto") {
+ return $protohash{$key}->{_name};
+ }
+ }
+ return $proto;
+}
+
+
+sub is_tcp_udp {
+ my $protocol = pop @_;
+ return 1 if (($protocol eq '6') || ($protocol eq 'tcp') ||
+ ($protocol eq '17') || ($protocol eq 'udp'));
+ return 0;
+}
+
sub rsa_get_local_key_file {
my $file = LOCAL_KEY_FILE_DEFAULT;