2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
3 * Copyright (c) 2006-2018 Red Hat, Inc.
7 * Author: Steven Dake (sdake@redhat.com)
8 * Jan Friesse (jfriesse@redhat.com)
10 * This software licensed under BSD license, the text of which follows:
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * - Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * - Neither the name of the MontaVista Software, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
44 #include <sys/socket.h>
45 #include <sys/types.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
52 #include <sys/param.h>
53 #include <sys/utsname.h>
55 #include <corosync/swab.h>
56 #include <qb/qblist.h>
57 #include <qb/qbdefs.h>
59 #include <corosync/totem/totem.h>
60 #include <corosync/config.h>
61 #include <corosync/logsys.h>
62 #include <corosync/icmap.h>
65 #include "totemconfig.h"
67 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
68 #define TOKEN_TIMEOUT 1000
69 #define TOKEN_WARNING 75
70 #define TOKEN_COEFFICIENT 650
71 #define JOIN_TIMEOUT 50
72 #define MERGE_TIMEOUT 200
73 #define DOWNCHECK_TIMEOUT 1000
74 #define FAIL_TO_RECV_CONST 2500
75 #define SEQNO_UNCHANGED_CONST 30
76 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
77 #define MINIMUM_TIMEOUT_HOLD (int)(MINIMUM_TIMEOUT * 0.8 - (1000/HZ))
78 #define MAX_NETWORK_DELAY 50
79 #define WINDOW_SIZE 50
80 #define MAX_MESSAGES 17
81 #define MISS_COUNT_CONST 5
82 #define BLOCK_UNLISTED_IPS 1
84 /* These currently match the defaults in libknet.h */
85 #define KNET_PING_INTERVAL 1000
86 #define KNET_PING_TIMEOUT 2000
87 #define KNET_PING_PRECISION 2048
88 #define KNET_PONG_COUNT 2
89 #define KNET_PMTUD_INTERVAL 30
90 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP
92 #define DEFAULT_PORT 5405
94 static char error_string_response
[768];
96 static void add_totem_config_notification(struct totem_config
*totem_config
);
98 static void *totem_get_param_by_name(struct totem_config
*totem_config
, const char *param_name
)
100 if (strcmp(param_name
, "totem.token") == 0)
101 return &totem_config
->token_timeout
;
102 if (strcmp(param_name
, "totem.token_warning") == 0)
103 return &totem_config
->token_warning
;
104 if (strcmp(param_name
, "totem.token_retransmit") == 0)
105 return &totem_config
->token_retransmit_timeout
;
106 if (strcmp(param_name
, "totem.hold") == 0)
107 return &totem_config
->token_hold_timeout
;
108 if (strcmp(param_name
, "totem.token_retransmits_before_loss_const") == 0)
109 return &totem_config
->token_retransmits_before_loss_const
;
110 if (strcmp(param_name
, "totem.join") == 0)
111 return &totem_config
->join_timeout
;
112 if (strcmp(param_name
, "totem.send_join") == 0)
113 return &totem_config
->send_join_timeout
;
114 if (strcmp(param_name
, "totem.consensus") == 0)
115 return &totem_config
->consensus_timeout
;
116 if (strcmp(param_name
, "totem.merge") == 0)
117 return &totem_config
->merge_timeout
;
118 if (strcmp(param_name
, "totem.downcheck") == 0)
119 return &totem_config
->downcheck_timeout
;
120 if (strcmp(param_name
, "totem.fail_recv_const") == 0)
121 return &totem_config
->fail_to_recv_const
;
122 if (strcmp(param_name
, "totem.seqno_unchanged_const") == 0)
123 return &totem_config
->seqno_unchanged_const
;
124 if (strcmp(param_name
, "totem.heartbeat_failures_allowed") == 0)
125 return &totem_config
->heartbeat_failures_allowed
;
126 if (strcmp(param_name
, "totem.max_network_delay") == 0)
127 return &totem_config
->max_network_delay
;
128 if (strcmp(param_name
, "totem.window_size") == 0)
129 return &totem_config
->window_size
;
130 if (strcmp(param_name
, "totem.max_messages") == 0)
131 return &totem_config
->max_messages
;
132 if (strcmp(param_name
, "totem.miss_count_const") == 0)
133 return &totem_config
->miss_count_const
;
134 if (strcmp(param_name
, "totem.knet_pmtud_interval") == 0)
135 return &totem_config
->knet_pmtud_interval
;
136 if (strcmp(param_name
, "totem.knet_compression_threshold") == 0)
137 return &totem_config
->knet_compression_threshold
;
138 if (strcmp(param_name
, "totem.knet_compression_level") == 0)
139 return &totem_config
->knet_compression_level
;
140 if (strcmp(param_name
, "totem.knet_compression_model") == 0)
141 return &totem_config
->knet_compression_model
;
142 if (strcmp(param_name
, "totem.block_unlisted_ips") == 0)
143 return &totem_config
->block_unlisted_ips
;
149 * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
150 * and readed value is zero, default value is used and stored into totem_config.
152 static void totem_volatile_config_set_uint32_value (struct totem_config
*totem_config
,
153 const char *key_name
, const char *deleted_key
, unsigned int default_value
,
154 int allow_zero_value
)
156 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
158 if (icmap_get_uint32(key_name
, totem_get_param_by_name(totem_config
, key_name
)) != CS_OK
||
159 (deleted_key
!= NULL
&& strcmp(deleted_key
, key_name
) == 0) ||
160 (!allow_zero_value
&& *(uint32_t *)totem_get_param_by_name(totem_config
, key_name
) == 0)) {
161 *(uint32_t *)totem_get_param_by_name(totem_config
, key_name
) = default_value
;
165 * Store totem_config value to cmap runtime section
167 if (strlen("runtime.config.") + strlen(key_name
) >= ICMAP_KEYNAME_MAXLEN
) {
169 * This shouldn't happen
174 strcpy(runtime_key_name
, "runtime.config.");
175 strcat(runtime_key_name
, key_name
);
177 icmap_set_uint32(runtime_key_name
, *(uint32_t *)totem_get_param_by_name(totem_config
, key_name
));
180 static void totem_volatile_config_set_int32_value (struct totem_config
*totem_config
,
181 const char *key_name
, const char *deleted_key
, int default_value
,
182 int allow_zero_value
)
184 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
186 if (icmap_get_int32(key_name
, totem_get_param_by_name(totem_config
, key_name
)) != CS_OK
||
187 (deleted_key
!= NULL
&& strcmp(deleted_key
, key_name
) == 0) ||
188 (!allow_zero_value
&& *(int32_t *)totem_get_param_by_name(totem_config
, key_name
) == 0)) {
189 *(int32_t *)totem_get_param_by_name(totem_config
, key_name
) = default_value
;
193 * Store totem_config value to cmap runtime section
195 if (strlen("runtime.config.") + strlen(key_name
) >= ICMAP_KEYNAME_MAXLEN
) {
197 * This shouldn't happen
202 strcpy(runtime_key_name
, "runtime.config.");
203 strcat(runtime_key_name
, key_name
);
205 icmap_set_int32(runtime_key_name
, *(int32_t *)totem_get_param_by_name(totem_config
, key_name
));
208 static void totem_volatile_config_set_string_value (struct totem_config
*totem_config
,
209 const char *key_name
, const char *deleted_key
, const char *default_value
)
211 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
213 void *old_config_ptr
;
215 config_value
= totem_get_param_by_name(totem_config
, key_name
);
216 old_config_ptr
= *config_value
;
217 if (icmap_get_string(key_name
, totem_get_param_by_name(totem_config
, key_name
)) != CS_OK
||
218 (deleted_key
!= NULL
&& strcmp(deleted_key
, key_name
) == 0)) {
220 /* Need to strdup() here so that the free() below works for a default and a configured value */
221 *config_value
= strdup(default_value
);
223 free(old_config_ptr
);
226 * Store totem_config value to cmap runtime section
228 if (strlen("runtime.config.") + strlen(key_name
) >= ICMAP_KEYNAME_MAXLEN
) {
230 * This shouldn't happen
235 strcpy(runtime_key_name
, "runtime.config.");
236 strcat(runtime_key_name
, key_name
);
238 icmap_set_string(runtime_key_name
, (char *)*config_value
);
242 * Read string value stored in key_name from icmap, use it as a boolean (yes/no) type, convert it
243 * to integer value (1/0) and store into totem_config.
245 * If key is not found or key_name == delete_key default value is used
246 * and stored into totem_config.
248 static void totem_volatile_config_set_boolean_value (struct totem_config
*totem_config
,
249 const char *key_name
, const char *deleted_key
, unsigned int default_value
)
251 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
258 if ((deleted_key
!= NULL
&& strcmp(deleted_key
, key_name
) == 0) ||
259 (icmap_get_string(key_name
, &str
) != CS_OK
)) {
261 * Do nothing. str is NULL (icmap_get_string ether not called or
265 if (strcmp(str
, "yes") == 0) {
267 } else if (strcmp(str
, "no") == 0) {
274 * Store totem_config value to cmap runtime section
276 if (strlen("runtime.config.") + strlen(key_name
) >= ICMAP_KEYNAME_MAXLEN
) {
278 * This shouldn't happen
283 strcpy(runtime_key_name
, "runtime.config.");
284 strcat(runtime_key_name
, key_name
);
286 *(uint32_t *)totem_get_param_by_name(totem_config
, key_name
) = val
;
288 icmap_set_uint32(runtime_key_name
, val
);
292 * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
293 * default value is stored. deleted_key is name of key beeing processed by delete operation
294 * from cmap. It is considered as non existing even if it can be read. Can be NULL.
296 static void totem_volatile_config_read (struct totem_config
*totem_config
, const char *deleted_key
)
300 totem_volatile_config_set_uint32_value(totem_config
, "totem.token_retransmits_before_loss_const", deleted_key
,
301 TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
, 0);
303 totem_volatile_config_set_uint32_value(totem_config
, "totem.token", deleted_key
, TOKEN_TIMEOUT
, 0);
305 totem_volatile_config_set_uint32_value(totem_config
, "totem.token_warning", deleted_key
, TOKEN_WARNING
, 1);
307 if (totem_config
->interfaces
[0].member_count
> 2) {
308 u32
= TOKEN_COEFFICIENT
;
309 icmap_get_uint32("totem.token_coefficient", &u32
);
310 totem_config
->token_timeout
+= (totem_config
->interfaces
[0].member_count
- 2) * u32
;
313 * Store totem_config value to cmap runtime section
315 icmap_set_uint32("runtime.config.totem.token", totem_config
->token_timeout
);
318 totem_volatile_config_set_uint32_value(totem_config
, "totem.max_network_delay", deleted_key
, MAX_NETWORK_DELAY
, 0);
320 totem_volatile_config_set_uint32_value(totem_config
, "totem.window_size", deleted_key
, WINDOW_SIZE
, 0);
322 totem_volatile_config_set_uint32_value(totem_config
, "totem.max_messages", deleted_key
, MAX_MESSAGES
, 0);
324 totem_volatile_config_set_uint32_value(totem_config
, "totem.miss_count_const", deleted_key
, MISS_COUNT_CONST
, 0);
325 totem_volatile_config_set_uint32_value(totem_config
, "totem.knet_pmtud_interval", deleted_key
, KNET_PMTUD_INTERVAL
, 0);
327 totem_volatile_config_set_uint32_value(totem_config
, "totem.token_retransmit", deleted_key
,
328 (int)(totem_config
->token_timeout
/ (totem_config
->token_retransmits_before_loss_const
+ 0.2)), 0);
330 totem_volatile_config_set_uint32_value(totem_config
, "totem.hold", deleted_key
,
331 (int)(totem_config
->token_retransmit_timeout
* 0.8 - (1000/HZ
)), 0);
333 totem_volatile_config_set_uint32_value(totem_config
, "totem.join", deleted_key
, JOIN_TIMEOUT
, 0);
335 totem_volatile_config_set_uint32_value(totem_config
, "totem.consensus", deleted_key
,
336 (int)(float)(1.2 * totem_config
->token_timeout
), 0);
338 totem_volatile_config_set_uint32_value(totem_config
, "totem.merge", deleted_key
, MERGE_TIMEOUT
, 0);
340 totem_volatile_config_set_uint32_value(totem_config
, "totem.downcheck", deleted_key
, DOWNCHECK_TIMEOUT
, 0);
342 totem_volatile_config_set_uint32_value(totem_config
, "totem.fail_recv_const", deleted_key
, FAIL_TO_RECV_CONST
, 0);
344 totem_volatile_config_set_uint32_value(totem_config
, "totem.seqno_unchanged_const", deleted_key
,
345 SEQNO_UNCHANGED_CONST
, 0);
347 totem_volatile_config_set_uint32_value(totem_config
, "totem.send_join", deleted_key
, 0, 1);
349 totem_volatile_config_set_uint32_value(totem_config
, "totem.heartbeat_failures_allowed", deleted_key
, 0, 1);
351 totem_volatile_config_set_uint32_value(totem_config
, "totem.knet_compression_threshold", deleted_key
, 0, 1);
353 totem_volatile_config_set_int32_value(totem_config
, "totem.knet_compression_level", deleted_key
, 0, 1);
355 totem_volatile_config_set_string_value(totem_config
, "totem.knet_compression_model", deleted_key
, "none");
357 totem_volatile_config_set_boolean_value(totem_config
, "totem.block_unlisted_ips", deleted_key
,
361 static int totem_volatile_config_validate (
362 struct totem_config
*totem_config
,
363 const char **error_string
)
365 static char local_error_reason
[512];
366 const char *error_reason
= local_error_reason
;
367 char name_key
[ICMAP_KEYNAME_MAXLEN
];
369 int i
, num_configured
, members
;
370 uint32_t tmp_config_value
;
372 if (totem_config
->max_network_delay
< MINIMUM_TIMEOUT
) {
373 snprintf (local_error_reason
, sizeof(local_error_reason
),
374 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
375 totem_config
->max_network_delay
, MINIMUM_TIMEOUT
);
379 if (totem_config
->token_timeout
< MINIMUM_TIMEOUT
) {
380 snprintf (local_error_reason
, sizeof(local_error_reason
),
381 "The token timeout parameter (%d ms) may not be less than (%d ms).",
382 totem_config
->token_timeout
, MINIMUM_TIMEOUT
);
386 if (totem_config
->token_warning
> 100 || totem_config
->token_warning
< 0) {
387 snprintf (local_error_reason
, sizeof(local_error_reason
),
388 "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
389 totem_config
->token_warning
);
393 if (totem_config
->token_retransmit_timeout
< MINIMUM_TIMEOUT
) {
394 if (icmap_get_uint32("totem.token_retransmit", &tmp_config_value
) == CS_OK
) {
395 snprintf (local_error_reason
, sizeof(local_error_reason
),
396 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
397 totem_config
->token_retransmit_timeout
, MINIMUM_TIMEOUT
);
400 snprintf (local_error_reason
, sizeof(local_error_reason
),
401 "Not appropriate token or token_retransmits_before_loss_const value set");
406 if (totem_config
->token_hold_timeout
< MINIMUM_TIMEOUT_HOLD
) {
407 snprintf (local_error_reason
, sizeof(local_error_reason
),
408 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
409 totem_config
->token_hold_timeout
, MINIMUM_TIMEOUT_HOLD
);
413 if (totem_config
->join_timeout
< MINIMUM_TIMEOUT
) {
414 snprintf (local_error_reason
, sizeof(local_error_reason
),
415 "The join timeout parameter (%d ms) may not be less than (%d ms).",
416 totem_config
->join_timeout
, MINIMUM_TIMEOUT
);
420 if (totem_config
->consensus_timeout
< MINIMUM_TIMEOUT
) {
421 snprintf (local_error_reason
, sizeof(local_error_reason
),
422 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
423 totem_config
->consensus_timeout
, MINIMUM_TIMEOUT
);
427 if (totem_config
->consensus_timeout
< totem_config
->join_timeout
) {
428 snprintf (local_error_reason
, sizeof(local_error_reason
),
429 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
430 totem_config
->consensus_timeout
, totem_config
->join_timeout
);
434 if (totem_config
->merge_timeout
< MINIMUM_TIMEOUT
) {
435 snprintf (local_error_reason
, sizeof(local_error_reason
),
436 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
437 totem_config
->merge_timeout
, MINIMUM_TIMEOUT
);
441 if (totem_config
->downcheck_timeout
< MINIMUM_TIMEOUT
) {
442 snprintf (local_error_reason
, sizeof(local_error_reason
),
443 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
444 totem_config
->downcheck_timeout
, MINIMUM_TIMEOUT
);
448 /* Check that we have nodelist 'name' if there is more than one link */
450 for (i
= 0; i
< INTERFACE_MAX
; i
++) {
451 if (totem_config
->interfaces
[i
].configured
) {
456 if (num_configured
> 1) {
457 members
= totem_config
->interfaces
[0].member_count
;
459 for (i
=0; i
<totem_config
->interfaces
[0].member_count
; i
++) {
460 snprintf(name_key
, sizeof(name_key
), "nodelist.node.%d.name", i
);
462 if (icmap_get_string(name_key
, &name_str
) != CS_OK
) {
463 snprintf (local_error_reason
, sizeof(local_error_reason
),
464 "for a multi-link configuration, all nodes must have a 'name' attribute");
469 for (i
=0; i
<num_configured
; i
++) {
470 if (totem_config
->interfaces
[i
].member_count
!= members
) {
471 snprintf (local_error_reason
, sizeof(local_error_reason
),
472 "Not all nodes have the same number of links");
484 snprintf (error_string_response
, sizeof(error_string_response
),
485 "parse error in config: %s\n", error_reason
);
486 *error_string
= error_string_response
;
491 static int totem_get_crypto(struct totem_config
*totem_config
, const char **error_string
)
494 const char *tmp_cipher
;
495 const char *tmp_hash
;
496 const char *tmp_model
;
502 if (icmap_get_string("totem.crypto_model", &str
) == CS_OK
) {
503 if (strcmp(str
, "nss") == 0) {
506 if (strcmp(str
, "openssl") == 0) {
507 tmp_model
= "openssl";
514 if (icmap_get_string("totem.secauth", &str
) == CS_OK
) {
515 if (strcmp(str
, "on") == 0) {
516 tmp_cipher
= "aes256";
522 if (icmap_get_string("totem.crypto_cipher", &str
) == CS_OK
) {
523 if (strcmp(str
, "none") == 0) {
526 if (strcmp(str
, "aes256") == 0) {
527 tmp_cipher
= "aes256";
529 if (strcmp(str
, "aes192") == 0) {
530 tmp_cipher
= "aes192";
532 if (strcmp(str
, "aes128") == 0) {
533 tmp_cipher
= "aes128";
538 if (icmap_get_string("totem.crypto_hash", &str
) == CS_OK
) {
539 if (strcmp(str
, "none") == 0) {
542 if (strcmp(str
, "md5") == 0) {
545 if (strcmp(str
, "sha1") == 0) {
548 if (strcmp(str
, "sha256") == 0) {
551 if (strcmp(str
, "sha384") == 0) {
554 if (strcmp(str
, "sha512") == 0) {
560 if ((strcmp(tmp_cipher
, "none") != 0) &&
561 (strcmp(tmp_hash
, "none") == 0)) {
562 *error_string
= "crypto_cipher requires crypto_hash with value other than none";
566 if (strcmp(tmp_model
, "none") == 0) {
567 *error_string
= "crypto_model should be 'nss' or 'openssl'";
571 free(totem_config
->crypto_cipher_type
);
572 free(totem_config
->crypto_hash_type
);
573 free(totem_config
->crypto_model
);
575 totem_config
->crypto_cipher_type
= strdup(tmp_cipher
);
576 totem_config
->crypto_hash_type
= strdup(tmp_hash
);
577 totem_config
->crypto_model
= strdup(tmp_model
);
582 static int nodelist_byname(const char *find_name
, int strip_domain
)
585 const char *iter_key
;
586 char name_str
[ICMAP_KEYNAME_MAXLEN
];
588 unsigned int node_pos
;
590 unsigned int namelen
;
592 iter
= icmap_iter_init("nodelist.node.");
593 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
594 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, name_str
);
598 /* ring0_addr is allowed as a fallback */
599 if (strcmp(name_str
, "name") && strcmp(name_str
, "ring0_addr")) {
602 if (icmap_get_string(iter_key
, &name
) != CS_OK
) {
605 namelen
= strlen(name
);
609 dot
= strchr(name
, '.');
611 namelen
= name
- dot
- 1;
614 if (strncmp(find_name
, name
, namelen
) == 0 &&
615 strlen(find_name
) == strlen(name
)) {
616 icmap_iter_finalize(iter
);
620 icmap_iter_finalize(iter
);
624 /* Compare two addresses - only address part (sin_addr/sin6_addr) is checked */
625 static int ipaddr_equal(const struct sockaddr
*addr1
, const struct sockaddr
*addr2
)
628 const void *addr1p
, *addr2p
;
630 if (addr1
->sa_family
!= addr2
->sa_family
)
633 if (addr1
->sa_family
== AF_INET
) {
634 addrlen
= sizeof(struct in_addr
);
635 addr1p
= &((struct sockaddr_in
*)addr1
)->sin_addr
;
636 addr2p
= &((struct sockaddr_in
*)addr2
)->sin_addr
;
638 if (addr1
->sa_family
== AF_INET6
) {
639 addrlen
= sizeof(struct in6_addr
);
640 addr1p
= &((struct sockaddr_in6
*)addr1
)->sin6_addr
;
641 addr2p
= &((struct sockaddr_in6
*)addr2
)->sin6_addr
;
645 return (memcmp(addr1p
, addr2p
, addrlen
) == 0);
649 /* Finds the local node and returns its position in the nodelist.
650 * Uses nodelist.local_node_pos as a cache to save effort
652 static int find_local_node(int use_cache
)
654 char nodename2
[PATH_MAX
];
655 char name_str
[ICMAP_KEYNAME_MAXLEN
];
657 const char *iter_key
;
658 unsigned int cached_pos
;
661 struct ifaddrs
*ifa
, *ifa_list
;
666 struct utsname utsname
;
668 /* Check for cached value first */
670 if (icmap_get_uint32("nodelist.local_node_pos", &cached_pos
) == CS_OK
) {
675 res
= uname(&utsname
);
679 node
= utsname
.nodename
;
682 node_pos
= nodelist_byname(node
, 0);
688 /* 2. Try to match with increasingly more
689 * specific versions of it
691 strcpy(nodename2
, node
);
692 dot
= strrchr(nodename2
, '.');
696 node_pos
= nodelist_byname(nodename2
, 0);
701 dot
= strrchr(nodename2
, '.');
704 node_pos
= nodelist_byname(nodename2
, 1);
711 * The corosync.conf name may not be related to uname at all,
712 * they may match a hostname on some network interface.
714 if (getifaddrs(&ifa_list
))
717 for (ifa
= ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
721 strcpy(nodename2
, node
);
726 if (sa
->sa_family
!= AF_INET
&& sa
->sa_family
!= AF_INET6
) {
730 if (sa
->sa_family
== AF_INET
) {
731 salen
= sizeof(struct sockaddr_in
);
733 if (sa
->sa_family
== AF_INET6
) {
734 salen
= sizeof(struct sockaddr_in6
);
737 if (getnameinfo(sa
, salen
,
738 nodename2
, sizeof(nodename2
),
741 node_pos
= nodelist_byname(nodename2
, 0);
747 /* Truncate this name and try again */
748 dot
= strchr(nodename2
, '.');
752 node_pos
= nodelist_byname(nodename2
, 0);
760 /* See if it's the IP address that's in corosync.conf */
761 if (getnameinfo(sa
, sizeof(*sa
),
762 nodename2
, sizeof(nodename2
),
763 NULL
, 0, NI_NUMERICHOST
))
766 node_pos
= nodelist_byname(nodename2
, 0);
775 freeifaddrs(ifa_list
);
780 * This section covers the usecase where the nodename specified in cluster.conf
781 * is an alias specified in /etc/hosts. For example:
782 * <ipaddr> hostname alias1 alias2
783 * and <clusternode name="alias2">
784 * the above calls use uname and getnameinfo does not return aliases.
785 * here we take the name specified in cluster.conf, resolve it to an address
786 * and then compare against all known local ip addresses.
787 * if we have a match, we found our nodename. In theory this chunk of code
788 * could replace all the checks above, but let's avoid any possible regressions
789 * and use it as last.
792 iter
= icmap_iter_init("nodelist.node.");
793 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
794 char *dbnodename
= NULL
;
795 struct addrinfo hints
;
796 struct addrinfo
*result
= NULL
, *rp
= NULL
;
798 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, name_str
);
802 /* 'ring0_addr' is allowed as a fallback, but 'name' will be found first
803 * because the names are in alpha order.
805 if (strcmp(name_str
, "name") && strcmp(name_str
, "ring0_addr")) {
808 if (icmap_get_string(iter_key
, &dbnodename
) != CS_OK
) {
812 memset(&hints
, 0, sizeof(struct addrinfo
));
813 hints
.ai_family
= AF_UNSPEC
;
814 hints
.ai_socktype
= SOCK_DGRAM
;
816 hints
.ai_protocol
= IPPROTO_UDP
;
818 if (getaddrinfo(dbnodename
, NULL
, &hints
, &result
)) {
822 for (rp
= result
; rp
!= NULL
; rp
= rp
->ai_next
) {
823 for (ifa
= ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
825 ipaddr_equal(rp
->ai_addr
, ifa
->ifa_addr
)) {
826 freeaddrinfo(result
);
833 freeaddrinfo(result
);
836 icmap_iter_finalize(iter
);
837 freeifaddrs(ifa_list
);
841 res
= icmap_set_uint32("nodelist.local_node_pos", node_pos
);
847 static enum totem_ip_version_enum
totem_config_get_ip_version(struct totem_config
*totem_config
)
849 enum totem_ip_version_enum res
;
852 res
= TOTEM_IP_VERSION_6_4
;
854 if (totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
855 res
= TOTEM_IP_VERSION_4
;
858 if (icmap_get_string("totem.ip_version", &str
) == CS_OK
) {
859 if (strcmp(str
, "ipv4") == 0) {
860 res
= TOTEM_IP_VERSION_4
;
862 if (strcmp(str
, "ipv6") == 0) {
863 res
= TOTEM_IP_VERSION_6
;
865 if (strcmp(str
, "ipv6-4") == 0) {
866 res
= TOTEM_IP_VERSION_6_4
;
868 if (strcmp(str
, "ipv4-6") == 0) {
869 res
= TOTEM_IP_VERSION_4_6
;
877 static uint16_t generate_cluster_id (const char *cluster_name
)
882 for (i
= 0; i
< strlen(cluster_name
); i
++) {
884 value
+= cluster_name
[i
];
887 return (value
& 0xFFFF);
890 static int get_cluster_mcast_addr (
891 const char *cluster_name
,
892 unsigned int linknumber
,
893 enum totem_ip_version_enum ip_version
,
894 struct totem_ip_address
*res
)
897 char addr
[INET6_ADDRSTRLEN
+ 1];
900 if (cluster_name
== NULL
) {
904 clusterid
= generate_cluster_id(cluster_name
) + linknumber
;
905 memset (res
, 0, sizeof(*res
));
907 switch (ip_version
) {
908 case TOTEM_IP_VERSION_4
:
909 case TOTEM_IP_VERSION_4_6
:
910 snprintf(addr
, sizeof(addr
), "239.192.%d.%d", clusterid
>> 8, clusterid
% 0xFF);
912 case TOTEM_IP_VERSION_6
:
913 case TOTEM_IP_VERSION_6_4
:
914 snprintf(addr
, sizeof(addr
), "ff15::%x", clusterid
);
923 err
= totemip_parse (res
, addr
, ip_version
);
928 static unsigned int generate_nodeid(
929 struct totem_config
*totem_config
,
933 struct totem_ip_address totemip
;
935 /* AF_INET hard-coded here because auto-generated nodeids
937 if (totemip_parse(&totemip
, addr
, TOTEM_IP_VERSION_4
) != 0)
940 memcpy (&nodeid
, &totemip
.addr
, sizeof (unsigned int));
942 #if __BYTE_ORDER == __LITTLE_ENDIAN
943 nodeid
= swab32 (nodeid
);
946 if (totem_config
->clear_node_high_bit
) {
947 nodeid
&= 0x7FFFFFFF;
952 static int check_for_duplicate_nodeids(
953 struct totem_config
*totem_config
,
954 const char **error_string
)
957 icmap_iter_t subiter
;
958 const char *iter_key
;
961 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
962 char *ring0_addr
=NULL
;
963 char *ring0_addr1
=NULL
;
964 unsigned int node_pos
;
965 unsigned int node_pos1
;
966 unsigned int last_node_pos
= -1;
968 unsigned int nodeid1
;
971 iter
= icmap_iter_init("nodelist.node.");
972 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
973 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, tmp_key
);
979 * This relies on the fact the icmap keys are always returned in order
980 * so all of the keys for a node will be grouped together. We're basically
981 * just running the code below once for each node.
983 if (last_node_pos
== node_pos
) {
986 last_node_pos
= node_pos
;
988 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos
);
991 /* Generated nodeids are only allowed for UDP/UDPU so ring0_addr is valid here */
992 if (icmap_get_uint32(tmp_key
, &nodeid
) != CS_OK
) {
994 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos
);
995 if (icmap_get_string(tmp_key
, &ring0_addr
) != CS_OK
) {
999 /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
1000 nodeid
= generate_nodeid(totem_config
, ring0_addr
);
1008 subiter
= icmap_iter_init("nodelist.node.");
1009 while (((iter_key
= icmap_iter_next(subiter
, NULL
, NULL
)) != NULL
) && (node_pos1
< node_pos
)) {
1010 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos1
, tmp_key
);
1011 if ((res
!= 2) || (node_pos1
>= node_pos
)) {
1015 if (strcmp(tmp_key
, "nodeid") != 0) {
1019 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos1
);
1020 if (icmap_get_uint32(tmp_key
, &nodeid1
) != CS_OK
) {
1022 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos1
);
1023 if (icmap_get_string(tmp_key
, &ring0_addr1
) != CS_OK
) {
1026 nodeid1
= generate_nodeid(totem_config
, ring0_addr1
);
1027 if (nodeid1
== -1) {
1032 if (nodeid
== nodeid1
) {
1034 snprintf (error_string_response
, sizeof(error_string_response
),
1035 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid
,
1036 autogenerated
?"(autogenerated from ":"",
1037 autogenerated
?ring0_addr
:"",
1038 autogenerated
?")":"");
1039 log_printf (LOGSYS_LEVEL_ERROR
, error_string_response
);
1040 *error_string
= error_string_response
;
1044 icmap_iter_finalize(subiter
);
1046 icmap_iter_finalize(iter
);
1052 * This needs to be done last of all. It would be nice to do it when reading the
1053 * interface params, but the totem params need to have them to be read first. We
1054 * need both, so this is a way round that circular dependancy.
1056 static void calc_knet_ping_timers(struct totem_config
*totem_config
)
1058 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
1061 for (interface
= 0; interface
< INTERFACE_MAX
; interface
++) {
1063 if (totem_config
->interfaces
[interface
].configured
) {
1064 if (!totem_config
->interfaces
[interface
].knet_pong_count
) {
1065 totem_config
->interfaces
[interface
].knet_pong_count
= KNET_PONG_COUNT
;
1067 if (!totem_config
->interfaces
[interface
].knet_ping_timeout
) {
1068 totem_config
->interfaces
[interface
].knet_ping_timeout
=
1069 totem_config
->token_timeout
/ totem_config
->interfaces
[interface
].knet_pong_count
;
1071 snprintf(runtime_key_name
, sizeof(runtime_key_name
),
1072 "runtime.config.totem.interface.%d.knet_ping_timeout", interface
);
1073 icmap_set_uint32(runtime_key_name
, totem_config
->interfaces
[interface
].knet_ping_timeout
);
1075 if (!totem_config
->interfaces
[interface
].knet_ping_interval
) {
1076 totem_config
->interfaces
[interface
].knet_ping_interval
=
1077 totem_config
->token_timeout
/ (totem_config
->interfaces
[interface
].knet_pong_count
* 2);
1079 snprintf(runtime_key_name
, sizeof(runtime_key_name
),
1080 "runtime.config.totem.interface.%d.knet_ping_interval", interface
);
1081 icmap_set_uint32(runtime_key_name
, totem_config
->interfaces
[interface
].knet_ping_interval
);
1087 * Compute difference between two set of totem interface arrays. set1 and set2
1088 * are changed so for same ring, ip existing in both set1 and set2 are cleared
1089 * (set to 0), and ips which are only in set1 or set2 remains untouched.
1090 * totempg_node_add/remove is called.
1092 static void compute_interfaces_diff(struct totem_interface
*set1
,
1093 struct totem_interface
*set2
)
1095 int ring_no
, set1_pos
, set2_pos
;
1096 struct totem_ip_address empty_ip_address
;
1098 memset(&empty_ip_address
, 0, sizeof(empty_ip_address
));
1100 for (ring_no
= 0; ring_no
< INTERFACE_MAX
; ring_no
++) {
1101 if (!set1
[ring_no
].configured
&& !set2
[ring_no
].configured
) {
1105 for (set1_pos
= 0; set1_pos
< set1
[ring_no
].member_count
; set1_pos
++) {
1106 for (set2_pos
= 0; set2_pos
< set2
[ring_no
].member_count
; set2_pos
++) {
1108 * For current ring_no remove all set1 items existing
1111 if (memcmp(&set1
[ring_no
].member_list
[set1_pos
],
1112 &set2
[ring_no
].member_list
[set2_pos
],
1113 sizeof(struct totem_ip_address
)) == 0) {
1114 memset(&set1
[ring_no
].member_list
[set1_pos
], 0,
1115 sizeof(struct totem_ip_address
));
1116 memset(&set2
[ring_no
].member_list
[set2_pos
], 0,
1117 sizeof(struct totem_ip_address
));
1123 for (ring_no
= 0; ring_no
< INTERFACE_MAX
; ring_no
++) {
1124 for (set1_pos
= 0; set1_pos
< set1
[ring_no
].member_count
; set1_pos
++) {
1126 * All items which remained in set1 doesn't exists in set2 any longer so
1127 * node has to be removed.
1129 if (memcmp(&set1
[ring_no
].member_list
[set1_pos
], &empty_ip_address
, sizeof(empty_ip_address
)) != 0) {
1130 log_printf(LOGSYS_LEVEL_DEBUG
,
1131 "removing dynamic member %s for ring %u",
1132 totemip_print(&set1
[ring_no
].member_list
[set1_pos
]),
1135 totempg_member_remove(&set1
[ring_no
].member_list
[set1_pos
], ring_no
);
1138 if (!set2
[ring_no
].configured
) {
1141 for (set2_pos
= 0; set2_pos
< set2
[ring_no
].member_count
; set2_pos
++) {
1143 * All items which remained in set2 doesn't existed in set1 so this is no node
1144 * and has to be added.
1146 if (memcmp(&set2
[ring_no
].member_list
[set2_pos
], &empty_ip_address
, sizeof(empty_ip_address
)) != 0) {
1147 log_printf(LOGSYS_LEVEL_DEBUG
,
1148 "adding dynamic member %s for ring %u",
1149 totemip_print(&set2
[ring_no
].member_list
[set2_pos
]),
1152 totempg_member_add(&set2
[ring_no
].member_list
[set2_pos
], ring_no
);
1159 * Reconfigure links in totempg. Sets new local IP address and adds params for new links.
1161 static void reconfigure_links(struct totem_config
*totem_config
)
1164 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
1166 struct totem_ip_address local_ip
;
1168 int local_node_pos
= find_local_node(0);
1170 for (i
= 0; i
<INTERFACE_MAX
; i
++) {
1171 if (!totem_config
->interfaces
[i
].configured
) {
1175 log_printf(LOGSYS_LEVEL_INFO
, "Configuring link %d\n", i
);
1177 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring%u_addr", local_node_pos
, i
);
1178 if (icmap_get_string(tmp_key
, &addr_string
) != CS_OK
) {
1182 err
= totemip_parse(&local_ip
, addr_string
, totem_config
->ip_version
);
1186 local_ip
.nodeid
= totem_config
->node_id
;
1188 /* In case this is a new link, fill in the defaults if there was no interface{} section for it */
1189 if (!totem_config
->interfaces
[i
].knet_link_priority
)
1190 totem_config
->interfaces
[i
].knet_link_priority
= 1;
1192 /* knet_ping_interval & knet_ping_timeout are set later once we know all the other params */
1194 if (!totem_config
->interfaces
[i
].knet_ping_precision
)
1195 totem_config
->interfaces
[i
].knet_ping_precision
= KNET_PING_PRECISION
;
1196 if (!totem_config
->interfaces
[i
].knet_pong_count
)
1197 totem_config
->interfaces
[i
].knet_pong_count
= KNET_PONG_COUNT
;
1198 if (!totem_config
->interfaces
[i
].knet_transport
)
1199 totem_config
->interfaces
[i
].knet_transport
= KNET_TRANSPORT_UDP
;
1200 if (!totem_config
->interfaces
[i
].ip_port
)
1201 totem_config
->interfaces
[i
].ip_port
= DEFAULT_PORT
+ i
;
1203 totempg_iface_set(&local_ip
, totem_config
->interfaces
[i
].ip_port
, i
);
1207 /* Check for differences in config that can't be done on-the-fly and print an error */
1208 static void check_things_have_not_changed(struct totem_config
*totem_config
)
1212 char addr_buf
[INET6_ADDRSTRLEN
];
1215 for (i
= 0; i
<INTERFACE_MAX
; i
++) {
1216 if (totem_config
->interfaces
[i
].configured
&&
1217 totem_config
->orig_interfaces
[i
].configured
) {
1218 if (totem_config
->interfaces
[i
].knet_transport
!=
1219 totem_config
->orig_interfaces
[i
].knet_transport
) {
1220 log_printf(LOGSYS_LEVEL_ERROR
,
1221 "New config has different knet transport for link %d. Internal value was NOT changed.\n", i
);
1224 for (j
=0; j
< min(totem_config
->interfaces
[i
].member_count
, totem_config
->orig_interfaces
[i
].member_count
); j
++) {
1225 if (memcmp(&totem_config
->interfaces
[i
].member_list
[j
],
1226 &totem_config
->orig_interfaces
[i
].member_list
[j
],
1227 sizeof(struct totem_ip_address
))) {
1229 ip_str
= totemip_print(&totem_config
->orig_interfaces
[i
].member_list
[j
]);
1231 /* if ip_str is NULL then the old address was invalid and is allowed to change */
1233 strncpy(addr_buf
, ip_str
, sizeof(addr_buf
));
1234 addr_buf
[sizeof(addr_buf
) - 1] = '\0';
1235 log_printf(LOGSYS_LEVEL_ERROR
,
1236 "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1237 i
, addr_buf
, totemip_print(&totem_config
->interfaces
[i
].member_list
[j
]));
1246 log_printf(LOGSYS_LEVEL_ERROR
, "To reconfigure an interface it must be deleted and recreated. A working interface needs to be available to corosync at all times");
1251 static int put_nodelist_members_to_config(struct totem_config
*totem_config
, int reload
, const char **error_string
)
1253 icmap_iter_t iter
, iter2
;
1254 const char *iter_key
, *iter_key2
;
1256 unsigned int node_pos
;
1257 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
1258 char tmp_key2
[ICMAP_KEYNAME_MAXLEN
];
1259 char *node_addr_str
;
1261 unsigned int linknumber
= 0;
1263 int last_node_pos
= -1;
1264 struct totem_interface
*new_interfaces
= NULL
;
1268 * We need to compute diff only for reload. Also for initial configuration
1269 * not all totem structures are initialized so corosync will crash during
1272 new_interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
1273 assert(new_interfaces
!= NULL
);
1276 /* Clear out nodelist so we can put the new one in if needed */
1277 for (i
= 0; i
< INTERFACE_MAX
; i
++) {
1278 for (j
= 0; j
< PROCESSOR_COUNT_MAX
; j
++) {
1279 memset(&totem_config
->interfaces
[i
].member_list
[j
], 0, sizeof(struct totem_ip_address
));
1281 totem_config
->interfaces
[i
].member_count
= 0;
1284 iter
= icmap_iter_init("nodelist.node.");
1285 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
1286 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, tmp_key
);
1290 /* If it's the same as the last node_pos then skip it */
1291 if (node_pos
== last_node_pos
) {
1294 last_node_pos
= node_pos
;
1296 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.", node_pos
);
1297 iter2
= icmap_iter_init(tmp_key
);
1298 while ((iter_key2
= icmap_iter_next(iter2
, NULL
, NULL
)) != NULL
) {
1299 unsigned int nodeid
;
1302 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos
);
1303 if (icmap_get_uint32(tmp_key
, &nodeid
) != CS_OK
) {
1307 res
= sscanf(iter_key2
, "nodelist.node.%u.ring%u%s", &node_pos
, &linknumber
, tmp_key2
);
1308 if (res
!= 3 || strcmp(tmp_key2
, "_addr") != 0) {
1312 if (icmap_get_string(iter_key2
, &node_addr_str
) != CS_OK
) {
1316 /* Generate nodeids if they are not provided and transport is UDP/U */
1318 (totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
||
1319 totem_config
->transport_number
== TOTEM_TRANSPORT_UDPU
)) {
1320 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos
);
1321 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1322 nodeid
= generate_nodeid(totem_config
, str
);
1324 sprintf(error_string_response
,
1325 "An IPV6 network requires that a node ID be specified "
1326 "for address '%s'.", node_addr_str
);
1327 *error_string
= error_string_response
;
1333 log_printf(LOGSYS_LEVEL_DEBUG
,
1334 "Generated nodeid = 0x%x for %s", nodeid
, str
);
1339 member_count
= totem_config
->interfaces
[linknumber
].member_count
;
1340 res
= totemip_parse(&totem_config
->interfaces
[linknumber
].member_list
[member_count
],
1341 node_addr_str
, totem_config
->ip_version
);
1343 totem_config
->interfaces
[linknumber
].member_list
[member_count
].nodeid
= nodeid
;
1344 totem_config
->interfaces
[linknumber
].member_count
++;
1345 totem_config
->interfaces
[linknumber
].configured
= 1;
1347 sprintf(error_string_response
, "failed to parse node address '%s'\n", node_addr_str
);
1348 *error_string
= error_string_response
;
1350 memset(&totem_config
->interfaces
[linknumber
].member_list
[member_count
], 0,
1351 sizeof(struct totem_ip_address
));
1353 free(node_addr_str
);
1354 icmap_iter_finalize(iter2
);
1355 icmap_iter_finalize(iter
);
1359 free(node_addr_str
);
1362 icmap_iter_finalize(iter2
);
1365 icmap_iter_finalize(iter
);
1368 log_printf(LOGSYS_LEVEL_DEBUG
, "About to reconfigure links from nodelist.\n");
1369 reconfigure_links(totem_config
);
1371 memcpy(new_interfaces
, totem_config
->interfaces
, sizeof (struct totem_interface
) * INTERFACE_MAX
);
1373 check_things_have_not_changed(totem_config
);
1375 compute_interfaces_diff(totem_config
->orig_interfaces
, new_interfaces
);
1377 free(new_interfaces
);
1382 static void config_convert_nodelist_to_interface(struct totem_config
*totem_config
)
1386 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
1387 char tmp_key2
[ICMAP_KEYNAME_MAXLEN
];
1388 char *node_addr_str
;
1389 unsigned int linknumber
= 0;
1391 const char *iter_key
;
1393 node_pos
= find_local_node(1);
1394 if (node_pos
> -1) {
1396 * We found node, so create interface section
1398 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.", node_pos
);
1399 iter
= icmap_iter_init(tmp_key
);
1400 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
1401 res
= sscanf(iter_key
, "nodelist.node.%u.ring%u%s", &node_pos
, &linknumber
, tmp_key2
);
1402 if (res
!= 3 || strcmp(tmp_key2
, "_addr") != 0) {
1406 if (icmap_get_string(iter_key
, &node_addr_str
) != CS_OK
) {
1410 snprintf(tmp_key2
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.bindnetaddr", linknumber
);
1411 icmap_set_string(tmp_key2
, node_addr_str
);
1412 free(node_addr_str
);
1414 icmap_iter_finalize(iter
);
1418 static int get_interface_params(struct totem_config
*totem_config
,
1419 const char **error_string
, uint64_t *warnings
,
1423 unsigned int linknumber
= 0;
1424 int member_count
= 0;
1426 icmap_iter_t iter
, member_iter
;
1427 const char *iter_key
;
1428 const char *member_iter_key
;
1429 char linknumber_key
[ICMAP_KEYNAME_MAXLEN
];
1430 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
1434 char *cluster_name
= NULL
;
1435 enum totem_ip_version_enum tmp_ip_version
= TOTEM_IP_VERSION_4
;
1438 for (i
=0; i
<INTERFACE_MAX
; i
++) {
1440 * Set back to defaults things that might have been configured and
1441 * now have been taken out of corosync.conf. These won't be caught by the
1442 * code below which only looks at interface{} sections that actually exist.
1444 totem_config
->interfaces
[i
].configured
= 0;
1445 totem_config
->interfaces
[i
].knet_ping_timeout
= 0;
1446 totem_config
->interfaces
[i
].knet_ping_interval
= 0;
1447 totem_config
->interfaces
[i
].knet_ping_precision
= KNET_PING_PRECISION
;
1448 totem_config
->interfaces
[i
].knet_pong_count
= KNET_PONG_COUNT
;
1451 if (icmap_get_string("totem.cluster_name", &cluster_name
) != CS_OK
) {
1452 cluster_name
= NULL
;
1455 iter
= icmap_iter_init("totem.interface.");
1456 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
1457 res
= sscanf(iter_key
, "totem.interface.%[^.].%s", linknumber_key
, tmp_key
);
1462 if (strcmp(tmp_key
, "bindnetaddr") != 0 && totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1467 linknumber
= atoi(linknumber_key
);
1469 if (linknumber
>= INTERFACE_MAX
) {
1472 snprintf (error_string_response
, sizeof(error_string_response
),
1473 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1474 linknumber
, INTERFACE_MAX
- 1);
1476 *error_string
= error_string_response
;
1480 /* These things are only valid for the initial read */
1483 * Get the bind net address
1485 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.bindnetaddr", linknumber
);
1487 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1488 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].bindnet
, str
,
1489 totem_config
->ip_version
);
1492 sprintf(error_string_response
, "failed to parse bindnet address '%s'\n", str
);
1493 *error_string
= error_string_response
;
1503 * Get interface multicast address
1505 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastaddr", linknumber
);
1506 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1507 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].mcast_addr
, str
,
1508 totem_config
->ip_version
);
1511 sprintf(error_string_response
, "failed to parse mcast address '%s'\n", str
);
1512 *error_string
= error_string_response
;
1519 } else if (totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1521 * User not specified address -> autogenerate one from cluster_name key
1522 * (if available). Return code is intentionally ignored, because
1523 * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
1524 * checked later anyway.
1527 if (totem_config
->interfaces
[0].bindnet
.family
== AF_INET
) {
1528 tmp_ip_version
= TOTEM_IP_VERSION_4
;
1529 } else if (totem_config
->interfaces
[0].bindnet
.family
== AF_INET6
) {
1530 tmp_ip_version
= TOTEM_IP_VERSION_6
;
1533 (void)get_cluster_mcast_addr (cluster_name
,
1536 &totem_config
->interfaces
[linknumber
].mcast_addr
);
1539 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.broadcast", linknumber
);
1540 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1541 if (strcmp (str
, "yes") == 0) {
1542 totem_config
->broadcast_use
= 1;
1548 /* These things are only valid for the initial read OR a newly-defined link */
1549 if (!reload
|| (totem_config
->interfaces
[linknumber
].configured
== 0)) {
1554 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastport", linknumber
);
1555 if (icmap_get_uint16(tmp_key
, &totem_config
->interfaces
[linknumber
].ip_port
) != CS_OK
) {
1556 if (totem_config
->broadcast_use
) {
1557 totem_config
->interfaces
[linknumber
].ip_port
= DEFAULT_PORT
+ (2 * linknumber
);
1559 totem_config
->interfaces
[linknumber
].ip_port
= DEFAULT_PORT
+ linknumber
;
1566 totem_config
->interfaces
[linknumber
].ttl
= 1;
1568 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.ttl", linknumber
);
1570 if (icmap_get_uint8(tmp_key
, &u8
) == CS_OK
) {
1571 totem_config
->interfaces
[linknumber
].ttl
= u8
;
1574 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_DEFAULT_TRANSPORT
;
1575 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_transport", linknumber
);
1576 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1577 if (strcmp(str
, "sctp") == 0) {
1578 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_TRANSPORT_SCTP
;
1580 else if (strcmp(str
, "udp") == 0) {
1581 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_TRANSPORT_UDP
;
1584 *error_string
= "Unrecognised knet_transport. expected 'udp' or 'sctp'";
1589 totem_config
->interfaces
[linknumber
].configured
= 1;
1592 * Get the knet link params
1594 totem_config
->interfaces
[linknumber
].knet_link_priority
= 1;
1595 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_link_priority", linknumber
);
1597 if (icmap_get_uint8(tmp_key
, &u8
) == CS_OK
) {
1598 totem_config
->interfaces
[linknumber
].knet_link_priority
= u8
;
1601 totem_config
->interfaces
[linknumber
].knet_ping_interval
= 0; /* real default applied later */
1602 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_interval", linknumber
);
1603 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1604 totem_config
->interfaces
[linknumber
].knet_ping_interval
= u32
;
1606 totem_config
->interfaces
[linknumber
].knet_ping_timeout
= 0; /* real default applied later */
1607 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_timeout", linknumber
);
1608 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1609 totem_config
->interfaces
[linknumber
].knet_ping_timeout
= u32
;
1611 totem_config
->interfaces
[linknumber
].knet_ping_precision
= KNET_PING_PRECISION
;
1612 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_precision", linknumber
);
1613 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1614 totem_config
->interfaces
[linknumber
].knet_ping_precision
= u32
;
1616 totem_config
->interfaces
[linknumber
].knet_pong_count
= KNET_PONG_COUNT
;
1617 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_pong_count", linknumber
);
1618 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1619 totem_config
->interfaces
[linknumber
].knet_pong_count
= u32
;
1622 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.member.", linknumber
);
1623 member_iter
= icmap_iter_init(tmp_key
);
1624 while ((member_iter_key
= icmap_iter_next(member_iter
, NULL
, NULL
)) != NULL
) {
1625 if (member_count
== 0) {
1626 if (icmap_get_string("nodelist.node.0.ring0_addr", &str
) == CS_OK
) {
1628 *warnings
|= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
;
1631 *warnings
|= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
;
1635 if (icmap_get_string(member_iter_key
, &str
) == CS_OK
) {
1636 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].member_list
[member_count
++],
1637 str
, totem_config
->ip_version
);
1639 sprintf(error_string_response
, "failed to parse node address '%s'\n", str
);
1640 *error_string
= error_string_response
;
1642 icmap_iter_finalize(member_iter
);
1643 icmap_iter_finalize(iter
);
1651 icmap_iter_finalize(member_iter
);
1653 totem_config
->interfaces
[linknumber
].member_count
= member_count
;
1656 icmap_iter_finalize(iter
);
1661 extern int totem_config_read (
1662 struct totem_config
*totem_config
,
1663 const char **error_string
,
1667 char *str
, *ring0_addr_str
;
1668 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
1676 memset (totem_config
, 0, sizeof (struct totem_config
));
1677 totem_config
->interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
1678 if (totem_config
->interfaces
== 0) {
1679 *error_string
= "Out of memory trying to allocate ethernet interface storage area";
1683 totem_config
->transport_number
= TOTEM_TRANSPORT_KNET
;
1684 if (icmap_get_string("totem.transport", &str
) == CS_OK
) {
1685 if (strcmp (str
, "udpu") == 0) {
1686 totem_config
->transport_number
= TOTEM_TRANSPORT_UDPU
;
1689 if (strcmp (str
, "udp") == 0) {
1690 totem_config
->transport_number
= TOTEM_TRANSPORT_UDP
;
1693 if (strcmp (str
, "knet") == 0) {
1694 totem_config
->transport_number
= TOTEM_TRANSPORT_KNET
;
1700 memset (totem_config
->interfaces
, 0,
1701 sizeof (struct totem_interface
) * INTERFACE_MAX
);
1703 strcpy (totem_config
->link_mode
, "passive");
1705 icmap_get_uint32("totem.version", (uint32_t *)&totem_config
->version
);
1707 if (totem_get_crypto(totem_config
, error_string
) != 0) {
1711 if (icmap_get_string("totem.link_mode", &str
) == CS_OK
) {
1712 if (strlen(str
) >= TOTEM_LINK_MODE_BYTES
) {
1713 *error_string
= "totem.link_mode is too long";
1718 strcpy (totem_config
->link_mode
, str
);
1722 icmap_get_uint32("totem.nodeid", &totem_config
->node_id
);
1724 totem_config
->clear_node_high_bit
= 0;
1725 if (icmap_get_string("totem.clear_node_high_bit", &str
) == CS_OK
) {
1726 if (strcmp (str
, "yes") == 0) {
1727 totem_config
->clear_node_high_bit
= 1;
1732 icmap_get_uint32("totem.threads", &totem_config
->threads
);
1734 icmap_get_uint32("totem.netmtu", &totem_config
->net_mtu
);
1736 totem_config
->ip_version
= totem_config_get_ip_version(totem_config
);
1738 if (icmap_get_string("totem.interface.0.bindnetaddr", &str
) != CS_OK
) {
1740 * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
1742 config_convert_nodelist_to_interface(totem_config
);
1744 if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str
) == CS_OK
) {
1746 * Both bindnetaddr and ring0_addr are set.
1747 * Log warning information, and use nodelist instead
1749 *warnings
|= TOTEM_CONFIG_BINDNETADDR_NODELIST_SET
;
1751 config_convert_nodelist_to_interface(totem_config
);
1753 free(ring0_addr_str
);
1760 * Broadcast option is global but set in interface section,
1761 * so reset before processing interfaces.
1763 totem_config
->broadcast_use
= 0;
1765 res
= get_interface_params(totem_config
, error_string
, warnings
, 0);
1771 * Use broadcast is global, so if set, make sure to fill mcast addr correctly
1772 * broadcast is only supported for UDP so just do interface 0;
1774 if (totem_config
->broadcast_use
) {
1775 totemip_parse (&totem_config
->interfaces
[0].mcast_addr
,
1776 "255.255.255.255", TOTEM_IP_VERSION_4
);
1781 * Store automatically generated items back to icmap only for UDP
1783 if (totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1784 for (i
= 0; i
< INTERFACE_MAX
; i
++) {
1785 if (!totem_config
->interfaces
[i
].configured
) {
1788 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastaddr", i
);
1789 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1792 str
= (char *)totemip_print(&totem_config
->interfaces
[i
].mcast_addr
);
1793 icmap_set_string(tmp_key
, str
);
1796 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastport", i
);
1797 if (icmap_get_uint16(tmp_key
, &u16
) != CS_OK
) {
1798 icmap_set_uint16(tmp_key
, totem_config
->interfaces
[i
].ip_port
);
1804 * Check existence of nodelist
1806 if ((icmap_get_string("nodelist.node.0.name", &str
) == CS_OK
) ||
1807 (icmap_get_string("nodelist.node.0.ring0_addr", &str
) == CS_OK
)) {
1812 local_node_pos
= find_local_node(1);
1813 if (local_node_pos
!= -1) {
1815 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", local_node_pos
);
1817 nodeid_set
= (totem_config
->node_id
!= 0);
1818 if (icmap_get_uint32(tmp_key
, &totem_config
->node_id
) == CS_OK
&& nodeid_set
) {
1819 *warnings
|= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
;
1821 if ((totem_config
->transport_number
== TOTEM_TRANSPORT_KNET
) && (!totem_config
->node_id
)) {
1822 *error_string
= "Knet requires an explicit nodeid for the local node";
1826 if ((totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
||
1827 totem_config
->transport_number
== TOTEM_TRANSPORT_UDPU
) && (!totem_config
->node_id
)) {
1829 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", local_node_pos
);
1830 icmap_get_string(tmp_key
, &str
);
1832 totem_config
->node_id
= generate_nodeid(totem_config
, str
);
1833 if (totem_config
->node_id
== -1) {
1834 *error_string
= "An IPV6 network requires that a node ID be specified";
1840 totem_config
->interfaces
[0].member_list
[local_node_pos
].nodeid
= totem_config
->node_id
;
1845 /* Users must not change this */
1846 icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
1849 if (put_nodelist_members_to_config(totem_config
, 0, error_string
)) {
1855 * Get things that might change in the future (and can depend on totem_config->interfaces);
1857 totem_volatile_config_read(totem_config
, NULL
);
1859 calc_knet_ping_timers(totem_config
);
1861 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1863 add_totem_config_notification(totem_config
);
1869 int totem_config_validate (
1870 struct totem_config
*totem_config
,
1871 const char **error_string
)
1873 static char local_error_reason
[512];
1874 char parse_error
[512];
1875 static char addr_str_buf
[INET6_ADDRSTRLEN
];
1876 const char *error_reason
= local_error_reason
;
1879 int num_configured
= 0;
1880 unsigned int interface_max
= INTERFACE_MAX
;
1882 for (i
= 0; i
< INTERFACE_MAX
; i
++) {
1883 if (totem_config
->interfaces
[i
].configured
) {
1887 if (num_configured
== 0) {
1888 error_reason
= "No interfaces defined";
1892 /* Check we found a local node name */
1893 if (icmap_get_uint32("nodelist.local_node_pos", &u32
) != CS_OK
) {
1894 error_reason
= "No valid name found for local host";
1898 for (i
= 0; i
< INTERFACE_MAX
; i
++) {
1900 * Some error checking of parsed data to make sure its valid
1903 struct totem_ip_address null_addr
;
1905 if (!totem_config
->interfaces
[i
].configured
) {
1909 memset (&null_addr
, 0, sizeof (struct totem_ip_address
));
1911 if ((totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) &&
1912 memcmp (&totem_config
->interfaces
[i
].mcast_addr
, &null_addr
,
1913 sizeof (struct totem_ip_address
)) == 0) {
1914 error_reason
= "No multicast address specified";
1918 if (totem_config
->interfaces
[i
].ip_port
== 0) {
1919 error_reason
= "No multicast port specified";
1923 if (totem_config
->interfaces
[i
].ttl
> 255) {
1924 error_reason
= "Invalid TTL (should be 0..255)";
1927 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_UDP
&&
1928 totem_config
->interfaces
[i
].ttl
!= 1) {
1929 error_reason
= "Can only set ttl on multicast transport types";
1932 if (totem_config
->interfaces
[i
].knet_link_priority
> 255) {
1933 error_reason
= "Invalid link priority (should be 0..255)";
1936 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
&&
1937 totem_config
->interfaces
[i
].knet_link_priority
!= 1) {
1938 error_reason
= "Can only set link priority on knet transport type";
1942 if (totem_config
->interfaces
[i
].mcast_addr
.family
== AF_INET6
&&
1943 totem_config
->node_id
== 0) {
1945 error_reason
= "An IPV6 network requires that a node ID be specified.";
1949 if (totem_config
->broadcast_use
== 0 && totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1950 if (totem_config
->interfaces
[i
].mcast_addr
.family
!= totem_config
->interfaces
[i
].bindnet
.family
) {
1951 error_reason
= "Multicast address family does not match bind address family";
1955 if (totemip_is_mcast (&totem_config
->interfaces
[i
].mcast_addr
) != 0) {
1956 error_reason
= "mcastaddr is not a correct multicast address.";
1960 /* Verify that all nodes on the same knet link have the same IP family */
1961 for (j
=1; j
<totem_config
->interfaces
[i
].member_count
; j
++) {
1962 if (totem_config
->interfaces
[i
].configured
) {
1963 if (totem_config
->interfaces
[i
].member_list
[j
].family
!=
1964 totem_config
->interfaces
[i
].member_list
[0].family
) {
1965 memcpy(addr_str_buf
,
1966 totemip_print(&(totem_config
->interfaces
[i
].member_list
[j
])),
1967 sizeof(addr_str_buf
));
1969 snprintf (local_error_reason
, sizeof(local_error_reason
),
1970 "Nodes for link %d have different IP families "
1971 "(compared %s with %s)", i
,
1973 totemip_print(&(totem_config
->interfaces
[i
].member_list
[0])));
1980 if (totem_config
->version
!= 2) {
1981 error_reason
= "This totem parser can only parse version 2 configurations.";
1985 if (totem_volatile_config_validate(totem_config
, error_string
) == -1) {
1989 if (check_for_duplicate_nodeids(totem_config
, error_string
) == -1) {
1994 * KNET Link values validation
1996 if (strcmp (totem_config
->link_mode
, "active") &&
1997 strcmp (totem_config
->link_mode
, "rr") &&
1998 strcmp (totem_config
->link_mode
, "passive")) {
1999 snprintf (local_error_reason
, sizeof(local_error_reason
),
2000 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config
->link_mode
);
2004 /* Only Knet does multiple interfaces */
2005 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
) {
2009 if (interface_max
< num_configured
) {
2010 snprintf (parse_error
, sizeof(parse_error
),
2011 "%d is too many configured interfaces for non-Knet transport.",
2013 error_reason
= parse_error
;
2017 /* Only knet allows crypto */
2018 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
) {
2019 if ((strcmp(totem_config
->crypto_cipher_type
, "none") != 0) ||
2020 (strcmp(totem_config
->crypto_hash_type
, "none") != 0)) {
2022 snprintf (parse_error
, sizeof(parse_error
),
2023 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2024 error_reason
= parse_error
;
2029 if (totem_config
->net_mtu
== 0) {
2030 if (totem_config
->transport_number
== TOTEM_TRANSPORT_KNET
) {
2031 totem_config
->net_mtu
= KNET_MAX_PACKET_SIZE
;
2034 totem_config
->net_mtu
= 1500;
2041 snprintf (error_string_response
, sizeof(error_string_response
),
2042 "parse error in config: %s\n", error_reason
);
2043 *error_string
= error_string_response
;
2048 static int read_keyfile (
2049 const char *key_location
,
2050 struct totem_config
*totem_config
,
2051 const char **error_string
)
2056 char error_str
[100];
2057 const char *error_ptr
;
2059 fd
= open (key_location
, O_RDONLY
);
2061 error_ptr
= qb_strerror_r(errno
, error_str
, sizeof(error_str
));
2062 snprintf (error_string_response
, sizeof(error_string_response
),
2063 "Could not open %s: %s\n",
2064 key_location
, error_ptr
);
2068 res
= read (fd
, totem_config
->private_key
, TOTEM_PRIVATE_KEY_LEN_MAX
);
2069 saved_errno
= errno
;
2073 error_ptr
= qb_strerror_r (saved_errno
, error_str
, sizeof(error_str
));
2074 snprintf (error_string_response
, sizeof(error_string_response
),
2075 "Could not read %s: %s\n",
2076 key_location
, error_ptr
);
2080 if (res
< TOTEM_PRIVATE_KEY_LEN_MIN
) {
2081 snprintf (error_string_response
, sizeof(error_string_response
),
2082 "Could only read %d bits of minimum %u bits from %s.\n",
2083 res
* 8, TOTEM_PRIVATE_KEY_LEN_MIN
* 8, key_location
);
2087 totem_config
->private_key_len
= res
;
2092 *error_string
= error_string_response
;
2096 int totem_config_keyread (
2097 struct totem_config
*totem_config
,
2098 const char **error_string
)
2101 char *key_location
= NULL
;
2105 memset (totem_config
->private_key
, 0, sizeof(totem_config
->private_key
));
2106 totem_config
->private_key_len
= 0;
2108 if (strcmp(totem_config
->crypto_cipher_type
, "none") == 0 &&
2109 strcmp(totem_config
->crypto_hash_type
, "none") == 0) {
2113 /* cmap may store the location of the key file */
2114 if (icmap_get_string("totem.keyfile", &key_location
) == CS_OK
) {
2115 res
= read_keyfile(key_location
, totem_config
, error_string
);
2121 } else { /* Or the key itself may be in the cmap */
2122 if (icmap_get("totem.key", NULL
, &key_len
, NULL
) == CS_OK
) {
2123 if (key_len
> sizeof(totem_config
->private_key
)) {
2124 sprintf(error_string_response
, "key is too long");
2127 if (key_len
< TOTEM_PRIVATE_KEY_LEN_MIN
) {
2128 sprintf(error_string_response
, "key is too short");
2131 if (icmap_get("totem.key", totem_config
->private_key
, &key_len
, NULL
) == CS_OK
) {
2132 totem_config
->private_key_len
= key_len
;
2135 sprintf(error_string_response
, "can't load private key");
2141 /* In desperation we read the default filename */
2143 res
= read_keyfile(COROSYSCONFDIR
"/authkey", totem_config
, error_string
);
2151 *error_string
= error_string_response
;
2156 static void debug_dump_totem_config(const struct totem_config
*totem_config
)
2159 log_printf(LOGSYS_LEVEL_DEBUG
, "Token Timeout (%d ms) retransmit timeout (%d ms)",
2160 totem_config
->token_timeout
, totem_config
->token_retransmit_timeout
);
2161 if (totem_config
->token_warning
) {
2162 uint32_t token_warning_ms
= totem_config
->token_warning
* totem_config
->token_timeout
/ 100;
2163 log_printf(LOGSYS_LEVEL_DEBUG
, "Token warning every %d ms (%d%% of Token Timeout)",
2164 token_warning_ms
, totem_config
->token_warning
);
2165 if (token_warning_ms
< totem_config
->token_retransmit_timeout
)
2166 log_printf (LOGSYS_LEVEL_DEBUG
,
2167 "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) "
2168 "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2169 token_warning_ms
, totem_config
->token_retransmit_timeout
);
2172 log_printf(LOGSYS_LEVEL_DEBUG
, "Token warnings disabled");
2173 log_printf(LOGSYS_LEVEL_DEBUG
, "token hold (%d ms) retransmits before loss (%d retrans)",
2174 totem_config
->token_hold_timeout
, totem_config
->token_retransmits_before_loss_const
);
2175 log_printf(LOGSYS_LEVEL_DEBUG
, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
2176 totem_config
->join_timeout
, totem_config
->send_join_timeout
, totem_config
->consensus_timeout
,
2177 totem_config
->merge_timeout
);
2178 log_printf(LOGSYS_LEVEL_DEBUG
, "downcheck (%d ms) fail to recv const (%d msgs)",
2179 totem_config
->downcheck_timeout
, totem_config
->fail_to_recv_const
);
2180 log_printf(LOGSYS_LEVEL_DEBUG
,
2181 "seqno unchanged const (%d rotations) Maximum network MTU %d",
2182 totem_config
->seqno_unchanged_const
, totem_config
->net_mtu
);
2183 log_printf(LOGSYS_LEVEL_DEBUG
,
2184 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2185 totem_config
->window_size
, totem_config
->max_messages
);
2186 log_printf(LOGSYS_LEVEL_DEBUG
, "missed count const (%d messages)", totem_config
->miss_count_const
);
2187 log_printf(LOGSYS_LEVEL_DEBUG
, "heartbeat_failures_allowed (%d)",
2188 totem_config
->heartbeat_failures_allowed
);
2189 log_printf(LOGSYS_LEVEL_DEBUG
, "max_network_delay (%d ms)", totem_config
->max_network_delay
);
2192 static void totem_change_notify(
2194 const char *key_name
,
2195 struct icmap_notify_value new_val
,
2196 struct icmap_notify_value old_val
,
2199 struct totem_config
*totem_config
= (struct totem_config
*)user_data
;
2202 const char *deleted_key
= NULL
;
2203 const char *error_string
;
2206 * If a full reload is in progress then don't do anything until it's done and
2207 * can reconfigure it all atomically
2209 if (icmap_get_uint8("config.reload_in_progress", &reloading
) == CS_OK
&& reloading
)
2212 param
= totem_get_param_by_name((struct totem_config
*)user_data
, key_name
);
2214 * Process change only if changed key is found in totem_config (-> param is not NULL)
2215 * or for special key token_coefficient. token_coefficient key is not stored in
2216 * totem_config, but it is used for computation of token timeout.
2218 if (!param
&& strcmp(key_name
, "totem.token_coefficient") != 0)
2222 * Values other than UINT32 are not supported, or needed (yet)
2225 case ICMAP_TRACK_DELETE
:
2226 deleted_key
= key_name
;
2228 case ICMAP_TRACK_ADD
:
2229 case ICMAP_TRACK_MODIFY
:
2236 totem_volatile_config_read (totem_config
, deleted_key
);
2237 log_printf(LOGSYS_LEVEL_DEBUG
, "Totem related config key changed. Dumping actual totem config.");
2238 debug_dump_totem_config(totem_config
);
2239 if (totem_volatile_config_validate(totem_config
, &error_string
) == -1) {
2240 log_printf (LOGSYS_LEVEL_ERROR
, "%s", error_string
);
2242 * TODO: Consider corosync exit and/or load defaults for volatile
2243 * values. For now, log error seems to be enough
2248 static void totem_reload_notify(
2250 const char *key_name
,
2251 struct icmap_notify_value new_val
,
2252 struct icmap_notify_value old_val
,
2255 struct totem_config
*totem_config
= (struct totem_config
*)user_data
;
2256 const char *error_string
;
2259 /* Reload has completed */
2260 if (*(uint8_t *)new_val
.data
== 0) {
2262 totem_config
->orig_interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
2263 assert(totem_config
->orig_interfaces
!= NULL
);
2264 memcpy(totem_config
->orig_interfaces
, totem_config
->interfaces
, sizeof (struct totem_interface
) * INTERFACE_MAX
);
2266 get_interface_params(totem_config
, &error_string
, &warnings
, 1);
2267 if (put_nodelist_members_to_config (totem_config
, 1, &error_string
)) {
2268 log_printf (LOGSYS_LEVEL_ERROR
, "%s", error_string
);
2270 totem_volatile_config_read (totem_config
, NULL
);
2272 calc_knet_ping_timers(totem_config
);
2274 log_printf(LOGSYS_LEVEL_DEBUG
, "Configuration reloaded. Dumping actual totem config.");
2275 debug_dump_totem_config(totem_config
);
2276 if (totem_volatile_config_validate(totem_config
, &error_string
) == -1) {
2277 log_printf (LOGSYS_LEVEL_ERROR
, "%s", error_string
);
2279 * TODO: Consider corosync exit and/or load defaults for volatile
2280 * values. For now, log error seems to be enough
2284 /* Reinstate the local_node_pos */
2285 (void)find_local_node(0);
2287 /* Reconfigure network params as appropriate */
2288 totempg_reconfigure();
2290 free(totem_config
->orig_interfaces
);
2292 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
2294 icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
2298 static void add_totem_config_notification(struct totem_config
*totem_config
)
2300 icmap_track_t icmap_track
;
2302 icmap_track_add("totem.",
2303 ICMAP_TRACK_ADD
| ICMAP_TRACK_DELETE
| ICMAP_TRACK_MODIFY
| ICMAP_TRACK_PREFIX
,
2304 totem_change_notify
,
2308 icmap_track_add("config.reload_in_progress",
2309 ICMAP_TRACK_ADD
| ICMAP_TRACK_MODIFY
,
2310 totem_reload_notify
,