Match newline in Cisco-AVPair[*]
Hello all, I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is ... if ("%{Cisco-AVPair[*]}" =~ /client-mac-address=(.*)/) { update control { My-Client-Mac-Address = "%{1}" } } ... The problem is that the regex I am using matches all newlines, so I get all Cisco-AVpair[X] after my match. The regex /client-mac-address=(.*)$/ does not seem to work. Is there any way to match the newline and get only the mac-address I am interested in? Sorry if this was replied in the past, the few tricks I tried did not work and being lazy, I posted in the list for a quick reply. Any suggestions welcome. Regards, Kostas -- Kostas Zorbadelos http://gr.linkedin.com/in/kzorba
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
The problem is that the regex I am using matches all newlines, so I get all Cisco-AVpair[X] after my match. The regex /client-mac-address=(.*)$/ does not seem to work. Is there any way to match the newline and get only the mac-address I am interested in?
Not really. Alan DeKok.
On 15 Apr 2015, at 15:08, Alan DeKok <aland@deployingradius.com> wrote:
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
No, the way he's doing it should work.
The problem is that the regex I am using matches all newlines, so I get all Cisco-AVpair[X] after my match. The regex /client-mac-address=(.*)$/ does not seem to work. Is there any way to match the newline and get only the mac-address I am interested in?
Could you provide debug output, I don't really understand what you're trying to say. -Arran Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS development team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
On 15 Apr 2015, at 16:15, Arran Cudbard-Bell <a.cudbardb@freeradius.org> wrote:
On 15 Apr 2015, at 15:08, Alan DeKok <aland@deployingradius.com> wrote:
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
No, the way he's doing it should work.
(0) update request { (0) Cisco-AVPair := 'foo=bar' (0) Cisco-AVPair += 'bar=baz' (0) Cisco-AVPair += 'baz=foo' (0) } # update request = noop (0) if (&Cisco-AVPair[*] =~ /bar=(.*)/) { (0) if (&Cisco-AVPair[*] =~ /bar=(.*)/) -> TRUE (0) if (&Cisco-AVPair[*] =~ /bar=(.*)/) { (0) if ("%{1}" != 'baz') { (0) EXPAND %{1} (0) --> baz (0) if ("%{1}" != 'baz') -> FALSE (0) } # if (&Cisco-AVPair[*] =~ /bar=(.*)/) = noop (0) ... skipping else for request 0: Preceding "if" was taken It works because the matching is short circuited when it finds a value that matches the regex. So the capture groups are from the last value that matched. Anyway, added a test case to make sure it doesn't break in future. -Arran Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS development team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
Arran Cudbard-Bell <a.cudbardb@freeradius.org> writes: Hi,
On 15 Apr 2015, at 15:08, Alan DeKok <aland@deployingradius.com> wrote:
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
the way I see it, I cannot do a "foreach" in unlang. I would need to create my own module, right? I perform the check in the accounting { section, to get my attribute and then update a database.
No, the way he's doing it should work.
The problem is that the regex I am using matches all newlines, so I get all Cisco-AVpair[X] after my match. The regex /client-mac-address=(.*)$/ does not seem to work. Is there any way to match the newline and get only the mac-address I am interested in?
Could you provide debug output, I don't really understand what you're trying to say.
sites-enabled/default: ... accounting { # Calculate the PPPoE Client Mac Address if ("%{ERX-Pppoe-Description}" =~ /pppoe (.*)/) { update control { My-Client-Mac-Address = "%{1}" } } elsif ("%{Cisco-AVPair[*]}" =~ /client-mac-address=(.*)/) { update control { My-Client-Mac-Address = "%{1}" } } else { update control { My-Client-Mac-Address = "unknown" } } detail sql } Example accounting in detail file (sensitive info stripped): Wed Apr 15 17:14:13 2015 Acct-Interim-Interval = 5400 Acct-Session-Time = 334800 Acct-Status-Type = Interim-Update Event-Timestamp = "Apr 15 2015 17:14:13 EEST" Cisco-AVPair = "parent-if-handle=134530272" NAS-Port-Type = Wireless-XGP Cisco-AVPair = "if-handle=135556640" Cisco-AVPair = "client-mac-address=4ced.de1e.0bca" ADSL-Agent-Circuit-Id = "0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4" Cisco-AVPair = "circuit-id-tag=0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4" Acct-Session-Id = "005c18e1" NAS-Port = 16777951 NAS-Port-Id = "#0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4#" Cisco-NAS-Port = "#0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4#" Called-Station-Id = "XXXXXXXX#" Calling-Station-Id = "0 0/0/1.735 # 0 0/0/0:4096.735 <DSLAM INFO>/0/0/17/0/4" User-Name = "XXXXXXX@DOMAIN" Acct-Authentic = RADIUS Framed-IP-Address = <user IP> Cisco-AVPair = "vrf-id=default" Cisco-AVPair = "accounting-list=default" Cisco-AVPair = "pppoe-session-id=36256" Framed-Protocol = PPP Service-Type = Framed-User X-Ascend-Connect-Progress = IPNCP-Opened Cisco-AVPair = "connect-progress=IPCP Open" Acct-Input-Octets = 3320876 Acct-Input-Packets = 45348 Acct-Output-Octets = 4102631 Acct-Output-Packets = 54145 Cisco-AVPair = "acct-input-octets-ipv4=90704" Cisco-AVPair = "acct-input-packets-ipv4=513" Cisco-AVPair = "acct-output-octets-ipv4=696656" Cisco-AVPair = "acct-output-packets-ipv4=9309" Cisco-AVPair = "acct-input-octets-ipv6=0" Cisco-AVPair = "acct-input-packets-ipv6=0" Cisco-AVPair = "acct-output-octets-ipv6=0" Cisco-AVPair = "acct-output-packets-ipv6=0" NAS-Identifier = "XXXXXXXX" NAS-IP-Address = <NAS IP ADDRESS> Acct-Delay-Time = 0 Proxy-State = 0x33383236 Acct-Unique-Session-Id = "08e2faefb2ddde79" Stripped-User-Name = "XXXXXXXX" Realm = "DOMAIN" Timestamp = 1429107253 With the above config My-Client-Mac-Address = "4ced.de1e.0bca\ncircuit-id-tag=0 0/0/0:4096.735 <D..." In the database I see '\n' as '=0A' as expected. I guess I can try to rewrite my regex. Any other suggestions, welcome. Regards, Kostas
-Arran
Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS development team
FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
elsif ("%{Cisco-AVPair[*]}" =~ /client-mac-address=(.*)/) { update control { My-Client-Mac-Address = "%{1}" }
"%{Cisco-AVPair[*]}" is not the same as &Cisco-AVPair[*]. The first example means concatenate all values of this attribute together using newlines. The second example means operate on all instances of this attribute. -Arran Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS development team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
On 15/04/15 17:10, Kostas Zorbadelos wrote:
Arran Cudbard-Bell <a.cudbardb@freeradius.org> writes:
Hi,
On 15 Apr 2015, at 15:08, Alan DeKok <aland@deployingradius.com> wrote:
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
the way I see it, I cannot do a "foreach" in unlang. I would need to
Yes you can. It was added in the 3.x series.
Phil Mayers <p.mayers@imperial.ac.uk> writes:
On Apr 15, 2015, at 9:29 AM, Kostas Zorbadelos <kzorba@otenet.gr> wrote:
I am trying to perform a match against the full Cisco-AVPair string (Cisco-AVPair[*]) to get a specific part. The exact check I am performing is
It would be better to loop over the Cisco-AVPairs with a "foreach", and the match the one you want.
the way I see it, I cannot do a "foreach" in unlang. I would need to
Yes you can. It was added in the 3.x series.
I understood that the required functionality exists in the 3.x series, so at some time I will need to upgrade. Running 2.2.x now, this is something I should have mentioned from the very beginning. As a workaround, until I upgrade, I performed a workaround in my regex, specifically "%{Cisco-AVPair[*]}" =~ /client-mac-address=(.{14})/ works as expected in my case and matches the information just before the \n (not including it). Not the "best" solution but works for now. Thanks everyone for the valuable input. Regards, Kostas
participants (4)
-
Alan DeKok -
Arran Cudbard-Bell -
Kostas Zorbadelos -
Phil Mayers