|
Electroneum
|
#include "util/log.h"

Go to the source code of this file.
Macros | |
| #define | BIT_CD 0x0010 |
| #define | BIT_AD 0x0020 |
| #define | BIT_Z 0x0040 |
| #define | BIT_RA 0x0080 |
| #define | BIT_RD 0x0100 |
| #define | BIT_TC 0x0200 |
| #define | BIT_AA 0x0400 |
| #define | BIT_QR 0x8000 |
| #define | FLAGS_GET_RCODE(f) ((f) & 0xf) |
| #define | FLAGS_SET_RCODE(f, r) (f = (((f) & 0xfff0) | (r))) |
| #define | UDP_AUTH_QUERY_TIMEOUT 3000 |
| #define | TCP_AUTH_QUERY_TIMEOUT 3000 |
| #define | EDNS_ADVERTISED_VERSION 0 |
| #define | EDNS_DO 0x8000 /* Dnssec Ok */ |
| #define | INET_SIZE 4 |
| #define | INET6_SIZE 16 |
| #define | DNSKEY_BIT_ZSK 0x0100 |
| #define | DNSKEY_BIT_SEP 0x0001 |
Functions | |
| int | str_is_ip6 (const char *str) |
| int | fd_set_nonblock (int s) |
| int | fd_set_block (int s) |
| int | is_pow2 (size_t num) |
| void * | memdup (void *data, size_t len) |
| void | log_addr (enum verbosity_value v, const char *str, struct sockaddr_storage *addr, socklen_t addrlen) |
| void | log_name_addr (enum verbosity_value v, const char *str, uint8_t *zone, struct sockaddr_storage *addr, socklen_t addrlen) |
| void | log_err_addr (const char *str, const char *err, struct sockaddr_storage *addr, socklen_t addrlen) |
| int | extstrtoaddr (const char *str, struct sockaddr_storage *addr, socklen_t *addrlen) |
| int | ipstrtoaddr (const char *ip, int port, struct sockaddr_storage *addr, socklen_t *addrlen) |
| int | netblockstrtoaddr (const char *ip, int port, struct sockaddr_storage *addr, socklen_t *addrlen, int *net) |
| int | authextstrtoaddr (char *str, struct sockaddr_storage *addr, socklen_t *addrlen, char **auth_name) |
| void | sockaddr_store_port (struct sockaddr_storage *addr, socklen_t addrlen, int port) |
| void | log_nametypeclass (enum verbosity_value v, const char *str, uint8_t *name, uint16_t type, uint16_t dclass) |
| int | sockaddr_cmp (struct sockaddr_storage *addr1, socklen_t len1, struct sockaddr_storage *addr2, socklen_t len2) |
| int | sockaddr_cmp_addr (struct sockaddr_storage *addr1, socklen_t len1, struct sockaddr_storage *addr2, socklen_t len2) |
| int | addr_is_ip6 (struct sockaddr_storage *addr, socklen_t len) |
| void | addr_mask (struct sockaddr_storage *addr, socklen_t len, int net) |
| int | addr_in_common (struct sockaddr_storage *addr1, int net1, struct sockaddr_storage *addr2, int net2, socklen_t addrlen) |
| void | addr_to_str (struct sockaddr_storage *addr, socklen_t addrlen, char *buf, size_t len) |
| int | addr_is_ip4mapped (struct sockaddr_storage *addr, socklen_t addrlen) |
| int | addr_is_broadcast (struct sockaddr_storage *addr, socklen_t addrlen) |
| int | addr_is_any (struct sockaddr_storage *addr, socklen_t addrlen) |
| void | sock_list_insert (struct sock_list **list, struct sockaddr_storage *addr, socklen_t len, struct regional *region) |
| void | sock_list_prepend (struct sock_list **list, struct sock_list *add) |
| int | sock_list_find (struct sock_list *list, struct sockaddr_storage *addr, socklen_t len) |
| void | sock_list_merge (struct sock_list **list, struct regional *region, struct sock_list *add) |
| void | log_crypto_err (const char *str) |
| int | listen_sslctx_setup (void *ctxt) |
| void | listen_sslctx_setup_2 (void *ctxt) |
| void * | listen_sslctx_create (char *key, char *pem, char *verifypem) |
| void * | connect_sslctx_create (char *key, char *pem, char *verifypem, int wincert) |
| void * | incoming_ssl_fd (void *sslctx, int fd) |
| void * | outgoing_ssl_fd (void *sslctx, int fd) |
| int | ub_openssl_lock_init (void) |
| void | ub_openssl_lock_delete (void) |
Variables | |
| uint16_t | EDNS_ADVERTISED_SIZE |
| int | MINIMAL_RESPONSES |
| int | RRSET_ROUNDROBIN |
This file contains functions to perform network related tasks.
Definition in file net_help.h.
| #define BIT_AA 0x0400 |
AA flag
Definition at line 68 of file net_help.h.
| #define BIT_AD 0x0020 |
AD flag
Definition at line 58 of file net_help.h.
| #define BIT_CD 0x0010 |
DNS constants for uint16_t style flag manipulation. host byteorder. 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +–+–+–+–+–+–+–+–+–+–+–+–+–+–+–+–+ |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE | +–+–+–+–+–+–+–+–+–+–+–+–+–+–+–+–+CD flag
Definition at line 56 of file net_help.h.
| #define BIT_QR 0x8000 |
QR flag
Definition at line 70 of file net_help.h.
| #define BIT_RA 0x0080 |
RA flag
Definition at line 62 of file net_help.h.
| #define BIT_RD 0x0100 |
RD flag
Definition at line 64 of file net_help.h.
| #define BIT_TC 0x0200 |
TC flag
Definition at line 66 of file net_help.h.
| #define BIT_Z 0x0040 |
Z flag
Definition at line 60 of file net_help.h.
| #define DNSKEY_BIT_SEP 0x0001 |
DNSKEY secure entry point, KSK flag
Definition at line 94 of file net_help.h.
| #define DNSKEY_BIT_ZSK 0x0100 |
DNSKEY zone sign key flag
Definition at line 92 of file net_help.h.
| #define EDNS_ADVERTISED_VERSION 0 |
Advertised version of EDNS capabilities
Definition at line 81 of file net_help.h.
| #define EDNS_DO 0x8000 /* Dnssec Ok */ |
bits for EDNS bitfield
Definition at line 85 of file net_help.h.
| #define FLAGS_GET_RCODE | ( | f | ) | ((f) & 0xf) |
get RCODE bits from uint16 flags
Definition at line 72 of file net_help.h.
| #define FLAGS_SET_RCODE | ( | f, | |
| r | |||
| ) | (f = (((f) & 0xfff0) | (r))) |
set RCODE bits in uint16 flags
Definition at line 74 of file net_help.h.
| #define INET6_SIZE 16 |
byte size of ip6 address
Definition at line 89 of file net_help.h.
| #define INET_SIZE 4 |
byte size of ip4 address
Definition at line 87 of file net_help.h.
| #define TCP_AUTH_QUERY_TIMEOUT 3000 |
timeout in milliseconds for TCP queries to auth servers.
Definition at line 79 of file net_help.h.
| #define UDP_AUTH_QUERY_TIMEOUT 3000 |
timeout in milliseconds for UDP queries to auth servers.
Definition at line 77 of file net_help.h.
| 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). |
| 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 |
| 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 |
| 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 |
| int addr_is_ip6 | ( | struct sockaddr_storage * | addr, |
| socklen_t | len | ||
| ) |
Checkout address family.
| addr | the sockaddr to examine. |
| len | the length of addr. |
| 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. |
| 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. |
| int authextstrtoaddr | ( | char * | str, |
| struct sockaddr_storage * | addr, | ||
| socklen_t * | addrlen, | ||
| char ** | auth_name | ||
| ) |
Convert address string, with "@port" appendix, to sockaddr. It can also have an "#tls-auth-name" appendix (after the port). The returned tls-auth-name string is a pointer into the input string. Uses DNS port by default.
| str | the string |
| addr | where to store sockaddr. |
| addrlen | length of stored sockaddr is returned. |
| auth_name | returned pointer to tls_auth_name, or NULL if none. |
| void* connect_sslctx_create | ( | char * | key, |
| char * | pem, | ||
| char * | verifypem, | ||
| int | wincert | ||
| ) |
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. |
| wincert | add system certificate store to ctx (add to verifypem ca certs). |
| 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. |
| int fd_set_block | ( | int | s | ) |
Set fd (back to) blocking.
| s | file descriptor. |
| int fd_set_nonblock | ( | int | s | ) |
Set fd nonblocking.
| s | file descriptor. |
| 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. |
| 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. |
| int is_pow2 | ( | size_t | num | ) |
See if number is a power of 2.
| num | the value. |
| 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). |
| int listen_sslctx_setup | ( | void * | ctxt | ) |
Set SSL_OP_NOxxx options on SSL context to disable bad crypto
| ctxt | SSL_CTX* |
| void listen_sslctx_setup_2 | ( | void * | ctxt | ) |
Further setup of listening SSL context, after keys loaded.
| ctxt | SSL_CTX* |
| 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. |
| void log_crypto_err | ( | const char * | str | ) |
Log libcrypto error with descriptive string. Calls log_err().
| str | what failed. |
| 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. |
| 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. |
| 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. |
| void* memdup | ( | void * | data, |
| size_t | len | ||
| ) |
Allocate memory and copy over contents.
| data | what to copy over. |
| len | length of data. |
| 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. performs a copy 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. |
| 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. |
| 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'. |
| 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 |
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. |
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. |
| 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. |
| 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. |
| void sockaddr_store_port | ( | struct sockaddr_storage * | addr, |
| socklen_t | addrlen, | ||
| int | port | ||
| ) |
Store port number into sockaddr structure
| addr | sockaddr structure, ip4 or ip6. |
| addrlen | length of addr. |
| port | port number to put into the addr. |
| int str_is_ip6 | ( | const char * | str | ) |
See if string is ip4 or ip6.
| str | IP specification. |
| void ub_openssl_lock_delete | ( | void | ) |
De-init the allocated openssl locks
| int ub_openssl_lock_init | ( | void | ) |
Initialize openssl locking for thread safety
| uint16_t EDNS_ADVERTISED_SIZE |
Advertised size of EDNS capabilities
| int MINIMAL_RESPONSES |
minimal responses when positive answer
| int RRSET_ROUNDROBIN |
rrset order roundrobin