| 1 | # | ||
| 2 | # udp_service.pm - Fwctl module to handle bidirectional UDP service. | ||
| 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::udp_service; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | |||
| 19 | use Fwctl::RuleSet qw(:udp_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 => 'udp', | ||
| 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_udp_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 | accept_udp_ruleset( $fw, $src, $src_if, $dst, $dst_if, | ||
| 67 | $masq, $options->{portfw} ); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub account_rules { | ||
| 71 | my $self = shift; | ||
| 72 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 73 | |||
| 74 | my ($fw) = $self->prototypes( $target, $options ); | ||
| 75 | |||
| 76 | my $masq = defined $options->{portfw} ? PORTFW : | ||
| 77 | $options->{masq} ? MASQ : NOMASQ; | ||
| 78 | acct_udp_ruleset( $fw, $src, $src_if, $dst, $dst_if, $masq ); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub valid_options { | ||
| 82 | my $self = shift; | ||
| 83 | ( "local_port=s", "port=s" ); | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; | ||
| 87 | =pod | ||
| 88 | |||
| 89 | =head1 NAME | ||
| 90 | |||
| 91 | Fwctl::Services::udp_service - Fwctl module to handle bidirectional UDP traffic. | ||
| 92 | |||
| 93 | =head1 SYNOPSIS | ||
| 94 | |||
| 95 | accept udp_service -src INTERNAL_NET -dst FIREWALL -masq -port 2049 | ||
| 96 | |||
| 97 | =head1 DESCRIPTION | ||
| 98 | |||
| 99 | This module is similar to the tcp_service one, in that it handles | ||
| 100 | simple bidirectional UDP communication between client and server. | ||
| 101 | Source and destination ports are given using the I<local_port> and | ||
| 102 | I<port> respectively. Those defaults to UNPRIVILEGED_PORTS. Enough to | ||
| 103 | shoot you in the foot, I know. | ||
| 104 | |||
| 105 | =head1 AUTHOR | ||
| 106 | |||
| 107 | Francis J. Lacoste <francis.lacoste@iNsu.COM> | ||
| 108 | |||
| 109 | =head1 COPYRIGHT | ||
| 110 | |||
| 111 | Copyright (c) 1999,2000 iNsu Innovations Inc. | ||
| 112 | All rights reserved. | ||
| 113 | |||
| 114 | This program is free software; you can redistribute it and/or modify | ||
| 115 | it under the terms of the GNU General Public License as published by | ||
| 116 | the Free Software Foundation; either version 2 of the License, or | ||
| 117 | (at your option) any later version. | ||
| 118 | |||
| 119 | =head1 SEE ALSO | ||
| 120 | |||
| 121 | fwctl(8) Fwctl(3) Fwctl::RuleSet(3) | ||
| 122 | |||
| 123 | =cut | ||
| 124 |