[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnu-radius] new rewrite function suggestion + patch, use case: DHCP
From: |
Josef Liška |
Subject: |
[Bug-gnu-radius] new rewrite function suggestion + patch, use case: DHCP assignment based on switch and port |
Date: |
Fri, 24 Apr 2009 00:35:16 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090318) |
Hello,
I have chosen GNU radius as backend for my dhcp servers on mikrotik
routeros 3.x,
because it is probably most flexible implementation of radius server.
I need to do special rewriting of request in order to achieve IP address
assignment based on
switch and port and not mac address. For this i use dhcp option 82 on
switches, which sets
Agent-Remote-Id and Agent-Circuit-Id.
Agent-Remote-Id is basically mac address of the switch, and Circuit-Id
is basically port number and vlan.
Rewrite language is strong enough to do the transformation in case of
text fields. But Agent-Remote-Id
and Agent-Circuit-Id are binary. Rewrite includes function qprn, which I
simply modified to new function tohex.
tohex encodes all characters, so that field and gsub can be used to
separate useful bytes from
Agent-Remote-Id and Agent-Circuit-Id.
My rewrite configuration is:
string
decode_agent_remote_id()
{
string agent;
string newagent;
agent = gsub("%"," ",tohex(%[Agent-Remote-Id]));
newagent =
field(agent,3)+":"+field(agent,4)+":"+field(agent,5)+":"+field(agent,6)+":"+field(agent,7)+":"+field(agent,8);
%[Orig-User-Name] = %[User-Name];
%[User-Name] = newagent+"port:"+field(gsub("%","
",tohex(%[Agent-Circuit-Id])),6);
return 0;
}
This return user names like "00:15:77:B1:D7:10port:03"
I would like to ask to include tohex function in next release, as this
might be useful.
--
Best regards
Josef Liška
CHL | system care
Phone: +420.272048055
Fax: +420.272048064
Cell: +420.776026526 denně 9:00 - 17:30 CEST
<https://www.chl.cz/>
--- radius-1.6.1/radiusd/rewrite.y 2008-12-15 09:03:24.000000000 +0100
+++ radius-1.6.1-phokz/radiusd/rewrite.y 2009-04-17 17:09:15.000000000
+0200
@@ -5519,6 +5519,34 @@
*p = 0;
}
+/* Phokz's hack */
+
+static void
+bi_tohex()
+{
+ grad_string_t arg;
+ char *p, *s, *end;
+ size_t count;
+ RWSTYPE *sp;
+
+ mem2string(&arg, (RWSTYPE*)getarg(1));
+ end = arg.data + arg.size;
+
+ /* Each encoded character takes 3 bytes. */
+ sp = heap_reserve(sizeof(RWSTYPE) + 3*arg.size + 1);
+ sp[0] = 3*arg.size;
+ pushn((RWSTYPE) sp);
+
+ for (p = (char*)(sp + 1), s = arg.data; s < end; s++) {
+ char buf[3];
+ snprintf(buf, sizeof buf, "%02X", *(unsigned char*)s);
+ *p++ = '%';
+ *p++ = buf[0];
+ *p++ = buf[1];
+ }
+ *p = 0;
+}
+
static void
bi_quote_string()
{
@@ -5667,6 +5695,8 @@
/* Time functions */
{ bi_time, "time", Integer, "" },
{ bi_strftime, "strftime", String, "si" },
+ /* Phokz's hack */
+ { bi_tohex, "tohex", String, "s" },
{ NULL }
};
jl.vcf
Description: Vcard
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gnu-radius] new rewrite function suggestion + patch, use case: DHCP assignment based on switch and port,
Josef Liška <=