diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2015-12-01 18:43:11 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2015-12-01 18:43:11 +0300 |
commit | b1c5ae767273119283089b35a79f1a64952234af (patch) | |
tree | 5237c6ecf92b4c68836199d002d86fdf039bbe32 | |
parent | e6c5b180e9b3fe0afac48bffe80522813a35b405 (diff) | |
download | accel-ppp-b1c5ae767273119283089b35a79f1a64952234af.tar.gz accel-ppp-b1c5ae767273119283089b35a79f1a64952234af.zip |
ipoe: implemented ability to use lua to make vlan name
[ipoe]
vlan-name=lua:make_vlan_name
lua function accepts three arguments: parent interface name, parent vlan number and vlan number caused vlan creation
sample lua function:
function make_vlan_name(ifname, svid, cvid)
print('make_vlan_name: '..ifname..','..svid..','..cvid)
return ifname..'.'..cvid
end
-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"); |