LCOV - code coverage report
Current view: top level - common - ipc_common.c (source / functions) Hit Total Coverage
Test: Pacemaker code coverage Lines: 0 33 0.0 %
Date: 2024-05-07 11:09:47 Functions: 0 4 0.0 %

          Line data    Source code
       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             : 
      22             : /*!
      23             :  * \internal
      24             :  * \brief Choose an IPC buffer size in bytes
      25             :  *
      26             :  * \param[in] max  Use this value if environment/default is lower
      27             :  *
      28             :  * \return Maximum of max and value of PCMK_ipc_buffer (default 128KB)
      29             :  */
      30             : unsigned int
      31           0 : pcmk__ipc_buffer_size(unsigned int max)
      32             : {
      33             :     static unsigned int global_max = 0;
      34             : 
      35           0 :     if (global_max == 0) {
      36             :         long long global_ll;
      37             : 
      38           0 :         if ((pcmk__scan_ll(pcmk__env_option(PCMK__ENV_IPC_BUFFER), &global_ll,
      39             :                            0LL) != pcmk_rc_ok)
      40           0 :             || (global_ll <= 0)) {
      41           0 :             global_max = MAX_MSG_SIZE; // Default for unset or invalid
      42             : 
      43           0 :         } else if (global_ll < MIN_MSG_SIZE) {
      44           0 :             global_max = MIN_MSG_SIZE;
      45             : 
      46           0 :         } else if (global_ll > UINT_MAX) {
      47           0 :             global_max = UINT_MAX;
      48             : 
      49             :         } else {
      50           0 :             global_max = (unsigned int) global_ll;
      51             :         }
      52             :     }
      53           0 :     return QB_MAX(max, global_max);
      54             : }
      55             : 
      56             : /*!
      57             :  * \brief Return pacemaker's default IPC buffer size
      58             :  *
      59             :  * \return IPC buffer size in bytes
      60             :  */
      61             : unsigned int
      62           0 : crm_ipc_default_buffer_size(void)
      63             : {
      64             :     static unsigned int default_size = 0;
      65             : 
      66           0 :     if (default_size == 0) {
      67           0 :         default_size = pcmk__ipc_buffer_size(0);
      68             :     }
      69           0 :     return default_size;
      70             : }
      71             : 
      72             : /*!
      73             :  * \internal
      74             :  * \brief Check whether an IPC header is valid
      75             :  *
      76             :  * \param[in] header  IPC header to check
      77             :  *
      78             :  * \return true if IPC header has a supported version, false otherwise
      79             :  */
      80             : bool
      81           0 : pcmk__valid_ipc_header(const pcmk__ipc_header_t *header)
      82             : {
      83           0 :     if (header == NULL) {
      84           0 :         crm_err("IPC message without header");
      85           0 :         return false;
      86             : 
      87           0 :     } else if (header->version > PCMK__IPC_VERSION) {
      88           0 :         crm_err("Filtering incompatible v%d IPC message (only versions <= %d supported)",
      89             :                 header->version, PCMK__IPC_VERSION);
      90           0 :         return false;
      91             :     }
      92           0 :     return true;
      93             : }
      94             : 
      95             : const char *
      96           0 : pcmk__client_type_str(uint64_t client_type)
      97             : {
      98           0 :     switch (client_type) {
      99           0 :         case pcmk__client_ipc:
     100           0 :             return "IPC";
     101           0 :         case pcmk__client_tcp:
     102           0 :             return "TCP";
     103             : #ifdef HAVE_GNUTLS_GNUTLS_H
     104           0 :         case pcmk__client_tls:
     105           0 :             return "TLS";
     106             : #endif
     107           0 :         default:
     108           0 :             return "unknown";
     109             :     }
     110             : }

Generated by: LCOV version 1.14