blob: a4c4a64e641b5e8e9d09901367eeb8ae8e83e7c7 [file] [log] [blame]
bellardc7f74642004-08-24 21:57:12 +00001/* tftp defines */
Markus Armbruster175de522016-06-29 15:29:06 +02002
Paolo Bonzinicb9c3772012-12-06 12:15:58 +01003#ifndef SLIRP_TFTP_H
Markus Armbruster175de522016-06-29 15:29:06 +02004#define SLIRP_TFTP_H
bellardc7f74642004-08-24 21:57:12 +00005
Bernhard Übelacker5f22b052014-06-21 15:26:05 +02006#define TFTP_SESSIONS_MAX 20
bellardc7f74642004-08-24 21:57:12 +00007
8#define TFTP_SERVER 69
9
10#define TFTP_RRQ 1
11#define TFTP_WRQ 2
12#define TFTP_DATA 3
13#define TFTP_ACK 4
14#define TFTP_ERROR 5
ths1f697db2007-02-20 00:07:50 +000015#define TFTP_OACK 6
bellardc7f74642004-08-24 21:57:12 +000016
17#define TFTP_FILENAME_MAX 512
Hervé Poussineau94435982016-11-21 20:45:49 +010018#define TFTP_BLOCKSIZE_MAX 1428
bellardc7f74642004-08-24 21:57:12 +000019
20struct tftp_t {
bellardc7f74642004-08-24 21:57:12 +000021 struct udphdr udp;
Stefan Weilb6dce922010-07-22 22:15:23 +020022 uint16_t tp_op;
bellardc7f74642004-08-24 21:57:12 +000023 union {
ths5fafdf22007-09-16 21:08:06 +000024 struct {
Stefan Weilb6dce922010-07-22 22:15:23 +020025 uint16_t tp_block_nr;
Hervé Poussineau94435982016-11-21 20:45:49 +010026 uint8_t tp_buf[TFTP_BLOCKSIZE_MAX];
bellardc7f74642004-08-24 21:57:12 +000027 } tp_data;
ths5fafdf22007-09-16 21:08:06 +000028 struct {
Stefan Weilb6dce922010-07-22 22:15:23 +020029 uint16_t tp_error_code;
Hervé Poussineau94435982016-11-21 20:45:49 +010030 uint8_t tp_msg[TFTP_BLOCKSIZE_MAX];
bellardc7f74642004-08-24 21:57:12 +000031 } tp_error;
Hervé Poussineau94435982016-11-21 20:45:49 +010032 char tp_buf[TFTP_BLOCKSIZE_MAX + 2];
bellardc7f74642004-08-24 21:57:12 +000033 } x;
Thomas Huthfad7fb92016-03-15 10:31:23 +010034} __attribute__((packed));
bellardc7f74642004-08-24 21:57:12 +000035
Jan Kiszka460fec62009-06-24 14:42:31 +020036struct tftp_session {
37 Slirp *slirp;
38 char *filename;
Hervé Poussineau78be0562012-09-10 20:52:25 +020039 int fd;
Hervé Poussineau94435982016-11-21 20:45:49 +010040 uint16_t block_size;
Jan Kiszka460fec62009-06-24 14:42:31 +020041
Thomas Huthfad7fb92016-03-15 10:31:23 +010042 struct sockaddr_storage client_addr;
Stefan Weilb6dce922010-07-22 22:15:23 +020043 uint16_t client_port;
Hervé Poussineau4aa401f2012-09-13 12:39:36 +020044 uint32_t block_nr;
Jan Kiszka460fec62009-06-24 14:42:31 +020045
46 int timestamp;
47};
48
Thomas Huthfad7fb92016-03-15 10:31:23 +010049void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m);
Paolo Bonzinicb9c3772012-12-06 12:15:58 +010050
51#endif