summaryrefslogtreecommitdiff
path: root/7/firewall.pl
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2023-11-23 10:49:21 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2023-11-23 10:49:21 +0100
commit2583897e4c5cbe56525365206c2a64bcd0c75e5f (patch)
treea98e8c51917e7690a79c939d16c46c9bf837cfb4 /7/firewall.pl
parent3d1c40ea667a25c1dde11a44a9e2e87a8cf51112 (diff)
downloadprolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.gz
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.bz2
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.xz
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.zip
wip
Diffstat (limited to '7/firewall.pl')
-rw-r--r--7/firewall.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/7/firewall.pl b/7/firewall.pl
new file mode 100644
index 0000000..9bb0cc2
--- /dev/null
+++ b/7/firewall.pl
@@ -0,0 +1,37 @@
+% vim set ft=prolog
+
+% rule(src, dst, proto, port, source(..)).
+
+:- module(firewall, [
+ %fw_rule/2,
+ warning/1,
+ retract_all_from/1]).
+
+:- use_module(library(assoc)).
+:- use_module(library(dcgs)).
+
+:- use_module(hosts, [
+ router_link/3]).
+
+:- dynamic(fw_rule/2).
+
+warning(Msg) :-
+ fw_rule(Host, Attr),
+ \+ get_assoc("from", Attr, _),
+ format("Missing 'from' on fw_rule for host '~w', ~w", [Host, Attr], Msg).
+
+rules_from(From, Rules) :-
+ findall(
+ fw_rule(H, Attr),
+ (
+ fw_rule(H, Attr),
+ get_assoc("from", Attr, From)
+ ),
+ Rules).
+
+retract_all_from(From) :-
+ rules_from(From, Rules),
+ retract_rules(Rules).
+
+retract_rules([R|Rules]) :- retract(R), retract_rules(Rules).
+retract_rules([]).