qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Set hostname in DHCP response
@ 2006-03-10  7:35 Ed Swierk
  2006-03-11 22:19 ` Paul Brook
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Swierk @ 2006-03-10  7:35 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

Here is a patch that sets the hostname in the DHCP response generated
by qemu's user-net DHCP server, and adds a new -hostname command line
option to specify the value.

If the guest OS is configured properly, the value received in the DHCP
response is automatically used to set the machine's hostname. (In Red
Hat/Fedora Linuxes, this happens if HOSTNAME is not hardcoded in
/etc/sysconfig/network.)

Feedback welcome.

--Ed

[-- Attachment #2: qemu-hostname.patch --]
[-- Type: text/x-patch, Size: 2889 bytes --]

diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c qemu-snapshot-2006-03-06_23/slirp/bootp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/bootp.c	2006-03-10 07:11:19.000000000 +0000
@@ -228,6 +228,16 @@
         val = htonl(LEASE_TIME);
         memcpy(q, &val, 4);
         q += 4;
+
+        if (slirp_hostname && *slirp_hostname) {
+            val = strlen(slirp_hostname);
+            if (val > 32)
+                val = 32;
+            *q++ = RFC1533_HOSTNAME;
+            *q++ = val;
+            memcpy(q, slirp_hostname, val);
+            q += val;
+        }
     }
     *q++ = RFC1533_END;
     
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h qemu-snapshot-2006-03-06_23/slirp/libslirp.h
--- qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/libslirp.h	2006-03-10 06:47:32.000000000 +0000
@@ -32,6 +32,7 @@
                    int guest_port);
 
 extern const char *tftp_prefix;
+extern const char *slirp_hostname;
 
 #ifdef __cplusplus
 }
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c qemu-snapshot-2006-03-06_23/slirp/slirp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c	2005-09-03 10:45:09.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/slirp.c	2006-03-10 06:46:28.000000000 +0000
@@ -25,6 +25,8 @@
 /* XXX: suppress those select globals */
 fd_set *global_readfds, *global_writefds, *global_xfds;
 
+const char *slirp_hostname = NULL;
+
 #ifdef _WIN32
 
 static int get_dns_addr(struct in_addr *pdns_addr)
diff -BurN qemu-snapshot-2006-03-06_23.orig/vl.c qemu-snapshot-2006-03-06_23/vl.c
--- qemu-snapshot-2006-03-06_23.orig/vl.c	2006-02-20 00:33:36.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/vl.c	2006-03-10 06:45:32.000000000 +0000
@@ -4183,6 +4183,7 @@
 #endif
            "-redir [tcp|udp]:host-port:[guest-host]:guest-port\n"
            "                redirect TCP or UDP connections from host to guest [-net user]\n"
+           "-hostname name  set hostname in DHCP responses\n"
 #endif
            "\n"
            "Linux boot specific:\n"
@@ -4267,6 +4268,7 @@
     QEMU_OPTION_tftp,
     QEMU_OPTION_smb,
     QEMU_OPTION_redir,
+    QEMU_OPTION_hostname,
 
     QEMU_OPTION_kernel,
     QEMU_OPTION_append,
@@ -4332,6 +4334,7 @@
     { "smb", HAS_ARG, QEMU_OPTION_smb },
 #endif
     { "redir", HAS_ARG, QEMU_OPTION_redir },
+    { "hostname", HAS_ARG, QEMU_OPTION_hostname },
 #endif
 
     { "kernel", HAS_ARG, QEMU_OPTION_kernel },
@@ -4785,6 +4788,9 @@
             case QEMU_OPTION_redir:
                 net_slirp_redir(optarg);                
                 break;
+            case QEMU_OPTION_hostname:
+                slirp_hostname = optarg;
+                break;
 #endif
 #ifdef HAS_AUDIO
             case QEMU_OPTION_audio_help:

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Set hostname in DHCP response
  2006-03-10  7:35 [Qemu-devel] [PATCH] Set hostname in DHCP response Ed Swierk
@ 2006-03-11 22:19 ` Paul Brook
  2006-03-13  2:13   ` Ed Swierk
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Brook @ 2006-03-11 22:19 UTC (permalink / raw)
  To: qemu-devel

On Friday 10 March 2006 07:35, Ed Swierk wrote:
> Here is a patch that sets the hostname in the DHCP response generated
> by qemu's user-net DHCP server, and adds a new -hostname command line
> option to specify the value.

This should be set via -net user,hostname=foo. No need for a separate option.

Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Set hostname in DHCP response
  2006-03-11 22:19 ` Paul Brook
@ 2006-03-13  2:13   ` Ed Swierk
  2006-03-13  2:46     ` Leonardo E. Reiter
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Swierk @ 2006-03-13  2:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: paul

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

On 3/11/06, Paul Brook <paul@codesourcery.com> wrote:
> This should be set via -net user,hostname=foo. No need for a separate option.

I agree, since the hostname is relevant only for user-net interfaces.
An updated patch is attached.

The only issue is that there's just a single, global hostname, not a
hostname per user-net interface. On the other hand, I'm not sure if
qemu supports multiple user-net interfaces in the first place. Does
the following configuration make sense?

    -net nic,vlan=0 -net user,vlan=0 -net nic,vlan=1 -net user,vlan=1

--Ed

[-- Attachment #2: qemu-hostname.patch --]
[-- Type: text/x-patch, Size: 2857 bytes --]

diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c qemu-snapshot-2006-03-06_23/slirp/bootp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/bootp.c	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/bootp.c	2006-03-10 07:11:19.000000000 +0000
@@ -228,6 +228,16 @@
         val = htonl(LEASE_TIME);
         memcpy(q, &val, 4);
         q += 4;
+
+        if (slirp_hostname && *slirp_hostname) {
+            val = strlen(slirp_hostname);
+            if (val > 32)
+                val = 32;
+            *q++ = RFC1533_HOSTNAME;
+            *q++ = val;
+            memcpy(q, slirp_hostname, val);
+            q += val;
+        }
     }
     *q++ = RFC1533_END;
     
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h qemu-snapshot-2006-03-06_23/slirp/libslirp.h
--- qemu-snapshot-2006-03-06_23.orig/slirp/libslirp.h	2005-06-05 17:11:42.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/libslirp.h	2006-03-10 06:47:32.000000000 +0000
@@ -32,6 +32,7 @@
                    int guest_port);
 
 extern const char *tftp_prefix;
+extern const char *slirp_hostname;
 
 #ifdef __cplusplus
 }
diff -BurN qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c qemu-snapshot-2006-03-06_23/slirp/slirp.c
--- qemu-snapshot-2006-03-06_23.orig/slirp/slirp.c	2005-09-03 10:45:09.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/slirp/slirp.c	2006-03-10 06:46:28.000000000 +0000
@@ -25,6 +25,8 @@
 /* XXX: suppress those select globals */
 fd_set *global_readfds, *global_writefds, *global_xfds;
 
+const char *slirp_hostname = NULL;
+
 #ifdef _WIN32
 
 static int get_dns_addr(struct in_addr *pdns_addr)
diff -BurN qemu-snapshot-2006-03-06_23.orig/vl.c qemu-snapshot-2006-03-06_23/vl.c
--- qemu-snapshot-2006-03-06_23.orig/vl.c	2006-02-20 00:33:36.000000000 +0000
+++ qemu-snapshot-2006-03-06_23/vl.c	2006-03-13 01:35:45.000000000 +0000
@@ -2758,6 +2758,12 @@
     } else
 #ifdef CONFIG_SLIRP
     if (!strcmp(device, "user")) {
+        if (get_param_value(buf, sizeof(buf), "hostname", p)) {
+            if (slirp_hostname)
+                fprintf(stderr, "hostname already set; ignoring hostname=%s\n", buf);
+            else
+                slirp_hostname = strdup(buf);
+        }
         ret = net_slirp_init(vlan);
     } else
 #endif
@@ -4157,8 +4163,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]\n"
-           "                connect the user mode network stack to VLAN 'n'\n"
+           "-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"
 #endif
 #ifdef _WIN32
            "-net tap[,vlan=n],ifname=name\n"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Set hostname in DHCP response
  2006-03-13  2:13   ` Ed Swierk
@ 2006-03-13  2:46     ` Leonardo E. Reiter
  0 siblings, 0 replies; 4+ messages in thread
From: Leonardo E. Reiter @ 2006-03-13  2:46 UTC (permalink / raw)
  To: qemu-devel

QEMU doesn't do a great job of supporting multiple user-net interfaces 
right now.  I was testing this the other day and getting some rather odd 
behavior (unexpected segfaults, etc.)  I didn't debug deep enough to 
figure out the specifics, but having a global state (like slirp is 
today) for multiple network providers is probably not a good idea.  I am 
contemplating writing a patch that will change the global state in slirp 
to an actual "opaque" state, even letting various slirp instances be 
configured to serve different subnets, etc.  This would be useful if for 
example you wanted to have 1 slirp interface access only "special" 
services, like smb, etc., and another act as a NAT to the internet.  In 
that case, in theory, stuff like VPN software in the guest OS should 
work without disrupting access to "special" services.  But for something 
like this to truly work, you need to have the ability to configure the 
subnet that slirp sets up _per NIC_, and that would of course mean 
removing the global state as the most obvious (and correct IMHO) solution.

Others will probably argue that you can use a combination of a single 
slirp NIC and a NAT tun/tap set up to accomplish the same basic thing 
today, without any modifications.  Still, the "zero" host configuration 
of slirp makes it very attractive on its own, so I still think the patch 
I'm referring to would be valuable.  I'd also implement an option to 
make slirp return the DNS/gateway in the DHCP packet for only 1 
interface, since guest OS's would probably not like having multiple 
default gateways.  This patch would be useful in a slightly different 
way even if you were trying to combine slirp with tun/tap, and having 
the guest OS configured for DHCP on all interfaces.  For example, you 
may want the guest OS to use the tun/tap interface as the default route, 
so telling the slirp interface to not return a gateway/DNS would 
probably still be a good idea even if you were only using 1 -net user. 
  That patch by itself would be trivial versus the global->local state 
patch I mentioned above, so I can see posting that one much sooner, if 
it even works as I'm expecting it to ;)

Regards,

Leo Reiter

Ed Swierk wrote:
> I agree, since the hostname is relevant only for user-net interfaces.
> An updated patch is attached.
> 
> The only issue is that there's just a single, global hostname, not a
> hostname per user-net interface. On the other hand, I'm not sure if
> qemu supports multiple user-net interfaces in the first place. Does
> the following configuration make sense?
> 
>     -net nic,vlan=0 -net user,vlan=0 -net nic,vlan=1 -net user,vlan=1
> 
> --Ed

-- 
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-13  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-10  7:35 [Qemu-devel] [PATCH] Set hostname in DHCP response Ed Swierk
2006-03-11 22:19 ` Paul Brook
2006-03-13  2:13   ` Ed Swierk
2006-03-13  2:46     ` Leonardo E. Reiter

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).