Fwctl/Services/snmp.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 79 CC 8 SCAR 23.9
CC
8
Cov
0%
accept_rules
20.0
account_rules
20.0
block_rules
6.0
CRAP 10.9
1 #
2 # snmp.pm: Fwctl service module to handle the snmp protocol.
3 #
4 # This file is part of Fwctl.
5 #
6 # Author: Francis J. Lacoste <francis.lacoste@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::snmp;
16  
17 use strict;
18  
19 use Fwctl::RuleSet qw( :ip_rulesets :udp_rulesets :masq :ports);
20 use Net::IPv4Addr qw(ipv4_in_network);
21 use IPChains;
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 DestPort => 'snmp',
38 %{$options->{ipchains}},
39 ),
40 IPChains->new(
41 Rule => $target,
42 Prot => 'udp',
43 SourcePort => 'snmp',
44 DestPort => 'snmp-trap',
45 %{$options->{ipchains}},
46 ),
47 );
48 }
49  
50 sub block_rules {
51 my $self = shift;
52 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
53  
54  
55 my ($snmp,$trap) = $self->prototypes( $target, $options );
56 if ( ipv4_in_network( $src, $dst ) ) {
57 block_ip_ruleset( $snmp, $src, $src_if, $src_if->{broadcast}, $dst_if );
58 }
59 block_udp_ruleset( $snmp, $src, $src_if, $dst, $dst_if );
60 block_ip_ruleset( $trap, $dst, $dst_if, $src, $src_if );
61 }
62  
63 sub accept_rules {
64 my $self = shift;
65 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
66  
67 my ($snmp,$trap) = $self->prototypes( $target, $options );
68 my $masq = defined $options->{portfw} ? PORTFW :
69 $options->{masq} ? MASQ : NOMASQ;
70  
71 if ( ipv4_in_network( $src, $dst ) ) {
72 accept_ip_ruleset( $snmp, $src, $src_if, $src_if->{broadcast}, $dst_if,
73 $masq, $options->{portfw} );
74 }
75 accept_udp_ruleset( $snmp, $src, $src_if, $dst, $dst_if,
76 $masq, $options->{portfw} );
77  
78 accept_ip_ruleset( $trap, $dst, $dst_if, $src, $src_if,
79 $masq, $options->{portfw} );
80 }
81  
82 sub account_rules {
83 my $self = shift;
84 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
85  
86 my ($snmp,$trap) = $self->prototypes( $target, $options );
87 my $masq = defined $options->{portfw} ? PORTFW :
88 $options->{masq} ? MASQ : NOMASQ;
89  
90 if ( ipv4_in_network( $src, $dst ) ) {
91 acct_ip_ruleset( $snmp, $src, $src_if, $src_if->{broadcast}, $dst_if,
92 $masq, $options->{portfw} );
93 }
94 acct_udp_ruleset( $snmp, $src, $src_if, $dst, $dst_if,
95 $masq, $options->{portfw} );
96 acct_ip_ruleset( $trap, $dst, $dst_if, $src, $src_if,
97 $masq, $options->{portfw} );
98 }
99  
100 sub valid_options {
101 my $self = shift;
102 ( );
103 }
104  
105 1;
106  
107 =pod
108  
109 =head1 NAME
110  
111 Fwctl::Services::snmp - Fwctl module to handle the snmp protocol.
112  
113 =head1 SYNOPSIS
114  
115 accept snmp -src INTERNAL_NET -dst PERIM_NET
116 deny snmp -src INTERNAL_NET -nolog
117 account snmp
118  
119 =head1 DESCRIPTION
120  
121 This module handles the SNMP protocol. Its handles SNMP broadcast
122 if dst is in the same network as src, SNMP traffic between source
123 and destination, as well as snmp-trap from destination to source.
124  
125 Since I don't really know the internals of the SNMP protocol this
126 could be totally broken. Use only to reduce log file clutter.
127  
128 =head1 AUTHOR
129  
130 Francis J. Lacoste <francis.lacoste@iNsu.COM>
131  
132 =head1 COPYRIGHT
133  
134 Copyright (c) 1999,2000 iNsu Innovations Inc.
135 All rights reserved.
136  
137 This program is free software; you can redistribute it and/or modify
138 it under the terms of the GNU General Public License as published by
139 the Free Software Foundation; either version 2 of the License, or
140 (at your option) any later version.
141  
142 =head1 SEE ALSO
143  
144 fwctl(8) Fwctl(3) Fwctl::RuleSet(3)
145  
146 =cut
147