summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 961146a)
raw | patch | inline | side by side (parent: 961146a)
author | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Feb 2008 14:46:20 +0000 (14:46 +0000) | ||
committer | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Feb 2008 14:46:20 +0000 (14:46 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8749 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-client | patch | blob | history |
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index b87220450a2ad42ae3c1d419859a683ff086b9cd..417b9263e02e01caf5408fc749ad850e15af7b2b 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
# matches (defaultroute last).
#===============================================================================
sub get_local_mac_for_remote_ip {
- my $server_ip= shift;
- my $result= "00:00:00:00:00:00";
- my $PROC_NET_ROUTE= ('/proc/net/route');
-
- open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE")
- or die "Could not open $PROC_NET_ROUTE";
-
- my @ifs = <PROC_NET_ROUTE>;
-
- close(PROC_NET_ROUTE);
+ my $server_ip= shift;
+ my $result= "00:00:00:00:00:00";
+
+ if($server_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) {
+ my $PROC_NET_ROUTE= ('/proc/net/route');
+
+ open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE")
+ or die "Could not open $PROC_NET_ROUTE";
+
+ my @ifs = <PROC_NET_ROUTE>;
+
+ close(PROC_NET_ROUTE);
+
+ # Eat header line
+ shift @ifs;
+ chomp @ifs;
+ foreach my $line(@ifs) {
+ my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line);
+ my $destination;
+ my $mask;
+ my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination);
+ $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask);
+ $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ if(new NetAddr::IP($server_ip)->within(new NetAddr::IP($destination, $mask))) {
+ # destination matches route, save mac and exit
+ $result= &get_mac($Iface);
+ last;
+ }
+ }
+ } else {
+ daemon_log("get_local_mac_for_remote_ip was called with a non-ip parameter: $server_ip", 1);
+ }
+ return $result;
+}
- # Eat header line
- shift @ifs;
- chomp @ifs;
- foreach my $line(@ifs) {
- my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line);
- my $destination;
- my $mask;
- my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination);
- $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
- ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask);
- $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
- if(new NetAddr::IP($server_ip)->within(new NetAddr::IP($destination, $mask))) {
- # destination matches route, save mac and exit
- $result= &get_mac($Iface);
- last;
- }
- }
+sub get_local_ip_for_remote_ip {
+ my $server_ip= shift;
+ my $result="0.0.0.0";
- return $result;
+ if($server_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) {
+ if($server_ip eq "127.0.0.1") {
+ $result="127.0.0.1";
+ } else {
+ my $PROC_NET_ROUTE= ('/proc/net/route');
+
+ open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE")
+ or die "Could not open $PROC_NET_ROUTE";
+
+ my @ifs = <PROC_NET_ROUTE>;
+
+ close(PROC_NET_ROUTE);
+
+ # Eat header line
+ shift @ifs;
+ chomp @ifs;
+ foreach my $line(@ifs) {
+ my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line);
+ my $destination;
+ my $mask;
+ my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination);
+ $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask);
+ $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ if(new NetAddr::IP($server_ip)->within(new NetAddr::IP($destination, $mask))) {
+ # destination matches route, save mac and exit
+ $result= &get_ip($Iface);
+ last;
+ }
+ }
+ }
+ } else {
+ daemon_log("get_local_ip_for_remote_ip was called with a non-ip parameter: $server_ip", 1);
+ }
+ return $result;
}
-
sub new_ldap_config {
my ($msg_hash) = @_ ;
my $element;
}
# create registration msg
- my $register_hash = &create_xml_hash("here_i_am", $client_address, $server);
+ my $register_hash = &create_xml_hash("here_i_am", &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)).":".$client_port, $server);
&add_content2xml_hash($register_hash, "new_passwd", $server_key);
&add_content2xml_hash($register_hash, "mac_address", &get_local_mac_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)));
&add_content2xml_hash($register_hash, "events", $events);