scriptdump.pl (55505) | scriptdump.pl (62583) |
---|---|
1#! @LOCALPREFIX@/bin/perl | 1#! @LOCALPREFIX@/bin/perl |
2# $FreeBSD: head/sbin/setkey/scriptdump.pl 55505 2000-01-06 12:40:54Z shin $ | 2# $FreeBSD: head/sbin/setkey/scriptdump.pl 62583 2000-07-04 16:22:05Z itojun $ |
3 4if ($< != 0) { 5 print STDERR "must be root to invoke this\n"; 6 exit 1; 7} 8 9$mode = 'add'; 10while ($i = shift @ARGV) { --- 4 unchanged lines hidden (view full) --- 15 exit 1; 16 } 17} 18 19open(IN, "setkey -D |") || die; 20foreach $_ (<IN>) { 21 if (/^[^\t]/) { 22 ($src, $dst) = split(/\s+/, $_); | 3 4if ($< != 0) { 5 print STDERR "must be root to invoke this\n"; 6 exit 1; 7} 8 9$mode = 'add'; 10while ($i = shift @ARGV) { --- 4 unchanged lines hidden (view full) --- 15 exit 1; 16 } 17} 18 19open(IN, "setkey -D |") || die; 20foreach $_ (<IN>) { 21 if (/^[^\t]/) { 22 ($src, $dst) = split(/\s+/, $_); |
23 } elsif (/^\t(esp|ah) mode=(\S+) spi=(\d+).*replay=(\d+)/) { 24 ($proto, $ipsecmode, $spi, $replay) = ($1, $2, $3, $4); | 23 } elsif (/^\t(esp|ah) mode=(\S+) spi=(\d+).*reqid=(\d+)/) { 24 ($proto, $ipsecmode, $spi, $reqid) = ($1, $2, $3, $4); |
25 } elsif (/^\tE: (\S+) (.*)/) { 26 $ealgo = $1; 27 $ekey = $2; 28 $ekey =~ s/\s//g; 29 $ekey =~ s/^/0x/g; 30 } elsif (/^\tA: (\S+) (.*)/) { 31 $aalgo = $1; 32 $akey = $2; 33 $akey =~ s/\s//g; 34 $akey =~ s/^/0x/g; | 25 } elsif (/^\tE: (\S+) (.*)/) { 26 $ealgo = $1; 27 $ekey = $2; 28 $ekey =~ s/\s//g; 29 $ekey =~ s/^/0x/g; 30 } elsif (/^\tA: (\S+) (.*)/) { 31 $aalgo = $1; 32 $akey = $2; 33 $akey =~ s/\s//g; 34 $akey =~ s/^/0x/g; |
35 } elsif (/^\tstate=/) { | 35 } elsif (/^\treplay=(\d+) flags=(0x\d+) state=/) { |
36 print "$mode $src $dst $proto $spi -m $ipsecmode"; | 36 print "$mode $src $dst $proto $spi -m $ipsecmode"; |
37 print " -r $replay" if $replay; | 37 $replay = $1; 38 print " -u $reqid" if $reqid; |
38 if ($mode eq 'add') { | 39 if ($mode eq 'add') { |
40 print " -r $replay" if $replay; |
|
39 if ($proto eq 'esp') { 40 print " -E $ealgo $ekey" if $ealgo; 41 print " -A $aalgo $akey" if $aalgo; 42 } elsif ($proto eq 'ah') { 43 print " -A $aalgo $akey" if $aalgo; 44 } | 41 if ($proto eq 'esp') { 42 print " -E $ealgo $ekey" if $ealgo; 43 print " -A $aalgo $akey" if $aalgo; 44 } elsif ($proto eq 'ah') { 45 print " -A $aalgo $akey" if $aalgo; 46 } |
45 } | 47 } |
46 print ";\n"; 47 48 $src = $dst = $upper = $proxy = ''; 49 $ealgo = $ekey = $aalgo = $akey = ''; 50 } 51} 52close(IN); 53 54exit 0; | 48 print ";\n"; 49 50 $src = $dst = $upper = $proxy = ''; 51 $ealgo = $ekey = $aalgo = $akey = ''; 52 } 53} 54close(IN); 55 56exit 0; |