| 1 | # | ||
| 2 | # timed.pm: Fwctl service module to handle timed 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::timed; | ||
| 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 | SourcePort => 'timed', | ||
| 38 | DestPort => 'timed', | ||
| 39 | %{$options->{ipchains}}, | ||
| 40 | ), | ||
| 41 | IPChains->new( | ||
| 42 | Rule => $target, | ||
| 43 | Prot => 'icmp', | ||
| 44 | ICMP => 'timestamp-request', | ||
| 45 | %{$options->{ipchains}}, | ||
| 46 | ), | ||
| 47 | IPChains->new( | ||
| 48 | Rule => $target, | ||
| 49 | Prot => 'icmp', | ||
| 50 | ICMP => 'timestamp-reply', | ||
| 51 | %{$options->{ipchains}}, | ||
| 52 | ), | ||
| 53 | ); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub block_rules { | ||
| 57 | my $self = shift; | ||
| 58 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 59 | |||
| 60 | |||
| 61 | my ($udp,$request,$reply) = $self->prototypes( $target, $options ); | ||
| 62 | if ( ipv4_in_network( $src, $dst ) ) { | ||
| 63 | block_udp_ruleset( $udp, $src, $src_if, $src_if->{broadcast}, $dst_if ); | ||
| 64 | } | ||
| 65 | block_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if ); | ||
| 66 | block_ip_ruleset( $request, $src, $src_if, $dst, $dst_if ); | ||
| 67 | block_ip_ruleset( $reply, $dst, $dst_if, $src, $src_if ); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub accept_rules { | ||
| 71 | my $self = shift; | ||
| 72 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 73 | |||
| 74 | my ($udp,$request,$reply) = $self->prototypes( $target, $options ); | ||
| 75 | if ( ipv4_in_network( $src, $dst ) ) { | ||
| 76 | accept_ip_ruleset( $udp, $src, $src_if, $src_if->{broadcast}, $dst_if, | ||
| 77 | $options->{masq} ? MASQ : NOMASQ | ||
| 78 | ); | ||
| 79 | } | ||
| 80 | accept_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if, | ||
| 81 | $options->{masq} ? MASQ : NOMASQ | ||
| 82 | ); | ||
| 83 | accept_ip_ruleset( $request, $src, $src_if, $dst, $dst_if, | ||
| 84 | $options->{masq} ? MASQ : NOMASQ | ||
| 85 | ); | ||
| 86 | accept_ip_ruleset( $reply, $dst, $dst_if, $src, $src_if, | ||
| 87 | $options->{masq} ? MASQ : NOMASQ | ||
| 88 | ); | ||
| 89 | |||
| 90 | } | ||
| 91 | |||
| 92 | sub account_rules { | ||
| 93 | my $self = shift; | ||
| 94 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 95 | |||
| 96 | my ($udp,$request,$reply) = $self->prototypes( $target, $options ); | ||
| 97 | if ( ipv4_in_network( $src, $dst ) ) { | ||
| 98 | accept_udp_ruleset( $udp, $src, $src_if, $src_if->{broadcast}, $dst_if, | ||
| 99 | $options->{masq} ? MASQ : NOMASQ | ||
| 100 | ); | ||
| 101 | } | ||
| 102 | acct_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if, | ||
| 103 | $options->{masq} ? MASQ : NOMASQ | ||
| 104 | ); | ||
| 105 | acct_ip_ruleset( $request, $src, $src_if, $dst, $dst_if, | ||
| 106 | $options->{masq} ? MASQ : NOMASQ | ||
| 107 | ); | ||
| 108 | acct_ip_ruleset( $reply, $src, $src_if, $dst, $dst_if, | ||
| 109 | $options->{masq} ? MASQ : NOMASQ | ||
| 110 | ); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub valid_options { | ||
| 114 | my $self = shift; | ||
| 115 | ( ); | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; | ||
| 119 | =pod | ||
| 120 | |||
| 121 | =head1 NAME | ||
| 122 | |||
| 123 | Fwctl::Services::timed - Fwctl module to handle any IP traffic. | ||
| 124 | |||
| 125 | =head1 SYNOPSIS | ||
| 126 | |||
| 127 | accept timed -src INTERNAL_NET -dst FIREWALL | ||
| 128 | deny timed -src INTERNET | ||
| 129 | |||
| 130 | =head1 DESCRIPTION | ||
| 131 | |||
| 132 | The timed module is used to handle the timed time synchronization | ||
| 133 | protocol. This modules takes care of the broadcast part of the | ||
| 134 | protocol and the ICMP part. | ||
| 135 | |||
| 136 | =head1 AUTHOR | ||
| 137 | |||
| 138 | Francis J. Lacoste <francis.lacoste@iNsu.COM> | ||
| 139 | |||
| 140 | =head1 COPYRIGHT | ||
| 141 | |||
| 142 | Copyright (c) 1999,2000 iNsu Innovations Inc. | ||
| 143 | All rights reserved. | ||
| 144 | |||
| 145 | This program is free software; you can redistribute it and/or modify | ||
| 146 | it under the terms of the GNU General Public License as published by | ||
| 147 | the Free Software Foundation; either version 2 of the License, or | ||
| 148 | (at your option) any later version. | ||
| 149 | |||
| 150 | =head1 SEE ALSO | ||
| 151 | |||
| 152 | fwctl(8) Fwctl(3) Fwctl::RuleSet(3) | ||
| 153 | |||
| 154 | =cut | ||
| 155 |