]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/bindings: eBPF socket filters bindings, avoid usage of lua 5.3 macro; fix...
authorGrigorii Demidov <grigorii.demidov@nic.cz>
Tue, 11 Dec 2018 14:57:57 +0000 (15:57 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 13 Dec 2018 11:26:38 +0000 (11:26 +0000)
daemon/bindings.c

index 271c52882751ea2de4dbff09a068851fd5587647..917943e1ec7e9c8029b22b8d2c3518edfc182772 100644 (file)
@@ -882,11 +882,10 @@ static int net_tls_handshake_timeout(lua_State *L)
 
 static int net_bpf_set(lua_State *L)
 {
-       int ret;
        struct engine *engine = engine_luaget(L);
        struct network *net = &engine->net;
 
-       if (lua_gettop(L) != 1 || lua_type(L, 1) != LUA_TINTEGER) {
+       if (lua_gettop(L) != 1 || !lua_isnumber(L, 1)) {
                format_error(L, "net.bpf_set(fd) takes one parameter: the open file descriptor of a loaded BPF program");
                lua_error(L);
                return 0;
@@ -895,6 +894,13 @@ static int net_bpf_set(lua_State *L)
 #if __linux__
 
        int progfd = lua_tointeger(L, 1);
+       if (progfd == 0) {
+               /* conversion error despite that fact
+                * that lua_isnumber(L, 1) has returned true.
+                * Real or stdin? */
+               lua_error(L);
+               return 0;
+       }
        lua_pop(L, 1);
 
        if (!network_set_bpf(net, progfd)) {
@@ -917,7 +923,6 @@ static int net_bpf_set(lua_State *L)
 
 static int net_bpf_clear(lua_State *L)
 {
-       int ret;
        struct engine *engine = engine_luaget(L);
        struct network *net = &engine->net;