From 2b256df842764409f0d1cd7a37afabcef4e2785b Mon Sep 17 00:00:00 2001 From: Kozlov Dmitry Date: Tue, 26 Jun 2012 19:16:57 +0400 Subject: ipoe: futher working --- accel-pppd/ctrl/ipoe/dhcpv4.c | 4 ++-- accel-pppd/ctrl/ipoe/ipoe.c | 3 ++- accel-pppd/ctrl/ipoe/lua.c | 45 ++++++++++++++++++++++++++++++++++------ accel-pppd/ctrl/ipoe/lua_lpack.c | 2 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index cd39deb..12923ee 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -108,8 +108,6 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna goto out_err; } - memcpy(serv->hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); - fcntl(raw_sock, F_SETFL, O_NONBLOCK); fcntl(raw_sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); @@ -119,6 +117,8 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna serv = _malloc(sizeof(*serv)); memset(serv, 0, sizeof(*serv)); + memcpy(serv->hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); + serv->ctx = ctx; serv->hnd.fd = sock; serv->hnd.read = dhcpv4_read; diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index ce7712f..1c54b7c 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -696,8 +696,9 @@ static void load_config(void) else if (strlen(opt) > 4 && memcmp(opt, "lua:", 4) == 0) { conf_username = USERNAME_LUA; conf_lua_username_func = opt + 4; + } #endif - } else + else log_emerg("ipoe: unknown username value '%s'\n", opt); } diff --git a/accel-pppd/ctrl/ipoe/lua.c b/accel-pppd/ctrl/ipoe/lua.c index 77beca6..0b24635 100644 --- a/accel-pppd/ctrl/ipoe/lua.c +++ b/accel-pppd/ctrl/ipoe/lua.c @@ -185,6 +185,12 @@ static void init_lua() if (lua_pcall(L, 0, 0, 0)) goto out_err; + lua_pushlightuserdata(L, L); + luaL_getmetatable(L, IPOE_PACKET4); + lua_setmetatable(L, -2); + + lua_settop(L, 0); + file_error = 0; pthread_setspecific(__key, L); @@ -198,6 +204,29 @@ out_err: L = NULL; } +/*static void stackDump (lua_State *L) { + int i=lua_gettop(L); + printf(" ---------------- Stack Dump ----------------" ); + while( i ) { + int t = lua_type(L, i); + switch (t) { + case LUA_TSTRING: + printf("%d:`%s'\n", i, lua_tostring(L, i)); + break; + case LUA_TBOOLEAN: + printf("%d: %s\n",i,lua_toboolean(L, i) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf("%d: %g\n", i, lua_tonumber(L, i)); + break; + default: printf("%d: %s\n", i, lua_typename(L, t)); break; + } + i--; + } + printf("--------------- Stack Dump Finished ---------------" ); + }*/ + + int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) { if (file_error && serial == __serial) @@ -211,27 +240,31 @@ int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) if (!L) return -1; - + lua_getglobal(L, func); lua_pushlightuserdata(L, ses); - luaL_getmetatable(L, IPOE_PACKET4); - lua_setmetatable(L, -2); if (lua_pcall(L, 1, 1, 0)) { log_ppp_error("ipoe: lua: %s\n", lua_tostring(L, -1)); - return -1; + goto out_err; } if (!lua_isstring(L, -1)) { log_ppp_error("ipoe: lua: function '%s' must return a string\n", func); - return -1; + goto out_err; } ses->ses.username = _strdup(lua_tostring(L, -1)); - lua_pop(L, 1); + lua_settop(L, 0); return 0; + +out_err: + file_error = 1; + lua_close(L); + L = NULL; + return -1; } static void load_config() diff --git a/accel-pppd/ctrl/ipoe/lua_lpack.c b/accel-pppd/ctrl/ipoe/lua_lpack.c index 22d3477..0dc3046 100644 --- a/accel-pppd/ctrl/ipoe/lua_lpack.c +++ b/accel-pppd/ctrl/ipoe/lua_lpack.c @@ -75,7 +75,7 @@ static void doswap(int swap, void *p, size_t n) memcpy(&a,s+i,m); \ i+=m; \ doswap(swap,&a,m); \ - lua_pushnumber(L,(lua_Number)a); \ + lua_pushinteger(L,(lua_Integer)a); \ ++n; \ break; \ } -- cgit v1.2.3