提交 d569e009 编写于 作者: D Dmitry Kozlov

ipoe: lua: introduced hwaddr field to session object

example function to use mac address as username:
function username(ses)
    return ses:hwaddr()
end
上级 cead7e72
...@@ -33,6 +33,7 @@ static int packet4_options(lua_State *L); ...@@ -33,6 +33,7 @@ static int packet4_options(lua_State *L);
static int packet4_agent_circuit_id(lua_State *L); static int packet4_agent_circuit_id(lua_State *L);
static int packet4_agent_remote_id(lua_State *L); static int packet4_agent_remote_id(lua_State *L);
static int packet4_vlan(lua_State *L); static int packet4_vlan(lua_State *L);
static int packet4_hwaddr(lua_State *L);
int luaopen_lpack(lua_State *L); int luaopen_lpack(lua_State *L);
int luaopen_bit(lua_State *L); int luaopen_bit(lua_State *L);
...@@ -45,6 +46,7 @@ static const struct luaL_reg packet4_lib [] = { ...@@ -45,6 +46,7 @@ static const struct luaL_reg packet4_lib [] = {
{"agent_circuit_id", packet4_agent_circuit_id}, {"agent_circuit_id", packet4_agent_circuit_id},
{"agent_remote_id", packet4_agent_remote_id}, {"agent_remote_id", packet4_agent_remote_id},
{"vlan", packet4_vlan}, {"vlan", packet4_vlan},
{"hwaddr", packet4_hwaddr},
{NULL, NULL} {NULL, NULL}
}; };
...@@ -185,6 +187,21 @@ static int packet4_vlan(lua_State *L) ...@@ -185,6 +187,21 @@ static int packet4_vlan(lua_State *L)
return 1; return 1;
} }
static int packet4_hwaddr(lua_State *L)
{
struct ipoe_session *ses = luaL_checkudata(L, 1, IPOE_PACKET4);
char str[20];
if (!ses)
return 0;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
ses->hwaddr[0], ses->hwaddr[1], ses->hwaddr[2], ses->hwaddr[3], ses->hwaddr[4], ses->hwaddr[5]);
lua_pushstring(L, str);
return 1;
}
static void init_lua() static void init_lua()
{ {
__serial = serial; __serial = serial;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册