Commit 6ce76216 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Support specification of speed/duplex from the TMCD, which is

currently unused cause the switches are unhappy when the nodes reset
to 10Mbs. Not sure what is going on with that, so punt for now and
return to it later.
parent 2b1bb6ed
......@@ -313,17 +313,32 @@ sub doifconfig ()
print IFC "#!/bin/sh\n";
while (<$TM>) {
if ($_ =~ /INTERFACE=(\d*) INET=([0-9.]*) MASK=([0-9.]*) MAC=(\w*)/) {
my $pat;
#
# Note that speed has a units spec: (K|M)bps
#
$pat = q(INTERFACE=(\d*) INET=([0-9.]*) MASK=([0-9.]*) MAC=(\w*) );
$pat .= q(SPEED=(\w*) DUPLEX=(\w*));
if ($_ =~ /$pat/) {
my $iface;
if ($iface = findiface($4)) {
my $ifline = os_ifconfig_line($iface, $2, $3);
my $inet = $2;
my $mask = $3;
my $mac = $4;
my $speed = $5;
my $duplex= $6;
if ($iface = findiface($mac)) {
my $ifline =
os_ifconfig_line($iface, $inet, $mask, $speed, $duplex);
print STDOUT " $ifline\n";
print IFC "$ifline\n";
}
else {
warn "*** WARNING: Bad MAC: $4\n";
warn "*** WARNING: Bad MAC: $mac\n";
}
}
else {
......
......@@ -41,8 +41,10 @@ my $USERMOD = "/usr/sbin/pw usermod";
my $GROUPADD = "/usr/sbin/pw groupadd";
my $CHPASS = "/usr/bin/chpass -p";
my $MKDB = "/usr/sbin/pwd_mkdb -p";
my $IFCONFIG = "/sbin/ifconfig %s inet %s netmask %s ".
"media 100baseTX mediaopt full-duplex";
my $IFCONFIG = "/sbin/ifconfig %s inet %s netmask %s %s %s";
my $IFC_100MBS = "media 100baseTX";
my $IFC_10MBS = "media 10baseT/UTP";
my $IFC_FDUPLEX = "mediaopt full-duplex";
my $RPMINSTALL = "/usr/local/bin/rpm -i %s";
#
......@@ -88,11 +90,43 @@ sub os_cleanup_node () {
# Generate and return an ifconfig line that is approriate for putting
# into a shell script (invoked at bootup).
#
sub os_ifconfig_line($$$)
sub os_ifconfig_line($$$$$)
{
my ($iface, $inet, $mask) = @_;
return sprintf($IFCONFIG, $iface, $inet, $mask);
my ($iface, $inet, $mask, $speed, $duplex) = @_;
my $media = "";
my $mediaopt = "";
#
# Need to check units on the speed. Just in case.
#
if ($speed =~ /(\d*)([A-Za-z]*)/) {
if ($2 eq "Mbps") {
$speed = $1;
}
elsif ($2 eq "Kbps") {
$speed = $1 / 1000;
}
else {
warn("*** Bad speed units in ifconfig!\n");
$speed = 100;
}
if ($speed == 100) {
$media = $IFC_100MBS;
}
elsif ($speed == 10) {
$media = $IFC_10MBS;
}
else {
warn("*** Bad Speed in ifconfig!\n");
$media = $IFC_100MBS;
}
}
if ($duplex eq "full") {
$mediaopt = $IFC_FDUPLEX;
}
return sprintf($IFCONFIG, $iface, $inet, $mask, $media, $mediaopt);
}
#
......
......@@ -313,17 +313,32 @@ sub doifconfig ()
print IFC "#!/bin/sh\n";
while (<$TM>) {
if ($_ =~ /INTERFACE=(\d*) INET=([0-9.]*) MASK=([0-9.]*) MAC=(\w*)/) {
my $pat;
#
# Note that speed has a units spec: (K|M)bps
#
$pat = q(INTERFACE=(\d*) INET=([0-9.]*) MASK=([0-9.]*) MAC=(\w*) );
$pat .= q(SPEED=(\w*) DUPLEX=(\w*));
if ($_ =~ /$pat/) {
my $iface;
if ($iface = findiface($4)) {
my $ifline = os_ifconfig_line($iface, $2, $3);
my $inet = $2;
my $mask = $3;
my $mac = $4;
my $speed = $5;
my $duplex= $6;
if ($iface = findiface($mac)) {
my $ifline =
os_ifconfig_line($iface, $inet, $mask, $speed, $duplex);
print STDOUT " $ifline\n";
print IFC "$ifline\n";
}
else {
warn "*** WARNING: Bad MAC: $4\n";
warn "*** WARNING: Bad MAC: $mac\n";
}
}
else {
......
......@@ -42,6 +42,10 @@ my $USERDEL = "/usr/sbin/userdel";
my $USERMOD = "/usr/sbin/usermod";
my $GROUPADD = "/usr/sbin/groupadd";
my $IFCONFIG = "/sbin/ifconfig %s inet %s netmask %s";
my $IFC_100MBS = "100baseTx";
my $IFC_10MBS = "10baseT";
my $IFC_FDUPLEX = "FD";
my $IFC_HDUPLEX = "HD";
my $RPMINSTALL = "/bin/rpm -i %s";
my @LOCKFILES = ("/etc/group.lock", "/etc/gshadow.lock");
......@@ -69,11 +73,58 @@ sub os_cleanup_node () {
# Generate and return an ifconfig line that is approriate for putting
# into a shell script (invoked at bootup).
#
sub os_ifconfig_line($$$)
sub os_ifconfig_line($$$$$)
{
my ($iface, $inet, $mask) = @_;
my ($iface, $inet, $mask, $speed, $duplex) = @_;
my ($ifc, $miirest, $miisleep, $miisetspd, $media);
#
# Need to check units on the speed. Just in case.
#
if ($speed =~ /(\d*)([A-Za-z]*)/) {
if ($2 eq "Mbps") {
$speed = $1;
}
elsif ($2 eq "Kbps") {
$speed = $1 / 1000;
}
else {
warn("*** Bad speed units in ifconfig!\n");
$speed = 100;
}
if ($speed == 100) {
$media = $IFC_100MBS;
}
elsif ($speed == 10) {
$media = $IFC_10MBS;
}
else {
warn("*** Bad Speed in ifconfig!\n");
$media = $IFC_100MBS;
}
}
if ($duplex eq "full") {
$media = "$media-$IFC_FDUPLEX";
}
elsif ($duplex eq "half") {
$media = "$media-$IFC_HDUPLEX";
}
else {
warn("*** Bad duplex in ifconfig!\n");
$media = "$media-$IFC_FDUPLEX";
}
$ifc = sprintf($IFCONFIG, $iface, $inet, $mask);
if ($speed != 100 || $duplex ne "full") {
$mii = "sleep 2\n".
"/sbin/mii-tool --reset $iface\n".
"sleep 2\n".
"/sbin/mii-tool --force=$media $iface";
$ifc = "$ifc\n$mii";
}
return sprintf($IFCONFIG, $iface, $inet, $mask);
return "$ifc";
}
#
......
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