goto cleanup;
}
- if (!(srv = virNetServerNew("libvirtd",
+ if (!(srv = virNetServerNew("libvirtd", 1,
config->min_workers,
config->max_workers,
config->prio_workers,
goto cleanup;
}
- if (!(srvAdm = virNetServerNew("admin",
+ if (!(srvAdm = virNetServerNew("admin", 1,
config->admin_min_workers,
config->admin_max_workers,
0,
virNetServerHasClients;
virNetServerNew;
virNetServerNewPostExecRestart;
+virNetServerNextClientID;
virNetServerPreExecRestart;
virNetServerProcessClients;
virNetServerStart;
return NULL;
}
- if (!(srv = virNetServerNew("virtlockd",
+ if (!(srv = virNetServerNew("virtlockd", 1,
1, 1, 0, config->max_clients,
config->max_clients, -1, 0,
NULL,
return NULL;
}
- if (!(logd->srv = virNetServerNew("virtlogd",
+ if (!(logd->srv = virNetServerNew("virtlogd", 1,
1, 1, 0, config->max_clients,
config->max_clients, -1, 0,
NULL,
LXC_STATE_DIR, ctrl->name) < 0)
return -1;
- if (!(srv = virNetServerNew("LXC",
+ if (!(srv = virNetServerNew("LXC", 1,
0, 0, 0, 1,
0, -1, 0,
NULL,
size_t nclients; /* Current clients count */
virNetServerClientPtr *clients; /* Clients */
+ unsigned long long next_client_id; /* next client ID */
size_t nclients_max; /* Max allowed clients count */
size_t nclients_unauth; /* Unauthenticated clients count */
size_t nclients_unauth_max; /* Max allowed unauth clients count */
VIR_ONCE_GLOBAL_INIT(virNetServer)
+unsigned long long virNetServerNextClientID(virNetServerPtr srv)
+{
+ unsigned long long val;
+
+ virObjectLock(srv);
+ val = srv->next_client_id++;
+ virObjectUnlock(srv);
+
+ return val;
+}
static int virNetServerProcessMsg(virNetServerPtr srv,
virNetServerClientPtr client,
virNetServerPtr srv = opaque;
virNetServerClientPtr client;
- if (!(client = virNetServerClientNew(clientsock,
+ if (!(client = virNetServerClientNew(virNetServerNextClientID(srv),
+ clientsock,
virNetServerServiceGetAuth(svc),
virNetServerServiceIsReadonly(svc),
virNetServerServiceGetMaxRequests(svc),
virNetServerPtr virNetServerNew(const char *name,
+ unsigned long long next_client_id,
size_t min_workers,
size_t max_workers,
size_t priority_workers,
if (VIR_STRDUP(srv->name, name) < 0)
goto error;
+ srv->next_client_id = next_client_id;
srv->nclients_max = max_clients;
srv->nclients_unauth_max = max_anonymous_clients;
srv->keepaliveInterval = keepaliveInterval;
unsigned int max_anonymous_clients;
unsigned int keepaliveInterval;
unsigned int keepaliveCount;
+ unsigned long long next_client_id;
const char *mdnsGroupName = NULL;
if (virJSONValueObjectGetNumberUint(object, "min_workers", &min_workers) < 0) {
goto error;
}
- if (!(srv = virNetServerNew(name,
+ if (virJSONValueObjectGetNumberUlong(object, "next_client_id",
+ &next_client_id) < 0) {
+ VIR_WARN("Missing next_client_id data in JSON document");
+ next_client_id = 1;
+ }
+
+ if (!(srv = virNetServerNew(name, next_client_id,
min_workers, max_workers,
priority_workers, max_clients,
max_anonymous_clients,
clientPrivNewPostExecRestart,
clientPrivPreExecRestart,
clientPrivFree,
- clientPrivOpaque)))
+ clientPrivOpaque,
+ srv)))
goto error;
if (virNetServerAddClient(srv, client) < 0) {
goto error;
}
+ if (virJSONValueObjectAppendNumberUlong(object, "next_client_id",
+ srv->next_client_id) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot set next_client_id data in JSON document"));
+ goto error;
+ }
+
if (srv->mdnsGroupName &&
virJSONValueObjectAppendString(object, "mdnsGroupName", srv->mdnsGroupName) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virNetServerPtr virNetServerNew(const char *name,
+ unsigned long long next_client_id,
size_t min_workers,
size_t max_workers,
size_t priority_workers,
long long int maxWorkers,
long long int prioWorkers);
+unsigned long long virNetServerNextClientID(virNetServerPtr srv);
+
#endif /* __VIR_NET_SERVER_H__ */
# include <sasl/sasl.h>
#endif
+#include "virnetserver.h"
#include "virnetserverclient.h"
#include "virlog.h"
{
virObjectLockable parent;
+ unsigned long long id;
bool wantClose;
bool delayedClose;
virNetSocketPtr sock;
static virNetServerClientPtr
-virNetServerClientNewInternal(virNetSocketPtr sock,
+virNetServerClientNewInternal(unsigned long long id,
+ virNetSocketPtr sock,
int auth,
#ifdef WITH_GNUTLS
virNetTLSContextPtr tls,
if (!(client = virObjectLockableNew(virNetServerClientClass)))
return NULL;
+ client->id = id;
client->sock = virObjectRef(sock);
client->auth = auth;
client->readonly = readonly;
}
-virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
+virNetServerClientPtr virNetServerClientNew(unsigned long long id,
+ virNetSocketPtr sock,
int auth,
bool readonly,
size_t nrequests_max,
#endif
);
- if (!(client = virNetServerClientNewInternal(sock, auth,
+ if (!(client = virNetServerClientNewInternal(id, sock, auth,
#ifdef WITH_GNUTLS
tls,
#endif
virNetServerClientPrivNewPostExecRestart privNew,
virNetServerClientPrivPreExecRestart privPreExecRestart,
virFreeCallback privFree,
- void *privOpaque)
+ void *privOpaque,
+ void *opaque)
{
virJSONValuePtr child;
virNetServerClientPtr client = NULL;
int auth;
bool readonly;
unsigned int nrequests_max;
+ unsigned long long id;
if (virJSONValueObjectGetNumberInt(object, "auth", &auth) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
+ if (!virJSONValueObjectHasKey(object, "id")) {
+ /* no ID found in, a new one must be generated */
+ id = virNetServerNextClientID((virNetServerPtr) opaque);
+ } else {
+ if (virJSONValueObjectGetNumberUlong(object, "id",
+ (unsigned long long *) &id) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Malformed id field in JSON state document"));
+ return NULL;
+ }
+ }
+
if (!(sock = virNetSocketNewPostExecRestart(child))) {
virObjectUnref(sock);
return NULL;
}
- if (!(client = virNetServerClientNewInternal(sock,
+ if (!(client = virNetServerClientNewInternal(id,
+ sock,
auth,
#ifdef WITH_GNUTLS
NULL,
virObjectLock(client);
+ if (virJSONValueObjectAppendNumberUlong(object, "id",
+ client->id) < 0)
+ goto error;
+
if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
goto error;
if (virJSONValueObjectAppendBoolean(object, "readonly", client->readonly) < 0)
return readonly;
}
+unsigned long long virNetServerClientGetID(virNetServerClientPtr client)
+{
+ return client->id;
+}
#ifdef WITH_GNUTLS
bool virNetServerClientHasTLSSession(virNetServerClientPtr client)
typedef void *(*virNetServerClientPrivNew)(virNetServerClientPtr client,
void *opaque);
-virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
+virNetServerClientPtr virNetServerClientNew(unsigned long long id,
+ virNetSocketPtr sock,
int auth,
bool readonly,
size_t nrequests_max,
virNetServerClientPrivNewPostExecRestart privNew,
virNetServerClientPrivPreExecRestart privPreExecRestart,
virFreeCallback privFree,
- void *privOpaque);
+ void *privOpaque,
+ void *opaque);
virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client);
int virNetServerClientGetAuth(virNetServerClientPtr client);
void virNetServerClientSetAuth(virNetServerClientPtr client, int auth);
bool virNetServerClientGetReadonly(virNetServerClientPtr client);
+unsigned long long virNetServerClientGetID(virNetServerClientPtr client);
# ifdef WITH_GNUTLS
bool virNetServerClientHasTLSSession(virNetServerClientPtr client);
--- /dev/null
+{
+ "servers": {
+ "testServer0": {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 10,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "next_client_id": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "id": 2,
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "id": 3,
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ }
+}
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 10,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
--- /dev/null
+{
+ "servers": {
+ "testServer0": {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 10,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "next_client_id": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "id": 2,
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "id": 3,
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ }
+}
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"mdnsGroupName": "libvirtTest",
"services": [
{
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
"max_anonymous_clients": 100,
"keepaliveInterval": 120,
"keepaliveCount": 5,
+ "next_client_id": 3,
"services": [
{
"auth": 0,
],
"clients": [
{
+ "id": 1,
"auth": 1,
"readonly": true,
"nrequests_max": 15,
}
},
{
+ "id": 2,
"auth": 2,
"readonly": true,
"nrequests_max": 66,
goto cleanup;
}
- if (!(srv = virNetServerNew(server_name,
+ if (!(srv = virNetServerNew(server_name, 1,
10, 50, 5, 100, 10,
120, 5,
mdns_group,
if (virNetSocketNewConnectSockFD(fdclient[1], &sk2) < 0)
goto error;
- if (!(cln1 = virNetServerClientNew(sk1,
+ if (!(cln1 = virNetServerClientNew(virNetServerNextClientID(srv),
+ sk1,
VIR_NET_SERVER_SERVICE_AUTH_SASL,
true,
15,
NULL, NULL, NULL, NULL)))
goto error;
- if (!(cln2 = virNetServerClientNew(sk2,
+ if (!(cln2 = virNetServerClientNew(virNetServerNextClientID(srv),
+ sk2,
VIR_NET_SERVER_SERVICE_AUTH_POLKIT,
true,
66,
EXEC_RESTART_TEST("admin-nomdns", 2);
EXEC_RESTART_TEST("admin-server-names", 2);
EXEC_RESTART_TEST("no-keepalive-required", 2);
+ EXEC_RESTART_TEST("client-ids", 1);
EXEC_RESTART_TEST_FAIL("anon-clients", 2);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
sv[0] = -1;
- if (!(client = virNetServerClientNew(sock, 0, false, 1,
+ if (!(client = virNetServerClientNew(1, sock, 0, false, 1,
# ifdef WITH_GNUTLS
NULL,
# endif