From 6ece71ecf691431006ae1389f9ab575a1a39683e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 21 May 2009 10:36:47 -0700 Subject: Add script option to check if interface is up Better than reading sysfs directly. --- scripts/vyatta-interfaces.pl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'scripts/vyatta-interfaces.pl') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index d0d8fa1..3e5beaa 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -48,7 +48,8 @@ use warnings; 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, $warn_name, $show_path); +my ($check_name, $show_names, $intf_cli_path, $vif_name, $warn_name); +my ($check_up, $show_path); sub usage { print "Usage: $0 --dev= --check=\n"; @@ -58,6 +59,7 @@ sub usage { print " $0 --dev= --eth-addr-delete=\n"; print " $0 --dev= --valid-addr={|dhcp}\n"; print " $0 --dev= --path\n"; + print " $0 --dev= --isup\n"; print " $0 --show=\n"; exit 1; } @@ -74,6 +76,7 @@ GetOptions("eth-addr-update=s" => \$eth_update, "vif=s" => \$vif_name, "warn" => \$warn_name, "path" => \$show_path, + "isup" => \$check_up, ) or usage(); update_eth_addrs($eth_update, $dev) if ($eth_update); @@ -86,6 +89,7 @@ is_valid_name($check_name, $dev) if ($check_name); exists_name($dev) if ($warn_name); show_interfaces($show_names) if ($show_names); show_config_path($dev) if ($show_path); +is_up($dev) if ($check_up); exit 0; sub is_ip_configured { @@ -106,6 +110,16 @@ sub is_ip_duplicate { return is_ip_configured($intf, $ip); } +sub is_up { + my $name = shift; + my $intf = new Vyatta::Interface($name); + + die "Unknown interface type for $name" unless $intf; + + exit 0 if ($intf->up()); + exit 1; +} + sub touch { my $file = shift; my $t = time; -- cgit v1.2.3