]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2914] extended documentation with for loops in scripts
authorRazvan Becheriu <razvan@isc.org>
Mon, 17 Jun 2024 13:30:46 +0000 (16:30 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 20 Jun 2024 09:38:37 +0000 (09:38 +0000)
doc/sphinx/arm/hooks-run-script.rst
src/hooks/dhcp/run_script/run_script.dox

index 8ec790695b2e5b073f1d4828435804026fbf3af0..d1b424a7b81c9dab5f8f3472356cb91f670468e9 100644 (file)
@@ -85,7 +85,7 @@ An example of a script implementing all hook points is presented below:
 
 ::
 
-   #!/bin/bash
+   #!/bin/sh
 
    unknown_handle() {
        echo "Unhandled function call ${*}"
@@ -625,3 +625,39 @@ at 0.
    LEASE6_PREFERRED_LIFETIME
    LEASE6_PREFIX_LEN
    LEASE6_TYPE
+
+The leases4_committed hook point needs for loops to handle the list of addresses.
+This can be achived in the following way:
+
+::
+
+   leases4_committed() {
+       for i in $(seq 0 $((LEASES4_SIZE-1))); do
+           LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS")
+           ...
+       done
+
+       for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do
+           DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS")
+           ...
+       done
+       exit 0
+   }
+
+The leases6_committed hook point needs for loops to handle the list of addresses.
+This can be achived in the following way:
+
+::
+
+   leases6_committed() {
+       for i in $(seq 0 $((LEASES6_SIZE-1))); do
+           LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS")
+           ...
+       done
+
+       for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do
+           DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS")
+           ...
+       done
+       exit 0
+   }
\ No newline at end of file
index 3fbcd12ffe621fd74664f686503607dd75ee1a43..585c983a136b6dbb2099f3b3aa4048e2c38dbab8 100644 (file)
@@ -101,7 +101,7 @@ the hook point.
 An example of a script implementing all hook points is presented below.
 
 @code
-#!/bin/bash
+#!/bin/sh
 
 unknown_handle() {
     echo "Unhandled function call ${*}"
@@ -666,6 +666,46 @@ LEASE6_TYPE
 
 @endcode
 
+The leases4_committed hook point needs for loops to handle the list of addresses.
+This can be achived in the following way:
+
+@code
+
+leases4_committed() {
+    for i in $(seq 0 $((LEASES4_SIZE-1))); do
+        LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS")
+        ...
+    done
+
+    for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do
+        DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS")
+        ...
+    done
+    exit 0
+}
+
+@endcode
+
+The leases6_committed hook point needs for loops to handle the list of addresses.
+This can be achived in the following way:
+
+@code
+
+leases6_committed() {
+    for i in $(seq 0 $((LEASES6_SIZE-1))); do
+        LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS")
+        ...
+    done
+
+    for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do
+        DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS")
+        ...
+    done
+    exit 0
+}
+
+@endcode
+
 @section libdhcp_run_scriptMTCompatibility Multi-Threading Compatibility
 
 The Run Script hooks library is compatible with multi-threading.