Fwctl/Services/ipsec.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 102 CC 10 SCAR 30.9
CC
10
Cov
0%
accept_rules
42.0
account_rules
30.0
new
2.0
CRAP 22.0
1 #
2 # pptp.pm: Fwctl service module to handle the IPSec service over ESP.
3 #
4 # This file is part of Fwctl.
5 #
6 # Author: Francis J. Lacoste <francis@iNsu.COM>
7 #
8 # Copyright (c) 1999,2000 iNsu Innovations Inc.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 package Fwctl::Services::ipsec;
16  
17 use strict;
18  
19 use Fwctl::RuleSet qw(:udp_rulesets :ip_rulesets :masq );
20 use IPChains;
21 use Carp;
22  
23 sub new {
24 my $proto = shift;
25 my $class = ref $proto || $proto;
26 bless {}, $class;
27 }
28  
29 sub prototypes {
30 my ($self,$target,$options) = @_;
31  
32 # Build prototype rule
33 (
34 IPChains->new(
35 Rule => $target,
36 Prot => 'udp',
37 SourcePort => 500,
38 DestPort => 500, # ISAKMP
39 %{$options->{ipchains}},
40 ),
41 IPChains->new(
42 Rule => $target,
43 Prot => 50, # ESP
44 %{$options->{ipchains}},
45 ),
46 );
47 }
48  
49 sub block_rules {
50 my $self = shift;
51 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
52  
53 my ($control,$esp) = $self->prototypes( $target, $options );
54  
55 block_udp_ruleset( $control, $src, $src_if, $dst, $dst_if );
56 block_ip_ruleset( $esp, $src, $src_if, $dst, $dst_if );
57 block_ip_ruleset( $esp, $dst, $dst_if, $src, $src_if );
58 }
59  
60 sub accept_rules {
61 my $self = shift;
62 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
63  
64 my ($control, $esp ) = $self->prototypes( $target, $options );
65  
66 my $masq = defined $options->{portfw} ? PORTFW :
67 $options->{masq} ? MASQ : NOMASQ;
68  
69 accept_udp_ruleset( $control, $src, $src_if, $dst, $dst_if,
70 $masq, $options->{portfw} );
71 accept_ip_ruleset( $esp, $src, $src_if, $dst, $dst_if,
72 $masq, $options->{portfw} );
73  
74 if ( $masq & MASQ ) {
75 $masq &= $masq ^ MASQ;
76 $masq |= UNMASQ;
77 } elsif ( $masq & PORTFW ) {
78 $masq &= $masq ^ PORTFW;
79 $masq |= UNPORTFW;
80 }
81 accept_ip_ruleset( $esp, $dst, $dst_if, $src, $src_if,
82 $masq, $options->{portfw} );
83  
84 if ($options->{masq} || $options->{portfw} ) {
85 system ( "/sbin/modprobe", "ip_masq_ipsec" ) == 0
86 or carp __PACKAGE__, ": couldn't load ip_masq_ipsec: $?\n";
87 }
88 }
89  
90 sub account_rules {
91 my $self = shift;
92 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
93  
94 my ( $control, $esp ) = $self->prototypes( $target, $options );
95  
96 my $masq = defined $options->{portfw} ? PORTFW :
97 $options->{masq} ? MASQ : NOMASQ;
98  
99 acct_udp_ruleset( $control, $src, $src_if, $dst, $dst_if,
100 $masq, $options->{portfw} );
101 acct_ip_ruleset( $esp, $src, $src_if, $dst, $dst_if,
102 $masq, $options->{portfw} );
103  
104 if ( $masq & MASQ ) {
105 $masq &= $masq ^ MASQ;
106 $masq |= UNMASQ;
107 } elsif ( $masq & PORTFW ) {
108 $masq &= $masq ^ PORTFW;
109 $masq |= UNPORTFW;
110 }
111 acct_ip_ruleset( $esp, $dst, $dst_if, $src, $src_if,
112 $masq, $options->{portfw} );
113  
114 }
115  
116 sub valid_options {
117 my $self = shift;
118 ( );
119 }
120  
121 1;
122 =pod
123  
124 =head1 NAME
125  
126 Fwctl::Services::ipsec - Fwctl module to handle the IPSec protocol.
127  
128 =head1 SYNOPSIS
129  
130 accept ipsec -src INT_NET -dst REMOTE_IPSEC
131  
132 =head1 DESCRIPTION
133  
134 This module will implements the rules to accept/block/account the IPSec
135 tunnelling protocol. In order to be able to masquerade that protocol, you
136 will need a kernel with the IPSec masquerade patch applied.
137  
138 See ftp://ftp.rubyriver.com/pub/jhardin/masquerade/ for informations.
139  
140 =head1 AUTHOR
141  
142 Francis J. Lacoste <francis.lacoste@iNsu.COM>
143  
144 =head1 COPYRIGHT
145  
146 Copyright (c) 1999,2000 iNsu Innovations Inc.
147 All rights reserved.
148  
149 This program is free software; you can redistribute it and/or modify
150 it under the terms of the GNU General Public License as published by
151 the Free Software Foundation; either version 2 of the License, or
152 (at your option) any later version.
153  
154 =head1 SEE ALSO
155  
156 fwctl(8) Fwctl(3) Fwctl::RuleSet(3)
157  
158 =cut
159