summaryrefslogtreecommitdiff
path: root/scripts/vyatta_net_name
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta_net_name')
-rwxr-xr-xscripts/vyatta_net_name51
1 files changed, 45 insertions, 6 deletions
diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name
index 43bed36d..e4508c3d 100755
--- a/scripts/vyatta_net_name
+++ b/scripts/vyatta_net_name
@@ -26,6 +26,7 @@ my $UDEVDIR = "/dev/.udev";
my $VYATTAUDEV = $UDEVDIR . "/vyatta";
my $LOCKFILE = $UDEVDIR . "/.vyatta-lock";
my $VYATTACFG = "/opt/vyatta/config/active";
+my $LOGFILE = "/var/log/vyatta/vnn.log";
# Check if interface name is free to use
sub is_available {
@@ -78,13 +79,13 @@ sub leave_rescan_hint {
# Use biosdevname program (ethernet only)
# to try and find name based on PCI slot and DMI info
sub biosdevname {
- my $ifname = shift;
+ my ($ifname, $hwaddr) = @_;
# biosdevname renames wlanX to ethX ??
if ($ifname =~ /^eth/) {
my $biosname = `/sbin/biosdevname --policy all_ethN -i $ifname`;
chomp $biosname;
-
+ logit("biosdevname recommends $biosname for $ifname $hwaddr\n");
return $biosname if ($biosname ne '');
}
return $ifname; # Fallback to existing name
@@ -114,7 +115,10 @@ sub coldplug {
# is name already in config file
my $newname = $interfaces->{$hwaddr};
- return $newname if ($newname);
+ if ($newname) {
+ logit("name for $ifname $hwaddr in config file is $newname\n");
+ return $newname;
+ }
# add already assigned names
if (opendir(my $dir, $VYATTAUDEV)) {
@@ -129,9 +133,11 @@ sub coldplug {
}
}
- $newname = biosdevname($ifname);
+ $newname = biosdevname($ifname, $hwaddr);
unless (is_available($interfaces, $newname)) {
+ logit("but $newname is not available for $ifname $hwaddr\n");
$newname = find_available($interfaces, $newname);
+ logit("So we will use $newname instead for $ifname $hwaddr\n");
}
leave_rescan_hint($newname, $hwaddr);
@@ -161,11 +167,16 @@ sub hotplug {
}
my $newname = $interfaces->{$hwaddr};
- return $newname if ($newname);
+ if ($newname) {
+ logit("hotplug: name for $ifname $hwaddr in config file is $newname\n");
+ return $newname
+ }
- $newname = biosdevname($ifname);
+ $newname = biosdevname($ifname, $hwaddr);
unless (is_available($interfaces, $newname)) {
+ logit("but $newname is not available for $ifname $hwaddr\n");
$newname = find_available($interfaces, $newname);
+ logit("So we will use $newname instead for $ifname $hwaddr\n");
}
syslog(LOG_INFO, "new name for '%s' is '%s'", $ifname, $newname);
@@ -188,6 +199,22 @@ sub unlock_file {
$LOCKF = undef;
}
+my $LOGF;
+
+sub open_logfile {
+ open ($LOGF, '>>', $LOGFILE)
+ or die "Can't open log file $LOGFILE : $!";
+}
+
+sub close_logfile {
+ close($LOGF);
+}
+
+sub logit {
+ my $now = localtime;
+ print $LOGF "$now: @_";
+}
+
# This script is called from udev with two arguments
# it outputs the new name (if any) to stdout
if ($#ARGV != 1) {
@@ -199,12 +226,24 @@ my $ifname = $ARGV[0];
my $hwaddr = $ARGV[1];
lock_file;
+
+# Need to log to file instead of syslog because this can be called by
+# udev running early in boot before syslog is started.
+open_logfile;
+
+logit("Starting vyatta_net_name for $ifname $hwaddr\n");
+
my $newname;
if ( -d $VYATTACFG ) {
$newname = hotplug($ifname, $hwaddr);
} else {
$newname = coldplug($ifname, $hwaddr);
}
+
+logit("Returning $newname for $ifname $hwaddr\n");
+
+close_logfile;
+
unlock_file;
print "$newname\n" if ($newname);