Lines Matching refs:env
91 dt_sample_rate_limited(struct dt_env* env) in dt_sample_rate_limited() argument
93 lock_basic_lock(&env->sample_lock); in dt_sample_rate_limited()
95 if(env->sample_rate > 1) { in dt_sample_rate_limited()
98 if (env->sample_rate_count > env->sample_rate) { in dt_sample_rate_limited()
103 env->sample_rate_count = 0; in dt_sample_rate_limited()
106 env->sample_rate_count++; in dt_sample_rate_limited()
107 lock_basic_unlock(&env->sample_lock); in dt_sample_rate_limited()
110 lock_basic_unlock(&env->sample_lock); in dt_sample_rate_limited()
115 dt_send(const struct dt_env *env, void *buf, size_t len_buf) in dt_send() argument
117 dt_msg_queue_submit(env->msgqueue, buf, len_buf); in dt_send()
121 dt_msg_init(const struct dt_env *env, in dt_msg_init() argument
131 if (env->identity != NULL) { in dt_msg_init()
132 dm->d.identity.data = (uint8_t *) env->identity; in dt_msg_init()
133 dm->d.identity.len = (size_t) env->len_identity; in dt_msg_init()
136 if (env->version != NULL) { in dt_msg_init()
137 dm->d.version.data = (uint8_t *) env->version; in dt_msg_init()
138 dm->d.version.len = (size_t) env->len_version; in dt_msg_init()
158 struct dt_env *env; in dt_create() local
171 env = (struct dt_env *) calloc(1, sizeof(struct dt_env)); in dt_create()
172 if (!env) in dt_create()
174 lock_basic_init(&env->sample_lock); in dt_create()
176 env->dtio = dt_io_thread_create(); in dt_create()
177 if(!env->dtio) { in dt_create()
179 free(env); in dt_create()
182 if(!dt_io_thread_apply_cfg(env->dtio, cfg)) { in dt_create()
183 dt_io_thread_delete(env->dtio); in dt_create()
184 free(env); in dt_create()
187 dt_apply_cfg(env, cfg); in dt_create()
188 return env; in dt_create()
192 dt_apply_identity(struct dt_env *env, struct config_file *cfg) in dt_apply_identity() argument
197 free(env->identity); in dt_apply_identity()
201 env->identity = strdup(buf); in dt_apply_identity()
206 env->identity = strdup(cfg->dnstap_identity); in dt_apply_identity()
208 if (env->identity == NULL) in dt_apply_identity()
210 env->len_identity = (unsigned int)strlen(env->identity); in dt_apply_identity()
212 env->identity); in dt_apply_identity()
216 dt_apply_version(struct dt_env *env, struct config_file *cfg) in dt_apply_version() argument
220 free(env->version); in dt_apply_version()
222 env->version = strdup(PACKAGE_STRING); in dt_apply_version()
224 env->version = strdup(cfg->dnstap_version); in dt_apply_version()
225 if (env->version == NULL) in dt_apply_version()
227 env->len_version = (unsigned int)strlen(env->version); in dt_apply_version()
229 env->version); in dt_apply_version()
233 dt_apply_cfg(struct dt_env *env, struct config_file *cfg) in dt_apply_cfg() argument
238 dt_apply_identity(env, cfg); in dt_apply_cfg()
239 dt_apply_version(env, cfg); in dt_apply_cfg()
240 if ((env->log_resolver_query_messages = (unsigned int) in dt_apply_cfg()
245 if ((env->log_resolver_response_messages = (unsigned int) in dt_apply_cfg()
250 if ((env->log_client_query_messages = (unsigned int) in dt_apply_cfg()
255 if ((env->log_client_response_messages = (unsigned int) in dt_apply_cfg()
260 if ((env->log_forwarder_query_messages = (unsigned int) in dt_apply_cfg()
265 if ((env->log_forwarder_response_messages = (unsigned int) in dt_apply_cfg()
270 lock_basic_lock(&env->sample_lock); in dt_apply_cfg()
271 if((env->sample_rate = (unsigned int)cfg->dnstap_sample_rate)) in dt_apply_cfg()
273 verbose(VERB_OPS, "dnstap SAMPLE_RATE enabled and set to \"%d\"", (int)env->sample_rate); in dt_apply_cfg()
275 lock_basic_unlock(&env->sample_lock); in dt_apply_cfg()
279 dt_init(struct dt_env *env, struct comm_base* base) in dt_init() argument
281 env->msgqueue = dt_msg_queue_create(base); in dt_init()
282 if(!env->msgqueue) { in dt_init()
286 if(!dt_io_thread_register_queue(env->dtio, env->msgqueue)) { in dt_init()
288 dt_msg_queue_delete(env->msgqueue); in dt_init()
289 env->msgqueue = NULL; in dt_init()
296 dt_deinit(struct dt_env* env) in dt_deinit() argument
298 dt_io_thread_unregister_queue(env->dtio, env->msgqueue); in dt_deinit()
299 dt_msg_queue_delete(env->msgqueue); in dt_deinit()
303 dt_delete(struct dt_env *env) in dt_delete() argument
305 if (!env) in dt_delete()
307 dt_io_thread_delete(env->dtio); in dt_delete()
308 lock_basic_destroy(&env->sample_lock); in dt_delete()
309 free(env->identity); in dt_delete()
310 free(env->version); in dt_delete()
311 free(env); in dt_delete()
434 dt_msg_send_client_query(struct dt_env *env, in dt_msg_send_client_query() argument
445 if(dt_sample_rate_limited(env)) in dt_msg_send_client_query()
453 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__CLIENT_QUERY); in dt_msg_send_client_query()
472 dt_send(env, dm.buf, dm.len_buf); in dt_msg_send_client_query()
476 dt_msg_send_client_response(struct dt_env *env, in dt_msg_send_client_response() argument
486 if(dt_sample_rate_limited(env)) in dt_msg_send_client_response()
492 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__CLIENT_RESPONSE); in dt_msg_send_client_response()
510 dt_send(env, dm.buf, dm.len_buf); in dt_msg_send_client_response()
514 dt_msg_send_outside_query(struct dt_env *env, in dt_msg_send_outside_query() argument
526 if(dt_sample_rate_limited(env)) in dt_msg_send_outside_query()
534 if (!env->log_forwarder_query_messages) in dt_msg_send_outside_query()
536 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__FORWARDER_QUERY); in dt_msg_send_outside_query()
538 if (!env->log_resolver_query_messages) in dt_msg_send_outside_query()
540 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__RESOLVER_QUERY); in dt_msg_send_outside_query()
564 dt_send(env, dm.buf, dm.len_buf); in dt_msg_send_outside_query()
568 dt_msg_send_outside_response(struct dt_env *env, in dt_msg_send_outside_response() argument
582 if(dt_sample_rate_limited(env)) in dt_msg_send_outside_response()
591 if (!env->log_forwarder_response_messages) in dt_msg_send_outside_response()
593 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__FORWARDER_RESPONSE); in dt_msg_send_outside_response()
595 if (!env->log_resolver_response_messages) in dt_msg_send_outside_response()
597 dt_msg_init(env, &dm, DNSTAP__MESSAGE__TYPE__RESOLVER_RESPONSE); in dt_msg_send_outside_response()
626 dt_send(env, dm.buf, dm.len_buf); in dt_msg_send_outside_response()