ia64/xen-unstable

changeset 11751:a95dfbc8dca8

[HVM/vncserver] Implement a 'vnclisten' option to limit the interface
that the VNC server from qemu listens on.

Defaults to only listen on 127.0.0.1

The old behaviour (listen on all interfaces) can be restored, by
- changing the system-wide default in /etc/xen/xend-config.sxp by adding:
(vnc-listen '0.0.0.0')
- changing individual domain config files by adding:
vnclisten="0.0.0.0"

Also allows specifying the hostname associated with an interface to limit
to that interface.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Christian Limpach <Christian.Limpach@xensource.com>
date Thu Oct 05 14:53:29 2006 +0100 (2006-10-05)
parents 8959876abbe3
children b3cba293e61a
files tools/examples/xend-config.sxp tools/examples/xmexample.hvm tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c tools/python/xen/xend/XendRoot.py tools/python/xen/xend/image.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/examples/xend-config.sxp	Thu Oct 05 14:07:57 2006 +0100
     1.2 +++ b/tools/examples/xend-config.sxp	Thu Oct 05 14:53:29 2006 +0100
     1.3 @@ -130,3 +130,8 @@
     1.4  
     1.5  # The tool used for initiating virtual TPM migration
     1.6  #(external-migration-tool '')
     1.7 +
     1.8 +# The interface for VNC servers to listen on. Defaults
     1.9 +# to 127.0.0.1  To restore old 'listen everywhere' behaviour
    1.10 +# set this to 0.0.0.0
    1.11 +#(vnc-listen '127.0.0.1')
     2.1 --- a/tools/examples/xmexample.hvm	Thu Oct 05 14:07:57 2006 +0100
     2.2 +++ b/tools/examples/xmexample.hvm	Thu Oct 05 14:53:29 2006 +0100
     2.3 @@ -132,6 +132,11 @@ sdl=0
     2.4  vnc=1
     2.5  
     2.6  #----------------------------------------------------------------------------
     2.7 +# address that should be listened on for the VNC server if vnc is set.
     2.8 +# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp
     2.9 +#vnclisten="127.0.0.1"
    2.10 +
    2.11 +#----------------------------------------------------------------------------
    2.12  # set VNC display number, default = domid
    2.13  #vncdisplay=1
    2.14  
     3.1 --- a/tools/ioemu/vl.c	Thu Oct 05 14:07:57 2006 +0100
     3.2 +++ b/tools/ioemu/vl.c	Thu Oct 05 14:53:29 2006 +0100
     3.3 @@ -122,6 +122,7 @@ static DisplayState display_state;
     3.4  int nographic;
     3.5  int vncviewer;
     3.6  int vncunused;
     3.7 +struct sockaddr_in vnclisten_addr;
     3.8  const char* keyboard_layout = NULL;
     3.9  int64_t ticks_per_sec;
    3.10  char *boot_device = NULL;
    3.11 @@ -2783,10 +2784,22 @@ fail:
    3.12      return -1;
    3.13  }
    3.14  
    3.15 +int parse_host(struct sockaddr_in *saddr, const char *buf)
    3.16 +{
    3.17 +    struct hostent *he;
    3.18 +
    3.19 +    if ((he = gethostbyname(buf)) != NULL) {
    3.20 +        saddr->sin_addr = *(struct in_addr *)he->h_addr;
    3.21 +    } else {
    3.22 +        if (!inet_aton(buf, &saddr->sin_addr))
    3.23 +            return -1;
    3.24 +    }
    3.25 +    return 0;
    3.26 +}
    3.27 +
    3.28  int parse_host_port(struct sockaddr_in *saddr, const char *str)
    3.29  {
    3.30      char buf[512];
    3.31 -    struct hostent *he;
    3.32      const char *p, *r;
    3.33      int port;
    3.34  
    3.35 @@ -2797,14 +2810,8 @@ int parse_host_port(struct sockaddr_in *
    3.36      if (buf[0] == '\0') {
    3.37          saddr->sin_addr.s_addr = 0;
    3.38      } else {
    3.39 -        if (isdigit(buf[0])) {
    3.40 -            if (!inet_aton(buf, &saddr->sin_addr))
    3.41 -                return -1;
    3.42 -        } else {
    3.43 -            if ((he = gethostbyname(buf)) == NULL)
    3.44 -                return - 1;
    3.45 -            saddr->sin_addr = *(struct in_addr *)he->h_addr;
    3.46 -        }
    3.47 +        if (parse_host(&saddr, buf) == -1)
    3.48 +            return -1;
    3.49      }
    3.50      port = strtol(p, (char **)&r, 0);
    3.51      if (r == p)
    3.52 @@ -5352,6 +5359,7 @@ void help(void)
    3.53  	   "-vnc display    start a VNC server on display\n"
    3.54             "-vncviewer      start a vncviewer process for this domain\n"
    3.55             "-vncunused      bind the VNC server to an unused port\n"
    3.56 +           "-vnclisten      bind the VNC server to this address\n"
    3.57             "-timeoffset     time offset (in seconds) from local time\n"
    3.58             "-acpi           disable or enable ACPI of HVM domain \n"
    3.59             "\n"
    3.60 @@ -5444,6 +5452,7 @@ enum {
    3.61      QEMU_OPTION_acpi,
    3.62      QEMU_OPTION_vncviewer,
    3.63      QEMU_OPTION_vncunused,
    3.64 +    QEMU_OPTION_vnclisten,
    3.65  };
    3.66  
    3.67  typedef struct QEMUOption {
    3.68 @@ -5522,6 +5531,7 @@ const QEMUOption qemu_options[] = {
    3.69      { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    3.70      { "vncviewer", 0, QEMU_OPTION_vncviewer },
    3.71      { "vncunused", 0, QEMU_OPTION_vncunused },
    3.72 +    { "vnclisten", HAS_ARG, QEMU_OPTION_vnclisten },
    3.73      
    3.74      /* temporary options */
    3.75      { "usb", 0, QEMU_OPTION_usb },
    3.76 @@ -5928,6 +5938,8 @@ int main(int argc, char **argv)
    3.77  
    3.78      nb_nics = 0;
    3.79      /* default mac address of the first network interface */
    3.80 +
    3.81 +    memset(&vnclisten_addr.sin_addr, 0, sizeof(vnclisten_addr.sin_addr));
    3.82      
    3.83      /* init debug */
    3.84      sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
    3.85 @@ -6312,6 +6324,9 @@ int main(int argc, char **argv)
    3.86                  if (vnc_display == -1)
    3.87                      vnc_display = 0;
    3.88                  break;
    3.89 +            case QEMU_OPTION_vnclisten:
    3.90 +                parse_host(&vnclisten_addr, optarg);
    3.91 +                break;
    3.92              }
    3.93          }
    3.94      }
    3.95 @@ -6548,7 +6563,7 @@ int main(int argc, char **argv)
    3.96      if (nographic) {
    3.97          dumb_display_init(ds);
    3.98      } else if (vnc_display != -1) {
    3.99 -	vnc_display = vnc_display_init(ds, vnc_display, vncunused);
   3.100 +	vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
   3.101  	if (vncviewer)
   3.102  	    vnc_start_viewer(vnc_display);
   3.103  	xenstore_write_vncport(vnc_display);
     4.1 --- a/tools/ioemu/vl.h	Thu Oct 05 14:07:57 2006 +0100
     4.2 +++ b/tools/ioemu/vl.h	Thu Oct 05 14:53:29 2006 +0100
     4.3 @@ -37,6 +37,8 @@
     4.4  #include <unistd.h>
     4.5  #include <fcntl.h>
     4.6  #include <sys/stat.h>
     4.7 +#include <sys/socket.h>
     4.8 +#include <sys/types.h>
     4.9  #include "xenctrl.h"
    4.10  #include "xs.h"
    4.11  #include <xen/hvm/e820.h>
    4.12 @@ -786,7 +788,7 @@ void sdl_display_init(DisplayState *ds, 
    4.13  void cocoa_display_init(DisplayState *ds, int full_screen);
    4.14  
    4.15  /* vnc.c */
    4.16 -int vnc_display_init(DisplayState *ds, int display, int find_unused);
    4.17 +int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr);
    4.18  int vnc_start_viewer(int port);
    4.19  
    4.20  /* ide.c */
     5.1 --- a/tools/ioemu/vnc.c	Thu Oct 05 14:07:57 2006 +0100
     5.2 +++ b/tools/ioemu/vnc.c	Thu Oct 05 14:53:29 2006 +0100
     5.3 @@ -1250,9 +1250,8 @@ static void vnc_listen_read(void *opaque
     5.4      }
     5.5  }
     5.6  
     5.7 -int vnc_display_init(DisplayState *ds, int display, int find_unused)
     5.8 +int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sockaddr_in *addr)
     5.9  {
    5.10 -    struct sockaddr_in addr;
    5.11      int reuse_addr, ret;
    5.12      VncState *vs;
    5.13  
    5.14 @@ -1290,11 +1289,10 @@ int vnc_display_init(DisplayState *ds, i
    5.15      }
    5.16  
    5.17   retry:
    5.18 -    addr.sin_family = AF_INET;
    5.19 -    addr.sin_port = htons(5900 + display);
    5.20 -    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
    5.21 +    addr->sin_family = AF_INET;
    5.22 +    addr->sin_port = htons(5900 + display);
    5.23  
    5.24 -    if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    5.25 +    if (bind(vs->lsock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
    5.26  	if (find_unused && errno == EADDRINUSE) {
    5.27  	    display++;
    5.28  	    goto retry;
     6.1 --- a/tools/python/xen/xend/XendRoot.py	Thu Oct 05 14:07:57 2006 +0100
     6.2 +++ b/tools/python/xen/xend/XendRoot.py	Thu Oct 05 14:53:29 2006 +0100
     6.3 @@ -96,6 +96,9 @@ class XendRoot:
     6.4  
     6.5      dom0_vcpus_default = '0'
     6.6  
     6.7 +    """Default interface to listen for VNC connections on"""
     6.8 +    xend_vnc_listen_default = '127.0.0.1'
     6.9 +
    6.10      components = {}
    6.11  
    6.12      def __init__(self):
    6.13 @@ -272,6 +275,9 @@ class XendRoot:
    6.14      def get_console_limit(self):
    6.15          return self.get_config_int('console-limit', 1024)
    6.16  
    6.17 +    def get_vnclisten_address(self):
    6.18 +        return self.get_config_value('vnc-listen', self.xend_vnc_listen_default)
    6.19 +
    6.20  def instance():
    6.21      """Get an instance of XendRoot.
    6.22      Use this instead of the constructor.
     7.1 --- a/tools/python/xen/xend/image.py	Thu Oct 05 14:07:57 2006 +0100
     7.2 +++ b/tools/python/xen/xend/image.py	Thu Oct 05 14:53:29 2006 +0100
     7.3 @@ -361,6 +361,11 @@ class HVMImageHandler(ImageHandler):
     7.4              else:
     7.5                  ret += ['-vnc', '%d' % vncdisplay]
     7.6              ret += ['-k', 'en-us']
     7.7 +            vnclisten = sxp.child_value(config, 'vnclisten')
     7.8 +            if not(vnclisten):
     7.9 +                vnclisten = xen.xend.XendRoot.instance().get_vnclisten_address()
    7.10 +            if vnclisten:
    7.11 +                ret += ['-vnclisten', vnclisten]
    7.12          return ret
    7.13  
    7.14      def createDeviceModel(self):
     8.1 --- a/tools/python/xen/xm/create.py	Thu Oct 05 14:07:57 2006 +0100
     8.2 +++ b/tools/python/xen/xm/create.py	Thu Oct 05 14:53:29 2006 +0100
     8.3 @@ -415,6 +415,10 @@ gopts.var('vncdisplay', val='',
     8.4            fn=set_value, default=None,
     8.5            use="""VNC display to use""")
     8.6  
     8.7 +gopts.var('vnclisten', val='',
     8.8 +          fn=set_value, default=None,
     8.9 +          use="""Address for VNC server to listen on.""")
    8.10 +
    8.11  gopts.var('vncunused', val='',
    8.12            fn=set_bool, default=1,
    8.13            use="""Try to find an unused port for the VNC server.
    8.14 @@ -633,8 +637,9 @@ def configure_hvm(config_image, vals):
    8.15      """
    8.16      args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
    8.17               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
    8.18 -             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'sdl', 'display',
    8.19 -             'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
    8.20 +             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
    8.21 +             'sdl', 'display', 'xauthority',
    8.22 +             'acpi', 'apic', 'usb', 'usbdevice' ]
    8.23      for a in args:
    8.24          if (vals.__dict__[a]):
    8.25              config_image.append([a, vals.__dict__[a]])