--- /dev/null
+# Verify that subnet lookups in a htrie cache work as expected
+
+subrequest @dhcpv4::Discover {
+ control.IP-Pool.Name = 'main'
+ Network-Subnet := 192.168.1.10/24
+
+ cache_subnet.store
+ if (!updated) {
+ reject
+ }
+
+ control.IP-Pool.Name := 'secondary'
+ Network-Subnet := 10.0.1.23/16
+
+ cache_subnet.store
+ if (!updated) {
+ reject
+ }
+
+ control = {}
+
+ Network-Subnet := 172.16.0.10
+ cache_subnet.load
+ if (!notfound) {
+ reject
+ }
+
+ Network-Subnet := 192.168.1.50/32
+ cache_subnet.load
+ if (!updated) {
+ reject
+ }
+
+ if (control.IP-Pool.Name != 'main') {
+ reject
+ }
+
+ Network-Subnet := 10.0.2.50/32
+ cache_subnet.load
+ if (!updated) {
+ reject
+ }
+
+ if (control.IP-Pool.Name != 'secondary') {
+ reject
+ }
+
+}
+
+if (updated) {
+ control.Auth-Type := ::Accept
+}
--- /dev/null
+# Used by cache-logic
+cache {
+ driver = "htrie"
+
+ key = Filter-Id
+ ttl = 5
+
+ update {
+ Callback-Id := control.Callback-Id[0]
+ NAS-Port := control.NAS-Port[0]
+ control += reply
+ }
+
+ add_stats = yes
+}
+
+cache cache_update {
+ driver = "htrie"
+
+ key = Filter-Id
+ ttl = 5
+
+ #
+ # Update sections in the cache module use very similar
+ # logic to update sections in unlang, except the result
+ # of evaluating the RHS isn't applied until the cache
+ # entry is merged.
+ #
+ update {
+ # Copy reply to session-state
+ session-state += reply
+
+ # Implicit cast between types (and multivalue copy)
+ Filter-Id += NAS-Port[*]
+
+ # Cache the result of an exec
+ Callback-Id := `/bin/echo 'echo test'`
+
+ # Create three string values and overwrite the middle one
+ Login-LAT-Service += 'foo'
+ Login-LAT-Service += 'bar'
+ Login-LAT-Service += 'baz'
+
+ Login-LAT-Service[1] := 'rab'
+
+ # Create three string values, then remove one
+ Login-LAT-Node += 'foo'
+ Login-LAT-Node += 'bar'
+ Login-LAT-Node += 'baz'
+
+ Login-LAT-Node -= 'bar'
+ }
+}
+
+#
+# Test some exotic keys
+#
+cache cache_bin_key_octets {
+ driver = "htrie"
+
+ key = Class
+ ttl = 5
+
+ update {
+ Callback-Id := Callback-Id[0]
+ }
+}
+
+cache cache_bin_key_ipaddr {
+ driver = "htrie"
+
+ key = Framed-IP-Address
+ ttl = 5
+
+ update {
+ Callback-Id := Callback-Id[0]
+ }
+}
+
+cache cache_not_radius {
+ driver = "htrie"
+
+ key = parent.Gateway-IP-Address
+
+ update {
+ parent.Your-IP-Address := parent.control.Your-IP-Address
+ outer.Framed-IP-Address := outer.control.Framed-IP-Address
+ }
+}
+
+cache cache_subnet {
+ driver = "htrie"
+
+ key = Network-Subnet
+
+ update {
+ control.IP-Pool.Name := control.IP-Pool.Name
+ }
+}
+
+cache cache_empty_update {
+ driver = "htrie"
+
+ key = Filter-Id
+ ttl = 5
+}
+
+# Regression test for literal data
+# Previously failed with "I-Am-A-Static-Key' expands to invalid tmpl type data-unresolved"
+cache static_key {
+ driver = "htrie"
+ key = "I-Am-A-Static-Key"
+ ttl = 5
+
+ update {
+ Callback-Id := Callback-Id[0]
+ }
+}