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) {
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));
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;
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;
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;
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;
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
*/
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. */
* \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:
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))
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))
/** 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;
}
/* 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)) {
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.
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;
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):
}
}
-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):
}
}
-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);
return kr_error(EINVAL);
}
- union inaddr address;
+ union kr_sockaddr address;
switch (sock->sa_family) {
case AF_INET:
*/
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. */
* @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;
/**
* @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.
* 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);
#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;
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) {
} 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);
}
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;
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));
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;
}
}
knot_dname_to_lower(key);
- union inaddr ia;
+ union kr_sockaddr ia;
if (parse_addr_str(&ia, addr) != 0) {
return kr_error(EINVAL);
}
if (addr) {
/* Remove the pair. */
- union inaddr ia;
+ union kr_sockaddr ia;
if (parse_addr_str(&ia, addr) != 0) {
return kr_error(EINVAL);
}
/* 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;