2010-12-01 16:36:40 +00:00
|
|
|
/*
|
|
|
|
* virnetserverservice.c: generic network RPC server service
|
|
|
|
*
|
2014-07-15 12:37:14 +00:00
|
|
|
* Copyright (C) 2006-2012, 2014 Red Hat, Inc.
|
2010-12-01 16:36:40 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-01 16:36:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "virnetserverservice.h"
|
|
|
|
|
2014-07-15 12:37:14 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
#include "virthread.h"
|
2019-06-25 16:27:04 +00:00
|
|
|
#include "virlog.h"
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
|
|
|
|
2019-06-25 16:27:04 +00:00
|
|
|
VIR_LOG_INIT("rpc.netserverservice");
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
struct _virNetServerService {
|
2018-04-13 11:51:23 +00:00
|
|
|
virObject parent;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
size_t nsocks;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetSocket **socks;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
int auth;
|
|
|
|
bool readonly;
|
2011-06-30 10:45:55 +00:00
|
|
|
size_t nrequests_client_max;
|
2021-10-12 07:55:38 +00:00
|
|
|
int timer;
|
|
|
|
bool timerActive;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *tls;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
virNetServerServiceDispatchFunc dispatchFunc;
|
|
|
|
void *dispatchOpaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virClass *virNetServerServiceClass;
|
2012-07-11 13:35:52 +00:00
|
|
|
static void virNetServerServiceDispose(void *obj);
|
|
|
|
|
|
|
|
static int virNetServerServiceOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virNetServerService, virClassForObject()))
|
2012-07-11 13:35:52 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virNetServerService);
|
2012-07-11 13:35:52 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static void virNetServerServiceAccept(virNetSocket *sock,
|
2019-10-14 12:45:33 +00:00
|
|
|
int events G_GNUC_UNUSED,
|
2010-12-01 16:36:40 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc = opaque;
|
|
|
|
virNetSocket *clientsock = NULL;
|
2021-10-12 07:55:38 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = virNetSocketAccept(sock, &clientsock);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc == -2) {
|
|
|
|
/* Could not accept new client due to EMFILE. Suspend listening on
|
|
|
|
* the socket and set up a timer to enable it later. Hopefully,
|
|
|
|
* some FDs will be closed meanwhile. */
|
|
|
|
VIR_DEBUG("Temporarily suspending listening on svc=%p because accept() on sock=%p failed (errno=%d)",
|
|
|
|
svc, sock, errno);
|
|
|
|
|
|
|
|
virNetServerServiceToggle(svc, false);
|
|
|
|
|
|
|
|
svc->timerActive = true;
|
|
|
|
/* Retry in 5 seconds. */
|
|
|
|
virEventUpdateTimeout(svc->timer, 5 * 1000);
|
|
|
|
}
|
2012-08-09 11:06:45 +00:00
|
|
|
goto cleanup;
|
2021-10-12 07:55:38 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (!clientsock) /* Connection already went away */
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!svc->dispatchFunc)
|
2012-08-09 11:06:45 +00:00
|
|
|
goto cleanup;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-08-09 11:06:45 +00:00
|
|
|
svc->dispatchFunc(svc, clientsock, svc->dispatchOpaque);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
cleanup:
|
2012-08-09 11:06:45 +00:00
|
|
|
virObjectUnref(clientsock);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 07:55:38 +00:00
|
|
|
static void
|
|
|
|
virNetServerServiceTimerFunc(int timer,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virNetServerService *svc = opaque;
|
|
|
|
|
|
|
|
VIR_DEBUG("Resuming listening on service svc=%p after previous suspend", svc);
|
|
|
|
|
|
|
|
virNetServerServiceToggle(svc, true);
|
|
|
|
|
|
|
|
virEventUpdateTimeout(timer, -1);
|
|
|
|
svc->timerActive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNetServerService *
|
|
|
|
virNetServerServiceNewSocket(virNetSocket **socks,
|
2019-06-24 10:48:38 +00:00
|
|
|
size_t nsocks,
|
|
|
|
int auth,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *tls,
|
2019-06-24 10:48:38 +00:00
|
|
|
bool readonly,
|
|
|
|
size_t max_queued_clients,
|
|
|
|
size_t nrequests_client_max)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc;
|
2010-12-01 16:36:40 +00:00
|
|
|
size_t i;
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
svc->socks = g_new0(virNetSocket *, nsocks);
|
2019-06-24 10:48:38 +00:00
|
|
|
svc->nsocks = nsocks;
|
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
|
|
|
svc->socks[i] = socks[i];
|
|
|
|
virObjectRef(svc->socks[i]);
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
svc->auth = auth;
|
|
|
|
svc->readonly = readonly;
|
2011-06-30 10:45:55 +00:00
|
|
|
svc->nrequests_client_max = nrequests_client_max;
|
2012-07-11 13:35:48 +00:00
|
|
|
svc->tls = virObjectRef(tls);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-10-12 07:55:38 +00:00
|
|
|
virObjectRef(svc);
|
|
|
|
svc->timer = virEventAddTimeout(-1, virNetServerServiceTimerFunc,
|
2022-07-13 20:26:51 +00:00
|
|
|
svc, virObjectUnref);
|
2021-10-12 07:55:38 +00:00
|
|
|
if (svc->timer < 0) {
|
|
|
|
virObjectUnref(svc);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2013-07-25 12:45:38 +00:00
|
|
|
if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0)
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (virNetSocketAddIOCallback(svc->socks[i],
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
2011-07-19 13:11:33 +00:00
|
|
|
svc,
|
2022-07-13 20:26:51 +00:00
|
|
|
virObjectUnref) < 0) {
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
2011-07-19 13:11:33 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *virNetServerServiceNewTCP(const char *nodename,
|
2019-06-24 10:48:38 +00:00
|
|
|
const char *service,
|
|
|
|
int family,
|
|
|
|
int auth,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *tls,
|
2019-06-24 10:48:38 +00:00
|
|
|
bool readonly,
|
|
|
|
size_t max_queued_clients,
|
|
|
|
size_t nrequests_client_max)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc;
|
2019-06-24 10:48:38 +00:00
|
|
|
size_t i;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetSocket **socks;
|
2019-06-24 10:48:38 +00:00
|
|
|
size_t nsocks;
|
|
|
|
|
2019-06-25 16:27:04 +00:00
|
|
|
VIR_DEBUG("Creating new TCP server nodename='%s' service='%s'",
|
|
|
|
NULLSTR(nodename), NULLSTR(service));
|
2019-06-24 10:48:38 +00:00
|
|
|
if (virNetSocketNewListenTCP(nodename,
|
|
|
|
service,
|
|
|
|
family,
|
|
|
|
&socks,
|
|
|
|
&nsocks) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
svc = virNetServerServiceNewSocket(socks,
|
|
|
|
nsocks,
|
|
|
|
auth,
|
|
|
|
tls,
|
|
|
|
readonly,
|
|
|
|
max_queued_clients,
|
|
|
|
nrequests_client_max);
|
|
|
|
|
|
|
|
for (i = 0; i < nsocks; i++)
|
|
|
|
virObjectUnref(socks[i]);
|
|
|
|
VIR_FREE(socks);
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *virNetServerServiceNewUNIX(const char *path,
|
2010-12-01 16:36:40 +00:00
|
|
|
mode_t mask,
|
|
|
|
gid_t grp,
|
|
|
|
int auth,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *tls,
|
2010-12-01 16:36:40 +00:00
|
|
|
bool readonly,
|
2013-07-25 12:45:38 +00:00
|
|
|
size_t max_queued_clients,
|
2013-01-07 14:54:18 +00:00
|
|
|
size_t nrequests_client_max)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc;
|
|
|
|
virNetSocket *sock;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2019-06-25 16:27:04 +00:00
|
|
|
VIR_DEBUG("Creating new UNIX server path='%s' mask=%o gid=%u",
|
|
|
|
path, mask, grp);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (virNetSocketNewListenUNIX(path,
|
|
|
|
mask,
|
2011-08-12 09:10:19 +00:00
|
|
|
-1,
|
2010-12-01 16:36:40 +00:00
|
|
|
grp,
|
2019-06-24 10:48:38 +00:00
|
|
|
&sock) < 0)
|
|
|
|
return NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2019-06-24 10:48:38 +00:00
|
|
|
svc = virNetServerServiceNewSocket(&sock,
|
|
|
|
1,
|
|
|
|
auth,
|
|
|
|
tls,
|
|
|
|
readonly,
|
|
|
|
max_queued_clients,
|
|
|
|
nrequests_client_max);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2019-06-24 10:48:38 +00:00
|
|
|
virObjectUnref(sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *virNetServerServiceNewFDs(int *fds,
|
2019-06-25 14:54:48 +00:00
|
|
|
size_t nfds,
|
2019-06-25 19:17:27 +00:00
|
|
|
bool unlinkUNIX,
|
2019-06-25 14:54:48 +00:00
|
|
|
int auth,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *tls,
|
2019-06-25 14:54:48 +00:00
|
|
|
bool readonly,
|
|
|
|
size_t max_queued_clients,
|
|
|
|
size_t nrequests_client_max)
|
2012-08-09 14:09:19 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc = NULL;
|
|
|
|
virNetSocket **socks;
|
2019-06-25 14:54:48 +00:00
|
|
|
size_t i;
|
2012-08-09 14:09:19 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
socks = g_new0(virNetSocket *, nfds);
|
2014-07-16 17:26:16 +00:00
|
|
|
|
2019-06-25 14:54:48 +00:00
|
|
|
for (i = 0; i < nfds; i++) {
|
|
|
|
if (virNetSocketNewListenFD(fds[i],
|
2019-06-25 19:17:27 +00:00
|
|
|
unlinkUNIX,
|
2019-06-25 14:54:48 +00:00
|
|
|
&socks[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
svc = virNetServerServiceNewSocket(socks,
|
|
|
|
nfds,
|
2019-06-24 10:48:38 +00:00
|
|
|
auth,
|
|
|
|
tls,
|
|
|
|
readonly,
|
|
|
|
max_queued_clients,
|
|
|
|
nrequests_client_max);
|
2012-08-09 14:09:19 +00:00
|
|
|
|
2019-06-25 14:54:48 +00:00
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < nfds && socks; i++)
|
|
|
|
virObjectUnref(socks[i]);
|
|
|
|
VIR_FREE(socks);
|
2012-08-09 14:09:19 +00:00
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *virNetServerServiceNewPostExecRestart(virJSONValue *object)
|
2012-08-09 11:54:54 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc;
|
|
|
|
virJSONValue *socks;
|
2012-08-09 11:54:54 +00:00
|
|
|
size_t i;
|
2018-04-19 21:29:02 +00:00
|
|
|
size_t n;
|
2012-10-26 20:28:40 +00:00
|
|
|
unsigned int max;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(object, "auth", &svc->auth) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing auth field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(object, "readonly", &svc->readonly) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing readonly field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberUint(object, "nrequests_client_max",
|
2012-10-26 20:28:40 +00:00
|
|
|
&max) < 0) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing nrequests_client_max field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
2012-10-26 20:28:40 +00:00
|
|
|
svc->nrequests_client_max = max;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (!(socks = virJSONValueObjectGet(object, "socks"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing socks field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:29:02 +00:00
|
|
|
if (!virJSONValueIsArray(socks)) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2018-04-19 21:29:02 +00:00
|
|
|
_("Malformed socks array"));
|
2012-08-09 11:54:54 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:29:02 +00:00
|
|
|
n = virJSONValueArraySize(socks);
|
2021-03-11 07:16:13 +00:00
|
|
|
svc->socks = g_new0(virNetSocket *, n);
|
2017-02-09 14:13:38 +00:00
|
|
|
svc->nsocks = n;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virJSONValue *child = virJSONValueArrayGet(socks, i);
|
|
|
|
virNetSocket *sock;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (!(sock = virNetSocketNewPostExecRestart(child))) {
|
|
|
|
virObjectUnref(sock);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
svc->socks[i] = sock;
|
|
|
|
|
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
|
|
|
virObjectRef(svc);
|
|
|
|
if (virNetSocketAddIOCallback(sock,
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
|
|
|
svc,
|
2022-07-13 20:26:51 +00:00
|
|
|
virObjectUnref) < 0) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virObjectUnref(svc);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-08-09 11:54:54 +00:00
|
|
|
virObjectUnref(svc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virJSONValue *virNetServerServicePreExecRestart(virNetServerService *svc)
|
2012-08-09 11:54:54 +00:00
|
|
|
{
|
2021-02-11 17:29:40 +00:00
|
|
|
g_autoptr(virJSONValue) object = virJSONValueNewObject();
|
|
|
|
g_autoptr(virJSONValue) socks = virJSONValueNewArray();
|
2012-08-09 11:54:54 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendNumberInt(object, "auth", svc->auth) < 0)
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectAppendBoolean(object, "readonly", svc->readonly) < 0)
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectAppendNumberUint(object, "nrequests_client_max", svc->nrequests_client_max) < 0)
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2021-02-11 17:29:40 +00:00
|
|
|
g_autoptr(virJSONValue) child = NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
if (!(child = virNetSocketPreExecRestart(svc->socks[i])))
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2021-02-11 16:57:45 +00:00
|
|
|
if (virJSONValueArrayAppend(socks, &child) < 0)
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 16:57:45 +00:00
|
|
|
if (virJSONValueObjectAppend(object, "socks", &socks) < 0)
|
2021-02-11 17:29:40 +00:00
|
|
|
return NULL;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2021-02-11 17:29:40 +00:00
|
|
|
return g_steal_pointer(&object);
|
2012-08-09 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virNetServerServiceGetPort(virNetServerService *svc)
|
2011-03-02 17:11:42 +00:00
|
|
|
{
|
|
|
|
/* We're assuming if there are multiple sockets
|
|
|
|
* for IPv4 & 6, then they are all on same port */
|
|
|
|
return virNetSocketGetPort(svc->socks[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virNetServerServiceGetAuth(virNetServerService *svc)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
return svc->auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
bool virNetServerServiceIsReadonly(virNetServerService *svc)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
return svc->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
size_t virNetServerServiceGetMaxRequests(virNetServerService *svc)
|
2012-08-09 11:06:45 +00:00
|
|
|
{
|
|
|
|
return svc->nrequests_client_max;
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetTLSContext *virNetServerServiceGetTLSContext(virNetServerService *svc)
|
2012-08-09 11:06:45 +00:00
|
|
|
{
|
|
|
|
return svc->tls;
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetServerServiceSetDispatcher(virNetServerService *svc,
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetServerServiceDispatchFunc func,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
svc->dispatchFunc = func;
|
|
|
|
svc->dispatchOpaque = opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
void virNetServerServiceDispose(void *obj)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNetServerService *svc = obj;
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2021-10-12 07:55:38 +00:00
|
|
|
if (svc->timer >= 0)
|
|
|
|
virEventRemoveTimeout(svc->timer);
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++)
|
2017-02-09 14:13:38 +00:00
|
|
|
virObjectUnref(svc->socks[i]);
|
2021-02-03 20:14:57 +00:00
|
|
|
g_free(svc->socks);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-07-11 13:35:48 +00:00
|
|
|
virObjectUnref(svc->tls);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetServerServiceToggle(virNetServerService *svc,
|
2010-12-01 16:36:40 +00:00
|
|
|
bool enabled)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++)
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetSocketUpdateIOCallback(svc->socks[i],
|
|
|
|
enabled ?
|
|
|
|
VIR_EVENT_HANDLE_READABLE :
|
|
|
|
0);
|
|
|
|
}
|
2011-08-04 08:54:58 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virNetServerServiceClose(virNetServerService *svc)
|
2011-08-04 08:54:58 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-08-04 08:54:58 +00:00
|
|
|
|
|
|
|
if (!svc)
|
|
|
|
return;
|
|
|
|
|
2015-06-18 12:37:43 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
|
|
|
virNetSocketRemoveIOCallback(svc->socks[i]);
|
2011-08-04 08:54:58 +00:00
|
|
|
virNetSocketClose(svc->socks[i]);
|
2015-06-18 12:37:43 +00:00
|
|
|
}
|
2011-08-04 08:54:58 +00:00
|
|
|
}
|
2021-10-12 07:55:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virNetServerServiceTimerActive(virNetServerService *svc)
|
|
|
|
{
|
|
|
|
return svc->timerActive;
|
|
|
|
}
|