| 1 | /* |
| 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_TRIGGER_INTERNAL_H |
| 9 | #define LTTNG_TRIGGER_INTERNAL_H |
| 10 | |
| 11 | #include <lttng/trigger/trigger.h> |
| 12 | #include <common/macros.h> |
| 13 | #include <common/buffer-view.h> |
| 14 | #include <common/dynamic-buffer.h> |
| 15 | #include <common/dynamic-array.h> |
| 16 | #include <common/credentials.h> |
| 17 | #include <stdint.h> |
| 18 | #include <stdbool.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <urcu/ref.h> |
| 21 | |
| 22 | struct lttng_trigger { |
| 23 | struct urcu_ref ref; /* internal use only */ |
| 24 | bool owns_internal_objects; /* internal use only */ |
| 25 | |
| 26 | struct lttng_condition *condition; |
| 27 | struct lttng_action *action; |
| 28 | char *name; |
| 29 | struct { /* Internal use only */ |
| 30 | bool set; |
| 31 | uint64_t value; |
| 32 | } key; |
| 33 | struct { /* internal use only */ |
| 34 | struct lttng_credentials credentials; |
| 35 | bool set; |
| 36 | } creds; |
| 37 | struct { |
| 38 | enum lttng_trigger_firing_policy_type type; |
| 39 | uint64_t threshold; |
| 40 | uint64_t current_count; |
| 41 | } firing_policy; |
| 42 | }; |
| 43 | |
| 44 | struct lttng_triggers { |
| 45 | struct lttng_dynamic_pointer_array array; |
| 46 | }; |
| 47 | |
| 48 | struct lttng_trigger_comm { |
| 49 | /* length excludes its own length. */ |
| 50 | uint32_t name_length /* Includes '\0' */; |
| 51 | uint32_t length; |
| 52 | uint8_t policy_type; |
| 53 | uint64_t policy_threshold; |
| 54 | /* A name, condition and action object follow. */ |
| 55 | char payload[]; |
| 56 | } LTTNG_PACKED; |
| 57 | |
| 58 | struct lttng_triggers_comm { |
| 59 | uint32_t count; |
| 60 | uint32_t length; |
| 61 | /* Count * lttng_trigger_comm structure */ |
| 62 | char payload[]; |
| 63 | }; |
| 64 | |
| 65 | LTTNG_HIDDEN |
| 66 | ssize_t lttng_trigger_create_from_buffer(const struct lttng_buffer_view *view, |
| 67 | struct lttng_trigger **trigger); |
| 68 | |
| 69 | LTTNG_HIDDEN |
| 70 | int lttng_trigger_serialize(const struct lttng_trigger *trigger, |
| 71 | struct lttng_dynamic_buffer *buf, |
| 72 | int *fd_to_send); |
| 73 | |
| 74 | LTTNG_HIDDEN |
| 75 | bool lttng_trigger_validate(const struct lttng_trigger *trigger); |
| 76 | |
| 77 | LTTNG_HIDDEN |
| 78 | int lttng_trigger_assign(struct lttng_trigger *dst, |
| 79 | const struct lttng_trigger *src); |
| 80 | |
| 81 | LTTNG_HIDDEN |
| 82 | bool lttng_trigger_is_equal(const struct lttng_trigger *a, |
| 83 | const struct lttng_trigger *b); |
| 84 | |
| 85 | LTTNG_HIDDEN |
| 86 | void lttng_trigger_set_key(struct lttng_trigger *trigger, uint64_t key); |
| 87 | |
| 88 | LTTNG_HIDDEN |
| 89 | uint64_t lttng_trigger_get_key(const struct lttng_trigger *trigger); |
| 90 | |
| 91 | LTTNG_HIDDEN |
| 92 | int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t offset); |
| 93 | |
| 94 | /* |
| 95 | * Allocate a new list of lttng_trigger. |
| 96 | * The returned object must be freed via lttng_triggers_destroy. |
| 97 | */ |
| 98 | LTTNG_HIDDEN |
| 99 | struct lttng_triggers *lttng_triggers_create(void); |
| 100 | |
| 101 | /* |
| 102 | * Return the non-const pointer of an element at index "index" of a |
| 103 | * lttng_triggers. |
| 104 | * |
| 105 | * The ownership of the lttng_triggers element is NOT transfered. |
| 106 | * The returned object can NOT be freed via lttng_trigger_destroy. |
| 107 | */ |
| 108 | LTTNG_HIDDEN |
| 109 | struct lttng_trigger *lttng_triggers_get_pointer_of_index( |
| 110 | const struct lttng_triggers *triggers, unsigned int index); |
| 111 | |
| 112 | /* |
| 113 | * TODO: |
| 114 | */ |
| 115 | LTTNG_HIDDEN |
| 116 | int lttng_triggers_add( |
| 117 | struct lttng_triggers *triggers, struct lttng_trigger *trigger); |
| 118 | |
| 119 | /* |
| 120 | * Serialize a trigger collection to a lttng_dynamic_buffer. |
| 121 | * Return LTTNG_OK on success, negative lttng error code on error. |
| 122 | */ |
| 123 | LTTNG_HIDDEN |
| 124 | int lttng_triggers_serialize(const struct lttng_triggers *triggers, |
| 125 | struct lttng_dynamic_buffer *buffer); |
| 126 | |
| 127 | LTTNG_HIDDEN |
| 128 | ssize_t lttng_triggers_create_from_buffer(const struct lttng_buffer_view *view, |
| 129 | struct lttng_triggers **triggers); |
| 130 | |
| 131 | LTTNG_HIDDEN |
| 132 | const struct lttng_credentials *lttng_trigger_get_credentials( |
| 133 | const struct lttng_trigger *trigger); |
| 134 | |
| 135 | LTTNG_HIDDEN |
| 136 | void lttng_trigger_set_credentials( |
| 137 | struct lttng_trigger *trigger, uid_t uid, gid_t git); |
| 138 | |
| 139 | LTTNG_HIDDEN |
| 140 | void lttng_trigger_get(struct lttng_trigger *trigger); |
| 141 | |
| 142 | LTTNG_HIDDEN |
| 143 | void lttng_trigger_put(struct lttng_trigger *trigger); |
| 144 | |
| 145 | LTTNG_HIDDEN |
| 146 | bool lttng_trigger_is_ready_to_fire( |
| 147 | struct lttng_trigger *trigger); |
| 148 | |
| 149 | /* |
| 150 | * Return the type of any uderlying domain requirement. If no particular |
| 151 | * requirement is needed return LTTNG_DOMAIN_NONE. |
| 152 | */ |
| 153 | LTTNG_HIDDEN |
| 154 | enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( |
| 155 | const struct lttng_trigger *trigger); |
| 156 | |
| 157 | #endif /* LTTNG_TRIGGER_INTERNAL_H */ |