/src/opensips/route_trace.h
Line | Count | Source |
1 | | /* |
2 | | * Route tracing hooks for external instrumentation |
3 | | * |
4 | | * Copyright (C) 2026 OpenSIPS Project |
5 | | * |
6 | | * opensips is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * opensips is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef ROUTE_TRACE_H |
23 | | #define ROUTE_TRACE_H |
24 | | |
25 | | #include <stddef.h> |
26 | | #include <stdint.h> |
27 | | |
28 | | struct sip_msg; |
29 | | |
30 | | typedef struct route_trace_ctx { |
31 | | uint8_t trace_id[16]; |
32 | | uint8_t span_id[8]; |
33 | | uint8_t trace_flags; |
34 | | uint64_t start_system_ns; |
35 | | uint64_t start_steady_ns; |
36 | | uint8_t has_start_time; |
37 | | } route_trace_ctx_t; |
38 | | |
39 | | typedef struct route_trace_handlers { |
40 | | void (*on_msg_start)(struct sip_msg *msg, int route_type, |
41 | | const char *route_name, int stack_size, int stack_start); |
42 | | void (*on_msg_end)(struct sip_msg *msg, int route_type, |
43 | | const char *route_name, int stack_size, int stack_start, int status); |
44 | | void (*on_route_enter)(struct sip_msg *msg, int route_type, |
45 | | const char *route_name, const char *file, int line, |
46 | | int stack_size, int stack_start); |
47 | | void (*on_route_exit)(struct sip_msg *msg, int route_type, |
48 | | const char *route_name, const char *file, int line, |
49 | | int stack_size, int stack_start, int status); |
50 | | int (*get_ctx)(route_trace_ctx_t *ctx); |
51 | | int (*set_ctx)(const route_trace_ctx_t *ctx); |
52 | | } route_trace_handlers_t; |
53 | | |
54 | | extern route_trace_handlers_t *route_trace_handlers; |
55 | | |
56 | | int register_route_tracer(route_trace_handlers_t *handlers); |
57 | | void unregister_route_tracer(route_trace_handlers_t *handlers); |
58 | | |
59 | | static inline int route_trace_enabled(void) |
60 | 0 | { |
61 | 0 | return route_trace_handlers != NULL; |
62 | 0 | } Unexecuted instantiation: action.c:route_trace_enabled Unexecuted instantiation: route_trace.c:route_trace_enabled |
63 | | |
64 | | static inline void route_trace_msg_start(struct sip_msg *msg, int route_type, |
65 | | const char *route_name, int stack_size, int stack_start) |
66 | 0 | { |
67 | 0 | if (route_trace_handlers && route_trace_handlers->on_msg_start) |
68 | 0 | route_trace_handlers->on_msg_start(msg, route_type, route_name, |
69 | 0 | stack_size, stack_start); |
70 | 0 | } Unexecuted instantiation: action.c:route_trace_msg_start Unexecuted instantiation: route_trace.c:route_trace_msg_start |
71 | | |
72 | | static inline void route_trace_msg_end(struct sip_msg *msg, int route_type, |
73 | | const char *route_name, int stack_size, int stack_start, int status) |
74 | 0 | { |
75 | 0 | if (route_trace_handlers && route_trace_handlers->on_msg_end) |
76 | 0 | route_trace_handlers->on_msg_end(msg, route_type, route_name, |
77 | 0 | stack_size, stack_start, status); |
78 | 0 | } Unexecuted instantiation: action.c:route_trace_msg_end Unexecuted instantiation: route_trace.c:route_trace_msg_end |
79 | | |
80 | | static inline void route_trace_route_enter(struct sip_msg *msg, int route_type, |
81 | | const char *route_name, const char *file, int line, |
82 | | int stack_size, int stack_start) |
83 | 0 | { |
84 | 0 | if (route_trace_handlers && route_trace_handlers->on_route_enter) |
85 | 0 | route_trace_handlers->on_route_enter(msg, route_type, route_name, |
86 | 0 | file, line, stack_size, stack_start); |
87 | 0 | } Unexecuted instantiation: action.c:route_trace_route_enter Unexecuted instantiation: route_trace.c:route_trace_route_enter |
88 | | |
89 | | static inline void route_trace_route_exit(struct sip_msg *msg, int route_type, |
90 | | const char *route_name, const char *file, int line, |
91 | | int stack_size, int stack_start, int status) |
92 | 0 | { |
93 | 0 | if (route_trace_handlers && route_trace_handlers->on_route_exit) |
94 | 0 | route_trace_handlers->on_route_exit(msg, route_type, route_name, |
95 | 0 | file, line, stack_size, stack_start, status); |
96 | 0 | } Unexecuted instantiation: action.c:route_trace_route_exit Unexecuted instantiation: route_trace.c:route_trace_route_exit |
97 | | |
98 | | static inline int route_trace_get_ctx(route_trace_ctx_t *ctx) |
99 | 0 | { |
100 | 0 | if (route_trace_handlers && route_trace_handlers->get_ctx) |
101 | 0 | return route_trace_handlers->get_ctx(ctx); |
102 | 0 | return 0; |
103 | 0 | } Unexecuted instantiation: action.c:route_trace_get_ctx Unexecuted instantiation: route_trace.c:route_trace_get_ctx |
104 | | |
105 | | static inline int route_trace_set_ctx(const route_trace_ctx_t *ctx) |
106 | 0 | { |
107 | 0 | if (route_trace_handlers && route_trace_handlers->set_ctx) |
108 | 0 | return route_trace_handlers->set_ctx(ctx); |
109 | 0 | return 0; |
110 | 0 | } Unexecuted instantiation: action.c:route_trace_set_ctx Unexecuted instantiation: route_trace.c:route_trace_set_ctx |
111 | | |
112 | | #endif /* ROUTE_TRACE_H */ |