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 /accel-pppd/ctrl/ipoe/lua.c | |
| 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
Diffstat (limited to 'accel-pppd/ctrl/ipoe/lua.c')
| -rw-r--r-- | accel-pppd/ctrl/ipoe/lua.c | 48 |
1 files changed, 48 insertions, 0 deletions
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"); |
