]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/forwardfw/rules.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 no warnings
'uninitialized' ;
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
31 my %defaultNetworks =();
41 my %configoutgoingfw =();
46 require '/var/ipfire/general-functions.pl' ;
47 require "${General::swroot}/lang.pl" ;
48 require "${General::swroot}/forward/bin/firewall-lib.pl" ;
50 my $configfwdfw = "${General::swroot}/forward/config" ;
51 my $configinput = "${General::swroot}/forward/input" ;
52 my $configoutgoing = "${General::swroot}/forward/outgoing" ;
53 my $p2pfile = "${General::swroot}/forward/p2protocols" ;
54 my $configgrp = "${General::swroot}/fwhosts/customgroups" ;
55 my $netsettings = "${General::swroot}/ethernet/settings" ;
56 my $errormessage = '' ;
60 my ( $TYPE , $PROT , $SPROT , $DPROT , $SPORT , $DPORT , $TIME , $TIMEFROM , $TIMETILL , $SRC_TGT );
61 my $CHAIN = "FORWARDFW" ;
62 my $conexists = 'off' ;
63 my $command = 'iptables -A' ;
67 & General
:: readhash
( "${General::swroot}/forward/settings" , \
%fwdfwsettings );
68 & General
:: readhash
( " $netsettings " , \
%defaultNetworks );
69 & General
:: readhasharray
( $configfwdfw , \
%configfwdfw );
70 & General
:: readhasharray
( $configinput , \
%configinputfw );
71 & General
:: readhasharray
( $configoutgoing , \
%configoutgoingfw );
72 & General
:: readhasharray
( $configgrp , \
%customgrp );
73 & General
:: get_aliases
( \
%aliases );
75 #check if we have an internetconnection
76 open ( CONN
, "/var/ipfire/red/iface" );
79 if (- f
"/var/ipfire/red/active" ){
82 open ( CONN1
, "/var/ipfire/red/local-ipaddress" );
88 my $MODE = 0 ; # 0 - normal operation
89 # 1 - print configline and rules to console
94 if ( $param eq 'flush' ){
96 print " Flushing chains... \n " ;
101 print " Flushing chains... \n " ;
105 print " Preparing rules... \n " ;
109 if ( $fwdfwsettings { 'POLICY' } eq 'MODE1' ){
111 system ( "/usr/sbin/firewall-policy" );
112 } elsif ( $fwdfwsettings { 'POLICY' } eq 'MODE2' ){
114 system ( "iptables -A $CHAIN -m conntrack --ctstate NEW -j ACCEPT" );
115 system ( "/usr/sbin/firewall-policy" );
116 system ( "/etc/sysconfig/firewall.local reload" );
122 system ( "iptables -F FORWARDFW" );
123 system ( "iptables -F INPUTFW" );
124 system ( "iptables -F OUTGOINGFW" );
125 system ( "iptables -t nat -F NAT_DESTINATION" );
126 system ( "iptables -t nat -F NAT_SOURCE" );
130 if (! - z
"${General::swroot}/forward/config" ){
131 & buildrules
( \
%configfwdfw );
133 if (! - z
"${General::swroot}/forward/input" ){
134 & buildrules
( \
%configinputfw );
136 if (! - z
"${General::swroot}/forward/outgoing" ){
137 & buildrules
( \
%configoutgoingfw );
151 foreach my $key ( sort { $a <=> $b } keys % $hash ){
152 next if (($ $hash { $key }[ 6 ] eq 'RED' || $ $hash { $key }[ 6 ] eq 'RED1' ) && $conexists eq 'off' );
153 $command = "iptables -A" ;
154 if ($ $hash { $key }[ 28 ] eq 'ON' ){
155 $command = 'iptables -t nat -A' ;
156 $natip =& get_nat_ip
($ $hash { $key }[ 29 ],$ $hash { $key }[ 31 ]);
157 if ($ $hash { $key }[ 31 ] eq 'dnat' ){
159 if ($ $hash { $key }[ 30 ] =~ /\|/ ){
160 $ $hash { $key }[ 30 ]=~ tr/|/,/ ;
161 $fireport = '-m multiport --dport ' .$ $hash { $key }[ 30 ];
163 $fireport = '--dport ' .$ $hash { $key }[ 30 ] if ($ $hash { $key }[ 30 ]> 0 );
170 if ($ $hash { $key }[ 2 ] eq 'ON' ){
172 if ($ $hash { $key }[ 3 ] eq 'cust_grp_src' ){
173 foreach my $grp ( sort { $a <=> $b } keys %customgrp ){
174 if ( $customgrp { $grp }[ 0 ] eq $ $hash { $key }[ 4 ]){
175 & get_address
( $customgrp { $grp }[ 3 ], $customgrp { $grp }[ 2 ], "src" );
179 & get_address
($ $hash { $key }[ 3 ],$ $hash { $key }[ 4 ], "src" );
182 if ($ $hash { $key }[ 5 ] eq 'cust_grp_tgt' ){
183 foreach my $grp ( sort { $a <=> $b } keys %customgrp ){
184 if ( $customgrp { $grp }[ 0 ] eq $ $hash { $key }[ 6 ]){
185 & get_address
( $customgrp { $grp }[ 3 ], $customgrp { $grp }[ 2 ], "tgt" );
188 } elsif ($ $hash { $key }[ 5 ] eq 'ipfire' ){
189 if ($ $hash { $key }[ 6 ] eq 'GREEN' ){
190 $targethash { $key }[ 0 ]= $defaultNetworks { 'GREEN_ADDRESS' };
192 if ($ $hash { $key }[ 6 ] eq 'BLUE' ){
193 $targethash { $key }[ 0 ]= $defaultNetworks { 'BLUE_ADDRESS' };
195 if ($ $hash { $key }[ 6 ] eq 'ORANGE' ){
196 $targethash { $key }[ 0 ]= $defaultNetworks { 'ORANGE_ADDRESS' };
198 if ($ $hash { $key }[ 6 ] eq 'ALL' ){
199 $targethash { $key }[ 0 ]= '0.0.0.0/0' ;
201 if ($ $hash { $key }[ 6 ] eq 'RED' || $ $hash { $key }[ 6 ] eq 'RED1' ){
202 open ( FILE
, "/var/ipfire/red/local-ipaddress" ) or die "Couldn't open local-ipaddress" ;
203 $targethash { $key }[ 0 ]= < FILE
>;
206 foreach my $alias ( sort keys %aliases ){
207 if ($ $hash { $key }[ 6 ] eq $alias ){
208 $targethash { $key }[ 0 ]= $aliases { $alias }{ 'IPT' };
213 & get_address
($ $hash { $key }[ 5 ],$ $hash { $key }[ 6 ], "tgt" );
215 ##get source prot and port
217 $SPORT = & get_port
( $hash , $key );
220 ##get target prot and port
221 $DPROT =& get_prot
( $hash , $key );
223 if ( $DPROT eq '' ){ $DPROT = ' ' ;}
224 @DPROT = split ( "," , $DPROT );
227 if ($ $hash { $key }[ 18 ] eq 'ON' ){
228 my ( $time1 , $time2 , $daylight );
229 my $daylight =$ $hash { $key }[ 28 ];
230 $time1 =& get_time
($ $hash { $key }[ 26 ], $daylight );
231 $time2 =& get_time
($ $hash { $key }[ 27 ], $daylight );
232 if ($ $hash { $key }[ 19 ] ne '' ){ push ( @timeframe , "Mon" );}
233 if ($ $hash { $key }[ 20 ] ne '' ){ push ( @timeframe , "Tue" );}
234 if ($ $hash { $key }[ 21 ] ne '' ){ push ( @timeframe , "Wed" );}
235 if ($ $hash { $key }[ 22 ] ne '' ){ push ( @timeframe , "Thu" );}
236 if ($ $hash { $key }[ 23 ] ne '' ){ push ( @timeframe , "Fri" );}
237 if ($ $hash { $key }[ 24 ] ne '' ){ push ( @timeframe , "Sat" );}
238 if ($ $hash { $key }[ 25 ] ne '' ){ push ( @timeframe , "Sun" );}
239 $TIME = join ( "," , @timeframe );
241 $TIMEFROM = "--timestart $time1 " ;
242 $TIMETILL = "--timestop $time2 " ;
243 $TIME = "-m time --weekdays $TIME $TIMEFROM $TIMETILL " ;
247 foreach my $i ( 0 .. $ #{$$hash{$key}}){
248 print " $i : $ $hash { $key }[ $i ] " ;
251 print "################################## \n " ;
252 #print rules to console
253 foreach my $DPROT ( @DPROT ){
254 $DPORT = & get_port
( $hash , $key , $DPROT );
256 $PROT = "-p $PROT " if ( $PROT ne '' && $PROT ne ' ' );
257 foreach my $a ( sort keys %sourcehash ){
258 foreach my $b ( sort keys %targethash ){
259 if ( $sourcehash { $a }[ 0 ] ne $targethash { $b }[ 0 ] && $targethash { $b }[ 0 ] ne 'none' || $sourcehash { $a }[ 0 ] eq '0.0.0.0/0.0.0.0' ){
261 if ( substr ( $sourcehash { $a }[ 0 ], 3 , 3 ) ne 'mac' && $sourcehash { $a }[ 0 ] ne '' ){ $STAG = "-s" ;}
262 if ( substr ( $DPORT , 2 , 4 ) eq 'icmp' ){
263 my @icmprule = split ( "," , substr ( $DPORT , 12 ,));
265 $icmptype = "--icmp-type " ;
270 if ($ $hash { $key }[ 17 ] eq 'ON' ){
271 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j LOG \n " ;
273 print " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j $ $hash { $key }[0] \n " ;
275 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ){
276 $natchain = 'NAT_DESTINATION' ;
277 if ($ $hash { $key }[ 17 ] eq 'ON' ){
278 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $fireport $TIME -j LOG --log-prefix 'DNAT' \n " ;
280 my ( $ip , $sub ) = split ( "/" , $targethash { $b }[ 0 ]);
281 #Process NAT with servicegroup used
282 if ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
283 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to $ip $DPORT \n " ;
284 $fwaccessdport = $DPORT ;
286 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to $ip $DPORT \n " ;
289 $fwaccessdport = "--dport " . substr ( $DPORT , 1 ,);
290 } elsif (! $DPORT && $ $hash { $key }[ 30 ] ne '' ){
291 if ($ $hash { $key }[ 30 ]=~ m/|/i ){
292 $ $hash { $key }[ 30 ] =~ s/\|/,/g ;
293 $fwaccessdport = "-m multiport --dport $ $hash { $key }[30]" ;
295 $fwaccessdport = "--dport $ $hash { $key }[30]" ;
299 print "iptables -A FORWARDFW $PROT -i $con $STAG $sourcehash { $a }[0] -d $ip $fwaccessdport $TIME -j $ $hash { $key }[0] \n " ;
301 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ){
302 $natchain = 'NAT_SOURCE' ;
303 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $nat --to $natip \n " ;
305 if ($ $hash { $key }[ 17 ] eq 'ON' ){
306 print " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
308 if ( $PROT ne '-p ICMP' ){
309 print "iptables -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
311 if ( $PROT eq '-p ICMP' && $ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){
312 print "iptables -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
320 } elsif ( $MODE eq '0' ){
321 foreach my $DPROT ( @DPROT ){
322 $DPORT = & get_port
( $hash , $key , $DPROT );
324 $PROT = "-p $PROT " if ( $PROT ne '' && $PROT ne ' ' );
325 foreach my $a ( sort keys %sourcehash ){
326 foreach my $b ( sort keys %targethash ){
327 if ( $sourcehash { $a }[ 0 ] ne $targethash { $b }[ 0 ] && $targethash { $b }[ 0 ] ne 'none' || $sourcehash { $a }[ 0 ] eq '0.0.0.0/0.0.0.0' ){
329 if ( substr ( $sourcehash { $a }[ 0 ], 3 , 3 ) ne 'mac' && $sourcehash { $a }[ 0 ] ne '' ){ $STAG = "-s" ;}
331 if ( substr ( $DPORT , 2 , 4 ) eq 'icmp' ){
332 my @icmprule = split ( "," , substr ( $DPORT , 12 ,));
334 $icmptype = "--icmp-type " ;
339 if ($ $hash { $key }[ 17 ] eq 'ON' ){
340 system ( " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j LOG" );
342 system ( " $command $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $icmptype $_ $TIME -j $ $hash { $key }[0]" );
344 #PROCESS DNAT RULE (Portforward)
345 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ){
346 $natchain = 'NAT_DESTINATION' ;
347 if ($ $hash { $key }[ 17 ] eq 'ON' ){
348 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $fireport $TIME -j LOG --log-prefix 'DNAT' \n " ;
350 my ( $ip , $sub ) = split ( "/" , $targethash { $b }[ 0 ]);
351 #Process NAT with servicegroup used
352 if ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
353 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to $ip $DPORT \n " ;
354 $fwaccessdport = $DPORT ;
356 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT $natip $fireport $TIME -j $nat --to $ip $DPORT \n " ;
359 $fwaccessdport = "--dport " . substr ( $DPORT , 1 ,);
360 } elsif (! $DPORT && $ $hash { $key }[ 30 ] ne '' ){
361 if ($ $hash { $key }[ 30 ]=~ m/|/i ){
362 $ $hash { $key }[ 30 ] =~ s/\|/,/g ;
363 $fwaccessdport = "-m multiport --dport $ $hash { $key }[30]" ;
365 $fwaccessdport = "--dport $ $hash { $key }[30]" ;
369 system "iptables -A FORWARDFW $PROT -i $con $STAG $sourcehash { $a }[0] -d $ip $fwaccessdport $TIME -j $ $hash { $key }[0] \n " ;
372 } elsif ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ){
373 $natchain = 'NAT_SOURCE' ;
374 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $nat --to $natip \n " ;
376 if ($ $hash { $key }[ 17 ] eq 'ON' && substr ( $DPORT , 2 , 4 ) ne 'icmp' ){
377 system " $command $natchain $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j LOG \n " ;
379 #PROCESS EVERY OTHER RULE (If NOT ICMP, else the rule would be applied double)
380 if ( $PROT ne '-p ICMP' ){
381 system "iptables -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
383 #PROCESS Prot ICMP and type = All ICMP-Types
384 if ( $PROT eq '-p ICMP' && $ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){
385 system "iptables -A $ $hash { $key }[1] $PROT $STAG $sourcehash { $a }[0] $SPORT -d $targethash { $b }[0] $DPORT $TIME -j $ $hash { $key }[0] \n " ;
407 if ( $val eq 'RED' || $val eq 'GREEN' || $val eq 'ORANGE' || $val eq 'BLUE' ){
408 $result = $defaultNetworks { $val . '_ADDRESS' };
409 } elsif ( $val eq 'ALL' ){
411 } elsif ( $val eq 'Default IP' && $type eq 'dnat' ){
412 $result = '-d ' . $redip ;
413 } elsif ( $val eq 'Default IP' && $type eq 'snat' ){
416 foreach my $al ( sort keys %aliases ){
417 if ( $val eq $al && $type eq 'dnat' ){
418 $result = '-d ' . $aliases { $al }{ 'IPT' };
419 } elsif ( $val eq $al && $type eq 'snat' ){
420 $result = $aliases { $al }{ 'IPT' };
433 $minutes = & utcmin
( $val );
434 $ruletime = $minutes + & time_get_utc
( $val );
435 if ( $ruletime < 0 ){ $ruletime += 1440 ;}
436 if ( $ruletime > 1440 ){ $ruletime -= 1440 ;}
437 $time = sprintf " %02d : %02d " , $ruletime / 60 , $ruletime % 60 ;
442 # Calculates the UTCtime from a given time
444 my @localtime = localtime ( time );
445 my @gmtime = gmtime ( time );
446 my $diff = ( $gmtime [ 2 ]* 60 + $gmtime [ 1 ] %60 )-( $localtime [ 2 ]* 60 + $localtime [ 1 ] %60 );
452 my ( $hrs , $min ) = split ( ":" , $ruletime );
453 my $newtime = $hrs * 60 + $min ;
460 open ( FILE
, "< $p2pfile " ) or die "Unable to read $p2pfile " ;
463 my $CMD = "-m ipp2p" ;
464 foreach my $p2pentry ( sort @p2ps ) {
465 my @p2pline = split ( /\;/ , $p2pentry );
466 if ( $fwdfwsettings { 'POLICY' } eq 'MODE1' ) {
468 if ( " $p2pline [2]" eq "on" ) {
469 $P2PSTRING = " $P2PSTRING -- $p2pline [1]" ;
473 if ( " $p2pline [2]" eq "off" ) {
474 $P2PSTRING = " $P2PSTRING -- $p2pline [1]" ;
480 print "/sbin/iptables -A FORWARDFW $CMD $P2PSTRING -j $DO \n " ;
484 system ( "/sbin/iptables -A FORWARDFW $CMD $P2PSTRING -j $DO " );
490 my $base = shift ; #source of checking ($configfwdfw{$key}[x] or groupkey
492 my $type = shift ; #src or tgt
499 my $key = & General
:: findhasharraykey
( $hash );
500 if ( $base eq 'src_addr' || $base eq 'tgt_addr' ){
501 if (& General
:: validmac
( $base2 )){
502 $ $hash { $key }[ 0 ] = "-m mac --mac-source $base2 " ;
504 $ $hash { $key }[ 0 ] = $base2 ;
506 } elsif ( $base eq 'std_net_src' || $base eq 'std_net_tgt' || $base eq 'Standard Network' ){
507 $ $hash { $key }[ 0 ]=& fwlib
:: get_std_net_ip
( $base2 , $con );
508 } elsif ( $base eq 'cust_net_src' || $base eq 'cust_net_tgt' || $base eq 'Custom Network' ){
509 $ $hash { $key }[ 0 ]=& fwlib
:: get_net_ip
( $base2 );
510 } elsif ( $base eq 'cust_host_src' || $base eq 'cust_host_tgt' || $base eq 'Custom Host' ){
511 $ $hash { $key }[ 0 ]=& fwlib
:: get_host_ip
( $base2 , $type );
512 } elsif ( $base eq 'ovpn_net_src' || $base eq 'ovpn_net_tgt' || $base eq 'OpenVPN static network' ){
513 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_net_ip
( $base2 , 1 );
514 } elsif ( $base eq 'ovpn_host_src' || $base eq 'ovpn_host_tgt' || $base eq 'OpenVPN static host' ){
515 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_host_ip
( $base2 , 33 );
516 } elsif ( $base eq 'ovpn_n2n_src' || $base eq 'ovpn_n2n_tgt' || $base eq 'OpenVPN N-2-N' ){
517 $ $hash { $key }[ 0 ]=& fwlib
:: get_ovpn_n2n_ip
( $base2 , 11 );
518 } elsif ( $base eq 'ipsec_net_src' || $base eq 'ipsec_net_tgt' || $base eq 'IpSec Network' ){
519 $ $hash { $key }[ 0 ]=& fwlib
:: get_ipsec_net_ip
( $base2 , 11 );
520 } elsif ( $base eq 'ipfire_src' ){
521 if ( $base2 eq 'GREEN' ){
522 $ $hash { $key }[ 0 ]= $defaultNetworks { 'GREEN_ADDRESS' };
524 if ( $base2 eq 'BLUE' ){
525 $ $hash { $key }[ 0 ]= $defaultNetworks { 'BLUE_ADDRESS' };
527 if ( $base2 eq 'ORANGE' ){
528 $ $hash { $key }[ 0 ]= $defaultNetworks { 'ORANGE_ADDRESS' };
531 $ $hash { $key }[ 0 ]= '0.0.0.0/0' ;
533 if ( $base2 eq 'RED' || $base2 eq 'RED1' ){
534 open ( FILE
, "/var/ipfire/red/local-ipaddress" ) or die "Couldn't open local-ipaddress" ;
535 $ $hash { $key }[ 0 ]= < FILE
>;
538 foreach my $alias ( sort keys %aliases ){
539 if ( $base2 eq $alias ){
540 $ $hash { $key }[ 0 ]= $aliases { $alias }{ 'IPT' };
550 #check AH,GRE,ESP or ICMP
551 if ($ $hash { $key }[ 7 ] ne 'ON' && $ $hash { $key }[ 11 ] ne 'ON' ){
552 return "$ $hash { $key }[8]" ;
554 if ($ $hash { $key }[ 7 ] eq 'ON' || $ $hash { $key }[ 11 ] eq 'ON' ){
555 #check if servicegroup or service
556 if ($ $hash { $key }[ 14 ] eq 'cust_srv' ){
557 return & fwlib
:: get_srv_prot
($ $hash { $key }[ 15 ]);
558 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
559 return & fwlib
:: get_srvgrp_prot
($ $hash { $key }[ 15 ]);
560 } elsif (($ $hash { $key }[ 10 ] ne '' || $ $hash { $key }[ 15 ] ne '' ) && $ $hash { $key }[ 8 ] eq '' ){ #when ports are used and prot set to "all"
562 } elsif (($ $hash { $key }[ 10 ] ne '' || $ $hash { $key }[ 15 ] ne '' ) && ($ $hash { $key }[ 8 ] eq 'TCP' || $ $hash { $key }[ 8 ] eq 'UDP' )){ #when ports are used and prot set to "tcp" or "udp"
563 return "$ $hash { $key }[8]" ;
564 } elsif (($ $hash { $key }[ 10 ] eq '' && $ $hash { $key }[ 15 ] eq '' ) && $ $hash { $key }[ 8 ] ne 'ICMP' ){ #when ports are NOT used and prot NOT set to "ICMP"
565 return "$ $hash { $key }[8]" ;
567 return "$ $hash { $key }[8]" ;
571 if ( $SRC_TGT eq '' && $ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 11 ] eq '' && $ $hash { $key }[ 12 ] ne '' ){
572 return "$ $hash { $key }[8]" ;
580 if ($ $hash { $key }[ 7 ] eq 'ON' && $SRC_TGT eq 'SRC' ){
581 if ($ $hash { $key }[ 10 ] ne '' ){
582 $ $hash { $key }[ 10 ] =~ s/\|/,/g ;
583 if ( index ($ $hash { $key }[ 10 ], "," ) > 0 ){
584 return "-m multiport --sport $ $hash { $key }[10] " ;
586 if ($ $hash { $key }[ 28 ] ne 'ON' || ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ) ||($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'dnat' ) ){
587 return "--sport $ $hash { $key }[10] " ;
589 return ":$ $hash { $key }[10]" ;
593 } elsif ($ $hash { $key }[ 11 ] eq 'ON' && $SRC_TGT eq '' ){
594 if ($ $hash { $key }[ 14 ] eq 'TGT_PORT' ){
595 if ($ $hash { $key }[ 15 ] ne '' ){
596 $ $hash { $key }[ 15 ] =~ s/\|/,/g ;
597 if ( index ($ $hash { $key }[ 15 ], "," ) > 0 ){
598 return "-m multiport --dport $ $hash { $key }[15] " ;
600 if ($ $hash { $key }[ 28 ] ne 'ON' || ($ $hash { $key }[ 28 ] eq 'ON' && $ $hash { $key }[ 31 ] eq 'snat' ) ){
601 return "--dport $ $hash { $key }[15] " ;
603 $ $hash { $key }[ 15 ] =~ s/\:/-/g ;
604 return ":$ $hash { $key }[15]" ;
608 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srv' ){
609 if ( $prot ne 'ICMP' ){
610 if ($ $hash { $key }[ 31 ] eq 'dnat' && $ $hash { $key }[ 28 ] eq 'ON' ){
611 return ":" .& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 1 , $prot );
613 return "--dport " .& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 1 , $prot );
615 } elsif ( $prot eq 'ICMP' && $ $hash { $key }[ 11 ] eq 'ON' ){ #When PROT is ICMP and "use targetport is checked, this is an icmp-service
616 return "--icmp-type " .& fwlib
:: get_srv_port
($ $hash { $key }[ 15 ], 3 , $prot );
618 } elsif ($ $hash { $key }[ 14 ] eq 'cust_srvgrp' ){
619 if ( $prot ne 'ICMP' ){
620 return & fwlib
:: get_srvgrp_port
($ $hash { $key }[ 15 ], $prot );
622 elsif ( $prot eq 'ICMP' ){
623 return & fwlib
:: get_srvgrp_port
($ $hash { $key }[ 15 ], $prot );
628 if ($ $hash { $key }[ 7 ] ne 'ON' && $ $hash { $key }[ 11 ] ne 'ON' && $SRC_TGT eq '' ){
629 if ($ $hash { $key }[ 9 ] ne '' && $ $hash { $key }[ 9 ] ne 'All ICMP-Types' ){
630 return "--icmp-type $ $hash { $key }[9] " ;
631 } elsif ($ $hash { $key }[ 9 ] eq 'All ICMP-Types' ){