diff options
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 5 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.h | 1 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/lua.c | 48 |
3 files changed, 54 insertions, 0 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 9e1a989b..e843b504 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -2245,6 +2245,11 @@ static int make_vlan_name(const char *parent, int svid, int cvid, char *name) const char *ptr2 = conf_vlan_name; char svid_str[5], cvid_str[5], *ptr3; +#ifdef USE_LUA + if (!memcmp(conf_vlan_name, "lua:", 4)) + return ipoe_lua_make_vlan_name(conf_vlan_name + 4, parent, svid, cvid, name); +#endif + sprintf(svid_str, "%i", svid); sprintf(cvid_str, "%i", cvid); diff --git a/accel-pppd/ctrl/ipoe/ipoe.h b/accel-pppd/ctrl/ipoe/ipoe.h index 1405092e..036eda80 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.h +++ b/accel-pppd/ctrl/ipoe/ipoe.h @@ -108,6 +108,7 @@ struct ipoe_session_info { #ifdef USE_LUA char *ipoe_lua_get_username(struct ipoe_session *, const char *func); +int ipoe_lua_make_vlan_name(const char *func, const char *parent, int svid, int cvid, char *name); #endif struct iphdr; diff --git a/accel-pppd/ctrl/ipoe/lua.c b/accel-pppd/ctrl/ipoe/lua.c index 84da9d12..b27b1f26 100644 --- a/accel-pppd/ctrl/ipoe/lua.c +++ b/accel-pppd/ctrl/ipoe/lua.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <string.h> #include <pthread.h> +#include <net/if.h> /* Include the Lua API header files. */ #include <lua.h> @@ -268,6 +269,53 @@ out: return r; } +int ipoe_lua_make_vlan_name(const char *func, const char *parent, int svid, int cvid, char *name) +{ + int r = -1; + const char *res; + + if (file_error && serial == __serial) + return -1; + + if (L && serial != __serial) { + lua_close(L); + init_lua(); + } else if (!L) + init_lua(); + + if (!L) + return -1; + + lua_getglobal(L, func); + lua_pushstring(L, parent); + lua_pushinteger(L, svid); + lua_pushinteger(L, cvid); + + if (lua_pcall(L, 3, 1, 0)) { + log_ppp_error("ipoe: lua: %s\n", lua_tostring(L, -1)); + lua_pop(L, 1); + goto out; + } + + if (!lua_isstring(L, -1)) { + log_ppp_error("ipoe: lua: function '%s' must return a string\n", func); + goto out; + } + + res = lua_tostring(L, -1); + + if (strlen(res) >= IFNAMSIZ) + goto out; + + strcpy(name, res); + r = 0; + +out: + lua_settop(L, 0); + + return r; +} + static void load_config() { conf_filename = conf_get_opt("ipoe", "lua-file"); |