diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-09-15 20:12:20 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-09-15 20:12:20 +0200 |
commit | 2908150adea4bbf7d8b1dd6ae9a84bdd53617708 (patch) | |
tree | 9390f0cf12bf9d1a4fc7c9cdcf6d44d93a4e5570 /scripts | |
parent | 0758b396d570b2ad4397ec35f5916515e8c223f9 (diff) | |
parent | 19e0bb3c555e0f6e948cc15b33637a770df225b5 (diff) | |
download | vyatta-cfg-system-2908150adea4bbf7d8b1dd6ae9a84bdd53617708.tar.gz vyatta-cfg-system-2908150adea4bbf7d8b1dd6ae9a84bdd53617708.zip |
Merge branch 'current' of github.com:vyos/vyatta-cfg-system into equuleus
* 'current' of github.com:vyos/vyatta-cfg-system:
T1616: fix DHCPv6 script behaviour in op mode.
openvpn: T1630: add system user openvpn
vxlan: T1636: initial rewrite with XML and Python
Makefile.am: fix after removing files for bridge and bonding
bridge: T1615: remove old vyatta-bridge.pl
bonding: T1614: increase config version from interfaces 1 -> 2
bonding: T1614: remove old style node.def files in favour of XML/Python rewrite
bridge: T1556: migrate bridge config to XML/Python
[tunnel] T1593: Added ip6gre encapsulation for tunnel interfaces
loopback: T1601: rewrite using XML/Python definitions
powerdns: T1595: add config migrator to remove 'listen-on'
powerdns: T1524: support setting allow-from network
dummy: T1580: rewrite in new style XML/Python
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-bonding.pl | 288 | ||||
-rwxr-xr-x | scripts/vyatta-bridge.pl | 132 | ||||
-rwxr-xr-x | scripts/vyatta-dhcpv6-client.pl | 10 |
3 files changed, 8 insertions, 422 deletions
diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl deleted file mode 100755 index 24182af3..00000000 --- a/scripts/vyatta-bonding.pl +++ /dev/null @@ -1,288 +0,0 @@ -#!/usr/bin/perl -# -# **** 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. -# -# A copy of the GNU General Public License is available as -# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution -# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. -# You can also obtain it by writing to the Free Software Foundation, -# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, -# MA 02110-1301, USA. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. -# All Rights Reserved. -# -# Author: Stephen Hemminger -# Date: September 2008 -# Description: Script to setup bonding interfaces -# -# **** End License **** -# - -use lib "/opt/vyatta/share/perl5/"; -use Vyatta::Interface; -use Vyatta::Config; -use Getopt::Long; - -use strict; -use warnings; - -my %modes = ( - "round-robin" => 0, - "active-backup" => 1, - "xor-hash" => 2, - "broadcast" => 3, - "802.3ad" => 4, - "transmit-load-balance" => 5, - "adaptive-load-balance" => 6, -); - -sub set_mode { - my ( $intf, $mode ) = @_; - my $val = $modes{$mode}; - die "Unknown bonding mode $mode\n" unless defined($val); - - open my $fm, '>', "/sys/class/net/$intf/bonding/mode" - or die "Error: $intf is not a bonding device:$!\n"; - print {$fm} $val, "\n"; - close $fm - or die "Error: $intf can not set mode $val:$!\n"; -} - -sub set_hash_policy { - my ( $intf, $hash ) = @_; - - open my $fm, '>', "/sys/class/net/$intf/bonding/xmit_hash_policy" - or die "Error: $intf is not a bonding device:$!\n"; - print {$fm} $hash, "\n"; - close $fm - or die "Error: $intf can not set hash $hash:$!\n"; -} - -sub get_slaves { - my $intf = shift; - - open my $f, '<', "/sys/class/net/$intf/bonding/slaves" - or die "$intf is not a bonding interface"; - my $slaves = <$f>; - close $f; - return unless $slaves; - - chomp $slaves; - return split( ' ', $slaves ); -} - -sub add_slave { - my ( $intf, $slave ) = @_; - my $sysfs_slaves = "/sys/class/net/$intf/bonding/slaves"; - - open my $f, '>', $sysfs_slaves - or die "Can't open $sysfs_slaves: $!"; - - print {$f} "+$slave\n"; - close $f; -} - -sub remove_slave { - my ( $intf, $slave ) = @_; - my $sysfs_slaves = "/sys/class/net/$intf/bonding/slaves"; - - open my $f, '>', $sysfs_slaves - or die "Can't open $sysfs_slaves: $!"; - - print {$f} "-$slave\n"; - close $f; -} - -# Go dumpster diving to figure out which ethernet interface (if any) -# gave it's address to be used by all bonding devices. -sub primary_slave { - my ( $intf, $bond_addr ) = @_; - - open my $p, '<', "/proc/net/bonding/$intf" - or die "Can't open /proc/net/bonding/$intf : $!"; - - my ( $dev, $match ); - while ( my $line = <$p> ) { - chomp $line; - if ( $line =~ m/^Slave Interface: (.*)$/ ) { - $dev = $1; - } - elsif ( $line =~ m/^Permanent HW addr: (.*)$/ ) { - if ( $1 eq $bond_addr ) { - $match = $dev; - last; - } - } - } - close $p; - - return $match; -} - -sub get_irq_affinity { - my $intf = shift; - my $cfg = new Vyatta::Config; - - my $slaveif = new Vyatta::Interface($intf); - unless ($slaveif) { - warn "$intf: unknown interface type"; - return; - } - $cfg->setLevel($slaveif->path()); - return $cfg->returnValue('smp-affinity'); -} - -sub if_down { - my $intf = shift; - system "sudo ip link set dev $intf down" - and die "Could not set $intf up ($!)\n"; -} - -sub if_up { - my $intf = shift; - system "sudo ip link set dev $intf up" - and die "Could not set $intf up ($!)\n"; - - my $smp_affinity = get_irq_affinity($intf); - if ($smp_affinity) { - system "/opt/vyatta/sbin/irq-affinity.pl $intf $smp_affinity" - and warn "Could not set $intf smp-affinity $smp_affinity\n"; - } -} - -# Can't change mode when bond device is up and slaves are attached -sub change_mode { - my ( $intf, $mode ) = @_; - my $interface = new Vyatta::Interface($intf); - die "$intf is not a valid interface" unless $interface; - - my $bond_up = $interface->up(); - - if_down($intf) if ($bond_up); - - # Remove all interfaces; do primary last - my $primary = primary_slave( $intf, $interface->hw_address()); - my @slaves = get_slaves($intf); - - foreach my $slave (@slaves) { - remove_slave( $intf, $slave ) unless ( $primary && $slave eq $primary ); - } - remove_slave( $intf, $primary ) if ($primary); - - set_mode( $intf, $mode ); - - add_slave( $intf, $primary) if ($primary); - foreach my $slave ( @slaves ) { - add_slave( $intf, $slave ) unless ($primary && $slave eq $primary); - } - if_up($intf) if ($bond_up); -} - -# Can't change hash when bond device is up -sub change_hash { - my ( $intf, $hash ) = @_; - my $interface = new Vyatta::Interface($intf); - die "$intf is not a valid interface" unless $interface; - my $bond_up = $interface->up(); - - if_down($intf) if $bond_up; - set_hash_policy( $intf, $hash ); - if_up($intf) if $bond_up; -} - -# Consistency checks prior to commit -sub commit_check { - my ( $intf, $slave ) = @_; - my $cfg = new Vyatta::Config; - - die "Bonding interface $intf does not exist\n" - unless ( -d "/sys/class/net/$intf" ); - - my $slaveif = new Vyatta::Interface($slave); - die "$slave: unknown interface type" unless $slaveif; - $cfg->setLevel($slaveif->path()); - - die "Error: can not add disabled interface $slave to bond-group $intf\n" - if $cfg->exists('disable'); - - die "Error: can not add interface $slave that is part of bridge to bond-group\n" - if defined($cfg->returnValue("bridge-group bridge")); - - my @addr = $cfg->returnValues('address'); - die "Error: can not add interface $slave with addresses to bond-group\n" - if (@addr); - - my @vrrp = $cfg->listNodes('vrrp vrrp-group'); - die "Error: can not add interface $slave with VRRP to bond-group\n" - if (@vrrp); - - $cfg->setLevel('interfaces pseudo-ethernet'); - foreach my $peth ($cfg->listNodes()) { - my $link = $cfg->returnValue("$peth link"); - - die "Error: can not add interface $slave to bond-group already used by pseudo-ethernet $peth\n" - if ($link eq $slave); - } -} - -# bonding requires interface to be down before enslaving -# but enslaving automatically brings interface up! -sub add_port { - my ( $intf, $slave ) = @_; - my $cfg = new Vyatta::Config; - my $slaveif = new Vyatta::Interface($slave); - die "$slave: unknown interface type" unless $slaveif; - - $cfg->setLevel($slaveif->path()); - my $old = $cfg->returnOrigValue('bond-group'); - - if_down($slave) if ($slaveif->up()); - remove_slave($old, $slave) if $old; - add_slave ($intf, $slave); -} - -sub remove_port { - my ( $intf, $slave ) = @_; - - remove_slave ($intf, $slave); - if_up ($slave); -} - -sub usage { - print "Usage: $0 --dev=bondX --mode={mode}\n"; - print " $0 --dev=bondX --hash=layerX\n"; - print " $0 --dev=bondX --add=ethX\n"; - print " $0 --dev=bondX --remove=ethX\n"; - print print "modes := ", join( ',', sort( keys %modes ) ), "\n"; - - exit 1; -} - -my ( $dev, $mode, $hash, $add_port, $rem_port, $check ); - -GetOptions( - 'dev=s' => \$dev, - 'mode=s' => \$mode, - 'hash=s' => \$hash, - 'add=s' => \$add_port, - 'remove=s' => \$rem_port, - 'check=s' => \$check, -) or usage(); - -die "$0: device not specified\n" unless $dev; - -commit_check($dev, $check) if $check; -change_mode( $dev, $mode ) if $mode; -change_hash( $dev, $hash ) if $hash; -add_port( $dev, $add_port ) if $add_port; -remove_port( $dev, $rem_port ) if $rem_port; diff --git a/scripts/vyatta-bridge.pl b/scripts/vyatta-bridge.pl deleted file mode 100755 index 7602c2ce..00000000 --- a/scripts/vyatta-bridge.pl +++ /dev/null @@ -1,132 +0,0 @@ -#! /usr/bin/perl -# -# **** 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. -# -# A copy of the GNU General Public License is available as -# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution -# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. -# You can also obtain it by writing to the Free Software Foundation, -# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, -# MA 02110-1301, USA. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. -# All Rights Reserved. -# -# Author: Stephen Hemminger -# Date: November 2010 -# Description: Script to setup bridge ports -# -# **** End License **** -# - -use strict; -use warnings; - -use lib "/opt/vyatta/share/perl5/"; -use Vyatta::Interface; -use Vyatta::Config; - -my $BRCTL = 'sudo /sbin/brctl'; - -die "Usage: $0 ACTION ethX\n" unless ($#ARGV == 1); - -my ($action, $ifname) = @ARGV; - -# Get bridge information from configuration -my $intf = new Vyatta::Interface($ifname); -die "Unknown interface type $ifname\n" - unless $intf; - -my $cfg = new Vyatta::Config; -$cfg->setLevel($intf->path()); - -my $oldbridge = $cfg->returnOrigValue('bridge-group bridge'); -my $newbridge = $cfg->returnValue('bridge-group bridge'); -my $cost = $cfg->returnValue('bridge-group cost'); -my $priority = $cfg->returnValue('bridge-group priority'); - -if (!defined($newbridge) && ($action ne 'SET')) { - $action = 'DELETE'; -} - -if (!defined($oldbridge) && ($action ne 'DELETE')) { - $action = 'SET'; -} - -if ($action eq 'SET') { - die "Error: $ifname: not in a bridge-group\n" unless $newbridge; - - die "Error: can not add interface $ifname that is part of bond-group to bridge\n" - if defined($cfg->returnValue('bond-group')); - - my @address = $cfg->returnValues('address'); - die "Error: Can not add interface $ifname with addresses to bridge\n" - if (@address); - - my @vrrp = $cfg->listNodes('vrrp vrrp-group'); - die "Error: Can not add interface $ifname with VRRP to bridge\n" - if (@vrrp); - - $cfg->setLevel('interfaces pseudo-ethernet'); - foreach my $peth ($cfg->listNodes()) { - my $link = $cfg->returnValue("$peth link"); - - die "Error: can not add interface $ifname to bridge already used by pseudo-ethernet $peth\n" - if ($link eq $ifname); - } - - print "Adding interface $ifname to bridge $newbridge\n"; - add_bridge_port($newbridge, $ifname, $cost, $priority); - -} elsif ($action eq 'DELETE') { - die "Error: $ifname: not in a bridge-group\n" unless $oldbridge; - - print "Removing interface $ifname from bridge $oldbridge\n"; - remove_bridge_port($oldbridge, $ifname); - -} elsif ($oldbridge ne $newbridge) { - print "Moving interface $ifname from $oldbridge to $newbridge\n"; - remove_bridge_port($oldbridge, $ifname); - add_bridge_port($newbridge, $ifname, $cost, $priority); -} - -exit 0; - -sub add_bridge_port { - my ($bridge, $port, $cost, $priority) = @_; - system("$BRCTL addif $bridge $port") == 0 - or exit 1; - - if ($cost) { - system("$BRCTL setpathcost $bridge $port $cost") == 0 - or exit 1; - } - - if ($priority) { - system("$BRCTL setportprio $bridge $port $priority") == 0 - or exit 1; - } -} - -sub remove_bridge_port { - my ($bridge, $port) = @_; - return unless $bridge; # not part of a bridge - - # this is the case where the bridge that this interface is assigned - # to is getting deleted in the same commit as the bridge node under - # this interface - Bug 5064|4734. Since bridge has a higher priority; - # it gets deleted before the removal of bridge-groups under interfaces - return unless (-d "/sys/class/net/$bridge"); - - system("$BRCTL delif $bridge $ifname") == 0 - or exit 1; -} diff --git a/scripts/vyatta-dhcpv6-client.pl b/scripts/vyatta-dhcpv6-client.pl index 64c6840d..b78d40b5 100755 --- a/scripts/vyatta-dhcpv6-client.pl +++ b/scripts/vyatta-dhcpv6-client.pl @@ -57,8 +57,14 @@ sub gen_conf_file { my $config = new Vyatta::Config; $config->setLevel($level); - if ($config->exists('duid')) { - my $duid = $config->returnValue('duid'); + my $duid = ''; + if($config->inSession()) { + $duid = $config->returnValue('duid'); + } else { + $duid = $config->returnEffectiveValue('duid'); + } + + if($duid) { print $FD_WR " send dhcp6.client-id $duid;\n"; } # my $hostname = hostname; |