unbound 0.1
delayer.c File Reference

This program delays queries made. More...

#include "config.h"
#include <sys/time.h>
#include "util/net_help.h"
#include "util/config_file.h"
#include "sldns/sbuffer.h"
#include <signal.h>

Data Structures

struct  ringbuf
 The ring buffer. More...
struct  proxy
 List of proxy fds that return replies from the server to our clients. More...
struct  tcp_send_list
 An item that has to be TCP relayed. More...
struct  tcp_proxy
 List of TCP proxy fd pairs to TCP connect client to server. More...

Macros

#define TRIES_PER_SELECT   100
 number of reads per select for delayer

Functions

static void usage (char *argv[])
 usage information for delayer
static int dl_tv_smaller (struct timeval *t1, const struct timeval *t2)
 timeval compare, t1 < t2
static void dl_tv_add (struct timeval *t1, const struct timeval *t2)
 timeval add, t1 += t2
static void dl_tv_subtract (struct timeval *t1, const struct timeval *t2)
 timeval subtract, t1 -= t2
static struct ringbuf * ring_create (size_t sz)
 create new ring buffer
static void ring_delete (struct ringbuf *r)
 delete ring buffer
static void ring_add (struct ringbuf *r, sldns_buffer *pkt, struct timeval *now, struct timeval *delay, struct proxy *p)
 add entry to ringbuffer
static int ring_empty (struct ringbuf *r)
 see if the ringbuffer is empty
static struct timeval * ring_peek_time (struct ringbuf *r)
 peek at timevalue for next item in ring
static int ring_pop (struct ringbuf *r, sldns_buffer *pkt, struct timeval *tv, struct proxy **p)
 get entry from ringbuffer
static RETSIGTYPE delayer_sigh (int sig)
 signal handler for user quit
static void service_send (struct ringbuf *ring, struct timeval *now, sldns_buffer *pkt, struct sockaddr_storage *srv_addr, socklen_t srv_len)
 send out waiting packets
static void do_proxy (struct proxy *p, int retsock, sldns_buffer *pkt)
 do proxy for one readable client
static void service_proxy (fd_set *rset, int retsock, struct proxy *proxies, sldns_buffer *pkt, struct timeval *now)
 proxy return replies to clients
static struct proxy * find_create_proxy (struct sockaddr_storage *from, socklen_t from_len, fd_set *rorig, int *max, struct proxy **proxies, int serv_ip6, struct timeval *now, struct timeval *reuse_timeout)
 find or else create proxy for this remote client
static void service_recv (int s, struct ringbuf *ring, sldns_buffer *pkt, fd_set *rorig, int *max, struct proxy **proxies, struct sockaddr_storage *srv_addr, socklen_t srv_len, struct timeval *now, struct timeval *delay, struct timeval *reuse)
 recv new waiting packets
static void tcp_proxy_delete (struct tcp_proxy *p)
 delete tcp proxy
static void service_tcp_listen (int s, fd_set *rorig, int *max, struct tcp_proxy **proxies, struct sockaddr_storage *srv_addr, socklen_t srv_len, struct timeval *now, struct timeval *tcp_timeout)
 accept new TCP connections, and set them up
static int tcp_relay_read (int s, struct tcp_send_list **first, struct tcp_send_list **last, struct timeval *now, struct timeval *delay, sldns_buffer *pkt)
 relay TCP, read a part
static int tcp_relay_write (int s, struct tcp_send_list **first, struct tcp_send_list **last, struct timeval *now)
 relay TCP, write a part
static void service_tcp_relay (struct tcp_proxy **tcp_proxies, struct timeval *now, struct timeval *delay, struct timeval *tcp_timeout, sldns_buffer *pkt, fd_set *rset, fd_set *rorig, fd_set *worig)
 perform TCP relaying
static int service_findwait (struct timeval *now, struct timeval *wait, struct ringbuf *ring, struct tcp_proxy *tcplist)
 find waiting time
static void proxy_list_clear (struct proxy *p)
 clear proxy list
static void tcp_proxy_list_clear (struct tcp_proxy *p)
 clear TCP proxy list
static void service_loop (int udp_s, int listen_s, struct ringbuf *ring, struct timeval *delay, struct timeval *reuse, struct sockaddr_storage *srv_addr, socklen_t srv_len, sldns_buffer *pkt)
 delayer service loop
static void service (const char *bind_str, int bindport, const char *serv_str, size_t memsize, int delay_msec)
 delayer main service routine
int main (int argc, char **argv)
 main program for delayer

Variables

static volatile int do_quit = 0
 signal handler global info
int optind
 getopt global, in case header files fail to declare it.
char * optarg
 getopt global, in case header files fail to declare it.

Detailed Description

This program delays queries made.

It performs as a proxy to another server and delays queries to it.

Macro Definition Documentation

◆ TRIES_PER_SELECT

#define TRIES_PER_SELECT   100

number of reads per select for delayer

Referenced by do_proxy(), and service_recv().

Function Documentation

◆ usage()

void usage ( char * argv[])
static

usage information for delayer

References usage().

◆ dl_tv_smaller()

int dl_tv_smaller ( struct timeval * t1,
const struct timeval * t2 )
static

◆ dl_tv_add()

void dl_tv_add ( struct timeval * t1,
const struct timeval * t2 )
static

timeval add, t1 += t2

References dl_tv_add().

Referenced by dl_tv_add(), ring_add(), service(), service_tcp_listen(), service_tcp_relay(), and tcp_relay_read().

◆ dl_tv_subtract()

void dl_tv_subtract ( struct timeval * t1,
const struct timeval * t2 )
static

timeval subtract, t1 -= t2

References dl_tv_subtract().

Referenced by dl_tv_subtract(), find_create_proxy(), and service_findwait().

◆ ring_create()

struct ringbuf * ring_create ( size_t sz)
static

create new ring buffer

References ringbuf::buf, fatal_exit(), ringbuf::high, ringbuf::low, ring_create(), and ringbuf::size.

Referenced by ring_create(), and service().

◆ ring_delete()

void ring_delete ( struct ringbuf * r)
static

delete ring buffer

References ringbuf::buf, and ring_delete().

Referenced by ring_delete(), and service().

◆ ring_add()

void ring_add ( struct ringbuf * r,
sldns_buffer * pkt,
struct timeval * now,
struct timeval * delay,
struct proxy * p )
static

◆ ring_empty()

int ring_empty ( struct ringbuf * r)
static

see if the ringbuffer is empty

References ringbuf::high, ringbuf::low, and ring_empty().

Referenced by ring_empty(), ring_peek_time(), and service_send().

◆ ring_peek_time()

struct timeval * ring_peek_time ( struct ringbuf * r)
static

peek at timevalue for next item in ring

References ringbuf::buf, ringbuf::low, ring_empty(), and ring_peek_time().

Referenced by ring_peek_time(), service_findwait(), and service_send().

◆ ring_pop()

int ring_pop ( struct ringbuf * r,
sldns_buffer * pkt,
struct timeval * tv,
struct proxy ** p )
static

◆ delayer_sigh()

RETSIGTYPE delayer_sigh ( int sig)
static

signal handler for user quit

References delayer_sigh(), and do_quit.

Referenced by delayer_sigh(), and service().

◆ service_send()

void service_send ( struct ringbuf * ring,
struct timeval * now,
sldns_buffer * pkt,
struct sockaddr_storage * srv_addr,
socklen_t srv_len )
static

◆ do_proxy()

void do_proxy ( struct proxy * p,
int retsock,
sldns_buffer * pkt )
static

◆ service_proxy()

void service_proxy ( fd_set * rset,
int retsock,
struct proxy * proxies,
sldns_buffer * pkt,
struct timeval * now )
static

proxy return replies to clients

References do_proxy(), proxy::lastuse, proxy::next, proxy::s, and service_proxy().

Referenced by service_loop(), and service_proxy().

◆ find_create_proxy()

struct proxy * find_create_proxy ( struct sockaddr_storage * from,
socklen_t from_len,
fd_set * rorig,
int * max,
struct proxy ** proxies,
int serv_ip6,
struct timeval * now,
struct timeval * reuse_timeout )
static

◆ service_recv()

void service_recv ( int s,
struct ringbuf * ring,
sldns_buffer * pkt,
fd_set * rorig,
int * max,
struct proxy ** proxies,
struct sockaddr_storage * srv_addr,
socklen_t srv_len,
struct timeval * now,
struct timeval * delay,
struct timeval * reuse )
static

◆ tcp_proxy_delete()

◆ service_tcp_listen()

void service_tcp_listen ( int s,
fd_set * rorig,
int * max,
struct tcp_proxy ** proxies,
struct sockaddr_storage * srv_addr,
socklen_t srv_len,
struct timeval * now,
struct timeval * tcp_timeout )
static

◆ tcp_relay_read()

int tcp_relay_read ( int s,
struct tcp_send_list ** first,
struct tcp_send_list ** last,
struct timeval * now,
struct timeval * delay,
sldns_buffer * pkt )
static

◆ tcp_relay_write()

int tcp_relay_write ( int s,
struct tcp_send_list ** first,
struct tcp_send_list ** last,
struct timeval * now )
static

◆ service_tcp_relay()

void service_tcp_relay ( struct tcp_proxy ** tcp_proxies,
struct timeval * now,
struct timeval * delay,
struct timeval * tcp_timeout,
sldns_buffer * pkt,
fd_set * rset,
fd_set * rorig,
fd_set * worig )
static

◆ service_findwait()

int service_findwait ( struct timeval * now,
struct timeval * wait,
struct ringbuf * ring,
struct tcp_proxy * tcplist )
static

◆ proxy_list_clear()

◆ tcp_proxy_list_clear()

void tcp_proxy_list_clear ( struct tcp_proxy * p)
static

clear TCP proxy list

References tcp_proxy::next, tcp_proxy_delete(), and tcp_proxy_list_clear().

Referenced by service_loop(), and tcp_proxy_list_clear().

◆ service_loop()

void service_loop ( int udp_s,
int listen_s,
struct ringbuf * ring,
struct timeval * delay,
struct timeval * reuse,
struct sockaddr_storage * srv_addr,
socklen_t srv_len,
sldns_buffer * pkt )
static

◆ service()

void service ( const char * bind_str,
int bindport,
const char * serv_str,
size_t memsize,
int delay_msec )
static

◆ main()

int main ( int argc,
char ** argv )

main program for delayer

References cfg_parse_memsize(), log_ident_set(), log_init(), main, optarg, optind, service(), usage(), and verbosity.

Variable Documentation

◆ do_quit

volatile int do_quit = 0
static

signal handler global info

Referenced by delayer_sigh(), service(), and service_loop().