aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/lttng_circuit.inc
blob: fc3e175c8a318e146d26a8629f284378c5e8a8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/* Copyright (c) 2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * \file lttng_circuit.inc
 * \brief LTTng tracing probe declaration for the circuit subsystem. It is in
*         this .inc file due to the non C standard syntax and the way we guard
*         the header with the LTTng specific TRACEPOINT_HEADER_MULTI_READ.
 **/

#include "orconfig.h"

/* We only build the following if LTTng instrumentation has been enabled. */
#ifdef USE_TRACING_INSTRUMENTATION_LTTNG

/* The following defines are LTTng-UST specific. */
#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER tor_circuit

#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "./src/core/or/lttng_circuit.inc"

#if !defined(LTTNG_CIRCUIT_INC) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define LTTNG_CIRCUIT_INC

#include <lttng/tracepoint.h>

/*
 * Circuit Purposes
 *
 * The following defines an enumeration of all possible circuit purpose so
 * they appear in the trace with the define name (first parameter of
 * ctf_enum_value) instead of the numerical value.
 */
TRACEPOINT_ENUM(tor_circuit, purpose,
  TP_ENUM_VALUES(
    /* Initializing. */
    ctf_enum_value("<UNSET>", 0)

    /* OR Side. */
    ctf_enum_value("OR", CIRCUIT_PURPOSE_OR)
    ctf_enum_value("OR_INTRO_POINT", CIRCUIT_PURPOSE_INTRO_POINT)
    ctf_enum_value("OR_REND_POINT_WAITING",
                   CIRCUIT_PURPOSE_REND_POINT_WAITING)
    ctf_enum_value("OR_REND_ESTABLISHED", CIRCUIT_PURPOSE_REND_ESTABLISHED)

    /* Client Side. */
    ctf_enum_value("C_GENERAL", CIRCUIT_PURPOSE_C_GENERAL)
    ctf_enum_value("C_INTRODUCING", CIRCUIT_PURPOSE_C_INTRODUCING)
    ctf_enum_value("C_INTRODUCE_ACK_WAIT",
                   CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT)
    ctf_enum_value("C_INTRODUCE_ACKED", CIRCUIT_PURPOSE_C_INTRODUCE_ACKED)
    ctf_enum_value("C_ESTABLISH_REND", CIRCUIT_PURPOSE_C_ESTABLISH_REND)
    ctf_enum_value("C_REND_READY", CIRCUIT_PURPOSE_C_REND_READY)
    ctf_enum_value("C_REND_READY_INTRO_ACKED",
                   CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED)
    ctf_enum_value("C_REND_JOINED", CIRCUIT_PURPOSE_C_REND_JOINED)
    ctf_enum_value("C_HSDIR_GET", CIRCUIT_PURPOSE_C_HSDIR_GET)

    /* CBT and Padding. */
    ctf_enum_value("C_MEASURE_TIMEOUT", CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT)
    ctf_enum_value("C_CIRCUIT_PADDING", CIRCUIT_PURPOSE_C_CIRCUIT_PADDING)

    /* Service Side. */
    ctf_enum_value("S_ESTABLISH_INTRO", CIRCUIT_PURPOSE_S_ESTABLISH_INTRO)
    ctf_enum_value("S_INTRO", CIRCUIT_PURPOSE_S_INTRO)
    ctf_enum_value("S_CONNECT_REND", CIRCUIT_PURPOSE_S_CONNECT_REND)
    ctf_enum_value("S_REND_JOINED", CIRCUIT_PURPOSE_S_REND_JOINED)
    ctf_enum_value("S_HSDIR_POST", CIRCUIT_PURPOSE_S_HSDIR_POST)

    /* Misc. */
    ctf_enum_value("TESTING", CIRCUIT_PURPOSE_TESTING)
    ctf_enum_value("CONTROLER", CIRCUIT_PURPOSE_CONTROLLER)
    ctf_enum_value("PATH_BIAS_TESTING", CIRCUIT_PURPOSE_PATH_BIAS_TESTING)

    /* VanGuard */
    ctf_enum_value("HS_VANGUARDS", CIRCUIT_PURPOSE_HS_VANGUARDS)
  )
)

/*
 * Circuit End Reasons
 *
 * The following defines an enumeration of all possible circuit end reasons so
 * they appear in the trace with the define name (first parameter of
 * ctf_enum_value) instead of the numerical value.
 */
TRACEPOINT_ENUM(tor_circuit, end_reason,
  TP_ENUM_VALUES(
    /* Local reasons. */
    ctf_enum_value("IP_NOW_REDUNDANT", END_CIRC_REASON_IP_NOW_REDUNDANT)
    ctf_enum_value("MEASUREMENT_EXPIRED", END_CIRC_REASON_MEASUREMENT_EXPIRED)
    ctf_enum_value("REASON_NOPATH", END_CIRC_REASON_NOPATH)
    ctf_enum_value("AT_ORIGIN", END_CIRC_AT_ORIGIN)
    ctf_enum_value("NONE", END_CIRC_REASON_NONE)
    ctf_enum_value("TORPROTOCOL", END_CIRC_REASON_TORPROTOCOL)
    ctf_enum_value("INTERNAL", END_CIRC_REASON_INTERNAL)
    ctf_enum_value("REQUESTED", END_CIRC_REASON_REQUESTED)
    ctf_enum_value("HIBERNATING", END_CIRC_REASON_HIBERNATING)
    ctf_enum_value("RESOURCELIMIT", END_CIRC_REASON_RESOURCELIMIT)
    ctf_enum_value("CONNECTFAILED", END_CIRC_REASON_CONNECTFAILED)
    ctf_enum_value("OR_IDENTITY", END_CIRC_REASON_OR_IDENTITY)
    ctf_enum_value("CHANNEL_CLOSED", END_CIRC_REASON_CHANNEL_CLOSED)
    ctf_enum_value("FINISHED", END_CIRC_REASON_FINISHED)
    ctf_enum_value("TIMEOUT", END_CIRC_REASON_TIMEOUT)
    ctf_enum_value("DESTROYED", END_CIRC_REASON_DESTROYED)
    ctf_enum_value("NOSUCHSERVICE", END_CIRC_REASON_NOSUCHSERVICE)

    /* Remote reasons. */
    ctf_enum_value("FLAG_REMOTE", END_CIRC_REASON_FLAG_REMOTE)
    ctf_enum_value("REMOTE_TORPROTOCOL",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_TORPROTOCOL)
    ctf_enum_value("REMOTE_INTERNAL",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_INTERNAL)
    ctf_enum_value("REMOTE_REQUESTED",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_REQUESTED)
    ctf_enum_value("REMOTE_HIBERNATING",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_HIBERNATING)
    ctf_enum_value("REMOTE_RESOURCELIMIT",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_RESOURCELIMIT)
    ctf_enum_value("REMOTE_CONNECTFAILED",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_CONNECTFAILED)
    ctf_enum_value("REMOTE_OR_IDENTITY",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_OR_IDENTITY)
    ctf_enum_value("REMOTE_CHANNEL_CLOSED",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_CHANNEL_CLOSED)
    ctf_enum_value("REMOTE_FINISHED",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_FINISHED)
    ctf_enum_value("REMOTE_TIMEOUT",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_TIMEOUT)
    ctf_enum_value("REMOTE_DESTROYED",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_DESTROYED)
    ctf_enum_value("REMOTE_NOSUCHSERVICE",
             END_CIRC_REASON_FLAG_REMOTE | END_CIRC_REASON_NOSUCHSERVICE)
  )
)

/*
 * Circuit State
 *
 * The following defines an enumeration of all possible circuit state so they
 * appear in the trace with the define name (first parameter of
 * ctf_enum_value) instead of the numerical value.
 */
TRACEPOINT_ENUM(tor_circuit, state,
  TP_ENUM_VALUES(
    ctf_enum_value("BUILDING", CIRCUIT_STATE_BUILDING)
    ctf_enum_value("ONIONSKIN_PENDING", CIRCUIT_STATE_ONIONSKIN_PENDING)
    ctf_enum_value("CHAN_WAIT", CIRCUIT_STATE_CHAN_WAIT)
    ctf_enum_value("GUARD_WAIT", CIRCUIT_STATE_GUARD_WAIT)
    ctf_enum_value("OPEN", CIRCUIT_STATE_OPEN)
  )
)

/*
 * Event Class
 *
 * A tracepoint class is a class of tracepoints which share the same output
 * event field definitions. They are then used by the
 * TRACEPOINT_EVENT_INSTANCE() macro as a base field definition.
 */

/* Class for origin circuit. */
TRACEPOINT_EVENT_CLASS(tor_circuit, origin_circuit_t_class,
  TP_ARGS(const origin_circuit_t *, circ),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id, circ->global_identifier)
    ctf_enum(tor_circuit, purpose, int, purpose, TO_CIRCUIT(circ)->purpose)
    ctf_enum(tor_circuit, state, int, state, TO_CIRCUIT(circ)->state)
  )
)

/* Class for or circuit. */
TRACEPOINT_EVENT_CLASS(tor_circuit, or_circuit_t_class,
  TP_ARGS(const or_circuit_t *, circ),
  TP_FIELDS(
    ctf_enum(tor_circuit, purpose, int, purpose, TO_CIRCUIT(circ)->purpose)
    ctf_enum(tor_circuit, state, int, state, TO_CIRCUIT(circ)->state)
  )
)

/*
 * Origin circuit events.
 *
 * Tracepoint use the origin_circuit_t object.
 */

/* Tracepoint emitted when a new origin circuit has been created. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, new_origin,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit has opened. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, opened,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit has established. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, establish,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit has been cannibalized. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, cannibalized,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit has timed out. This is called
 * when circuit_expire_building() as selected the circuit and is about to
 * close it for timeout. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, timeout,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit has timed out due to idleness.
 * This is when the circuit is closed after MaxCircuitDirtiness. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, origin_circuit_t_class, idle_timeout,
  TP_ARGS(const origin_circuit_t *, circ)
)

/* Tracepoint emitted when an origin circuit sends out its first onion skin. */
TRACEPOINT_EVENT(tor_circuit, first_onion_skin,
  TP_ARGS(const origin_circuit_t *, circ, const crypt_path_t *, hop),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id, circ->global_identifier)
    ctf_enum(tor_circuit, purpose, int, purpose, TO_CIRCUIT(circ)->purpose)
    ctf_enum(tor_circuit, state, int, state, TO_CIRCUIT(circ)->state)
    ctf_array_hex(char, fingerprint, hop->extend_info->identity_digest,
                  DIGEST_LEN)
  )
)

/* Tracepoint emitted when an origin circuit sends out an intermediate onion
 * skin. */
TRACEPOINT_EVENT(tor_circuit, intermediate_onion_skin,
  TP_ARGS(const origin_circuit_t *, circ, const crypt_path_t *, hop),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id, circ->global_identifier)
    ctf_enum(tor_circuit, purpose, int, purpose, TO_CIRCUIT(circ)->purpose)
    ctf_enum(tor_circuit, state, int, state, TO_CIRCUIT(circ)->state)
    ctf_array_hex(char, fingerprint, hop->extend_info->identity_digest,
                  DIGEST_LEN)
  )
)

/*
 * OR circuit events.
 *
 * Tracepoint use the or_circuit_t object.
 */

/* Tracepoint emitted when a new or circuit has been created. */
TRACEPOINT_EVENT_INSTANCE(tor_circuit, or_circuit_t_class, new_or,
  TP_ARGS(const or_circuit_t *, circ)
)

/*
 * General circuit events.
 *
 * Tracepoint use the circuit_t object.
 */

/* Tracepoint emitted when a circuit is freed. */
TRACEPOINT_EVENT(tor_circuit, free,
  TP_ARGS(const circuit_t *, circ),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id,
                (CIRCUIT_IS_ORIGIN(circ) ?
                 TO_ORIGIN_CIRCUIT(circ)->global_identifier : 0))
    ctf_enum(tor_circuit, purpose, int, purpose, circ->purpose)
    ctf_enum(tor_circuit, state, int, state, circ->state)
  )
)

/* Tracepoint emitted when a circuit is marked for close. */
TRACEPOINT_EVENT(tor_circuit, mark_for_close,
  TP_ARGS(const circuit_t *, circ),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id,
                (CIRCUIT_IS_ORIGIN(circ) ?
                 TO_ORIGIN_CIRCUIT(circ)->global_identifier : 0))
    ctf_enum(tor_circuit, purpose, int, purpose, circ->purpose)
    ctf_enum(tor_circuit, state, int, state, circ->state)
    ctf_enum(tor_circuit, end_reason, int, close_reason,
             circ->marked_for_close_reason)
    ctf_enum(tor_circuit, end_reason, int, orig_close_reason,
             circ->marked_for_close_orig_reason)
  )
)

/* Tracepoint emitted when a circuit changes purpose. */
TRACEPOINT_EVENT(tor_circuit, change_purpose,
  TP_ARGS(const circuit_t *, circ, int, old_purpose, int, new_purpose),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id,
                (CIRCUIT_IS_ORIGIN(circ) ?
                 TO_ORIGIN_CIRCUIT(circ)->global_identifier : 0))
    ctf_enum(tor_circuit, state, int, state, circ->state)
    ctf_enum(tor_circuit, purpose, int, purpose, old_purpose)
    ctf_enum(tor_circuit, purpose, int, new, new_purpose)
  )
)

/* Tracepoint emitted when a circuit changes state. */
TRACEPOINT_EVENT(tor_circuit, change_state,
  TP_ARGS(const circuit_t *, circ, int, old_state, int, new_state),
  TP_FIELDS(
    ctf_integer(uint32_t, circ_id,
                (CIRCUIT_IS_ORIGIN(circ) ?
                 TO_ORIGIN_CIRCUIT(circ)->global_identifier : 0))
    ctf_enum(tor_circuit, purpose, int, purpose, circ->purpose)
    ctf_enum(tor_circuit, state, int, old, old_state)
    ctf_enum(tor_circuit, state, int, new, new_state)
  )
)

#endif /* LTTNG_CIRCUIT_INC || TRACEPOINT_HEADER_MULTI_READ */

/* Must be included after the probes declaration. */
#include <lttng/tracepoint-event.h>

#endif /* USE_TRACING_INSTRUMENTATION_LTTNG */