diff options
27 files changed, 267 insertions, 383 deletions
diff --git a/Makefile.am b/Makefile.am index 7de4e17..9e60f85 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ cfgdir = $(datadir)/vyatta-cfg/templates -share_perl5dir = /opt/vyatta/share/perl5 +share_perl5dir = /opt/vyatta/share/perl5/Vyatta completiondir = /etc/bash_completion.d initddir = /etc/init.d defaultdir = /etc/default @@ -45,13 +45,12 @@ sbin_SCRIPTS += scripts/vyatta-interfaces.pl sbin_SCRIPTS += scripts/vyatta-irqaffin sbin_SCRIPTS += scripts/vyatta-check-typeless-node.pl -share_perl5_SCRIPTS = scripts/VyattaConfig.pm -share_perl5_SCRIPTS += scripts/VyattaConfigDOMTree.pm -share_perl5_SCRIPTS += scripts/VyattaConfigOutput.pm -share_perl5_SCRIPTS += scripts/VyattaConfigLoad.pm -share_perl5_SCRIPTS += scripts/VyattaMisc.pm -share_perl5_SCRIPTS += scripts/VyattaTypeChecker.pm -share_perl5_SCRIPTS += scripts/VyattaIpTablesAddressFilter.pm +share_perl5_DATA = lib/Vyatta/Config.pm +share_perl5_DATA += lib/Vyatta/Misc.pm +share_perl5_DATA += lib/Vyatta/TypeChecker.pm +share_perl5_DATA += lib/Vyatta/ConfigDOMTree.pm +share_perl5_DATA += lib/Vyatta/ConfigOutput.pm +share_perl5_DATA += lib/Vyatta/ConfigLoad.pm default_DATA = etc/default/vyatta-cfg diff --git a/debian/rules b/debian/rules index 244a67b..b3c442a 100755 --- a/debian/rules +++ b/debian/rules @@ -17,7 +17,7 @@ DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) PACKAGE=vyatta-cfg PKGDIR=$(CURDIR)/debian/$(PACKAGE) -CFLAGS = -Wall -g +CFLAGS = -Wall -g configure = ./configure configure += --host=$(DEB_HOST_GNU_TYPE) @@ -31,7 +31,7 @@ configure += LDFLAGS="-Wl,-z,defs" ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) CFLAGS += -O0 else - CFLAGS += -O2 + CFLAGS += -Os endif configure: configure.ac Makefile.am @@ -88,7 +88,11 @@ binary-indep: build install dh_compress dh_fixperms dh_installdeb - dh_gencontrol + if [ -f "../.VYATTA_DEV_BUILD" ]; then \ + dh_gencontrol -- -v999.dev; \ + else \ + dh_gencontrol; \ + fi dh_md5sums dh_builddeb diff --git a/etc/init.d/vyatta-ofr b/etc/init.d/vyatta-ofr index 75a03b4..4fb4c1e 100755 --- a/etc/init.d/vyatta-ofr +++ b/etc/init.d/vyatta-ofr @@ -66,15 +66,10 @@ have_rl_system () { # if necessary, provide initial config init_bootfile () { - # try floppy - # if we do not discover an fd device, try loading the floppy module - grep -q fd /proc/devices || modprobe -q floppy 2>/dev/null - grep -q ext2 /proc/filesystems || modprobe -q ext2 2>/dev/null - grep -q vfat /proc/filesystems || modprobe -q vfat 2>/dev/null if [ ! -d /media/floppy/config ] && grep -q fd /proc/devices then mkdir -p /media/floppy - mount /dev/fd0 /media/floppy -o sync || + mount /dev/fd0 /media/floppy -o sync || mount -t ext2 /dev/fd0 /media/floppy -o sync || mount -t vfat /dev/fd0 /media/floppy fi 2>/dev/null diff --git a/scripts/VyattaConfig.pm b/lib/Vyatta/Config.pm index 9ddc8ef..9e57448 100755 --- a/scripts/VyattaConfig.pm +++ b/lib/Vyatta/Config.pm @@ -19,11 +19,11 @@ # All Rights Reserved. # **** End License **** -package VyattaConfig; +package Vyatta::Config; use strict; -use VyattaConfigDOMTree; +use Vyatta::ConfigDOMTree; my %fields = ( _changes_only_dir_base => $ENV{VYATTA_CHANGES_ONLY_DIR}, @@ -84,7 +84,7 @@ sub listNodes { $path = $self->{_new_config_dir_base} . $self->{_current_dir_level}; } - #print "DEBUG VyattaConfig->listNodes(): path = $path\n"; + #print "DEBUG Vyatta::Config->listNodes(): path = $path\n"; opendir DIR, "$path" or return (); @nodes = grep !/^\./, readdir DIR; closedir DIR; @@ -94,7 +94,7 @@ sub listNodes { my $tmp = pop (@nodes); $tmp =~ s/\n//g; $tmp =~ s/%2F/\//g; - #print "DEBUG VyattaConfig->listNodes(): node = $tmp\n"; + #print "DEBUG Vyatta::Config->listNodes(): node = $tmp\n"; push @nodes_modified, $tmp; } @@ -119,7 +119,7 @@ sub listOrigNodes { $path = $self->{_active_dir_base} . $self->{_current_dir_level}; } - #print "DEBUG VyattaConfig->listNodes(): path = $path\n"; + #print "DEBUG Vyatta::Config->listNodes(): path = $path\n"; opendir DIR, "$path" or return (); @nodes = grep !/^\./, readdir DIR; closedir DIR; @@ -129,7 +129,7 @@ sub listOrigNodes { my $tmp = pop (@nodes); $tmp =~ s/\n//g; $tmp =~ s/%2F/\//g; - #print "DEBUG VyattaConfig->listNodes(): node = $tmp\n"; + #print "DEBUG Vyatta::Config->listNodes(): node = $tmp\n"; push @nodes_modified, $tmp; } @@ -154,7 +154,7 @@ sub listOrigNodesNoDef { $path = $self->{_active_dir_base} . $self->{_current_dir_level}; } - #print "DEBUG VyattaConfig->listNodes(): path = $path\n"; + #print "DEBUG Vyatta::Config->listNodes(): path = $path\n"; opendir DIR, "$path" or return (); @nodes = grep !/^\./, readdir DIR; closedir DIR; @@ -164,7 +164,7 @@ sub listOrigNodesNoDef { my $tmp = pop (@nodes); $tmp =~ s/\n//g; $tmp =~ s/%2F/\//g; - #print "DEBUG VyattaConfig->listNodes(): node = $tmp\n"; + #print "DEBUG Vyatta::Config->listNodes(): node = $tmp\n"; if ($tmp ne 'def') { push @nodes_modified, $tmp; } @@ -376,13 +376,13 @@ sub isChangedOrDeleted { sub isAdded { my ($self, $node) = @_; - #print "DEBUG VyattaConfig->isAdded(): node $node\n"; + #print "DEBUG Vyatta::Config->isAdded(): node $node\n"; # let's setup the filepath for the modify dir $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; my $filepathNewConfig = "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node"; - #print "DEBUG VyattaConfig->isAdded(): filepath $filepathNewConfig\n"; + #print "DEBUG Vyatta::Config->isAdded(): filepath $filepathNewConfig\n"; # if the node doesn't exist in the modify dir, it's not # been added. so short circuit and return false. @@ -415,7 +415,7 @@ sub listNodeStatus { @nodes = $self->listNodes("$path"); foreach my $node (@nodes) { if ($node =~ /.+/) { - #print "DEBUG VyattaConfig->listNodeStatus(): node $node\n"; + #print "DEBUG Vyatta::Config->listNodeStatus(): node $node\n"; # No deleted nodes -- added, changed, ot static only. if ($self->isAdded("$path $node")) { $nodehash{$node} = "added"; } elsif ($self->isChanged("$path $node")) { $nodehash{$node} = "changed"; } @@ -433,7 +433,7 @@ sub createActiveDOMTree { my $self = shift; - my $tree = new VyattaConfigDOMTree($self->{_active_dir_base} . $self->{_current_dir_level},"active"); + my $tree = new Vyatta::ConfigDOMTree($self->{_active_dir_base} . $self->{_current_dir_level},"active"); return $tree; } @@ -443,7 +443,7 @@ sub createChangesOnlyDOMTree { my $self = shift; - my $tree = new VyattaConfigDOMTree($self->{_changes_only_dir_base} . $self->{_current_dir_level}, + my $tree = new Vyatta::ConfigDOMTree($self->{_changes_only_dir_base} . $self->{_current_dir_level}, "changes_only"); return $tree; @@ -453,11 +453,9 @@ sub createChangesOnlyDOMTree { sub createNewConfigDOMTree { my $self = shift; + my $level = $self->{_new_config_dir_base} . $self->{_current_dir_level}; - my $tree = new VyattaConfigDOMTree($self->{_new_config_dir_base} . $self->{_current_dir_level}, - "new_config"); - - return $tree; + return new Vyatta::ConfigDOMTree($level, "new_config"); } @@ -601,3 +599,5 @@ sub compareValueLists { } return %comp_hash; } + +1; diff --git a/scripts/VyattaConfigDOMTree.pm b/lib/Vyatta/ConfigDOMTree.pm index 4e7ce31..865f17b 100755 --- a/scripts/VyattaConfigDOMTree.pm +++ b/lib/Vyatta/ConfigDOMTree.pm @@ -32,7 +32,7 @@ # # -package VyattaConfigDOMTree; +package Vyatta::ConfigDOMTree; use strict; @@ -350,7 +350,7 @@ sub _construct_dom_tree { $valuePresent++; } } elsif (-d $fn) { - my $subnode = new VyattaConfigDOMTree($fn,$entry); + my $subnode = new Vyatta::ConfigDOMTree($fn,$entry); if(defined $subnode) { if(! defined $self->{_subnodes} ) { $self->{_subnodes} = {}; @@ -368,3 +368,5 @@ sub _construct_dom_tree { return $self; } + +1; diff --git a/scripts/VyattaConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 5305dc8..f7c0154 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -18,13 +18,16 @@ # Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. # All Rights Reserved. -package VyattaConfigLoad; +package Vyatta::ConfigLoad; + +our @EXPORT = qw(getStartupConfigStatements loadConfigHierarchy getConfigDiff); +use base qw(Exporter); use strict; use sort 'stable'; -use lib "/opt/vyatta/share/perl5/"; +use lib "/opt/vyatta/share/perl5"; use XorpConfigParser; -use VyattaConfig; +use Vyatta::Config; # configuration ordering. higher rank configured before lower rank. my $default_rank = 0; @@ -390,7 +393,7 @@ sub findSetNodes { # $0: hash ref of config hierarchy. # return: hash containing the diff. sub getConfigDiff { - $active_cfg = new VyattaConfig; + $active_cfg = new Vyatta::Config; $new_cfg_ref = shift; @set_list = (); @delete_list = (); diff --git a/scripts/VyattaConfigOutput.pm b/lib/Vyatta/ConfigOutput.pm index fa0b274..ccb7f19 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/lib/Vyatta/ConfigOutput.pm @@ -27,11 +27,14 @@ # outputActiveConfig() # prints the "active" config. suitable for "saving", for example. -package VyattaConfigOutput; +package Vyatta::ConfigOutput; +our @EXPORT = qw(set_show_all set_hide_password outputActiveConfig outputNewConfig); +use base qw(Exporter); use strict; -use lib '/opt/vyatta/share/perl5/'; -use VyattaConfig; +use lib '/opt/vyatta/share/perl5'; +use Vyatta::Config; + use Sort::Versions; # whether to show default values @@ -324,7 +327,7 @@ sub displayChildren { # @ARGV: represents the 'root' path. the output starts at this point under # the new config. sub outputNewConfig { - $config = new VyattaConfig; + $config = new Vyatta::Config; $config->setLevel(join ' ', @_); my %rnodes = $config->listNodeStatus(); if (scalar(keys %rnodes) > 0) { @@ -363,7 +366,7 @@ sub outputNewConfig { # @ARGV: represents the 'root' path. the output starts at this point under # the active config. sub outputActiveConfig { - $config = new VyattaConfig; + $config = new Vyatta::Config; $config->setLevel(join ' ', @_); displayDeletedOrigChildren([ @_ ], '', 1); } diff --git a/scripts/VyattaMisc.pm b/lib/Vyatta/Misc.pm index 7072908..77bba36 100755 --- a/scripts/VyattaMisc.pm +++ b/lib/Vyatta/Misc.pm @@ -21,16 +21,79 @@ # All Rights Reserved. # **** End License **** -package VyattaMisc; +package Vyatta::Misc; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(getNetAddIP isIpAddress is_ip_v4_or_v6); -@EXPORT_OK = qw(getNetAddIP isIpAddress is_ip_v4_or_v6); +@EXPORT = qw(get_sysfs_value getNetAddIP isIpAddress is_ip_v4_or_v6); +@EXPORT_OK = qw(get_sysfs_value getNetAddIP isIpAddress is_ip_v4_or_v6 getPortRuleString); use strict; -use VyattaConfig; +use Vyatta::Config; + +sub get_sysfs_value { + my ($intf, $name) = @_; + + open (my $statf, '<', "/sys/class/net/$intf/$name") + or die "Can't open statistics file /sys/class/net/$intf/$name"; + + my $value = <$statf>; + chomp $value if defined $value; + close $statf; + return $value; +} + +# check if interace is configured to get an IP address using dhcp +sub is_dhcp_enabled { + my ($intf, $outside_cli) = @_; + + my $config = new Vyatta::Config; + if (!($outside_cli eq '')) { + $config->{_active_dir_base} = "/opt/vyatta/config/active/"; + } + + if ($intf =~ m/^eth/) { + if ($intf =~ m/(\w+)\.(\d+)/) { + $config->setLevel("interfaces ethernet $1 vif $2"); + } else { + $config->setLevel("interfaces ethernet $intf"); + } + } elsif ($intf =~ m/^br/) { + $config->setLevel("interfaces bridge $intf"); + } elsif ($intf =~ m/^bond/) { + if ($intf =~ m/(\w+)\.(\d+)/) { + $config->setLevel("interfaces bonding $1 vif $2"); + } else { + $config->setLevel("interfaces bonding $intf"); + } + } else { + # + # add other interfaces that can be configured to use dhcp above + # + return 0; + } + my @addrs = $config->returnOrigValues("address"); + foreach my $addr (@addrs) { + if (defined $addr && $addr eq "dhcp") { + return 1; + } + } + return 0; +} + +# return dhclient related files for interface +sub generate_dhclient_intf_files { + my $intf = shift; + my $dhclient_dir = '/var/lib/dhcp3/'; + + $intf =~ s/\./_/g; + my $intf_config_file = $dhclient_dir . 'dhclient_' . $intf . '.conf'; + my $intf_process_id_file = $dhclient_dir . 'dhclient_' . $intf . '.pid'; + my $intf_leases_file = $dhclient_dir . 'dhclient_' . $intf . '.leases'; + return ($intf_config_file, $intf_process_id_file, $intf_leases_file); + +} # getInterfacesIPadresses() returns IP addresses for the interface type passed to it # possible type of interfaces : 'broadcast', 'pointopoint', 'multicast', 'all' @@ -420,4 +483,4 @@ sub getPortRuleString { return ($rule_str, undef); } -return 1; +1; diff --git a/scripts/VyattaTypeChecker.pm b/lib/Vyatta/TypeChecker.pm index f77664f..124dc17 100755 --- a/scripts/VyattaTypeChecker.pm +++ b/lib/Vyatta/TypeChecker.pm @@ -21,9 +21,9 @@ # Perl module for type validation. # Usage 1: validate a value of a specific type. -# use VyattaTypeChecker; +# use Vyatta::TypeChecker; # ... -# if (VyattaTypeChecker::validateType('ipv4', '1.1.1.1')) { +# if (validateType('ipv4', '1.1.1.1')) { # # valid # ... # } else { @@ -33,7 +33,7 @@ # # Usage 2: find the type of a value (from a list of candidates), returns # undef if the value is not valid for any of the candidates. -# $valtype = VyattaTypeChecker::findType('1.1.1.1', 'ipv4', 'ipv6'); +# $valtype = findType('1.1.1.1', 'ipv4', 'ipv6'); # if (!defined($valtype)) { # # neither ipv4 nor ipv6 # ... @@ -45,7 +45,9 @@ # } # } -package VyattaTypeChecker; +package Vyatta::TypeChecker; +our @EXPORT = qw(findType validateType); +use base qw(Exporter); use strict; @@ -225,4 +227,3 @@ sub findType { } 1; - diff --git a/scripts/VyattaIpTablesAddressFilter.pm b/scripts/VyattaIpTablesAddressFilter.pm deleted file mode 100755 index 9789fef..0000000 --- a/scripts/VyattaIpTablesAddressFilter.pm +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/perl - -# Author: An-Cheng Huang <ancheng@vyatta.com> -# Date: 2007 -# Description: IP tables address filter - -# **** License **** -# 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) 2006, 2007, 2008 Vyatta, Inc. -# All Rights Reserved. -# **** End License **** - -package VyattaIpTablesAddressFilter; - -use VyattaConfig; -use VyattaMisc; -use VyattaTypeChecker; - -my %_protocolswithports = ( - tcp => 1, - udp => 1, - 6 => 1, - 17 => 1, -); - -my %fields = ( - _srcdst => undef, - _range_start => undef, - _range_stop => undef, - _network => undef, - _address => undef, - _port => undef, - _protocol => undef, - _src_mac => undef, -); - -sub new { - my $that = shift; - my $class = ref ($that) || $that; - my $self = { - %fields, - }; - - bless $self, $class; - return $self; -} - -sub setup { - my ($self, $level) = @_; - my $config = new VyattaConfig; - - $config->setLevel("$level"); - - # setup needed parent nodes - $self->{_srcdst} = $config->returnParent(".."); - $self->{_protocol} = $config->returnValue(".. protocol"); - - # setup address filter nodes - $self->{_address} = $config->returnValue("address"); - $self->{_network} = undef; - $self->{_range_start} = undef; - $self->{_range_stop} = undef; - if (defined($self->{_address})) { - if ($self->{_address} =~ /\//) { - $self->{_network} = $self->{_address}; - $self->{_address} = undef; - } elsif ($self->{_address} =~ /^([^-]+)-([^-]+)$/) { - $self->{_range_start} = $1; - $self->{_range_stop} = $2; - $self->{_address} = undef; - } - } - - $self->{_port} = $config->returnValue("port"); - $self->{_src_mac} = $config->returnValue("mac-address"); - - return 0; -} - -sub setupOrig { - my ($self, $level) = @_; - my $config = new VyattaConfig; - - $config->setLevel("$level"); - - # setup needed parent nodes - $self->{_srcdst} = $config->returnParent(".."); - $self->{_protocol} = $config->returnOrigValue(".. protocol"); - - # setup address filter nodes - $self->{_address} = $config->returnOrigValue("address"); - $self->{_network} = undef; - $self->{_range_start} = undef; - $self->{_range_stop} = undef; - if (defined($self->{_address})) { - if ($self->{_address} =~ /\//) { - $self->{_network} = $self->{_address}; - $self->{_address} = undef; - } elsif ($self->{_address} =~ /^([^-]+)-([^-]+)$/) { - $self->{_range_start} = $1; - $self->{_range_stop} = $2; - $self->{_address} = undef; - } - } - - $self->{_port} = $config->returnOrigValue("port"); - $self->{_src_mac} = $config->returnValue("mac-address"); - - return 0; -} - -sub print { - my ($self) = @_; - - print "srcdst: $self->{_srcdst}\n" if defined $self->{_srcdst}; - print "range start: $self->{_range_start}\n" if defined $self->{_range_start}; - print "range stop: $self->{_range_stop}\n" if defined $self->{_range_stop}; - print "network: $self->{_network}\n" if defined $self->{_network}; - print "address: $self->{_address}\n" if defined $self->{_address}; - print "port: $self->{_port}\n" if defined $self->{_port}; - print "protocol: $self->{_protocol}\n" if defined $self->{_protocol}; - print "src-mac: $self->{_src_mac}\n" if defined $self->{_src_mac}; - - return 0; -} - -sub rule { - my ($self) = @_; - my $rule = ""; - my $can_use_port = 1; - - if (!defined($self->{_protocol}) - || !defined($_protocolswithports{$self->{_protocol}})) { - $can_use_port = 0; - } - - if (($self->{_srcdst} eq "source") && (defined($self->{_src_mac}))) { - # handle src mac - my $str = $self->{_src_mac}; - $str =~ s/^\!(.*)$/! $1/; - $rule .= "-m mac --mac-source $str "; - } - - # set the address filter parameters - if (defined($self->{_network})) { - my $str = $self->{_network}; - return (undef, "\"$str\" is not a valid IP subnet") - if (!VyattaTypeChecker::validateType('ipv4net_negate', $str, 1)); - $str =~ s/^\!(.*)$/! $1/; - $rule .= "--$self->{_srcdst} $str "; - } elsif (defined($self->{_address})) { - my $str = $self->{_address}; - return (undef, "\"$str\" is not a valid IP address") - if (!VyattaTypeChecker::validateType('ipv4_negate', $str, 1)); - $str =~ s/^\!(.*)$/! $1/; - $rule .= "--$self->{_srcdst} $str "; - } elsif ((defined $self->{_range_start}) && (defined $self->{_range_stop})) { - my $start = $self->{_range_start}; - my $stop = $self->{_range_stop}; - return (undef, "\"$start-$stop\" is not a valid IP range") - if (!VyattaTypeChecker::validateType('ipv4_negate', $start, 1) - || !VyattaTypeChecker::validateType('ipv4', $stop, 1)); - my $negate = ''; - if ($self->{_range_start} =~ /^!(.*)$/) { - $start = $1; - $negate = '! ' - } - if ("$self->{_srcdst}" eq "source") { - $rule .= ("-m iprange $negate--src-range $start-$self->{_range_stop} "); - } - elsif ("$self->{_srcdst}" eq "destination") { - $rule .= ("-m iprange $negate--dst-range $start-$self->{_range_stop} "); - } - } - - my ($port_str, $port_err) - = VyattaMisc::getPortRuleString($self->{_port}, $can_use_port, - ($self->{_srcdst} eq "source") ? "s" : "d", - $self->{_protocol}); - return (undef, $port_err) if (!defined($port_str)); - $rule .= $port_str; - return ($rule, undef); -} - -sub outputXmlElem { - my ($name, $value, $fh) = @_; - print $fh " <$name>$value</$name>\n"; -} - -sub outputXml { - my ($self, $prefix, $fh) = @_; - outputXmlElem("${prefix}_addr", $self->{_address}, $fh); - outputXmlElem("${prefix}_net", $self->{_network}, $fh); - outputXmlElem("${prefix}_addr_start", $self->{_range_start}, $fh); - outputXmlElem("${prefix}_addr_stop", $self->{_range_stop}, $fh); - outputXmlElem("${prefix}_port", $self->{_port}, $fh); -} - diff --git a/scripts/vyatta-check-typeless-node.pl b/scripts/vyatta-check-typeless-node.pl index 65a7408..1780a5e 100644..100755 --- a/scripts/vyatta-check-typeless-node.pl +++ b/scripts/vyatta-check-typeless-node.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl use lib "/opt/vyatta/share/perl5/"; -use VyattaConfig; -use VyattaMisc; +use Vyatta::Config; +use Vyatta::Misc; use Getopt::Long; ## Check if a typeless node exists @@ -9,7 +9,7 @@ use Getopt::Long; # i.e. $VAR(./node/) always expands to true. Once bug 2525 is properly # fixed, this can go away my $node = shift; -my $config = new VyattaConfig; +my $config = new Vyatta::Config; if ($config->exists("$node")) { exit 0; diff --git a/scripts/vyatta-cli-expand-var.pl b/scripts/vyatta-cli-expand-var.pl index 2691615..f690f0b 100755 --- a/scripts/vyatta-cli-expand-var.pl +++ b/scripts/vyatta-cli-expand-var.pl @@ -21,7 +21,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use VyattaConfig; +use Vyatta::Config; # expand a variable reference if ($#ARGV != 0) { @@ -59,7 +59,7 @@ if (/\@/) { exit 1; } -my $config = new VyattaConfig; +my $config = new Vyatta::Config; my $path_str = join ' ', (split /\//); my $val_str = ""; if ($multi_val) { diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index b9b083e..2fe4ac6 100644..100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -25,7 +25,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use VyattaConfigLoad; +use Vyatta::ConfigLoad; my $conf_file = '/opt/vyatta/etc/config/config.boot'; @@ -33,7 +33,7 @@ $conf_file = $ARGV[0] if defined $ARGV[0]; # get a list of all config statement in the startup config file # (sorted by rank). -my @all_nodes = VyattaConfigLoad::getStartupConfigStatements($conf_file); +my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); if (scalar(@all_nodes) == 0) { # no config statements exit 1; diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index 29b6bcd..856799a 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -24,7 +24,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use VyattaConfigLoad; +use Vyatta::ConfigLoad; umask 0002; @@ -47,7 +47,7 @@ sub restore_fds { # get a list of all config statement in the startup config file # (sorted by rank). -my @all_nodes = VyattaConfigLoad::getStartupConfigStatements($ARGV[0]); +my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0]); if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); diff --git a/scripts/vyatta-find-type.pl b/scripts/vyatta-find-type.pl index 3c9ccc6..9621a58 100755 --- a/scripts/vyatta-find-type.pl +++ b/scripts/vyatta-find-type.pl @@ -21,7 +21,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use VyattaTypeChecker; +use Vyatta::TypeChecker; # find the type of a value (from a list of candidates) if ($#ARGV < 1) { @@ -29,7 +29,7 @@ if ($#ARGV < 1) { exit 1; } -if (my $type = VyattaTypeChecker::findType(@ARGV)) { +if (my $type = Vyatta::TypeChecker::findType(@ARGV)) { # type found print "$type"; exit 0; diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index d382922..31b7d8d 100644..100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -31,21 +31,20 @@ # use lib "/opt/vyatta/share/perl5/"; -use VyattaConfig; -use VyattaMisc; +use Vyatta::Config; +use Vyatta::Misc; use Getopt::Long; use POSIX; use NetAddr::IP; +use Fcntl; use strict; use warnings; my $dhcp_daemon = '/sbin/dhclient'; -my $dhclient_dir = '/var/lib/dhcp3/'; - -my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient); +my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient, $intf_cli_path); GetOptions("eth-addr-update=s" => \$eth_update, "eth-addr-delete=s" => \$eth_delete, @@ -54,6 +53,7 @@ GetOptions("eth-addr-update=s" => \$eth_update, "valid-mac=s" => \$mac, "set-mac=s" => \$mac_update, "op-command=s" => \$op_dhclient, + "intf-cli-path=s" => \$intf_cli_path ); if (defined $eth_update) { update_eth_addrs($eth_update, $dev); } @@ -65,7 +65,7 @@ if (defined $op_dhclient) { op_dhcp_command($op_dhclient, $dev); } sub is_ip_configured { my ($intf, $ip) = @_; - my $wc = `ip addr show $intf | grep $ip | wc -l`; + my $wc = `ip addr show $intf | grep -c $ip`; if (defined $wc and $wc > 0) { return 1; } else { @@ -96,6 +96,15 @@ sub is_ip_duplicate { } } +sub touch { + my $file = shift; + my $t = time; + + sysopen (my $f, $file, O_RDWR|O_CREAT) + or die "Can't touch $file: $!"; + close $f; + utime $t, $t, $file; +} sub dhcp_write_file { my ($file, $data) = @_; @@ -114,44 +123,15 @@ sub dhcp_conf_header { return $output; } -sub is_dhcp_enabled { - my $intf = shift; - - my $config = new VyattaConfig; - - # FIXME: this is wrong and depends on name of interface -> type - # which is not dependable - if ($intf =~ m/^eth/ || $intf =~ m/^bond/) { - if ($intf =~ m/(\w+)\.(\d+)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); - } else { - $config->setLevel("interfaces ethernet $intf"); - } - } elsif ($intf =~ m/^br/) { - $config->setLevel("interfaces bridge $intf"); - } else { - # - # FIXME: currently we only support dhcp on ethernet - # and bridge interfaces (what about wireles, ...???) - # - return 0; - } - my @addrs = $config->returnOrigValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - return 1; - } - } - return 0; -} - sub is_address_enabled { my $intf = shift; - my $config = new VyattaConfig; + my $config = new Vyatta::Config; ## FIXME this is name based madness find a better way ## so we don't have to redo with each interface type! + ## POSSIBLE SOLUTION: pass the cli-path uptill 'address' node from + ## address/node.def so we don't have to determine the address type here if ($intf =~ m/^eth/) { if ($intf =~ m/(\w+)\.(\d+)/) { $config->setLevel("interfaces ethernet $1 vif $2"); @@ -159,7 +139,11 @@ sub is_address_enabled { $config->setLevel("interfaces ethernet $intf"); } } elsif ($intf =~ m/^bond/) { - $config->setLevel("interfaces bonding $intf"); + if ($intf =~ m/(\w+)\.(\d+)/) { + $config->setLevel("interfaces bonding $1 vif $2"); + } else { + $config->setLevel("interfaces bonding $intf"); + } } elsif ($intf =~ m/^br/) { $config->setLevel("interfaces bridge $intf"); } else { @@ -176,20 +160,20 @@ sub is_address_enabled { } sub get_hostname { - my $config = new VyattaConfig; + my $config = new Vyatta::Config; $config->setLevel("system"); return $config->returnValue("host-name"); } sub is_domain_name_set { - my $config = new VyattaConfig; + my $config = new Vyatta::Config; $config->setLevel("system"); return $config->returnValue("domain-name"); } sub get_mtu { my $intf = shift; - my $config = new VyattaConfig; + my $config = new Vyatta::Config; $config->setLevel("interfaces $intf"); return $config->returnValue("mtu"); } @@ -229,42 +213,64 @@ sub dhcp_update_config { dhcp_write_file($conf_file, $output); } -sub generate_dhclient_intf_files { +sub is_intf_disabled { my $intf = shift; - $intf =~ s/\./_/g; - my $intf_config_file = $dhclient_dir . 'dhclient_' . $intf . '.conf'; - my $intf_process_id_file = $dhclient_dir . 'dhclient_' . $intf . '.pid'; - my $intf_leases_file = $dhclient_dir . 'dhclient_' . $intf . '.leases'; - return ($intf_config_file, $intf_process_id_file, $intf_leases_file); + # only do this if script run from config mode + if (!defined $op_dhclient) { + + if (!defined $intf_cli_path) { + print "unable to check if interface is disabled without cli path\n"; + exit 1; + } + my $config = new Vyatta::Config; + $config->setLevel("$intf_cli_path"); + + if ($intf =~ m/^br/) { + if ($config->returnValue("disable") eq "true") { + return 1; + } + } else { + if ($config->exists("disable")) { + return 1; + } + } + + } + return 0; } + sub run_dhclient { my $intf = shift; - my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = Vyatta::Misc::generate_dhclient_intf_files($intf); dhcp_update_config($intf_config_file, $intf); - my $cmd = "$dhcp_daemon -q -nw -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file $intf 2> /dev/null &"; - # adding & at the end to make the process into a daemon immediately - system ($cmd); + if (!(is_intf_disabled($intf))) { + my $cmd = "$dhcp_daemon -q -nw -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file $intf 2> /dev/null &"; + # adding & at the end to make the process into a daemon immediately + system ($cmd) == 0 + or warn "start $dhcp_daemon failed: $?\n"; + } } sub stop_dhclient { my $intf = shift; - - my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); - my $release_cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; - system ($release_cmd); - system ("rm -f $intf_config_file"); + if (!(is_intf_disabled($intf))) { + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = Vyatta::Misc::generate_dhclient_intf_files($intf); + my $release_cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; + system ($release_cmd) == 0 + or warn "stop $dhcp_daemon failed: $?\n"; + } } sub update_eth_addrs { my ($addr, $intf) = @_; if ($addr eq "dhcp") { + touch("/var/lib/dhcp3/$intf"); run_dhclient($intf); - system ("touch /var/lib/dhcp3/$intf\;"); return; } my $version = is_ip_v4_or_v6($addr); @@ -310,7 +316,10 @@ sub delete_eth_addrs { if ($addr eq "dhcp") { stop_dhclient($intf); - system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease; rm -f /var/lib/dhcp3/$intf\; rm -f /var/run/vyatta/dhclient/dhclient_release_$intf\;"); + unlink("/var/lib/dhcp3/dhclient_$intf\_lease"); + unlink("/var/lib/dhcp3/$intf"); + unlink("/var/run/vyatta/dhclient/dhclient_release_$intf"); + unlink("/var/lib/dhcp3/dhclient_$intf\.conf"); exit 0; } my $version = is_ip_v4_or_v6($addr); @@ -378,7 +387,7 @@ sub is_valid_addr { print "Error: can't use dhcp client on loopback interface\n"; exit 1; } - if (is_dhcp_enabled($intf)) { + if (Vyatta::Misc::is_dhcp_enabled($intf)) { print "Error: dhcp already configured for $intf\n"; exit 1; } @@ -424,7 +433,7 @@ sub is_valid_addr { } } - if (is_dhcp_enabled($intf)) { + if (Vyatta::Misc::is_dhcp_enabled($intf)) { print "Error: remove dhcp before adding static addresses for $intf\n"; exit 1; } @@ -450,10 +459,17 @@ sub is_valid_addr { sub op_dhcp_command { my ($op_command, $intf) = @_; - if (!is_dhcp_enabled($intf)) { + if (!Vyatta::Misc::is_dhcp_enabled($intf)) { print "$intf is not using DHCP to get an IP address\n"; exit 1; } + + my $flags = Vyatta::Misc::get_sysfs_value($intf, 'flags'); + my $hex_flags = hex($flags); + if (!($hex_flags & 0x1)) { + print "$intf is disabled. Unable to release/renew lease\n"; + exit 1; + } my $tmp_dhclient_dir = '/var/run/vyatta/dhclient/'; my $release_file = $tmp_dhclient_dir . 'dhclient_release_' . $intf; @@ -464,16 +480,14 @@ sub op_dhcp_command { } else { print "Releasing DHCP lease on $intf ...\n"; stop_dhclient($intf); - if(! -d $tmp_dhclient_dir ){ - system ("mkdir $tmp_dhclient_dir\;"); - } - system ("touch $release_file\;"); + mkdir ($tmp_dhclient_dir) if (! -d $tmp_dhclient_dir ); + touch ($release_file); exit 0; } } elsif ($op_command eq "dhcp-renew") { print "Renewing DHCP lease on $intf ...\n"; run_dhclient($intf); - system ("rm -f $release_file\;"); + unlink ($release_file); exit 0; } diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index dfbf575..664fd2a 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -26,7 +26,7 @@ use lib "/opt/vyatta/share/perl5/"; use POSIX; use IO::Prompt; use Sys::Syslog qw(:standard :macros); -use VyattaConfigLoad; +use Vyatta::ConfigLoad; $SIG{'INT'} = 'IGNORE'; @@ -147,7 +147,7 @@ syslog("warning", "Load config [$orig_load_file] by $login"); system("$sbindir/vyatta_config_migrate.pl $load_file"); print "Loading config file $load_file...\n"; -my %cfg_hier = VyattaConfigLoad::loadConfigHierarchy($load_file); +my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($load_file); if (scalar(keys %cfg_hier) == 0) { print "The specified file does not contain any configuration.\n"; print "Do you want to remove everything in the running configuration? [no] "; @@ -158,7 +158,7 @@ if (scalar(keys %cfg_hier) == 0) { } } -my %cfg_diff = VyattaConfigLoad::getConfigDiff(\%cfg_hier); +my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff(\%cfg_hier); my @delete_list = @{$cfg_diff{'delete'}}; my @set_list = @{$cfg_diff{'set'}}; diff --git a/scripts/vyatta-output-config.pl b/scripts/vyatta-output-config.pl index 05bdc4c..a632297 100755 --- a/scripts/vyatta-output-config.pl +++ b/scripts/vyatta-output-config.pl @@ -20,20 +20,20 @@ # **** End License **** use strict; -use lib "/opt/vyatta/share/perl5/"; -use VyattaConfigOutput; +use lib "/opt/vyatta/share/perl5"; +use Vyatta::ConfigOutput; if ($ARGV[0] eq '-all') { shift; - VyattaConfigOutput::set_show_all(1); + set_show_all(1); } if ($ARGV[0] eq '-active') { shift; - VyattaConfigOutput::set_hide_password(1); - VyattaConfigOutput::outputActiveConfig(@ARGV); + set_hide_password(1); + outputActiveConfig(@ARGV); } else { - VyattaConfigOutput::outputNewConfig(@ARGV); + outputNewConfig(@ARGV); } exit 0; diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl index 2c02766..dd53d51 100755 --- a/scripts/vyatta-save-config.pl +++ b/scripts/vyatta-save-config.pl @@ -20,8 +20,8 @@ # **** End License **** use strict; -use lib "/opt/vyatta/share/perl5/"; -use VyattaConfigOutput; +use lib "/opt/vyatta/share/perl5"; +use Vyatta::ConfigOutput; my $etcdir = "/opt/vyatta/etc"; my $bootpath = $etcdir . "/config"; @@ -84,8 +84,8 @@ if ($mode eq 'local') { } select SAVE; -VyattaConfigOutput::set_show_all(1); -VyattaConfigOutput::outputActiveConfig(); +set_show_all(1); +outputActiveConfig(); print $version_str; close SAVE; select STDOUT; diff --git a/scripts/vyatta-validate-type.pl b/scripts/vyatta-validate-type.pl index eecc024..f180489 100755 --- a/scripts/vyatta-validate-type.pl +++ b/scripts/vyatta-validate-type.pl @@ -21,7 +21,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use VyattaTypeChecker; +use Vyatta::TypeChecker; # validate a value of a specific type if ($#ARGV < 1) { @@ -35,5 +35,5 @@ if ($ARGV[0] eq '-q') { $quiet = 1; } -exit 0 if (VyattaTypeChecker::validateType($ARGV[0], $ARGV[1], $quiet)); +exit 0 if (Vyatta::TypeChecker::validateType($ARGV[0], $ARGV[1], $quiet)); exit 1; diff --git a/src/cli_new.c b/src/cli_new.c index ae48903..dc6b760 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -2138,24 +2138,13 @@ const char *type_to_name(vtw_type_e type) { void dump_log(int argc, char **argv) { int i; - int len; - char *cp; - len = 0; - for (i=0; i<argc;++i) - len += strlen(argv[i]); - len += argc; - cp = my_malloc(len, "dump_log"); - len = 0; - for (i=0; i<argc;++i){ - strcpy(cp+len, argv[i]); - len += strlen(argv[i]); - cp[len]= ' '; - ++len; + printf("Command:"); + for (i = 0; i < argc; ++i) { + putchar(' '); + puts(argv[i]); } - cp[len-1]=0; - printf("Command: %s\n",cp); - my_free(cp); + putchar('\n'); } #endif diff --git a/templates/interfaces/ethernet/node.def b/templates/interfaces/ethernet/node.def index 3023a70..402b13b 100644 --- a/templates/interfaces/ethernet/node.def +++ b/templates/interfaces/ethernet/node.def @@ -10,8 +10,7 @@ syntax:expression: exec " \ fi" update: sudo ip link set "$VAR(@)" up - vyatta-vtysh -c "configure terminal" \ - -c "interface $VAR(@)" -c "link-detect" + vyatta-link-detect $VAR(@) on delete: sudo ip link set "$VAR(@)" down allowed: for dev in /sys/class/net/eth*; do if [[ -d $dev && -L $dev/device ]] diff --git a/templates/interfaces/ethernet/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/address/node.def index d523793..5277263 100644 --- a/templates/interfaces/ethernet/node.tag/address/node.def +++ b/templates/interfaces/ethernet/node.tag/address/node.def @@ -2,8 +2,10 @@ multi: type: txt help: Set an IP address for this interface syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr $VAR(@) --dev $VAR(../@)"; "Invalid IP address/prefix [$VAR(@)] for interface $VAR(../@)" -update:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)"; "Error setting address $VAR(@) on interface $VAR(../@)" -delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)"; "Error deleting address $VAR(@) on interface $VAR(../@)" +update:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@) \ +--intf-cli-path \"interfaces ethernet $VAR(../@)\""; "Error setting address $VAR(@) on interface $VAR(../@)" +delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@) \ +--intf-cli-path \"interfaces ethernet $VAR(../@)\""; "Error deleting address $VAR(@) on interface $VAR(../@)" allowed: echo "dhcp <>" comp_help:Possible completions: <x.x.x.x/x> Set the IP address and prefix length diff --git a/templates/interfaces/ethernet/node.tag/disable/node.def b/templates/interfaces/ethernet/node.tag/disable/node.def index 54090cc..90dd582 100644 --- a/templates/interfaces/ethernet/node.tag/disable/node.def +++ b/templates/interfaces/ethernet/node.tag/disable/node.def @@ -1,3 +1,11 @@ help: Set interface disabled -update:expression: "sudo ip link set $VAR(../@) down"; "Error disabling dev $VAR(../@)" -delete:expression: "sudo ip link set $VAR(../@) up"; "Error enabling dev $VAR(../@)" +update: /etc/netplug/linkdown.d/dhclient $VAR(../@) + if ! sudo ip link set $VAR(../@) down 2>/dev/null; then + echo "Error disabling dev $VAR(../@)" + /etc/netplug/linkup.d/dhclient $VAR(../@) + exit 1 + fi +delete: if ! sudo ip link set $VAR(../@) up; then + echo "Error enabling dev $VAR(../@)" + exit 1 + fi diff --git a/templates/interfaces/ethernet/node.tag/vif/node.def b/templates/interfaces/ethernet/node.tag/vif/node.def index d37b045..4d0350b 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.def @@ -5,8 +5,7 @@ syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 4094; "VLAN ID must be between 0 a create: sudo modprobe 8021q sudo vconfig add "$VAR(../@)" "$VAR(@)" sudo ip link set "$VAR(../@).$VAR(@)" up - vyatta-vtysh -c "configure terminal" \ - -c "interface $VAR(../@).$VAR(@)" -c "link-detect" + vyatta-link-detect "$VAR(../@).$VAR(@)" on delete: sudo vconfig rem "$VAR(../@).$VAR(@)" comp_help: possible completions: <0-4094> Set VLAN ID diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def index 625130a..0ef5583 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def @@ -2,8 +2,10 @@ multi: type: txt help: Set an IP address for this interface syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Invalid IP address/prefix [$VAR(@)] for interface $VAR(../../@).$VAR(../@)" -create:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Error setting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " -delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Error deleting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " +create:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../../@).$VAR(../@) \ +--intf-cli-path \"interfaces ethernet $VAR(../../@) vif $VAR(../@)\""; "Error setting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " +delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../../@).$VAR(../@) \ +--intf-cli-path \"interfaces ethernet $VAR(../../@) vif $VAR(../@)\""; "Error deleting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " allowed: echo "dhcp <>" comp_help:Possible completions: <x.x.x.x/x> Set the IP address and prefix length diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def index 9599de3..78b2487 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def @@ -1,3 +1,11 @@ help: Set interface disabled -update:expression: "sudo ip link set $VAR(../../@).$VAR(../@) down"; "Error disabling dev $VAR(../../@).$VAR(../@)" -delete:expression: "sudo ip link set $VAR(../../@).$VAR(../@) up"; "Error enabling dev $VAR(../../@).$VAR(../@)" +update: /etc/netplug/linkdown.d/dhclient $VAR(../../@).$VAR(../@) + if ! sudo ip link set $VAR(../../@).$VAR(../@) down 2>/dev/null; then + echo "Error disabling dev $VAR(../../@).$VAR(../@)" + /etc/netplug/linkup.d/dhclient $VAR(../../@).$VAR(../@) + exit 1 + fi +delete: if ! sudo ip link set $VAR(../../@).$VAR(../@) up; then + echo "Error enabling dev $VAR(../../@).$VAR(../@)" + exit 1 + fi |