45#include <sys/socket.h>
76 char *buf,
size_t buf_size)
80 for (i = 0; servicenames[i].c_name != NULL; i++) {
81 if (service_id == servicenames[i].
c_val) {
82 return (servicenames[i].
c_name);
85 snprintf(buf, buf_size,
"%d", service_id);
95 return ((strncmp ((
char *)name1->
value, (
char *)name2->
value,
109 if (gettimeofday(&tv, 0)) {
113 time_now = (
cs_time_t)(tv.tv_sec) * 1000000000ULL;
114 time_now += (
cs_time_t)(tv.tv_usec) * 1000ULL;
134 "Corosync Cluster Engine exiting normally");
137 "with status %d at %s:%u.", err, file, line);
149 memset (ret_name, 0,
sizeof (ret_name));
153 return ((
char *)name->
value);
157 strncpy ((
char *)name->
value, str, sizeof (name->
value) - 1);
158 ((
char *)name->
value)[
sizeof (name->
value) - 1] =
'\0';
162 name->
length = strlen (str);
167 if (str1->
length == strlen (str2)) {
168 return ((strncmp ((
char *)str1->
value, (
char *)str2,
177 static char path[PATH_MAX] = {
'\0'};
181 if (path[0] ==
'\0') {
183 res = snprintf(path, PATH_MAX,
"%s", state_dir);
185 }
else if ((state_dir = getenv(
"STATE_DIRECTORY")) != NULL) {
195 res = snprintf(path, PATH_MAX,
"%s", state_dir);
197 res = snprintf(path, PATH_MAX,
"%s/%s",
LOCALSTATEDIR,
"lib/corosync");
200 assert(res < PATH_MAX);
206static int safe_strcat(
char *dst,
size_t dst_len,
const char *src)
209 if (strlen(dst) + strlen(src) >= dst_len - 1) {
218#define UTILS_IS_VALID_KNET_LIST_MAX_ITEMS 256
229static int util_is_valid_knet_list_helper(
const char *val,
230 const char **items,
size_t no_items,
231 const char **list_str,
int machine_parseable_str,
232 const char *error_string_prefix,
const char **error_string)
234 static char local_error_str[512];
235 static char local_list_str[256];
239 if (list_str != NULL) {
240 *list_str = local_list_str;
243 memset(local_error_str, 0,
sizeof(local_error_str));
244 memset(local_list_str, 0,
sizeof(local_list_str));
246 safe_strcat(local_error_str,
sizeof(local_error_str), error_string_prefix);
248 for (zi = 0; zi < no_items; zi++) {
250 }
else if (zi == no_items - 1) {
251 if (machine_parseable_str) {
252 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
254 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" or ");
257 if (machine_parseable_str) {
258 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
260 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
", ");
264 (void)safe_strcat(local_list_str,
sizeof(local_list_str), items[zi]);
266 if (val != NULL && strcmp(val, items[zi]) == 0) {
272 (void)safe_strcat(local_error_str,
sizeof(local_error_str), local_list_str);
273 *error_string = local_error_str;
276 return (model_found);
287 const char **list_str,
int machine_parseable_str,
288 const char *error_string_prefix,
const char **error_string)
295 if (knet_get_crypto_list(NULL, &entries) != 0) {
296 *error_string =
"internal error - cannot get knet crypto list";
300 if (entries >
sizeof(crypto_list) /
sizeof(crypto_list[0])) {
301 *error_string =
"internal error - too many knet crypto list entries";
305 if (knet_get_crypto_list(crypto_list, &entries) != 0) {
306 *error_string =
"internal error - cannot get knet crypto list";
310 for (zi = 0; zi < entries; zi++) {
311 items[zi] = crypto_list[zi].name;
314 return (util_is_valid_knet_list_helper(val, items, entries, list_str,
315 machine_parseable_str, error_string_prefix, error_string));
322 const char **list_str,
int machine_parseable_str,
323 const char *error_string_prefix,
const char **error_string)
330 if (knet_get_compress_list(NULL, &entries) != 0) {
331 *error_string =
"internal error - cannot get knet compress list";
335 if (entries >
sizeof(compress_list) /
sizeof(compress_list[0])) {
336 *error_string =
"internal error - too many knet compress list entries";
340 if (knet_get_compress_list(compress_list, &entries) != 0) {
341 *error_string =
"internal error - cannot get knet compress list";
345 for (zi = 0; zi < entries; zi++) {
346 items[zi] = compress_list[zi].name;
349 return (util_is_valid_knet_list_helper(val, items, entries, list_str,
350 machine_parseable_str, error_string_prefix, error_string));
357 const char **list_str,
int machine_parseable_str,
358 const char *error_string_prefix,
const char **error_string)
361 size_t items_out_idx = 0;
362#ifdef HAVE_KNET_GET_CRYPTO_CIPHER_LIST
368#ifdef ENABLE_UNENCRYPTED
369 items[items_out_idx++] =
"none";
372#ifdef HAVE_KNET_GET_CRYPTO_CIPHER_LIST
373 if (knet_get_crypto_cipher_list(NULL, &entries) != 0) {
374 *error_string =
"internal error - cannot get crypto cipher list";
378 if (entries > (
sizeof(crypto_cipher_list) /
sizeof(crypto_cipher_list[0])) - items_out_idx) {
379 *error_string =
"internal error - too many knet crypto cipher list entries";
383 if (knet_get_crypto_cipher_list(crypto_cipher_list, &entries) != 0) {
384 *error_string =
"internal error - cannot get knet crypto cipher list";
388 for (zi = 0; zi < entries; zi++) {
389 items[items_out_idx++] = crypto_cipher_list[zi].name;
392 items[items_out_idx++] =
"aes256";
393 items[items_out_idx++] =
"aes192";
394 items[items_out_idx++] =
"aes128";
397 return (util_is_valid_knet_list_helper(val, items, items_out_idx, list_str,
398 machine_parseable_str, error_string_prefix, error_string));
405 const char **list_str,
int machine_parseable_str,
406 const char *error_string_prefix,
const char **error_string)
409 size_t items_out_idx = 0;
410#ifdef HAVE_KNET_GET_CRYPTO_HASH_LIST
416#ifdef ENABLE_UNENCRYPTED
417 items[items_out_idx++] =
"none";
420#ifdef HAVE_KNET_GET_CRYPTO_HASH_LIST
421 if (knet_get_crypto_hash_list(NULL, &entries) != 0) {
422 *error_string =
"internal error - cannot get crypto hash list";
426 if (entries > (
sizeof(crypto_hash_list) /
sizeof(crypto_hash_list[0])) - items_out_idx) {
427 *error_string =
"internal error - too many knet crypto hash list entries";
431 if (knet_get_crypto_hash_list(crypto_hash_list, &entries) != 0) {
432 *error_string =
"internal error - cannot get knet crypto hash list";
436 for (zi = 0; zi < entries; zi++) {
437 items[items_out_idx++] = crypto_hash_list[zi].name;
440 items[items_out_idx++] =
"md5";
441 items[items_out_idx++] =
"sha1";
442 items[items_out_idx++] =
"sha256";
443 items[items_out_idx++] =
"sha384";
444 items[items_out_idx++] =
"sha512";
447 return (util_is_valid_knet_list_helper(val, items, items_out_idx, list_str,
448 machine_parseable_str, error_string_prefix, error_string));
459 tos = (dscp & 0x3f) << 2;
460 res = setsockopt(socket, IPPROTO_IP, IP_TOS, &tos,
sizeof(tos));
int64_t cs_time_t
cs_time_t
#define CS_MAX_NAME_LENGTH
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
void logsys_system_fini(void)
logsys_system_fini
#define LOGSYS_LEVEL_NOTICE
#define LOGSYS_DECLARE_SUBSYS(subsys)
The LOGSYS_DECLARE_SUBSYS macro.
uint8_t value[CS_MAX_NAME_LENGTH]
int util_is_valid_knet_crypto_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
char * getcs_name_t(cs_name_t *name)
const char * get_state_dir(void)
cs_time_t clust_time_now(void)
Get the time of day and convert to nanoseconds.
int util_is_valid_knet_crypto_cipher(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
int util_is_valid_knet_crypto_hash(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
const char * short_service_name_get(uint32_t service_id, char *buf, size_t buf_size)
Get the short name of a service from the service_id.
int util_is_valid_knet_compress_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
#define UTILS_IS_VALID_KNET_LIST_MAX_ITEMS
int name_match(cs_name_t *name1, cs_name_t *name2)
Compare two names.
void setcs_name_t(cs_name_t *name, char *str)
int set_socket_dscp(int socket, unsigned char dscp)
void _corosync_out_of_memory_error(void)
void _corosync_exit_error(enum e_corosync_done err, const char *file, unsigned int line) __attribute__((noreturn))
int cs_name_tisEqual(cs_name_t *str1, char *str2)