The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
tftp.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 3b323f24f463f53855b91bdfcc9da3a2365f0ab5 $
20  * @file src/protocols/tftp/tftp.h
21  * @brief Functions to encode/decode TFTP packets.
22  * @author Jorge Pereira <jpereira@freeradius.org>
23  *
24  * @copyright 2021 The FreeRADIUS server project.
25  * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
26  */
27 
28 RCSIDH(tftp_h, "$Id: 3b323f24f463f53855b91bdfcc9da3a2365f0ab5 $")
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <freeradius-devel/protocol/tftp/freeradius.internal.h>
35 #include <freeradius-devel/protocol/tftp/rfc1350.h>
36 
37 #include <freeradius-devel/util/dbuff.h>
38 
39 #define FR_TFTP_MAX_CODE (FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND+1)
40 #define FR_TFTP_MAX_ERROR_CODE (FR_ERROR_CODE_VALUE_NO_SUCH_USER+1)
41 #define FR_TFTP_HDR_LEN (4) /* at least: 2-bytes opcode + 2-bytes */
42 
43 /*
44  * 2. Overview of the Protocol
45  *
46  * Any transfer begins with a request to read or write a file, which
47  * also serves to request a connection. If the server grants the
48  * request, the connection is opened and the file is sent in fixed
49  * length blocks of 512 bytes. Each data packet contains one block of
50  * data, and must be acknowledged by an acknowledgment packet before the
51  * next packet can be sent. A data packet of less than 512 bytes
52  * signals termination of a transfer. If a packet gets lost in the
53  * network, the intended recipient will timeout and may retransmit his
54  * last packet (which may be data or an acknowledgment), thus causing
55  * the sender of the lost packet to retransmit that lost packet. The
56  * sender has to keep just one packet on hand for retransmission, since
57  * the lock step acknowledgment guarantees that all older packets have
58  * been received. Notice that both machines involved in a transfer are
59  * considered senders and receivers. One sends data and receives
60  * acknowledgments, the other sends acknowledgments and receives data.
61  */
62 #define FR_TFTP_DEFAULT_BLOCK_SIZE 1024
63 
64 /*
65  * As described in https://tools.ietf.org/html/rfc2348
66  *
67  * The number of octets in a block, specified in ASCII. Valid
68  * values range between "8" and "65464" octets, inclusive. The
69  * blocksize refers to the number of data octets; it does not
70  * include the four octets of TFTP header.
71  */
72 #define FR_TFTP_BLOCK_MIN_SIZE 8
73 #define FR_TFTP_BLOCK_MAX_SIZE 65464
74 
75 /*
76  * The original protocol has a transfer file size limit of 512 bytes/block x 65535 blocks = 32 MB.
77  * In 1998 this limit was extended to 65535 bytes/block x 65535 blocks = 4 GB
78  * by TFTP Blocksize Option RFC 2348.
79  */
80 #define FR_TFTP_MAX_FILESIZE (FR_TFTP_BLOCK_MAX_SIZE * FR_TFTP_BLOCK_MAX_SIZE)
81 
82 int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out,
83  uint8_t const *data, size_t data_len) CC_HINT(nonnull(2,3));
84 ssize_t fr_tftp_encode(fr_dbuff_t *dbuff, fr_pair_list_t *vps) CC_HINT(nonnull(1,2));
85 
86 /* base.c */
87 extern char const *fr_tftp_codes[FR_TFTP_MAX_CODE];
89 
90 int fr_tftp_global_init(void);
91 void fr_tftp_global_free(void);
92 
93 #ifdef __cplusplus
94 }
95 #endif
#define RCSIDH(h, id)
Definition: build.h:445
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
#define FR_TFTP_MAX_CODE
Definition: tftp.h:39
char const * fr_tftp_error_codes[FR_TFTP_MAX_ERROR_CODE]
Definition: base.c:80
char const * fr_tftp_codes[FR_TFTP_MAX_CODE]
Definition: base.c:71
int fr_tftp_global_init(void)
Definition: base.c:90
ssize_t fr_tftp_encode(fr_dbuff_t *dbuff, fr_pair_list_t *vps))
Definition: encode.c:75
int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len))
Definition: decode.c:74
void fr_tftp_global_free(void)
Definition: base.c:114
#define FR_TFTP_MAX_ERROR_CODE
Definition: tftp.h:40
static fr_slen_t data
Definition: value.h:1259
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:984