25#include <freeradius-devel/kafka/base.h>
26#include <freeradius-devel/server/tmpl.h>
27#include <freeradius-devel/util/size.h>
51 static _Thread_local
char buff[
sizeof(
"18446744073709551615")];
99 size_t size = vb.vb_size;
121 *
out = vb.vb_bool ?
"true" :
"false";
151 char tmp[
sizeof(
"18446744073709551615b")];
161 size_t mapping_len = *kctx->mapping_len;
197 if (kctx->size_scale) size *= kctx->size_scale;
248 if (*pconf) rd_kafka_conf_destroy(*pconf);
266 if (!kc)
return NULL;
270 MEM(kc->
conf = rd_kafka_conf_new());
277 MEM(s = talloc(ctx, rd_kafka_conf_t *));
307 fr_assert_msg(kc,
"kafka base struct missing - caller must embed fr_kafka_conf_t as first member");
323 if (
count <= 1)
goto do_single;
325 MEM(array = talloc_array(ctx,
char const *,
count));
326 for (cp_p = cp, i = 0;
335 if (slen < 0)
return -1;
347 value, errstr,
sizeof(errstr)) != RD_KAFKA_CONF_OK) {
370 size_t buff_len =
sizeof(
buff);
375 rd_kafka_conf_res_t ret;
378 fr_assert_msg(kc,
"kafka base struct missing during default generation");
380 if ((ret = rd_kafka_conf_get(kc->
conf, kctx->
property,
buff, &buff_len)) != RD_KAFKA_CONF_OK) {
381 if (ret == RD_KAFKA_CONF_UNKNOWN) {
412 .
name = __FUNCTION__,
431 fr_sbuff_set_to_start(&value_elem);
460 fr_assert_msg(kc,
"kafka base struct missing - caller must embed fr_kafka_conf_t as first member");
463 errstr,
sizeof(errstr)) != RD_KAFKA_CONF_OK) {
484 if (ktc->
rdtc) rd_kafka_topic_conf_destroy(ktc->
rdtc);
499 MEM(ktc->
rdtc = rd_kafka_topic_conf_new());
529 fr_assert_msg(ktc,
"kafka topic conf missing - topic parser invoked without subsection hook");
536 value, errstr,
sizeof(errstr)) != RD_KAFKA_CONF_OK) {
559 size_t buff_len =
sizeof(
buff);
564 rd_kafka_conf_res_t ret;
566 fr_assert_msg(ktc,
"kafka topic conf missing during default generation");
568 if ((ret = rd_kafka_topic_conf_get(ktc->
rdtc, kctx->
property,
buff, &buff_len)) != RD_KAFKA_CONF_OK) {
569 if (ret == RD_KAFKA_CONF_UNKNOWN) {
605 fr_assert_msg(ktc,
"kafka topic conf missing - raw parser invoked without subsection hook");
608 errstr,
sizeof(errstr)) != RD_KAFKA_CONF_OK) {
754 .uctx = &(
fr_kafka_conf_ctx_t){ .property =
"sasl.kerberos.kinit.keytab", .empty_default =
true }},
792 {
L(
"false"),
"none" },
794 {
L(
"true"),
"https" },
795 {
L(
"yes"),
"https" }
836 .uctx = &(
fr_kafka_conf_ctx_t){ .property =
"ssl.certificate.location", .empty_default =
true }},
998 .uctx = &(
fr_kafka_conf_ctx_t){ .property =
"topic.blacklist", .string_sep =
",", .empty_default =
true }},
1209 rd_kafka_conf_t *
conf;
1218 conf = rd_kafka_conf_new();
1221 rk = rd_kafka_new(RD_KAFKA_PRODUCER,
conf, errstr,
sizeof(errstr));
1226 rd_kafka_destroy(rk);
#define L(_str)
Helper for initialising arrays of string literals.
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
Parse a configuration section into user-supplied variables.
int cf_pair_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, CONF_PAIR *cp, conf_parser_t const *rule)
Parses a CONF_PAIR into a boxed value.
#define CONF_PARSER_TERMINATOR
void const * uctx
User data accessible by the cf_parse_t func.
#define FR_CONF_PAIR_GLOBAL(_name, _type, _flags, _func, _dflt_func)
conf_parser_t entry which doesn't fill in a pointer or offset, but relies on functions to record valu...
#define FR_CONF_SUBSECTION_GLOBAL(_name, _flags, _subcs)
conf_parser_t entry which runs conf_parser_t entries for a subsection without any output
fr_type_t type
An fr_type_t value, controls the output type.
#define fr_rule_multi(_rule)
char const * name1
Name of the CONF_ITEM to parse.
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
@ CONF_FLAG_SECRET
Only print value if debug level >= 3.
@ CONF_FLAG_FILE_READABLE
File matching value must exist, and must be readable.
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *attr)
Find a pair with a name matching attr, after specified pair.
unsigned int cf_pair_count(CONF_SECTION const *cs, char const *attr)
Count the number of times an attribute occurs in a parent section.
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_quote, fr_token_t rhs_quote)
Allocate a CONF_PAIR.
char const * cf_section_name1(CONF_SECTION const *cs)
Return the first identifier of a CONF_SECTION.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
#define cf_log_debug(_cf, _fmt,...)
#define cf_item_mark_parsed(_cf)
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
size_t size_scale
Divide/multiply FR_TYPE_SIZE by this amount.
CONF_SECTION * cs
topic's CONF_SECTION (for call_env lookups of per-topic pairs like value / key)
fr_rb_tree_t * topics
Declared topics, keyed by name.
rd_kafka_topic_conf_t * rdtc
char const * property
Kafka configuration property.
char const * name
as it appeared in config
fr_kafka_topic_conf_t * conf
parsed per-topic librdkafka conf
char const * string_sep
Used for multi-value configuration items.
bool empty_default
Don't produce messages saying the default is missing.
size_t * mapping_len
Length of the mapping tables.
fr_table_ptr_sorted_t * mapping
Mapping table between string constant.
uctx attached to each entry in KAFKA_BASE_PRODUCER_CONFIG
Declared topic record - one per topic { <name> { ... } } subsection.
void fr_kafka_free(void)
Drop one ref to librdkafka's global init.
conf_parser_t const kafka_connection_config[]
conf_parser_t const kafka_base_consumer_topics_config[]
static int kafka_topic_config_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_token_t quote, conf_parser_t const *rule)
Return the default value for a topic from the kafka client library.
conf_parser_t const kafka_base_topic_properties_config[]
Per-topic properties { ... } escape-hatch contents.
static size_t kafka_check_cert_cn_table_len
fr_kafka_topic_t * kafka_topic_conf_find(fr_kafka_conf_t const *kc, char const *name)
Look up a declared topic by name on an fr_kafka_conf_t
static uint32_t kafka_instance_count
int kafka_config_parse(TALLOC_CTX *ctx, UNUSED void *out, void *base, CONF_ITEM *ci, conf_parser_t const *rule)
Translate config items directly to settings in a kafka config struct.
conf_parser_t const kafka_base_consumer_topic_config[]
int kafka_config_raw_parse(TALLOC_CTX *ctx, UNUSED void *out, void *base, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Untyped passthrough: hand a CONF_PAIR's attr/value straight to rd_kafka_conf_set.
int kafka_config_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_token_t quote, conf_parser_t const *rule)
Return the default value from the kafka client library.
static fr_kafka_conf_t * kafka_conf_get(TALLOC_CTX *ctx, void *base)
Fetch the fr_kafka_conf_t currently being populated by the parser.
static int kafka_topic_config_parse(UNUSED TALLOC_CTX *ctx, UNUSED void *out, void *base, CONF_ITEM *ci, conf_parser_t const *rule)
Translate config items directly to settings in a kafka topic config struct.
int fr_kafka_init(void)
Drive librdkafka's lazy global init deterministically.
int kafka_topic_config_raw_parse(UNUSED TALLOC_CTX *ctx, UNUSED void *out, void *base, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Topic-level counterpart to kafka_config_raw_parse
conf_parser_t const kafka_base_properties_config[]
properties { ... } escape-hatch contents
static int _kafka_topic_conf_free(fr_kafka_topic_conf_t *ktc)
Destructor on a per-topic conf - releases the librdkafka handle.
static conf_parser_t const kafka_sasl_oauth_config[]
static fr_table_ptr_sorted_t kafka_check_cert_cn_table[]
conf_parser_t const kafka_version_config[]
int kafka_topic_subsection_parse(TALLOC_CTX *ctx, void *out, void *base, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Per-topic subsection hook.
static int kafka_noop_parse(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *base, UNUSED CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
No-op parser used to reserve CONF_PAIR names inside a topic subsection that the module reads separate...
conf_parser_t const kafka_consumer_group_config[]
conf_parser_t const kafka_tls_config[]
conf_parser_t const kafka_base_producer_topics_config[]
static fr_kafka_topic_conf_t * kafka_topic_conf_alloc(TALLOC_CTX *ctx)
Allocate a per-topic conf parented under ctx
static int _kafka_conf_free(rd_kafka_conf_t **pconf)
Destructor on the talloc sentinel that owns the rd_kafka_conf_t handle.
static void _kafka_null_log_cb(UNUSED rd_kafka_t const *rk, UNUSED int level, UNUSED char const *fac, UNUSED char const *buf)
conf_parser_t const kafka_metadata_config[]
static conf_parser_t const kafka_sasl_kerberos_config[]
static conf_parser_t const kafka_base_producer_topic_config[]
static int kafka_config_parse_single(char const **out, CONF_PAIR *cp, conf_parser_t const *rule)
Common parse path for a single CONF_PAIR's value.
static int kafka_config_dflt_single(CONF_PAIR **out, UNUSED void *parent, CONF_SECTION *cs, char const *value, fr_token_t quote, conf_parser_t const *rule)
Common dflt path: take a librdkafka-native value string and materialise it as a CONF_PAIR in the call...
static int8_t _kafka_topic_cmp(void const *one, void const *two)
Order-by-name comparator for the fr_kafka_conf_t.topics tree.
conf_parser_t const kafka_sasl_config[]
size_t fr_sbuff_out_unescape_until(fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
#define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black that verifies elements are of a specific talloc type.
fr_slen_t fr_sbuff_array_concat(fr_sbuff_t *out, char const *const *array, char const *sep)
Concat an array of strings (not NULL terminated), with a string separator.
ssize_t fr_sbuff_in_sprintf(fr_sbuff_t *sbuff, char const *fmt,...)
Print using a fmt string to an sbuff.
#define fr_sbuff_start(_sbuff_or_marker)
#define FR_SBUFF_IN(_start, _len_or_end)
char const * str
Terminal string.
char const * name
Name for rule set to aid we debugging.
size_t len
Length of the list.
#define FR_SBUFF_IN_STR(_start)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define FR_SBUFF_OUT(_start, _len_or_end)
char subs[SBUFF_CHAR_CLASS]
Special characters and their substitutions.
#define FR_SBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
Terminal element with pre-calculated lengths.
Set of terminal elements.
Set of parsing rules for *unescape_until functions.
fr_slen_t fr_size_from_str(size_t *out, fr_sbuff_t *in)
Parse a size string with optional unit.
fr_slen_t fr_size_to_str(fr_sbuff_t *out, size_t in)
Print a size string with unit.
static char buff[sizeof("18446744073709551615")+3]
fr_aka_sim_id_type_t type
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
#define fr_table_str_by_str_value(_table, _str_value, _def)
Brute force search a sorted or ordered ptr table, assuming the pointers are strings.
An element in a lexicographically sorted array of name to ptr mappings.
#define talloc_strdup(_ctx, _str)
fr_slen_t fr_time_delta_from_str(fr_time_delta_t *out, char const *in, size_t inlen, fr_time_res_t hint)
Create fr_time_delta_t from a string.
fr_slen_t fr_time_delta_to_str(fr_sbuff_t *out, fr_time_delta_t delta, fr_time_res_t res, bool is_unsigned)
Print fr_time_delta_t to a string with an appropriate suffix.
static int64_t fr_time_delta_to_msec(fr_time_delta_t delta)
A time delta, a difference in time measured in nanoseconds.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_type_is_string(_x)
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
#define FR_VALUE_BOX_INITIALISER_NULL(_vb)
A static initialiser for stack/globally allocated boxes.
static size_t char ** out