virnetsocket.h 6.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21
 */

22 23 24 25 26 27 28 29 30 31 32 33 34
#pragma once

#include "virsocketaddr.h"
#include "vircommand.h"
#ifdef WITH_GNUTLS
# include "virnettlscontext.h"
#endif
#include "virobject.h"
#ifdef WITH_SASL
# include "virnetsaslcontext.h"
#endif
#include "virjson.h"
#include "viruri.h"
35 36 37 38 39 40 41 42 43 44

typedef struct _virNetSocket virNetSocket;
typedef virNetSocket *virNetSocketPtr;


typedef void (*virNetSocketIOFunc)(virNetSocketPtr sock,
                                   int events,
                                   void *opaque);


45 46 47
int virNetSocketCheckProtocols(bool *hasIPv4,
                               bool *hasIPv6);

48 49
int virNetSocketNewListenTCP(const char *nodename,
                             const char *service,
50
                             int family,
51 52 53 54 55
                             virNetSocketPtr **addrs,
                             size_t *naddrs);

int virNetSocketNewListenUNIX(const char *path,
                              mode_t mask,
56
                              uid_t user,
57 58
                              gid_t grp,
                              virNetSocketPtr *addr);
59 60 61

int virNetSocketNewListenFD(int fd,
                            virNetSocketPtr *addr);
62 63 64

int virNetSocketNewConnectTCP(const char *nodename,
                              const char *service,
65
                              int family,
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
                              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,
81
                              bool noVerify,
82
                              const char *netcat,
83
                              const char *keyfile,
84 85 86
                              const char *path,
                              virNetSocketPtr *addr);

87 88
int virNetSocketNewConnectLibSSH2(const char *host,
                                  const char *port,
89
                                  int family,
90 91 92 93 94 95 96
                                  const char *username,
                                  const char *privkey,
                                  const char *knownHosts,
                                  const char *knownHostsVerify,
                                  const char *authMethods,
                                  const char *command,
                                  virConnectAuthPtr auth,
97
                                  virURIPtr uri,
98 99
                                  virNetSocketPtr *retsock);

100 101 102 103 104 105 106 107 108 109 110 111 112
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);

113 114 115
int virNetSocketNewConnectExternal(const char **cmdargv,
                                   virNetSocketPtr *addr);

116 117
int virNetSocketNewConnectSockFD(int sockfd,
                                 virNetSocketPtr *retsock);
118 119 120 121 122

virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);

virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);

123
int virNetSocketGetFD(virNetSocketPtr sock);
124 125
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);

126 127
bool virNetSocketIsLocal(virNetSocketPtr sock);

128 129
bool virNetSocketHasPassFD(virNetSocketPtr sock);

130 131
int virNetSocketGetPort(virNetSocketPtr sock);

132 133 134
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
                                uid_t *uid,
                                gid_t *gid,
135
                                pid_t *pid,
136
                                unsigned long long *timestamp)
137
    ATTRIBUTE_NOINLINE;
138
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
139
                                  char **context)
140
    ATTRIBUTE_NOINLINE;
141 142 143 144

int virNetSocketSetBlocking(virNetSocketPtr sock,
                            bool blocking);

145 146
void virNetSocketSetQuietEOF(virNetSocketPtr sock);

147 148 149
ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);

150
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
151
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
152

153
#ifdef WITH_GNUTLS
154 155
void virNetSocketSetTLSSession(virNetSocketPtr sock,
                               virNetTLSSessionPtr sess);
156
#endif
157

158
#ifdef WITH_SASL
159 160
void virNetSocketSetSASLSession(virNetSocketPtr sock,
                                virNetSASLSessionPtr sess);
161
#endif
162
bool virNetSocketHasCachedData(virNetSocketPtr sock);
163
bool virNetSocketHasPendingData(virNetSocketPtr sock);
164

165 166
const char *virNetSocketLocalAddrStringSASL(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrStringSASL(virNetSocketPtr sock);
167
const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock);
168

169
int virNetSocketListen(virNetSocketPtr sock, int backlog);
170 171 172 173 174 175
int virNetSocketAccept(virNetSocketPtr sock,
                       virNetSocketPtr *clientsock);

int virNetSocketAddIOCallback(virNetSocketPtr sock,
                              int events,
                              virNetSocketIOFunc func,
176 177
                              void *opaque,
                              virFreeCallback ff);
178 179 180 181 182 183

void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
                                  int events);

void virNetSocketRemoveIOCallback(virNetSocketPtr sock);

184
void virNetSocketClose(virNetSocketPtr sock);