From d0a5e6f8bb58cd5ed78b293bffaeae3398e1e4ab Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Sat, 1 Jan 2022 22:01:55 +1100 Subject: [PATCH] add net option and minor code polishing --- ipset-control.lsp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ipset-control.lsp b/ipset-control.lsp index 9c9bf93..899e37a 100644 --- a/ipset-control.lsp +++ b/ipset-control.lsp @@ -1,15 +1,18 @@ # Should load from "ipset.cfg" -(constant 'TABLE "TIMO" 'NET "192.168.104.0/24" - 'IPSET "/sbin/ipset" ) +(constant 'IPSET "/sbin/ipset" 'TABLE "TIMO" ) -# Apply "add" or "del" on the controllable as needed, and exit +;; Return current low-leve "close" or "open" status +(define (current-status) + (if (exec (format "%s list %s | grep %s" IPSET TABLE NET)) "close" "open")) + +;; Ensure low-level setting is "close" or "open" as given (define (control cmd reason) - (let ((a (case cmd ("open" "del") ("close" "add") (true "XXX")))) - (when (!= cmd (if (exec (format "%s list %s | grep %s" IPSET TABLE NET)) - "close" "open")) - (! (println (date-value) (format " ipset-control (%s): " reason) - (format "%s %s %s %s" IPSET a TABLE NET))))) - (exit 0)) + (when (!= cmd (current-status)) + (let ((todo (case cmd ("open" "del") ("close" "add") (true "XXX")))) + (! (println (date-value) + (format " ipset-control (%s): " reason) + (format "%s %s %s %s" IPSET todo TABLE NET))))) + ) "ipset-control.lsp" -- 2.39.2