2 * Definitions for Bundle Protocol Version 7 dissection.
4 * RFC 9171: https://www.rfc-editor.org/rfc/rfc9171.html
6 * Copyright 2019-2021, Brian Sipos <brian.sipos@gmail.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: LGPL-2.1-or-later
17 #include <ws_symbol_export.h>
18 #include <epan/tvbuff.h>
19 #include <epan/proto.h>
20 #include <epan/expert.h>
26 /* This dissector defines two layers of protocol:
27 * - The BPv7 bundle format and its block types.
28 * - The BPv7 Administrative Record which is a bundle payload as indicated by
29 * a primary block flag.
31 * BPv7 block-type-specific data (BTSD) dissectors are registered with the
32 * dissector table "bpv7.block_type" and Administrative Record dissectors
33 * with the table "bpv7.admin_record_type". Both use uint64_t* table keys.
34 * Both use bp_dissector_data_t* as dissector user data.
36 * There is a BTSD heuristic dissector table "bpv7.btsd" which uses
37 * bp_dissector_data_t* as dissector user data.
39 * Payload block (block type 1) dissection is additionally handled based on
40 * bundle flags and destination EID as:
41 * - If the bundle flags mark it as administrative, it is dissected as such.
42 * - If the destination is a well-known SSP, the dissector table
43 * "bpv7.payload.dtn_wkssp" is used with the scheme-specific part.
44 * - If the destination is "dtn" scheme, the dissector table
45 * "bpv7.payload.dtn_serv" is used with the service demux (text string).
46 * There is also Decode As behavior for dtn service demux.
47 * - If the destination is "ipn" scheme, the dissector table
48 * "bpv7.payload.ipn_serv" is used with the service number (uint value).
49 * There is also Decode As behavior for ipn service number.
50 * - Finally, fall through to BTSD heuristic dissection.
51 * All payload dissection uses bp_dissector_data_t* as dissector user data.
55 * RFC 9171 Section 4.2.1.
58 /// no CRC is present.
60 /// a standard X-25 CRC-16 is present.
62 /// a standard CRC32C (Castagnoli) CRC-32 is present.
66 /** Bundle processing control flags.
67 * RFC 9171 Section 4.2.3.
70 /// bundle deletion status reports are requested.
71 BP_BUNDLE_REQ_DELETION_REPORT
= 0x040000,
72 /// bundle delivery status reports are requested.
73 BP_BUNDLE_REQ_DELIVERY_REPORT
= 0x020000,
74 /// bundle forwarding status reports are requested.
75 BP_BUNDLE_REQ_FORWARDING_REPORT
= 0x010000,
76 /// bundle reception status reports are requested.
77 BP_BUNDLE_REQ_RECEPTION_REPORT
= 0x004000,
78 /// status time is requested in all status reports.
79 BP_BUNDLE_REQ_STATUS_TIME
= 0x000040,
80 /// user application acknowledgement is requested.
81 BP_BUNDLE_USER_APP_ACK
= 0x000020,
82 /// bundle must not be fragmented.
83 BP_BUNDLE_NO_FRAGMENT
= 0x000004,
84 /// payload is an administrative record.
85 BP_BUNDLE_PAYLOAD_ADMIN
= 0x000002,
86 /// bundle is a fragment.
87 BP_BUNDLE_IS_FRAGMENT
= 0x000001,
88 } BundleProcessingFlag
;
90 /** Block processing control flags.
91 * RFC 9171 Section 4.2.4.
94 /// block must be removed from bundle if it can't be processed.
95 BP_BLOCK_REMOVE_IF_NO_PROCESS
= 0x10,
96 /// bundle must be deleted if block can't be processed.
97 BP_BLOCK_DELETE_IF_NO_PROCESS
= 0x04,
98 /// transmission of a status report is requested if block can't be processed.
99 BP_BLOCK_STATUS_IF_NO_PROCESS
= 0x02,
100 /// block must be replicated in every fragment.
101 BP_BLOCK_REPLICATE_IN_FRAGMENT
= 0x01,
102 } BlockProcessingFlag
;
104 /** Standard block type codes.
105 * RFC 9171 Section 4.3.2 and Section 4.4.
108 BP_BLOCKTYPE_INVALID
= 0,
110 BP_BLOCKTYPE_PAYLOAD
= 1,
112 BP_BLOCKTYPE_PREV_NODE
= 6,
114 BP_BLOCKTYPE_BUNDLE_AGE
= 7,
116 BP_BLOCKTYPE_HOP_COUNT
= 10,
117 /// Block Integrity Block
118 BP_BLOCKTYPE_BIB
= 11,
119 /// Block Confidentiality Block
120 BP_BLOCKTYPE_BCB
= 12,
123 /** Administrative record type codes.
124 * RFC 9171 Section 6.1.
127 /// Bundle status report
128 BP_ADMINTYPE_BUNDLE_STATUS
= 1,
129 } AdminRecordTypeCode
;
131 /// DTN time with derived UTC time
139 /// Creation Timestamp used to correlate bundles
142 bp_dtn_time_t abstime
;
147 /** Function to match the GCompareDataFunc signature.
150 int bp_creation_ts_compare(const void *a
, const void *b
, void *user_data
);
152 /** Endpoint ID scheme encodings.
159 /// Metadata from a Endpoint ID
163 /// Derived URI text as address
166 /// Optional DTN-scheme well-known SSP
167 const char *dtn_wkssp
;
168 /// Optional DTN-scheme service name
169 const char *dtn_serv
;
170 /// Optional IPN-scheme service name
174 /** Construct a new timestamp.
177 bp_eid_t
* bp_eid_new(wmem_allocator_t
*alloc
);
179 /** Function to match the GDestroyNotify signature.
182 void bp_eid_free(wmem_allocator_t
*alloc
, bp_eid_t
*obj
);
184 /** Function to match the GCompareFunc signature.
187 bool bp_eid_equal(const void *a
, const void *b
);
189 /// Security marking metadata
191 /// Block numbers marking the data as security integrity protected
193 /// Block numbers marking the data as security-modified and not decodable
197 /// Metadata extracted from the primary block
199 /// Display item for the whole block
200 proto_item
*item_block
;
202 /// Bundle flags (assumed zero).
203 /// Values are BundleProcessingFlag.
208 bp_eid_t
*src_nodeid
;
210 bp_eid_t
*rep_nodeid
;
211 /// Creation Timestamp
213 /// Optional fragment start offset
214 uint64_t *frag_offset
;
215 /// Optional bundle total length
217 /// CRC type code (assumed zero)
219 /// Raw bytes of CRC field
223 } bp_block_primary_t
;
225 /** Construct a new object on the file allocator.
228 bp_block_primary_t
* bp_block_primary_new(wmem_allocator_t
*alloc
);
230 /** Function to match the GDestroyNotify signature.
233 void bp_block_primary_free(wmem_allocator_t
*alloc
, bp_block_primary_t
*obj
);
236 /// The index of the block within the bundle.
237 /// This is for internal bookkeeping, *not* the block number.
239 /// Display item for the whole block
240 proto_item
*item_block
;
242 /// Type of this block
244 /// Unique identifier for this block
245 uint64_t *block_number
;
246 /// All flags on this block
248 /// CRC type code (assumed zero)
250 /// Raw bytes of CRC field
253 /// Type-specific data, unencoded
255 /// Type-specific data tree
256 proto_tree
*tree_data
;
259 } bp_block_canonical_t
;
261 /** Construct a new object on the file allocator.
262 * @param blk_ix The index of the block within the bundle.
263 * The canonical index is always greater than zero.
266 bp_block_canonical_t
* bp_block_canonical_new(wmem_allocator_t
*alloc
, uint64_t blk_ix
);
269 void bp_block_canonical_delete(wmem_allocator_t
*alloc
, bp_block_canonical_t
*obj
);
271 /// Identification of an individual bundle
273 /// Normalized EID URI for the Source Node ID
275 /// Creation Timestamp
277 /// Pointer to external optional fragment start offset
278 const uint64_t *frag_offset
;
279 /// Pointer to external optional bundle total length
280 const uint64_t *total_len
;
283 /** Construct a new object on the file allocator.
284 * @param alloc The allocator to use.
285 * @param src The non-null pointer to source EID.
286 * @param ts The non-null pointer to Timestamp.
287 * @param off Optional fragment offset value.
288 * @param len Optional fragment length value.
291 bp_bundle_ident_t
* bp_bundle_ident_new(wmem_allocator_t
*alloc
, const bp_eid_t
*src
, const bp_creation_ts_t
*ts
, const uint64_t *off
, const uint64_t *len
);
294 void bp_bundle_ident_free(wmem_allocator_t
*alloc
, bp_bundle_ident_t
*obj
);
296 /** Function to match the GEqualFunc signature.
299 gboolean
bp_bundle_ident_equal(const void *a
, const void *b
);
301 /** Function to match the GHashFunc signature.
304 unsigned bp_bundle_ident_hash(const void *key
);
306 /// Metadata extracted per-bundle
308 /// Index of the frame
310 /// Layer within the frame
312 /// Timestamp on the frame (end time if reassembled)
314 /// Bundle identity derived from #primary data
315 bp_bundle_ident_t
*ident
;
316 /// Required primary block
317 bp_block_primary_t
*primary
;
318 /// Additional blocks in order (type bp_block_canonical_t)
320 /// Map from block number (uint64_t) to pointer to block of that number
321 /// (bp_block_canonical_t owned by #blocks)
322 wmem_map_t
*block_nums
;
323 /// Map from block type code (uint64_t) to sequence (wmem_list_t) of
324 /// pointers to block of that type (bp_block_canonical_t owned by #blocks)
325 wmem_map_t
*block_types
;
327 /// Payload BTSD start offset in bundle TVB
328 unsigned *pyld_start
;
329 /// Payload BTSD length
333 /** Construct a new object on the file allocator.
336 bp_bundle_t
* bp_bundle_new(wmem_allocator_t
*alloc
);
338 /** Function to match the GDestroyNotify signature.
341 void bp_bundle_free(wmem_allocator_t
*alloc
, bp_bundle_t
*obj
);
343 /** Extract an Endpoint ID.
344 * All EID fields are allocated with wmem_file_scope().
346 * @param tree The tree to write items under.
347 * @param hfindex The root item field.
348 * @param hfindex_uri The reassembled URI item field.
349 * @param pinfo Packet info to update.
350 * @param tvb Buffer to read from.
351 * @param[in,out] offset Starting offset within @c tvb.
352 * @param[out] eid If non-null, the EID to write to.
353 * @return The new tree item.
356 proto_item
* proto_tree_add_cbor_eid(proto_tree
*tree
, int hfindex
, int hfindex_uri
, packet_info
*pinfo
, tvbuff_t
*tvb
, int *offset
, bp_eid_t
*eid
);
358 /// Metadata for an entire file
360 /// Map from a bundle ID (bp_bundle_ident_t) to wmem_list_t of bundle (bp_bundle_t)
362 /// Map from subject bundle ID (bp_bundle_ident_t) to
363 /// map from references (bp_bundle_ident_t) of status bundles to NULL
365 wmem_map_t
*admin_status
;
368 /** Data supplied to each block sub-dissector.
371 /// The overall bundle being decoded (so far)
373 /// This block being decoded
374 bp_block_canonical_t
*block
;
375 } bp_dissector_data_t
;
381 #endif /* PACKET_BPV7_H */