From dbb604095571e183fe1da079938d518e88cc1c96 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 20 Mar 2012 20:55:41 +0000 Subject: [PATCH] Prevent some extraneous process spawing and futile transmit attempts. Also, do broadcast IPv4 in addition to multicast IPv4 and multicast IPv6. Some switches seem to make the admin work for multicast to work at all... git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11916 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/SLP.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/SLP.pm b/perl-xCAT/xCAT/SLP.pm index 6d89978c0..4d288241e 100644 --- a/perl-xCAT/xCAT/SLP.pm +++ b/perl-xCAT/xCAT/SLP.pm @@ -43,6 +43,7 @@ sub dodiscover { } } unless ($args{SrvTypes}) { croak "SrvTypes argument is required for xCAT::SLP::Dodiscover"; } + setsockopt($args{'socket'},SOL_SOCKET,SO_BROADCAST,1); #allow for broadcasts to be sent, we know what we are doing my @srvtypes; if (ref $args{SrvTypes}) { @srvtypes = @{$args{SrvTypes}}; @@ -259,10 +260,16 @@ sub send_service_request_single { $socket->send($packet,0,$v6addr); } foreach my $ip (@{$interfaces->{$iface}->{ipv4addrs}}) { - $ip =~ s/\/.*//; + $ip =~ s/\/(.*)//; + my $maskbits = $1; my $ipn = inet_aton($ip); #we are ipv4 only, this is ok - setsockopt($socket,0,IP_MULTICAST_IF,pack("NNI",$ipv4mcastaddr,$ipn,$interfaces->{$iface}->{scopeidx})); + my $ipnum=unpack("N",$ipn); + $ipnum= $ipnum | (2**(32-$maskbits))-1; + my $bcastn = pack("N",$ipnum); + my $bcastaddr = sockaddr_in(427,$bcastn); + setsockopt($socket,0,IP_MULTICAST_IF,$ipn); $socket->send($packet,0,$ipv4sockaddr); + $socket->send($packet,0,$bcastaddr); } } } @@ -273,8 +280,14 @@ sub get_interfaces { my %ifacemap; my $payingattention=0; my $interface; + my $keepcurrentiface; foreach my $line (@ipoutput) { if ($line =~ /^\d/) { # new interface, new context.. + if ($interface and not $keepcurrentiface) { + #don't bother reporting unusable nics + delete $ifacemap{$interface}; + } + $keepcurrentiface=0; unless ($line =~ /MULTICAST/) { #don't care if it isn't multicast capable $payingattention=0; next; @@ -285,6 +298,9 @@ sub get_interfaces { $ifacemap{$interface}->{scopeidx}=$1; } unless ($payingattention) { next; } #don't think about lines unless in context of paying attention. + if ($line =~ /inet/) { + $keepcurrentiface=1; + } if ($line =~ /\s+inet\s+(\S+)\s/) { #got an ipv4 address, store it push @{$ifacemap{$interface}->{ipv4addrs}},$1; }