]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
v4: Define args for %(icmp: ) xlat (#4024)
authorNick Porter <nick@portercomputing.co.uk>
Wed, 24 Mar 2021 13:56:45 +0000 (13:56 +0000)
committerGitHub <noreply@github.com>
Wed, 24 Mar 2021 13:56:45 +0000 (13:56 +0000)
* Define arg for icmp xlat

* Update documentation for new %(icmp: ) syntax

* Update icmp module test syntax

doc/antora/modules/raddb/pages/mods-available/icmp.adoc
raddb/mods-available/icmp
src/modules/rlm_icmp/rlm_icmp.c
src/tests/modules/icmp/ping.unlang

index 35b4c552b303e713fdfa74336f1a0ba0dadfbdd8..46fe16803b1fc6fcc88fe69575acfffd3ab32b00 100644 (file)
@@ -68,8 +68,8 @@ Copy of the `icmp` module, as it may be easier to remember `ping` than `icmp`.
 == Default Configuration
 
 ```
-#      `%{icmp:192.0.2.1}`
-#      `%{icmp:%{NAS-IP-Address}}`
+#      `%(icmp:192.0.2.1)`
+#      `%(icmp:%{NAS-IP-Address})`
 #      $ setcap cap_net_raw+ep ${bindir}/radiusd
 icmp {
 #      interface = eth0
index 761d82b377c25a4fe65675d26b69a32b1c87702c..b6aed8f92a46842c0d36c5f562f911c7049aee73 100644 (file)
@@ -11,7 +11,7 @@
 #
 #  This module is useful only for `xlat`.  Use it via the following expansion:
 #
-#      `%{icmp:192.0.2.1}`
+#      `%(icmp:192.0.2.1)`
 #
 #  The module will "ping" the given IP address.  If that IP address responds
 #  with an ICMP Echo Reply, then the result of the expansion will be `yes`.
 #  The IP address does not have to be a fixed string.  It can be another
 #  expansion, such as:
 #
-#      `%{icmp:%{NAS-IP-Address}}`
+#      `%(icmp:%{NAS-IP-Address})`
 #
 #
 # == Capabilities and Permissions
 #
-#  On Linus, you may need to do:
+#  On Linux, you may need to do:
 #
 #      $ setcap cap_net_raw+ep ${bindir}/radiusd
 #
index a0f29f9ae0289c2c808810275c4b12cb9d1dc15d..92ec4d70519c6b7202e0e3bd36be9c757752e8e0 100644 (file)
@@ -170,11 +170,11 @@ static void _xlat_icmp_timeout(request_t *request,
        unlang_interpret_mark_runnable(request);
 }
 
-/** Xlat to delay the request
+/** Xlat to ping a specified ip address
  *
  * Example (ping 192.0.2.1):
 @verbatim
-"%{icmp:192.0.2.1}"
+"%(icmp:192.0.2.1)"
 @endverbatim
  *
  * @ingroup xlat_functions
@@ -203,11 +203,6 @@ static xlat_action_t xlat_icmp(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out,
         */
        if (!in_head) return XLAT_ACTION_FAIL;
 
-       if (fr_value_box_list_concat(ctx, in_head, in, FR_TYPE_STRING, true) < 0) {
-               RPEDEBUG("Failed concatenating input");
-               return XLAT_ACTION_FAIL;
-       }
-
        if (fr_value_box_cast_in_place(ctx, in_head, thread->t->ipaddr_type, NULL) < 0) {
                RPEDEBUG("Failed casting result to IP address");
                return XLAT_ACTION_FAIL;
@@ -285,6 +280,11 @@ static xlat_action_t xlat_icmp(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out,
        return unlang_xlat_yield(request, xlat_icmp_resume, xlat_icmp_cancel, echo);
 }
 
+extern xlat_arg_parser_t xlat_icmp_arg;
+xlat_arg_parser_t xlat_icmp_arg = {
+       .required = false, .concat = true, .variadic = false, .type = FR_TYPE_STRING, .func = NULL, .uctx = NULL
+};
+
 static int echo_cmp(void const *one, void const *two)
 {
        rlm_icmp_echo_t const *a = one;
@@ -535,14 +535,15 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance,
 
 static int mod_bootstrap(void *instance, CONF_SECTION *conf)
 {
-       rlm_icmp_t *inst = instance;
-       xlat_t const *xlat;
+       rlm_icmp_t      *inst = instance;
+       xlat_t          *xlat;
 
        inst->xlat_name = cf_section_name2(conf);
        if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf);
        inst->name = inst->xlat_name;
 
        xlat = xlat_register(inst, inst->xlat_name, xlat_icmp, true);
+       xlat_func_mono(xlat, &xlat_icmp_arg);
        xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_icmp_t *, NULL, inst);
        xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, xlat_icmp_thread_inst_t, NULL, inst);
 
index 718800dd5c03ae9a50aeb949b0263d2e47fde1fd..0bd0c439dedadd8a89af0117ad7c65cd2bf93b17 100644 (file)
@@ -1,5 +1,5 @@
 update control {
-       &Tmp-String-0 := "%{ping:127.0.0.1}"
+       &Tmp-String-0 := "%(ping:127.0.0.1)"
 }
 
 #