unbound
0.1
|
Implementation of net_help.h. More...
#include "config.h"
#include "util/net_help.h"
#include "util/log.h"
#include "util/data/dname.h"
#include "util/module.h"
#include "util/regional.h"
#include "sldns/parseutil.h"
#include "sldns/wire2str.h"
#include <fcntl.h>
Macros | |
#define | MAX_ADDR_STRLEN 128 /* characters */ |
max length of an IP address (the address portion) that we allow | |
Functions | |
int | str_is_ip6 (const char *str) |
See if string is ip4 or ip6. More... | |
int | fd_set_nonblock (int s) |
Set fd nonblocking. More... | |
int | fd_set_block (int s) |
Set fd (back to) blocking. More... | |
int | is_pow2 (size_t num) |
See if number is a power of 2. More... | |
void * | memdup (void *data, size_t len) |
Allocate memory and copy over contents. More... | |
void | log_addr (enum verbosity_value v, const char *str, struct sockaddr_storage *addr, socklen_t addrlen) |
Prints the sockaddr in readable format with log_info. More... | |
int | extstrtoaddr (const char *str, struct sockaddr_storage *addr, socklen_t *addrlen) |
Convert address string, with "@port" appendix, to sockaddr. More... | |
int | ipstrtoaddr (const char *ip, int port, struct sockaddr_storage *addr, socklen_t *addrlen) |
Convert ip address string and port to sockaddr. More... | |
int | netblockstrtoaddr (const char *str, int port, struct sockaddr_storage *addr, socklen_t *addrlen, int *net) |
Convert ip netblock (ip/netsize) string and port to sockaddr. More... | |
void | log_nametypeclass (enum verbosity_value v, const char *str, uint8_t *name, uint16_t type, uint16_t dclass) |
Print string with neat domain name, type and class. More... | |
void | log_name_addr (enum verbosity_value v, const char *str, uint8_t *zone, struct sockaddr_storage *addr, socklen_t addrlen) |
Prints zone name and sockaddr in readable format with log_info. More... | |
void | log_err_addr (const char *str, const char *err, struct sockaddr_storage *addr, socklen_t addrlen) |
Log errno and addr. More... | |
int | sockaddr_cmp (struct sockaddr_storage *addr1, socklen_t len1, struct sockaddr_storage *addr2, socklen_t len2) |
Compare two sockaddrs. More... | |
int | sockaddr_cmp_addr (struct sockaddr_storage *addr1, socklen_t len1, struct sockaddr_storage *addr2, socklen_t len2) |
Compare two sockaddrs. More... | |
int | addr_is_ip6 (struct sockaddr_storage *addr, socklen_t len) |
Checkout address family. More... | |
void | addr_mask (struct sockaddr_storage *addr, socklen_t len, int net) |
Make sure the sockaddr ends in zeroes. More... | |
int | addr_in_common (struct sockaddr_storage *addr1, int net1, struct sockaddr_storage *addr2, int net2, socklen_t addrlen) |
See how many bits are shared, equal, between two addrs. More... | |
void | addr_to_str (struct sockaddr_storage *addr, socklen_t addrlen, char *buf, size_t len) |
Put address into string, works for IPv4 and IPv6. More... | |
int | addr_is_ip4mapped (struct sockaddr_storage *addr, socklen_t addrlen) |
See if sockaddr is an ipv6 mapped ipv4 address, "::ffff:0.0.0.0". More... | |
int | addr_is_broadcast (struct sockaddr_storage *addr, socklen_t addrlen) |
See if sockaddr is 255.255.255.255. More... | |
int | addr_is_any (struct sockaddr_storage *addr, socklen_t addrlen) |
See if sockaddr is 0.0.0.0 or ::0. More... | |
void | sock_list_insert (struct sock_list **list, struct sockaddr_storage *addr, socklen_t len, struct regional *region) |
Insert new socket list item. More... | |
void | sock_list_prepend (struct sock_list **list, struct sock_list *add) |
Append one list to another. More... | |
int | sock_list_find (struct sock_list *list, struct sockaddr_storage *addr, socklen_t len) |
Find addr in list. More... | |
void | sock_list_merge (struct sock_list **list, struct regional *region, struct sock_list *add) |
Merge socklist into another socket list. More... | |
void | log_crypto_err (const char *str) |
Log libcrypto error with descriptive string. More... | |
int | listen_sslctx_setup (void *ctxt) |
Set SSL_OP_NOxxx options on SSL context to disable bad crypto. More... | |
void | listen_sslctx_setup_2 (void *ctxt) |
Further setup of listening SSL context, after keys loaded. More... | |
void * | listen_sslctx_create (char *key, char *pem, char *verifypem) |
create SSL listen context More... | |
void * | connect_sslctx_create (char *key, char *pem, char *verifypem) |
create SSL connect context More... | |
void * | incoming_ssl_fd (void *sslctx, int fd) |
accept a new fd and wrap it in a BIO in SSL More... | |
void * | outgoing_ssl_fd (void *sslctx, int fd) |
connect a new fd and wrap it in a BIO in SSL More... | |
int | ub_openssl_lock_init (void) |
Initialize openssl locking for thread safety. More... | |
void | ub_openssl_lock_delete (void) |
De-init the allocated openssl locks. | |
Variables | |
uint16_t | EDNS_ADVERTISED_SIZE = 4096 |
default value for EDNS ADVERTISED size More... | |
int | MINIMAL_RESPONSES = 0 |
minimal responses when positive answer: default is no More... | |
int | RRSET_ROUNDROBIN = 0 |
rrset order roundrobin: default is no More... | |
Implementation of net_help.h.
int str_is_ip6 | ( | const char * | str | ) |
See if string is ip4 or ip6.
str | IP specification. |
Referenced by calc_num46(), ipstrtoaddr(), listening_ports_open(), net_test(), netblockstrtoaddr(), outside_network_create(), and ub_ctx_hosts().
int fd_set_nonblock | ( | int | s | ) |
Set fd nonblocking.
s | file descriptor. |
References log_err().
Referenced by comm_point_perform_accept(), comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), create_local_accept_sock(), create_tcp_accept_sock(), create_udp_sock(), outnet_tcp_take_into_use(), tube_create(), tube_read_msg(), and tube_write_msg().
int fd_set_block | ( | int | s | ) |
Set fd (back to) blocking.
s | file descriptor. |
References log_err(), and verbosity.
Referenced by comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), handle_req(), tube_read_msg(), and tube_write_msg().
int is_pow2 | ( | size_t | num | ) |
See if number is a power of 2.
num | the value. |
Referenced by net_test().
void* memdup | ( | void * | data, |
size_t | len | ||
) |
Allocate memory and copy over contents.
data | what to copy over. |
len | length of data. |
Referenced by add_bg_result(), anchor_new_ta(), anchor_new_ta_key(), assemble_it(), auth_zone_create(), autr_tp_create(), az_domain_create(), comm_point_send_reply(), delegpt_add_ns_mlc(), delegpt_create_mlc(), delegpt_set_name_mlc(), dns_cache_store(), edns_opt_copy_alloc(), fill_res(), forwards_insert_data(), infra_create_ratedata(), key_entry_copy(), lz_enter_zone_tag(), lz_setup_implicit(), match_all(), match_answer(), match_question(), move_into_cache(), neg_setup_data_node(), neg_setup_zone_node(), new_entry(), packed_rrset_copy_alloc(), pending_udp_query(), qlist_add_line(), repinfo_copy_rrsets(), serviced_create(), setup_if(), tcp_relay_read(), ub_packed_rrset_heap_key(), and worker_create().
void log_addr | ( | enum verbosity_value | v, |
const char * | str, | ||
struct sockaddr_storage * | addr, | ||
socklen_t | addrlen | ||
) |
Prints the sockaddr in readable format with log_info.
Debug helper.
v | at what verbosity level to print this. |
str | descriptive string printed with it. |
addr | the sockaddr to print. Can be ip4 or ip6. |
addrlen | length of addr. |
References verbose(), and verbosity.
Referenced by comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), delegpt_log(), do_proxy(), iter_filter_unsuitable(), iter_merge_retry_counts(), pending_find_match(), pick_outgoing_tcp(), service_tcp_relay(), serviced_tcp_callback(), sock_list_logentry(), tcp_proxy_delete(), and worker_handle_request().
int extstrtoaddr | ( | const char * | str, |
struct sockaddr_storage * | addr, | ||
socklen_t * | addrlen | ||
) |
Convert address string, with "@port" appendix, to sockaddr.
Uses DNS port by default.
str | the string |
addr | where to store sockaddr. |
addrlen | length of stored sockaddr is returned. |
References ipstrtoaddr(), and MAX_ADDR_STRLEN.
Referenced by ah(), contact_server(), interfacechecks(), open_svr(), parse_delegpt(), read_fwds_addr(), read_stubs_addr(), replay_moment_read(), replay_range_read(), service(), ub_ctx_set_fwd(), ub_ctx_set_stub(), and warn_hosts().
int ipstrtoaddr | ( | const char * | ip, |
int | port, | ||
struct sockaddr_storage * | addr, | ||
socklen_t * | addrlen | ||
) |
Convert ip address string and port to sockaddr.
ip | ip4 or ip6 address string. |
port | port number, host format. |
addr | where to store sockaddr. |
addrlen | length of stored sockaddr is returned. |
References MAX_ADDR_STRLEN, and str_is_ip6().
Referenced by cfg_ptr_reverse(), do_flush_infra(), extstrtoaddr(), infra_test(), net_test(), netblockstrtoaddr(), and setup_if().
int netblockstrtoaddr | ( | const char * | ip, |
int | port, | ||
struct sockaddr_storage * | addr, | ||
socklen_t * | addrlen, | ||
int * | net | ||
) |
Convert ip netblock (ip/netsize) string and port to sockaddr.
SLOW, does a malloc internally to avoid writing over 'ip' string.
ip | ip4 or ip6 address string. |
port | port number, host format. |
addr | where to store sockaddr. |
addrlen | length of stored sockaddr is returned. |
net | netblock size is returned. |
References addr_mask(), ipstrtoaddr(), log_err(), and str_is_ip6().
Referenced by acl_find_or_create(), acl_list_str_cfg(), aclchecks(), dns64_apply_cfg(), donotq_str_cfg(), lz_enter_override(), read_addrs(), respip_find_or_create(), setup_if(), verify_respip_set_actions(), and verify_rrset().
void log_nametypeclass | ( | enum verbosity_value | v, |
const char * | str, | ||
uint8_t * | name, | ||
uint16_t | type, | ||
uint16_t | dclass | ||
) |
Print string with neat domain name, type and class.
v | at what verbosity level to print this. |
str | string of message. |
name | domain name uncompressed wireformat. |
type | host format RR type. |
dclass | host format RR class. |
References dname_str(), LDNS_MAX_DOMAINLEN, and verbosity.
Referenced by add_item(), anchor_store_new_rr(), anchors_assemble_rrsets(), autr_process_prime(), autr_tp_remove(), cache_fill_missing(), check_zone_invariants(), generate_a_aaaa_check(), generate_ns_check(), generate_parentside_target_query(), generate_target_query(), get_random_data(), iter_mark_cycle_targets(), iter_mark_pside_cycle_targets(), iter_scrub_ds(), local_zone_out(), local_zones_print(), log_query_info(), log_rrset_key(), lz_inform_print(), lz_setup_implicit(), mesh_make_new_space(), neg_insert_data(), nsec3_do_prove_nameerror(), nsec3_prove_closest_encloser(), nsec3_prove_nameerror(), primeResponseToKE(), processCollectClass(), processValidate(), remove_item(), remove_rrset(), respip_inform_print(), scrub_message(), val_check_nonsecure(), val_dlv_init(), val_neg_addreferral(), val_neg_addreply(), val_neg_dlvlookup(), val_verify_rrset(), validate_any_response(), validate_cname_response(), validate_msg_signatures(), validate_positive_response(), and verifytest_rrset().
void log_name_addr | ( | enum verbosity_value | v, |
const char * | str, | ||
uint8_t * | zone, | ||
struct sockaddr_storage * | addr, | ||
socklen_t | addrlen | ||
) |
Prints zone name and sockaddr in readable format with log_info.
Debug.
v | at what verbosity level to print this. |
str | descriptive string printed with it. |
zone | DNS domain name, uncompressed wireformat. |
addr | the sockaddr to print. Can be ip4 or ip6. |
addrlen | length of addr. |
References dname_str(), LDNS_MAX_DOMAINLEN, verbose(), and verbosity.
Referenced by remove_rr(), and serviced_udp_callback().
void log_err_addr | ( | const char * | str, |
const char * | err, | ||
struct sockaddr_storage * | addr, | ||
socklen_t | addrlen | ||
) |
Log errno and addr.
str | descriptive string printed with it. |
err | errno string to print, i.e. strerror(errno). |
addr | the sockaddr to print. Can be ip4 or ip6. |
addrlen | length of addr. |
References log_err(), and verbosity.
Referenced by comm_point_perform_accept(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), create_tcp_accept_sock(), create_udp_sock(), and outnet_tcp_take_into_use().
int sockaddr_cmp | ( | struct sockaddr_storage * | addr1, |
socklen_t | len1, | ||
struct sockaddr_storage * | addr2, | ||
socklen_t | len2 | ||
) |
Compare two sockaddrs.
Imposes an ordering on the addresses. Compares address and port.
addr1 | address 1. |
len1 | lengths of addr1. |
addr2 | address 2. |
len2 | lengths of addr2. |
References INET6_SIZE, INET_SIZE, and log_assert.
Referenced by find_create_proxy(), infra_compfunc(), infra_del_host(), pending_cmp(), pending_find_match(), pending_matches_current(), and serviced_cmp().
int sockaddr_cmp_addr | ( | struct sockaddr_storage * | addr1, |
socklen_t | len1, | ||
struct sockaddr_storage * | addr2, | ||
socklen_t | len2 | ||
) |
Compare two sockaddrs.
Compares address, not the port.
addr1 | address 1. |
len1 | lengths of addr1. |
addr2 | address 2. |
len2 | lengths of addr2. |
References INET6_SIZE, INET_SIZE, and log_assert.
Referenced by addr_tree_compare(), delegpt_find_addr(), net_test(), and sock_list_find().
int addr_is_ip6 | ( | struct sockaddr_storage * | addr, |
socklen_t | len | ||
) |
Checkout address family.
addr | the sockaddr to examine. |
len | the length of addr. |
Referenced by addr_in_common(), addr_is_ip4mapped(), addr_mask(), addr_to_str(), addr_tree_lookup(), cfg_ptr_reverse(), delegpt_add_target(), delegpt_add_target_mlc(), dns64_apply_cfg(), hash_addr(), iter_filter_unsuitable(), open_svr(), outnet_tcp_take_into_use(), pick_outgoing_tcp(), proxy_list_clear(), randomize_and_send_udp(), serviced_encode(), udp_sockport(), and warn_hosts().
void addr_mask | ( | struct sockaddr_storage * | addr, |
socklen_t | len, | ||
int | net | ||
) |
Make sure the sockaddr ends in zeroes.
For tree insertion and subsequent comparison.
addr | the ip4 or ip6 addr. |
len | length of addr. |
net | number of bits to leave untouched, the rest of the netblock address is zeroed. |
References addr_is_ip6().
Referenced by net_test(), and netblockstrtoaddr().
int addr_in_common | ( | struct sockaddr_storage * | addr1, |
int | net1, | ||
struct sockaddr_storage * | addr2, | ||
int | net2, | ||
socklen_t | addrlen | ||
) |
See how many bits are shared, equal, between two addrs.
addr1 | first addr. |
net1 | netblock size of first addr. |
addr2 | second addr. |
net2 | netblock size of second addr. |
addrlen | length of first addr and of second addr. They must be of the same length (i.e. same type IP4, IP6). |
References addr_is_ip6(), log_assert, and match().
Referenced by addr_tree_init_parents(), addr_tree_lookup(), handle_ipv6_ptr(), and net_test().
void addr_to_str | ( | struct sockaddr_storage * | addr, |
socklen_t | addrlen, | ||
char * | buf, | ||
size_t | len | ||
) |
Put address into string, works for IPv4 and IPv6.
addr | address |
addrlen | length of address |
buf | result string stored here |
len | length of buf. On failure a string with "error" is stored inside. |
References addr_is_ip6().
Referenced by dump_infra_host(), errinf_origin(), get_mesh_status(), infra_ip_ratelimit_inc(), log_reply_info(), lz_inform_print(), print_dp_details(), respip_inform_print(), and ssl_print_name_dp().
int addr_is_ip4mapped | ( | struct sockaddr_storage * | addr, |
socklen_t | addrlen | ||
) |
See if sockaddr is an ipv6 mapped ipv4 address, "::ffff:0.0.0.0".
addr | address |
addrlen | length of address |
References addr_is_ip6().
Referenced by net_test(), and udp_send_errno_needs_log().
int addr_is_broadcast | ( | struct sockaddr_storage * | addr, |
socklen_t | addrlen | ||
) |
See if sockaddr is 255.255.255.255.
addr | address |
addrlen | length of address |
Referenced by udp_send_errno_needs_log().
int addr_is_any | ( | struct sockaddr_storage * | addr, |
socklen_t | addrlen | ||
) |
See if sockaddr is 0.0.0.0 or ::0.
addr | address |
addrlen | length of address |
Referenced by net_test(), and pick_outgoing_tcp().
void sock_list_insert | ( | struct sock_list ** | list, |
struct sockaddr_storage * | addr, | ||
socklen_t | len, | ||
struct regional * | region | ||
) |
Insert new socket list item.
If fails logs error.
list | pointer to pointer to first item. |
addr | address or NULL if 'cache'. |
len | length of addr, or 0 if 'cache'. |
region | where to allocate |
References sock_list::addr, sock_list::len, log_assert, log_err(), sock_list::next, and regional_alloc().
Referenced by generate_parentside_target_query(), processInitRequest3(), sock_list_merge(), and val_blacklist().
Append one list to another.
Must both be from same qstate(regional).
list | pointer to result list that is modified. |
add | item(s) to add. They are prepended to list. |
References sock_list::next.
Referenced by val_blacklist().
int sock_list_find | ( | struct sock_list * | list, |
struct sockaddr_storage * | addr, | ||
socklen_t | len | ||
) |
Find addr in list.
list | to search in |
addr | address to look for. |
len | length. Can be 0, look for 'cache entry'. |
References sock_list::addr, sock_list::len, sock_list::next, and sockaddr_cmp_addr().
Referenced by iter_fill_rtt(), and sock_list_merge().
Merge socklist into another socket list.
Allocates the new entries freshly and copies them over, so also performs a region switchover. Allocation failures are logged.
list | the destination list (checked for duplicates) |
region | where to allocate |
add | the list of entries to add. |
References sock_list::addr, sock_list::len, sock_list::next, sock_list_find(), and sock_list_insert().
Referenced by val_blacklist().
void log_crypto_err | ( | const char * | str | ) |
Log libcrypto error with descriptive string.
Calls log_err().
str | what failed. |
References log_err().
Referenced by connect_sslctx_create(), daemon_remote_create(), handle_req(), incoming_ssl_fd(), listen_sslctx_create(), listen_sslctx_setup(), listen_sslctx_setup_2(), outgoing_ssl_fd(), recv_one(), ssl_handle_read(), ssl_handle_write(), and write_q().
int listen_sslctx_setup | ( | void * | ctxt | ) |
Set SSL_OP_NOxxx options on SSL context to disable bad crypto.
ctxt | SSL_CTX* |
References log_crypto_err().
Referenced by daemon_remote_create(), and listen_sslctx_create().
void listen_sslctx_setup_2 | ( | void * | ctxt | ) |
Further setup of listening SSL context, after keys loaded.
ctxt | SSL_CTX* |
References log_crypto_err().
Referenced by listen_sslctx_create().
void* listen_sslctx_create | ( | char * | key, |
char * | pem, | ||
char * | verifypem | ||
) |
create SSL listen context
key | private key file. |
pem | public key cert. |
verifypem | if nonNULL, verifylocation file. return SSL_CTX* or NULL on failure (logged). |
References listen_sslctx_setup(), listen_sslctx_setup_2(), log_crypto_err(), and log_err().
void* connect_sslctx_create | ( | char * | key, |
char * | pem, | ||
char * | verifypem | ||
) |
create SSL connect context
key | if nonNULL (also pem nonNULL), the client private key. |
pem | client public key (or NULL if key is NULL). |
verifypem | if nonNULL used for verifylocation file. |
References log_crypto_err(), and log_err().
Referenced by libworker_setup().
void* incoming_ssl_fd | ( | void * | sslctx, |
int | fd | ||
) |
accept a new fd and wrap it in a BIO in SSL
sslctx | the SSL_CTX to use (from listen_sslctx_create()). |
fd | from accept, nonblocking. |
References log_crypto_err().
Referenced by comm_point_tcp_accept_callback().
void* outgoing_ssl_fd | ( | void * | sslctx, |
int | fd | ||
) |
connect a new fd and wrap it in a BIO in SSL
sslctx | the SSL_CTX to use (from connect_sslctx_create()) |
fd | from connect. |
References log_crypto_err().
Referenced by outnet_tcp_take_into_use().
int ub_openssl_lock_init | ( | void | ) |
Initialize openssl locking for thread safety.
uint16_t EDNS_ADVERTISED_SIZE = 4096 |
default value for EDNS ADVERTISED size
Advertised size of EDNS capabilities.
Referenced by answer_from_cache(), answer_norec_from_cache(), config_apply(), error_encode(), local_encode(), local_error_encode(), and serviced_encode().
int MINIMAL_RESPONSES = 0 |
minimal responses when positive answer: default is no
minimal responses when positive answer
Referenced by config_apply().
int RRSET_ROUNDROBIN = 0 |