| 1 | # | ||
| 2 | # dhcp.pm: Fwctl service module to handle the dhcp protocol. | ||
| 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::dhcp; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | |||
| 19 | use Fwctl::RuleSet qw(:ip_rulesets :ports); | ||
| 20 | use IPChains; | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $proto = shift; | ||
| 24 | my $class = ref $proto || $proto; | ||
| 25 | bless {}, $class; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub prototypes { | ||
| 29 | my ($self,$target,$options) = @_; | ||
| 30 | |||
| 31 | # Build prototype rule | ||
| 32 | ( | ||
| 33 | # Client | ||
| 34 | IPChains->new( | ||
| 35 | Rule => $target, | ||
| 36 | Prot => 'udp', | ||
| 37 | SourcePort => 'bootpc', | ||
| 38 | DestPort => 'bootps', | ||
| 39 | %{$options->{ipchains}}, | ||
| 40 | ), | ||
| 41 | # Server | ||
| 42 | IPChains->new( | ||
| 43 | Rule => $target, | ||
| 44 | Prot => 'udp', | ||
| 45 | SourcePort => 'bootps', | ||
| 46 | DestPort => 'bootpc', | ||
| 47 | %{$options->{ipchains}}, | ||
| 48 | ), | ||
| 49 | ); | ||
| 50 | } | ||
| 51 | |||
| 52 | sub block_rules { | ||
| 53 | my $self = shift; | ||
| 54 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 55 | |||
| 56 | my ($client,$server) = $self->prototypes( $target, $options ); | ||
| 57 | block_ip_ruleset( $client, "0.0.0.0", $src_if, "255.255.255.255", $dst_if ); | ||
| 58 | block_ip_ruleset( $server, $dst, $dst_if, "255.255.255.255", $src_if ); | ||
| 59 | block_ip_ruleset( $client, $src, $src_if, $dst, $dst_if ); | ||
| 60 | block_ip_ruleset( $client, $src, $src_if, "255.255.255.255", $dst_if ); | ||
| 61 | block_ip_ruleset( $server, $dst, $dst_if, $src, $src_if ); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub accept_rules { | ||
| 65 | my $self = shift; | ||
| 66 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 67 | |||
| 68 | my ($client,$server) = $self->prototypes( $target, $options ); | ||
| 69 | accept_ip_ruleset( $client, "0.0.0.0", $src_if, "255.255.255.255", $dst_if ); | ||
| 70 | accept_ip_ruleset( $server, $dst, $dst_if, "255.255.255.255", $src_if ); | ||
| 71 | accept_ip_ruleset( $client, $src, $src_if, $dst, $dst_if ); | ||
| 72 | accept_ip_ruleset( $client, $src, $src_if, "255.255.255.255", $dst_if ); | ||
| 73 | accept_ip_ruleset( $server, $dst, $dst_if, $src, $src_if ); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | sub account_rules { | ||
| 78 | my $self = shift; | ||
| 79 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 80 | |||
| 81 | my ($client,$server) = $self->prototypes( $target, $options ); | ||
| 82 | acct_ip_ruleset( $client, "0.0.0.0", $src_if, "255.255.255.255", $dst_if ); | ||
| 83 | acct_ip_ruleset( $server, $dst, $dst_if, "255.255.255.255", $src_if ); | ||
| 84 | acct_ip_ruleset( $client, $src, $src_if, $dst, $dst_if ); | ||
| 85 | acct_ip_ruleset( $client, $src, $src_if, "255.255.255.255", $dst_if ); | ||
| 86 | acct_ip_ruleset( $server, $dst, $dst_if, $src, $src_if ); | ||
| 87 | |||
| 88 | } | ||
| 89 | |||
| 90 | sub valid_options { | ||
| 91 | my $self = shift; | ||
| 92 | ( ); | ||
| 93 | } | ||
| 94 | |||
| 95 | 1; | ||
| 96 | =pod | ||
| 97 | |||
| 98 | =head1 NAME | ||
| 99 | |||
| 100 | Fwctl::Services::dhcp - Fwctl module to handle the dhcp protocol. | ||
| 101 | |||
| 102 | =head1 SYNOPSIS | ||
| 103 | |||
| 104 | accept dhcp -src INTERNAL_NET -dst DHCP_SERVER | ||
| 105 | deny dhcp -src INTERNAL_NET -nolog | ||
| 106 | account dhcp -src INTERNAL_NET | ||
| 107 | |||
| 108 | =head1 DESCRIPTION | ||
| 109 | |||
| 110 | This module is used to handle the DHCP protocol. It adds rules to | ||
| 111 | handle the special addresses used by the DHCP protocol. Since DHCP | ||
| 112 | is a broadcast based protocol restricted to local segment, so which | ||
| 113 | by definition doesn't cross a firewall, who would want to use such | ||
| 114 | a module ? | ||
| 115 | |||
| 116 | Two use, first to prevent clutter of log files which denied dhcp | ||
| 117 | broadcast packets when you are using DHCP on the internal network. | ||
| 118 | Second, when your firewall is acting as a DHCP server to the | ||
| 119 | internal network. ??? Who would want to do that ??? Someone trying | ||
| 120 | to replace all WinGate installations with linux based solutions ;-). | ||
| 121 | |||
| 122 | =head1 AUTHOR | ||
| 123 | |||
| 124 | Francis J. Lacoste <francis.lacoste@iNsu.COM> | ||
| 125 | |||
| 126 | =head1 COPYRIGHT | ||
| 127 | |||
| 128 | Copyright (c) 1999,2000 iNsu Innovations Inc. | ||
| 129 | All rights reserved. | ||
| 130 | |||
| 131 | This program is free software; you can redistribute it and/or modify | ||
| 132 | it under the terms of the GNU General Public License as published by | ||
| 133 | the Free Software Foundation; either version 2 of the License, or | ||
| 134 | (at your option) any later version. | ||
| 135 | |||
| 136 | =head1 SEE ALSO | ||
| 137 | |||
| 138 | fwctl(8) Fwctl(3) Fwctl::RuleSet(3) | ||
| 139 | |||
| 140 | =cut | ||
| 141 |