2008-04-01 16:52:26 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* commio.h: A header for the network subsystem.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
*/
|
2008-12-02 23:49:39 +00:00
|
|
|
|
2008-04-01 16:52:26 +00:00
|
|
|
#ifndef RB_LIB_H
|
2008-12-02 23:49:39 +00:00
|
|
|
# error "Do not use commio.h directly"
|
2008-04-01 16:52:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INCLUDED_commio_h
|
|
|
|
#define INCLUDED_commio_h
|
|
|
|
|
|
|
|
|
2008-12-02 23:49:39 +00:00
|
|
|
struct sockaddr;
|
2008-04-01 16:52:26 +00:00
|
|
|
struct _fde;
|
|
|
|
typedef struct _fde rb_fde_t;
|
|
|
|
|
|
|
|
/* Callback for completed IO events */
|
|
|
|
typedef void PF(rb_fde_t *, void *);
|
|
|
|
|
|
|
|
/* Callback for completed connections */
|
|
|
|
/* int fd, int status, void * */
|
|
|
|
typedef void CNCB(rb_fde_t *, int, void *);
|
|
|
|
/* callback for fd table dumps */
|
|
|
|
typedef void DUMPCB(int, const char *desc, void *);
|
|
|
|
/* callback for accept callbacks */
|
|
|
|
typedef void ACCB(rb_fde_t *, int status, struct sockaddr *addr, rb_socklen_t len, void *);
|
|
|
|
/* callback for pre-accept callback */
|
|
|
|
typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
RB_OK,
|
|
|
|
RB_ERR_BIND,
|
|
|
|
RB_ERR_DNS,
|
|
|
|
RB_ERR_TIMEOUT,
|
|
|
|
RB_ERR_CONNECT,
|
|
|
|
RB_ERROR,
|
|
|
|
RB_ERROR_SSL,
|
|
|
|
RB_ERR_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RB_FD_NONE 0x01
|
|
|
|
#define RB_FD_FILE 0x02
|
|
|
|
#define RB_FD_SOCKET 0x04
|
|
|
|
#define RB_FD_PIPE 0x08
|
|
|
|
#define RB_FD_LISTEN 0x10
|
|
|
|
#define RB_FD_SSL 0x20
|
|
|
|
#define RB_FD_UNKNOWN 0x40
|
2017-08-19 14:11:49 +00:00
|
|
|
#define RB_FD_SCTP 0x80
|
|
|
|
|
|
|
|
#define RB_FD_INHERIT_TYPES (RB_FD_SCTP)
|
2008-04-01 16:52:26 +00:00
|
|
|
|
|
|
|
#define RB_RW_IO_ERROR -1 /* System call error */
|
|
|
|
#define RB_RW_SSL_ERROR -2 /* SSL Error */
|
|
|
|
#define RB_RW_SSL_NEED_READ -3 /* SSL Needs read */
|
|
|
|
#define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */
|
|
|
|
|
|
|
|
|
|
|
|
struct rb_iovec
|
|
|
|
{
|
|
|
|
void *iov_base;
|
|
|
|
size_t iov_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void rb_fdlist_init(int closeall, int maxfds, size_t heapsize);
|
|
|
|
|
2021-07-09 00:11:22 +00:00
|
|
|
rb_fde_t *rb_open(int, uint8_t, const char *);
|
2008-04-01 16:52:26 +00:00
|
|
|
void rb_close(rb_fde_t *);
|
|
|
|
void rb_dump_fd(DUMPCB *, void *xdata);
|
|
|
|
void rb_note(rb_fde_t *, const char *);
|
2021-06-19 10:41:17 +00:00
|
|
|
void rb_close_pending_fds(void);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
|
|
|
/* Type of IO */
|
|
|
|
#define RB_SELECT_READ 0x1
|
|
|
|
#define RB_SELECT_WRITE 0x2
|
|
|
|
|
2015-05-27 21:46:46 +00:00
|
|
|
#define RB_SELECT_ACCEPT RB_SELECT_READ
|
|
|
|
#define RB_SELECT_CONNECT RB_SELECT_WRITE
|
2008-04-01 16:52:26 +00:00
|
|
|
|
2015-05-27 21:46:46 +00:00
|
|
|
#define RB_SSL_CERTFP_LEN 64
|
|
|
|
|
|
|
|
/* Methods for certfp */
|
2016-04-23 21:51:05 +00:00
|
|
|
/* Digest of full X.509 certificate */
|
|
|
|
#define RB_SSL_CERTFP_METH_CERT_SHA1 0x0000
|
|
|
|
#define RB_SSL_CERTFP_METH_CERT_SHA256 0x0001
|
|
|
|
#define RB_SSL_CERTFP_METH_CERT_SHA512 0x0002
|
|
|
|
/* Digest of SubjectPublicKeyInfo (RFC 5280), used by DANE (RFC 6698) */
|
|
|
|
#define RB_SSL_CERTFP_METH_SPKI_SHA256 0x1001
|
|
|
|
#define RB_SSL_CERTFP_METH_SPKI_SHA512 0x1002
|
2015-05-27 21:46:46 +00:00
|
|
|
|
|
|
|
#define RB_SSL_CERTFP_LEN_SHA1 20
|
|
|
|
#define RB_SSL_CERTFP_LEN_SHA256 32
|
|
|
|
#define RB_SSL_CERTFP_LEN_SHA512 64
|
2010-01-31 18:04:20 +00:00
|
|
|
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_set_nb(rb_fde_t *);
|
2020-12-13 08:38:25 +00:00
|
|
|
int rb_set_cloexec(rb_fde_t *);
|
|
|
|
int rb_clear_cloexec(rb_fde_t *);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_set_buffers(rb_fde_t *, int);
|
|
|
|
|
|
|
|
int rb_get_sockerr(rb_fde_t *);
|
|
|
|
|
|
|
|
void rb_settimeout(rb_fde_t *, time_t, PF *, void *);
|
|
|
|
void rb_checktimeouts(void *);
|
2016-04-24 16:11:20 +00:00
|
|
|
void rb_connect_tcp(rb_fde_t *, struct sockaddr *, struct sockaddr *, CNCB *, void *, int);
|
|
|
|
void rb_connect_tcp_ssl(rb_fde_t *, struct sockaddr *, struct sockaddr *, CNCB *, void *, int);
|
2017-08-22 19:59:53 +00:00
|
|
|
void rb_connect_sctp(rb_fde_t *, struct sockaddr_storage *connect_addrs, size_t connect_len, struct sockaddr_storage *bind_addrs, size_t bind_len, CNCB *, void *, int);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_connect_sockaddr(rb_fde_t *, struct sockaddr *addr, int len);
|
|
|
|
|
|
|
|
const char *rb_errstr(int status);
|
|
|
|
rb_fde_t *rb_socket(int family, int sock_type, int proto, const char *note);
|
2008-12-02 23:49:39 +00:00
|
|
|
int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2,
|
|
|
|
const char *note);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
2017-08-19 14:11:49 +00:00
|
|
|
int rb_bind(rb_fde_t *F, struct sockaddr *addr);
|
|
|
|
int rb_sctp_bindx(rb_fde_t *F, struct sockaddr_storage *addrs, size_t len);
|
|
|
|
int rb_inet_get_proto(rb_fde_t *F);
|
|
|
|
|
2008-12-02 23:49:39 +00:00
|
|
|
void rb_accept_tcp(rb_fde_t *, ACPRE * precb, ACCB * callback, void *data);
|
2008-04-01 16:52:26 +00:00
|
|
|
ssize_t rb_write(rb_fde_t *, const void *buf, int count);
|
|
|
|
ssize_t rb_writev(rb_fde_t *, struct rb_iovec *vector, int count);
|
|
|
|
|
|
|
|
ssize_t rb_read(rb_fde_t *, void *buf, int count);
|
|
|
|
int rb_pipe(rb_fde_t **, rb_fde_t **, const char *desc);
|
|
|
|
|
2015-12-12 13:50:48 +00:00
|
|
|
int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile, const char *cipher_list);
|
2012-03-17 14:48:25 +00:00
|
|
|
int rb_ssl_listen(rb_fde_t *, int backlog, int defer_accept);
|
|
|
|
int rb_listen(rb_fde_t *, int backlog, int defer_accept);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
|
|
|
const char *rb_inet_ntop(int af, const void *src, char *dst, unsigned int size);
|
|
|
|
int rb_inet_pton(int af, const char *src, void *dst);
|
|
|
|
const char *rb_inet_ntop_sock(struct sockaddr *src, char *dst, unsigned int size);
|
2019-08-31 15:10:50 +00:00
|
|
|
int rb_inet_pton_sock(const char *src, struct sockaddr_storage *dst);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_getmaxconnect(void);
|
|
|
|
int rb_ignore_errno(int);
|
|
|
|
|
|
|
|
/* Generic wrappers */
|
|
|
|
void rb_setselect(rb_fde_t *, unsigned int type, PF * handler, void *client_data);
|
|
|
|
void rb_init_netio(void);
|
|
|
|
int rb_select(unsigned long);
|
2023-11-05 22:05:41 +00:00
|
|
|
void rb_defer(void (*)(void *), void *);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_fd_ssl(rb_fde_t *F);
|
2021-07-09 00:11:22 +00:00
|
|
|
int rb_get_fd(rb_fde_t *F);
|
2008-04-01 16:52:26 +00:00
|
|
|
const char *rb_get_ssl_strerror(rb_fde_t *F);
|
2015-05-27 21:46:46 +00:00
|
|
|
int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN], int method);
|
2016-04-26 19:21:23 +00:00
|
|
|
int rb_get_ssl_certfp_file(const char *filename, uint8_t certfp[RB_SSL_CERTFP_LEN], int method);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
2021-07-09 00:11:22 +00:00
|
|
|
rb_fde_t *rb_get_fde(int fd);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
2008-12-02 23:49:39 +00:00
|
|
|
int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int count);
|
|
|
|
|
2008-07-29 22:41:27 +00:00
|
|
|
void rb_set_type(rb_fde_t *F, uint8_t type);
|
|
|
|
uint8_t rb_get_type(rb_fde_t *F);
|
2008-04-01 16:52:26 +00:00
|
|
|
|
|
|
|
const char *rb_get_iotype(void);
|
|
|
|
|
2008-12-02 23:49:39 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2008-04-01 16:52:26 +00:00
|
|
|
RB_PRNG_FILE,
|
|
|
|
RB_PRNG_DEFAULT,
|
|
|
|
} prng_seed_t;
|
|
|
|
|
|
|
|
int rb_init_prng(const char *path, prng_seed_t seed_type);
|
|
|
|
int rb_get_random(void *buf, size_t len);
|
2008-12-02 23:49:39 +00:00
|
|
|
void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout);
|
|
|
|
void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout);
|
2008-04-01 16:52:26 +00:00
|
|
|
int rb_supports_ssl(void);
|
|
|
|
|
2008-06-25 05:28:30 +00:00
|
|
|
unsigned int rb_ssl_handshake_count(rb_fde_t *F);
|
|
|
|
void rb_ssl_clear_handshake_count(rb_fde_t *F);
|
2008-12-02 23:49:39 +00:00
|
|
|
|
|
|
|
int rb_pass_fd_to_process(rb_fde_t *, pid_t, rb_fde_t *);
|
|
|
|
rb_fde_t *rb_recv_fd(rb_fde_t *);
|
|
|
|
|
2015-12-11 14:32:02 +00:00
|
|
|
const char *rb_ssl_get_cipher(rb_fde_t *F);
|
|
|
|
|
2016-04-08 08:49:23 +00:00
|
|
|
int rb_ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6, struct sockaddr_in *restrict ip4);
|
|
|
|
|
2008-04-01 16:52:26 +00:00
|
|
|
#endif /* INCLUDED_commio_h */
|