unbound 0.1
|
This file has functions to get queries from clients. More...
#include "config.h"
#include <sys/types.h>
#include <sys/time.h>
#include "services/listen_dnsport.h"
#include "services/outside_network.h"
#include "util/netevent.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/net_help.h"
#include <netdb.h>
#include <fcntl.h>
Defines | |
#define | TCP_BACKLOG 5 |
number of queued TCP connections for listen() | |
Functions | |
static void | verbose_print_addr (struct addrinfo *addr) |
Debug print of the getaddrinfo returned address. | |
int | create_udp_sock (int family, int socktype, struct sockaddr *addr, socklen_t addrlen, int v6only, int *inuse, int *noproto, int rcv, int snd) |
Create and bind nonblocking UDP socket. | |
int | create_tcp_accept_sock (struct addrinfo *addr, int v6only, int *noproto) |
Create and bind TCP listening socket. | |
static int | make_sock (int stype, const char *ifname, const char *port, struct addrinfo *hints, int v6only, int *noip6, size_t rcv, size_t snd) |
Create socket from getaddrinfo results. | |
static int | make_sock_port (int stype, const char *ifname, const char *port, struct addrinfo *hints, int v6only, int *noip6, size_t rcv, size_t snd) |
make socket and first see if ifname contains port override info | |
static int | port_insert (struct listen_port **list, int s, enum listen_type ftype) |
Add port to open ports list. | |
static int | set_recvpktinfo (int s, int family) |
set fd to receive source address packet info | |
static int | ports_create_if (const char *ifname, int do_auto, int do_udp, int do_tcp, struct addrinfo *hints, const char *port, struct listen_port **list, size_t rcv, size_t snd) |
Helper for ports_open. | |
static int | listen_cp_insert (struct comm_point *c, struct listen_dnsport *front) |
Add items to commpoint list in front. | |
struct listen_dnsport * | listen_create (struct comm_base *base, struct listen_port *ports, size_t bufsize, int tcp_accept_count, comm_point_callback_t *cb, void *cb_arg) |
Create commpoints with for this thread for the shared ports. | |
void | listen_list_delete (struct listen_list *list) |
delete listen_list of commpoints. | |
void | listen_delete (struct listen_dnsport *front) |
delete the listening structure | |
struct listen_port * | listening_ports_open (struct config_file *cfg) |
Create shared listening ports Getaddrinfo, create socket, bind and listen to zero or more interfaces for IP4 and/or IP6, for UDP and/or TCP. | |
void | listening_ports_free (struct listen_port *list) |
Close and delete the (list of) listening ports. | |
size_t | listen_get_mem (struct listen_dnsport *listen) |
get memory size used by the listening structs |
This file has functions to get queries from clients.
static void verbose_print_addr | ( | struct addrinfo * | addr | ) | [static] |
Debug print of the getaddrinfo returned address.
addr,: | the address returned. |
References VERB_ALGO, verbose(), and verbosity.
Referenced by create_tcp_accept_sock(), and make_sock().
int create_udp_sock | ( | int | family, |
int | socktype, | ||
struct sockaddr * | addr, | ||
socklen_t | addrlen, | ||
int | v6only, | ||
int * | inuse, | ||
int * | noproto, | ||
int | rcv, | ||
int | snd | ||
) |
Create and bind nonblocking UDP socket.
family,: | for socket call. |
socktype,: | for socket call. |
addr,: | for bind call. |
addrlen,: | for bind call. |
v6only,: | if enabled, IP6 sockets get IP6ONLY option set. if enabled with value 2 IP6ONLY option is disabled. |
inuse,: | on error, this is set true if the port was in use. |
noproto,: | on error, this is set true if cause is that the IPv6 proto (family) is not available. |
rcv,: | set size on rcvbuf with socket option, if 0 it is not set. |
snd,: | set size on sndbuf with socket option, if 0 it is not set. |
References fd_set_nonblock(), log_addr(), log_err(), and log_warn().
Referenced by make_sock(), and udp_sockport().
int create_tcp_accept_sock | ( | struct addrinfo * | addr, |
int | v6only, | ||
int * | noproto | ||
) |
Create and bind TCP listening socket.
addr,: | address info ready to make socket. |
v6only,: | enable ip6 only flag on ip6 sockets. |
noproto,: | if error caused by lack of protocol support. |
References fd_set_nonblock(), log_addr(), log_err(), TCP_BACKLOG, and verbose_print_addr().
Referenced by add_open(), and make_sock().
static int port_insert | ( | struct listen_port ** | list, |
int | s, | ||
enum listen_type | ftype | ||
) | [static] |
Add port to open ports list.
list,: | list head. changed. |
s,: | fd. |
ftype,: | if fd is UDP. |
References listen_port::fd, listen_port::ftype, and listen_port::next.
Referenced by ports_create_if().
static int ports_create_if | ( | const char * | ifname, |
int | do_auto, | ||
int | do_udp, | ||
int | do_tcp, | ||
struct addrinfo * | hints, | ||
const char * | port, | ||
struct listen_port ** | list, | ||
size_t | rcv, | ||
size_t | snd | ||
) | [static] |
Helper for ports_open.
Creates one interface (or NULL for default).
ifname,: | The interface ip address. |
do_auto,: | use automatic interface detection. If enabled, then ifname must be the wildcard name. |
do_udp,: | if udp should be used. |
do_tcp,: | if udp should be used. |
hints,: | for getaddrinfo. family and flags have to be set by caller. |
port,: | Port number to use (as string). |
list,: | list of open ports, appended to, changed to point to list head. |
rcv,: | receive buffer size for UDP |
snd,: | send buffer size for UDP |
References listen_type_tcp, listen_type_udp, listen_type_udpancil, log_warn(), make_sock_port(), port_insert(), and set_recvpktinfo().
Referenced by listening_ports_open().
static int listen_cp_insert | ( | struct comm_point * | c, |
struct listen_dnsport * | front | ||
) | [static] |
Add items to commpoint list in front.
c,: | commpoint to add. |
front,: | listen struct. |
References listen_list::com, listen_dnsport::cps, and listen_list::next.
Referenced by listen_create().
struct listen_dnsport* listen_create | ( | struct comm_base * | base, |
struct listen_port * | ports, | ||
size_t | bufsize, | ||
int | tcp_accept_count, | ||
comm_point_callback_t * | cb, | ||
void * | cb_arg | ||
) | [read] |
Create commpoints with for this thread for the shared ports.
base,: | the comm_base that provides event functionality. for default all ifs. |
ports,: | the list of shared ports. |
bufsize,: | size of datagram buffer. |
tcp_accept_count,: | max number of simultaneous TCP connections from clients. |
cb,: | callback function when a request arrives. It is passed the packet and user argument. Return true to send a reply. |
cb_arg,: | user data argument for callback function. |
Referenced by worker_init().
void listen_list_delete | ( | struct listen_list * | list | ) |
delete listen_list of commpoints.
Calls commpointdelete() on items. This may close the fds or not depending on flags.
list,: | to delete. |
References listen_list::com, comm_point_delete(), and listen_list::next.
Referenced by daemon_remote_clear(), and listen_delete().
void listen_delete | ( | struct listen_dnsport * | listen | ) |
delete the listening structure
listen,: | listening structure. |
Referenced by listen_create(), and worker_delete().
struct listen_port* listening_ports_open | ( | struct config_file * | cfg | ) | [read] |
Create shared listening ports Getaddrinfo, create socket, bind and listen to zero or more interfaces for IP4 and/or IP6, for UDP and/or TCP.
On the given port number. It creates the sockets.
cfg,: | settings on what ports to open. |
Referenced by daemon_open_shared_ports().
size_t listen_get_mem | ( | struct listen_dnsport * | listen | ) |
get memory size used by the listening structs
listen,: | listening structure. |
Referenced by worker_mem_report().