Coda Distributed File System
Loading...
Searching...
No Matches
tcpftp.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
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14#*/
15
16/* TCPFTP parameter block.
17 *
18 * TCPFTP streams a file's bytes over the codatunnel daemon-to-daemon channel
19 * rather than through the in-RPC2-process SFTP loop. The SE still travels with
20 * the RPC, but only its *control* payload rides in the request body: a single
21 * 8-byte correlation cookie. Everything else - file identity, tag, direction,
22 * offset, length, and any in-VM buffers - is resolved locally at each end from
23 * its own SE descriptor, so it never crosses; the cookie is the one value that
24 * pairs the two codatunneld registrations. This header describes that block;
25 * ftp_proto.c implements its (de)serialization so it can be unit-tested without
26 * a live connection or LWP context. */
27
28#ifndef _RPC2_TCPFTP_H_
29#define _RPC2_TCPFTP_H_
30
31#include <stddef.h>
32#include <stdint.h>
33#include <sys/socket.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include <rpc2/se.h>
40
41/* Per-connection codatunnel offload state. Embedded in the standalone TCPFTP
42 * entry and in the SMARTFTP SFTP_Entry when the connection negotiated TCPFTP.
43 * Only the cookie crosses the wire (see ftp_proto.c). */
45 uint64_t Cookie; /* correlation cookie; 0 == none */
46 int VmFd; /* in-VM sink spool fd; -1 == none */
47 int GotBlock; /* server: cookie parsed from the request */
48};
49
50#define TCPFTP_ROLE_SOURCE 0 /* mirror CT_SOURCE / CT_SINK (codatunnel/ctp.h) */
51#define TCPFTP_ROLE_SINK 1
52
53/* Length a local registration reports to the daemon: for a source, size past
54 * the seek offset capped at ByteQuota when positive (<= 0 == unlimited,
55 * matching classic SFTP); for a sink, 0 (accept however many bytes arrive).
56 * See tcpftp_reglen() in tcpftp1.c. */
57uint64_t tcpftp_reglen(const struct SFTP_Descriptor *d, int role,
58 uint64_t size);
59
60/* Open/resolve the local file for d's tag + role and register it with the
61 * daemon (see tcpftp1.c). in_cookie is 0 (client, generate) or the client's
62 * cookie (server, reuse); *out_cookie receives the resulting cookie. Returns 0
63 * or an RPC2_SEFAIL* code. */
64int tcpftp_register_local(struct TcpFtpState *st, const struct sockaddr *peer,
65 socklen_t plen, struct SFTP_Descriptor *d, int role,
66 uint64_t in_cookie, uint64_t *out_cookie);
67
68/* Wait for the daemon's terminal status; for an in-VM sink, drain the spool
69 * back into d's buffer. Returns the terminal status (0 == ok). When nowait
70 * is set the wait is non-blocking: a still-pending cookie yields -1
71 * (not-done) instead of blocking the io thread. */
72long tcpftp_finalize(struct TcpFtpState *st, struct SFTP_Descriptor *d,
73 uint64_t cookie, int nowait);
74
75/* Byte size of the packed param block: a fixed 8 bytes (the correlation
76 * cookie) for every supported form. */
77size_t tcpftp_param_blocksize(void);
78
79/* Serialize the correlation cookie into buf[0..maxlen). Returns 0 and sets
80 * *wrote (=8) on success; -1 if any argument is NULL or maxlen is smaller than
81 * tcpftp_param_blocksize(). The cookie is the only wire field; everything else
82 * is local to each end and is not encoded. */
83int tcpftp_pack_param_block(const uint64_t *cookie, unsigned char *buf,
84 size_t maxlen, size_t *wrote);
85
86/* Inverse of tcpftp_pack_param_block: reads exactly one 8-byte block from buf
87 * and stores its cookie into *cookie. Returns 0 on success; -1 if len is not
88 * exactly 8, or a pointer is NULL. */
89int tcpftp_unpack_param_block(const unsigned char *buf, size_t len,
90 uint64_t *cookie);
91
92/* Register the TCPFTP side-effect definition with RPC2 (grows the SE_DefSpecs
93 * table, exactly as SFTP_Activate does). Call before RPC2_Init, alongside
94 * SFTP_Activate. No-op if the SE table is already active. Returns the SE
95 * number (TCPFTP). */
96long TCPFTP_Activate(void);
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* _RPC2_TCPFTP_H_ */
int socklen_t
Definition mariner.cc:73
Definition se.h:101
Definition tcpftp.h:44
uint64_t Cookie
Definition tcpftp.h:45
int VmFd
Definition tcpftp.h:46
int GotBlock
Definition tcpftp.h:47
int tcpftp_unpack_param_block(const unsigned char *buf, size_t len, uint64_t *cookie)
Definition ftp_proto.c:47
int tcpftp_pack_param_block(const uint64_t *cookie, unsigned char *buf, size_t maxlen, size_t *wrote)
Definition ftp_proto.c:37
uint64_t tcpftp_reglen(const struct SFTP_Descriptor *d, int role, uint64_t size)
Definition tcpftp1.c:229
size_t tcpftp_param_blocksize(void)
Definition ftp_proto.c:31
long tcpftp_finalize(struct TcpFtpState *st, struct SFTP_Descriptor *d, uint64_t cookie, int nowait)
Definition tcpftp1.c:423
long TCPFTP_Activate(void)
Definition tcpftp1.c:651
int tcpftp_register_local(struct TcpFtpState *st, const struct sockaddr *peer, socklen_t plen, struct SFTP_Descriptor *d, int role, uint64_t in_cookie, uint64_t *out_cookie)
Definition tcpftp1.c:260
char d
Definition tdb.c:54