7272 * - netif_rx() feedback
7373 */
7474
75- #include "lua.h"
76- #include "lauxlib.h"
77- #include "lualib.h"
78- #include "luadata.h"
75+ #ifndef _LUNATIK_H
76+ #define _LUNATIK_H
77+ #include <lua.h>
78+ #include <lauxlib.h>
79+ #include <lualib.h>
80+ #endif
81+
82+ #ifndef _LUADATA_H
83+ #define _LUADATA_H
84+ #include <luadata.h>
85+ #endif
7986
8087#include <linux/uaccess.h>
8188#include <linux/bitops.h>
@@ -891,6 +898,8 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
891898 lua_State * L = NULL ;
892899 lua_state_cpu * sc ;
893900 int cpu ;
901+ int base ;
902+ int data_ref ;
894903 u32 ret = 0 ;
895904
896905 cpu = smp_processor_id ();
@@ -904,16 +913,22 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
904913 if (!L )
905914 goto out ;
906915
916+ base = lua_gettop (L );
907917 if (lua_getglobal (L , func ) != LUA_TFUNCTION ) {
908- printk (KERN_INFO "function %s not found\n" , func );
918+ printk (KERN_WARNING "function %s not found\n" , func );
909919 goto out ;
910920 }
911921
912- ldata_newref (L , ctx -> data , ctx -> data_end - ctx -> data );
913- lua_pcall (L , 1 , 1 , 0 );
922+ data_ref = ldata_newref (L , ctx -> data , ctx -> data_end - ctx -> data );
923+ if (lua_pcall (L , 1 , 1 , 0 )) {
924+ printk (KERN_WARNING "%s\n" , lua_tostring (L , -1 ));
925+ goto cleanup ;
926+ }
914927 ret = lua_tointeger (L , -1 );
915- lua_pop (L , 1 );
916928
929+ cleanup :
930+ lua_settop (L , base );
931+ ldata_unref (L , data_ref );
917932out :
918933 return ret ;
919934}
@@ -5219,7 +5234,11 @@ int generic_xdp_lua_install(char *lua_prog) {
52195234 lua_state_cpu * sc ;
52205235
52215236 list_for_each_entry (sc , & lua_state_cpu_list , list ) {
5222- luaL_dostring (sc -> L , lua_prog );
5237+ if (luaL_dostring (sc -> L , lua_prog )) {
5238+ printk (KERN_WARNING "error: %s\nOn cpu: %d\n" ,
5239+ lua_tostring (sc -> L , -1 ), sc -> cpu );
5240+ return -1 ;
5241+ }
52235242 }
52245243
52255244 return 0 ;
@@ -9927,6 +9946,7 @@ static int __init net_dev_init(void)
99279946 }
99289947
99299948 luaL_openlibs (new_state_cpu -> L );
9949+ luaL_requiref (new_state_cpu -> L , "data" , luaopen_data , 1 );
99309950 new_state_cpu -> cpu = i ;
99319951
99329952 list_add (& new_state_cpu -> list , & lua_state_cpu_list );
0 commit comments