xref: /netbsd-src/external/bsd/nsd/dist/ipc.h (revision d83a80ee7fb31190352cf1f781441e06ca6a86db)
1 /*
2  * ipc.h - Interprocess communication routines. Handlers read and write.
3  *
4  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  *
8  */
9 
10 #ifndef NSD_IPC_H
11 #define NSD_IPC_H
12 
13 #include "netio.h"
14 struct buffer;
15 struct nsd;
16 struct nsd_child;
17 struct xfrd_tcp;
18 struct xfrd_state;
19 struct nsdst;
20 struct event;
21 
22 /*
23  * Data for the server_main IPC handler
24  * Used by parent side to listen to children, and write to children.
25  */
26 struct main_ipc_handler_data
27 {
28 	struct nsd	*nsd;
29 	struct nsd_child *child;
30 	int		child_num;
31 
32 	/* pointer to the socket, as it may change if it is restarted */
33 	int		*xfrd_sock;
34 	struct buffer	*packet;
35 	int		forward_mode;
36 	size_t		got_bytes;
37 	uint16_t	total_bytes;
38 	uint32_t	acl_num;
39 	int32_t		acl_xfr;
40 };
41 
42 /*
43  * Data for ipc handler, nsd and a conn for reading ipc msgs.
44  * Used by children to listen to parent.
45  * Used by parent to listen to xfrd.
46  */
47 struct ipc_handler_conn_data
48 {
49 	struct nsd	*nsd;
50 	struct xfrd_tcp	*conn;
51 };
52 
53 /*
54  * Routine used by server_main.
55  * Handle a command received from the xfrdaemon processes.
56  */
57 void parent_handle_xfrd_command(netio_type *netio,
58 	netio_handler_type *handler, netio_event_types_type event_types);
59 
60 /*
61  * Routine used by server_main.
62  * Handle a command received from the reload process.
63  */
64 void parent_handle_reload_command(netio_type *netio,
65 	netio_handler_type *handler, netio_event_types_type event_types);
66 
67 /*
68  * Routine used by server_main.
69  * Handle a command received from the children processes.
70  * Send commands and forwarded xfrd packets when writable.
71  */
72 void parent_handle_child_command(netio_type *netio,
73 	netio_handler_type *handler, netio_event_types_type event_types);
74 
75 /*
76  * Routine used by server_child.
77  * Handle a command received from the parent process.
78  */
79 void child_handle_parent_command(int fd, short event, void* arg);
80 
81 /*
82  * Routine used by xfrd
83  * Handle interprocess communication with parent process, read and write.
84  */
85 void xfrd_handle_ipc(int fd, short event, void* arg);
86 
87 /* check if all children have exited in an orderly fashion and set mode */
88 void parent_check_all_children_exited(struct nsd* nsd);
89 
90 /** add stats to total */
91 void stats_add(struct nsdst* total, struct nsdst* s);
92 /** subtract stats from total */
93 void stats_subtract(struct nsdst* total, struct nsdst* s);
94 
95 /** set event to listen to given mode, no timeout, must be added already */
96 void ipc_xfrd_set_listening(struct xfrd_state* xfrd, short mode);
97 
98 #endif /* NSD_IPC_H */
99