If statement regex match with multiple similar attributes

Herwin Weststrate herwin at quarantainenet.nl
Wed Jan 7 10:23:13 CET 2015


On 07-01-15 09:49, jberry at plus.net wrote:
> Hi there,
> 
> Freeradius version: 2.2.5
> 
> I have a question relating to how if statements applied to a packet are
> handled.
> 
> I have a packet something like this (I¹ve snipped a load of stuff) that
> contains 2 class attributes:
> 
>  Framed-Protocol = PPP
>  Class = 0x5030323a3***************************************
>  ...
>  Class = 0x434653494421****************
>  ...
> 
> 
> I am trying to overwrite some attributes in the post-auth section based on
> a Class attribute matching a given string being present. I can get this
> working like so using a sting comparison on the hex:
> 
>  if( reply:Class =~ /^0x5030323a3/ ) {
>    update reply {
>      ...
>    }
>  }
> 
> What I can¹t get to work is making the if statement check the second Class
> attribute (the one I actually want to check!). It is not feasible to
> change the order they appear because of the complexity of the system (and
> tbh I would probably not want to assume it would always be second). So if
> I go with:
> 
>  if( reply:Class =~ /^0x434653494421/ ) {
>    update reply {
>      ...
>    }
>  }
> 
> 
> The debug shows it trying and failing to match
> 
>  ++? if (reply:Class =~ /0x434653494421/ )
>  ? Evaluating (reply:Class =~ /0x434653494421/) -> FALSE
>  ++? if (reply:Class =~ /0x434653494421/ ) -> FALSE
> 
> 
> Any ideas? I can¹t find anything in the docs or on google (mainly because
> its a really hard search term)

Is upgrading your FreeRADIUS a possibility? Starting from version 3,
there is a foreach statement in unlang, that can loop through the results.

Otherwise, if it is always the second Class, you could use
%{reply:Class[1]}, but this feels a bit like a hack. There are some
hints about this in the man page of unlang.

-- 
Herwin Weststrate


More information about the Freeradius-Users mailing list