Browse Source

Implemented new function sysctl_set_if_lower

In 180-increase-arp-caches the same logic was called again
and again. This could be done by a function!

See https://git.c3pb.de/freifunk-pb/ffpb-packages/issues/2
Michael Schwarz 9 years ago
parent
commit
76ac60d020
1 changed files with 12 additions and 17 deletions
  1. 12 17
      ffpb/ffpb-node-tuning/files/lib/gluon/upgrade/180-increase-arp-caches

+ 12 - 17
ffpb/ffpb-node-tuning/files/lib/gluon/upgrade/180-increase-arp-caches

@@ -3,23 +3,18 @@
 require 'luci.sys'
 local sysctl = require 'gluon.sysctl'
 
-if (tonumber(luci.sys.exec('sysctl net.ipv4.neigh.default.gc_thresh1'):match('%d+', 34)) or 128) < 192 then
-  sysctl.set('net.ipv4.neigh.default.gc_thresh1', 192)
-end
-if (tonumber(luci.sys.exec('sysctl net.ipv4.neigh.default.gc_thresh2'):match('%d+', 34)) or 512) < 640 then
-  sysctl.set('net.ipv4.neigh.default.gc_thresh2', 640)
-end
-if (tonumber(luci.sys.exec('sysctl net.ipv4.neigh.default.gc_thresh3'):match('%d+', 34)) or 1024) < 1280 then
-  sysctl.set('net.ipv4.neigh.default.gc_thresh3', 1280)
-end
-if (tonumber(luci.sys.exec('sysctl net.ipv6.neigh.default.gc_thresh1'):match('%d+', 34)) or 128) < 512 then
-  sysctl.set('net.ipv6.neigh.default.gc_thresh1', 512)
-end
-if (tonumber(luci.sys.exec('sysctl net.ipv6.neigh.default.gc_thresh2'):match('%d+', 34)) or 512) < 1024 then
-  sysctl.set('net.ipv6.neigh.default.gc_thresh2', 1024)
-end
-if (tonumber(luci.sys.exec('sysctl net.ipv6.neigh.default.gc_thresh3'):match('%d+', 34)) or 1024) < 1536 then
-  sysctl.set('net.ipv6.neigh.default.gc_thresh3', 1536)
+function sysctl_set_if_lower(_key, _value)
+	local command = "sysctl " .. _key
+	if (tonumber(luci.sys.exec(command):match('%d+', 34)) or 128) < _value then
+		sysctl.set(_key, _value)
+	end
 end
 
+sysctl_set_if_lower('net.ipv4.neigh.default.gc_thresh1', 192)
+sysctl_set_if_lower('net.ipv4.neigh.default.gc_thresh2', 640)
+sysctl_set_if_lower('net.ipv4.neigh.default.gc_thresh3', 1280)
+sysctl_set_if_lower('net.ipv6.neigh.default.gc_thresh1', 512)
+sysctl_set_if_lower('net.ipv6.neigh.default.gc_thresh2', 1024)
+sysctl_set_if_lower('net.ipv6.neigh.default.gc_thresh3', 1536)
+
 os.execute('sync; sysctl -qp')