From: Alan T. DeKok Date: Thu, 5 Sep 2024 23:56:18 +0000 (-0400) Subject: move to protocol::enum for subrequest X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a09fe8774d5b8d25d0f15c6352004e07842d6cfa;p=thirdparty%2Ffreeradius-server.git move to protocol::enum for subrequest because 'foo.bar' is an attribute reference when there's no "&", so we can't use "dhcpv4.Discover" --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 82a05820086..01ee69f9883 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -1797,11 +1797,6 @@ static CONF_ITEM *process_subrequest(cf_stack_t *stack) return NULL; } - if (token != T_BARE_WORD) { - ERROR("%s[%d]: The first argument to 'subrequest' must be a name or an attribute reference", - frame->filename, frame->lineno); - return NULL; - } mod = buff[1]; /* diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 0883c64657f..c3f6c0306a6 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -3958,7 +3958,7 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c char *namespace = NULL; char const *packet_name = NULL; - char *p; + char *p = NULL; tmpl_t *vpt = NULL, *src_vpt = NULL, *dst_vpt = NULL; @@ -4001,8 +4001,11 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c /* * If !tmpl_require_enum_prefix, '&' means "attribute reference". + * + * Or, bare word means "attribute reference". */ - if (name2[0] == '&') { + if ((name2[0] == '&') || + (tmpl_require_enum_prefix && ((p = strchr(name2, ':')) == NULL))) { size_t slen; slen = tmpl_afrom_attr_substr(parent, NULL, &vpt, @@ -4034,6 +4037,37 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c goto get_packet_type; } + /* + * subrequest foo::bar { ... } + * + * Change to dictionary "foo", packet type "bar". + */ + if (p) { + if (p[1] != ':') { + cf_log_err(cs, "Invalid syntax in namespace::enum"); + return NULL; + } + + MEM(namespace = talloc_strdup(parent, name2)); /* get a modifiable copy */ + + p = namespace + (p - name2); + *p = '\0'; + p += 2; + packet_name = p; + + dict = fr_dict_by_protocol_name(namespace); + if (!dict) { + dict_ref = fr_dict_autoload_talloc(NULL, &dict, namespace); + if (!dict_ref) { + cf_log_err(cs, "Unknown namespace '%s'", namespace); + talloc_free(namespace); + return NULL; + } + } + + goto get_packet_type; + } + /* * subrequest foo { ... } * @@ -4044,7 +4078,7 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c dict = unlang_ctx->rules->attr.dict_def; packet_name = name2; - } else { + } else if (!tmpl_require_enum_prefix) { /* * subrequest foo.bar { ... } * @@ -4065,6 +4099,17 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c return NULL; } } + + WARN("Deprecated syntax 'subrequest %s ...'", name2); + WARN(" please switch to 'subrequest %s::%s ...", namespace, packet_name); + + } else { + /* + * We have tmpl_require_enum prefix, so bare word foo.bar is "attribute foo, + * sub-attribute bar" + */ + dict = unlang_ctx->rules->attr.dict_def; + packet_name = name2; } /*