From cf5756733d007584d297e52001e4781a41eb37ac Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Thu, 20 May 2021 23:20:51 +0200 Subject: [PATCH] Tweak "magic split" comments --- freeradius_utils/auth.py | 6 +----- radius/api/views.py | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/freeradius_utils/auth.py b/freeradius_utils/auth.py index dc052a78..9c1fd295 100644 --- a/freeradius_utils/auth.py +++ b/freeradius_utils/auth.py @@ -198,11 +198,7 @@ def post_auth(data): .first() ) # Find the port number from freeradius - # - # For Juniper, the result looks something like this: NAS-Port-Id = "ge-0/0/6.0"" - # For other brands (e.g. HP or Mikrotik), the result usually looks like: NAS-Port-Id = "6.0" - # This "magic split" handles both cases - # Cisco can rot in Hell for all I care, so their format is not supported (it looks like NAS-Port-ID = atm 31/31/7:255.65535 guangzhou001/0/31/63/31/127) + # See above for details about this "magic split" port = port.split(".")[0].split("/")[-1][-2:] out = decide_vlan_switch(nas_machine, nas_type, port, mac) sw_name, room, reason, vlan_id, decision, attributes = out diff --git a/radius/api/views.py b/radius/api/views.py index 6c56073d..ba490b04 100644 --- a/radius/api/views.py +++ b/radius/api/views.py @@ -150,7 +150,10 @@ def post_auth(request, nas_id, nas_port, user_mac): if hasattr(nas_interface.machine, "switch"): stack = nas_interface.machine.switch.stack if stack: - # magic split + # For Juniper, the result looks something like this: NAS-Port-Id = "ge-0/0/6.0"" + # For other brands (e.g. HP or Mikrotik), the result usually looks like: NAS-Port-Id = "6.0" + # This "magic split" handles both cases + # Cisco can rot in Hell for all I care, so their format is not supported (it looks like NAS-Port-ID = atm 31/31/7:255.65535 guangzhou001/0/31/63/31/127) id_stack_member = nas_port.split("-")[1].split("/")[0] switch = ( Switch.objects.filter(stack=stack) @@ -161,7 +164,7 @@ def post_auth(request, nas_id, nas_port, user_mac): # get the switch port port = None if nas_port and nas_port != "None": - # magic split + # magic split (see above) port_number = nas_port.split(".")[0].split("/")[-1][-2:] port = Port.objects.filter(switch=switch, port=port_number).first()