1#! /usr/pkg/bin/perl
2
3die "insufficient arguments" if (scalar(@ARGV) < 2);
4$src = $ARGV[0];
5$dst = $ARGV[1];
6$mode = 'transport';
7if (scalar(@ARGV) > 2) {
8	$mode = $ARGV[2];
9}
10
11open(OUT, "|setkey -c");
12if ($mode eq 'transport') {
13	print STDERR "install esp transport mode: $src -> $dst\n";
14	print OUT "spdadd $src $dst any -P out ipsec esp/transport//require;\n";
15	print OUT "spdadd $dst $src any -P in ipsec esp/transport//require;\n";
16} elsif ($mode eq 'delete') {
17	print STDERR "delete policy: $src -> $dst\n";
18	print OUT "spddelete $src $dst any -P out;\n";
19	print OUT "spddelete $dst $src any -P in;\n";
20}
21close(OUT);
22