Skip to content

Commit

Permalink
13844 bhyve VNC server could differentiate VMs
Browse files Browse the repository at this point in the history
Reviewed by: Jorge Schrauwen <sjorge@blackdot.be>
Reviewed by: Dan Cross <cross@oxidecomputer.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>
  • Loading branch information
citrus-it committed Jun 4, 2021
1 parent d4deec1 commit 37fc8a1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
11 changes: 9 additions & 2 deletions usr/src/cmd/bhyve/pci_fbuf.c
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2015 Nahanni Systems, Inc.
* Copyright 2018 Joyent, Inc.
* Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -465,13 +466,19 @@ pci_fbuf_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl)
#ifdef __FreeBSD__
error = rfb_init(sc->rfb_host, sc->rfb_port, sc->rfb_wait, sc->rfb_password);
#else
char *name;

(void) asprintf(&name, "%s (bhyve)", get_config_value("name"));

if (sc->rfb_unix != NULL) {
error = rfb_init_unix(sc->rfb_unix, sc->rfb_wait,
sc->rfb_password);
sc->rfb_password, name != NULL ? name : "bhyve");
} else {
error = rfb_init(sc->rfb_host, sc->rfb_port, sc->rfb_wait,
sc->rfb_password);
sc->rfb_password, name != NULL ? name : "bhyve");
}
if (error != 0)
free(name);
#endif
done:
if (error)
Expand Down
32 changes: 31 additions & 1 deletion usr/src/cmd/bhyve/rfb.c
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
* Copyright (c) 2015 Leon Dang
* Copyright 2020 Joyent, Inc.
* Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -143,6 +144,9 @@ struct rfb_softc {
uint32_t *crc; /* WxH crc cells */
uint32_t *crc_tmp; /* buffer to store single crc row */
int crc_width, crc_height;
#ifndef __FreeBSD__
const char *name;
#endif
};

struct rfb_pixfmt {
Expand Down Expand Up @@ -233,7 +237,11 @@ struct rfb_cuttext_msg {
};

static void
#ifndef __FreeBSD__
rfb_send_server_init_msg(int cfd, struct rfb_softc *rc)
#else
rfb_send_server_init_msg(int cfd)
#endif
{
struct bhyvegc_image *gc_image;
struct rfb_srvr_info sinfo;
Expand All @@ -255,9 +263,18 @@ rfb_send_server_init_msg(int cfd)
sinfo.pixfmt.pad[0] = 0;
sinfo.pixfmt.pad[1] = 0;
sinfo.pixfmt.pad[2] = 0;

#ifndef __FreeBSD__
const char *name = rc->name != NULL ? rc->name : "bhyve";

sinfo.namelen = htonl(strlen(name));
(void)stream_write(cfd, &sinfo, sizeof(sinfo));
(void)stream_write(cfd, name, strlen(name));
#else
sinfo.namelen = htonl(strlen("bhyve"));
(void)stream_write(cfd, &sinfo, sizeof(sinfo));
(void)stream_write(cfd, "bhyve", strlen("bhyve"));
#endif
}

static void
Expand Down Expand Up @@ -994,7 +1011,11 @@ rfb_handle(struct rfb_softc *rc, int cfd)
len = stream_read(cfd, buf, 1);

/* 4a. Write server-init info */
#ifndef __FreeBSD__
rfb_send_server_init_msg(cfd, rc);
#else
rfb_send_server_init_msg(cfd);
#endif

if (!rc->zbuf) {
rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
Expand Down Expand Up @@ -1095,7 +1116,11 @@ sse42_supported(void)
}

int
#ifndef __FreeBSD__
rfb_init(char *hostname, int port, int wait, char *password, const char *name)
#else
rfb_init(char *hostname, int port, int wait, char *password)
#endif
{
int e;
char servname[6];
Expand All @@ -1120,6 +1145,10 @@ rfb_init(char *hostname, int port, int wait, char *password)

rc->password = password;

#ifndef __FreeBSD__
rc->name = name;
#endif

snprintf(servname, sizeof(servname), "%d", port ? port : 5900);

if (!hostname || strlen(hostname) == 0)
Expand Down Expand Up @@ -1198,7 +1227,7 @@ rfb_init(char *hostname, int port, int wait, char *password)

#ifndef __FreeBSD__
int
rfb_init_unix(const char *path, int wait, char *password)
rfb_init_unix(const char *path, int wait, char *password, const char *name)
{
struct rfb_softc *rc;
struct sockaddr_un sock;
Expand All @@ -1223,6 +1252,7 @@ rfb_init_unix(const char *path, int wait, char *password)
rc->crc_height = RFB_MAX_HEIGHT;

rc->password = password;
rc->name = name;

rc->sfd = socket(PF_UNIX, SOCK_STREAM, 0);
if (rc->sfd < 0) {
Expand Down
9 changes: 7 additions & 2 deletions usr/src/cmd/bhyve/rfb.h
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
* Copyright 2018 Joyent, Inc.
* Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,9 +35,13 @@

#define RFB_PORT 5900

int rfb_init(char *hostname, int port, int wait, char *password);
#ifndef __FreeBSD__
int rfb_init_unix(const char *path, int wait, char *password);
int rfb_init(char *hostname, int port, int wait, char *password,
const char *name);
int rfb_init_unix(const char *path, int wait, char *password,
const char *name);
#else
int rfb_init(char *hostname, int port, int wait, char *password);
#endif

#endif /* _RFB_H_ */

0 comments on commit 37fc8a1

Please sign in to comment.