| 1 | # | ||
| 2 | # tcp_service.pm: Fwctl service module to handle client/server tcp connection. | ||
| 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::tcp_service; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | |||
| 19 | use Fwctl::RuleSet qw(:tcp_rulesets :masq); | ||
| 20 | use IPChains; | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $proto = shift; | ||
| 24 | my $class = ref $proto || $proto; | ||
| 25 | bless { | ||
| 26 | port => "1:1023", | ||
| 27 | local_port => "1024:65535", | ||
| 28 | }, $class; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub prototypes { | ||
| 32 | my ($self,$target,$options) = @_; | ||
| 33 | |||
| 34 | my $src_port = $options->{local_port} || $self->{local_port}; | ||
| 35 | my $dst_port = $options->{port} || $self->{port}; | ||
| 36 | |||
| 37 | # Build prototype rule | ||
| 38 | ( | ||
| 39 | IPChains->new( | ||
| 40 | Rule => $target, | ||
| 41 | Prot => 'tcp', | ||
| 42 | SourcePort => $src_port, | ||
| 43 | DestPort => $dst_port, | ||
| 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 | |||
| 54 | my ($fw) = $self->prototypes( $target, $options ); | ||
| 55 | block_tcp_ruleset( $fw, $src, $src_if, $dst, $dst_if ); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub accept_rules { | ||
| 59 | my $self = shift; | ||
| 60 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 61 | |||
| 62 | my ($fw) = $self->prototypes( $target, $options ); | ||
| 63 | |||
| 64 | my $masq = defined $options->{portfw} ? PORTFW : | ||
| 65 | $options->{masq} ? MASQ : NOMASQ; | ||
| 66 | |||
| 67 | accept_tcp_ruleset( $fw, $src, $src_if, $dst, $dst_if, | ||
| 68 | $masq, $options->{portfw} ); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub account_rules { | ||
| 72 | my $self = shift; | ||
| 73 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 74 | |||
| 75 | my ($fw) = $self->prototypes( $target, $options ); | ||
| 76 | |||
| 77 | my $masq = defined $options->{portfw} ? PORTFW : | ||
| 78 | $options->{masq} ? MASQ : NOMASQ; | ||
| 79 | |||
| 80 | acct_tcp_ruleset( $fw, $src, $src_if, $dst, $dst_if, $masq ); | ||
| 81 | } | ||
| 82 | |||
| 83 | sub valid_options { | ||
| 84 | my $self = shift; | ||
| 85 | ( "local_port=s", "port=s" ); | ||
| 86 | } | ||
| 87 | |||
| 88 | 1; | ||
| 89 | |||
| 90 | =pod | ||
| 91 | |||
| 92 | =head1 NAME | ||
| 93 | |||
| 94 | Fwctl::Services::tcp_service - Fwctl module to handle simple TCP client/server communication. | ||
| 95 | |||
| 96 | =head1 SYNOPSIS | ||
| 97 | |||
| 98 | accept tcp_service -src INTERNAL_NET -dst DATABASE_SERVER -port postgres | ||
| 99 | # Same as | ||
| 100 | accept postgres -src INTERNAL_NET -dst DATABASE_SERVER | ||
| 101 | account tcp_service -src INTERNET -port telnet | ||
| 102 | # Same as | ||
| 103 | account telnet -src INTERNET | ||
| 104 | |||
| 105 | =head1 DESCRIPTION | ||
| 106 | |||
| 107 | This Fwctl module is used to handle single connection TCP client/server. It | ||
| 108 | takes as options I<port> and I<local_port> which are used to set the | ||
| 109 | destination and source port of the connection. | ||
| 110 | |||
| 111 | This is the module used to auto generate TCP service. | ||
| 112 | |||
| 113 | =head1 AUTHOR | ||
| 114 | |||
| 115 | Francis J. Lacoste <francis.lacoste@iNsu.COM> | ||
| 116 | |||
| 117 | =head1 COPYRIGHT | ||
| 118 | |||
| 119 | Copyright (c) 1999,2000 iNsu Innovations Inc. | ||
| 120 | All rights reserved. | ||
| 121 | |||
| 122 | This program is free software; you can redistribute it and/or modify | ||
| 123 | it under the terms of the GNU General Public License as published by | ||
| 124 | the Free Software Foundation; either version 2 of the License, or | ||
| 125 | (at your option) any later version. | ||
| 126 | |||
| 127 | =head1 SEE ALSO | ||
| 128 | |||
| 129 | fwctl(8) Fwctl(3) Fwctl::RuleSet(3) | ||
| 130 | |||
| 131 | =cut | ||
| 132 |