From a919283f045a10bfd047f28b1bd720bf53a0058e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 3 Mar 2009 08:39:51 -0800 Subject: Extend vyatta-interfaces to do device name checking Have one central place for validity checks. --- scripts/vyatta-interfaces.pl | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 89b6e1e..2471c01 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -48,6 +48,16 @@ my $dhcp_daemon = '/sbin/dhclient'; my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient); my ($check_name, $show_names, $intf_cli_path, $vif_name); +sub usage() { + print "Usage: $0 --dev= --check=\n"; + print " $0 --dev= --valid-mac=\n"; + print " $0 --dev= --eth-addr-update=\n"; + print " $0 --dev= --eth-addr-delete=\n"; + print " $0 --dev= --valid-addr={|dhcp}\n"; + print " $0 --show=\n"; + exit 1; +} + GetOptions("eth-addr-update=s" => \$eth_update, "eth-addr-delete=s" => \$eth_delete, "valid-addr=s" => \$addr, @@ -58,7 +68,7 @@ GetOptions("eth-addr-update=s" => \$eth_update, "check=s" => \$check_name, "show=s" => \$show_names, "vif=s" => \$vif_name, -); +) or usage(); if ($eth_update) { update_eth_addrs($eth_update, $dev); } if ($eth_delete) { delete_eth_addrs($eth_delete, $dev); } @@ -66,7 +76,7 @@ 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 ($check_name) { is_valid_name($check_name, $dev); } if ($show_names) { show_interfaces($show_names); } sub is_ip_configured { @@ -427,12 +437,17 @@ sub op_dhcp_command { } sub is_valid_name { - my $name = shift; - my $intf = new Vyatta::Interface($name); - - exit 0 if $intf; + my ($type, $name) = @_; + die "Missing --dev argument\n" unless $name; - die "$name: is not a known interface name\n"; + my $intf = new Vyatta::Interface($name); + die "$name does not match any known interface name type\n" + unless $intf; + die "$name is a ", $intf->type(), " interface not an $type interface\n" + if ($intf->type() ne $type); + die "$type interface $name does not exist on system\n" + unless grep { $name eq $_ } getInterfaces(); + exit 0; } # generate one line with all known interfaces (for allowed) -- cgit v1.2.3