Electroneum
listen_dnsport.h File Reference
#include "util/netevent.h"
Include dependency graph for listen_dnsport.h:

Go to the source code of this file.

Classes

struct  listen_dnsport
 
struct  listen_list
 
struct  listen_port
 

Enumerations

enum  listen_type {
  listen_type_udp, listen_type_tcp, listen_type_udpancil, listen_type_ssl,
  listen_type_udp_dnscrypt, listen_type_tcp_dnscrypt, listen_type_udpancil_dnscrypt
}
 

Functions

struct listen_portlistening_ports_open (struct config_file *cfg, int *reuseport)
 
void listening_ports_free (struct listen_port *list)
 
struct listen_dnsportlisten_create (struct comm_base *base, struct listen_port *ports, size_t bufsize, int tcp_accept_count, void *sslctx, struct dt_env *dtenv, comm_point_callback_type *cb, void *cb_arg)
 
void listen_delete (struct listen_dnsport *listen)
 
void listen_list_delete (struct listen_list *list)
 
size_t listen_get_mem (struct listen_dnsport *listen)
 
void listen_stop_accept (struct listen_dnsport *listen)
 
void listen_start_accept (struct listen_dnsport *listen)
 
int create_udp_sock (int family, int socktype, struct sockaddr *addr, socklen_t addrlen, int v6only, int *inuse, int *noproto, int rcv, int snd, int listen, int *reuseport, int transparent, int freebind, int use_systemd)
 
int create_tcp_accept_sock (struct addrinfo *addr, int v6only, int *noproto, int *reuseport, int transparent, int mss, int freebind, int use_systemd)
 
int create_local_accept_sock (const char *path, int *noproto, int use_systemd)
 

Detailed Description

This file has functions to get queries from clients.

Definition in file listen_dnsport.h.

Enumeration Type Documentation

◆ listen_type

type of ports

Enumerator
listen_type_udp 

udp type

listen_type_tcp 

tcp type

listen_type_udpancil 

udp ipv6 (v4mapped) for use with ancillary data

listen_type_ssl 

ssl over tcp type

listen_type_udp_dnscrypt 

udp type + dnscrypt

listen_type_tcp_dnscrypt 

tcp type + dnscrypt

listen_type_udpancil_dnscrypt 

udp ipv6 (v4mapped) for use with ancillary data + dnscrypt

Definition at line 82 of file listen_dnsport.h.

Function Documentation

◆ create_local_accept_sock()

int create_local_accept_sock ( const char *  path,
int *  noproto,
int  use_systemd 
)

Create and bind local listening socket

Parameters
pathpath to the socket.
noprotoon error, this is set true if cause is that local sockets are not supported.
use_systemdif true, fetch sockets from systemd.
Returns
: the socket. -1 on error.

◆ create_tcp_accept_sock()

int create_tcp_accept_sock ( struct addrinfo addr,
int  v6only,
int *  noproto,
int *  reuseport,
int  transparent,
int  mss,
int  freebind,
int  use_systemd 
)

Create and bind TCP listening socket

Parameters
addraddress info ready to make socket.
v6onlyenable ip6 only flag on ip6 sockets.
noprotoif error caused by lack of protocol support.
reuseportif nonNULL and true, try to set SO_REUSEPORT on listening UDP port. Set to false on return if it failed to do so.
transparentset IP_TRANSPARENT socket option.
mssmaximum segment size of the socket. if zero, leaves the default.
freebindset IP_FREEBIND socket option.
use_systemdif true, fetch sockets from systemd.
Returns
: the socket. -1 on error.

◆ create_udp_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,
int  listen,
int *  reuseport,
int  transparent,
int  freebind,
int  use_systemd 
)

Create and bind nonblocking UDP socket

Parameters
familyfor socket call.
socktypefor socket call.
addrfor bind call.
addrlenfor bind call.
v6onlyif enabled, IP6 sockets get IP6ONLY option set. if enabled with value 2 IP6ONLY option is disabled.
inuseon error, this is set true if the port was in use.
noprotoon error, this is set true if cause is that the IPv6 proto (family) is not available.
rcvset size on rcvbuf with socket option, if 0 it is not set.
sndset size on sndbuf with socket option, if 0 it is not set.
listenif true, this is a listening UDP port, eg port 53, and set SO_REUSEADDR on it.
reuseportif nonNULL and true, try to set SO_REUSEPORT on listening UDP port. Set to false on return if it failed to do so.
transparentset IP_TRANSPARENT socket option.
freebindset IP_FREEBIND socket option.
use_systemdif true, fetch sockets from systemd.
Returns
: the socket. -1 on error.

◆ listen_create()

struct listen_dnsport* listen_create ( struct comm_base base,
struct listen_port ports,
size_t  bufsize,
int  tcp_accept_count,
void *  sslctx,
struct dt_env *  dtenv,
comm_point_callback_type cb,
void *  cb_arg 
)

Create commpoints with for this thread for the shared ports.

Parameters
basethe comm_base that provides event functionality. for default all ifs.
portsthe list of shared ports.
bufsizesize of datagram buffer.
tcp_accept_countmax number of simultaneous TCP connections from clients.
sslctxnonNULL if ssl context.
dtenvnonNULL if dnstap enabled.
cbcallback function when a request arrives. It is passed the packet and user argument. Return true to send a reply.
cb_arguser data argument for callback function.
Returns
: the malloced listening structure, ready for use. NULL on error.

◆ listen_delete()

void listen_delete ( struct listen_dnsport listen)

delete the listening structure

Parameters
listenlistening structure.

◆ listen_get_mem()

size_t listen_get_mem ( struct listen_dnsport listen)

get memory size used by the listening structs

Parameters
listenlistening structure.
Returns
: size in bytes.

◆ listen_list_delete()

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.

Parameters
listto delete.

◆ listen_start_accept()

void listen_start_accept ( struct listen_dnsport listen)

start accept handlers for TCP (was stopped before)

Parameters
listenlistening structure.

◆ listen_stop_accept()

void listen_stop_accept ( struct listen_dnsport listen)

stop accept handlers for TCP (until enabled again)

Parameters
listenlistening structure.

◆ listening_ports_free()

void listening_ports_free ( struct listen_port list)

Close and delete the (list of) listening ports.

◆ listening_ports_open()

struct listen_port* listening_ports_open ( struct config_file cfg,
int *  reuseport 
)

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.

Parameters
cfgsettings on what ports to open.
reuseportset to true if you want reuseport, or NULL to not have it, set to false on exit if reuseport failed to apply (because of no kernel support).
Returns
: linked list of ports or NULL on error.