pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
ipc_common.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <stdio.h>
13 #include <stdint.h> // uint64_t
14 #include <sys/types.h>
15 
16 #include <crm/common/xml.h>
17 #include "crmcommon_private.h"
18 
19 #define MIN_MSG_SIZE 12336 // sizeof(struct qb_ipc_connection_response)
20 #define MAX_MSG_SIZE 128*1024 // 128k default
21 
30 unsigned int
31 pcmk__ipc_buffer_size(unsigned int max)
32 {
33  static long long env_value = 0LL; // Will be bounded to unsigned int
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 
87 unsigned int
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 
106 bool
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 }
Client uses TCP connection.
Definition: ipc_internal.h:139
#define PCMK__ENV_IPC_BUFFER
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Definition: results.c:503
unsigned int pcmk__ipc_buffer_size(unsigned int max)
Definition: ipc_common.c:31
const char * pcmk__env_option(const char *option)
Definition: options.c:1094
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
Definition: strings.c:96
#define crm_warn(fmt, args...)
Definition: logging.h:394
bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
Definition: ipc_common.c:107
#define PCMK__IPC_VERSION
#define crm_debug(fmt, args...)
Definition: logging.h:402
#define MAX_MSG_SIZE
Definition: ipc_common.c:20
Wrappers for and extensions to libxml2.
unsigned int crm_ipc_default_buffer_size(void)
Return pacemaker&#39;s default IPC buffer size.
Definition: ipc_common.c:88
#define MIN_MSG_SIZE
Definition: ipc_common.c:19
#define crm_err(fmt, args...)
Definition: logging.h:391
const char * pcmk__client_type_str(uint64_t client_type)
Definition: ipc_common.c:122
Client uses plain IPC.
Definition: ipc_internal.h:136