From 7500ce0fc8ed65da2dd763a193122c5769b95520 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 28 Sep 2021 14:37:22 -0500 Subject: interface-names: T3869: remove legacy code --- Makefile.am | 4 - scripts/system/vyatta_interface_rescan | 168 -------------------- scripts/vyatta_net_name | 278 --------------------------------- 3 files changed, 450 deletions(-) delete mode 100755 scripts/system/vyatta_interface_rescan delete mode 100755 scripts/vyatta_net_name diff --git a/Makefile.am b/Makefile.am index 8d2c8194..940bccce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,6 @@ sbin_SCRIPTS += scripts/vyatta-dhcp-helper.pl sbin_SCRIPTS += scripts/check_file_in_config_dir sbin_SCRIPTS += scripts/vyatta-grub-setup sbin_SCRIPTS += scripts/standalone_root_pw_reset -sbin_SCRIPTS += scripts/system/vyatta_interface_rescan sbin_SCRIPTS += scripts/system/vyatta_update_sysctl.pl sbin_SCRIPTS += scripts/snmp/if-mib-alias sbin_SCRIPTS += scripts/vyatta-interfaces.pl @@ -41,9 +40,6 @@ sysconf_DATA += sysconf/LICENSE sysconf_DATA += sysconf/filecaps sysconf_DATA += sysconf/netdevice -libudevdir = /lib/udev -libudev_SCRIPTS = scripts/vyatta_net_name - rsyslogdir = /etc/rsyslog.d curver_DATA = cfg-version/vrrp@3 diff --git a/scripts/system/vyatta_interface_rescan b/scripts/system/vyatta_interface_rescan deleted file mode 100755 index 2e8ad8ca..00000000 --- a/scripts/system/vyatta_interface_rescan +++ /dev/null @@ -1,168 +0,0 @@ -#! /usr/bin/perl - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. -# All Rights Reserved. - -# Thus updates the configuration to add new interfaces. -# It is run on boot after udev and before vyatta configuration. - -use strict; -use lib "/opt/vyatta/share/perl5/"; -use Sys::Syslog qw(:standard :macros); -use XorpConfigParser; -use File::Copy; - -my $TMPFILE = "/tmp/config.boot.$$"; - -# These vendors are known to violate the local MAC address assignment convention -my %whitelist = ( - '02:07:01' => 'Interlan', - '02:60:60' => '3Com', - '02:60:8c' => '3Com', - '02:a0:c9' => 'Intel', - '02:aa:3c' => 'Olivetti', - '02:cf:1f' => 'CMC', - '02:e0:3b' => 'Prominet', - '02:e6:d3' => 'BTI', - '52:54:00' => 'Realtek', - '52:54:4c' => 'Novell 2000', - '52:54:ab' => 'Realtec', - 'e2:0c:0f' => 'Kingston Technologies', -); - -# Ignore devices with local assigned or invalid mac address, -# these devices don't have a persistent address -sub persistent_address { - my $mac = shift; - - return if ($mac eq '00:00:00:00:00:00'); # zero address is reserved - - # get first octet - return unless ($mac =~ /^([0-9a-f][0-9a-f]):/); - my $oct0 = hex($1); - - return if ($oct0 & 0x1); # skip it is a multicast address - - return 1 unless ($oct0 & 0x2); # this is good, not locally assigned - - return 1 if ( -d '/proc/xen' ); # workaround Xen breakage - - # unless it is in whitelist, it is non persistent - $mac =~ /^([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])/; - return $whitelist{$1}; -} - -# Map from eth0 to ethernet -# TODO make smarter if more types -sub interface_type { - my $ifname = shift; - - return "ethernet" if ($ifname =~ /^eth/); - return "wireless" if ($ifname =~ /^wlan/); - - die "unknown interface name %s\n", $ifname; -} - -sub get_hwid { - my $name = shift; - - open (my $f, '<', $name) - or die "Can't open $name : $!"; - - my $hwaddr = <$f>; - chomp $hwaddr; - close $f; - - return $hwaddr; -} - -# Determine phy for wlan device -# (This is ugly) -sub get_phy { - my $wlan = shift; - my $phypath = "/sys/class/net/$wlan/phy80211"; - - # link should be: ../../ieee80211/phy0 - return unless (readlink($phypath) =~ m!../../ieee80211/(phy[0-9]+)$!); - - return $1; -} - -# vyatta_net_name leaves files in /run/udev/vyatta -# the filename is the interface and the contents are the hardware id -sub interface_rescan { - my ($VYATTAUDEV, $BOOTFILE) = @_; - - # parse existing config - my $xcp = new XorpConfigParser(); - $xcp->parse($BOOTFILE); - - # get list of changed interfaces - opendir( my $dir, $VYATTAUDEV ) - or die "Can't open $VYATTAUDEV : $!"; - my @interfaces = grep { ! /^\./ } readdir($dir); - close $dir; - - foreach my $ifname (sort @interfaces) { - my $hwaddr = get_hwid("$VYATTAUDEV/$ifname"); - - # Ignore devices that disappear (or get renamed) - unless (-d "/sys/class/net/$ifname") { - syslog(LOG_INFO, "%s: does not exist", $ifname); - next; - } - - unless (persistent_address($hwaddr)) { - syslog(LOG_NOTICE, "%s: skipping address %s is not persistent", - $ifname, $hwaddr); - next; - } - - # Add new entry to config - my $ifpath = interface_type($ifname) . " $ifname"; - - syslog(LOG_INFO, "add config for %s hw-id %s", $ifname, $hwaddr); - $xcp->create_node(['interfaces',$ifpath,"hw-id $hwaddr"]); - - # Add existing phy entry for wireless - if ($ifname =~ /^wlan/) { - my $phy = get_phy($ifname); - $xcp->create_node(['interfaces',$ifpath,"physical-device $phy"]) if $phy; - } - - } - - # Rewrite new config file - open (my $tmp, '>', $TMPFILE) - or die "Can't open $TMPFILE : $!"; - - select $tmp; - $xcp->output(0); - select STDOUT; - close $tmp; - - copy($TMPFILE, $BOOTFILE) - or die "Can't copy $TMPFILE to $BOOTFILE : $!"; - - unlink($TMPFILE); -} - -# main -die "vyatta_interface_rescan called with wrong args" - unless ($#ARGV == 1); - -openlog("vyatta-interface-rescan", "", LOG_DAEMON); - -interface_rescan(@ARGV); -exit 0; - diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name deleted file mode 100755 index d61ac6a3..00000000 --- a/scripts/vyatta_net_name +++ /dev/null @@ -1,278 +0,0 @@ -#! /usr/bin/perl - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. -# All Rights Reserved. - -use strict; -use lib "/opt/vyatta/share/perl5/"; -use XorpConfigParser; -use Vyatta::Config; -use Sys::Syslog qw(:standard :macros); -use Fcntl qw(:flock); - -my $BOOTFILE = "/opt/vyatta/etc/config/config.boot"; -my $VYATTACFG = "/opt/vyatta/config/active/interfaces"; - -my $UDEVDIR = "/run/udev/"; -my $VYATTAUDEV = $UDEVDIR . "vyatta"; -my $LOCKFILE = $UDEVDIR . ".vyatta-lock"; -my $UDEVLOG = $UDEVDIR . "log/"; -my $LOGFILE = $UDEVLOG . "vyatta-net-name.coldplug"; - -# Check if interface name is free to use -sub is_available { - my ($interfaces, $ifname) = @_; - - my $count = grep { $_ eq $ifname } values %$interfaces; - return ($count == 0); -} - -# Find next available interface name -sub find_available { - my ($interfaces, $ifprefix) = @_; - $ifprefix =~ s/\d+$//; - - for (my $id = 0; ; $id++) { - my $ifname = sprintf("%s%d", $ifprefix, $id); - - # is it in Vyatta config? - return $ifname if (is_available($interfaces, $ifname)); - } -} - -# Find the hardware id in the parsed config node for interface -sub get_hwid_from_children { - my $children = shift; - - foreach my $attr (@$children) { - next unless (($attr->{'name'} =~ /^hw-id ([0-9a-f:]+)/) || ($attr->{'name'} =~ /^hw-id "([0-9a-f:]+)"/)); - return $1; - } - - return; # not found -} - - -# Leave file for vyatta_interface_rescan -sub leave_rescan_hint { - my ($ifname, $hwaddr) = @_; - my $name = "$VYATTAUDEV/$ifname"; - - mkdir($VYATTAUDEV); - open (my $f, '>', $name) - or die "Can't create $name : $!"; - - print {$f} "$hwaddr\n"; - close $f; - return 1; -} - -# Use biosdevname program (ethernet only) -# to try and find name based on PCI slot and DMI info -sub biosdevname { - my $ifname = shift; - - # biosdevname works only on ethernet devices - return $ifname unless ($ifname =~ /^eth/); - - # Don't use biosdevname in Xen - return $ifname if ( -d "/proc/xen" ); - - # Let the interface name changes ordered by previous invocations of this - # script complete before we call biosdevname. If we don't, biosdevame - # may generate incorrect name. - sleep 1; - - my $biosname = `/sbin/biosdevname --policy all_ethN -i $ifname 2>/dev/null`; - chomp $biosname; - - # if biosdevname has no answer it outputs a nothing - return ($biosname eq '') ? $ifname : $biosname; -} - -# parse vyatta config.boot -# if file does not then running before off livecd then return empty hash -sub parse_config_boot { - my $interfaces = {}; - - if ( -f $BOOTFILE ) { - my $xcp = new XorpConfigParser(); - $xcp->parse($BOOTFILE); - - my $inode = $xcp->get_node(['interfaces']); - if ($inode) { - foreach my $child (@{$inode->{'children'}}) { - # is hwid defined in config? - my $hwid = get_hwid_from_children($child->{'children'}); - next unless $hwid; - - # split into type 'ethernet' and 'eth0' - my ($type, $intf) = ($child->{'name'} =~ /^(\w+) (\w+)/); - next unless defined($type); - next unless ($type eq 'ethernet') || ($type eq 'wireless'); - - $interfaces->{$hwid} = $intf; - } - } - } - - return $interfaces; -} - -sub logit { - my ($log, $msg) = @_; - my $now = localtime; - print $log "$now: $msg"; -} - -# Determine network name to use based on Vyatta config during boot -sub coldplug { - my ($ifname, $hwaddr, $predef_ifname) = @_; - - # at this time root directory is read-only so use log file instead - mkdir ($UDEVLOG); - open (my $log, '>>', $LOGFILE) - or die "Can't open $LOGFILE : $!"; - logit($log, "lookup $ifname $hwaddr\n"); - - # parse config file to produce map of existing hw-id values - my $interfaces = parse_config_boot(); - - # is name already in config file - my $newname = $interfaces->{$hwaddr}; - if ($newname) { - logit($log, "use hw-id $hwaddr in config mapped to '$newname'\n"); - return $newname; - } - - # add already assigned names - if (opendir(my $dir, $VYATTAUDEV)) { - foreach my $intf (grep { ! /^\./ } readdir($dir)) { - if (open (my $f, '<', "$VYATTAUDEV/$intf")) { - my $hwid = <$f>; - close $f; - chomp $hwid; - - $interfaces->{$hwid} = $intf; - } - } - } - - 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); - } - - logit($log, "new name for '$ifname' is '$newname'\n"); - close $log; - - leave_rescan_hint($newname, $hwaddr); - - return $newname; -} - -# Determine name from active config -sub hotplug { - my ($ifname, $hwaddr, $predef_ifname) = @_; - - # real filesystem available use real logging - openlog("vyatta-net-name", "", LOG_DAEMON); - - # Parse active config - my $cfg = new Vyatta::Config; - $cfg->setLevel('interfaces'); - - my $interfaces = {}; - foreach my $type ($cfg->listOrigNodes()) { - next unless ($type eq 'ethernet') || ($type eq 'wireless'); - foreach my $intf ($cfg->listOrigNodes($type)) { - my $hwid = $cfg->returnOrigValue("$type $intf hw-id"); - next unless $hwid; - # TBD this could be a hash with name and path? - $interfaces->{$hwid} = $intf; - } - } - - my $newname = $interfaces->{$hwaddr}; - if ($newname) { - syslog(LOG_DEBUG, "use hw-id %s in config mapped to '%s'", $hwaddr, $newname); - return $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); - } - - syslog(LOG_INFO, "new name for '%s' is '%s'", $ifname, $newname); - - return $newname; -} - -my $LOCKF; -sub lock_file { - open ($LOCKF, '>', $LOCKFILE) - or die "Can't open $LOCKFILE : $!"; - - flock ($LOCKF, LOCK_EX) - or die "Can't lock $LOCKFILE : $!"; - -} - -sub unlock_file { - close $LOCKF; - $LOCKF = undef; -} - -# This script is called from udev with two or three arguments -# it outputs the new name (if any) to stdout -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, $predef_ifname); -} else { - $newname = coldplug($ifname, $hwaddr, $predef_ifname); -} -unlock_file; - -print "$newname\n" if ($newname); - -exit 0; -- cgit v1.2.3