Hi all, I currently have some unlang code that looks like this (I've fixed the wrapping to make it legible: if ((&request:NAS-IP-Address =~ /^192.168.0.3[2-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.[45][0-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.6[0-3]/)) { ... do stuff } This is a check for "Is the NAS-IP-Address in 192.168.0.32/27"? Is there a neater way to do this? - the obvious option: if (&request:NAS-IP-Address == 192.168.0.32/27) { doesn't work, and I can't see any anything else in a rummage through the documentation that might work. It isn't a big deal, the regex option works; it just isn't very elegant. Thanks Paul.
On Mon, 2017-12-04 at 15:05 +0000, Paul Thornton wrote:
if ((&request:NAS-IP-Address =~ /^192.168.0.3[2-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.[45][0-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.6[0-3]/)) { ... do stuff }
This is a check for "Is the NAS-IP-Address in 192.168.0.32/27"?
Is there a neater way to do this? - the obvious option: if (&request:NAS-IP-Address == 192.168.0.32/27) {
if (NAS-IP-Address < "192.168.0.32/27") { ... } -- Matthew
Hi,
if (NAS-IP-Address < "192.168.0.32/27") { ... }
Thanks, much neater.
I find the lack of mathematical correctness of this operator disturbing. The RHS is a set, and the LHS is either an element contained in this set or not. If only the config files were UTF-8, then the operator to use would be "ELEMENT OF", U+2208, ∈. Stefan -- Stefan WINTER Ingenieur de Recherche Fondation RESTENA - Réseau Téléinformatique de l'Education Nationale et de la Recherche 2, avenue de l'Université L-4365 Esch-sur-Alzette Tel: +352 424409 1 Fax: +352 422473 PGP key updated to 4096 Bit RSA - I will encrypt all mails if the recipient's key is known to me http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0DE6A358A39DC66
On Dec 6, 2017, at 9:56 AM, Stefan Winter <stefan.winter@restena.lu> wrote:
I find the lack of mathematical correctness of this operator disturbing.
I spent a long time doing math and set theory. You're not wrong.
The RHS is a set, and the LHS is either an element contained in this set or not.
Yes.
If only the config files were UTF-8, then the operator to use would be "ELEMENT OF", U+2208, ∈.
The config files are UTF-8. Feel free to send a patch allowing this. :) But until there's an easy way to enter unicode characters on all operating systems, overloading "<" and ">" is terrible, but useful. If we wanted to go the Perl route, we would just add all kinds of special operators with magic characters. Or, just use text: if (Framed-IP-Address IN 192.0.2.0/24) But internally, that would likely just map to "<". Alan DeKok.
On 4 Dec 2017, at 15:10, Matthew Newton <mcn@freeradius.org> wrote:
On Mon, 2017-12-04 at 15:05 +0000, Paul Thornton wrote:
if ((&request:NAS-IP-Address =~ /^192.168.0.3[2-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.[45][0-9]/) || (&request:NAS-IP-Address =~ /^192.168.0.6[0-3]/)) { ... do stuff }
This is a check for "Is the NAS-IP-Address in 192.168.0.32/27"?
Is there a neater way to do this? - the obvious option: if (&request:NAS-IP-Address == 192.168.0.32/27) {
if (NAS-IP-Address < "192.168.0.32/27") { ... }
You need to cast NAS-IP-Address to the IPv4 prefix type I think?
participants (5)
-
Alan DeKok -
Arran Cudbard-Bell -
Matthew Newton -
Paul Thornton -
Stefan Winter