summaryrefslogtreecommitdiff
path: root/scripts/vyatta-update-conntrack-log.pl
blob: 0548762b74623a976cd4e1791c050881550f570a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

use strict;
use lib "/opt/vyatta/share/perl5";
use Vyatta::Conntrack::Config;
use Vyatta::Conntrack::ConntrackUtil;

my $pfile = '/var/run/vyatta/connlogd.lock';

my $config = new Vyatta::Conntrack::Config;
my $oconfig = new Vyatta::Conntrack::Config;

$config->setup();
$oconfig->setupOrig();

if (!(Vyatta::Conntrack::ConntrackUtil::check_for_conntrack_hooks())) {
  print "Warning: Connection tracking is not enabled\n";
}

if (!($config->isDifferentFrom($oconfig))) {
  if ($config->isEmpty()) {
    print STDERR "Conntrack logging error: Empty Configuration\n";
    exit 1;
  }
  # config not changed. do nothing.
  exit 0;
}

if ($config->isEmpty()) {
  # delete the daemon process
  Vyatta::Conntrack::Config::kill_daemon();
  # delete the .lock and .log file getting generated
  `rm -f $pfile`;
  exit 0;
}

my ($cmd, $err) = $config->get_command();
if (defined ($cmd)) {
  # First stop the daemon and restart with config 
  Vyatta::Conntrack::Config::kill_daemon();
  `rm -f $pfile`;
  system("$cmd");
  if ($? >> 8) {
    print STDERR "Failed to start conntrack logging daemon";
    exit 1;
  }
}
if (defined ($err)) {
  print STDERR "Conntrack logging error: $err\n";
  exit 1;
}

exit 0;