X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fmodules%2FArpHandler.pm;h=be47d61400b9fdf05cb67725313445a27df369ed;hb=4957ac6d16f1533e611f5d857d9e2bb32f91f7fd;hp=38a93a57a6efc9edf4ea1e637b400a796e697504;hpb=2d9515b77545fcd401db5d0bcd26243a2024994b;p=gosa.git diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 38a93a57a..be47d6140 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -6,8 +6,6 @@ use Exporter; use strict; use warnings; use GOSA::GosaSupportDaemon; -use Getopt::Long; -use Config::IniFiles; use POSIX; use Fcntl; use Net::LDAP; @@ -16,10 +14,18 @@ use Net::LDAP::Entry; use Net::DNS; use Switch; use Data::Dumper; -use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/; -use POE qw(Component::Pcap Component::ArpWatch); -BEGIN{} +# Don't start if some of the modules are missing +my $start_service=1; +BEGIN{ + unless(eval('use Socket qw(PF_INET SOCK_DGRAM inet_ntoa sockaddr_in)')) { + $start_service=0; + } + unless(eval('use POE qw(Component::Pcap Component::ArpWatch)')) { + $start_service=0; + } +} + END{} my ($timeout, $mailto, $mailfrom, $user, $group); @@ -39,11 +45,44 @@ sub get_module_info { "socket", ); - $ldap = Net::LDAP->new("ldap.intranet.gonicus.de") or die "$@"; + # Don't start if some of the modules are missing + if($start_service) { + eval { + $ldap = Net::LDAP->new("ldap.intranet.gonicus.de"); + }; + if ($@) { + &main::daemon_log("Could not connect to LDAP Server!\n$@", 1); + } else { + &main::daemon_log("Could not connect to LDAP Server!\n$@", 1); + + } - if ((!defined($interface)) || $interface eq 'all') { - foreach my $device(&get_interfaces) { - if(not(&get_mac($device) eq "00:00:00:00:00:00")) { + # When interface is not configured (or 'all'), start arpwatch on all possible interfaces + if ((!defined($interface)) || $interface eq 'all') { + foreach my $device(&get_interfaces) { + # TODO: Need a better workaround for IPv4-to-IPv6 bridges + if($device =~ m/^sit\d+$/) { + next; + } + + # If device has a valid mac address + if(not(&get_mac($device) eq "00:00:00:00:00:00")) { + &main::daemon_log("Starting ArpWatch on $device", 1); + POE::Session->create( + inline_states => { + _start => sub { + &start(@_,$device); + }, + _stop => sub { + $_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' ) + }, + got_packet => \&got_packet, + }, + ); + } + } + } else { + foreach my $device(split(/[\s,]+/, $interface)) { &main::daemon_log("Starting ArpWatch on $device", 1); POE::Session->create( inline_states => { @@ -51,43 +90,31 @@ sub get_module_info { &start(@_,$device); }, _stop => sub { - $_[KERNEL]->post( eval("arp_watch_$device") => 'shutdown' ) + $_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' ) }, got_packet => \&got_packet, }, ); } } - } else { - &main::daemon_log("Starting ArpWatch on $interface", 1); - POE::Session->create( - inline_states => { - _start => \&start, - _stop => sub { - $_[KERNEL]->post( arp_watch => 'shutdown' ) - }, - got_packet => \&got_packet, - }, - ); } - return \@info; } sub process_incoming_msg { - return 0; + return 1; } sub start { - my $device = $_[ARG0] || 'eth0'; + my $device = (exists($_[ARG0])?$_[ARG0]:'eth0'); POE::Component::ArpWatch->spawn( - Alias => eval("arp_watch_$device"), - Device => 'eth0', + Alias => sprintf("arp_watch_$device"), + Device => $device, Dispatch => 'got_packet', Session => $_[SESSION], ); - $_[KERNEL]->post( arp_watch => 'run' ); + $_[KERNEL]->post( sprintf("arp_watch_$device") => 'run' ); } sub got_packet {