source: trunk/packages/xen-common/xen-common/tools/ioemu/patches/vnc-listen-specific-interface @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

File size: 5.4 KB
Line 
1# HG changeset patch
2# User Christian Limpach <Christian.Limpach@xensource.com>
3# Node ID a95dfbc8dca8ecddcb9be51d78f446b0fa461892
4# Parent  8959876abbe319963974fab21dda7185e0ad84e6
5[HVM/vncserver] Implement a 'vnclisten' option to limit the interface
6that the VNC server from qemu listens on.
7
8Defaults to only listen on 127.0.0.1
9
10The old behaviour (listen on all interfaces) can be restored, by
11- changing the system-wide default in /etc/xen/xend-config.sxp by adding:
12(vnc-listen '0.0.0.0')
13- changing individual domain config files by adding:
14vnclisten="0.0.0.0"
15
16Also allows specifying the hostname associated with an interface to limit
17to that interface.
18
19Signed-off-by:  Daniel P. Berrange <berrange@redhat.com>
20
21Index: ioemu/vl.c
22===================================================================
23--- ioemu.orig/vl.c     2007-05-03 10:24:06.000000000 +0100
24+++ ioemu/vl.c  2007-05-03 10:24:06.000000000 +0100
25@@ -123,6 +123,7 @@
26 int nographic;
27 int vncviewer;
28 int vncunused;
29+struct sockaddr_in vnclisten_addr;
30 const char* keyboard_layout = NULL;
31 int64_t ticks_per_sec;
32 int boot_device = 'c';
33@@ -2831,10 +2832,22 @@
34     return -1;
35 }
36 
37+int parse_host(struct sockaddr_in *saddr, const char *buf)
38+{
39+    struct hostent *he;
40+
41+    if ((he = gethostbyname(buf)) != NULL) {
42+        saddr->sin_addr = *(struct in_addr *)he->h_addr;
43+    } else {
44+        if (!inet_aton(buf, &saddr->sin_addr))
45+            return -1;
46+    }
47+    return 0;
48+}
49+
50 int parse_host_port(struct sockaddr_in *saddr, const char *str)
51 {
52     char buf[512];
53-    struct hostent *he;
54     const char *p, *r;
55     int port;
56 
57@@ -2845,14 +2858,8 @@
58     if (buf[0] == '\0') {
59         saddr->sin_addr.s_addr = 0;
60     } else {
61-        if (isdigit(buf[0])) {
62-            if (!inet_aton(buf, &saddr->sin_addr))
63-                return -1;
64-        } else {
65-            if ((he = gethostbyname(buf)) == NULL)
66-                return - 1;
67-            saddr->sin_addr = *(struct in_addr *)he->h_addr;
68-        }
69+        if (parse_host(saddr, buf) == -1)
70+            return -1;
71     }
72     port = strtol(p, (char **)&r, 0);
73     if (r == p)
74@@ -5419,6 +5426,7 @@
75           "-vnc display    start a VNC server on display\n"
76            "-vncviewer      start a vncviewer process for this domain\n"
77            "-vncunused      bind the VNC server to an unused port\n"
78+           "-vnclisten      bind the VNC server to this address\n"
79            "-acpi           disable or enable ACPI of HVM domain \n"
80            "\n"
81            "During emulation, the following keys are useful:\n"
82@@ -5507,6 +5515,7 @@
83     QEMU_OPTION_acpi,
84     QEMU_OPTION_vncviewer,
85     QEMU_OPTION_vncunused,
86+    QEMU_OPTION_vnclisten,
87 };
88 
89 typedef struct QEMUOption {
90@@ -5583,6 +5592,7 @@
91     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
92     { "vncviewer", 0, QEMU_OPTION_vncviewer },
93     { "vncunused", 0, QEMU_OPTION_vncunused },
94+    { "vnclisten", HAS_ARG, QEMU_OPTION_vnclisten },
95     
96     /* temporary options */
97     { "usb", 0, QEMU_OPTION_usb },
98@@ -5974,6 +5984,8 @@
99 
100     nb_nics = 0;
101     /* default mac address of the first network interface */
102+
103+    memset(&vnclisten_addr.sin_addr, 0, sizeof(vnclisten_addr.sin_addr));
104     
105     /* init debug */
106     sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
107@@ -6346,6 +6358,9 @@
108                 if (vnc_display == -1)
109                     vnc_display = 0;
110                 break;
111+            case QEMU_OPTION_vnclisten:
112+                parse_host(&vnclisten_addr, optarg);
113+                break;
114             }
115         }
116     }
117@@ -6547,7 +6562,7 @@
118     if (nographic) {
119         dumb_display_init(ds);
120     } else if (vnc_display != -1) {
121-       vnc_display = vnc_display_init(ds, vnc_display, vncunused);
122+       vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
123        if (vncviewer)
124            vnc_start_viewer(vnc_display);
125     } else {
126Index: ioemu/vl.h
127===================================================================
128--- ioemu.orig/vl.h     2007-05-03 10:24:06.000000000 +0100
129+++ ioemu/vl.h  2007-05-03 10:24:06.000000000 +0100
130@@ -37,6 +37,8 @@
131 #include <unistd.h>
132 #include <fcntl.h>
133 #include <sys/stat.h>
134+#include <sys/socket.h>
135+#include <sys/types.h>
136 #include "xenctrl.h"
137 #include "xs.h"
138 #include <xen/hvm/e820.h>
139@@ -785,7 +787,7 @@
140 void cocoa_display_init(DisplayState *ds, int full_screen);
141 
142 /* vnc.c */
143-int vnc_display_init(DisplayState *ds, int display, int find_unused);
144+int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr);
145 int vnc_start_viewer(int port);
146 
147 /* ide.c */
148Index: ioemu/vnc.c
149===================================================================
150--- ioemu.orig/vnc.c    2007-05-03 10:24:06.000000000 +0100
151+++ ioemu/vnc.c 2007-05-03 10:24:06.000000000 +0100
152@@ -1197,9 +1197,8 @@
153     }
154 }
155 
156-int vnc_display_init(DisplayState *ds, int display, int find_unused)
157+int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr)
158 {
159-    struct sockaddr_in addr;
160     int reuse_addr, ret;
161     VncState *vs;
162 
163@@ -1237,11 +1236,10 @@
164     }
165 
166  retry:
167-    addr.sin_family = AF_INET;
168-    addr.sin_port = htons(5900 + display);
169-    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
170+    addr->sin_family = AF_INET;
171+    addr->sin_port = htons(5900 + display);
172 
173-    if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
174+    if (bind(vs->lsock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
175        if (find_unused && errno == EADDRINUSE) {
176            display++;
177            goto retry;
Note: See TracBrowser for help on using the repository browser.