virnetsocket.h 6.9 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
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_NET_SOCKET_H__
# define __VIR_NET_SOCKET_H__

27
# include "virsocketaddr.h"
28
# include "vircommand.h"
29
# ifdef WITH_GNUTLS
30 31
#  include "virnettlscontext.h"
# endif
32
# include "virobject.h"
33
# ifdef WITH_SASL
34 35
#  include "virnetsaslcontext.h"
# endif
36
# include "virjson.h"
37
# include "viruri.h"
38 39 40 41 42 43 44 45 46 47

typedef struct _virNetSocket virNetSocket;
typedef virNetSocket *virNetSocketPtr;


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


48 49 50
int virNetSocketCheckProtocols(bool *hasIPv4,
                               bool *hasIPv6);

51 52
int virNetSocketNewListenTCP(const char *nodename,
                             const char *service,
53
                             int family,
54 55 56 57 58
                             virNetSocketPtr **addrs,
                             size_t *naddrs);

int virNetSocketNewListenUNIX(const char *path,
                              mode_t mask,
59
                              uid_t user,
60 61
                              gid_t grp,
                              virNetSocketPtr *addr);
62 63 64

int virNetSocketNewListenFD(int fd,
                            virNetSocketPtr *addr);
65 66 67

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

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

103 104 105 106 107 108 109 110 111 112 113 114 115
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);

116 117 118
int virNetSocketNewConnectExternal(const char **cmdargv,
                                   virNetSocketPtr *addr);

119 120
int virNetSocketNewConnectSockFD(int sockfd,
                                 virNetSocketPtr *retsock);
121 122 123 124 125

virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);

virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);

126
int virNetSocketGetFD(virNetSocketPtr sock);
127 128
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);

129 130
bool virNetSocketIsLocal(virNetSocketPtr sock);

131 132
bool virNetSocketHasPassFD(virNetSocketPtr sock);

133 134
int virNetSocketGetPort(virNetSocketPtr sock);

135 136 137
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
                                uid_t *uid,
                                gid_t *gid,
138
                                pid_t *pid,
139
                                unsigned long long *timestamp)
140
    ATTRIBUTE_MOCKABLE;
141
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
142
                                  char **context)
143
    ATTRIBUTE_MOCKABLE;
144 145 146 147

int virNetSocketSetBlocking(virNetSocketPtr sock,
                            bool blocking);

148 149
void virNetSocketSetQuietEOF(virNetSocketPtr sock);

150 151 152
ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);

153
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
154
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
155

156
# ifdef WITH_GNUTLS
157 158
void virNetSocketSetTLSSession(virNetSocketPtr sock,
                               virNetTLSSessionPtr sess);
159
# endif
160

161
# ifdef WITH_SASL
162 163 164 165
void virNetSocketSetSASLSession(virNetSocketPtr sock,
                                virNetSASLSessionPtr sess);
# endif
bool virNetSocketHasCachedData(virNetSocketPtr sock);
166
bool virNetSocketHasPendingData(virNetSocketPtr sock);
167

168 169
const char *virNetSocketLocalAddrStringSASL(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrStringSASL(virNetSocketPtr sock);
170
const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock);
171

172
int virNetSocketListen(virNetSocketPtr sock, int backlog);
173 174 175 176 177 178
int virNetSocketAccept(virNetSocketPtr sock,
                       virNetSocketPtr *clientsock);

int virNetSocketAddIOCallback(virNetSocketPtr sock,
                              int events,
                              virNetSocketIOFunc func,
179 180
                              void *opaque,
                              virFreeCallback ff);
181 182 183 184 185 186

void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
                                  int events);

void virNetSocketRemoveIOCallback(virNetSocketPtr sock);

187
void virNetSocketClose(virNetSocketPtr sock);
188 189 190


#endif /* __VIR_NET_SOCKET_H__ */