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 }
};
begin:vcard
fn;quoted-printable:Josef Li=C5=A1ka
n;quoted-printable:Li=C5=A1ka;Josef
org;quoted-printable:CHL po=C4=8D=C3=ADta=C4=8De, s.r.o.
adr;quoted-printable:;;Karla Majera 93;V=C5=A1enory;;252 31;Czech Republic
email;internet:[email protected]
title:root
tel;work:+420 272 048 055
tel;fax:+420 272 048 064
tel;cell:+420 776 026526
note:jabber: [email protected]
x-mozilla-html:FALSE
url:http://www.chl.cz
version:2.1
end:vcard
_______________________________________________
Bug-gnu-radius mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gnu-radius