]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: bind `struct network` into lua
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 10 Jun 2024 13:52:42 +0000 (15:52 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 22 Jul 2024 10:56:01 +0000 (12:56 +0200)
Because why not.  It's easy and it might become useful one day.
Unfortunately porting this to 5.x was a bit involved,
as there's no `the_network` yet - I reordered struct engine for it.

> (require 'ffi').C.the_worker.engine.net.tcp.user_timeout
1000

daemon/engine.h
daemon/lua/kres-gen-31.lua
daemon/lua/kres-gen-32.lua
daemon/lua/kres-gen.sh

index 63accd372fa3dcaba86abdc84f43bd54d17d8c71..900c10c68ebcc61e8f04bd113d2bb1688267aeb9 100644 (file)
@@ -14,8 +14,8 @@ struct lua_State;
 #include "daemon/network.h"
 
 struct engine {
-    struct kr_context resolver;
     struct network net;
+    struct kr_context resolver;
     module_array_t modules;
     array_t(const struct kr_cdb_api *) backends;
     knot_mm_t *pool;
index 46b349ea1aa48dd5f45fcf1e2da0aa005020ff63..02d510f423defed0ac830d864a4f13bd080243d5 100644 (file)
@@ -461,6 +461,7 @@ int kr_cache_remove(struct kr_cache *, const knot_dname_t *, uint16_t);
 int kr_cache_remove_subtree(struct kr_cache *, const knot_dname_t *, _Bool, int);
 int kr_cache_commit(struct kr_cache *);
 uint32_t packet_ttl(const knot_pkt_t *);
+struct tls_credentials;
 typedef struct {
        int sock_type;
        _Bool tls;
@@ -511,6 +512,36 @@ typedef struct {
        zi_callback cb;
        void *cb_param;
 } zi_config_t;
+typedef struct uv_loop_s uv_loop_t;
+typedef struct trie tls_client_params_t;
+struct net_tcp_param {
+       uint64_t in_idle_timeout;
+       uint64_t tls_handshake_timeout;
+       unsigned int user_timeout;
+};
+struct network {
+       uv_loop_t *loop;
+       trie_t *endpoints;
+       trie_t *endpoint_kinds;
+       _Bool missing_kind_is_error : 1;
+       _Bool proxy_all4 : 1;
+       _Bool proxy_all6 : 1;
+       trie_t *proxy_addrs4;
+       trie_t *proxy_addrs6;
+       struct tls_credentials *tls_credentials;
+       tls_client_params_t *tls_client_params;
+       struct tls_session_ticket_ctx *tls_session_ticket_ctx;
+       struct net_tcp_param tcp;
+       int tcp_backlog;
+       struct {
+               int snd;
+               int rcv;
+       } listen_udp_buflens;
+       struct {
+               int snd;
+               int rcv;
+       } listen_tcp_buflens;
+};
 struct args *the_args;
 struct endpoint {
        void *handle;
@@ -536,6 +567,7 @@ knot_pkt_t *worker_resolve_mk_pkt(const char *, uint16_t, uint16_t, const struct
 struct qr_task *worker_resolve_start(knot_pkt_t *, struct kr_qflags);
 int zi_zone_import(const zi_config_t);
 struct engine {
+       struct network net;
        struct kr_context resolver;
        char _stub[];
 };
index 88b50ded0ed20da587d6a63cbf5b15c0b8a0dc77..79d4eac5102e402d1076904a8dfad28e50c3669b 100644 (file)
@@ -462,6 +462,7 @@ int kr_cache_remove(struct kr_cache *, const knot_dname_t *, uint16_t);
 int kr_cache_remove_subtree(struct kr_cache *, const knot_dname_t *, _Bool, int);
 int kr_cache_commit(struct kr_cache *);
 uint32_t packet_ttl(const knot_pkt_t *);
+struct tls_credentials;
 typedef struct {
        int sock_type;
        _Bool tls;
@@ -512,6 +513,36 @@ typedef struct {
        zi_callback cb;
        void *cb_param;
 } zi_config_t;
+typedef struct uv_loop_s uv_loop_t;
+typedef struct trie tls_client_params_t;
+struct net_tcp_param {
+       uint64_t in_idle_timeout;
+       uint64_t tls_handshake_timeout;
+       unsigned int user_timeout;
+};
+struct network {
+       uv_loop_t *loop;
+       trie_t *endpoints;
+       trie_t *endpoint_kinds;
+       _Bool missing_kind_is_error : 1;
+       _Bool proxy_all4 : 1;
+       _Bool proxy_all6 : 1;
+       trie_t *proxy_addrs4;
+       trie_t *proxy_addrs6;
+       struct tls_credentials *tls_credentials;
+       tls_client_params_t *tls_client_params;
+       struct tls_session_ticket_ctx *tls_session_ticket_ctx;
+       struct net_tcp_param tcp;
+       int tcp_backlog;
+       struct {
+               int snd;
+               int rcv;
+       } listen_udp_buflens;
+       struct {
+               int snd;
+               int rcv;
+       } listen_tcp_buflens;
+};
 struct args *the_args;
 struct endpoint {
        void *handle;
@@ -537,6 +568,7 @@ knot_pkt_t *worker_resolve_mk_pkt(const char *, uint16_t, uint16_t, const struct
 struct qr_task *worker_resolve_start(knot_pkt_t *, struct kr_qflags);
 int zi_zone_import(const zi_config_t);
 struct engine {
+       struct network net;
        struct kr_context resolver;
        char _stub[];
 };
index 3befd5dae45e9bbb8909e8bf16984a67aca30944..270134d8ebd4e6ccfa97424bcf77debf2f5a7de4 100755 (executable)
@@ -289,6 +289,7 @@ EOF
 
 
 ## kresd itself: worker stuff
+echo "struct tls_credentials;"
 
 ${CDEFS} ${KRESD} types <<-EOF
        endpoint_flags_t
@@ -299,6 +300,11 @@ ${CDEFS} ${KRESD} types <<-EOF
        config_array_t
        struct args
        zi_config_t
+       # struct network - and all requirements that are missing so far
+       typedef uv_loop_t
+       typedef tls_client_params_t
+       struct net_tcp_param
+       struct network
 EOF
 echo "struct args *the_args;"
 
@@ -317,7 +323,7 @@ ${CDEFS} ${KRESD} functions <<-EOF
        zi_zone_import
 EOF
 
-echo "struct engine" | ${CDEFS} ${KRESD} types | sed '/struct network/,$ d'
+echo "struct engine" | ${CDEFS} ${KRESD} types | sed '/modules/,$ d'
 printf "\tchar _stub[];\n};\n"
 
 echo "struct worker_ctx" | ${CDEFS} ${KRESD} types | sed '/uv_loop_t/,$ d'