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
//! Protocol plugin layer + typed event surface.
//!
//! The [`Protocol`] trait + role markers ([`FlowProtocol`] /
//! [`MessageProtocol`]) define how the [`Monitor`](crate::monitor::Monitor)
//! observes traffic. Built-in markers ship in [`builtin`]; typed
//! lifecycle/message events live in [`event_typed`].
//!
//! The 0.19 `ProtocolMonitor` / `ProtocolEvent` sum-type API was
//! removed in 0.22 — use `Monitor::builder()` + `on`/`on_ctx` instead.
pub use ;
// Re-export the 7 built-in `Protocol` markers at the protocol
// module level so `use netring::protocol::Http;` works (without
// the intermediate `::builtin::` path). The markers also live at
// `netring::protocol::builtin::*` and `netring::prelude::*` for
// users who prefer those paths.
pub use Dns;
pub use Http;
pub use ;
pub use ;
// ─── Plugin layer (netring 0.20, Phase A) ──────────────────────────────────
//
// The `Protocol` trait + supporting types define a protocol-agnostic plugin
// layer. Downstream crates implement `Protocol` for their own marker types
// and register them via the (forthcoming) `Monitor::builder().protocol::<P>()`
// API.
//
// In Phase A these types are defined but NOT yet consumed by the existing
// `ProtocolMonitorBuilder`. Phase B introduces the `Monitor` builder that
// uses them.
/// A protocol the monitor can observe.
///
/// Implementors are usually zero-sized marker types (`struct Http;`).
/// The marker is used as a type-level identifier; the runtime
/// dispatch key is its `TypeId`.
///
/// `'static` is required because dispatch is keyed by `TypeId`.
/// This forecloses lifetime-parameterized marker types — not a
/// real limitation since markers are typically ZSTs.
///
/// Built-in markers ship in [`builtin`]; downstream crates can
/// add their own without editing netring.
///
/// ## Why [`Self::register`] instead of returning a boxed parser
///
/// flowscope's `DriverBuilder::session_on_ports` (and friends)
/// require `P: SessionParser + Clone + Send + 'static`. A boxed
/// trait object (`Box<dyn SessionParser<Message = M>>`) can't
/// satisfy `Clone` and is `!Sized`, so the "give me your boxed
/// parser, I'll register it" shape doesn't compile. Instead the
/// `Protocol` impl drives the registration itself — it keeps the
/// parser as its concrete type all the way to the call site.
/// 0.22 R1: a protocol whose **flows the tracker follows** end to
/// end. Flow-tracked protocols emit the lifecycle events
/// [`FlowStarted`] / [`FlowEstablished`] / [`FlowEnded`] / [`FlowTick`]
/// and participate in the flat [`FlowPacket`] stream; they are keyed by
/// 5-tuple.
///
/// Implemented for [`builtin::Tcp`], [`builtin::Udp`], and
/// [`builtin::Icmp`] (ICMP is *both* flow-tracked — the kernel/
/// flowscope tracker follows ICMP echo + error 5-tuples — and a
/// [`MessageProtocol`]). It is **not** implemented for the L7 markers
/// (`Http`/`Dns`/`Tls`/…): their "flow" is the underlying TCP/UDP
/// flow, so `FlowStarted<Http>` is a type error — use
/// `FlowStarted<Tcp>` and scope by parser via `on::<Http>` instead.
///
/// The bound is what makes `on::<FlowStarted<Http>>(…)` fail to
/// compile (caught at build, not silently never-firing at runtime).
/// 0.22 R1: a protocol that delivers **discrete parsed messages**.
/// `on::<Self>(|msg, ctx| …)` fires once per [`Protocol::Message`]
/// the parser emits.
///
/// Implemented for the L7 markers (`Http`/`Dns`/`Tls`/`TlsHandshake`)
/// and [`builtin::Icmp`]. It is **not** implemented for the
/// lifecycle-only markers [`builtin::Tcp`] / [`builtin::Udp`] (their
/// [`Protocol::Message`] is `()`), so `on::<Tcp>(…)` is a type error —
/// use a lifecycle event (`on::<FlowStarted<Tcp>>`) instead.
///
/// Also gates the broadcast surface
/// ([`MonitorBuilder::with_broadcast`](crate::monitor::MonitorBuilder::with_broadcast)
/// / [`Monitor::subscribe`](crate::monitor::Monitor::subscribe)):
/// only message protocols carry a meaningful per-message stream.
/// How a protocol selects packets for its parser.
/// 0.25 S1: the **traffic interest** of one consumer (a handler, a registered
/// protocol parser, an exporter). The Monitor folds every consumer's class
/// into the OR-union it pushes to the kernel as a conservative prefilter
/// (see the subscription-engine design). A consumer can only ever *widen* the
/// union, never narrow it — so the kernel filter is always a superset of what
/// some consumer wants, and no consumer is starved.
///
/// Kept in the `protocol` module (no `Predicate` dependency) so the [`Event`]
/// trait can declare it; the Monitor maps it to a
/// [`Predicate`](crate::monitor::subscription::Predicate) at build time.
/// Result of a signature function. `Match` pins the flow to this
/// protocol's parser; `NoMatch` skips it; `NeedMoreData` says
/// "I need more bytes" — the dispatcher keeps probing until budget
/// runs out.
///
/// Mirrors [`flowscope::detect::signatures::SignatureMatch`] —
/// the [`From`] impl converts losslessly so netring users can
/// pass flowscope signature functions directly into
/// [`Dispatch::Signature`].
/// Error type for [`Protocol::register`]. Most parsers are
/// infallible to construct; flowscope parsers that take config
/// can fail. Lifecycle-only markers (Tcp, Udp) use this to
/// indicate "no parser slot needed — handled by the central
/// flow tracker."
;
/// Convenience alias — the flow key produced by
/// [`flowscope::extract::FiveTuple`]. Most user code names this
/// rather than the longer fully-qualified path.
pub type FlowKey = FiveTupleKey;