New feature in v3: cast!

Alan DeKok aland at deployingradius.com
Sun May 12 14:40:14 CEST 2013


Brian Candler wrote:
> 1. Why is <ipaddr> necessary before the literal? Surely an unquoted
> 127.0.0.1 can't be parsed as anything else.

  See my other example for why it's necessary.

  In *some* cases, you know the data type of an expression.  In those
cases, you can easily do type-specific comparisons.  That's what unlang
does today:

	if (Framed-IP-Address == 127.0.0.1) {

  The type is "ipaddr", because of Framed-IP-Address.  The RHS is in
fact parsed into a second Framed-IP-Address attribute, and the two are
compared.

  However... you can't currently do a type-safe comparison like:

	if (127.0.0.1 < 127.0.0.2) {

  The interpretor does *string* comparisons.  Which is wrong for IP
addresses.  Adding a cast allows you to do:

	if (<ipaddr>127.0.0.1 < 127.0.0.2) {

  Which does type-safe checks as with Framed-IP-Address, above.

> 2. What does the & in front of Framed-IP-Address do?

$ man unlang  :)

  It's a reference.

	if (&User-Name == &Filter-Id) {

  Does type-safe comparisons on the *values* of the two attributes.  The
v2 unlang code would require you to do:

	if (User-Name == "%{Filter-Id}") {

  Which converts Filter-Id to a string, parses the string into a
temporary User-Name attribute, and then compares the two User-Name
attributes.

  Using a reference means you can skip 2 out of 3 of those steps.

  Alan DeKok.


More information about the Freeradius-Devel mailing list