Coda Distributed File System
Loading...
Searching...
No Matches
subprojects
rpc2
codatunnel
ctp.h
Go to the documentation of this file.
1
/* BLURB lgpl
2
3
Coda File System
4
Release 8
5
6
Copyright (c) 2026 Carnegie Mellon University
7
Additional copyrights listed below
8
9
This code is distributed "AS IS" without warranty of any kind under
10
the terms of the GNU Library General Public Licence Version 2, as
11
shown in the file LICENSE. The technical and financial contributors to
12
Coda are listed in the file CREDITS.
13
14
Additional copyrights
15
16
#*/
17
18
/* Pure wire protocol for codatunneld. No libuv, no gnutls, so this can be
19
* included (and unit-tested) without pulling the tunnel dependencies into
20
* a build. The same header wraps both the daemon-to-daemon TLS records and
21
* the Unix-socket ("vside") exchanges between an app and its codatunneld.
22
*
23
* The `opcode` word is the former `is_init0` hint, reused in place. The byte
24
* layout of ctp_t is unchanged, so sizeof(ctp_t) and the "magic01" magic word
25
* are preserved for backward compatibility with peers that only ever wrote the
26
* word to 0 (a plain packet) or 1 (INIT0).
27
*/
28
29
#ifndef _CODATUNNEL_CTP_H_
30
#define _CODATUNNEL_CTP_H_
31
32
#include <stdint.h>
33
#include <sys/socket.h>
34
#include <sys/types.h>
35
36
#define CT_MAGIC "magic01"
37
#define CT_MAGICSZ 8
38
39
enum
ct_opcode
40
{
41
CT_PKT
= 0,
/* encapsulated RPC2 packet (today's plain packet) */
42
CT_INIT0
= 1,
/* peername hint (NUL-padded body) */
43
CT_FILEREG
= 2,
/* app->daemon: register a local transfer */
44
CT_FILEUNREG
= 3,
/* app->daemon: cancel/release a registration */
45
CT_FILEDONE
= 4,
/* daemon->app: terminal state of a registration */
46
CT_TRANSFER_READY
=
47
5,
/* daemon->daemon: sink (driver end) is open, proceed */
48
CT_TRANSFER_DATA
= 6,
/* daemon->daemon: file bytes @{cookie,offset} */
49
CT_TRANSFER_EOF
= 7,
/* daemon->daemon: no more bytes for cookie */
50
CT_TRANSFER_ERROR
= 8,
/* daemon->daemon: local open/xfer failed */
51
CT_TRANSFER_REQUEST
=
52
9,
/* daemon->daemon: sink asks the source for bytes @{cookie,offset} */
53
};
54
55
/* role values for ct_filereg.role */
56
#define CT_SOURCE 0
57
#define CT_SINK 1
58
59
/*
60
* ct_filereg.flags bits. The "driver" bit drives the CT_TRANSFER_READY start
61
* rule: a single daemon can only see its own FILEREG, so it cannot tell which
62
* end registered first. The RPC-server side (CheckSE) is always the driver
63
* end — it passes the client's cookie back through *cookie, which is the
64
* "non-zero in -> use as-is (server side)" convention, so the app sets this
65
* bit from that single fact. A SOURCE that is "driver" (a fetch) starts
66
* streaming immediately (the sink pre-registered); a SOURCE that is not
67
* "driver" (a store) waits for the sink's CT_TRANSFER_READY before streaming.
68
*/
69
#define CT_FILREG_DRIVER 0x1
70
71
/* CT_CHUNKMAX, CT_MAX_RECORD and the TLS payload ceiling live further down,
72
* after ctp_t and ct_transfer_data are defined (the payload size is derived
73
* from sizeof() of both). */
74
75
/* Status values carried in ct_filedone.status and ct_transfer_error.status,
76
* in the SFTP error space (0 == success). The daemon maps its local errno
77
* into these; the app's SE layer maps them back to SE status at finalize. */
78
#define CT_STATUS_SUCCESS 0
79
#define CT_STATUS_NOENT 1
/* file does not exist */
80
#define CT_STATUS_ACCES 2
/* permission denied */
81
#define CT_STATUS_NOSPC 3
/* disk / quota full */
82
#define CT_STATUS_IOERR 4
/* any other local I/O or resource error */
83
#define CT_STATUS_TIMEOUT 5
/* channel death or cancellation */
84
85
typedef
struct
codatunnel_packet
{
86
char
magic
[8];
87
uint32_t
is_retry
;
88
uint32_t
opcode
;
/* was is_init0; values from enum ct_opcode */
89
uint32_t
msglen
;
90
uint32_t
addrlen
;
91
struct
sockaddr_storage
addr
;
92
}
ctp_t
;
93
94
/* The layout must stay exactly: magic + four 32-bit words + the address.
95
Written against the field widths (not a hard-coded total) because
96
sizeof(struct sockaddr_storage) is platform dependent. The typedef form is
97
used (rather than a C11 _Static_assert) so this compiles under C99 too. */
98
typedef
char
ctp_size_invariant
[(
sizeof
(
ctp_t
) ==
99
(
size_t
)
CT_MAGICSZ
+ 4 *
sizeof
(
uint32_t
) +
100
sizeof
(
struct
sockaddr_storage
)) ?
101
1 :
102
-1];
103
104
typedef
struct
ct_filedone
{
105
uint64_t
cookie
;
106
uint64_t
nbytes
;
107
uint32_t
status
;
/* SFTP error space; 0 == success */
108
uint32_t
pad
;
109
}
ct_filedone
;
110
111
typedef
struct
ct_filereg
{
112
uint64_t
cookie
;
113
uint32_t
role
;
/* CT_SOURCE or CT_SINK */
114
uint32_t
flags
;
/* CT_FILREG_* bits */
115
uint16_t
peerlen
;
116
uint16_t
pad
;
117
uint64_t
offset
;
118
uint64_t
length
;
/* total file length / expected sink bytes */
119
struct
sockaddr_storage
peer
;
/* which tunnel channel this rides */
120
}
ct_filereg
;
121
122
/*
123
* The daemon-to-daemon data-path payloads, as the file-transfer opcodes
124
* arrive in the body region of a ctp_t envelope over the TLS channel
125
* (opcode == 5..8). The body itself is written in network byte order there
126
* (the ctp_t header does that already); the structs here are the pure byte
127
* layout. Only the ctp_t envelope is the shared framing; these ride in its
128
* body region. CT_TRANSFER_DATA is followed (in the same record) by up to
129
* CT_CHUNKMAX payload bytes, located at offset sizeof(ct_transfer_data).
130
*/
131
typedef
struct
ct_transfer_ready
{
132
uint64_t
cookie
;
133
}
ct_transfer_ready
;
134
135
typedef
struct
ct_transfer_data
{
136
uint64_t
cookie
;
137
uint64_t
offset
;
/* absolute file offset of the payload that follows */
138
}
ct_transfer_data
;
139
140
typedef
struct
ct_transfer_eof
{
141
uint64_t
cookie
;
142
}
ct_transfer_eof
;
143
144
typedef
struct
ct_transfer_error
{
145
uint64_t
cookie
;
146
uint32_t
status
;
/* SFTP error space; 0 == none */
147
uint32_t
pad
;
148
}
ct_transfer_error
;
149
150
typedef
struct
ct_transfer_request
{
151
uint64_t
cookie
;
152
uint64_t
offset
;
/* absolute file offset of the requested bytes */
153
uint64_t
len
;
/* how many bytes the sink wants (<= CT_CHUNKMAX) */
154
}
ct_transfer_request
;
155
156
/* A TLS record's content payload size is negotiated per session and, in
157
* practice, ranges from 512 up to 16384 bytes depending on configuration and
158
* TLS extensions. A full-chunk CT_TRANSFER_DATA record is the ctp_t header
159
* (whose addr field is a whole sockaddr_storage on every platform we build
160
* for) + the ct_transfer_data header + the payload. Size the payload to the
161
* largest record we could possibly expect (16384) so the scratch and
162
* reassembly buffers cover any record the daemon will send or accept. Each
163
* daemon actually reads/sends/accepts only what its own session negotiated
164
* (gnutls_record_get_max_size()), which is <= this, so every record stays
165
* inside a single TLS fragment and gnutls never splits it. */
166
#define CT_TLSMAXPAYLOAD 16384
167
#define CT_CHUNKMAX \
168
(CT_TLSMAXPAYLOAD - (size_t)sizeof(ctp_t) - sizeof(ct_transfer_data))
169
170
/* Largest record a daemon will accept on a channel: a full-chunk
171
* CT_TRANSFER_DATA. Everything the daemon decrypts today must fit in this;
172
* bigger is a protocol violation (the connection is dropped). */
173
#define CT_MAX_RECORD (sizeof(ctp_t) + sizeof(ct_transfer_data) + CT_CHUNKMAX)
174
175
#endif
/* _CODATUNNEL_CTP_H_ */
uint16_t
unsigned short uint16_t
Definition
coda.h:103
uint32_t
unsigned int uint32_t
Definition
coda.h:105
ct_opcode
ct_opcode
Definition
ctp.h:40
CT_FILEDONE
@ CT_FILEDONE
Definition
ctp.h:45
CT_TRANSFER_REQUEST
@ CT_TRANSFER_REQUEST
Definition
ctp.h:51
CT_FILEREG
@ CT_FILEREG
Definition
ctp.h:43
CT_TRANSFER_ERROR
@ CT_TRANSFER_ERROR
Definition
ctp.h:50
CT_TRANSFER_READY
@ CT_TRANSFER_READY
Definition
ctp.h:46
CT_TRANSFER_EOF
@ CT_TRANSFER_EOF
Definition
ctp.h:49
CT_INIT0
@ CT_INIT0
Definition
ctp.h:42
CT_PKT
@ CT_PKT
Definition
ctp.h:41
CT_FILEUNREG
@ CT_FILEUNREG
Definition
ctp.h:44
CT_TRANSFER_DATA
@ CT_TRANSFER_DATA
Definition
ctp.h:48
CT_MAGICSZ
#define CT_MAGICSZ
Definition
ctp.h:37
ctp_size_invariant
char ctp_size_invariant[(sizeof(ctp_t)==(size_t) CT_MAGICSZ+4 *sizeof(uint32_t)+sizeof(struct sockaddr_storage)) ? 1 :-1]
Definition
ctp.h:102
ctp_t
struct codatunnel_packet ctp_t
codatunnel_packet
Definition
ctp.h:85
codatunnel_packet::addr
struct sockaddr_storage addr
Definition
ctp.h:91
codatunnel_packet::magic
char magic[8]
Definition
ctp.h:86
codatunnel_packet::msglen
uint32_t msglen
Definition
ctp.h:89
codatunnel_packet::opcode
uint32_t opcode
Definition
ctp.h:88
codatunnel_packet::addrlen
uint32_t addrlen
Definition
ctp.h:90
codatunnel_packet::is_retry
uint32_t is_retry
Definition
ctp.h:87
ct_filedone
Definition
ctp.h:104
ct_filedone::pad
uint32_t pad
Definition
ctp.h:108
ct_filedone::cookie
uint64_t cookie
Definition
ctp.h:105
ct_filedone::nbytes
uint64_t nbytes
Definition
ctp.h:106
ct_filedone::status
uint32_t status
Definition
ctp.h:107
ct_filereg
Definition
ctp.h:111
ct_filereg::cookie
uint64_t cookie
Definition
ctp.h:112
ct_filereg::peerlen
uint16_t peerlen
Definition
ctp.h:115
ct_filereg::role
uint32_t role
Definition
ctp.h:113
ct_filereg::length
uint64_t length
Definition
ctp.h:118
ct_filereg::flags
uint32_t flags
Definition
ctp.h:114
ct_filereg::offset
uint64_t offset
Definition
ctp.h:117
ct_filereg::peer
struct sockaddr_storage peer
Definition
ctp.h:119
ct_filereg::pad
uint16_t pad
Definition
ctp.h:116
ct_transfer_data
Definition
ctp.h:135
ct_transfer_data::offset
uint64_t offset
Definition
ctp.h:137
ct_transfer_data::cookie
uint64_t cookie
Definition
ctp.h:136
ct_transfer_eof
Definition
ctp.h:140
ct_transfer_eof::cookie
uint64_t cookie
Definition
ctp.h:141
ct_transfer_error
Definition
ctp.h:144
ct_transfer_error::pad
uint32_t pad
Definition
ctp.h:147
ct_transfer_error::status
uint32_t status
Definition
ctp.h:146
ct_transfer_error::cookie
uint64_t cookie
Definition
ctp.h:145
ct_transfer_ready
Definition
ctp.h:131
ct_transfer_ready::cookie
uint64_t cookie
Definition
ctp.h:132
ct_transfer_request
Definition
ctp.h:150
ct_transfer_request::offset
uint64_t offset
Definition
ctp.h:152
ct_transfer_request::len
uint64_t len
Definition
ctp.h:153
ct_transfer_request::cookie
uint64_t cookie
Definition
ctp.h:151
sockaddr_storage
Definition
rpc2.private.h:63
Generated by
1.9.8