Skip to content

Commit

Permalink
T1903: Implement predefined interface naming for VMWare
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyEshenko committed Dec 26, 2019
1 parent 0b8818d commit 4fa0b07
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ udevrulesdir = /lib/udev/rules.d
libudev_SCRIPTS = scripts/vyatta_net_name
udevrules_DATA = sysconf/65-vyatta-net.rules
udevrules_DATA += sysconf/42-qemu-usb.rules
udevrules_DATA += sysconf/64-vyos-vmware-net.rules

cronhourlydir = /etc/cron.hourly
cronhourly_SCRIPTS = sysconf/vyatta-logrotate-hourly
Expand Down
37 changes: 27 additions & 10 deletions scripts/vyatta_net_name
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sub logit {

# Determine network name to use based on Vyatta config during boot
sub coldplug {
my ($ifname, $hwaddr) = @_;
my ($ifname, $hwaddr, $predef_ifname) = @_;

# at this time root directory is read-only so use log file instead
mkdir ($UDEVLOG);
Expand Down Expand Up @@ -168,8 +168,14 @@ sub coldplug {
}
}

$newname = biosdevname($ifname);
logit($log, "biosdevname for $ifname returned '$newname'\n");
if ($predef_ifname) {
$newname = $predef_ifname;
logit($log, "predefined interface name for $ifname returned '$newname'\n");
}
else {
$newname = biosdevname($ifname);
logit($log, "biosdevname for $ifname returned '$newname'\n");
}

unless (is_available($interfaces, $newname)) {
$newname = find_available($interfaces, $newname);
Expand All @@ -185,7 +191,7 @@ sub coldplug {

# Determine name from active config
sub hotplug {
my ($ifname, $hwaddr) = @_;
my ($ifname, $hwaddr, $predef_ifname) = @_;

# real filesystem available use real logging
openlog("vyatta-net-name", "", LOG_DAEMON);
Expand All @@ -211,8 +217,14 @@ sub hotplug {
return $newname;
}

$newname = biosdevname($ifname);
syslog(LOG_DEBUG, "biosdevname for %s returned '%s'", $ifname, $newname);
if ($predef_ifname) {
$newname = $predef_ifname;
syslog(LOG_DEBUG, "predefined interface name for %s returned '%s'", $ifname, $newname);
}
else{
$newname = biosdevname($ifname);
syslog(LOG_DEBUG, "biosdevname for %s returned '%s'", $ifname, $newname);
}

unless (is_available($interfaces, $newname)) {
$newname = find_available($interfaces, $newname);
Expand All @@ -238,21 +250,26 @@ sub unlock_file {
$LOCKF = undef;
}

# This script is called from udev with two arguments
# This script is called from udev with two or three arguments
# it outputs the new name (if any) to stdout
if ($#ARGV != 1) {
if ($#ARGV > 2 or $#ARGV < 1) {
die "vyatta_net_name called with wrong args:" . join(' ', @ARGV) . "\n";
}

my $ifname = $ARGV[0];
my $hwaddr = $ARGV[1];

my $predef_ifname = "";
if ($ARGV[2]){
$predef_ifname = $ARGV[2];
}

lock_file;
my $newname;
if ( -d $VYATTACFG ) {
$newname = hotplug($ifname, $hwaddr);
$newname = hotplug($ifname, $hwaddr, $predef_ifname);
} else {
$newname = coldplug($ifname, $hwaddr);
$newname = coldplug($ifname, $hwaddr, $predef_ifname);
}
unlock_file;

Expand Down
14 changes: 14 additions & 0 deletions sysconf/64-vyos-vmware-net.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ATTR{[dmi/id]sys_vendor}!="VMware, Inc.", GOTO="end_vmware_nic"

ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet0", ENV{VYOS_IFNAME}="eth0"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet1", ENV{VYOS_IFNAME}="eth1"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet2", ENV{VYOS_IFNAME}="eth2"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet3", ENV{VYOS_IFNAME}="eth3"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet4", ENV{VYOS_IFNAME}="eth4"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet5", ENV{VYOS_IFNAME}="eth5"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet6", ENV{VYOS_IFNAME}="eth6"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet7", ENV{VYOS_IFNAME}="eth7"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet8", ENV{VYOS_IFNAME}="eth8"
ACTION=="add", SUBSYSTEM=="net", ATTRS{label}=="Ethernet9", ENV{VYOS_IFNAME}="eth9"

LABEL="end_vmware_nic"
7 changes: 7 additions & 0 deletions sysconf/65-vyatta-net.rules
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ KERNEL!="eth*|wlan*", GOTO="vyatta_net_end"
# ignore "secondary" monitor interfaces of mac80211 drivers
KERNEL=="wlan*", ATTRS{type}=="803", GOTO="vyatta_net_end"

# If using VyOS predefined names
ENV{VYOS_IFNAME}!="eth*", GOTO="end_vyos_predef_names"

DRIVERS=="?*", PROGRAM="vyatta_net_name %k $attr{address} $env{VYOS_IFNAME}", NAME="%c", GOTO="vyatta_net_end"

LABEL="end_vyos_predef_names"

# ignore interfaces without a driver link like bridges and VLANs
DRIVERS=="?*", PROGRAM="vyatta_net_name %k $attr{address}", NAME="%c"

Expand Down

0 comments on commit 4fa0b07

Please sign in to comment.