-
Notifications
You must be signed in to change notification settings - Fork 107
/
router.h
124 lines (108 loc) · 3.62 KB
/
router.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright 2013-2024 Fabian Groffen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ROUTER_H
#define ROUTER_H 1
#include <stdio.h>
#include <time.h>
#include "relay.h"
#include "server.h"
#include "aggregator.h"
#include "posixregex.h"
#ifdef HAVE_SSL
#include <openssl/ssl.h>
#endif
#define PMODE_NORM (1 << 0)
#define PMODE_AGGR (1 << 1)
#define PMODE_HASH (1 << 2)
#define PMODE_STUB (1 << 3)
#define PMODE_PEMT (1 << 4)
#define PMODE_DEBUG (PMODE_HASH | PMODE_STUB)
#define CONN_DESTS_SIZE 128
#ifndef TMPDIR
# define TMPDIR "/tmp"
#endif
#define SOCKFILE ".s.carbon-c-relay"
typedef struct {
const char *metric;
server *dest;
} destination;
/* ensure we always define the protovers such that the parser can
* reference them, even though they will never get used */
#ifdef HAVE_SSL
# define TLSVER(S,V) S = V
# ifndef SSL3_VERSION
# define SSL3_VERSION 0x0300
# endif
# ifndef TLS1_3_VERSION
# define TLS1_3_VERSION 0x0304
# endif
#else
# define TLSVER(S,V) S
#endif
typedef enum _router_tlsprotover {
_rp_UNSET = 0,
TLSVER(_rp_SSL3, SSL3_VERSION),
TLSVER(_rp_TLS1_0, TLS1_VERSION),
TLSVER(_rp_TLS1_1, TLS1_1_VERSION),
TLSVER(_rp_TLS1_2, TLS1_2_VERSION),
TLSVER(_rp_TLS1_3, TLS1_3_VERSION)
} tlsprotover;
#undef TLSVER
typedef struct _router_listener {
con_type lsnrtype;
con_trnsp transport;
con_proto ctype;
char *ip;
unsigned short port;
int *socks;
#ifdef HAVE_SSL
SSL_CTX *ctx;
SSL **sslstrms;
char *pemcert;
tlsprotover protomin;
tlsprotover protomax;
char *ciphers;
char *ciphersuites;
struct timespec pemmtimespec;
#endif
struct addrinfo *saddrs;
struct _router_listener *next;
} listener;
typedef struct _router router;
typedef enum { SUB, CUM } col_mode;
#define RE_MAX_MATCHES 64
router *router_readconfig(router *orig, const char *path, char workercnt, size_t queuesize, size_t batchsize, int maxstalls, unsigned short iotimeout, unsigned int sockbufsize, unsigned short port);
void router_optimise(router *r, int threshold);
char router_printdiffs(router *old, router *new, FILE *out);
listener *router_contains_listener(router *rtr, listener *lsnr);
void router_transplant_queues(router *new, router *old);
void router_reopen_files(router *rtr);
void router_transplant_listener_socks(router *rtr, listener *olsnr, listener *nlsnr);
char router_start(router *r);
size_t router_rewrite_metric(char (*newmetric)[METRIC_BUFSIZ], char **newfirstspace, const char *metric, const char *firstspace, const char *replacement, const size_t nmatch, const regmatch_t *pmatch);
void router_printconfig(router *r, FILE *f, char mode);
char router_route(router *r, destination ret[], size_t *retcnt, size_t retsize, char *srcaddr, char *metric, char *firstspace, int dispatcher_id);
void router_test(router *r, char *metric_path);
listener *router_get_listeners(router *r);
server **router_getservers(router *r);
aggregator *router_getaggregators(router *r);
char *router_getcollectorstub(router *r);
int router_getcollectorinterval(router *r);
char *router_getcollectorprefix(router *r);
col_mode router_getcollectormode(router *r);
void router_shutdown(router *r);
void router_free(router *r);
#endif