| 1 | /* |
| 2 | * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_EVENT_RULE_INTERNAL_H |
| 9 | #define LTTNG_EVENT_RULE_INTERNAL_H |
| 10 | |
| 11 | #include <common/credentials.hpp> |
| 12 | #include <common/macros.hpp> |
| 13 | #include <common/sessiond-comm/sessiond-comm.hpp> |
| 14 | |
| 15 | #include <lttng/domain.h> |
| 16 | #include <lttng/event-rule/event-rule.h> |
| 17 | #include <lttng/event.h> |
| 18 | #include <lttng/lttng-error.h> |
| 19 | |
| 20 | #include <stdbool.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <urcu/ref.h> |
| 24 | |
| 25 | struct lttng_payload; |
| 26 | struct lttng_payload_view; |
| 27 | struct mi_writer; |
| 28 | |
| 29 | enum lttng_event_rule_generate_exclusions_status { |
| 30 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK, |
| 31 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE, |
| 32 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR, |
| 33 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY, |
| 34 | }; |
| 35 | |
| 36 | using event_rule_destroy_cb = void (*)(struct lttng_event_rule *); |
| 37 | using event_rule_validate_cb = bool (*)(const struct lttng_event_rule *); |
| 38 | using event_rule_serialize_cb = int (*)(const struct lttng_event_rule *, struct lttng_payload *); |
| 39 | using event_rule_equal_cb = bool (*)(const struct lttng_event_rule *, |
| 40 | const struct lttng_event_rule *); |
| 41 | using event_rule_create_from_payload_cb = ssize_t (*)(struct lttng_payload_view *, |
| 42 | struct lttng_event_rule **); |
| 43 | using event_rule_generate_filter_bytecode_cb = |
| 44 | enum lttng_error_code (*)(struct lttng_event_rule *, const struct lttng_credentials *); |
| 45 | using event_rule_get_filter_cb = const char *(*) (const struct lttng_event_rule *); |
| 46 | using event_rule_get_filter_bytecode_cb = |
| 47 | const struct lttng_bytecode *(*) (const struct lttng_event_rule *); |
| 48 | using event_rule_generate_exclusions_cb = enum lttng_event_rule_generate_exclusions_status (*)( |
| 49 | const struct lttng_event_rule *, struct lttng_event_exclusion **); |
| 50 | using event_rule_hash_cb = unsigned long (*)(const struct lttng_event_rule *); |
| 51 | using event_rule_generate_lttng_event_cb = struct lttng_event *(*) (const struct lttng_event_rule *); |
| 52 | using event_rule_mi_serialize_cb = enum lttng_error_code (*)(const struct lttng_event_rule *, |
| 53 | struct mi_writer *); |
| 54 | |
| 55 | struct lttng_event_rule { |
| 56 | struct urcu_ref ref; |
| 57 | enum lttng_event_rule_type type; |
| 58 | event_rule_validate_cb validate; |
| 59 | event_rule_serialize_cb serialize; |
| 60 | event_rule_equal_cb equal; |
| 61 | event_rule_destroy_cb destroy; |
| 62 | event_rule_generate_filter_bytecode_cb generate_filter_bytecode; |
| 63 | event_rule_get_filter_cb get_filter; |
| 64 | event_rule_get_filter_bytecode_cb get_filter_bytecode; |
| 65 | event_rule_generate_exclusions_cb generate_exclusions; |
| 66 | event_rule_hash_cb hash; |
| 67 | event_rule_generate_lttng_event_cb generate_lttng_event; |
| 68 | event_rule_mi_serialize_cb mi_serialize; |
| 69 | }; |
| 70 | |
| 71 | struct lttng_event_rule_comm { |
| 72 | /* enum lttng_event_rule_type */ |
| 73 | int8_t event_rule_type; |
| 74 | char payload[]; |
| 75 | }; |
| 76 | |
| 77 | void lttng_event_rule_init(struct lttng_event_rule *event_rule, enum lttng_event_rule_type type); |
| 78 | |
| 79 | bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule); |
| 80 | |
| 81 | ssize_t lttng_event_rule_create_from_payload(struct lttng_payload_view *payload, |
| 82 | struct lttng_event_rule **event_rule); |
| 83 | |
| 84 | int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule, |
| 85 | struct lttng_payload *payload); |
| 86 | |
| 87 | bool lttng_event_rule_is_equal(const struct lttng_event_rule *a, const struct lttng_event_rule *b); |
| 88 | |
| 89 | bool lttng_event_rule_get(struct lttng_event_rule *rule); |
| 90 | |
| 91 | void lttng_event_rule_put(struct lttng_event_rule *rule); |
| 92 | |
| 93 | enum lttng_domain_type lttng_event_rule_get_domain_type(const struct lttng_event_rule *rule); |
| 94 | |
| 95 | enum lttng_error_code |
| 96 | lttng_event_rule_generate_filter_bytecode(struct lttng_event_rule *rule, |
| 97 | const struct lttng_credentials *creds); |
| 98 | |
| 99 | /* |
| 100 | * If not present/implemented returns NULL. |
| 101 | * Caller DOES NOT own the returned object. |
| 102 | */ |
| 103 | const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule); |
| 104 | |
| 105 | /* |
| 106 | * If not present/implemented returns NULL. |
| 107 | * Caller DOES NOT own the returned object. |
| 108 | */ |
| 109 | const struct lttng_bytecode * |
| 110 | lttng_event_rule_get_filter_bytecode(const struct lttng_event_rule *rule); |
| 111 | |
| 112 | /* |
| 113 | * If not present/implemented return NULL. |
| 114 | * Caller OWNS the returned object. |
| 115 | */ |
| 116 | enum lttng_event_rule_generate_exclusions_status |
| 117 | lttng_event_rule_generate_exclusions(const struct lttng_event_rule *rule, |
| 118 | struct lttng_event_exclusion **exclusions); |
| 119 | |
| 120 | const char *lttng_event_rule_type_str(enum lttng_event_rule_type type); |
| 121 | |
| 122 | unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule); |
| 123 | |
| 124 | /* |
| 125 | * This is a compatibility helper allowing us to generate a sessiond-side (not |
| 126 | * communication) `struct lttng_event` object from an event rule. |
| 127 | * |
| 128 | * This effectively bridges older parts of the code using those structures and |
| 129 | * new event-rule based code. |
| 130 | * |
| 131 | * The caller owns the returned object. |
| 132 | */ |
| 133 | struct lttng_event *lttng_event_rule_generate_lttng_event(const struct lttng_event_rule *rule); |
| 134 | |
| 135 | /* Test if an event rule targets an agent domain. */ |
| 136 | bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule); |
| 137 | |
| 138 | enum lttng_error_code lttng_event_rule_mi_serialize(const struct lttng_event_rule *rule, |
| 139 | struct mi_writer *writer); |
| 140 | |
| 141 | #endif /* LTTNG_EVENT_RULE_INTERNAL_H */ |