Changeset 3512


Ignore:
Timestamp:
Feb 17, 2016, 1:37:44 AM (21 months ago)
Author:
bruno
Message:
  • Fix #785 by returning conf values when NFS server not on the same LAN as the client
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/bin/mr-net-get-config

    r3278 r3512  
    131131my ($scheme, $account, $host, $port, $path) = pb_get_uri($url);
    132132
    133 # If hot is a name transform into an IP
     133# If host is a name transform into an IP
    134134my $hostip = inet_ntoa(scalar gethostbyname($host || 'localhost'));
     135
     136my $found = 0;
    135137
    136138# We need to loop on all if to see which one is on the same LAN as the server
     
    138140    # Skip fake interfaces
    139141    next if (not defined $if->address);
    140     my $netfs_ipaddr = $if->address;
    141     my $netfs_netmask = $if->netmask;
    142     my $netfs_broadcast = $if->broadcast;
    143     my $netfs_hwaddr = $if->hwaddr;
    144142    pb_log(2, "interface = $if\n");
    145143    pb_log(2, "--\n");
    146     pb_log(2, "addr =      $netfs_ipaddr\n",
    147         "broadcast = $netfs_broadcast\n",
    148         "netmask =   $netfs_netmask\n",
     144    pb_log(2, "addr =      $if->address\n",
     145        "broadcast = $if->broadcast\n",
     146        "netmask =   $if->netmask\n",
    149147        "dstaddr =   ",$if->dstaddr,"\n",
    150         "hwaddr =    $netfs_hwaddr\n",
     148        "hwaddr =    $if->hwaddr\n",
    151149        "mtu =       ",$if->mtu,"\n",
    152150        "metric =    ",$if->metric,"\n",
     
    162160    pb_log(2, "--\n");
    163161    if (ipv4_in_network($if->address, $if->netmask, $hostip)) {
    164         pb_log(1, "Netfs server $host is in network $netfs_ipaddr/$netfs_netmask\n");
     162        pb_log(1, "Netfs server $host is in network $if->address/$if->netmask\n");
     163        $found = 1;
    165164        # So generate conf file
    166         print $fd "netfs-dev $if\n";
    167         print $fd "netfs-proto $scheme\n";
    168         print $fd "netfs-client-ipaddr $netfs_ipaddr\n";
    169         print $fd "netfs-client-netmask $netfs_netmask\n";
    170         print $fd "netfs-client-broadcast $netfs_broadcast\n";
    171         print $fd "netfs-client-hwaddr $netfs_hwaddr\n";
    172         print $fd "netfs-server-mount $ARGV[0]\n";
    173         print $fd "netfs-server-user $account\n";
    174         print $fd "netfs-server-ipaddr $hostip\n";
    175         open(ROUTE, "/proc/net/route") || die "Unable to read /proc/net/route: $!";
    176         while (<ROUTE>) {
    177             my ($iface,$dest,$gw,$foo) = split(/\s+/,$_);
    178             # Keep only default route
    179             next if ($dest !~ /^00000000$/);
    180             $gw =~ s/([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})/hex($4).".".hex($3).".".hex($2).".".hex($1)/eg;
    181             print $fd "netfs-client-defgw $gw\n";
    182         }
    183         close(ROUTE);
     165        my ($iface,$gw) = mr_net_get_def_gw();
     166        mr_net_print_conf($fd, $if, $scheme, $if->address, $if->netmask, $if->broadcast, $if->hwaddr, $ARGV[0], $account, $hostip, $gw);
    184167        last if ($pbdebug > 1);
    185168    }
    186169}
     170if ($found == 0) {
     171    # Not found yet, so use the default GW to reach the server
     172    my ($iface,$gw) = mr_net_get_def_gw();
     173    my $if = IO::Interface::Simple->new($iface);
     174    mr_net_print_conf($fd, $if, $scheme, $if->address, $if->netmask, $if->broadcast, $if->hwaddr, $ARGV[0], $account, $hostip, $gw);
     175    }
     176
    187177close($fd);
     178
     179sub mr_net_get_def_gw {
     180
     181my ($iface,$dest,$gw,$foo);
     182
     183open(ROUTE, "/proc/net/route") || die "Unable to read /proc/net/route: $!";
     184while (<ROUTE>) {
     185    ($iface,$dest,$gw,$foo) = split(/\s+/,$_);
     186    # Keep only default route
     187    next if ($dest !~ /^00000000$/);
     188    $gw =~ s/([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})/hex($4).".".hex($3).".".hex($2).".".hex($1)/eg;
     189    last;
     190}
     191close(ROUTE);
     192return($iface,$gw);
     193}
     194
     195sub mr_net_print_conf {
     196
     197my ($fd, $iface, $scheme, $netfs_ipaddr, $netfs_netmask, $netfs_broadcast, $netfs_hwaddr, $netfs_server_mount, $account, $hostip, $gw) = @_;
     198
     199print $fd "netfs-dev $iface\n";
     200print $fd "netfs-proto $scheme\n";
     201print $fd "netfs-client-ipaddr $netfs_ipaddr\n";
     202print $fd "netfs-client-netmask $netfs_netmask\n";
     203print $fd "netfs-client-broadcast $netfs_broadcast\n";
     204print $fd "netfs-client-hwaddr $netfs_hwaddr\n";
     205print $fd "netfs-server-mount $ARGV[0]\n";
     206print $fd "netfs-server-user $account\n";
     207print $fd "netfs-server-ipaddr $hostip\n";
     208print $fd "netfs-client-defgw $gw\n";
     209}
Note: See TracChangeset for help on using the changeset viewer.