diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-03-03 08:39:51 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-03-03 08:39:51 -0800 |
commit | a919283f045a10bfd047f28b1bd720bf53a0058e (patch) | |
tree | 8e3834660a578b466a93976896b114ae73a43793 | |
parent | a6316a2b0f98b50b2f36bfa440b8dd432df98131 (diff) | |
download | vyatta-cfg-a919283f045a10bfd047f28b1bd720bf53a0058e.tar.gz vyatta-cfg-a919283f045a10bfd047f28b1bd720bf53a0058e.zip |
Extend vyatta-interfaces to do device name checking
Have one central place for validity checks.
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 29 |
1 files changed, 22 insertions, 7 deletions
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=<interface> --check=<type>\n"; + print " $0 --dev=<interface> --valid-mac=<aa:aa:aa:aa:aa:aa>\n"; + print " $0 --dev=<interface> --eth-addr-update=<aa:aa:aa:aa:aa:aa>\n"; + print " $0 --dev=<interface> --eth-addr-delete=<aa:aa:aa:aa:aa:aa>\n"; + print " $0 --dev=<interface> --valid-addr={<a.b.c.d>|dhcp}\n"; + print " $0 --show=<type>\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) |