This source file includes following definitions.
- pcmk__ipc_sys_name
1
2
3
4
5
6
7
8
9
10 #ifndef PCMK__CRM_COMMON_IPC_INTERNAL__H
11 #define PCMK__CRM_COMMON_IPC_INTERNAL__H
12
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include <sys/uio.h>
16 #include <sys/types.h>
17
18 #include <gnutls/gnutls.h>
19
20 #include <glib.h>
21 #include <libxml/tree.h>
22 #include <qb/qbipcs.h>
23
24 #include <crm_config.h>
25 #include <crm/crm.h>
26 #include <crm/common/ipc.h>
27 #include <crm/common/ipc_controld.h>
28 #include <crm/common/ipc_pacemakerd.h>
29 #include <crm/common/mainloop.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36
37
38
39
40
41
42 #define PCMK__SPECIAL_PID 1
43
44
45 #define PCMK__IPC_TIMEOUT 120
46
47 #if defined(HAVE_GETPEEREID)
48
49
50
51
52 #define PCMK__SPECIAL_PID_AS_0(p) (((p) == PCMK__SPECIAL_PID) ? 0 : (p))
53 #else
54 #define PCMK__SPECIAL_PID_AS_0(p) (p)
55 #endif
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 int pcmk__ipc_is_authentic_process_active(const char *name, uid_t refuid,
90 gid_t refgid, pid_t *gotpid);
91
92 int pcmk__connect_generic_ipc(crm_ipc_t *ipc);
93 int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd);
94 int pcmk__connect_ipc(pcmk_ipc_api_t *api, enum pcmk_ipc_dispatch dispatch_type,
95 int attempts);
96 int pcmk__connect_ipc_retry_conrefused(pcmk_ipc_api_t *api,
97 enum pcmk_ipc_dispatch dispatch_type,
98 int attempts);
99
100
101
102
103 typedef struct pcmk__client_s pcmk__client_t;
104
105 struct pcmk__remote_s {
106
107 char *buffer;
108 size_t buffer_size;
109 size_t buffer_offset;
110 int auth_timeout;
111 int tcp_socket;
112 mainloop_io_t *source;
113 time_t uptime;
114 char *start_state;
115
116
117 char *token;
118
119
120
121
122 gnutls_session_t tls_session;
123 };
124
125 enum pcmk__client_flags {
126
127
128
129
130
131 pcmk__client_ipc = (UINT64_C(1) << 32),
132
133
134 pcmk__client_tcp = (UINT64_C(1) << 33),
135
136
137 pcmk__client_tls = (UINT64_C(1) << 34),
138
139
140
141
142 pcmk__client_proxied = (UINT64_C(1) << 40),
143
144
145 pcmk__client_privileged = (UINT64_C(1) << 41),
146
147
148 pcmk__client_to_proxy = (UINT64_C(1) << 42),
149
150
151
152
153
154
155 pcmk__client_authenticated = (UINT64_C(1) << 43),
156
157
158 pcmk__client_tls_handshake_complete = (UINT64_C(1) << 44),
159 };
160
161 #define PCMK__CLIENT_TYPE(client) ((client)->flags & UINT64_C(0xff00000000))
162
163 struct pcmk__client_s {
164 unsigned int pid;
165
166 char *id;
167 char *name;
168 char *user;
169 uint64_t flags;
170
171 int request_id;
172 void *userdata;
173
174 int event_timer;
175 GQueue *event_queue;
176
177
178
179
180 GByteArray *buffer;
181
182
183
184
185
186 qb_ipcs_connection_t *ipcs;
187
188 struct pcmk__remote_s *remote;
189
190 unsigned int queue_backlog;
191 unsigned int queue_max;
192 };
193
194 #define pcmk__set_client_flags(client, flags_to_set) do { \
195 (client)->flags = pcmk__set_flags_as(__func__, __LINE__, \
196 LOG_TRACE, \
197 "Client", pcmk__client_name(client), \
198 (client)->flags, (flags_to_set), #flags_to_set); \
199 } while (0)
200
201 #define pcmk__clear_client_flags(client, flags_to_clear) do { \
202 (client)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
203 LOG_TRACE, \
204 "Client", pcmk__client_name(client), \
205 (client)->flags, (flags_to_clear), #flags_to_clear); \
206 } while (0)
207
208 #define pcmk__set_ipc_flags(ipc_flags, ipc_name, flags_to_set) do { \
209 ipc_flags = pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, \
210 "IPC", (ipc_name), \
211 (ipc_flags), (flags_to_set), \
212 #flags_to_set); \
213 } while (0)
214
215 #define pcmk__clear_ipc_flags(ipc_flags, ipc_name, flags_to_clear) do { \
216 ipc_flags = pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, \
217 "IPC", (ipc_name), \
218 (ipc_flags), (flags_to_clear), \
219 #flags_to_clear); \
220 } while (0)
221
222 guint pcmk__ipc_client_count(void);
223 void pcmk__foreach_ipc_client(GHFunc func, gpointer user_data);
224
225 void pcmk__client_cleanup(void);
226
227 pcmk__client_t *pcmk__find_client(const qb_ipcs_connection_t *c);
228 pcmk__client_t *pcmk__find_client_by_id(const char *id);
229 const char *pcmk__client_name(const pcmk__client_t *c);
230 const char *pcmk__client_type_str(uint64_t client_type);
231
232 pcmk__client_t *pcmk__new_unauth_client(void *key);
233 pcmk__client_t *pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid);
234 void pcmk__free_client(pcmk__client_t *c);
235 void pcmk__drop_all_clients(qb_ipcs_service_t *s);
236 void pcmk__set_client_queue_max(pcmk__client_t *client, const char *qmax);
237
238 xmlNode *pcmk__ipc_create_ack_as(const char *function, int line, uint32_t flags,
239 const char *tag, const char *ver, crm_exit_t status);
240 #define pcmk__ipc_create_ack(flags, tag, ver, st) \
241 pcmk__ipc_create_ack_as(__func__, __LINE__, (flags), (tag), (ver), (st))
242
243 int pcmk__ipc_send_ack_as(const char *function, int line, pcmk__client_t *c,
244 uint32_t request, uint32_t flags, const char *tag,
245 const char *ver, crm_exit_t status);
246 #define pcmk__ipc_send_ack(c, req, flags, tag, ver, st) \
247 pcmk__ipc_send_ack_as(__func__, __LINE__, (c), (req), (flags), (tag), (ver), (st))
248
249 int pcmk__ipc_prepare_iov(uint32_t request, const GString *message,
250 uint16_t index, struct iovec **result, ssize_t *bytes);
251 int pcmk__ipc_send_xml(pcmk__client_t *c, uint32_t request,
252 const xmlNode *message, uint32_t flags);
253 int pcmk__ipc_send_iov(pcmk__client_t *c, struct iovec *iov, uint32_t flags);
254 void pcmk__ipc_free_client_buffer(crm_ipc_t *client);
255 int pcmk__ipc_msg_append(GByteArray **buffer, guint8 *data);
256 xmlNode *pcmk__client_data2xml(pcmk__client_t *c, uint32_t *id, uint32_t *flags);
257
258 int pcmk__client_pid(qb_ipcs_connection_t *c);
259
260 void pcmk__serve_attrd_ipc(qb_ipcs_service_t **ipcs,
261 struct qb_ipcs_service_handlers *cb);
262 void pcmk__serve_fenced_ipc(qb_ipcs_service_t **ipcs,
263 struct qb_ipcs_service_handlers *cb);
264 void pcmk__serve_pacemakerd_ipc(qb_ipcs_service_t **ipcs,
265 struct qb_ipcs_service_handlers *cb);
266 qb_ipcs_service_t *pcmk__serve_schedulerd_ipc(struct qb_ipcs_service_handlers *cb);
267 qb_ipcs_service_t *pcmk__serve_controld_ipc(struct qb_ipcs_service_handlers *cb);
268
269 void pcmk__serve_based_ipc(qb_ipcs_service_t **ipcs_ro,
270 qb_ipcs_service_t **ipcs_rw,
271 qb_ipcs_service_t **ipcs_shm,
272 struct qb_ipcs_service_handlers *ro_cb,
273 struct qb_ipcs_service_handlers *rw_cb);
274
275 void pcmk__stop_based_ipc(qb_ipcs_service_t *ipcs_ro,
276 qb_ipcs_service_t *ipcs_rw,
277 qb_ipcs_service_t *ipcs_shm);
278
279 static inline const char *
280 pcmk__ipc_sys_name(const char *ipc_name, const char *fallback)
281 {
282 return ipc_name ? ipc_name : ((crm_system_name ? crm_system_name : fallback));
283 }
284
285 const char *pcmk__pcmkd_state_enum2friendly(enum pcmk_pacemakerd_state state);
286
287 const char *pcmk__controld_api_reply2str(enum pcmk_controld_api_reply reply);
288 const char *pcmk__pcmkd_api_reply2str(enum pcmk_pacemakerd_api_reply reply);
289
290 #ifdef __cplusplus
291 }
292 #endif
293
294 #endif