new rewrite function suggestion + patch, use case: DHCP assignment based on switch and port
Josef Liška <[email protected]> Fri, 24 Apr 2009 00:35:16 +0200
| Newsgroups | gmane.comp.gnu.radius.bugs |
|---|---|
| Organization | CHL počítače, s.r.o. |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------020003020700090700060202
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Hello,
I have chosen GNU radius as backend for my dhcp servers on mikrotik=20
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=20
assignment based on
switch and port and not mac address. For this i use dhcp option 82 on=20
switches, which sets
Agent-Remote-Id and Agent-Circuit-Id.
Agent-Remote-Id is basically mac address of the switch, and Circuit-Id=20
is basically port number and vlan.
Rewrite language is strong enough to do the transformation in case of=20
text fields. But Agent-Remote-Id
and Agent-Circuit-Id are binary. Rewrite includes function qprn, which I=20
simply modified to new function tohex.
tohex encodes all characters, so that field and gsub can be used to=20
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 =3D gsub("%"," ",tohex(%[Agent-Remote-Id]));
newagent =3D=20
field(agent,3)+":"+field(agent,4)+":"+field(agent,5)+":"+field(agent,6)+"=
:"+field(agent,7)+":"+field(agent,8);
%[Orig-User-Name] =3D %[User-Name];
%[User-Name] =3D newagent+"port:"+field(gsub("%","=20
",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=20
might be useful.
--=20
Best regards
Josef Li=C5=A1ka
CHL | system care
Phone: +420.272048055
Fax: +420.272048064
Cell: +420.776026526 denn=C4=9B 9:00 - 17:30 CEST
<https://www.chl.cz/>
--------------020003020700090700060202
Content-Type: text/x-diff;
name="phokz_tohex.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="phokz_tohex.patch"
--- 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 }
};
--------------020003020700090700060202
Content-Type: text/x-vcard; charset=utf-8;
name="jl.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="jl.vcf"
YmVnaW46dmNhcmQNCmZuO3F1b3RlZC1wcmludGFibGU6Sm9zZWYgTGk9QzU9QTFrYQ0Kbjtx
dW90ZWQtcHJpbnRhYmxlOkxpPUM1PUExa2E7Sm9zZWYNCm9yZztxdW90ZWQtcHJpbnRhYmxl
OkNITCBwbz1DND04RD1DMz1BRHRhPUM0PThEZSwgcy5yLm8uDQphZHI7cXVvdGVkLXByaW50
YWJsZTo7O0thcmxhIE1hamVyYSA5MztWPUM1PUExZW5vcnk7OzI1MiAzMTtDemVjaCBSZXB1
YmxpYw0KZW1haWw7aW50ZXJuZXQ6amxAY2hsLmN6DQp0aXRsZTpyb290DQp0ZWw7d29yazor
NDIwIDI3MiAwNDggMDU1DQp0ZWw7ZmF4Ois0MjAgMjcyIDA0OCAwNjQNCnRlbDtjZWxsOis0
MjAgNzc2IDAyNjUyNg0Kbm90ZTpqYWJiZXI6IGpsQGNobC5jeg0KeC1tb3ppbGxhLWh0bWw6
RkFMU0UNCnVybDpodHRwOi8vd3d3LmNobC5jeg0KdmVyc2lvbjoyLjENCmVuZDp2Y2FyZA0K
DQo=
--------------020003020700090700060202
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Bug-gnu-radius mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gnu-radius
--------------020003020700090700060202--