]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/utils: rename union inaddr to union kr_sockaddr
authorOto Šťáva <oto.stava@nic.cz>
Mon, 20 Dec 2021 11:28:40 +0000 (12:28 +0100)
committerOto Šťáva <oto.stava@nic.cz>
Mon, 20 Dec 2021 11:30:54 +0000 (12:30 +0100)
16 files changed:
daemon/bindings/net.c
daemon/io.c
daemon/lua/kres-gen-29.lua
daemon/lua/kres-gen-31.lua
daemon/lua/kres-gen.sh
daemon/session.c
daemon/tls.c
daemon/worker.c
lib/resolve.h
lib/selection.c
lib/selection.h
lib/selection_forward.c
lib/selection_iter.c
lib/utils.h
modules/hints/hints.c
modules/stats/stats.c

index f0b7cb69cf5745bae099d25ba7a5419fbdb02e1c..ec9c822c87366777ba1e399e72c47fe8be62bbbd 100644 (file)
@@ -929,11 +929,11 @@ static int net_tls_sticket_secret_file(lua_State *L)
 
 static int net_outgoing(lua_State *L, int family)
 {
-       union inaddr *addr;
+       union kr_sockaddr *addr;
        if (family == AF_INET)
-               addr = (union inaddr*)&the_worker->out_addr4;
+               addr = (union kr_sockaddr*)&the_worker->out_addr4;
        else
-               addr = (union inaddr*)&the_worker->out_addr6;
+               addr = (union kr_sockaddr*)&the_worker->out_addr6;
 
        if (lua_gettop(L) == 0) { /* Return the current value. */
                if (addr->ip.sa_family == AF_UNSPEC) {
index fff74a01d9b167429f6c208c3232d72de72ea829..7a4d7eb28b507e1b927ecfc869089c863bb97180 100644 (file)
@@ -196,7 +196,7 @@ int io_listen_udp(uv_loop_t *loop, uv_udp_t *handle, int fd)
        kr_require(s);
        session_flags(s)->outgoing = false;
 
-       int socklen = sizeof(union inaddr);
+       int socklen = sizeof(union kr_sockaddr);
        ret = uv_udp_getsockname(handle, session_get_sockname(s), &socklen);
        if (ret) {
                kr_log_error(IO, "ERROR: getsockname failed: %s\n", uv_strerror(ret));
index b1a09f9aaf797f0e55e6dc7c823e9cc3e6550176..554d44702b29ccb3bdfacf2ea307c5fe151b7dec 100644 (file)
@@ -163,10 +163,10 @@ typedef struct {
        size_t cap;
 } kr_http_header_array_t;
 typedef struct {
-       union inaddr *at;
+       union kr_sockaddr *at;
        size_t len;
        size_t cap;
-} inaddr_array_t;
+} kr_sockaddr_array_t;
 struct kr_zonecut {
        knot_dname_t *name;
        knot_rrset_t *key;
@@ -229,7 +229,7 @@ struct kr_request {
                addr_info_f is_tls_capable;
                addr_info_f is_tcp_connected;
                addr_info_f is_tcp_waiting;
-               inaddr_array_t forwarding_targets;
+               kr_sockaddr_array_t forwarding_targets;
        } selection_context;
        unsigned int count_no_nsaddr;
        unsigned int count_fail_row;
index 8fe3ac8c32ab7c9d9c88f4594914f0ddd763c799..e44966113f85a77c81adad5204878b325ec98137 100644 (file)
@@ -163,10 +163,10 @@ typedef struct {
        size_t cap;
 } kr_http_header_array_t;
 typedef struct {
-       union inaddr *at;
+       union kr_sockaddr *at;
        size_t len;
        size_t cap;
-} inaddr_array_t;
+} kr_sockaddr_array_t;
 struct kr_zonecut {
        knot_dname_t *name;
        knot_rrset_t *key;
@@ -229,7 +229,7 @@ struct kr_request {
                addr_info_f is_tls_capable;
                addr_info_f is_tcp_connected;
                addr_info_f is_tcp_waiting;
-               inaddr_array_t forwarding_targets;
+               kr_sockaddr_array_t forwarding_targets;
        } selection_context;
        unsigned int count_no_nsaddr;
        unsigned int count_fail_row;
index b4244505fc80287f737c53ad84aed5fb0d0e4cdf..fb730266dd8f361114f45cb0e95c6638f3099337 100755 (executable)
@@ -120,7 +120,7 @@ ${CDEFS} ${LIBKRES} types <<-EOF
        ranked_rr_array_t
        kr_http_header_array_entry_t
        kr_http_header_array_t
-       inaddr_array_t
+       kr_sockaddr_array_t
        struct kr_zonecut
        kr_qarray_t
        struct kr_rplan
index 3df4933c0c7db548b75f2eace1e60e3e55a6a536..0ef74134982b80c35da2fcec128b5665a4ab0777 100644 (file)
@@ -28,8 +28,8 @@
  */
 struct session {
        struct session_flags sflags;  /**< miscellaneous flags. */
-       union inaddr peer;            /**< address of peer; not for UDP clients (downstream) */
-       union inaddr sockname;        /**< our local address; for UDP it may be a wildcard */
+       union kr_sockaddr peer;       /**< address of peer; not for UDP clients (downstream) */
+       union kr_sockaddr sockname;   /**< our local address; for UDP it may be a wildcard */
        uv_handle_t *handle;          /**< libuv handle for IO operations. */
        uv_timer_t timeout;           /**< libuv handle for timer. */
 
index 317a008ffb0e68a8223958f74a3bd2d8fd87b5fe..0071c0535e22440154dc79289024a8f17fc44179 100644 (file)
@@ -842,7 +842,7 @@ tls_client_param_t * tls_client_param_new()
  * \param len[out] output length
  * \param key[out] output buffer
  */
-static bool construct_key(const union inaddr *addr, uint32_t *len, char *key)
+static bool construct_key(const union kr_sockaddr *addr, uint32_t *len, char *key)
 {
        switch (addr->ip.sa_family) {
        case AF_INET:
@@ -875,7 +875,7 @@ tls_client_param_t ** tls_client_param_getptr(tls_client_params_t **params,
                        return NULL;
        }
        /* Construct the key. */
-       const union inaddr *ia = (const union inaddr *)addr;
+       const union kr_sockaddr *ia = (const union kr_sockaddr *)addr;
        char key[sizeof(ia->ip6.sin6_port) + sizeof(ia->ip6.sin6_addr)];
        uint32_t len;
        if (!construct_key(ia, &len, key))
@@ -887,7 +887,7 @@ tls_client_param_t ** tls_client_param_getptr(tls_client_params_t **params,
 
 int tls_client_param_remove(tls_client_params_t *params, const struct sockaddr *addr)
 {
-       const union inaddr *ia = (const union inaddr *)addr;
+       const union kr_sockaddr *ia = (const union kr_sockaddr *)addr;
        char key[sizeof(ia->ip6.sin6_port) + sizeof(ia->ip6.sin6_addr)];
        uint32_t len;
        if (!construct_key(ia, &len, key))
index e5379d11c2fde20fd5c478682c901fd91d80be5b..73a1900f9369a0e23d06849ef7f33efe6233409b 100644 (file)
@@ -64,10 +64,10 @@ struct request_ctx
                /** NULL if the request didn't come over network. */
                struct session *session;
                /** Requestor's address; separate because of UDP session "sharing". */
-               union inaddr addr;
+               union kr_sockaddr addr;
                /** Local address.  For AF_XDP we couldn't use session's,
                 * as the address might be different every time. */
-               union inaddr dst_addr;
+               union kr_sockaddr dst_addr;
                /** MAC addresses - ours [0] and router's [1], in case of AF_XDP socket. */
                uint8_t eth_addrs[2][6];
        } source;
@@ -163,11 +163,11 @@ static uv_handle_t *ioreq_spawn(struct worker_ctx *worker,
        }
 
        /* Bind to outgoing address, according to IP v4/v6. */
-       union inaddr *addr;
+       union kr_sockaddr *addr;
        if (family == AF_INET) {
-               addr = (union inaddr *)&worker->out_addr4;
+               addr = (union kr_sockaddr *)&worker->out_addr4;
        } else {
-               addr = (union inaddr *)&worker->out_addr6;
+               addr = (union kr_sockaddr *)&worker->out_addr6;
        }
        if (addr->ip.sa_family != AF_UNSPEC) {
                if (kr_fails_assert(addr->ip.sa_family == family)) {
index efd665671350f6fb84b6ee589fa6061ac8d82369..beea663a01824ea3b152071203c08d41d9a0ee9d 100644 (file)
@@ -186,7 +186,7 @@ struct kr_request_qsource_flags {
 
 typedef bool (*addr_info_f)(struct sockaddr*);
 typedef void (*async_resolution_f)(knot_dname_t*, enum knot_rr_type);
-typedef array_t(union inaddr) inaddr_array_t;
+typedef array_t(union kr_sockaddr) kr_sockaddr_array_t;
 
 /**
  * Name resolution request.
@@ -246,7 +246,7 @@ struct kr_request {
                addr_info_f is_tls_capable;
                addr_info_f is_tcp_connected;
                addr_info_f is_tcp_waiting;
-               inaddr_array_t forwarding_targets; /**< When forwarding, possible targets are put here */
+               kr_sockaddr_array_t forwarding_targets; /**< When forwarding, possible targets are put here */
        } selection_context;
        unsigned int count_no_nsaddr;
        unsigned int count_fail_row;
index 0a20d0dfa010e9b818d7b24d992233714a662f2f..8e737fc9323ab3b73b6b263393179dccd081b8b1 100644 (file)
@@ -180,7 +180,7 @@ int put_rtt_state(const uint8_t *ip, size_t len, struct rtt_state state,
        return ret;
 }
 
-void bytes_to_ip(uint8_t *bytes, size_t len, uint16_t port, union inaddr *dst)
+void bytes_to_ip(uint8_t *bytes, size_t len, uint16_t port, union kr_sockaddr *dst)
 {
        switch (len) {
        case sizeof(struct in_addr):
@@ -199,7 +199,7 @@ void bytes_to_ip(uint8_t *bytes, size_t len, uint16_t port, union inaddr *dst)
        }
 }
 
-uint8_t *ip_to_bytes(const union inaddr *src, size_t len)
+uint8_t *ip_to_bytes(const union kr_sockaddr *src, size_t len)
 {
        switch (len) {
        case sizeof(struct in_addr):
@@ -311,7 +311,7 @@ static void check_network_settings(struct address_state *address_state,
        }
 }
 
-void update_address_state(struct address_state *state, union inaddr *address,
+void update_address_state(struct address_state *state, union kr_sockaddr *address,
                          size_t address_len, struct kr_query *qry)
 {
        check_tls_capable(state, qry->request, &address->ip);
@@ -751,7 +751,7 @@ int kr_forward_add_target(struct kr_request *req, const struct sockaddr *sock)
                return kr_error(EINVAL);
        }
 
-       union inaddr address;
+       union kr_sockaddr address;
 
        switch (sock->sa_family) {
        case AF_INET:
index f3d7ffbee2009457b15bfd8448a85bdabe6f1479..0b1c44973db4f3e3c12a0e8477dadf12269d3c14 100644 (file)
@@ -66,7 +66,7 @@ enum kr_transport_protocol {
  */
 struct kr_transport {
        knot_dname_t *ns_name; /**< Set to "." for forwarding targets.*/
-       union inaddr address;
+       union kr_sockaddr address;
        size_t address_len;
        enum kr_transport_protocol protocol;
        unsigned timeout; /**< Timeout in ms to be set for UDP transmission. */
@@ -179,7 +179,7 @@ struct address_state {
  * @brief Array of these is one of inputs for the actual selection algorithm (`select_transport`)
  */
 struct choice {
-       union inaddr address;
+       union kr_sockaddr address;
        size_t address_len;
        struct address_state *address_state;
        /** used to overwrite the port number;
@@ -245,12 +245,12 @@ int put_rtt_state(const uint8_t *ip, size_t len, struct rtt_state state,
 /**
  * @internal Helper function for conversion between different IP representations.
  */
-void bytes_to_ip(uint8_t *bytes, size_t len, uint16_t port, union inaddr *dst);
+void bytes_to_ip(uint8_t *bytes, size_t len, uint16_t port, union kr_sockaddr *dst);
 
 /**
  * @internal Helper function for conversion between different IP representations.
  */
-uint8_t *ip_to_bytes(const union inaddr *src, size_t len);
+uint8_t *ip_to_bytes(const union kr_sockaddr *src, size_t len);
 
 /**
  * @internal Fetch per-address information from various sources.
@@ -258,5 +258,5 @@ uint8_t *ip_to_bytes(const union inaddr *src, size_t len);
  * Note that this opens a RO cache transaction; the callee is responsible
  * for its closing not too long afterwards (e.g. calling kr_cache_commit).
  */
-void update_address_state(struct address_state *state, union inaddr *address,
+void update_address_state(struct address_state *state, union kr_sockaddr *address,
                          size_t address_len, struct kr_query *qry);
index f60117d29419d7a9da9d9cc472610f61fa58b071..0a97da92948988b86d574fc9df56a3837aa58fc9 100644 (file)
@@ -10,7 +10,7 @@
 #define FORWARDING_TIMEOUT 2000
 
 struct forward_local_state {
-       inaddr_array_t *targets;
+       kr_sockaddr_array_t *targets;
        struct address_state *addr_states;
        /** Index of last choice in the targets array, used for error reporting. */
        size_t last_choice_index;
@@ -38,7 +38,7 @@ void forward_choose_transport(struct kr_query *qry,
        int valid = 0;
 
        for (int i = 0; i < local_state->targets->len; i++) {
-               union inaddr *address = &local_state->targets->at[i];
+               union kr_sockaddr *address = &local_state->targets->at[i];
                size_t addr_len;
                uint16_t port;
                switch (address->ip.sa_family) {
index 1d284d8fbe5fecef75b8c2f1aba1737b721333dd..2e70265be24ad93f11bd9c5a35304ab9c8590211 100644 (file)
@@ -121,7 +121,7 @@ static void unpack_state_from_zonecut(struct iter_local_state *local_state,
                        } else if (address_len == sizeof(struct in6_addr)) {
                                name_state->aaaa_state = RECORD_RESOLVED;
                        }
-                       union inaddr tmp_address;
+                       union kr_sockaddr tmp_address;
                        bytes_to_ip(address, address_len, 0, &tmp_address);
                        update_address_state(address_state, &tmp_address, address_len, qry);
                }
index a1eb928502b6ac7256a74c95a14831e79052d3ad..89000ff063c41a77f85d1949d8e383e54b964379 100644 (file)
@@ -233,8 +233,8 @@ int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
 KR_EXPORT
 void kr_pkt_make_auth_header(knot_pkt_t *pkt);
 
-/** Simple storage for IPx address or AF_UNSPEC. */
-union inaddr {
+/** Simple storage for IPx address and their ports or AF_UNSPEC. */
+union kr_sockaddr {
        struct sockaddr ip;
        struct sockaddr_in ip4;
        struct sockaddr_in6 ip6;
index 01e9b6d68f593a21a18be6639c98f24897b3ca64..737b7683fc7cfeb6f19c5dbc9d03bd58026978c8 100644 (file)
@@ -169,7 +169,7 @@ static int query(kr_layer_t *ctx, knot_pkt_t *pkt)
        return KR_STATE_DONE;
 }
 
-static int parse_addr_str(union inaddr *sa, const char *addr)
+static int parse_addr_str(union kr_sockaddr *sa, const char *addr)
 {
        int family = strchr(addr, ':') ? AF_INET6 : AF_INET;
        memset(sa, 0, sizeof(*sa));
@@ -220,7 +220,7 @@ static const knot_dname_t * raw_addr2reverse(const uint8_t *raw_addr, int family
 static const knot_dname_t * addr2reverse(const char *addr)
 {
        /* Parse address string */
-       union inaddr ia;
+       union kr_sockaddr ia;
        if (parse_addr_str(&ia, addr) != 0) {
                return NULL;
        }
@@ -237,7 +237,7 @@ static int add_pair(struct kr_zonecut *hints, const char *name, const char *addr
        }
        knot_dname_to_lower(key);
 
-       union inaddr ia;
+       union kr_sockaddr ia;
        if (parse_addr_str(&ia, addr) != 0) {
                return kr_error(EINVAL);
        }
@@ -276,7 +276,7 @@ static int del_pair(struct hints_data *data, const char *name, const char *addr)
 
         if (addr) {
                /* Remove the pair. */
-               union inaddr ia;
+               union kr_sockaddr ia;
                if (parse_addr_str(&ia, addr) != 0) {
                        return kr_error(EINVAL);
                }
index 0cb7d32e58d2cf1f125713d125a034973f6ddec4..3b69cd1f1f8d417e57ab1ba6b26a67dfd566776e 100644 (file)
@@ -156,7 +156,7 @@ static int collect_rtt(kr_layer_t *ctx, knot_pkt_t *pkt)
        /* Socket address is encoded into sockaddr_in6 struct that
         * unions with sockaddr_in and differ in sa_family */
        struct sockaddr_in6 *e = &data->upstreams.q.at[data->upstreams.head];
-       const union inaddr *src = &req->upstream.transport->address;
+       const union kr_sockaddr *src = &req->upstream.transport->address;
        switch (src->ip.sa_family) {
                case AF_INET:  memcpy(e, &src->ip4, sizeof(src->ip4)); break;
                case AF_INET6: memcpy(e, &src->ip6, sizeof(src->ip6)); break;