mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
slirp: Rework external configuration interface
With the internal IP configuration made more flexible, we can now enhance the user interface. This patch adds a number of new options to "-net user": net (address and mask), host, dhcpstart, dns and smbserver. It also renames "redir" to "hostfwd" and "channel" to "guestfwd" in order to (hopefully) clarify their meanings. The format of guestfwd is extended so that the user can define not only the port but also the virtual server's IP address the forwarding starts from. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
committed by
Anthony Liguori
parent
a13a4126c8
commit
c92ef6a22d
+34
-18
@@ -749,10 +749,11 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
|
||||
"-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n"
|
||||
" create a new Network Interface Card and connect it to VLAN 'n'\n"
|
||||
#ifdef CONFIG_SLIRP
|
||||
"-net user[,vlan=n][,name=str][ip=netaddr][,restrict=y|n][,hostname=host]\n"
|
||||
" [,tftp=dir][,bootfile=f][,redir=rule][,channel=rule]"
|
||||
"-net user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=y|n]\n"
|
||||
" [,hostname=host][,dhcpstart=addr][,dns=addr][,tftp=dir][,bootfile=f]\n"
|
||||
" [,hostfwd=rule][,guestfwd=rule]"
|
||||
#ifndef _WIN32
|
||||
"[,smb=dir]\n"
|
||||
"[,smb=dir[,smbserver=addr]]\n"
|
||||
#endif
|
||||
" connect the user mode network stack to VLAN 'n', configure its\n"
|
||||
" DHCP server and enabled optional services\n"
|
||||
@@ -819,8 +820,14 @@ Connect user mode stack to VLAN @var{n} (@var{n} = 0 is the default).
|
||||
@item name=@var{name}
|
||||
Assign symbolic name for use in monitor commands.
|
||||
|
||||
@item ip=@var{netaddr}
|
||||
Set IP network address the guest will see (default: 10.0.2.x).
|
||||
@item net=@var{addr}[/@var{mask}]
|
||||
Set IP network address the guest will see. Optionally specify the netmask,
|
||||
either in the form a.b.c.d or as number of valid top-most bits. Default is
|
||||
10.0.2.0/8.
|
||||
|
||||
@item host=@var{addr}
|
||||
Specify the guest-visible address of the host. Default is the 2nd IP in the
|
||||
guest network, i.e. x.x.x.2.
|
||||
|
||||
@item restrict=y|yes|n|no
|
||||
If this options is enabled, the guest will be isolated, i.e. it will not be
|
||||
@@ -830,12 +837,20 @@ to the outside. This option does not affect explicitly set forwarding rule.
|
||||
@item hostname=@var{name}
|
||||
Specifies the client hostname reported by the builtin DHCP server.
|
||||
|
||||
@item dhcpstart=@var{addr}
|
||||
Specify the first of the 16 IPs the built-in DHCP server can assign. Default
|
||||
is the 16th to 31st IP in the guest network, i.e. x.x.x.16 to x.x.x.31.
|
||||
|
||||
@item dns=@var{addr}
|
||||
Specify the guest-visible address of the virtual nameserver. The address must
|
||||
be different from the host address. Default is the 3rd IP in the guest network,
|
||||
i.e. x.x.x.3.
|
||||
|
||||
@item tftp=@var{dir}
|
||||
When using the user mode network stack, activate a built-in TFTP
|
||||
server. The files in @var{dir} will be exposed as the root of a TFTP server.
|
||||
The TFTP client on the guest must be configured in binary mode (use the command
|
||||
@code{bin} of the Unix TFTP client). The host IP address on the guest is
|
||||
10.0.2.2 by default.
|
||||
@code{bin} of the Unix TFTP client).
|
||||
|
||||
@item bootfile=@var{file}
|
||||
When using the user mode network stack, broadcast @var{file} as the BOOTP
|
||||
@@ -847,10 +862,11 @@ Example (using pxelinux):
|
||||
qemu -hda linux.img -boot n -net user,tftp=/path/to/tftp/files,bootfile=/pxelinux.0
|
||||
@end example
|
||||
|
||||
@item smb=@var{dir}
|
||||
@item smb=@var{dir}[,smbserver=@var{addr}]
|
||||
When using the user mode network stack, activate a built-in SMB
|
||||
server so that Windows OSes can access to the host files in @file{@var{dir}}
|
||||
transparently.
|
||||
transparently. The IP address of the SMB server can be set to @var{addr}. By
|
||||
default the 4th IP in the guest network is used, i.e. x.x.x.4.
|
||||
|
||||
In the guest Windows OS, the line:
|
||||
@example
|
||||
@@ -865,19 +881,19 @@ Note that a SAMBA server must be installed on the host OS in
|
||||
@file{/usr/sbin/smbd}. QEMU was tested successfully with smbd versions from
|
||||
Red Hat 9, Fedora Core 3 and OpenSUSE 11.x.
|
||||
|
||||
@item redir=[tcp|udp]:@var{host-port}:[@var{guest-host}]:@var{guest-port}
|
||||
Redirect incoming TCP or UDP connections to the host port @var{host-port} to
|
||||
the guest @var{guest-host} on guest port @var{guest-port}. If @var{guest-host}
|
||||
is not specified, its value is 10.0.2.15 (default address given by the built-in
|
||||
DHCP server). If no connection type is specified, TCP is used. This option can
|
||||
be given multiple times.
|
||||
@item hostfwd=[tcp|udp]:@var{hostport}:[@var{guestaddr}]:@var{guestport}
|
||||
Redirect incoming TCP or UDP connections to the host port @var{hostport} to
|
||||
the guest IP address @var{guestaddr} on guest port @var{guestport}. If
|
||||
@var{guestaddr} is not specified, its value is x.x.x.15 (default first address
|
||||
given by the built-in DHCP server). If no connection type is specified, TCP is
|
||||
used. This option can be given multiple times.
|
||||
|
||||
For example, to redirect host X11 connection from screen 1 to guest
|
||||
screen 0, use the following:
|
||||
|
||||
@example
|
||||
# on the host
|
||||
qemu -net user,redir=tcp:6001::6000 [...]
|
||||
qemu -net user,hostfwd=tcp:6001::6000 [...]
|
||||
# this host xterm should open in the guest X11 server
|
||||
xterm -display :1
|
||||
@end example
|
||||
@@ -887,14 +903,14 @@ the guest, use the following:
|
||||
|
||||
@example
|
||||
# on the host
|
||||
qemu -net user,redir=tcp:5555::23 [...]
|
||||
qemu -net user,hostfwd=tcp:5555::23 [...]
|
||||
telnet localhost 5555
|
||||
@end example
|
||||
|
||||
Then when you use on the host @code{telnet localhost 5555}, you
|
||||
connect to the guest telnet server.
|
||||
|
||||
@item channel=@var{port}:@var{dev}
|
||||
@item guestfwd=[tcp]:@var{server}:@var{port}-@var{dev}
|
||||
Forward guest TCP connections to port @var{port} on the host to character
|
||||
device @var{dev}. This option can be given multiple times.
|
||||
|
||||
|
||||
+13
-11
@@ -5,8 +5,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void slirp_init(int restricted, const char *special_ip, const char *tftp_path,
|
||||
const char *bootfile);
|
||||
void slirp_init(int restricted, struct in_addr vnetwork,
|
||||
struct in_addr vnetmask, struct in_addr vhost,
|
||||
const char *vhostname, const char *tftp_path,
|
||||
const char *bootfile, struct in_addr vdhcp_start,
|
||||
struct in_addr vnameserver);
|
||||
|
||||
void slirp_select_fill(int *pnfds,
|
||||
fd_set *readfds, fd_set *writefds, fd_set *xfds);
|
||||
@@ -19,18 +22,17 @@ void slirp_input(const uint8_t *pkt, int pkt_len);
|
||||
int slirp_can_output(void);
|
||||
void slirp_output(const uint8_t *pkt, int pkt_len);
|
||||
|
||||
int slirp_redir_rm(int is_udp, int host_port);
|
||||
int slirp_redir(int is_udp, int host_port,
|
||||
struct in_addr guest_addr, int guest_port);
|
||||
int slirp_add_exec(int do_pty, const void *args, int addr_low_byte,
|
||||
int slirp_add_hostfwd(int is_udp, int host_port,
|
||||
struct in_addr guest_addr, int guest_port);
|
||||
int slirp_remove_hostfwd(int is_udp, int host_port);
|
||||
|
||||
int slirp_add_exec(int do_pty, const void *args, struct in_addr guest_addr,
|
||||
int guest_port);
|
||||
|
||||
extern char slirp_hostname[33];
|
||||
|
||||
void slirp_stats(void);
|
||||
void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
|
||||
int size);
|
||||
size_t slirp_socket_can_recv(int addr_low_byte, int guest_port);
|
||||
void slirp_socket_recv(struct in_addr guest_addr, int guest_port,
|
||||
const uint8_t *buf, int size);
|
||||
size_t slirp_socket_can_recv(struct in_addr guest_addr, int guest_port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ extern int ppp_exit;
|
||||
extern int tcp_keepintvl;
|
||||
extern uint8_t client_ethaddr[6];
|
||||
extern int slirp_restrict;
|
||||
extern char slirp_hostname[33];
|
||||
extern char *tftp_prefix;
|
||||
extern char *bootp_filename;
|
||||
|
||||
|
||||
+24
-28
@@ -173,12 +173,14 @@ static void slirp_cleanup(void)
|
||||
static void slirp_state_save(QEMUFile *f, void *opaque);
|
||||
static int slirp_state_load(QEMUFile *f, void *opaque, int version_id);
|
||||
|
||||
void slirp_init(int restricted, const char *special_ip, const char *tftp_path,
|
||||
const char *bootfile)
|
||||
void slirp_init(int restricted, struct in_addr vnetwork,
|
||||
struct in_addr vnetmask, struct in_addr vhost,
|
||||
const char *vhostname, const char *tftp_path,
|
||||
const char *bootfile, struct in_addr vdhcp_start,
|
||||
struct in_addr vnameserver)
|
||||
{
|
||||
// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
|
||||
|
||||
struct in_addr special_addr = { .s_addr = htonl(0x0a000200) };
|
||||
#ifdef _WIN32
|
||||
WSADATA Data;
|
||||
|
||||
@@ -203,8 +205,11 @@ void slirp_init(int restricted, const char *special_ip, const char *tftp_path,
|
||||
fprintf (stderr, "Warning: No DNS servers found\n");
|
||||
}
|
||||
|
||||
if (special_ip) {
|
||||
inet_aton(special_ip, &special_addr);
|
||||
vnetwork_addr = vnetwork;
|
||||
vnetwork_mask = vnetmask;
|
||||
vhost_addr = vhost;
|
||||
if (vhostname) {
|
||||
pstrcpy(slirp_hostname, sizeof(slirp_hostname), vhostname);
|
||||
}
|
||||
qemu_free(tftp_prefix);
|
||||
tftp_prefix = NULL;
|
||||
@@ -216,12 +221,9 @@ void slirp_init(int restricted, const char *special_ip, const char *tftp_path,
|
||||
if (bootfile) {
|
||||
bootp_filename = qemu_strdup(bootfile);
|
||||
}
|
||||
vdhcp_startaddr = vdhcp_start;
|
||||
vnameserver_addr = vnameserver;
|
||||
|
||||
vnetwork_addr = special_addr;
|
||||
vnetwork_mask.s_addr = htonl(0xffffff00);
|
||||
vhost_addr.s_addr = special_addr.s_addr | htonl(2);
|
||||
vdhcp_startaddr.s_addr = special_addr.s_addr | htonl(15);
|
||||
vnameserver_addr.s_addr = special_addr.s_addr | htonl(3);
|
||||
getouraddr();
|
||||
register_savevm("slirp", 0, 1, slirp_state_save, slirp_state_load, NULL);
|
||||
}
|
||||
@@ -755,7 +757,7 @@ void if_encap(const uint8_t *ip_data, int ip_data_len)
|
||||
/* Unlistens a redirection
|
||||
*
|
||||
* Return value: number of redirs removed */
|
||||
int slirp_redir_rm(int is_udp, int host_port)
|
||||
int slirp_remove_hostfwd(int is_udp, int host_port)
|
||||
{
|
||||
struct socket *so;
|
||||
struct socket *head = (is_udp ? &udb : &tcb);
|
||||
@@ -775,8 +777,8 @@ int slirp_redir_rm(int is_udp, int host_port)
|
||||
return n;
|
||||
}
|
||||
|
||||
int slirp_redir(int is_udp, int host_port,
|
||||
struct in_addr guest_addr, int guest_port)
|
||||
int slirp_add_hostfwd(int is_udp, int host_port,
|
||||
struct in_addr guest_addr, int guest_port)
|
||||
{
|
||||
if (!guest_addr.s_addr) {
|
||||
guest_addr = vdhcp_startaddr;
|
||||
@@ -793,13 +795,13 @@ int slirp_redir(int is_udp, int host_port,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int slirp_add_exec(int do_pty, const void *args, int addr_low_byte,
|
||||
int guest_port)
|
||||
int slirp_add_exec(int do_pty, const void *args, struct in_addr guest_addr,
|
||||
int guest_port)
|
||||
{
|
||||
struct in_addr guest_addr = {
|
||||
.s_addr = vnetwork_addr.s_addr | htonl(addr_low_byte)
|
||||
};
|
||||
|
||||
if (!guest_addr.s_addr) {
|
||||
guest_addr.s_addr =
|
||||
vnetwork_addr.s_addr | (htonl(0x0204) & ~vnetwork_mask.s_addr);
|
||||
}
|
||||
if ((guest_addr.s_addr & vnetwork_mask.s_addr) != vnetwork_addr.s_addr ||
|
||||
guest_addr.s_addr == vhost_addr.s_addr ||
|
||||
guest_addr.s_addr == vnameserver_addr.s_addr) {
|
||||
@@ -833,11 +835,8 @@ slirp_find_ctl_socket(struct in_addr guest_addr, int guest_port)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t slirp_socket_can_recv(int addr_low_byte, int guest_port)
|
||||
size_t slirp_socket_can_recv(struct in_addr guest_addr, int guest_port)
|
||||
{
|
||||
struct in_addr guest_addr = {
|
||||
.s_addr = vnetwork_addr.s_addr | htonl(addr_low_byte)
|
||||
};
|
||||
struct iovec iov[2];
|
||||
struct socket *so;
|
||||
|
||||
@@ -855,13 +854,10 @@ size_t slirp_socket_can_recv(int addr_low_byte, int guest_port)
|
||||
return sopreprbuf(so, iov, NULL);
|
||||
}
|
||||
|
||||
void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
|
||||
int size)
|
||||
void slirp_socket_recv(struct in_addr guest_addr, int guest_port,
|
||||
const uint8_t *buf, int size)
|
||||
{
|
||||
int ret;
|
||||
struct in_addr guest_addr = {
|
||||
.s_addr = vnetwork_addr.s_addr | htonl(addr_low_byte)
|
||||
};
|
||||
struct socket *so = slirp_find_ctl_socket(guest_addr, guest_port);
|
||||
|
||||
if (!so)
|
||||
|
||||
Reference in New Issue
Block a user