From 5db06eea839ef18cc090570af0227059c3bd51b7 Mon Sep 17 00:00:00 2001 From: John Southworth Date: Thu, 3 Feb 2011 19:21:44 -0600 Subject: Initial additions to support local and remote protoport in general instead of just for GRE --- lib/Vyatta/VPN/Util.pm | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'lib') 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(){ + 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; -- cgit v1.2.3