virnetsocket.h 6.2 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
int virNetSocketNewConnectExternal(const char **cmdargv,
                                   virNetSocketPtr *addr);

106 107
int virNetSocketNewConnectSockFD(int sockfd,
                                 virNetSocketPtr *retsock);
108 109 110 111 112

virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);

virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);

113
int virNetSocketGetFD(virNetSocketPtr sock);
114 115
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);

116 117
bool virNetSocketIsLocal(virNetSocketPtr sock);

118 119
bool virNetSocketHasPassFD(virNetSocketPtr sock);

120 121
int virNetSocketGetPort(virNetSocketPtr sock);

122 123 124
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
                                uid_t *uid,
                                gid_t *gid,
125 126
                                pid_t *pid,
                                unsigned long long *timestamp);
127 128
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
                                  char **context);
129 130 131 132 133 134 135

int virNetSocketSetBlocking(virNetSocketPtr sock,
                            bool blocking);

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

136
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
137
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
138

139
# ifdef WITH_GNUTLS
140 141
void virNetSocketSetTLSSession(virNetSocketPtr sock,
                               virNetTLSSessionPtr sess);
142
# endif
143

144
# ifdef WITH_SASL
145 146 147 148
void virNetSocketSetSASLSession(virNetSocketPtr sock,
                                virNetSASLSessionPtr sess);
# endif
bool virNetSocketHasCachedData(virNetSocketPtr sock);
149
bool virNetSocketHasPendingData(virNetSocketPtr sock);
150

151 152
const char *virNetSocketLocalAddrStringSASL(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrStringSASL(virNetSocketPtr sock);
153
const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock);
154

155
int virNetSocketListen(virNetSocketPtr sock, int backlog);
156 157 158 159 160 161
int virNetSocketAccept(virNetSocketPtr sock,
                       virNetSocketPtr *clientsock);

int virNetSocketAddIOCallback(virNetSocketPtr sock,
                              int events,
                              virNetSocketIOFunc func,
162 163
                              void *opaque,
                              virFreeCallback ff);
164 165 166 167 168 169

void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
                                  int events);

void virNetSocketRemoveIOCallback(virNetSocketPtr sock);

170
void virNetSocketClose(virNetSocketPtr sock);
171 172 173


#endif /* __VIR_NET_SOCKET_H__ */