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