libkvm - Add ability to access userspace from kgdb on cores
[dragonfly.git] / usr.sbin / setkey / scriptdump.pl
blob0ea15e70166cdaae3ee1e11725b8e0579e66d06c
1 #! @LOCALPREFIX@/bin/perl
2 # $FreeBSD: src/usr.sbin/setkey/scriptdump.pl,v 1.1.2.3 2001/10/24 19:49:16 ume Exp $
3 # $DragonFly: src/usr.sbin/setkey/scriptdump.pl,v 1.2 2003/06/17 04:30:03 dillon Exp $
5 if ($< != 0) {
6 print STDERR "must be root to invoke this\n";
7 exit 1;
10 $mode = 'add';
11 while ($i = shift @ARGV) {
12 if ($i eq '-d') {
13 $mode = 'delete';
14 } else {
15 print STDERR "usage: scriptdump [-d]\n";
16 exit 1;
20 open(IN, "setkey -D |") || die;
21 foreach $_ (<IN>) {
22 if (/^[^\t]/) {
23 ($src, $dst) = split(/\s+/, $_);
24 } elsif (/^\t(esp|ah) mode=(\S+) spi=(\d+).*reqid=(\d+)/) {
25 ($proto, $ipsecmode, $spi, $reqid) = ($1, $2, $3, $4);
26 } elsif (/^\tE: (\S+) (.*)/) {
27 $ealgo = $1;
28 $ekey = $2;
29 $ekey =~ s/\s//g;
30 $ekey =~ s/^/0x/g;
31 } elsif (/^\tA: (\S+) (.*)/) {
32 $aalgo = $1;
33 $akey = $2;
34 $akey =~ s/\s//g;
35 $akey =~ s/^/0x/g;
36 } elsif (/^\tseq=(0x\d+) replay=(\d+) flags=(0x\d+) state=/) {
37 print "$mode $src $dst $proto $spi";
38 $replay = $2;
39 print " -u $reqid" if $reqid;
40 if ($mode eq 'add') {
41 print " -m $ipsecmode -r $replay" if $replay;
42 if ($proto eq 'esp') {
43 print " -E $ealgo $ekey" if $ealgo;
44 print " -A $aalgo $akey" if $aalgo;
45 } elsif ($proto eq 'ah') {
46 print " -A $aalgo $akey" if $aalgo;
49 print ";\n";
51 $src = $dst = $upper = $proxy = '';
52 $ealgo = $ekey = $aalgo = $akey = '';
55 close(IN);
57 exit 0;