-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathnetlog-conf.c
More file actions
333 lines (276 loc) · 11.7 KB
/
netlog-conf.c
File metadata and controls
333 lines (276 loc) · 11.7 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <resolv.h>
#include "conf-parser.h"
#include "def.h"
#include "extract-word.h"
#include "in-addr-util.h"
#include "netlog-conf.h"
#include "parse-util.h"
#include "sd-resolve.h"
#include "string-util.h"
int config_parse_netlog_remote_address(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
const char *e;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
r = socket_address_parse(&m->address, rvalue);
if (r < 0) {
const struct addrinfo hints = {
.ai_flags = AI_NUMERICSERV|AI_ADDRCONFIG,
.ai_socktype = SOCK_DGRAM,
.ai_family = socket_ipv6_is_supported() ? AF_UNSPEC : AF_INET,
};
uint32_t u;
e = strchr(rvalue, ':');
if (e) {
r = safe_atou(e+1, &u);
if (r < 0)
return r;
if (u <= 0 || u > 0xFFFF)
return -EINVAL;
m->port = u;
m->server_name = strndup(rvalue, e-rvalue);
if (!m->server_name)
return log_oom();
log_debug("Remote server='%s' port: '%u'...", m->server_name, u);
/* Tell the resolver to reread /etc/resolv.conf, in
* case it changed. */
res_init();
log_debug("Resolving %s...", m->server_name);
r = sd_resolve_getaddrinfo(m->resolve, &m->resolve_query, m->server_name, NULL, &hints, manager_resolve_handler, m);
if (r < 0)
return log_error_errno(r, "Failed to create resolver: %m");
m->resolving = true;
return 0;
}
log_syntax(unit, LOG_WARNING, filename, line, -r, "Failed to parse '%s=%s', ignoring.", lvalue, rvalue);
return 0;
}
return 0;
}
int config_parse_protocol(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
r = protocol_from_string(rvalue);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, -r, "Failed to parse '%s=%s', ignoring.", lvalue, rvalue);
return 0;
}
m->protocol = r;
return 0;
}
int config_parse_log_format(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
r = log_format_from_string(rvalue);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, -r, "Failed to parse '%s=%s', ignoring.", lvalue, rvalue);
return 0;
}
m->log_format = r;
return 0;
}
int config_parse_tls_certificate_auth_mode(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
r = certificate_auth_mode_from_string(rvalue);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, -r, "Failed to parse '%s=%s', ignoring.", lvalue, rvalue);
return 0;
}
m->auth_mode = r;
return 0;
}
int config_parse_namespace(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
if (streq(rvalue, "*"))
m->namespace_flags = SD_JOURNAL_ALL_NAMESPACES;
else if (startswith(rvalue, "+")) {
m->namespace_flags = SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE;
m->namespace = strdup(rvalue);
if (!m->namespace)
return log_oom();
} else {
m->namespace = strdup(rvalue);
if (!m->namespace)
return log_oom();
}
return 0;
}
int config_parse_syslog_facility(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
uint32_t val = 0;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
for (const char *p = rvalue;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue);
return 0;
}
if (r == 0)
break;
r = syslog_facility_from_string(word);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse syslog facility '%s', ignoring", word);
} else
val |= UINT32_C(1) << r;
}
m->excluded_syslog_facilities = val;
return 0;
}
int config_parse_syslog_level(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Manager *m = userdata;
uint8_t val = 0;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
assert(m);
for (const char *p = rvalue;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue);
return 0;
}
if (r == 0)
break;
r = syslog_level_from_string(word);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse syslog level '%s', ignoring", word);
} else
val |= UINT8_C(1) << r;
}
m->excluded_syslog_levels = val;
return 0;
}
int manager_parse_config_file(Manager *m) {
int r;
assert(m);
r = config_parse_many(PKGSYSCONFDIR "/netlogd.conf",
CONF_PATHS_NULSTR("systemd/netlogd.conf.d"),
"Network\0",
config_item_perf_lookup, netlog_gperf_lookup,
false, m);
if (r < 0)
return r;
if (m->connection_retry_usec < 1 * USEC_PER_SEC) {
log_warning("Invalid ConnectionRetrySec=. Using default value.");
m->connection_retry_usec = DEFAULT_CONNECTION_RETRY_USEC;
}
if (m->auth_mode != OPEN_SSL_CERTIFICATE_AUTH_MODE_DENY
&& m->protocol != SYSLOG_TRANSMISSION_PROTOCOL_TLS
&& m->protocol != SYSLOG_TRANSMISSION_PROTOCOL_DTLS)
log_warning("TLSCertificateAuthMode= set but unencrypted %s connection specified.", protocol_to_string(m->protocol));
if (m->server_cert
&& m->protocol != SYSLOG_TRANSMISSION_PROTOCOL_TLS
&& m->protocol != SYSLOG_TRANSMISSION_PROTOCOL_DTLS)
log_warning("TLSServerCertificate= set but unencrypted %s connection specified.", protocol_to_string(m->protocol));
if (m->dir && m->namespace)
log_warning("Ignoring Namespace= setting since Directory= is set.");
if (m->structured_data && m->syslog_structured_data)
log_warning("Ignoring UseSysLogStructuredData= since StructuredData= is set.");
if (timestamp_is_set(m->keep_alive_time) && !m->keep_alive)
log_warning("Ignoring KeepAliveTimeSec= since KeepAlive= is not set.");
if (m->keep_alive_interval > 0 && !m->keep_alive)
log_warning("Ignoring KeepAliveIntervalSec= since KeepAlive= is not set.");
if (m->keep_alive_cnt > 0 && !m->keep_alive)
log_warning("Ignoring KeepAliveProbes= since KeepAlive= is not set.");
if (m->send_buffer != 0 && (m->send_buffer < 4096 || m->send_buffer > 128 * 1024 * 1024))
log_warning("SendBuffer= set to an suspicious value of %zu.", m->send_buffer);
return 0;
}