tmpl_attr_insert(vpt, ar);
}
- fr_sbuff_marker_release(&m_s);
+ if (tmpl_is_attr(vpt) && (tmpl_rules_cast(vpt) == tmpl_da(vpt)->type)) vpt->rules.cast = FR_TYPE_NULL;
+ fr_sbuff_marker_release(&m_s);
return 0;
}
tmpl_set_name(vpt, T_BARE_WORD, fr_sbuff_start(&our_name), fr_sbuff_used(&our_name));
vpt->rules = *t_rules; /* Record the rules */
+ if (tmpl_is_attr(vpt) && (tmpl_da(vpt)->type == tmpl_rules_cast(vpt))) vpt->rules.cast = FR_TYPE_NULL;
if (!tmpl_substr_terminal_check(&our_name, p_rules)) {
fr_strerror_const("Unexpected text after attribute reference");
*out = vpt;
+ if (tmpl_rules_cast(vpt) == tmpl_value_type(vpt)) vpt->rules.cast = FR_TYPE_NULL;
+
TMPL_VERIFY(vpt);
return fr_sbuff_set(in, &our_in);
vpt->quote = tmpl_cast_quote(vpt->quote, type, enumv,
unescaped, talloc_array_length(unescaped) - 1);
talloc_free(unescaped);
+
+ /*
+ * The data is now of the correct type, so we don't need to keep a cast.
+ */
+ vpt->rules.cast = FR_TYPE_NULL;
}
break;
} else {
vpt->quote = T_BARE_WORD;
}
+
+ /*
+ * The data is now of the correct type, so we don't need to keep a cast.
+ */
+ vpt->rules.cast = FR_TYPE_NULL;
}
break;
- case TMPL_TYPE_ATTR: /* FIXME - We should check cast compatibility with resolved attrs */
+ case TMPL_TYPE_ATTR:
+ /*
+ * Suppress casts to the same type.
+ */
+ if (tmpl_da(vpt)->type == type) {
+ vpt->rules.cast = FR_TYPE_NULL;
+ break;
+ }
+ FALL_THROUGH;
+
case TMPL_TYPE_ATTR_UNRESOLVED:
vpt->rules.cast = type;
break;
* The attribute reference needs resolving.
*/
} else if (tmpl_contains_attr(vpt)) {
+ fr_type_t dst_type = tmpl_rules_cast(vpt);
+
ret = tmpl_attr_resolve(vpt, tr_rules);
+ if (ret < 0) return ret;
+
+ if (dst_type == tmpl_da(vpt)->type) {
+ vpt->rules.cast = FR_TYPE_NULL;
+ }
+
/*
* Convert unresolved tmpls int enumvs, or failing that, string values.
match &User-Name == &User-Password
condition <ipv6addr>::1
-match ERROR offset 0: Cannot do cast for existence check
+match ERROR offset 0: Invalid cast from ipv6addr to bool. Unsupported
condition <ipaddr>&Filter-Id == &Framed-IP-Address
match <ipaddr>&Filter-Id == &Framed-IP-Address
# Normalize things
#
condition <ipaddr>127.0.0.1 < &Framed-IP-Address
-match &Framed-IP-Address > <ipaddr>127.0.0.1
+match &Framed-IP-Address > 127.0.0.1
# =* and !* are only for attrs / lists
condition "foo" !* bar
match true
condition <ipaddr>127.0.0.1 == "%{md4: 127.0.0.1}"
-match <ipaddr>127.0.0.1 == "%{md4: 127.0.0.1}"
+match 127.0.0.1 == "%{md4: 127.0.0.1}"
#
# Bare %{...} is allowed.
#
condition <ipaddr>127.0.0.1 == %{md4:127.0.0.1}
-match <ipaddr>127.0.0.1 == %{md4:127.0.0.1}
+match 127.0.0.1 == %{md4:127.0.0.1}
condition <ipaddr>127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'}
-match <ipaddr>127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'}
+match 127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'}
condition <ether> 00:11:22:33:44:55 == "00:11:22:33:44:55"
match true
condition <ether>00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}"
-match <ether>00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}"
+match 00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}"
condition <ether> 00:XX:22:33:44:55 == 00:11:22:33:44:55
match ERROR offset 12: Missing separator, expected ':'
# is on the LHS of the condition.
#
condition <string>"foo" == &User-Name
-match &User-Name == <string>"foo"
+match &User-Name == "foo"
# This used to be expr, but expr isn't a builtin, so it failed...
condition <integer>"%{md4: 1 + 1}" < &NAS-Port
match <ipaddr>&Filter-Id == &Framed-IP-Address
condition <ipaddr>127.0.0.1 == &Filter-Id
-match <ipaddr>&Filter-Id == <ipaddr>127.0.0.1
+match <ipaddr>&Filter-Id == 127.0.0.1
condition &Tmp-uint64-0 == &request.Foo-Stuff-Bar
match &Tmp-uint64-0 == &Foo-Stuff-Bar
# is parsed as ipv4prefix
#
condition <ipv4prefix>192.168.0.0/24 > &NAS-IP-Address
-match <ipv4prefix>&NAS-IP-Address < <ipv4prefix>192.168.0.0/24
+match <ipv4prefix>&NAS-IP-Address < 192.168.0.0/24
#
# This is allowed and means "the list is not empty"
# Forcefully cast RHS bareword
condition &User-Name == <ipaddr>192.168.0.1
-match <ipaddr>&User-Name == <ipaddr>192.168.0.1
+match <ipaddr>&User-Name == 192.168.0.1
# Forcefully cast LHS bareword
condition <ipaddr>192.168.0.1 == &User-Name
-match <ipaddr>&User-Name == <ipaddr>192.168.0.1
+match <ipaddr>&User-Name == 192.168.0.1
# Forcefully cast RHS single quotes
#condition &Framed-IP-Address == <ipaddr>'192.168.0.1'
match &Packet-Src-IPv6-Address == ::
condition &Packet-Src-IP-Address == <ipaddr>*
-match &Packet-Src-IP-Address == <ipaddr>0.0.0.0
+match &Packet-Src-IP-Address == 0.0.0.0
condition &Packet-Src-IP-Address == 0.0.0.0
match &Packet-Src-IP-Address == 0.0.0.0