summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Vyatta/Interface.pm16
-rwxr-xr-xscripts/vyatta-interfaces.pl45
2 files changed, 50 insertions, 11 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm
index ea9c40f..017b7e4 100644
--- a/lib/Vyatta/Interface.pm
+++ b/lib/Vyatta/Interface.pm
@@ -77,6 +77,9 @@ sub new {
my $class = ref($that) || $that;
my ($dev, $vif);
+ # need argument to constructor
+ return unless $name;
+
# Strip off vif from name
if ( $name =~ m/(\w)+\.(\d)+/ ) {
$dev = $1;
@@ -87,20 +90,21 @@ sub new {
foreach my $prefix (keys %net_prefix) {
next unless $dev =~ /$prefix/;
- my $path = $net_prefix{$prefix}{path};
+ my $type = $net_prefix{$prefix}{path};
my $vifpath = $net_prefix{$prefix}{vif};
# Interface name has vif, but this type doesn't support vif!
return if ( $vif && !$vifpath );
# Check path if given
- return if ( $#_ >= 0 && join( ' ', @_ ) ne $path );
+ return if ( $#_ >= 0 && join( ' ', @_ ) ne $type );
- $path = "interfaces $path $dev";
+ my $path = "interfaces $type $dev";
$path .= " $vifpath $vif" if $vif;
my $self = {
name => $name,
+ type => $type,
path => $path,
dev => $dev,
vif => $vif,
@@ -108,7 +112,6 @@ sub new {
bless $self, $class;
return $self;
-
}
return; # nothing
@@ -135,6 +138,11 @@ sub physicalDevice {
return $self->{dev};
}
+sub type {
+ my $self = shift;
+ return $self->{type};
+}
+
## Configuration checks
sub configured {
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl
index de31e5e..9596632 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -33,6 +33,7 @@
use lib "/opt/vyatta/share/perl5/";
use Vyatta::Config;
use Vyatta::Misc;
+use Vyatta::Interface;
use Getopt::Long;
use POSIX;
@@ -44,7 +45,8 @@ use warnings;
my $dhcp_daemon = '/sbin/dhclient';
-my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient, $intf_cli_path);
+my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient);
+my ($check_name, $show_names, $intf_cli_path);
GetOptions("eth-addr-update=s" => \$eth_update,
"eth-addr-delete=s" => \$eth_delete,
@@ -53,14 +55,18 @@ GetOptions("eth-addr-update=s" => \$eth_update,
"valid-mac=s" => \$mac,
"set-mac=s" => \$mac_update,
"op-command=s" => \$op_dhclient,
+ "check=s" => \$check_name,
+ "show=s" => \$show_names,
);
-if (defined $eth_update) { update_eth_addrs($eth_update, $dev); }
-if (defined $eth_delete) { delete_eth_addrs($eth_delete, $dev); }
-if (defined $addr) { is_valid_addr($addr, $dev); }
-if (defined $mac) { is_valid_mac($mac, $dev); }
-if (defined $mac_update) { update_mac($mac_update, $dev); }
-if (defined $op_dhclient) { op_dhcp_command($op_dhclient, $dev); }
+if ($eth_update) { update_eth_addrs($eth_update, $dev); }
+if ($eth_delete) { delete_eth_addrs($eth_delete, $dev); }
+if ($addr) { is_valid_addr($addr, $dev); }
+if ($mac) { is_valid_mac($mac, $dev); }
+if ($mac_update) { update_mac($mac_update, $dev); }
+if ($op_dhclient) { op_dhcp_command($op_dhclient, $dev); }
+if ($check_name) { is_valid_name($check_name); }
+if ($show_names) { show_interfaces($show_names); }
sub is_ip_configured {
my ($intf, $ip) = @_;
@@ -430,6 +436,31 @@ sub op_dhcp_command {
}
+sub is_valid_name {
+ my $name = shift;
+ my $intf = new Vyatta::Interface($name);
+
+ exit 0 if $intf;
+
+ die "$name: is not a known interface name\n";
+}
+
+# generate one line with all known interfaces (for allowed)
+sub show_interfaces {
+ my $type = shift;
+ my @interfaces = getInterfaces();
+
+ foreach my $name (@interfaces) {
+ my $intf = new Vyatta::Interface($name);
+ next unless $intf;
+
+ next unless ($type eq 'all' || $type eq $intf->type());
+ print $name, ' ';
+ }
+ print "\n";
+ exit 0;
+}
+
exit 0;
# end of file