]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * commio.h: A header for the network subsystem. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
22 | * USA | |
23 | * | |
24 | */ | |
25 | ||
26 | #ifndef RB_LIB_H | |
27 | # error "Do not use commio.h directly" | |
28 | #endif | |
29 | ||
30 | #ifndef INCLUDED_commio_h | |
31 | #define INCLUDED_commio_h | |
32 | ||
33 | ||
34 | struct sockaddr; | |
35 | struct _fde; | |
36 | typedef struct _fde rb_fde_t; | |
37 | ||
38 | /* Callback for completed IO events */ | |
39 | typedef void PF(rb_fde_t *, void *); | |
40 | ||
41 | /* Callback for completed connections */ | |
42 | /* int fd, int status, void * */ | |
43 | typedef void CNCB(rb_fde_t *, int, void *); | |
44 | /* callback for fd table dumps */ | |
45 | typedef void DUMPCB(int, const char *desc, void *); | |
46 | /* callback for accept callbacks */ | |
47 | typedef void ACCB(rb_fde_t *, int status, struct sockaddr *addr, rb_socklen_t len, void *); | |
48 | /* callback for pre-accept callback */ | |
49 | typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *); | |
50 | ||
51 | enum | |
52 | { | |
53 | RB_OK, | |
54 | RB_ERR_BIND, | |
55 | RB_ERR_DNS, | |
56 | RB_ERR_TIMEOUT, | |
57 | RB_ERR_CONNECT, | |
58 | RB_ERROR, | |
59 | RB_ERROR_SSL, | |
60 | RB_ERR_MAX | |
61 | }; | |
62 | ||
63 | #define RB_FD_NONE 0x01 | |
64 | #define RB_FD_FILE 0x02 | |
65 | #define RB_FD_SOCKET 0x04 | |
66 | #ifndef _WIN32 | |
67 | #define RB_FD_PIPE 0x08 | |
68 | #else | |
69 | #define RB_FD_PIPE RB_FD_SOCKET | |
70 | #endif | |
71 | #define RB_FD_LISTEN 0x10 | |
72 | #define RB_FD_SSL 0x20 | |
73 | #define RB_FD_UNKNOWN 0x40 | |
74 | ||
75 | #define RB_RW_IO_ERROR -1 /* System call error */ | |
76 | #define RB_RW_SSL_ERROR -2 /* SSL Error */ | |
77 | #define RB_RW_SSL_NEED_READ -3 /* SSL Needs read */ | |
78 | #define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */ | |
79 | ||
80 | ||
81 | struct rb_iovec | |
82 | { | |
83 | void *iov_base; | |
84 | size_t iov_len; | |
85 | }; | |
86 | ||
87 | ||
88 | void rb_fdlist_init(int closeall, int maxfds, size_t heapsize); | |
89 | ||
90 | rb_fde_t *rb_open(rb_platform_fd_t, uint8_t, const char *); | |
91 | void rb_close(rb_fde_t *); | |
92 | void rb_dump_fd(DUMPCB *, void *xdata); | |
93 | void rb_note(rb_fde_t *, const char *); | |
94 | ||
95 | /* Type of IO */ | |
96 | #define RB_SELECT_READ 0x1 | |
97 | #define RB_SELECT_WRITE 0x2 | |
98 | ||
99 | #define RB_SELECT_ACCEPT RB_SELECT_READ | |
100 | #define RB_SELECT_CONNECT RB_SELECT_WRITE | |
101 | ||
102 | #define RB_SSL_CERTFP_LEN 64 | |
103 | ||
104 | /* Methods for certfp */ | |
105 | /* Digest of full X.509 certificate */ | |
106 | #define RB_SSL_CERTFP_METH_CERT_SHA1 0x0000 | |
107 | #define RB_SSL_CERTFP_METH_CERT_SHA256 0x0001 | |
108 | #define RB_SSL_CERTFP_METH_CERT_SHA512 0x0002 | |
109 | /* Digest of SubjectPublicKeyInfo (RFC 5280), used by DANE (RFC 6698) */ | |
110 | #define RB_SSL_CERTFP_METH_SPKI_SHA256 0x1001 | |
111 | #define RB_SSL_CERTFP_METH_SPKI_SHA512 0x1002 | |
112 | ||
113 | #define RB_SSL_CERTFP_LEN_SHA1 20 | |
114 | #define RB_SSL_CERTFP_LEN_SHA256 32 | |
115 | #define RB_SSL_CERTFP_LEN_SHA512 64 | |
116 | ||
117 | int rb_set_nb(rb_fde_t *); | |
118 | int rb_set_buffers(rb_fde_t *, int); | |
119 | ||
120 | int rb_get_sockerr(rb_fde_t *); | |
121 | ||
122 | void rb_settimeout(rb_fde_t *, time_t, PF *, void *); | |
123 | void rb_checktimeouts(void *); | |
124 | void rb_connect_tcp(rb_fde_t *, struct sockaddr *, struct sockaddr *, CNCB *, void *, int); | |
125 | void rb_connect_tcp_ssl(rb_fde_t *, struct sockaddr *, struct sockaddr *, CNCB *, void *, int); | |
126 | int rb_connect_sockaddr(rb_fde_t *, struct sockaddr *addr, int len); | |
127 | ||
128 | const char *rb_errstr(int status); | |
129 | rb_fde_t *rb_socket(int family, int sock_type, int proto, const char *note); | |
130 | int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2, | |
131 | const char *note); | |
132 | ||
133 | void rb_accept_tcp(rb_fde_t *, ACPRE * precb, ACCB * callback, void *data); | |
134 | ssize_t rb_write(rb_fde_t *, const void *buf, int count); | |
135 | ssize_t rb_writev(rb_fde_t *, struct rb_iovec *vector, int count); | |
136 | ||
137 | ssize_t rb_read(rb_fde_t *, void *buf, int count); | |
138 | int rb_pipe(rb_fde_t **, rb_fde_t **, const char *desc); | |
139 | ||
140 | int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile, const char *cipher_list); | |
141 | int rb_ssl_listen(rb_fde_t *, int backlog, int defer_accept); | |
142 | int rb_listen(rb_fde_t *, int backlog, int defer_accept); | |
143 | ||
144 | const char *rb_inet_ntop(int af, const void *src, char *dst, unsigned int size); | |
145 | int rb_inet_pton(int af, const char *src, void *dst); | |
146 | const char *rb_inet_ntop_sock(struct sockaddr *src, char *dst, unsigned int size); | |
147 | int rb_inet_pton_sock(const char *src, struct sockaddr *dst); | |
148 | int rb_getmaxconnect(void); | |
149 | int rb_ignore_errno(int); | |
150 | ||
151 | /* Generic wrappers */ | |
152 | void rb_setselect(rb_fde_t *, unsigned int type, PF * handler, void *client_data); | |
153 | void rb_init_netio(void); | |
154 | int rb_select(unsigned long); | |
155 | int rb_fd_ssl(rb_fde_t *F); | |
156 | rb_platform_fd_t rb_get_fd(rb_fde_t *F); | |
157 | const char *rb_get_ssl_strerror(rb_fde_t *F); | |
158 | int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN], int method); | |
159 | int rb_get_ssl_certfp_file(const char *filename, uint8_t certfp[RB_SSL_CERTFP_LEN], int method); | |
160 | ||
161 | rb_fde_t *rb_get_fde(rb_platform_fd_t fd); | |
162 | ||
163 | int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid); | |
164 | int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int count); | |
165 | ||
166 | void rb_set_type(rb_fde_t *F, uint8_t type); | |
167 | uint8_t rb_get_type(rb_fde_t *F); | |
168 | ||
169 | const char *rb_get_iotype(void); | |
170 | ||
171 | typedef enum | |
172 | { | |
173 | RB_PRNG_FILE, | |
174 | #ifdef _WIN32 | |
175 | RB_PRNGWIN32, | |
176 | #endif | |
177 | RB_PRNG_DEFAULT, | |
178 | } prng_seed_t; | |
179 | ||
180 | int rb_init_prng(const char *path, prng_seed_t seed_type); | |
181 | int rb_get_random(void *buf, size_t len); | |
182 | void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout); | |
183 | void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout); | |
184 | int rb_supports_ssl(void); | |
185 | ||
186 | unsigned int rb_ssl_handshake_count(rb_fde_t *F); | |
187 | void rb_ssl_clear_handshake_count(rb_fde_t *F); | |
188 | ||
189 | int rb_pass_fd_to_process(rb_fde_t *, pid_t, rb_fde_t *); | |
190 | rb_fde_t *rb_recv_fd(rb_fde_t *); | |
191 | ||
192 | const char *rb_ssl_get_cipher(rb_fde_t *F); | |
193 | ||
194 | int rb_ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6, struct sockaddr_in *restrict ip4); | |
195 | ||
196 | #endif /* INCLUDED_commio_h */ |