tftp for slirp
PATCH 1/1 tftp for slirp
Hi again,
The attached patch adds a simple read-only tftp server to the slirp code. The code is no beauty contest winner, but it works for me(tm). The server is tested against the tftp client shipped with busybox.
Use the command line switch -tftp to add a prefix that should be exported by the server. Using -tftp "/home/d" will export both "/home/damm" and "/home/douglas". The server exports nothing by default.
Cool things to add in the future would be blocksize support and options passing from the bootp/dhcp client...
/ magnus - not subscribed
Makefile.target +1 -1
@@ -260,7 +260,7 @@ DEFINES+=-I$(SRC_PATH)/slirp SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \ slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \ -tcp_subr.o tcp_timer.o udp.o bootp.o debug.o +tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o VL_OBJS+=$(addprefix slirp/, $(SLIRP_OBJS)) endif
slirp/slirp.h +1 -0
@@ -210,6 +210,7 @@#endif #include "bootp.h" +#include "tftp.h" #include "libslirp.h" extern struct ttys *ttys_unit[MAX_INTERFACES ];
slirp/tftp.c +343 -0
343 lines not on this page · raw message
slirp/tftp.h +30 -0
@@ -0,0 +1,30 @@ +/* tftp defines */ + +#define TFTP_SESSIONS_MAX 3 + +#define TFTP_SERVER 69 + +#define TFTP_RRQ 1 +#define TFTP_WRQ 2 +#define TFTP_DATA 3 +#define TFTP_ACK 4 +#define TFTP_ERROR 5 + +#define TFTP_FILENAME_MAX 512 + +struct tftp_t { +struct ip ip; +struct udphdr udp; +u_int16_t tp_op; +union { +struct { +u_int16_t tp_block_nr; +u_int8_t tp_buf[512 ]; + } tp_data; +u_int8_t tp_buf[512 +2 ]; + } x; +}; + +extern char *tftp_prefix; + +void tftp_input (struct mbuf *m);
slirp/udp.c +8 -0
@@ -153,6 +153,14 @@ goto bad; } +/* +* handle TFTP +*/ +if (ntohs (uh->uh_dport) ==TFTP_SERVER ) { +tftp_input (m); + goto bad; + } +/* * Locate pcb for datagram. */
vl.c +11 -0
@@ -2344,6 +2344,7 @@ "-tun-fd fd use this fd as already opened tap/tun interface\n" #ifdef CONFIG_SLIRP "-user-net use user mode network stack [default if no tap/tun script]\n" + "-tftp prefix allow tftp access to files starting with prefix [only with -user-net enabled]\n" #endif"-dummy-net use dummy network stack\n" "\n"
@@ -2418,6 +2419,7 @@ QEMU_OPTION_n, QEMU_OPTION_tun_fd, QEMU_OPTION_user_net, + QEMU_OPTION_tftp, QEMU_OPTION_dummy_net, QEMU_OPTION_kernel,
@@ -2470,6 +2472,7 @@ { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, #ifdef CONFIG_SLIRP { "user-net", 0, QEMU_OPTION_user_net }, + { "tftp", HAS_ARG, QEMU_OPTION_tftp }, #endif { "dummy-net", 0, QEMU_OPTION_dummy_net },
@@ -2719,9 +2722,17 @@ } }break ; +#ifdef CONFIG_SLIRP +case QEMU_OPTION_tftp: + { +extern const char *tftp_prefix; + tftp_prefix = optarg; + } +break ;case QEMU_OPTION_user_net: net_if_type =NET_IF_USER ;break ; +#endif case QEMU_OPTION_dummy_net: net_if_type =NET_IF_DUMMY ;break ;
Quoted 3 lines · Magnus Damm
Hi again,
The attached patch adds a simple read-only tftp server to the slirp
OK, cool, but what does it do?
Are you serving files from the guest, what kinds of guests, etc.
I couldn't figure it out from the description.
-- John.