2010-12-06 17:03:35 +00:00
|
|
|
/*
|
|
|
|
* virnetsocket.h: generic network socket handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2011 Red Hat, Inc.
|
|
|
|
* 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-06 17:03:35 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "virsocketaddr.h"
|
|
|
|
#include "vircommand.h"
|
2020-01-22 16:21:35 +00:00
|
|
|
#include "virnettlscontext.h"
|
2019-06-18 16:12:39 +00:00
|
|
|
#include "virobject.h"
|
|
|
|
#ifdef WITH_SASL
|
|
|
|
# include "virnetsaslcontext.h"
|
|
|
|
#endif
|
|
|
|
#include "virjson.h"
|
|
|
|
#include "viruri.h"
|
2010-12-06 17:03:35 +00:00
|
|
|
|
|
|
|
typedef struct _virNetSocket virNetSocket;
|
|
|
|
typedef virNetSocket *virNetSocketPtr;
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*virNetSocketIOFunc)(virNetSocketPtr sock,
|
|
|
|
int events,
|
|
|
|
void *opaque);
|
|
|
|
|
|
|
|
|
2015-05-21 15:27:15 +00:00
|
|
|
int virNetSocketCheckProtocols(bool *hasIPv4,
|
|
|
|
bool *hasIPv6);
|
|
|
|
|
2010-12-06 17:03:35 +00:00
|
|
|
int virNetSocketNewListenTCP(const char *nodename,
|
|
|
|
const char *service,
|
2015-05-21 14:51:28 +00:00
|
|
|
int family,
|
2010-12-06 17:03:35 +00:00
|
|
|
virNetSocketPtr **addrs,
|
|
|
|
size_t *naddrs);
|
|
|
|
|
|
|
|
int virNetSocketNewListenUNIX(const char *path,
|
|
|
|
mode_t mask,
|
2011-08-12 09:10:19 +00:00
|
|
|
uid_t user,
|
2010-12-06 17:03:35 +00:00
|
|
|
gid_t grp,
|
|
|
|
virNetSocketPtr *addr);
|
2012-08-09 14:09:19 +00:00
|
|
|
|
|
|
|
int virNetSocketNewListenFD(int fd,
|
2019-06-25 19:17:27 +00:00
|
|
|
bool unlinkUNIX,
|
2012-08-09 14:09:19 +00:00
|
|
|
virNetSocketPtr *addr);
|
2010-12-06 17:03:35 +00:00
|
|
|
|
|
|
|
int virNetSocketNewConnectTCP(const char *nodename,
|
|
|
|
const char *service,
|
2015-05-21 14:51:28 +00:00
|
|
|
int family,
|
2010-12-06 17:03:35 +00:00
|
|
|
virNetSocketPtr *addr);
|
|
|
|
|
|
|
|
int virNetSocketNewConnectUNIX(const char *path,
|
|
|
|
bool spawnDaemon,
|
|
|
|
const char *binary,
|
|
|
|
virNetSocketPtr *addr);
|
|
|
|
|
|
|
|
int virNetSocketNewConnectCommand(virCommandPtr cmd,
|
|
|
|
virNetSocketPtr *retsock);
|
|
|
|
|
|
|
|
int virNetSocketNewConnectSSH(const char *nodename,
|
|
|
|
const char *service,
|
|
|
|
const char *binary,
|
|
|
|
const char *username,
|
|
|
|
bool noTTY,
|
2011-07-11 19:50:31 +00:00
|
|
|
bool noVerify,
|
2010-12-06 17:03:35 +00:00
|
|
|
const char *netcat,
|
2011-07-19 17:52:21 +00:00
|
|
|
const char *keyfile,
|
2010-12-06 17:03:35 +00:00
|
|
|
const char *path,
|
|
|
|
virNetSocketPtr *addr);
|
|
|
|
|
2011-11-14 14:50:02 +00:00
|
|
|
int virNetSocketNewConnectLibSSH2(const char *host,
|
|
|
|
const char *port,
|
2015-05-21 14:51:28 +00:00
|
|
|
int family,
|
2011-11-14 14:50:02 +00:00
|
|
|
const char *username,
|
|
|
|
const char *privkey,
|
|
|
|
const char *knownHosts,
|
|
|
|
const char *knownHostsVerify,
|
|
|
|
const char *authMethods,
|
|
|
|
const char *command,
|
|
|
|
virConnectAuthPtr auth,
|
2013-07-09 14:46:32 +00:00
|
|
|
virURIPtr uri,
|
2011-11-14 14:50:02 +00:00
|
|
|
virNetSocketPtr *retsock);
|
|
|
|
|
2016-11-09 14:28:36 +00:00
|
|
|
int virNetSocketNewConnectLibssh(const char *host,
|
|
|
|
const char *port,
|
|
|
|
int family,
|
|
|
|
const char *username,
|
|
|
|
const char *privkey,
|
|
|
|
const char *knownHosts,
|
|
|
|
const char *knownHostsVerify,
|
|
|
|
const char *authMethods,
|
|
|
|
const char *command,
|
|
|
|
virConnectAuthPtr auth,
|
|
|
|
virURIPtr uri,
|
|
|
|
virNetSocketPtr *retsock);
|
|
|
|
|
2010-12-06 17:03:35 +00:00
|
|
|
int virNetSocketNewConnectExternal(const char **cmdargv,
|
|
|
|
virNetSocketPtr *addr);
|
|
|
|
|
2013-09-23 10:58:26 +00:00
|
|
|
int virNetSocketNewConnectSockFD(int sockfd,
|
|
|
|
virNetSocketPtr *retsock);
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);
|
|
|
|
|
|
|
|
virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);
|
|
|
|
|
2010-12-06 17:03:35 +00:00
|
|
|
int virNetSocketGetFD(virNetSocketPtr sock);
|
2011-07-07 14:17:21 +00:00
|
|
|
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);
|
|
|
|
|
2010-12-06 17:03:35 +00:00
|
|
|
bool virNetSocketIsLocal(virNetSocketPtr sock);
|
|
|
|
|
2011-10-21 10:13:21 +00:00
|
|
|
bool virNetSocketHasPassFD(virNetSocketPtr sock);
|
|
|
|
|
2019-06-24 10:48:12 +00:00
|
|
|
char *virNetSocketGetPath(virNetSocketPtr sock);
|
2011-03-02 17:11:42 +00:00
|
|
|
int virNetSocketGetPort(virNetSocketPtr sock);
|
|
|
|
|
2012-01-18 17:41:36 +00:00
|
|
|
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|
|
|
uid_t *uid,
|
|
|
|
gid_t *gid,
|
2013-04-25 16:05:00 +00:00
|
|
|
pid_t *pid,
|
2017-04-07 14:07:49 +00:00
|
|
|
unsigned long long *timestamp)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2013-04-25 10:33:43 +00:00
|
|
|
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
|
2017-04-07 14:07:49 +00:00
|
|
|
char **context)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2010-12-06 17:03:35 +00:00
|
|
|
|
|
|
|
int virNetSocketSetBlocking(virNetSocketPtr sock,
|
|
|
|
bool blocking);
|
|
|
|
|
2017-03-17 15:01:45 +00:00
|
|
|
void virNetSocketSetQuietEOF(virNetSocketPtr sock);
|
|
|
|
|
2010-12-06 17:03:35 +00:00
|
|
|
ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
|
|
|
|
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);
|
|
|
|
|
2011-10-21 10:13:21 +00:00
|
|
|
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
|
2011-11-04 16:02:14 +00:00
|
|
|
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
|
2011-10-21 10:13:21 +00:00
|
|
|
|
2010-12-10 12:22:03 +00:00
|
|
|
void virNetSocketSetTLSSession(virNetSocketPtr sock,
|
|
|
|
virNetTLSSessionPtr sess);
|
2011-11-14 14:50:02 +00:00
|
|
|
|
2019-06-18 16:12:39 +00:00
|
|
|
#ifdef WITH_SASL
|
2010-12-10 12:22:03 +00:00
|
|
|
void virNetSocketSetSASLSession(virNetSocketPtr sock,
|
|
|
|
virNetSASLSessionPtr sess);
|
2019-06-18 16:12:39 +00:00
|
|
|
#endif
|
2010-12-10 12:22:03 +00:00
|
|
|
bool virNetSocketHasCachedData(virNetSocketPtr sock);
|
2011-11-08 09:13:27 +00:00
|
|
|
bool virNetSocketHasPendingData(virNetSocketPtr sock);
|
2010-12-06 17:03:35 +00:00
|
|
|
|
2016-06-20 14:01:50 +00:00
|
|
|
const char *virNetSocketLocalAddrStringSASL(virNetSocketPtr sock);
|
|
|
|
const char *virNetSocketRemoteAddrStringSASL(virNetSocketPtr sock);
|
2016-06-20 13:48:47 +00:00
|
|
|
const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock);
|
2010-12-06 17:03:35 +00:00
|
|
|
|
2011-08-12 09:07:51 +00:00
|
|
|
int virNetSocketListen(virNetSocketPtr sock, int backlog);
|
2010-12-06 17:03:35 +00:00
|
|
|
int virNetSocketAccept(virNetSocketPtr sock,
|
|
|
|
virNetSocketPtr *clientsock);
|
|
|
|
|
|
|
|
int virNetSocketAddIOCallback(virNetSocketPtr sock,
|
|
|
|
int events,
|
|
|
|
virNetSocketIOFunc func,
|
2011-07-19 13:11:33 +00:00
|
|
|
void *opaque,
|
|
|
|
virFreeCallback ff);
|
2010-12-06 17:03:35 +00:00
|
|
|
|
|
|
|
void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
|
|
|
|
int events);
|
|
|
|
|
|
|
|
void virNetSocketRemoveIOCallback(virNetSocketPtr sock);
|
|
|
|
|
2011-08-04 08:54:58 +00:00
|
|
|
void virNetSocketClose(virNetSocketPtr sock);
|