From: "Ed Swierk" <eswierk@arastra.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Allow user to configure -net user subnet
Date: Wed, 3 May 2006 15:33:51 -0700 [thread overview]
Message-ID: <c1bf1cf0605031533p1671e25ejf3b71b71649a2af1@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
In environments where the 10.0.2.0/24 subnet is already used for
another purpose, it's useful to be able to configure a different -net
user (slirp) subnet, such as 192.168.100.0/24.
The attached patch adds a subnet option to -user net. Currently only
/24 subnets (mask 255.255.255.0) are accepted. An error is generated
if the specified subnet is not of the form XX.YY.ZZ.0/24. This
restriction could be relaxed in the future with more extensive changes
to slirp.
One quirk is that the default guest-host for the -redir option remains
10.0.2.15 even if the user passes a different subnet to -net user.
Obviously this can be worked around by explicitly specifying the
correct guest-host. The next patch (qemu-slirp-options.patch) fixes
this issue, among others.
--Ed
[-- Attachment #2: qemu-slirp-subnet-option.patch --]
[-- Type: text/x-patch, Size: 3438 bytes --]
diff -BurN qemu.orig/slirp/libslirp.h qemu/slirp/libslirp.h
--- qemu.orig/slirp/libslirp.h 2006-05-01 16:05:27.000000000 +0000
+++ qemu/slirp/libslirp.h 2006-05-02 17:27:59.000000000 +0000
@@ -13,6 +13,8 @@
extern "C" {
#endif
+#include "ctl.h"
+
void slirp_init(void);
void slirp_select_fill(int *pnfds,
@@ -33,6 +35,8 @@
extern const char *tftp_prefix;
extern char slirp_hostname[33];
+extern struct in_addr special_addr;
+extern struct in_addr alias_addr;
#ifdef __cplusplus
}
diff -BurN qemu.orig/slirp/main.h qemu/slirp/main.h
--- qemu.orig/slirp/main.h 2006-05-02 17:27:34.000000000 +0000
+++ qemu/slirp/main.h 2006-05-02 17:27:59.000000000 +0000
@@ -33,8 +33,6 @@
extern u_int curtime;
extern fd_set *global_readfds, *global_writefds, *global_xfds;
extern struct in_addr ctl_addr;
-extern struct in_addr special_addr;
-extern struct in_addr alias_addr;
extern struct in_addr our_addr;
extern struct in_addr loopback_addr;
extern struct in_addr dns_addr;
diff -BurN qemu.orig/slirp/slirp.c qemu/slirp/slirp.c
--- qemu.orig/slirp/slirp.c 2006-05-02 17:27:34.000000000 +0000
+++ qemu/slirp/slirp.c 2006-05-02 17:27:59.000000000 +0000
@@ -155,8 +155,6 @@
fprintf (stderr, "Warning: No DNS servers found\n");
}
- inet_aton(CTL_SPECIAL, &special_addr);
- alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
getouraddr();
}
diff -BurN qemu.orig/vl.c qemu/vl.c
--- qemu.orig/vl.c 2006-05-01 16:05:27.000000000 +0000
+++ qemu/vl.c 2006-05-02 17:28:44.000000000 +0000
@@ -2400,7 +2400,7 @@
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
goto fail;
if (buf[0] == '\0') {
- pstrcpy(buf, sizeof(buf), "10.0.2.15");
+ pstrcpy(buf, sizeof(buf), CTL_LOCAL);
}
if (!inet_aton(buf, &guest_addr))
goto fail;
@@ -3170,6 +3170,22 @@
} else
#ifdef CONFIG_SLIRP
if (!strcmp(device, "user")) {
+ if (get_param_value(buf, sizeof(buf), "subnet", p)) {
+ char *len;
+ len = strchr(buf, 0) - 3;
+ if (len < buf || strcmp(len, "/24")) {
+ fprintf(stderr, "qemu: invalid subnet=%s (mask must be /24)\n", buf);
+ return -1;
+ }
+ *len = 0;
+ } else {
+ pstrcpy(buf, sizeof(buf), CTL_SPECIAL);
+ }
+ if (!inet_aton(buf, &special_addr) || (ntohl(special_addr.s_addr) & 0xff)) {
+ fprintf(stderr, "qemu: invalid subnet=%s\n", buf);
+ return -1;
+ }
+ alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
if (get_param_value(buf, sizeof(buf), "hostname", p)) {
pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
}
@@ -4628,9 +4644,9 @@
"-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
" create a new Network Interface Card and connect it to VLAN 'n'\n"
#ifdef CONFIG_SLIRP
- "-net user[,vlan=n][,hostname=host]\n"
- " connect the user mode network stack to VLAN 'n' and send\n"
- " hostname 'host' to DHCP clients\n"
+ "-net user[,vlan=n][,hostname=host][,subnet=addr/24]\n"
+ " connect the user mode network stack to VLAN 'n'; send\n"
+ " hostname 'host' to DHCP clients; use subnet addr\n"
#endif
#ifdef _WIN32
"-net tap[,vlan=n],ifname=name\n"
reply other threads:[~2006-05-03 22:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1bf1cf0605031533p1671e25ejf3b71b71649a2af1@mail.gmail.com \
--to=eswierk@arastra.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).