xref: /openbsd-src/usr.sbin/nsd/ipc.h (revision 9e506f0ad7fb5f52c816951211689a5bb54fb164)
162ac0c33Sjakob /*
262ac0c33Sjakob  * ipc.h - Interprocess communication routines. Handlers read and write.
362ac0c33Sjakob  *
4d3fecca9Ssthen  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
562ac0c33Sjakob  *
662ac0c33Sjakob  * See LICENSE for the license.
762ac0c33Sjakob  *
862ac0c33Sjakob  */
962ac0c33Sjakob 
1062ac0c33Sjakob #ifndef NSD_IPC_H
1162ac0c33Sjakob #define NSD_IPC_H
1262ac0c33Sjakob 
1362ac0c33Sjakob #include "netio.h"
1462ac0c33Sjakob struct buffer;
1562ac0c33Sjakob struct nsd;
1662ac0c33Sjakob struct nsd_child;
1762ac0c33Sjakob struct xfrd_tcp;
18d3fecca9Ssthen struct xfrd_state;
19d3fecca9Ssthen struct nsdst;
20d3fecca9Ssthen struct event;
2162ac0c33Sjakob 
2262ac0c33Sjakob /*
2362ac0c33Sjakob  * Data for the server_main IPC handler
2462ac0c33Sjakob  * Used by parent side to listen to children, and write to children.
2562ac0c33Sjakob  */
2662ac0c33Sjakob struct main_ipc_handler_data
2762ac0c33Sjakob {
2862ac0c33Sjakob 	struct nsd	*nsd;
2962ac0c33Sjakob 	struct nsd_child *child;
3062ac0c33Sjakob 	int		child_num;
3162ac0c33Sjakob 
3262ac0c33Sjakob 	/* pointer to the socket, as it may change if it is restarted */
3362ac0c33Sjakob 	int		*xfrd_sock;
3462ac0c33Sjakob 	struct buffer	*packet;
3562ac0c33Sjakob 	int		forward_mode;
3662ac0c33Sjakob 	size_t		got_bytes;
3762ac0c33Sjakob 	uint16_t	total_bytes;
3862ac0c33Sjakob 	uint32_t	acl_num;
397b21d3ddSsthen 	int32_t		acl_xfr;
4062ac0c33Sjakob };
4162ac0c33Sjakob 
4262ac0c33Sjakob /*
4362ac0c33Sjakob  * Data for ipc handler, nsd and a conn for reading ipc msgs.
4462ac0c33Sjakob  * Used by children to listen to parent.
4562ac0c33Sjakob  * Used by parent to listen to xfrd.
4662ac0c33Sjakob  */
4762ac0c33Sjakob struct ipc_handler_conn_data
4862ac0c33Sjakob {
4962ac0c33Sjakob 	struct nsd	*nsd;
5062ac0c33Sjakob 	struct xfrd_tcp	*conn;
5162ac0c33Sjakob };
5262ac0c33Sjakob 
5362ac0c33Sjakob /*
5462ac0c33Sjakob  * Routine used by server_main.
5562ac0c33Sjakob  * Handle a command received from the xfrdaemon processes.
5662ac0c33Sjakob  */
5762ac0c33Sjakob void parent_handle_xfrd_command(netio_type *netio,
5862ac0c33Sjakob 	netio_handler_type *handler, netio_event_types_type event_types);
5962ac0c33Sjakob 
6062ac0c33Sjakob /*
6162ac0c33Sjakob  * Routine used by server_main.
6262ac0c33Sjakob  * Handle a command received from the reload process.
6362ac0c33Sjakob  */
6462ac0c33Sjakob void parent_handle_reload_command(netio_type *netio,
6562ac0c33Sjakob 	netio_handler_type *handler, netio_event_types_type event_types);
6662ac0c33Sjakob 
6762ac0c33Sjakob /*
6862ac0c33Sjakob  * Routine used by server_main.
6962ac0c33Sjakob  * Handle a command received from the children processes.
7062ac0c33Sjakob  * Send commands and forwarded xfrd packets when writable.
7162ac0c33Sjakob  */
7262ac0c33Sjakob void parent_handle_child_command(netio_type *netio,
7362ac0c33Sjakob 	netio_handler_type *handler, netio_event_types_type event_types);
7462ac0c33Sjakob 
7562ac0c33Sjakob /*
7662ac0c33Sjakob  * Routine used by server_child.
7762ac0c33Sjakob  * Handle a command received from the parent process.
7862ac0c33Sjakob  */
79d3fecca9Ssthen void child_handle_parent_command(int fd, short event, void* arg);
8062ac0c33Sjakob 
8162ac0c33Sjakob /*
8262ac0c33Sjakob  * Routine used by xfrd
8362ac0c33Sjakob  * Handle interprocess communication with parent process, read and write.
8462ac0c33Sjakob  */
85d3fecca9Ssthen void xfrd_handle_ipc(int fd, short event, void* arg);
8662ac0c33Sjakob 
8762ac0c33Sjakob /* check if all children have exited in an orderly fashion and set mode */
8862ac0c33Sjakob void parent_check_all_children_exited(struct nsd* nsd);
8962ac0c33Sjakob 
90d3fecca9Ssthen /** add stats to total */
91d3fecca9Ssthen void stats_add(struct nsdst* total, struct nsdst* s);
92*9e506f0aSbrad /** subtract stats from total */
93*9e506f0aSbrad void stats_subtract(struct nsdst* total, struct nsdst* s);
94d3fecca9Ssthen 
95d3fecca9Ssthen /** set event to listen to given mode, no timeout, must be added already */
96d3fecca9Ssthen void ipc_xfrd_set_listening(struct xfrd_state* xfrd, short mode);
97d3fecca9Ssthen 
9862ac0c33Sjakob #endif /* NSD_IPC_H */
99