72
72
* - netif_rx() feedback
73
73
*/
74
74
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
79
86
80
87
#include <linux/uaccess.h>
81
88
#include <linux/bitops.h>
@@ -891,6 +898,8 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
891
898
lua_State * L = NULL ;
892
899
lua_state_cpu * sc ;
893
900
int cpu ;
901
+ int base ;
902
+ int data_ref ;
894
903
u32 ret = 0 ;
895
904
896
905
cpu = smp_processor_id ();
@@ -904,16 +913,22 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
904
913
if (!L )
905
914
goto out ;
906
915
916
+ base = lua_gettop (L );
907
917
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 );
909
919
goto out ;
910
920
}
911
921
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
+ }
914
927
ret = lua_tointeger (L , -1 );
915
- lua_pop (L , 1 );
916
928
929
+ cleanup :
930
+ lua_settop (L , base );
931
+ ldata_unref (L , data_ref );
917
932
out :
918
933
return ret ;
919
934
}
@@ -5219,7 +5234,11 @@ int generic_xdp_lua_install(char *lua_prog) {
5219
5234
lua_state_cpu * sc ;
5220
5235
5221
5236
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
+ }
5223
5242
}
5224
5243
5225
5244
return 0 ;
@@ -9927,6 +9946,7 @@ static int __init net_dev_init(void)
9927
9946
}
9928
9947
9929
9948
luaL_openlibs (new_state_cpu -> L );
9949
+ luaL_requiref (new_state_cpu -> L , "data" , luaopen_data , 1 );
9930
9950
new_state_cpu -> cpu = i ;
9931
9951
9932
9952
list_add (& new_state_cpu -> list , & lua_state_cpu_list );
0 commit comments