]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/qosd
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / scripts / qosd
CommitLineData
bcad0fd0 1#!/usr/bin/perl -w
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
a7fb5630 21
66c36198 22use strict;
a7fb5630
MT
23
24# Configuration options:
25#
7ccede9b 26my $device = "$ARGV[0]";
bcad0fd0 27
1c163c04
CS
28our %mainsettings = ();
29require '/var/ipfire/general-functions.pl';
bcad0fd0
CS
30&General::readhash("${General::swroot}/main/settings", \%mainsettings);
31
1c163c04 32our $rrd_datadir = $mainsettings{'RRDLOG'}."/";
bcad0fd0 33our $event_datadir = $mainsettings{'RRDLOG'};
a7fb5630
MT
34our $STEP = 10;
35our $tc_command = "/sbin/tc";
36
37# A trick is to set the environment PERL5LIB to include $GRAPHDIR
38# This is done by the init-script
39# ($GRAPHDIR is obtained from /usr/local/etc/ADSL-optimizer.conf)
40my $include_dir = '/var/ipfire/qos/bin';
41
42
bcad0fd0
CS
43# Create the $mainsettings{'RRDLOG'} if it doesn't exists
44if ( ! -d $mainsettings{'RRDLOG'} ) {
45 print "RRD-datadir not found, creating it: $mainsettings{'RRDLOG'} \n";
46 my $status = system("mkdir $mainsettings{'RRDLOG'}");
47 die "\nERROR cannot create \"$mainsettings{'RRDLOG'}\"\n" unless $status == 0;
a7fb5630
MT
48}
49
50# use POSIX;
51#
bcad0fd0 52#POSIX::setsid()
a7fb5630
MT
53# or die "Can't become a daemon: $!";
54
55# The init scripts will do the right "daemon" thing...
bcad0fd0 56# Become a daemon
a7fb5630
MT
57print "Becoming a daemon...\n";
58my $pid = fork;
59exit if $pid;
60die "Couldn't fork: $!" unless defined($pid);
61
62my $time_to_die = 0;
63sub signal_handler {
64 $time_to_die = 1;
65}
66# Trap signals
67$SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
68$SIG{PIPE} = 'IGNORE';
69
70our %classes_data;
71our %classes_info;
72require "$include_dir/parse-func.pl";
bcad0fd0 73require "$include_dir/event-func.pl";
a7fb5630
MT
74require "$include_dir/RRD-func.pl";
75
76until ($time_to_die) {
77
78 #print "Parsing tc statistics on $device\n";
79 my $res = parse_class($device);
80 if ( ! $res ) {
81 print " Error when parsing classes on $device\n";
82 }
83
84 #print "Updating RRD data-files\n";
85 $res = update_rrds();
86 #if ( $res ) {
87 # print " Error updating RRDs: \"$res\"\n";
88 #}
bcad0fd0 89
a7fb5630
MT
90# my $timestamp = time;
91# print "$timestamp\n";
bcad0fd0 92
a7fb5630
MT
93 sleep($STEP);
94}
95
96print "tc-collector daemon exiting ... bye bye!\n";