Commit 43bb0e7c authored by Ryan Jackson's avatar Ryan Jackson

Make newnode scripts work on Linux

FreeBSD network devices are named after the device driver used, whereas
Linux network devices are named after the interface type, such as 'eth0'
for the first ethernet interface.  The newclient script would send each
interface name to the server via the 'ifacenameX' parameter, and
newnodecheckin.php would use it to get the driver type for the
interface.  This works with the FreeBSD MFS, but not with the Linux one.
Without this fix, all reported interfaces would be of type 'eth', which
isn't helpful.

To fix this, a new parameter was added to newnodecheckin.php called
'ifacedriverX' (where X is the interface number).  This parameter is
optional for backward compatibility with existing newnode MFS images.
If present, it is used to specify the interface type.  If not, the
ifacenameX parameter is munged as before to extract the interface type.

The newclient script reports this parameter under both FreeBSD and
Linux.  On FreeBSD, the interface name is munged to extract the type.
On Linux, the driver name is extracted from sysfs.
parent 21e32adf
......@@ -247,6 +247,8 @@ sub buildURL {
my $ifaceindex = 0;
foreach my $aref (@ifaces) {
my ($iface, $mac, $status) = @$aref;
my $driver = get_iface_driver($iface);
$URL .= "&ifacedriver$ifaceindex=" . urlencode($driver);
$URL .= "&ifacename$ifaceindex=" . urlencode($iface);
$URL .= "&ifacemac$ifaceindex=" . urlencode($mac);
$ifaceindex++;
......@@ -262,12 +264,12 @@ sub buildURL {
#
sub checkin {
my ($URL) = @_;
my $checkin_command = $FETCH;
my $checkin_command = "$FETCH -o '-' '$URL'";
if (! -x $FETCH) {
$checkin_command = $WGET
$checkin_command = "$WGET -O '-' --quiet '$URL'";
}
open(CHECKIN,"$checkin_command -o '-' '$URL'|")
open(CHECKIN,"$checkin_command|")
or error_fatal($ERROR_CHECKIN,"Unable to check in with boss!\n");
my $id = undef;
while (<CHECKIN>) {
......@@ -297,6 +299,38 @@ sub find_interfaces
}
}
sub linux_get_iface_driver
{
my ($iface) = @_;
my $link = "/sys/class/net/$iface/device/driver";
my $driver = undef;
if (-l $link) {
$driver = (split(/\//, readlink($link)))[-1];
}
return $driver;
}
sub freebsd_get_iface_driver
{
my ($iface) = @_;
$iface =~ s/\d+$//;
return $iface;
}
sub get_iface_driver
{
if ($^O eq 'freebsd') {
freebsd_get_iface_driver(@_);
}
elsif ($^O eq 'linux') {
linux_get_iface_driver(@_);
}
}
sub freebsd_find_interfaces {
#
# Grab this node's MAC addresses - we'll just parse them from the output of
......
......@@ -39,17 +39,21 @@ $tmpIP = getenv("REMOTE_ADDR");
#
$interfaces = array();
foreach ($HTTP_GET_VARS as $key => $value) {
if (preg_match("/iface(name|mac)(\d+)/",$key,$matches)) {
if (preg_match("/iface(name|mac|driver)(\d+)/",$key,$matches)) {
$vartype = $matches[1];
$ifacenum = $matches[2];
if ($vartype == "name") {
if (preg_match("/^([a-z]+)(\d+)$/i",$value,$matches)) {
$interfaces[$ifacenum]["type"] = $matches[1];
if (!isset($interfaces[$ifacenum]["type"])) {
$interfaces[$ifacenum]["type"] = $matches[1];
}
$interfaces[$ifacenum]["card"] = $ifacenum;
} else {
echo "Bad interface name $value!";
continue;
}
} else if ($vartype == "driver") {
$interfaces[$ifacenum]["type"] = $value;
} else {
$interfaces[$ifacenum]["mac"] = $value;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment