/src/samba/third_party/ngtcp2/lib/ngtcp2_log.h
Line | Count | Source |
1 | | /* |
2 | | * ngtcp2 |
3 | | * |
4 | | * Copyright (c) 2018 ngtcp2 contributors |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person obtaining |
7 | | * a copy of this software and associated documentation files (the |
8 | | * "Software"), to deal in the Software without restriction, including |
9 | | * without limitation the rights to use, copy, modify, merge, publish, |
10 | | * distribute, sublicense, and/or sell copies of the Software, and to |
11 | | * permit persons to whom the Software is furnished to do so, subject to |
12 | | * the following conditions: |
13 | | * |
14 | | * The above copyright notice and this permission notice shall be |
15 | | * included in all copies or substantial portions of the Software. |
16 | | * |
17 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18 | | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19 | | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
20 | | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
21 | | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
22 | | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
23 | | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 | | */ |
25 | | #ifndef NGTCP2_LOG_H |
26 | | #define NGTCP2_LOG_H |
27 | | |
28 | | #ifdef HAVE_CONFIG_H |
29 | | # include <config.h> |
30 | | #endif /* defined(HAVE_CONFIG_H) */ |
31 | | |
32 | | #include <ngtcp2/ngtcp2.h> |
33 | | |
34 | | #include "ngtcp2_pkt.h" |
35 | | |
36 | | typedef struct ngtcp2_log { |
37 | | /* log_printf is a sink to write log. NULL means no logging |
38 | | output. */ |
39 | | ngtcp2_printf log_printf; |
40 | | /* events is an event filter. Only events set in this field are |
41 | | emitted. */ |
42 | | uint8_t events; |
43 | | /* ts is the time point used to write time delta in the log. */ |
44 | | ngtcp2_tstamp ts; |
45 | | /* last_ts is the most recent time point that this object is |
46 | | told. */ |
47 | | ngtcp2_tstamp last_ts; |
48 | | /* user_data is user-defined opaque data which is passed to |
49 | | log_pritnf. */ |
50 | | void *user_data; |
51 | | /* scid is SCID encoded as NULL-terminated hex string. */ |
52 | | char scid[NGTCP2_MAX_CIDLEN * 2 + 1]; |
53 | | } ngtcp2_log; |
54 | | |
55 | | /** |
56 | | * @enum |
57 | | * |
58 | | * :type:`ngtcp2_log_event` defines an event of ngtcp2 library |
59 | | * internal logger. |
60 | | */ |
61 | | typedef enum ngtcp2_log_event { |
62 | | /** |
63 | | * :enum:`NGTCP2_LOG_EVENT_NONE` represents no event. |
64 | | */ |
65 | | NGTCP2_LOG_EVENT_NONE, |
66 | | /** |
67 | | * :enum:`NGTCP2_LOG_EVENT_CON` is a connection (catch-all) event |
68 | | */ |
69 | | NGTCP2_LOG_EVENT_CON = 0x1, |
70 | | /** |
71 | | * :enum:`NGTCP2_LOG_EVENT_PKT` is a packet event. |
72 | | */ |
73 | | NGTCP2_LOG_EVENT_PKT = 0x2, |
74 | | /** |
75 | | * :enum:`NGTCP2_LOG_EVENT_FRM` is a QUIC frame event. |
76 | | */ |
77 | | NGTCP2_LOG_EVENT_FRM = 0x4, |
78 | | /** |
79 | | * :enum:`NGTCP2_LOG_EVENT_LDC` is a loss detection and congestion |
80 | | * control event. |
81 | | */ |
82 | | NGTCP2_LOG_EVENT_LDC = 0x8, |
83 | | /** |
84 | | * :enum:`NGTCP2_LOG_EVENT_CRY` is a crypto event. |
85 | | */ |
86 | | NGTCP2_LOG_EVENT_CRY = 0x10, |
87 | | /** |
88 | | * :enum:`NGTCP2_LOG_EVENT_PTV` is a path validation event. |
89 | | */ |
90 | | NGTCP2_LOG_EVENT_PTV = 0x20, |
91 | | /** |
92 | | * :enum:`NGTCP2_LOG_EVENT_CCA` is a congestion controller algorithm |
93 | | * event. |
94 | | */ |
95 | | NGTCP2_LOG_EVENT_CCA = 0x40, |
96 | | } ngtcp2_log_event; |
97 | | |
98 | | void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid, |
99 | | ngtcp2_printf log_printf, ngtcp2_tstamp ts, |
100 | | void *user_data); |
101 | | |
102 | | void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
103 | | const ngtcp2_frame *fr); |
104 | | void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
105 | | const ngtcp2_frame *fr); |
106 | | |
107 | | void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
108 | | const uint32_t *sv, size_t nsv); |
109 | | |
110 | | void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset2 *sr); |
111 | | |
112 | | void ngtcp2_log_remote_tp(ngtcp2_log *log, |
113 | | const ngtcp2_transport_params *params); |
114 | | |
115 | | void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type, |
116 | | uint8_t flags, ngtcp2_tstamp sent_ts); |
117 | | |
118 | | void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); |
119 | | |
120 | | void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); |
121 | | |
122 | 0 | #define NGTCP2_LOG_HD "I%08" PRIu64 " 0x%s %s" |
123 | | |
124 | | uint64_t ngtcp2_log_timestamp(const ngtcp2_log *log); |
125 | | |
126 | 0 | static inline const char *ngtcp2_log_event_str(ngtcp2_log_event ev) { |
127 | 0 | switch (ev) { |
128 | 0 | case NGTCP2_LOG_EVENT_CON: |
129 | 0 | return "con"; |
130 | 0 | case NGTCP2_LOG_EVENT_PKT: |
131 | 0 | return "pkt"; |
132 | 0 | case NGTCP2_LOG_EVENT_FRM: |
133 | 0 | return "frm"; |
134 | 0 | case NGTCP2_LOG_EVENT_LDC: |
135 | 0 | return "ldc"; |
136 | 0 | case NGTCP2_LOG_EVENT_CRY: |
137 | 0 | return "cry"; |
138 | 0 | case NGTCP2_LOG_EVENT_PTV: |
139 | 0 | return "ptv"; |
140 | 0 | case NGTCP2_LOG_EVENT_CCA: |
141 | 0 | return "cca"; |
142 | 0 | case NGTCP2_LOG_EVENT_NONE: |
143 | 0 | default: |
144 | 0 | return "non"; |
145 | 0 | } |
146 | 0 | } Unexecuted instantiation: ngtcp2_bbr.c:ngtcp2_log_event_str Unexecuted instantiation: ngtcp2_cc.c:ngtcp2_log_event_str Unexecuted instantiation: ngtcp2_conn.c:ngtcp2_log_event_str Unexecuted instantiation: ngtcp2_log.c:ngtcp2_log_event_str Unexecuted instantiation: ngtcp2_pv.c:ngtcp2_log_event_str Unexecuted instantiation: ngtcp2_rtb.c:ngtcp2_log_event_str |
147 | | |
148 | | #define ngtcp2_log_infof_raw(LOG, EV, FMT, ...) \ |
149 | 0 | (LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \ |
150 | 0 | ngtcp2_log_timestamp(LOG), (LOG)->scid, \ |
151 | 0 | ngtcp2_log_event_str(EV), __VA_ARGS__); |
152 | | |
153 | | /** |
154 | | * @function |
155 | | * |
156 | | * `ngtcp2_log_infof` writes info level log with printf like |
157 | | * formatting. |
158 | | */ |
159 | | #define ngtcp2_log_infof(LOG, EV, FMT, ...) \ |
160 | 0 | do { \ |
161 | 0 | if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \ |
162 | 0 | break; \ |
163 | 0 | } \ |
164 | 0 | \ |
165 | 0 | ngtcp2_log_infof_raw((LOG), (EV), FMT, __VA_ARGS__); \ |
166 | 0 | } while (0) |
167 | | |
168 | | #define ngtcp2_log_info_raw(LOG, EV, FMT) \ |
169 | 0 | (LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \ |
170 | 0 | ngtcp2_log_timestamp(LOG), (LOG)->scid, \ |
171 | 0 | ngtcp2_log_event_str(EV)) |
172 | | |
173 | | /** |
174 | | * @function |
175 | | * |
176 | | * `ngtcp2_log_info` writes info level log. FMT should not contain |
177 | | * formatting directive. This function exists to workaround the issue |
178 | | * that __VA_ARGS__ cannot be empty. |
179 | | */ |
180 | | #define ngtcp2_log_info(LOG, EV, FMT) \ |
181 | 0 | do { \ |
182 | 0 | if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \ |
183 | 0 | break; \ |
184 | 0 | } \ |
185 | 0 | \ |
186 | 0 | ngtcp2_log_info_raw((LOG), (EV), FMT); \ |
187 | 0 | } while (0) |
188 | | |
189 | | #endif /* !defined(NGTCP2_LOG_H) */ |