~ubuntu-branches/debian/squeeze/shorewall/squeeze

« back to all changes in this revision

Viewing changes to Perl/Shorewall/Tc.pm

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2010-07-14 19:58:19 UTC
  • mfrom: (1.3.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100714195819-at1n1yi85rcv8f13
Tags: 4.4.11-1
New Upstream Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
our @ISA = qw(Exporter);
41
41
our @EXPORT = qw( setup_tc );
42
42
our @EXPORT_OK = qw( process_tc_rule initialize );
43
 
our $VERSION = '4.4_9';
 
43
our $VERSION = '4.4_11';
44
44
 
45
45
our %tcs = ( T => { chain  => 'tcpost',
46
46
                    connmark => 0,
317
317
                        require_capability( 'TPROXY_TARGET', 'Use of TPROXY', 's');
318
318
 
319
319
                        fatal_error "Invalid TPROXY specification( $cmd/$rest )" if $rest;
320
 
                        
 
320
 
321
321
                        $chain = 'tcpre';
322
322
 
323
323
                        $cmd =~ /TPROXY\((.+?)\)$/;
337
337
                        }
338
338
 
339
339
                        $target .= "--on-port $port";
340
 
                        
 
340
 
341
341
                        if ( defined $ip && $ip ne '' ) {
342
342
                            validate_address $ip, 1;
343
343
                            $target .= " --on-ip $ip";
344
344
                        }
345
345
 
346
 
                        $target .= ' --tproxy-mark';    
 
346
                        $target .= ' --tproxy-mark';
347
347
                    }
348
 
                        
 
348
 
349
349
 
350
350
                    if ( $rest ) {
351
351
                        fatal_error "Invalid MARK ($originalmark)" if $marktype == NOMARK;
371
371
                my $val = numeric_value( $cmd );
372
372
                fatal_error "Invalid MARK/CLASSIFY ($cmd)" unless defined $val;
373
373
                my $limit = $globals{TC_MASK};
374
 
                fatal_error "Marks <= $limit may not be set in the PREROUTING or OUTPUT chains when HIGH_ROUTE_MARKS=Yes"
375
 
                    if $cmd && ( $chain eq 'tcpre' || $chain eq 'tcout' ) && $val <= $limit;
 
374
                unless ( have_capability 'FWMARK_RT_MASK' ) {
 
375
                    fatal_error "Marks <= $limit may not be set in the PREROUTING or OUTPUT chains when HIGH_ROUTE_MARKS=Yes"
 
376
                        if $cmd && ( $chain eq 'tcpre' || $chain eq 'tcout' ) && $val <= $limit;
 
377
                }
376
378
            }
377
379
        }
378
380
    }
443
445
}
444
446
 
445
447
sub process_simple_device() {
446
 
    my ( $device , $type , $bandwidth ) = split_line 1, 3, 'tcinterfaces';
 
448
    my ( $device , $type , $in_bandwidth ) = split_line 1, 3, 'tcinterfaces';
447
449
 
448
450
    fatal_error "Duplicate INTERFACE ($device)"    if $tcdevices{$device};
449
451
    fatal_error "Invalid INTERFACE name ($device)" if $device =~ /[:+]/;
463
465
        }
464
466
    }
465
467
 
466
 
    $bandwidth = rate_to_kbit( $bandwidth );
 
468
    $in_bandwidth = rate_to_kbit( $in_bandwidth );
467
469
 
468
470
    emit "if interface_is_up $physical; then";
469
471
 
471
473
 
472
474
    emit ( "${dev}_exists=Yes",
473
475
           "qt \$TC qdisc del dev $physical root",
474
 
           "qt \$TC qdisc del dev $physical ingress\n"     
 
476
           "qt \$TC qdisc del dev $physical ingress\n"
475
477
         );
476
478
 
477
479
    emit ( "run_tc qdisc add dev $physical handle ffff: ingress",
478
 
           "run_tc filter add dev $physical parent ffff: protocol all prio 10 u32 match ip src 0.0.0.0/0 police rate ${bandwidth}kbit burst 10k drop flowid :1\n"
479
 
         ) if $bandwidth;
480
 
          
 
480
           "run_tc filter add dev $physical parent ffff: protocol all prio 10 u32 match ip src 0.0.0.0/0 police rate ${in_bandwidth}kbit burst 10k drop flowid :1\n"
 
481
         ) if $in_bandwidth;
 
482
 
481
483
    emit "run_tc qdisc add dev $physical root handle $number: prio bands 3 priomap $config{TC_PRIOMAP}";
482
484
 
483
485
    for ( my $i = 1; $i <= 3; $i++ ) {
488
490
    }
489
491
 
490
492
    save_progress_message_short qq("   TC Device $physical defined.");
491
 
    
 
493
 
492
494
    pop_indent;
493
495
    emit 'else';
494
496
    push_indent;
497
499
    emit "${dev}_exists=";
498
500
    pop_indent;
499
501
    emit "fi\n";
500
 
 
 
502
 
501
503
    progress_message "  Simple tcdevice \"$currentline\" $done.";
502
 
}    
 
504
}
503
505
 
504
506
sub validate_tc_device( ) {
505
507
    my ( $device, $inband, $outband , $options , $redirected ) = split_line 3, 5, 'tcdevices';
1094
1096
                  1 );
1095
1097
    } else {
1096
1098
        my $postref = $mangle_table->{tcpost};
1097
 
        
 
1099
 
1098
1100
        if ( $address ne '-' ) {
1099
1101
            fatal_error "Invalid combination of columns" unless $proto eq '-' && $ports eq '-';
1100
1102
            add_rule( $postref ,
1101
1103
                      join( '', match_source_net( $address) , $rule ) ,
1102
1104
                      1 );
1103
1105
        } else {
1104
 
            add_rule( $postref , 
 
1106
            add_rule( $postref ,
1105
1107
                      join( '', do_proto( $proto, $ports, '-' , 0 ) , $rule ) ,
1106
1108
                      1 );
1107
1109
 
1113
1115
                    $ipp2p = 1;
1114
1116
                }
1115
1117
 
1116
 
                add_rule( $postref , 
 
1118
                add_rule( $postref ,
1117
1119
                          join( '' , do_proto( $proto, '-', $ports, 0 ) , $rule ) ,
1118
1120
                          1 )
1119
1121
                    unless $proto =~ /^ipp2p/ || $protocol == ICMP || $protocol == IPv6_ICMP;
1139
1141
    my $fn1 = open_file 'tcpri';
1140
1142
 
1141
1143
    if ( $fn1 ) {
1142
 
        first_entry 
1143
 
            sub { 
 
1144
        first_entry
 
1145
            sub {
1144
1146
                progress_message2 "$doing $fn1...";
1145
1147
                warning_message "There are entries in $fn1 but $fn was empty" unless $interfaces;
1146
1148
            };
1383
1385
        add_jump $mangle_table->{OUTPUT} ,     'tcout', 0, $mark_part;
1384
1386
 
1385
1387
        if ( have_capability( 'MANGLE_FORWARD' ) ) {
1386
 
            add_rule( $mangle_table->{FORWARD},     '-j MARK --set-mark 0' ) if have_capability 'MARK';
 
1388
            my $mask = have_capability 'EXMARK' ? have_capability 'FWMARK_RT_MASK' ? '/' . in_hex $globals{PROVIDER_MASK} : '' : '';
 
1389
 
 
1390
            add_rule( $mangle_table->{FORWARD},     "-j MARK --set-mark 0${mask}" ) if $config{FORWARD_CLEAR_MARK};
1387
1391
            add_jump $mangle_table->{FORWARD} ,     'tcfor',  0;
1388
1392
            add_jump $mangle_table->{POSTROUTING} , 'tcpost', 0;
1389
1393
        }