libvirt/qemud/qemud.h

213 lines
5.1 KiB
C
Raw Normal View History

2007-02-14 01:40:09 +00:00
/*
* qemud.h: daemon data structure definitions
2007-02-14 01:40:09 +00:00
*
* Copyright (C) 2006-2008 Red Hat, Inc.
2007-02-14 01:40:09 +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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef QEMUD_INTERNAL_H__
#define QEMUD_INTERNAL_H__
#include <config.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include "gnutls_1_0_compat.h"
#if HAVE_SASL
#include <sasl/sasl.h>
#endif
2007-02-14 01:40:09 +00:00
2007-12-05 18:21:27 +00:00
#ifdef HAVE_POLKIT
#include <dbus/dbus.h>
#endif
#ifdef HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
#endif
#include <rpc/types.h>
#include <rpc/xdr.h>
#include "remote_protocol.h"
2007-02-14 01:40:09 +00:00
#ifdef __GNUC__
#ifdef HAVE_ANSIDECL_H
#include <ansidecl.h>
#endif
#ifndef ATTRIBUTE_UNUSED
#define ATTRIBUTE_UNUSED __attribute__((__unused__))
2007-02-14 01:40:09 +00:00
#endif
#ifndef ATTRIBUTE_FORMAT
#define ATTRIBUTE_FORMAT(args...) __attribute__((__format__ (args)))
#endif
2007-02-14 01:40:09 +00:00
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_FORMAT(...)
2007-02-14 01:40:09 +00:00
#endif
typedef enum {
QEMUD_ERR,
QEMUD_WARN,
QEMUD_INFO,
#ifdef ENABLE_DEBUG
QEMUD_DEBUG
#endif
} qemudLogPriority;
enum qemud_mode {
2008-12-04 22:16:40 +00:00
QEMUD_MODE_RX_HEADER, /* Receiving the fixed length RPC header data */
QEMUD_MODE_RX_PAYLOAD, /* Receiving the variable length RPC payload data */
QEMUD_MODE_WAIT_DISPATCH, /* Message received, waiting for worker to process */
QEMUD_MODE_IN_DISPATCH, /* RPC call being processed */
QEMUD_MODE_TX_PACKET, /* Transmitting reply to RPC call */
QEMUD_MODE_TLS_HANDSHAKE, /* Performing TLS handshake */
};
/* Whether we're passing reads & writes through a sasl SSF */
enum qemud_sasl_ssf {
QEMUD_SASL_SSF_NONE = 0,
QEMUD_SASL_SSF_READ = 1,
QEMUD_SASL_SSF_WRITE = 2,
};
enum qemud_sock_type {
QEMUD_SOCK_TYPE_UNIX = 0,
QEMUD_SOCK_TYPE_TCP = 1,
QEMUD_SOCK_TYPE_TLS = 2,
};
2007-02-14 01:40:09 +00:00
/* Stores the per-client connection state */
struct qemud_client {
2008-12-04 22:16:40 +00:00
PTHREAD_MUTEX_T(lock);
int magic;
2007-02-14 01:40:09 +00:00
int fd;
int watch;
2008-12-04 22:16:40 +00:00
int readonly:1;
int closing:1;
enum qemud_mode mode;
struct sockaddr_storage addr;
socklen_t addrlen;
int type; /* qemud_sock_type */
gnutls_session_t tlssession;
int auth;
#if HAVE_SASL
sasl_conn_t *saslconn;
int saslSSF;
const char *saslDecoded;
unsigned int saslDecodedLength;
unsigned int saslDecodedOffset;
const char *saslEncoded;
unsigned int saslEncodedLength;
unsigned int saslEncodedOffset;
char *saslUsername;
#endif
unsigned int incomingSerial;
unsigned int outgoingSerial;
char buffer [REMOTE_MESSAGE_MAX];
unsigned int bufferLength;
unsigned int bufferOffset;
/* This is only valid if a remote open call has been made on this
* connection, otherwise it will be NULL. Also if remote close is
* called, it will be set back to NULL if that succeeds.
*/
virConnectPtr conn;
2008-12-04 22:16:40 +00:00
int refs;
/* back-pointer to our server */
struct qemud_server *server;
2007-02-14 01:40:09 +00:00
};
#define QEMUD_CLIENT_MAGIC 0x7788aaee
2007-02-14 01:40:09 +00:00
struct qemud_socket {
int fd;
int watch;
2007-02-14 01:40:09 +00:00
int readonly;
int type; /* qemud_sock_type */
int auth;
int port;
2007-02-14 01:40:09 +00:00
struct qemud_socket *next;
};
/* Main server state */
struct qemud_server {
2008-12-04 22:16:40 +00:00
pthread_mutex_t lock;
pthread_cond_t job;
int nworkers;
pthread_t *workers;
2007-02-14 01:40:09 +00:00
int nsockets;
struct qemud_socket *sockets;
int nclients;
struct qemud_client **clients;
2008-12-04 22:16:40 +00:00
int sigread;
2007-05-18 18:36:24 +00:00
char logDir[PATH_MAX];
unsigned int shutdown : 1;
#ifdef HAVE_AVAHI
struct libvirtd_mdns *mdns;
#endif
#if HAVE_SASL
char **saslUsernameWhitelist;
#endif
2007-12-05 18:21:27 +00:00
#if HAVE_POLKIT
DBusConnection *sysbus;
#endif
2007-02-14 01:40:09 +00:00
};
void qemudLog(int priority, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf,2,3);
#ifdef ENABLE_DEBUG
#define qemudDebug(...) qemudLog(QEMUD_DEBUG, __VA_ARGS__)
#else
#define qemudDebug(fmt, ...) do {} while(0)
#endif
int qemudSetCloseExec(int fd);
int qemudSetNonBlock(int fd);
2008-12-04 22:12:53 +00:00
unsigned int
remoteDispatchClientRequest (struct qemud_server *server,
struct qemud_client *client);
void qemudDispatchClientWrite(struct qemud_server *server,
struct qemud_client *client);
2008-04-04 15:09:19 +00:00
#if HAVE_POLKIT
int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid);
#endif
int remoteRelayDomainEvent (virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainPtr dom,
int event,
2008-11-17 16:43:00 +00:00
int detail,
void *opaque);
2007-02-14 01:40:09 +00:00
#endif