How to get client IP address/target port in python code
Good day! I use rlm_python plugin to add custom logic to the Freeradius. For logging purposes I want to know client IP address and target port. I check source code of freeradius and found that its possible to obtain this information from request structure. However I can't find how to get it from python code. Is it possible? Thanks
On May 8, 2019, at 5:37 AM, Dmitriy Golubev <golubev.dmitriy@gmail.com> wrote:
I use rlm_python plugin to add custom logic to the Freeradius. For logging purposes I want to know client IP address and target port. I check source code of freeradius and found that its possible to obtain this information from request structure. However I can't find how to get it from python code.
The attributes are "virtual" in that you can reference them, but they're not in any list. The fix is simple: make them real. update request { Tmp-IP-Address-0 := Packet-Src-IP-Address ... } See Packet Src / Dst IP-Address / Port. Alan DeKok.
Alan, good day! Thank you for your reply. When I post this question I found 2 things: 1. This code working: update request { &Packet-Src-IP-Address = "%{Packet-Src-IP-Address}" &Packet-Dst-Port = "%{Packet-Dst-Port}" } Is it correct? In your code I see that you don't use '&', don't expand attribute value and use fake attribute name instead of real one. I am not expert in unlang, can you explain these differences? 2. 'preprocess' module add NAS-IP-Address and populate it with Client IP address in case if it was not filed by RADIUS client. This behavior is ok for me. Thanks On Wed, May 8, 2019 at 1:30 PM Alan DeKok <aland@deployingradius.com> wrote:
On May 8, 2019, at 5:37 AM, Dmitriy Golubev <golubev.dmitriy@gmail.com> wrote:
I use rlm_python plugin to add custom logic to the Freeradius. For logging purposes I want to know client IP address and target port. I check source code of freeradius and found that its possible to obtain this information from request structure. However I can't find how to get it from python code.
The attributes are "virtual" in that you can reference them, but they're not in any list.
The fix is simple: make them real.
update request { Tmp-IP-Address-0 := Packet-Src-IP-Address ... }
See Packet Src / Dst IP-Address / Port.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On May 8, 2019, at 8:29 AM, Dmitriy Golubev <golubev.dmitriy@gmail.com> wrote:
Thank you for your reply. When I post this question I found 2 things: 1. This code working: update request { &Packet-Src-IP-Address = "%{Packet-Src-IP-Address}" &Packet-Dst-Port = "%{Packet-Dst-Port}" } Is it correct? In your code I see that you don't use '&', don't expand attribute value
Sure. My example was a quick response. The above should work.
and use fake attribute name instead of real one.
The issue there is that Packet-Src-IP-Address is a virtual attribute, with certain behaviour. The above might work, but it may also have side effects. I prefer to do something that I *know* works. Alan DeKok.
Thank you very much On Wed, May 8, 2019 at 3:38 PM Alan DeKok <aland@deployingradius.com> wrote:
On May 8, 2019, at 8:29 AM, Dmitriy Golubev <golubev.dmitriy@gmail.com> wrote:
Thank you for your reply. When I post this question I found 2 things: 1. This code working: update request { &Packet-Src-IP-Address = "%{Packet-Src-IP-Address}" &Packet-Dst-Port = "%{Packet-Dst-Port}" } Is it correct? In your code I see that you don't use '&', don't expand attribute value
Sure. My example was a quick response. The above should work.
and use fake attribute name instead of real one.
The issue there is that Packet-Src-IP-Address is a virtual attribute, with certain behaviour. The above might work, but it may also have side effects. I prefer to do something that I *know* works.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
participants (2)
-
Alan DeKok -
Dmitriy Golubev