Skip to content

Commit 6d4741e

Browse files
Merge pull request #2 from Craig-Robb-GGL/craigr/network_verifier_plugin_type
New Network Verifier plugin type
2 parents d814153 + 9ae7491 commit 6d4741e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+904
-53
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ if(FLB_TLS)
743743
find_package(OpenSSL)
744744
if(OPENSSL_FOUND)
745745
FLB_DEFINITION(FLB_HAVE_OPENSSL)
746+
include_directories(${OPENSSL_INCLUDE_DIR})
746747
endif()
747748

748749
if (FLB_SYSTEM_WINDOWS AND NOT(OPENSSL_FOUND))

include/fluent-bit/config_format/flb_cf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum section_type {
6060
FLB_CF_PLUGINS, /* plugins */
6161
FLB_CF_UPSTREAM_SERVERS, /* upstream_servers */
6262
FLB_CF_CUSTOM, /* [CUSTOM] */
63+
FLB_CF_NETWORK_VERIFIER, /* [network_verifier] */
6364
FLB_CF_INPUT, /* [INPUT] */
6465
FLB_CF_FILTER, /* [FILTER] */
6566
FLB_CF_OUTPUT, /* [OUTPUT] */
@@ -112,6 +113,9 @@ struct flb_cf {
112113
/* 'custom' type plugins */
113114
struct mk_list customs;
114115

116+
/* 'network_verifier' type plugins */
117+
struct mk_list network_verifiers;
118+
115119
/* pipeline */
116120
struct mk_list inputs;
117121
struct mk_list filters;

include/fluent-bit/flb_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct flb_config {
136136
struct mk_list parser_plugins; /* not yet implemented */
137137
struct mk_list filter_plugins;
138138
struct mk_list out_plugins;
139+
struct mk_list network_verifier_plugins;
139140

140141
/* Custom instances */
141142
struct mk_list customs;
@@ -156,6 +157,9 @@ struct flb_config {
156157
/* Filter instances */
157158
struct mk_list filters;
158159

160+
/* Network Verifier instances */
161+
struct mk_list network_verifiers;
162+
159163
struct mk_event_loop *evl; /* the event loop (mk_core) */
160164

161165
struct flb_bucket_queue *evl_bktq; /* bucket queue for evl track event priority */

include/fluent-bit/flb_connection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,7 @@ void flb_connection_unset_connection_timeout(struct flb_connection *connection);
181181
void flb_connection_reset_io_timeout(struct flb_connection *connection);
182182
void flb_connection_unset_io_timeout(struct flb_connection *connection);
183183

184+
void flb_connection_notify_error(const struct flb_connection* conn,
185+
const char* dest, int port, int error_code, const char* error_msg);
186+
184187
#endif

include/fluent-bit/flb_input.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ struct flb_input_instance {
458458
char *tls_max_version; /* Maximum protocol version of TLS */
459459
char *tls_ciphers; /* TLS ciphers */
460460

461+
462+
char *network_verifier; /* Network Verifier alias */
463+
struct flb_network_verifier_instance* verifier_ins;
464+
461465
struct mk_list *tls_config_map;
462466

463467
#ifdef FLB_HAVE_TLS
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2024 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef FLB_NETWORK_VERIFIER_H
21+
#define FLB_NETWORK_VERIFIER_H
22+
23+
#include <fluent-bit/flb_info.h>
24+
#include <fluent-bit/flb_config.h>
25+
#include <fluent-bit/flb_config_map.h>
26+
27+
#include <openssl/types.h>
28+
29+
#define FLB_X509_STORE_EX_INDEX 0
30+
31+
struct flb_network_verifier_instance;
32+
33+
struct flb_network_verifier_plugin {
34+
char *name; /* Name */
35+
char *description; /* Description */
36+
37+
/* Config map */
38+
struct flb_config_map *config_map;
39+
40+
/* Callbacks */
41+
int (*cb_init) (struct flb_network_verifier_instance *, struct flb_config *);
42+
int (*cb_verify_tls) (int, X509_STORE_CTX *);
43+
int (*cb_connection_failure) (struct flb_network_verifier_instance*, const char*, int, int, const char*);
44+
int (*cb_exit) (void *, struct flb_config *);
45+
46+
struct mk_list _head; /* Link to parent list (config->network_verifier_plugins) */
47+
};
48+
49+
/*
50+
* Each initialized plugin must have an instance, the same plugin may be
51+
* loaded more than one time.
52+
*
53+
* An instance will contain basic fixed plugin data while also
54+
* allowing for plugin context data, generated when the plugin is invoked.
55+
*/
56+
struct flb_network_verifier_instance {
57+
int id; /* instance id */
58+
int log_level; /* instance log level */
59+
char name[32]; /* numbered name */
60+
char *alias; /* alias name */
61+
void *context; /* Instance local context */
62+
struct flb_network_verifier_plugin *plugin; /* original plugin */
63+
64+
struct mk_list properties; /* config properties */
65+
struct mk_list *config_map; /* configuration map */
66+
67+
/* Keep a reference to the original context this instance belongs to */
68+
const struct flb_config *config;
69+
70+
struct mk_list _head; /* config->network_verifiers */
71+
};
72+
73+
struct flb_network_verifier_instance *flb_network_verifier_new(
74+
struct flb_config *config, const char *name);
75+
76+
const char *flb_network_verifier_get_alias(
77+
struct flb_network_verifier_instance *ins);
78+
79+
int flb_network_verifier_set_property(
80+
struct flb_network_verifier_instance *ins, const char *k, const char *v);
81+
int flb_network_verifier_plugin_property_check(
82+
struct flb_network_verifier_instance *ins,
83+
struct flb_config *config);
84+
int flb_network_verifier_init_all(struct flb_config *config);
85+
void flb_network_verifier_exit(struct flb_config *config);
86+
87+
void flb_network_verifier_instance_destroy(
88+
struct flb_network_verifier_instance *ins);
89+
90+
const struct flb_network_verifier_instance *find_network_verifier_instance(
91+
struct flb_config *config,
92+
const char* alias);
93+
94+
95+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2024 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef FLB_NETWORK_VERIFIER_PLUGIN_H
21+
#define FLB_NETWORK_VERIFIER_PLUGIN_H
22+
23+
#include <fluent-bit/flb_info.h>
24+
#include <fluent-bit/flb_network_verifier.h>
25+
#include <fluent-bit/flb_log.h>
26+
27+
#define flb_plg_log(ctx, level, fmt, ...) \
28+
if (flb_log_check_level(ctx->log_level, level)) \
29+
flb_log_print(level, NULL, 0, "[network_verifier:%s:%s] " fmt, \
30+
ctx->plugin->name, \
31+
flb_network_verifier_get_alias(ctx), ##__VA_ARGS__)
32+
33+
#define flb_plg_error(ctx, fmt, ...) \
34+
flb_plg_log(ctx, FLB_LOG_ERROR, fmt, ##__VA_ARGS__)
35+
36+
#define flb_plg_warn(ctx, fmt, ...) \
37+
flb_plg_log(ctx, FLB_LOG_WARN, fmt, ##__VA_ARGS__)
38+
39+
#define flb_plg_info(ctx, fmt, ...) \
40+
flb_plg_log(ctx, FLB_LOG_INFO, fmt, ##__VA_ARGS__)
41+
42+
#define flb_plg_debug(ctx, fmt, ...) \
43+
flb_plg_log(ctx, FLB_LOG_DEBUG, fmt, ##__VA_ARGS__)
44+
45+
#define flb_plg_trace(ctx, fmt, ...) \
46+
flb_plg_log(ctx, FLB_LOG_TRACE, fmt, ##__VA_ARGS__)
47+
#endif

include/fluent-bit/flb_output.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ struct flb_output_instance {
377377
char *tls_win_thumbprints; /* CertStore Thumbprints (Windows) */
378378
# endif
379379
#endif
380+
char* network_verifier; /* Connection Verifier alias */
381+
struct flb_network_verifier_instance* verifier_ins;
380382

381383
/*
382384
* network info:

include/fluent-bit/flb_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define FLB_PLUGIN_FILTER 2
2929
#define FLB_PLUGIN_OUTPUT 3
3030
#define FLB_PLUGIN_PROCESSOR 4
31+
#define FLB_PLUGIN_NETWORK_VERIFIER 5
3132

3233
/* Informational contexts for discovered dynamic plugins */
3334
struct flb_plugin {
@@ -42,6 +43,7 @@ struct flb_plugins {
4243
struct mk_list processor;
4344
struct mk_list filter;
4445
struct mk_list output;
46+
struct mk_list network_verifier;
4547
};
4648

4749
struct flb_plugins *flb_plugin_create();

include/fluent-bit/flb_plugins.h.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <fluent-bit/flb_input.h>
2626
#include <fluent-bit/flb_output.h>
2727
#include <fluent-bit/flb_filter.h>
28+
#include <fluent-bit/flb_network_verifier.h>
2829
#include <fluent-bit/flb_config.h>
2930
#include <fluent-bit/flb_log.h>
3031

@@ -34,6 +35,7 @@ extern struct flb_output_plugin *flb_zig_native_output_plugin_init(void *);
3435
@FLB_OUT_PLUGINS_DECL@
3536
@FLB_FILTER_PLUGINS_DECL@
3637
@FLB_PROCESSOR_PLUGINS_DECL@
38+
@FLB_NETWORK_VERIFIER_PLUGINS_DECL@
3739

3840
int flb_plugins_register(struct flb_config *config)
3941
{
@@ -42,12 +44,14 @@ int flb_plugins_register(struct flb_config *config)
4244
struct flb_output_plugin *out;
4345
struct flb_filter_plugin *filter;
4446
struct flb_processor_plugin *processor;
47+
struct flb_network_verifier_plugin *network_verifier;
4548

4649
@FLB_CUSTOM_PLUGINS_ADD@
4750
@FLB_IN_PLUGINS_ADD@
4851
@FLB_OUT_PLUGINS_ADD@
4952
@FLB_FILTER_PLUGINS_ADD@
5053
@FLB_PROCESSOR_PLUGINS_ADD@
54+
@FLB_NETWORK_VERIFIER_PLUGINS_ADD@
5155

5256
return 0;
5357
}
@@ -61,6 +65,7 @@ void flb_plugins_unregister(struct flb_config *config)
6165
struct flb_output_plugin *out;
6266
struct flb_filter_plugin *filter;
6367
struct flb_processor_plugin *processor;
68+
struct flb_network_verifier_plugin *network_verifier;
6469

6570
mk_list_foreach_safe(head, tmp, &config->custom_plugins) {
6671
custom = mk_list_entry(head, struct flb_custom_plugin, _head);
@@ -100,6 +105,12 @@ void flb_plugins_unregister(struct flb_config *config)
100105
mk_list_del(&processor->_head);
101106
flb_free(processor);
102107
}
108+
109+
mk_list_foreach_safe(head, tmp, &config->network_verifier_plugins) {
110+
network_verifier = mk_list_entry(head, struct flb_network_verifier_plugin, _head);
111+
mk_list_del(&network_verifier->_head);
112+
flb_free(network_verifier);
113+
}
103114
}
104115

105116
#endif

0 commit comments

Comments
 (0)