NewMadeleine

Documentation

« back to PM2 home.
nm_headers.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2026 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef NM_HEADERS_H
17#define NM_HEADERS_H
18
21{
22 uint16_t v0len;
23} __attribute__((packed));
24
26#define NM_PROTO_ID_MASK 0x0F
28#define NM_PROTO_FLAG_MASK 0xF0
29
31#define NM_PROTO_SMALL_DATA 0x01
33#define NM_PROTO_SHORT_DATA 0x02
35#define NM_PROTO_PKT_DATA 0x03
37#define NM_PROTO_RDV 0x04
39#define NM_PROTO_RTR 0x05
41#define NM_PROTO_ACK 0x06
43#define NM_PROTO_STRAT 0x07
45#define NM_PROTO_MSG 0x08
47#define NM_PROTO_DEBUG 0x0F
48
50#define NM_PROTO_FLAG_LASTCHUNK 0x10
52#define NM_PROTO_FLAG_ALIGNED 0x20
54#define NM_PROTO_FLAG_ACKREQ 0x40
55
56
57/* Warning : All header structs (except the global one) _MUST_ begin
58 * with the 'proto_id' field
59 */
60
72{
73 uint16_t len;
74 uint16_t skip;
75} __attribute__((packed));
76
86
95
104
116
127
134
142
172
179
182{
184 uint64_t req;
185} __attribute__((packed));
186
189
191
202
207
208
209#define NM_HEADER_PKT_DATA_SIZE \
210 sizeof(struct nm_header_pkt_data_s)
211
212#define NM_HEADER_DATA_SIZE \
213 nm_aligned(sizeof(struct nm_header_data_s))
214
215#define NM_HEADER_SHORT_DATA_SIZE \
216 nm_aligned(sizeof(struct nm_header_short_data_s))
217
218#define NM_HEADER_CTRL_SIZE(P_CTRL) \
219 nm_header_ctrl_size(P_CTRL)
220
221static inline size_t nm_header_ctrl_size(const union nm_header_ctrl_generic_s*const p_ctrl)
222{
223 switch(p_ctrl->generic.proto_id & NM_PROTO_ID_MASK)
224 {
225 case NM_PROTO_RDV:
226 return sizeof(struct nm_header_ctrl_rdv_s);
227 break;
228 case NM_PROTO_RTR:
229 return sizeof(struct nm_header_ctrl_rtr_s);
230 break;
231 case NM_PROTO_ACK:
232 return sizeof(struct nm_header_ctrl_ack_s);
233 break;
234 case NM_PROTO_MSG:
235 return sizeof(struct nm_header_msg_s);
236 break;
237 default:
238 NM_FATAL("invalid kind 0x%x for control header.\n", p_ctrl->generic.proto_id);
239 break;
240 }
241}
242
245{
246 assert((flags & NM_PROTO_ID_MASK) == 0x00);
247 p_header->proto_id = NM_PROTO_PKT_DATA | flags;
248 p_header->tag_id = tag_id;
249 p_header->seq = seq;
250 p_header->data_len = len;
251 p_header->chunk_offset = chunk_offset;
252 p_header->hlen = NM_HEADER_PKT_DATA_SIZE;
253}
254
255static inline void nm_header_init_data(struct nm_header_data_s*p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags,
257{
258 assert((flags & NM_PROTO_ID_MASK) == 0x00);
259 p_header->proto_id = NM_PROTO_SMALL_DATA | flags;
260 p_header->tag_id = tag_id;
261 p_header->seq = seq;
262 p_header->skip = skip;
263 p_header->len = len;
264 p_header->chunk_offset = chunk_offset;
265}
266
269{
271 p_header->tag_id = tag_id;
272 p_header->seq = seq;
273 p_header->len = len;
274}
275
277{
278 p_ctrl->msg.proto_id = NM_PROTO_MSG;
279 p_ctrl->msg.tag_id = tag_id;
280 p_ctrl->msg.seq = seq;
281 p_ctrl->msg.msg_len = msg_len;
282 }
283
284static inline void nm_header_init_rdv(union nm_header_ctrl_generic_s*p_ctrl, struct nm_req_s*p_pack,
285 nm_len_t chunk_len, nm_len_t chunk_offset, int is_contig_data, uint8_t rdv_flags)
286{
288 rdv_flags |= NM_PROTO_FLAG_ACKREQ;
289 assert((rdv_flags & NM_PROTO_ID_MASK) == 0);
290 p_ctrl->rdv.proto_id = NM_PROTO_RDV | rdv_flags;
291 p_ctrl->rdv.tag_id = p_pack->tag;
292 p_ctrl->rdv.seq = p_pack->seq;
293 p_ctrl->rdv.chunk_offset = chunk_offset;
294 p_ctrl->rdv.chunk_len = chunk_len;
295 p_ctrl->rdv.msg_len = p_pack->pack.len;
296 p_ctrl->rdv.priority = p_pack->pack.priority;
298}
299
302{
303 p_ctrl->rtr.proto_id = NM_PROTO_RTR;
304 p_ctrl->rtr.tag_id = tag;
305 p_ctrl->rtr.seq = seq;
306 p_ctrl->rtr.trk_id = trk_id;
307 p_ctrl->rtr.chunk_offset = chunk_offset;
308 p_ctrl->rtr.chunk_len = chunk_len;
309 p_ctrl->rtr.payload_size = payload_size;
310}
311
313{
314 p_ctrl->ack.proto_id = NM_PROTO_ACK;
315 p_ctrl->ack.tag_id = tag;
316 p_ctrl->ack.seq = seq;
317}
318
319static inline void nm_header_init_debug(struct nm_header_debug_s*p_header, int req)
320{
321 p_header->proto_id = NM_PROTO_DEBUG;
322 p_header->req = req;
323}
324
325#endif /* NM_HEADER_H */
#define NM_REQ_FLAG_PACK_SYNCHRONOUS
flag pack as synchronous (i.e.
nm_tag_t tag
the user-supplied tag
assert(p_data->ops.p_traversal !=NULL)
nm_len_t payload_size
Definition nm_headers.h:6
#define NM_PROTO_ID_MASK
mask for proto ID part
Definition nm_headers.h:26
static void nm_header_init_rdv(union nm_header_ctrl_generic_s *p_ctrl, struct nm_req_s *p_pack, nm_len_t chunk_len, nm_len_t chunk_offset, int is_contig_data, uint8_t rdv_flags)
Definition nm_headers.h:284
static void nm_header_init_msg(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag_id, nm_seq_t seq, nm_len_t msg_len)
Definition nm_headers.h:276
uint16_t skip
skip value for iovec
Definition nm_headers.h:1
#define NM_PROTO_PKT_DATA
new optimized packet format
Definition nm_headers.h:35
#define NM_PROTO_MSG
msg matching informations, contains no data chunk
Definition nm_headers.h:45
PUK_LIST_CREATE_FUNCS(nm_ctrl_chunk)
static void nm_header_init_data(struct nm_header_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags, uint16_t skip, nm_len_t len, nm_len_t chunk_offset)
Definition nm_headers.h:255
#define NM_PROTO_RTR
ready-to-receive, replay to rdv
Definition nm_headers.h:39
static void nm_header_init_debug(struct nm_header_debug_s *p_header, int req)
Definition nm_headers.h:319
uint64_t req
a type of debug request; unused for now
Definition nm_headers.h:1
uint16_t len
chunk len
Definition nm_headers.h:0
static void nm_header_init_ack(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag, nm_seq_t seq)
Definition nm_headers.h:312
#define NM_PROTO_ACK
an ack for a ssend (sent when receiving first chunk)
Definition nm_headers.h:41
#define NM_PROTO_FLAG_ACKREQ
data sent as synchronous send- please send an ack on first chunk
Definition nm_headers.h:54
static size_t nm_header_ctrl_size(const union nm_header_ctrl_generic_s *const p_ctrl)
Definition nm_headers.h:221
#define NM_PROTO_DEBUG
internal debug msg
Definition nm_headers.h:47
int is_contig_data
whether data is contiguous on the sender side
Definition nm_headers.h:7
nm_len_t chunk_len
length of this chunk
Definition nm_headers.h:4
union nm_header_ctrl_generic_s __attribute__
#define NM_PROTO_SHORT_DATA
a simplified (short header) chunk of data
Definition nm_headers.h:33
PUK_LIST_DECLARE_TYPE(nm_ctrl_chunk)
nm_core_tag_t tag_id
tag for the message
Definition nm_headers.h:1
static void nm_header_init_short_data(struct nm_header_short_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, nm_len_t len)
Definition nm_headers.h:267
nm_trk_id_t trk_id
index of the track relative to the gate
Definition nm_headers.h:3
#define NM_HEADER_PKT_DATA_SIZE
Definition nm_headers.h:209
static void nm_header_init_rtr(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag, nm_seq_t seq, nm_trk_id_t trk_id, nm_len_t chunk_offset, nm_len_t chunk_len, nm_len_t payload_size)
Definition nm_headers.h:300
static void nm_header_init_pkt_data(struct nm_header_pkt_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags, nm_len_t len, nm_len_t chunk_offset)
Definition nm_headers.h:243
nm_len_t chunk_offset
offset of the enclosed chunk
Definition nm_headers.h:4
#define NM_PROTO_RDV
rendez-vous request
Definition nm_headers.h:37
nm_len_t msg_len
length of the full message
Definition nm_headers.h:3
#define NM_PROTO_FLAG_LASTCHUNK
last chunk of data for the given pack
Definition nm_headers.h:50
nm_seq_t seq
sequence number
Definition nm_headers.h:2
#define NM_PROTO_SMALL_DATA
a chunk of data on small trk
Definition nm_headers.h:31
PUK_ALLOCATOR_TYPE_SINGLE(nm_ctrl_chunk, struct nm_ctrl_chunk_s)
allocator for control chunks
#define NM_FATAL(format,...)
Definition nm_log.h:36
nm_onesided_flag_t flags
int8_t nm_trk_id_t
ID of a track, assigned in order.
Definition nm_types.h:86
int32_t nm_prio_t
message priority
Definition nm_types.h:78
uint64_t nm_len_t
data length used by nmad
Definition nm_types.h:68
uint32_t nm_seq_t
Sequence number for packets on a given gate/tag.
Definition nm_types.h:102
uint8_t nm_proto_t
protocol flags- not part of the public API, but needed for inline
Definition nm_types.h:99
An internal tag.
a chunk of control data
Definition nm_headers.h:194
const void * p_payload
payload for the ctrl chunk (e.g.
Definition nm_headers.h:198
nm_header_ctrl_generic_t ctrl
Definition nm_headers.h:197
nm_len_t size
size of the payload (0 if none)
Definition nm_headers.h:199
PUK_LIST_LINK(nm_ctrl_chunk)
nm_gate_t p_gate
Definition nm_headers.h:196
Connection to another process.
Definition nm_gate.h:104
base header that matches all data/ctrl headers first fields (except header_strat)
Definition nm_headers.h:137
nm_proto_t proto_id
Definition nm_headers.h:138
nm_core_tag_t tag_id
Definition nm_headers.h:139
nm_core_tag_t tag_id
Definition nm_headers.h:131
nm_proto_t proto_id
proto ID- should be NM_PROTO_ACK
Definition nm_headers.h:130
nm_len_t chunk_len
length of this chunk
Definition nm_headers.h:111
nm_proto_t proto_id
proto ID- should be NM_PROTO_RDV
Definition nm_headers.h:107
int is_contig_data
whether data is contiguous on the sender side
Definition nm_headers.h:114
nm_len_t msg_len
length of the full message
Definition nm_headers.h:112
nm_len_t chunk_offset
offset of this chunk relative to full message
Definition nm_headers.h:110
nm_core_tag_t tag_id
Definition nm_headers.h:108
nm_trk_id_t trk_id
index of the track relative to the gate
Definition nm_headers.h:122
nm_proto_t proto_id
proto ID- should be NM_PROTO_RTR
Definition nm_headers.h:119
nm_core_tag_t tag_id
tag of the acknowledged data
Definition nm_headers.h:120
nm_core_tag_t tag_id
tag for the message
Definition nm_headers.h:80
nm_proto_t proto_id
proto ID- should be NM_PROTO_SMALL_DATA
Definition nm_headers.h:79
nm_seq_t seq
sequence number
Definition nm_headers.h:81
nm_len_t chunk_offset
Definition nm_headers.h:83
uint16_t skip
skip offset for data buffer, relative to v0 end (0xFFFF for inline data)
Definition nm_headers.h:84
header for debug messages
Definition nm_headers.h:182
uint64_t req
a type of debug request; unused for now
Definition nm_headers.h:184
nm_proto_t proto_id
Definition nm_headers.h:183
global header at the beginning of pw
Definition nm_headers.h:21
uint16_t v0len
size of v0 actually used ( == offset value to reach v[1] )
Definition nm_headers.h:22
header for msg matching information only, contains no data; for cases where early information is need...
Definition nm_headers.h:98
nm_proto_t proto_id
proto ID- should be NM_PROTO_MSG
Definition nm_headers.h:99
nm_len_t msg_len
Definition nm_headers.h:102
nm_core_tag_t tag_id
Definition nm_headers.h:100
sub-header for pkt_data chunks
Definition nm_headers.h:72
uint16_t skip
skip value for iovec
Definition nm_headers.h:74
uint16_t len
chunk len
Definition nm_headers.h:73
nm_len_t chunk_offset
offset of the enclosed chunk
Definition nm_headers.h:67
nm_len_t data_len
length of data enclosed
Definition nm_headers.h:66
nm_proto_t proto_id
proto ID- should be NM_PROTO_PKT_DATA
Definition nm_headers.h:63
nm_core_tag_t tag_id
tag for the message
Definition nm_headers.h:64
uint16_t hlen
length in header (header + data in header)
Definition nm_headers.h:68
nm_seq_t seq
sequence number
Definition nm_headers.h:65
header for very short data; single chunk assumed (chunk_offset=0, chunk_len=len, FLAG_LASTCHUNK)
Definition nm_headers.h:89
nm_core_tag_t tag_id
Definition nm_headers.h:91
nm_proto_t proto_id
proto ID- should be NM_PROTO_SHORT_DATA
Definition nm_headers.h:90
header for strategy private packets
Definition nm_headers.h:175
nm_proto_t proto_id
should be NM_PROTO_STRAT
Definition nm_headers.h:176
a generic pack/unpack request
nm_core_tag_t tag
tag to send to/from (works in combination with tag_mask for recv)
struct nm_req_s::@15::@17 pack
nm_prio_t priority
request priority level
nm_req_flag_t flags
flags given by user
nm_len_t len
cumulated data length
nm_seq_t seq
packet sequence number on the given tag
a unified control header type
Definition nm_headers.h:145
struct nm_header_ctrl_rdv_s rdv
Definition nm_headers.h:147
struct nm_header_msg_s msg
Definition nm_headers.h:146
struct nm_header_common_s generic
Definition nm_headers.h:150
struct nm_header_ctrl_ack_s ack
Definition nm_headers.h:149
struct nm_header_ctrl_rtr_s rtr
Definition nm_headers.h:148
a unified data header type
Definition nm_headers.h:154
struct nm_header_short_data_s short_data
Definition nm_headers.h:156
struct nm_header_pkt_data_s pkt_data
Definition nm_headers.h:155
struct nm_header_data_s data
Definition nm_headers.h:157
struct nm_header_common_s generic
Definition nm_headers.h:158
a unified header for all types (ctrl/data)
Definition nm_headers.h:162
struct nm_header_data_s data
Definition nm_headers.h:166
struct nm_header_msg_s msg
Definition nm_headers.h:167
struct nm_header_common_s generic
Definition nm_headers.h:163
struct nm_header_ctrl_rtr_s rtr
Definition nm_headers.h:169
struct nm_header_pkt_data_s pkt_data
Definition nm_headers.h:164
struct nm_header_ctrl_ack_s ack
Definition nm_headers.h:170
struct nm_header_short_data_s short_data
Definition nm_headers.h:165
struct nm_header_ctrl_rdv_s rdv
Definition nm_headers.h:168