# 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"