summaryrefslogtreecommitdiff
path: root/src/main/resources/io/trygvis/rules/acme/vpn.drl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/resources/io/trygvis/rules/acme/vpn.drl')
-rw-r--r--src/main/resources/io/trygvis/rules/acme/vpn.drl52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/main/resources/io/trygvis/rules/acme/vpn.drl b/src/main/resources/io/trygvis/rules/acme/vpn.drl
index 456cbae..88c44f1 100644
--- a/src/main/resources/io/trygvis/rules/acme/vpn.drl
+++ b/src/main/resources/io/trygvis/rules/acme/vpn.drl
@@ -16,18 +16,23 @@ declare WgNet
networkCidr : String
end
+declare WgIpPool
+ net : String
+ role : String
+ cidr : Ipv4Cidr
+end
+
+declare WgIpPool
+ net : String
+ cidr : Ipv4Cidr
+end
+
rule "Create link network" when
$net : WgNet()
not(Ipv4Cidr(network == IpCalc.cidr($net.linkCidr).network))
then
- insert(IpCalc.cidr($net.linkCidr))
-end
-
-rule "Create link network addresses" when
- $cidr : Ipv4Cidr()
- $addresses : Ipv4Address() from $cidr.addresses
-then
- insert($addresses)
+ insert(new WgIpPool($net.name, "link", IpCalc.cidr($net.linkCidr)))
+ insert(new WgIpPool($net.name, "network", IpCalc.cidr($net.networkCidr)))
end
declare WgHost
@@ -85,16 +90,21 @@ then
insert(new WgConnection($h.name, $other.name))
end
-//declare AllocatedIp
-// owner : Object
-// ip : Ipv4Address
-//end
-//
-//rule "Assign IP"
-//when
-// $host : WgHost()
-// $ip : Ipv4Address()
-//then
-// var allocation = new AllocatedIp($host, $ip);
-// insert(allocation)
-//end
+declare WgIpAllocation
+ host : String
+ role : String
+ ip : Ipv4Address
+end
+
+rule "Assign IP"
+when
+ $net : WgNet()
+ $host : WgHost(net == $net.name)
+ $pool : WgIpPool(net == $net.name)
+ not(WgIpAllocation(host == $host.name, role == $pool.role))
+ $ip : Ipv4Address() from $pool.cidr.addresses()
+ not(WgIpAllocation(ip == $ip))
+then
+ System.out.printf("IP: net=%s, pool.role=%s, host=%s, ip=%s%n", $net.name, $pool.role, $host.name, $ip);
+ insert(new WgIpAllocation($host.name, $pool.role, $ip))
+end