diff options
author | DmitriyEshenko <dmitriy.eshenko@vyos.io> | 2019-12-24 16:30:59 +0000 |
---|---|---|
committer | DmitriyEshenko <dmitriy.eshenko@vyos.io> | 2019-12-24 16:30:59 +0000 |
commit | 55b7799a3699924559fcfec11eb32c61257087b1 (patch) | |
tree | ec8f465422b6c887318bd4bb8242d4c4e0321924 | |
parent | 36c4bc42fda37bedef5aa1c9aacff3d217ea1773 (diff) | |
download | vyatta-cfg-system-55b7799a3699924559fcfec11eb32c61257087b1.tar.gz vyatta-cfg-system-55b7799a3699924559fcfec11eb32c61257087b1.zip |
T1903: Implement predefined interface naming for VMWare
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | scripts/vyatta_net_name | 37 | ||||
-rw-r--r-- | sysconf/64-vyos-vmware-net.rules | 14 | ||||
-rw-r--r-- | sysconf/65-vyatta-net.rules | 7 |
4 files changed, 49 insertions, 10 deletions
diff --git a/Makefile.am b/Makefile.am index 8ccd7887..f95356b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -100,6 +100,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 diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name index 53ae9fba..f4251892 100755 --- a/scripts/vyatta_net_name +++ b/scripts/vyatta_net_name @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; diff --git a/sysconf/64-vyos-vmware-net.rules b/sysconf/64-vyos-vmware-net.rules new file mode 100644 index 00000000..66a4a069 --- /dev/null +++ b/sysconf/64-vyos-vmware-net.rules @@ -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" diff --git a/sysconf/65-vyatta-net.rules b/sysconf/65-vyatta-net.rules index 0f4b9006..2b48c121 100644 --- a/sysconf/65-vyatta-net.rules +++ b/sysconf/65-vyatta-net.rules @@ -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" |