pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ipc_common.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2021 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  long long global_ll;
37 
38  if ((pcmk__scan_ll(getenv("PCMK_ipc_buffer"), &global_ll,
39  0LL) != pcmk_rc_ok)
40  || (global_ll <= 0)) {
41  global_max = MAX_MSG_SIZE; // Default for unset or invalid
42 
43  } else if (global_ll < MIN_MSG_SIZE) {
44  global_max = MIN_MSG_SIZE;
45 
46  } else if (global_ll > UINT_MAX) {
47  global_max = UINT_MAX;
48 
49  } else {
50  global_max = (unsigned int) global_ll;
51  }
52  }
53  return QB_MAX(max, global_max);
54 }
55 
61 unsigned int
63 {
64  static unsigned int default_size = 0;
65 
66  if (default_size == 0) {
67  default_size = pcmk__ipc_buffer_size(0);
68  }
69  return default_size;
70 }
71 
80 bool
82 {
83  if (header == NULL) {
84  crm_err("IPC message without header");
85  return false;
86 
87  } else if (header->version > PCMK__IPC_VERSION) {
88  crm_err("Filtering incompatible v%d IPC message (only versions <= %d supported)",
89  header->version, PCMK__IPC_VERSION);
90  return false;
91  }
92  return true;
93 }
94 
95 const char *
96 pcmk__client_type_str(uint64_t client_type)
97 {
98  switch (client_type) {
99  case pcmk__client_ipc:
100  return "IPC";
101  case pcmk__client_tcp:
102  return "TCP";
103 #ifdef HAVE_GNUTLS_GNUTLS_H
104  case pcmk__client_tls:
105  return "TLS";
106 #endif
107  default:
108  return "unknown";
109  }
110 }
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
Definition: strings.c:97
#define PCMK__IPC_VERSION
#define MAX_MSG_SIZE
Definition: ipc_common.c:20
G_GNUC_INTERNAL bool pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
Definition: ipc_common.c:81
unsigned int crm_ipc_default_buffer_size(void)
Return pacemaker&#39;s default IPC buffer size.
Definition: ipc_common.c:62
G_GNUC_INTERNAL unsigned int pcmk__ipc_buffer_size(unsigned int max)
Definition: ipc_common.c:31
#define MIN_MSG_SIZE
Definition: ipc_common.c:19
#define crm_err(fmt, args...)
Definition: logging.h:350
const char * pcmk__client_type_str(uint64_t client_type)
Definition: ipc_common.c:96