This source file includes following definitions.
- pcmk__ipc_buffer_size
- crm_ipc_default_buffer_size
- pcmk__valid_ipc_header
- pcmk__client_type_str
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <sys/types.h>
15
16 #include <crm/common/xml.h>
17 #include "crmcommon_private.h"
18
19 #define MIN_MSG_SIZE 12336
20 #define MAX_MSG_SIZE 128*1024
21
22
23
24
25
26
27
28
29
30 unsigned int
31 pcmk__ipc_buffer_size(unsigned int max)
32 {
33 static long long env_value = 0LL;
34
35 if (env_value == 0LL) {
36 const char *env_value_s = pcmk__env_option(PCMK__ENV_IPC_BUFFER);
37 int rc = pcmk__scan_ll(env_value_s, &env_value, MAX_MSG_SIZE);
38
39 if (rc != pcmk_rc_ok) {
40 env_value = MAX_MSG_SIZE;
41 max = QB_MAX(max, env_value);
42 crm_warn("Using %u as IPC buffer size because '%s' is not "
43 "a valid value for PCMK_" PCMK__ENV_IPC_BUFFER ": %s",
44 max, env_value_s, pcmk_rc_str(rc));
45
46 } else if (env_value <= 0LL) {
47 env_value = MAX_MSG_SIZE;
48 max = QB_MAX(max, env_value);
49 crm_warn("Using %u as IPC buffer size because PCMK_"
50 PCMK__ENV_IPC_BUFFER " (%s) is not a positive integer",
51 max, env_value_s);
52
53 } else if (env_value < MIN_MSG_SIZE) {
54 env_value = MIN_MSG_SIZE;
55 max = QB_MAX(max, env_value);
56 crm_debug("Using %u as IPC buffer size because PCMK_"
57 PCMK__ENV_IPC_BUFFER " (%s) is too small",
58 max, env_value_s);
59
60 } else if (env_value > UINT_MAX) {
61 env_value = UINT_MAX;
62 max = UINT_MAX;
63 crm_debug("Using %u as IPC buffer size because PCMK_"
64 PCMK__ENV_IPC_BUFFER " (%s) is too big",
65 max, env_value_s);
66 }
67 }
68
69 if (env_value > max) {
70 const char *source = "PCMK_" PCMK__ENV_IPC_BUFFER;
71
72 if (env_value == MAX_MSG_SIZE) {
73 source = "default";
74 }
75 crm_debug("Using IPC buffer size %lld from %s (not %u)",
76 env_value, source, max);
77 max = env_value;
78 }
79 return max;
80 }
81
82
83
84
85
86
87 unsigned int
88 crm_ipc_default_buffer_size(void)
89 {
90 static unsigned int default_size = 0;
91
92 if (default_size == 0) {
93 default_size = pcmk__ipc_buffer_size(0);
94 }
95 return default_size;
96 }
97
98
99
100
101
102
103
104
105
106 bool
107 pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
108 {
109 if (header == NULL) {
110 crm_err("IPC message without header");
111 return false;
112
113 } else if (header->version > PCMK__IPC_VERSION) {
114 crm_err("Filtering incompatible v%d IPC message (only versions <= %d supported)",
115 header->version, PCMK__IPC_VERSION);
116 return false;
117 }
118 return true;
119 }
120
121 const char *
122 pcmk__client_type_str(uint64_t client_type)
123 {
124 switch (client_type) {
125 case pcmk__client_ipc:
126 return "IPC";
127 case pcmk__client_tcp:
128 return "TCP";
129 #ifdef HAVE_GNUTLS_GNUTLS_H
130 case pcmk__client_tls:
131 return "TLS";
132 #endif
133 default:
134 return "unknown";
135 }
136 }