diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2024-03-22 12:30:31 +0100 |
---|---|---|
committer | Oto Šťáva <oto.stava@nic.cz> | 2024-03-22 12:30:31 +0100 |
commit | 88b8fd0b155d3cf6268960ab3268bec4639d4583 (patch) | |
tree | 3aeb4f004a4f58227725587537aa9bcc359918d2 /daemon | |
parent | Merge branch 'doc-update-oci' into '6.0' (diff) | |
parent | Merge branch 'time_t' into 'master' (diff) | |
download | knot-resolver-88b8fd0b155d3cf6268960ab3268bec4639d4583.tar.xz knot-resolver-88b8fd0b155d3cf6268960ab3268bec4639d4583.zip |
Merge remote-tracking branch 'origin/master' into 6.0
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/lua/kres-gen-30.lua | 7 | ||||
-rw-r--r-- | daemon/lua/kres-gen-31.lua | 7 | ||||
-rw-r--r-- | daemon/lua/kres-gen-32.lua | 7 | ||||
-rwxr-xr-x | daemon/lua/kres-gen.sh | 15 | ||||
-rw-r--r-- | daemon/lua/meson.build | 19 | ||||
-rw-r--r-- | daemon/proxyv2.c | 45 | ||||
-rw-r--r-- | daemon/proxyv2.h | 23 |
7 files changed, 75 insertions, 48 deletions
diff --git a/daemon/lua/kres-gen-30.lua b/daemon/lua/kres-gen-30.lua index ae182a37..36e3e405 100644 --- a/daemon/lua/kres-gen-30.lua +++ b/daemon/lua/kres-gen-30.lua @@ -2,9 +2,10 @@ local ffi = require('ffi') --[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[ -typedef long time_t; -typedef long __time_t; -typedef long __suseconds_t; + +typedef @time_t@ time_t; +typedef @time_t@ __time_t; +typedef @time_t@ __suseconds_t; struct timeval { __time_t tv_sec; __suseconds_t tv_usec; diff --git a/daemon/lua/kres-gen-31.lua b/daemon/lua/kres-gen-31.lua index 1033e104..beeec867 100644 --- a/daemon/lua/kres-gen-31.lua +++ b/daemon/lua/kres-gen-31.lua @@ -2,9 +2,10 @@ local ffi = require('ffi') --[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[ -typedef long time_t; -typedef long __time_t; -typedef long __suseconds_t; + +typedef @time_t@ time_t; +typedef @time_t@ __time_t; +typedef @time_t@ __suseconds_t; struct timeval { __time_t tv_sec; __suseconds_t tv_usec; diff --git a/daemon/lua/kres-gen-32.lua b/daemon/lua/kres-gen-32.lua index 23a338f0..9edee2de 100644 --- a/daemon/lua/kres-gen-32.lua +++ b/daemon/lua/kres-gen-32.lua @@ -2,9 +2,10 @@ local ffi = require('ffi') --[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[ -typedef long time_t; -typedef long __time_t; -typedef long __suseconds_t; + +typedef @time_t@ time_t; +typedef @time_t@ __time_t; +typedef @time_t@ __suseconds_t; struct timeval { __time_t tv_sec; __suseconds_t tv_usec; diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index 5939dc65..5039a723 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -53,12 +53,15 @@ printf -- "local ffi = require('ffi')\n" printf -- "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[\n" # Some system dependencies. TODO: this generated part isn't perfectly portable. -${CDEFS} ${LIBKRES} types <<-EOF - typedef time_t - __time_t - __suseconds_t - struct timeval -EOF +printf " +typedef @time_t@ time_t; +typedef @time_t@ __time_t; +typedef @time_t@ __suseconds_t; +struct timeval { + __time_t tv_sec; + __suseconds_t tv_usec; +}; +" ## Various types (mainly), from libknot and libkres diff --git a/daemon/lua/meson.build b/daemon/lua/meson.build index b19777c2..6df5bc5b 100644 --- a/daemon/lua/meson.build +++ b/daemon/lua/meson.build @@ -47,10 +47,23 @@ else kres_gen_fname = 'kres-gen-30.lua' endif +# Exact types around time_t aren't easy to detect, but at least we need the same size. +time_t_size = meson.get_compiler('c').sizeof('time_t', prefix: '#include <sys/time.h>') +kres_gen_config = {} +foreach t: [ 'long', 'long long' ] + if meson.get_compiler('c').sizeof(t) == time_t_size + kres_gen_config = { 'time_t': t } + break + endif +endforeach +if kres_gen_config == {} + error('Unexpected sizeof(time_t) == @0@'.format(time_t_size)) +endif + kres_gen_lua = configure_file( input: kres_gen_fname, output: 'kres-gen.lua', - copy: true, + configuration: kres_gen_config, ) run_target( # run manually to re-generate kres-gen.lua @@ -72,9 +85,9 @@ if get_option('kres_gen_test') and not meson.is_cross_build() ] # Construct the lua tester as a meson string. kres_gen_test_luastr = ''' - dofile('@0@') + dofile('@0@/../../@1@') local ffi = require('ffi') - '''.format(meson.current_source_dir() / kres_gen_fname) + '''.format(meson.current_build_dir(), kres_gen_lua) foreach ttc: types_to_check # We're careful with adding just includes; otherwise it's more fragile (e.g. linking flags). if 'dep' in ttc diff --git a/daemon/proxyv2.c b/daemon/proxyv2.c index f796aad8..73eb5769 100644 --- a/daemon/proxyv2.c +++ b/daemon/proxyv2.c @@ -92,12 +92,12 @@ static inline enum proxy2_family proxy2_header_protocol(const struct proxy2_head static inline union proxy2_address *proxy2_get_address(const struct proxy2_header *h) { - return (union proxy2_address *) ((uint8_t *) h + sizeof(struct proxy2_header)); + return (union proxy2_address *)((uint8_t *)h + sizeof(struct proxy2_header)); } static inline struct proxy2_tlv *get_tlvs(const struct proxy2_header *h, size_t addr_len) { - return (struct proxy2_tlv *) ((uint8_t *) proxy2_get_address(h) + addr_len); + return (struct proxy2_tlv *)((uint8_t *)proxy2_get_address(h) + addr_len); } /** Gets the length of the TLV's `value` attribute. */ @@ -112,20 +112,20 @@ static inline bool has_tlv(const struct proxy2_header *h, uint64_t addr_length = ntohs(h->length); ptrdiff_t hdr_len = sizeof(struct proxy2_header) + addr_length; - uint8_t *tlv_hdr_end = (uint8_t *) tlv + sizeof(struct proxy2_tlv); - ptrdiff_t distance = tlv_hdr_end - (uint8_t *) h; + uint8_t *tlv_hdr_end = (uint8_t *)tlv + sizeof(struct proxy2_tlv); + ptrdiff_t distance = tlv_hdr_end - (uint8_t *)h; if (hdr_len < distance) return false; uint8_t *tlv_end = tlv_hdr_end + proxy2_tlv_length(tlv); - distance = tlv_end - (uint8_t *) h; + distance = tlv_end - (uint8_t *)h; return hdr_len >= distance; } static inline void next_tlv(struct proxy2_tlv **tlv) { - uint8_t *next = ((uint8_t *) *tlv + sizeof(struct proxy2_tlv) + proxy2_tlv_length(*tlv)); - *tlv = (struct proxy2_tlv *) next; + uint8_t *next = ((uint8_t *)*tlv + sizeof(struct proxy2_tlv) + proxy2_tlv_length(*tlv)); + *tlv = (struct proxy2_tlv *)next; } @@ -141,7 +141,7 @@ bool proxy_allowed(const struct sockaddr *saddr) trie = the_network->proxy_addrs4; addr_size = sizeof(addr.ip4); - addr.ip4 = ((struct sockaddr_in *) saddr)->sin_addr; + addr.ip4 = ((struct sockaddr_in *)saddr)->sin_addr; break; case AF_INET6: if (the_network->proxy_all6) @@ -149,7 +149,7 @@ bool proxy_allowed(const struct sockaddr *saddr) trie = the_network->proxy_addrs6; addr_size = sizeof(addr.ip6); - addr.ip6 = ((struct sockaddr_in6 *) saddr)->sin6_addr; + addr.ip6 = ((struct sockaddr_in6 *)saddr)->sin6_addr; break; default: kr_assert(false); // Only IPv4 and IPv6 proxy addresses supported @@ -157,14 +157,14 @@ bool proxy_allowed(const struct sockaddr *saddr) } trie_val_t *val; - int ret = trie_get_leq(trie, (char *) &addr, addr_size, &val); + int ret = trie_get_leq(trie, (char *)&addr, addr_size, &val); if (ret != kr_ok() && ret != 1) return false; kr_assert(val); const struct net_proxy_data *found = *val; kr_assert(found); - return kr_bitcmp((char *) &addr, (char *) &found->addr, found->netmask) == 0; + return kr_bitcmp((char *)&addr, (char *)&found->addr, found->netmask) == 0; } ssize_t proxy_process_header(struct proxy_result *out, @@ -173,7 +173,7 @@ ssize_t proxy_process_header(struct proxy_result *out, if (!buf) return kr_error(EINVAL); - const struct proxy2_header *hdr = (struct proxy2_header *) buf; + const struct proxy2_header *hdr = (struct proxy2_header *)buf; uint64_t content_length = ntohs(hdr->length); ssize_t hdr_len = sizeof(struct proxy2_header) + content_length; @@ -192,7 +192,7 @@ ssize_t proxy_process_header(struct proxy_result *out, enum proxy2_command command = proxy2_header_command(hdr); if (command == PROXY2_CMD_LOCAL) { /* Addresses for LOCAL are to be discarded */ - *out = (struct proxy_result) { .command = PROXY2_CMD_LOCAL }; + *out = (struct proxy_result){ .command = PROXY2_CMD_LOCAL }; goto fill_wirebuf; } @@ -201,13 +201,14 @@ ssize_t proxy_process_header(struct proxy_result *out, return kr_error(KNOT_EMALF); } - *out = (struct proxy_result) { .command = PROXY2_CMD_PROXY }; + *out = (struct proxy_result){ .command = PROXY2_CMD_PROXY }; /* Parse flags */ enum proxy2_family family = proxy2_header_family(hdr); switch(family) { case PROXY2_AF_UNSPEC: - case PROXY2_AF_UNIX: /* UNIX is unsupported, fall back to UNSPEC */ + case PROXY2_AF_UNIX: + /* UNIX is unsupported, fall back to UNSPEC */ out->family = AF_UNSPEC; break; case PROXY2_AF_INET: @@ -216,7 +217,8 @@ ssize_t proxy_process_header(struct proxy_result *out, case PROXY2_AF_INET6: out->family = AF_INET6; break; - default: /* PROXYv2 prohibits other values */ + default: + /* PROXYv2 prohibits other values */ return kr_error(KNOT_EMALF); } @@ -228,7 +230,8 @@ ssize_t proxy_process_header(struct proxy_result *out, case PROXY2_PROTOCOL_STREAM: out->protocol = SOCK_STREAM; break; - default: /* PROXYv2 prohibits other values */ + default: + /* PROXYv2 prohibits other values */ return kr_error(KNOT_EMALF); } @@ -241,12 +244,12 @@ ssize_t proxy_process_header(struct proxy_result *out, if (content_length < addr_length) return kr_error(KNOT_EMALF); - out->src_addr.ip4 = (struct sockaddr_in) { + out->src_addr.ip4 = (struct sockaddr_in){ .sin_family = AF_INET, .sin_addr = { .s_addr = addr->ipv4_addr.src_addr }, .sin_port = addr->ipv4_addr.src_port, }; - out->dst_addr.ip4 = (struct sockaddr_in) { + out->dst_addr.ip4 = (struct sockaddr_in){ .sin_family = AF_INET, .sin_addr = { .s_addr = addr->ipv4_addr.dst_addr }, .sin_port = addr->ipv4_addr.dst_port, @@ -257,7 +260,7 @@ ssize_t proxy_process_header(struct proxy_result *out, if (content_length < addr_length) return kr_error(KNOT_EMALF); - out->src_addr.ip6 = (struct sockaddr_in6) { + out->src_addr.ip6 = (struct sockaddr_in6){ .sin6_family = AF_INET6, .sin6_port = addr->ipv6_addr.src_port }; @@ -265,7 +268,7 @@ ssize_t proxy_process_header(struct proxy_result *out, &out->src_addr.ip6.sin6_addr.s6_addr, &addr->ipv6_addr.src_addr, sizeof(out->src_addr.ip6.sin6_addr.s6_addr)); - out->dst_addr.ip6 = (struct sockaddr_in6) { + out->dst_addr.ip6 = (struct sockaddr_in6){ .sin6_family = AF_INET6, .sin6_port = addr->ipv6_addr.dst_port }; diff --git a/daemon/proxyv2.h b/daemon/proxyv2.h index c18e71ce..a21f14b1 100644 --- a/daemon/proxyv2.h +++ b/daemon/proxyv2.h @@ -6,7 +6,6 @@ #include <stdint.h> -#include "daemon/session2.h" #include "lib/utils.h" extern const char PROXY2_SIGNATURE[12]; @@ -20,14 +19,20 @@ enum proxy2_command { /** Parsed result of the PROXY protocol */ struct proxy_result { - enum proxy2_command command; /**< Proxy command - PROXY or LOCAL. */ - int family; /**< Address family from netinet library (e.g. AF_INET6). */ - int protocol; /**< Protocol type from socket library (e.g. SOCK_STREAM). */ - union kr_sockaddr src_addr; /**< Parsed source address and port. */ - union kr_sockaddr dst_addr; /**< Parsed destination address and port. */ - bool has_tls : 1; /**< `true` = client has used TLS with the proxy. - If TLS padding is enabled, it will be used even if - the proxy did not use TLS with kresd. */ + /** Proxy command - PROXY or LOCAL. */ + enum proxy2_command command; + /** Address family from netinet library (e.g. AF_INET6). */ + int family; + /** Protocol type from socket library (e.g. SOCK_STREAM). */ + int protocol; + /** Parsed source address and port. */ + union kr_sockaddr src_addr; + /** Parsed destination address and port. */ + union kr_sockaddr dst_addr; + /** `true` = client has used TLS with the proxy. If TLS padding is + * enabled, it will be used even if the communication between kresd and + * the proxy is unencrypted. */ + bool has_tls : 1; }; /** Checks for a PROXY protocol version 2 signature in the specified buffer. */ |