summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2014-11-05 14:45:57 +0600
committerDaniil Baturin <daniil@baturin.org>2014-11-05 14:45:57 +0600
commit0c20ea86adefa872505854393f2c5a2d2b3b3783 (patch)
treeb5f00f3a263c469a4fd0de1dc1f826678631b355 /scripts
parent7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d (diff)
parentd6de6f2755f326b8fb5195e051e801577939bdbf (diff)
downloadvyatta-cfg-system-0c20ea86adefa872505854393f2c5a2d2b3b3783.tar.gz
vyatta-cfg-system-0c20ea86adefa872505854393f2c5a2d2b3b3783.zip
Merge pull request #30 from jhendryUK/manage_sysctl_options
Manage sysctl options
Diffstat (limited to 'scripts')
-rw-r--r--scripts/system/vyatta_update_sysctl.pl86
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/system/vyatta_update_sysctl.pl b/scripts/system/vyatta_update_sysctl.pl
new file mode 100644
index 00000000..ddf10115
--- /dev/null
+++ b/scripts/system/vyatta_update_sysctl.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+#
+# Module: vyatta_update_sysctl.pl
+#
+# **** 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: Jason Hendry
+# Date: October 2014
+# Description: Script to manage sysctl values
+#
+# **** End License ****
+#
+
+use lib "/opt/vyatta/share/perl5/";
+use Vyatta::Config;
+use Vyatta::File qw(touch);
+
+use Getopt::Long;
+
+use strict;
+use warnings;
+
+my $SYSCTL = '/sbin/sysctl';
+
+my (@opts);
+
+sub usage {
+ print <<EOF;
+Usage: $0 --option=<sysctl_option> <value>
+EOF
+ exit 1;
+}
+
+GetOptions(
+ "option=s{2}" => \@opts,
+ ) or usage();
+
+set_sysctl_value(@opts) if (@opts);
+exit 0;
+
+sub set_sysctl_value {
+ my ($sysctl_opt, $nvalue) = @_;
+ my $ovalue = get_sysctl_value($sysctl_opt);
+
+ if ($nvalue ne $ovalue) {
+ my $cmd = "$SYSCTL -w $sysctl_opt=$nvalue 2>&1 1>&-";
+ system($cmd);
+ if ($? >> 8) {
+ die "exec of $SYSCTL failed: '$cmd'";
+ }
+ }
+}
+
+sub get_sysctl_value {
+ my $option = shift;
+ my $val;
+
+ open( my $sysctl, '-|', "$SYSCTL $option 2>&1" ) or die "sysctl failed: $!\n";
+ while (<$sysctl>) {
+ chomp;
+ $val = (split(/ = /, $_))[1];
+ }
+ close $sysctl;
+ return ($val);
+}
+
+# net.ipv4.ipfrag_time