2018-02-27 19:20:58 +00:00
|
|
|
/*-
|
2015-02-24 18:19:20 +00:00
|
|
|
* SSLsplit - transparent SSL/TLS interception
|
2018-02-27 19:20:58 +00:00
|
|
|
* https://www.roe.ch/SSLsplit
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009-2018, Daniel Roethlisberger <daniel@roe.ch>.
|
2019-03-13 11:42:40 +00:00
|
|
|
* Copyright (c) 2017-2019, Soner Tari <sonertari@gmail.com>.
|
2012-04-13 12:47:30 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2018-02-27 19:20:58 +00:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
2012-04-13 12:47:30 +00:00
|
|
|
*
|
2018-02-27 19:20:58 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2012-04-13 12:47:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PXYCONN_H
|
|
|
|
#define PXYCONN_H
|
|
|
|
|
2017-07-25 13:07:39 +00:00
|
|
|
#include "proxy.h"
|
2012-04-13 12:47:30 +00:00
|
|
|
#include "opts.h"
|
|
|
|
#include "attrib.h"
|
|
|
|
#include "pxythrmgr.h"
|
2017-05-29 09:22:23 +00:00
|
|
|
#include "log.h"
|
2012-04-13 12:47:30 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
#include <event2/buffer.h>
|
2018-10-11 21:07:30 +00:00
|
|
|
#include <event2/bufferevent.h>
|
2012-04-13 12:47:30 +00:00
|
|
|
|
2017-10-26 15:57:46 +00:00
|
|
|
/*
|
|
|
|
* Print helper for logging code.
|
|
|
|
*/
|
|
|
|
#define STRORDASH(x) (((x)&&*(x))?(x):"-")
|
|
|
|
#define STRORNONE(x) (((x)&&*(x))?(x):"")
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
#define WANT_CONNECT_LOG(ctx) ((ctx)->opts->connectlog||!(ctx)->opts->detach)
|
2018-10-15 10:42:40 +00:00
|
|
|
#define WANT_CONTENT_LOG(ctx) ((ctx)->opts->contentlog&&((ctx)->proto!=PROTO_PASSTHROUGH))
|
2018-10-08 18:42:49 +00:00
|
|
|
|
|
|
|
#define SSLPROXY_KEY "SSLproxy:"
|
|
|
|
#define SSLPROXY_KEY_LEN strlen(SSLPROXY_KEY)
|
|
|
|
|
2019-03-07 20:14:53 +00:00
|
|
|
#define USERAUTH_MSG "You must authenticate to access the Internet at %s\r\n"
|
|
|
|
|
|
|
|
#define PROTOERROR_MSG "Connection is terminated due to protocol error\r\n"
|
|
|
|
#define PROTOERROR_MSG_LEN strlen(PROTOERROR_MSG)
|
2019-03-05 22:09:02 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
typedef struct pxy_conn_child_ctx pxy_conn_child_ctx_t;
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
typedef void (*fd_readcb_func_t)(evutil_socket_t, short, void *);
|
2019-03-13 14:11:54 +00:00
|
|
|
typedef int (*connect_func_t)(pxy_conn_ctx_t *);
|
2018-10-11 21:07:30 +00:00
|
|
|
|
|
|
|
typedef void (*callback_func_t)(struct bufferevent *, void *);
|
|
|
|
typedef void (*eventcb_func_t)(struct bufferevent *, short, void *);
|
|
|
|
|
2018-10-29 18:38:42 +00:00
|
|
|
typedef void (*bev_free_func_t)(struct bufferevent *, pxy_conn_ctx_t *);
|
2018-10-11 21:07:30 +00:00
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
typedef void (*proto_free_func_t)(pxy_conn_ctx_t *);
|
2019-03-07 20:14:53 +00:00
|
|
|
typedef int (*proto_validate_func_t)(pxy_conn_ctx_t *, char *, size_t);
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
typedef void (*child_connect_func_t)(pxy_conn_child_ctx_t *);
|
|
|
|
typedef void (*child_proto_free_func_t)(pxy_conn_child_ctx_t *);
|
2017-07-15 01:07:42 +00:00
|
|
|
|
2018-11-03 15:50:49 +00:00
|
|
|
/*
|
|
|
|
* Proxy connection context state, describes a proxy connection
|
|
|
|
* with source and destination socket bufferevents, SSL context and
|
|
|
|
* other session state. One of these exists per handled proxy
|
|
|
|
* connection.
|
|
|
|
*/
|
|
|
|
|
2017-07-07 14:18:01 +00:00
|
|
|
/* single socket bufferevent descriptor */
|
2017-05-29 09:22:23 +00:00
|
|
|
typedef struct pxy_conn_desc {
|
|
|
|
struct bufferevent *bev;
|
|
|
|
SSL *ssl;
|
|
|
|
unsigned int closed : 1;
|
2018-10-29 18:38:42 +00:00
|
|
|
bev_free_func_t free;
|
2017-05-29 09:22:23 +00:00
|
|
|
} pxy_conn_desc_t;
|
|
|
|
|
2018-10-12 18:59:16 +00:00
|
|
|
enum conn_type {
|
|
|
|
CONN_TYPE_PARENT = 0,
|
|
|
|
CONN_TYPE_CHILD,
|
|
|
|
};
|
|
|
|
|
2018-10-19 23:03:21 +00:00
|
|
|
typedef enum protocol {
|
2018-10-08 18:42:49 +00:00
|
|
|
PROTO_ERROR = -1,
|
2018-10-06 00:24:14 +00:00
|
|
|
PROTO_PASSTHROUGH = 0,
|
|
|
|
PROTO_HTTP,
|
|
|
|
PROTO_HTTPS,
|
|
|
|
PROTO_POP3,
|
|
|
|
PROTO_POP3S,
|
|
|
|
PROTO_SMTP,
|
|
|
|
PROTO_SMTPS,
|
|
|
|
PROTO_AUTOSSL,
|
|
|
|
PROTO_TCP,
|
|
|
|
PROTO_SSL,
|
2018-10-19 23:03:21 +00:00
|
|
|
} protocol_t;
|
2018-10-17 23:00:49 +00:00
|
|
|
|
2018-10-15 10:42:40 +00:00
|
|
|
typedef struct ssl_ctx ssl_ctx_t;
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
typedef struct proto_ctx proto_ctx_t;
|
2018-10-11 21:07:30 +00:00
|
|
|
typedef struct proto_child_ctx proto_child_ctx_t;
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-15 10:42:40 +00:00
|
|
|
struct ssl_ctx {
|
|
|
|
/* log strings related to SSL */
|
|
|
|
char *ssl_names;
|
|
|
|
char *origcrtfpr;
|
|
|
|
char *usedcrtfpr;
|
|
|
|
|
|
|
|
/* ssl */
|
|
|
|
unsigned int sni_peek_retries : 6; /* max 64 SNI parse retries */
|
|
|
|
unsigned int immutable_cert : 1; /* 1 if the cert cannot be changed */
|
|
|
|
unsigned int generated_cert : 1; /* 1 if we generated a new cert */
|
|
|
|
|
|
|
|
/* server name indicated by client in SNI TLS extension */
|
|
|
|
char *sni;
|
|
|
|
|
|
|
|
X509 *origcrt;
|
|
|
|
|
2018-10-22 13:12:07 +00:00
|
|
|
char *srvdst_ssl_version;
|
|
|
|
char *srvdst_ssl_cipher;
|
2019-03-22 12:21:39 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Per-thread list of ssl conns waiting for the first read event to complete ssl setup
|
|
|
|
// Note that accepting a connection does not mean that a packet will be received,
|
|
|
|
// so we should keep track of such conns, otherwise they may get lost causing memory and fd leak
|
2019-03-22 12:21:39 +00:00
|
|
|
pxy_conn_ctx_t *next_pending;
|
|
|
|
unsigned int pending : 1; /* 1 until first readcb */
|
2018-10-15 10:42:40 +00:00
|
|
|
};
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
struct proto_ctx {
|
2018-10-17 23:00:49 +00:00
|
|
|
protocol_t proto;
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
connect_func_t connectcb;
|
2018-10-08 18:42:49 +00:00
|
|
|
fd_readcb_func_t fd_readcb;
|
2018-10-11 21:07:30 +00:00
|
|
|
|
|
|
|
callback_func_t bev_readcb;
|
|
|
|
callback_func_t bev_writecb;
|
|
|
|
eventcb_func_t bev_eventcb;
|
|
|
|
|
2018-10-08 18:42:49 +00:00
|
|
|
proto_free_func_t proto_free;
|
2019-03-07 20:14:53 +00:00
|
|
|
proto_validate_func_t validatecb;
|
|
|
|
unsigned int is_valid : 1; /* 0 until passed proto validation */
|
2018-10-08 18:42:49 +00:00
|
|
|
|
|
|
|
// For protocol specific fields, if any
|
|
|
|
void *arg;
|
2018-10-05 01:55:24 +00:00
|
|
|
};
|
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
struct proto_child_ctx {
|
2018-10-17 23:00:49 +00:00
|
|
|
protocol_t proto;
|
2018-10-11 21:07:30 +00:00
|
|
|
|
|
|
|
child_connect_func_t connectcb;
|
|
|
|
|
|
|
|
callback_func_t bev_readcb;
|
|
|
|
callback_func_t bev_writecb;
|
|
|
|
eventcb_func_t bev_eventcb;
|
|
|
|
|
|
|
|
child_proto_free_func_t proto_free;
|
|
|
|
|
|
|
|
// For protocol specific fields, if any
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
2018-11-03 15:50:49 +00:00
|
|
|
#ifdef HAVE_LOCAL_PROCINFO
|
|
|
|
/* local process data - filled in iff pid != -1 */
|
|
|
|
typedef struct pxy_conn_lproc_desc {
|
|
|
|
struct sockaddr_storage srcaddr;
|
|
|
|
socklen_t srcaddrlen;
|
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
/* derived log strings */
|
|
|
|
char *exec_path;
|
|
|
|
char *user;
|
|
|
|
char *group;
|
|
|
|
} pxy_conn_lproc_desc_t;
|
|
|
|
#endif /* HAVE_LOCAL_PROCINFO */
|
|
|
|
|
2017-07-12 19:37:36 +00:00
|
|
|
/* parent connection state consisting of three connection descriptors,
|
2017-05-29 09:22:23 +00:00
|
|
|
* connection-wide state and the specs and options */
|
2017-07-15 01:07:42 +00:00
|
|
|
struct pxy_conn_ctx {
|
2017-07-18 19:07:29 +00:00
|
|
|
// Common properties
|
2017-07-29 21:34:46 +00:00
|
|
|
// @attention The order of these common vars should match with their order in children
|
2018-10-12 18:59:16 +00:00
|
|
|
enum conn_type type;
|
|
|
|
|
2018-09-22 23:02:15 +00:00
|
|
|
pxy_conn_ctx_t *conn; /* parent's conn ctx is itself */
|
2018-10-17 23:00:49 +00:00
|
|
|
protocol_t proto;
|
2018-09-22 23:02:15 +00:00
|
|
|
|
2017-05-29 09:22:23 +00:00
|
|
|
/* per-connection state */
|
|
|
|
struct pxy_conn_desc src;
|
|
|
|
struct pxy_conn_desc dst;
|
2017-07-18 19:07:29 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
/* store fd and fd event while connected is 0 */
|
|
|
|
evutil_socket_t fd;
|
2018-10-12 18:59:16 +00:00
|
|
|
// End of common properties
|
2018-10-11 21:07:30 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// For protocol specific fields, never NULL
|
2018-10-15 10:42:40 +00:00
|
|
|
proto_ctx_t *protoctx;
|
2019-03-23 17:41:59 +00:00
|
|
|
// For ssl specific fields, NULL for non-ssl conns
|
2018-10-15 10:42:40 +00:00
|
|
|
ssl_ctx_t *sslctx;
|
2017-05-29 09:22:23 +00:00
|
|
|
|
|
|
|
/* log strings from socket */
|
|
|
|
char *srchost_str;
|
|
|
|
char *srcport_str;
|
|
|
|
char *dsthost_str;
|
|
|
|
char *dstport_str;
|
|
|
|
|
|
|
|
/* content log context */
|
2018-11-03 15:23:31 +00:00
|
|
|
log_content_ctx_t logctx;
|
2017-07-18 19:07:29 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
/* status flags */
|
|
|
|
unsigned int connected : 1; /* 0 until both ends are connected */
|
|
|
|
unsigned int enomem : 1; /* 1 if out of memory */
|
2018-10-22 20:13:42 +00:00
|
|
|
unsigned int srvdst_connected : 1; /* 0 until server is connected */
|
2017-07-18 19:07:29 +00:00
|
|
|
unsigned int dst_connected : 1; /* 0 until dst is connected */
|
2018-10-22 20:13:42 +00:00
|
|
|
unsigned int term : 1; /* 0 until term requested */
|
2019-03-23 17:41:59 +00:00
|
|
|
unsigned int term_requestor : 1; /* 1 client, 0 server side */
|
2017-07-25 13:07:39 +00:00
|
|
|
|
2018-10-22 13:12:07 +00:00
|
|
|
struct pxy_conn_desc srvdst;
|
2017-05-29 09:22:23 +00:00
|
|
|
|
|
|
|
struct event *ev;
|
|
|
|
|
2018-11-03 15:23:31 +00:00
|
|
|
/* original source and destination address, and family */
|
|
|
|
struct sockaddr_storage srcaddr;
|
|
|
|
socklen_t srcaddrlen;
|
|
|
|
struct sockaddr_storage dstaddr;
|
|
|
|
socklen_t dstaddrlen;
|
2017-05-29 09:22:23 +00:00
|
|
|
int af;
|
|
|
|
|
2017-07-15 01:07:42 +00:00
|
|
|
// Thread that the conn is attached to
|
|
|
|
pxy_thr_ctx_t *thr;
|
2019-03-15 12:39:15 +00:00
|
|
|
unsigned int thr_locked : 1; /* 1 to prevent double locking */
|
|
|
|
unsigned int in_thr_conns : 1; /* 1 to prevent adding twice */
|
2017-07-15 01:07:42 +00:00
|
|
|
|
|
|
|
// Unique id of the conn
|
2017-10-26 17:10:36 +00:00
|
|
|
long long unsigned int id;
|
2017-07-15 01:07:42 +00:00
|
|
|
|
|
|
|
pxy_thrmgr_ctx_t *thrmgr;
|
|
|
|
proxyspec_t *spec;
|
|
|
|
opts_t *opts;
|
|
|
|
|
|
|
|
struct event_base *evbase;
|
|
|
|
struct evdns_base *dnsbase;
|
|
|
|
|
|
|
|
evutil_socket_t dst_fd;
|
2018-10-22 13:12:07 +00:00
|
|
|
evutil_socket_t srvdst_fd;
|
2017-07-15 01:07:42 +00:00
|
|
|
|
|
|
|
// Priv sep socket to obtain a socket for children
|
|
|
|
evutil_socket_t clisock;
|
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// fd of event listener for children, explicitly closed on error (not for stats only)
|
2017-07-15 01:07:42 +00:00
|
|
|
evutil_socket_t child_fd;
|
|
|
|
struct evconnlistener *child_evcl;
|
2018-10-15 10:42:40 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// SSLproxy specific info: ip:port addr child is listening on, orig client addr, and orig server addr
|
|
|
|
// SSLproxy header is never sent to the Internet, always removed by child conns
|
2018-10-20 21:25:01 +00:00
|
|
|
char *sslproxy_header;
|
|
|
|
size_t sslproxy_header_len;
|
2019-03-23 17:41:59 +00:00
|
|
|
unsigned int sent_sslproxy_header : 1; /* 1 to prevent inserting SSLproxy header twice */
|
2017-07-15 01:07:42 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Number of child conns, active or closed, always goes up never down
|
2017-07-15 01:07:42 +00:00
|
|
|
unsigned int child_count;
|
2019-03-23 17:41:59 +00:00
|
|
|
// List of child conns
|
|
|
|
pxy_conn_child_ctx_t *children;
|
2017-07-15 01:07:42 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// For statistics only
|
2017-07-15 01:07:42 +00:00
|
|
|
evutil_socket_t child_src_fd;
|
|
|
|
evutil_socket_t child_dst_fd;
|
|
|
|
|
2017-07-15 10:04:13 +00:00
|
|
|
// Conn create time
|
|
|
|
time_t ctime;
|
2017-07-15 01:07:42 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Conn last access time, used to determine expired conns
|
2017-07-15 10:04:13 +00:00
|
|
|
// Updated on entry to callback functions, parent or child
|
|
|
|
time_t atime;
|
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Per-thread conn list, used to determine idle and expired conns, and to close them
|
2017-07-15 01:07:42 +00:00
|
|
|
pxy_conn_ctx_t *next;
|
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Expired conns are link-listed using this pointer, a temporary list used in conn thr timercb only
|
2017-07-15 01:07:42 +00:00
|
|
|
pxy_conn_ctx_t *next_expired;
|
2017-07-18 19:07:29 +00:00
|
|
|
|
2019-03-15 12:39:15 +00:00
|
|
|
// Number of times we try to acquire user db before giving up
|
2019-02-16 14:29:14 +00:00
|
|
|
unsigned int identify_user_count;
|
2019-03-23 17:41:59 +00:00
|
|
|
// User owner of conn
|
2019-02-16 14:29:14 +00:00
|
|
|
char *user;
|
2019-03-23 17:41:59 +00:00
|
|
|
// Ethernet address of client
|
2019-02-28 23:08:24 +00:00
|
|
|
char *ether;
|
2019-03-23 17:41:59 +00:00
|
|
|
// Idle time of user, reset to 0 by a new conn from user if idle time > timeout/2
|
2019-03-10 01:26:00 +00:00
|
|
|
unsigned int idletime;
|
2019-03-15 12:39:15 +00:00
|
|
|
// We send redirect/error msg to client if user auth or proto validation fails
|
|
|
|
unsigned int sent_userauth_msg : 1; /* 1 until error msg is sent */
|
|
|
|
unsigned int sent_protoerror_msg : 1; /* 1 until error msg is sent */
|
2019-03-14 00:47:03 +00:00
|
|
|
|
2017-07-18 19:07:29 +00:00
|
|
|
#ifdef HAVE_LOCAL_PROCINFO
|
|
|
|
/* local process information */
|
|
|
|
pxy_conn_lproc_desc_t lproc;
|
|
|
|
#endif /* HAVE_LOCAL_PROCINFO */
|
2017-07-15 01:07:42 +00:00
|
|
|
};
|
2017-05-29 09:22:23 +00:00
|
|
|
|
2017-07-12 19:37:36 +00:00
|
|
|
/* child connection state consisting of two connection descriptors,
|
|
|
|
* connection-wide state */
|
2017-07-15 01:07:42 +00:00
|
|
|
struct pxy_conn_child_ctx {
|
2017-07-18 19:07:29 +00:00
|
|
|
// Common properties
|
2017-07-29 21:34:46 +00:00
|
|
|
// @attention The order of these common vars should match with their order in parent
|
2018-10-12 18:59:16 +00:00
|
|
|
enum conn_type type;
|
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Parent conn
|
|
|
|
pxy_conn_ctx_t *conn;
|
2018-10-17 23:00:49 +00:00
|
|
|
protocol_t proto;
|
2018-09-22 23:02:15 +00:00
|
|
|
|
2017-07-11 22:45:15 +00:00
|
|
|
/* per-connection state */
|
|
|
|
struct pxy_conn_desc src;
|
|
|
|
struct pxy_conn_desc dst;
|
2017-07-12 19:37:36 +00:00
|
|
|
|
2017-07-18 19:07:29 +00:00
|
|
|
/* store fd and fd event while connected is 0 */
|
|
|
|
evutil_socket_t fd;
|
2018-10-12 18:59:16 +00:00
|
|
|
// End of common properties
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-15 10:42:40 +00:00
|
|
|
proto_child_ctx_t *protoctx;
|
2017-07-18 19:07:29 +00:00
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
/* status flags */
|
|
|
|
unsigned int connected : 1; /* 0 until both ends are connected */
|
2018-10-22 20:13:42 +00:00
|
|
|
unsigned int term : 1; /* 0 until term requested */
|
2018-10-11 21:07:30 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// For statistics only
|
2017-07-18 19:07:29 +00:00
|
|
|
evutil_socket_t dst_fd;
|
2017-07-11 22:45:15 +00:00
|
|
|
|
2019-03-23 17:41:59 +00:00
|
|
|
// Child conns remove the SSLproxy header inserted by parent
|
|
|
|
int removed_sslproxy_header; /* 1 after SSLproxy header is removed */
|
2017-07-12 19:37:36 +00:00
|
|
|
|
|
|
|
// Children of the conn are link-listed using this pointer
|
2019-03-23 17:41:59 +00:00
|
|
|
// We identify child conns with their src fds, so the src fd of child is used as its id while removing it from this list
|
2017-07-12 19:37:36 +00:00
|
|
|
pxy_conn_child_ctx_t *next;
|
2017-07-15 01:07:42 +00:00
|
|
|
};
|
2017-07-11 22:45:15 +00:00
|
|
|
|
2018-11-30 11:28:51 +00:00
|
|
|
#ifdef HAVE_LOCAL_PROCINFO
|
2018-10-17 23:00:49 +00:00
|
|
|
int pxy_prepare_logging_local_procinfo(pxy_conn_ctx_t *) NONNULL(1);
|
2018-11-30 11:28:51 +00:00
|
|
|
#endif /* HAVE_LOCAL_PROCINFO */
|
2018-10-11 21:07:30 +00:00
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
void pxy_log_connect_src(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-22 13:12:07 +00:00
|
|
|
void pxy_log_connect_srvdst(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
int pxy_log_content_inbuf(pxy_conn_ctx_t *, struct evbuffer *, int) NONNULL(1);
|
|
|
|
void pxy_log_connect_nonhttp(pxy_conn_ctx_t *) NONNULL(1);
|
|
|
|
void pxy_log_dbg_evbuf_info(pxy_conn_ctx_t *, pxy_conn_desc_t *, pxy_conn_desc_t *) NONNULL(1,2,3);
|
2018-10-15 22:51:07 +00:00
|
|
|
|
2019-03-15 21:44:12 +00:00
|
|
|
unsigned char *pxy_malloc_packet(size_t, pxy_conn_ctx_t *) MALLOC NONNULL(2) WUNRES;
|
2018-10-15 22:51:07 +00:00
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
int pxy_set_dstaddr(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-17 13:28:21 +00:00
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
void pxy_insert_sslproxy_header(pxy_conn_ctx_t *, unsigned char *, size_t *) NONNULL(1,2,3);
|
2018-10-20 12:29:51 +00:00
|
|
|
void pxy_try_remove_sslproxy_header(pxy_conn_child_ctx_t *, unsigned char *, size_t *) NONNULL(1,2,3);
|
2018-10-15 22:51:07 +00:00
|
|
|
|
2018-10-20 12:29:51 +00:00
|
|
|
void pxy_try_set_watermark(struct bufferevent *, pxy_conn_ctx_t *, struct bufferevent *) NONNULL(1,2,3);
|
|
|
|
void pxy_try_unset_watermark(struct bufferevent *, pxy_conn_ctx_t *, pxy_conn_desc_t *) NONNULL(1,2,3);
|
2018-10-15 22:51:07 +00:00
|
|
|
|
2018-10-29 18:38:42 +00:00
|
|
|
int pxy_try_close_conn_end(pxy_conn_desc_t *, pxy_conn_ctx_t *) NONNULL(1,2);
|
2018-10-08 18:42:49 +00:00
|
|
|
|
2018-10-29 18:38:42 +00:00
|
|
|
void pxy_try_disconnect(pxy_conn_ctx_t *, pxy_conn_desc_t *, pxy_conn_desc_t *, int) NONNULL(1,2,3);
|
|
|
|
void pxy_try_disconnect_child(pxy_conn_child_ctx_t *, pxy_conn_desc_t *, pxy_conn_desc_t *) NONNULL(1,2,3);
|
2018-10-15 16:22:27 +00:00
|
|
|
|
2018-10-28 20:51:22 +00:00
|
|
|
int pxy_try_consume_last_input(struct bufferevent *, pxy_conn_ctx_t *) NONNULL(1,2);
|
|
|
|
int pxy_try_consume_last_input_child(struct bufferevent *, pxy_conn_child_ctx_t *) NONNULL(1,2);
|
2018-10-17 23:00:49 +00:00
|
|
|
void pxy_discard_inbuf(struct bufferevent *) NONNULL(1);
|
2018-10-17 13:28:21 +00:00
|
|
|
|
|
|
|
void pxy_conn_ctx_free(pxy_conn_ctx_t *, int) NONNULL(1);
|
|
|
|
void pxy_conn_free(pxy_conn_ctx_t *, int) NONNULL(1);
|
2018-10-22 20:13:42 +00:00
|
|
|
void pxy_conn_term(pxy_conn_ctx_t *, int) NONNULL(1);
|
|
|
|
void pxy_conn_term_child(pxy_conn_child_ctx_t *) NONNULL(1);
|
2018-10-23 01:02:00 +00:00
|
|
|
void pxy_conn_free_children(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-17 13:28:21 +00:00
|
|
|
|
2018-10-28 20:51:22 +00:00
|
|
|
int pxy_connect_srvdst(struct bufferevent *, pxy_conn_ctx_t *) NONNULL(1,2);
|
2018-10-15 16:22:27 +00:00
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
int pxy_setup_child_listener(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-11 21:07:30 +00:00
|
|
|
|
2018-10-28 20:51:22 +00:00
|
|
|
int pxy_bev_readcb_preexec_logging_and_stats(struct bufferevent *, pxy_conn_ctx_t *) NONNULL(1,2);
|
|
|
|
int pxy_bev_eventcb_postexec_logging_and_stats(struct bufferevent *, short , pxy_conn_ctx_t *) NONNULL(1,3);
|
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
void pxy_bev_readcb(struct bufferevent *, void *);
|
|
|
|
void pxy_bev_writecb(struct bufferevent *, void *);
|
|
|
|
void pxy_bev_eventcb(struct bufferevent *, short, void *);
|
|
|
|
|
2018-10-28 20:51:22 +00:00
|
|
|
int pxy_bev_readcb_preexec_logging_and_stats_child(struct bufferevent *, pxy_conn_child_ctx_t *) NONNULL(1,2);
|
|
|
|
void pxy_bev_eventcb_postexec_stats_child(short, pxy_conn_child_ctx_t *) NONNULL(2);
|
|
|
|
|
2018-10-11 21:07:30 +00:00
|
|
|
void pxy_bev_readcb_child(struct bufferevent *, void *);
|
|
|
|
void pxy_bev_writecb_child(struct bufferevent *, void *);
|
|
|
|
void pxy_bev_eventcb_child(struct bufferevent *, short, void *);
|
|
|
|
|
2018-10-17 23:00:49 +00:00
|
|
|
void pxy_conn_connect(pxy_conn_ctx_t *) NONNULL(1);
|
2018-10-15 22:51:07 +00:00
|
|
|
void pxy_fd_readcb(evutil_socket_t, short, void *);
|
2019-03-14 00:47:03 +00:00
|
|
|
int pxy_userauth(pxy_conn_ctx_t *) NONNULL(1);
|
2017-07-11 22:45:15 +00:00
|
|
|
void pxy_conn_setup(evutil_socket_t, struct sockaddr *, int,
|
|
|
|
pxy_thrmgr_ctx_t *, proxyspec_t *, opts_t *,
|
|
|
|
evutil_socket_t)
|
|
|
|
NONNULL(2,4,5,6);
|
2018-10-15 22:51:07 +00:00
|
|
|
|
2012-04-13 12:47:30 +00:00
|
|
|
#endif /* !PXYCONN_H */
|
|
|
|
|
|
|
|
/* vim: set noet ft=c: */
|