pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
ipc_common.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2020 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/msg_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 unsigned int global_max = 0;
34 
35  if (global_max == 0) {
36  const char *env = getenv("PCMK_ipc_buffer");
37 
38  if (env) {
39  int env_max = crm_parse_int(env, "0");
40 
41  global_max = (env_max > 0)? QB_MAX(MIN_MSG_SIZE, env_max) : MAX_MSG_SIZE;
42 
43  } else {
44  global_max = MAX_MSG_SIZE;
45  }
46  }
47  return QB_MAX(max, global_max);
48 }
49 
55 unsigned int
57 {
58  static unsigned int default_size = 0;
59 
60  if (default_size == 0) {
61  default_size = pcmk__ipc_buffer_size(0);
62  }
63  return default_size;
64 }
65 
74 bool
76 {
77  if (header == NULL) {
78  crm_err("IPC message without header");
79  return false;
80 
81  } else if (header->version > PCMK__IPC_VERSION) {
82  crm_err("Filtering incompatible v%d IPC message (only versions <= %d supported)",
83  header->version, PCMK__IPC_VERSION);
84  return false;
85  }
86  return true;
87 }
88 
89 const char *
90 pcmk__client_type_str(uint64_t client_type)
91 {
92  switch (client_type) {
93  case pcmk__client_ipc:
94  return "IPC";
95  case pcmk__client_tcp:
96  return "TCP";
97 #ifdef HAVE_GNUTLS_GNUTLS_H
98  case pcmk__client_tls:
99  return "TLS";
100 #endif
101  default:
102  return "unknown";
103  }
104 }
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
Definition: strings.c:134
unsigned int pcmk__ipc_buffer_size(unsigned int max)
Definition: ipc_common.c:31
bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
Definition: ipc_common.c:75
#define PCMK__IPC_VERSION
#define MAX_MSG_SIZE
Definition: ipc_common.c:20
unsigned int crm_ipc_default_buffer_size(void)
Return pacemaker's default IPC buffer size.
Definition: ipc_common.c:56
#define MIN_MSG_SIZE
Definition: ipc_common.c:19
#define crm_err(fmt, args...)
Definition: logging.h:347
const char * pcmk__client_type_str(uint64_t client_type)
Definition: ipc_common.c:90