2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
3 * Copyright (c) 2006-2013 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>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/param.h>
52 #include <corosync/swab.h>
53 #include <qb/qblist.h>
54 #include <qb/qbdefs.h>
56 #include <corosync/totem/totem.h>
57 #include <corosync/config.h>
58 #include <corosync/logsys.h>
59 #include <corosync/icmap.h>
62 #include "totemconfig.h"
64 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
65 #define TOKEN_TIMEOUT 1000
66 #define TOKEN_COEFFICIENT 650
67 #define JOIN_TIMEOUT 50
68 #define MERGE_TIMEOUT 200
69 #define DOWNCHECK_TIMEOUT 1000
70 #define FAIL_TO_RECV_CONST 2500
71 #define SEQNO_UNCHANGED_CONST 30
72 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
73 #define MAX_NETWORK_DELAY 50
74 #define WINDOW_SIZE 50
75 #define MAX_MESSAGES 17
76 #define MISS_COUNT_CONST 5
78 /* These currently match the defaults in libknet.h */
79 #define KNET_PING_INTERVAL 1000
80 #define KNET_PING_TIMEOUT 2000
81 #define KNET_PING_PRECISION 2048
82 #define KNET_PONG_COUNT 2
83 #define KNET_PMTUD_INTERVAL 30
84 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP
86 #define DEFAULT_PORT 5405
88 static char error_string_response
[512];
90 static void add_totem_config_notification(struct totem_config
*totem_config
);
93 /* All the volatile parameters are uint32s, luckily */
94 static uint32_t *totem_get_param_by_name(struct totem_config
*totem_config
, const char *param_name
)
96 if (strcmp(param_name
, "totem.token") == 0)
97 return &totem_config
->token_timeout
;
98 if (strcmp(param_name
, "totem.token_retransmit") == 0)
99 return &totem_config
->token_retransmit_timeout
;
100 if (strcmp(param_name
, "totem.hold") == 0)
101 return &totem_config
->token_hold_timeout
;
102 if (strcmp(param_name
, "totem.token_retransmits_before_loss_const") == 0)
103 return &totem_config
->token_retransmits_before_loss_const
;
104 if (strcmp(param_name
, "totem.join") == 0)
105 return &totem_config
->join_timeout
;
106 if (strcmp(param_name
, "totem.send_join") == 0)
107 return &totem_config
->send_join_timeout
;
108 if (strcmp(param_name
, "totem.consensus") == 0)
109 return &totem_config
->consensus_timeout
;
110 if (strcmp(param_name
, "totem.merge") == 0)
111 return &totem_config
->merge_timeout
;
112 if (strcmp(param_name
, "totem.downcheck") == 0)
113 return &totem_config
->downcheck_timeout
;
114 if (strcmp(param_name
, "totem.fail_recv_const") == 0)
115 return &totem_config
->fail_to_recv_const
;
116 if (strcmp(param_name
, "totem.seqno_unchanged_const") == 0)
117 return &totem_config
->seqno_unchanged_const
;
118 if (strcmp(param_name
, "totem.heartbeat_failures_allowed") == 0)
119 return &totem_config
->heartbeat_failures_allowed
;
120 if (strcmp(param_name
, "totem.max_network_delay") == 0)
121 return &totem_config
->max_network_delay
;
122 if (strcmp(param_name
, "totem.window_size") == 0)
123 return &totem_config
->window_size
;
124 if (strcmp(param_name
, "totem.max_messages") == 0)
125 return &totem_config
->max_messages
;
126 if (strcmp(param_name
, "totem.miss_count_const") == 0)
127 return &totem_config
->miss_count_const
;
128 if (strcmp(param_name
, "totem.knet_pmtud_interval") == 0)
129 return &totem_config
->knet_pmtud_interval
;
135 * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
136 * and readed value is zero, default value is used and stored into totem_config.
138 static void totem_volatile_config_set_value (struct totem_config
*totem_config
,
139 const char *key_name
, const char *deleted_key
, unsigned int default_value
,
140 int allow_zero_value
)
142 char runtime_key_name
[ICMAP_KEYNAME_MAXLEN
];
144 if (icmap_get_uint32(key_name
, totem_get_param_by_name(totem_config
, key_name
)) != CS_OK
||
145 (deleted_key
!= NULL
&& strcmp(deleted_key
, key_name
) == 0) ||
146 (!allow_zero_value
&& *totem_get_param_by_name(totem_config
, key_name
) == 0)) {
147 *totem_get_param_by_name(totem_config
, key_name
) = default_value
;
151 * Store totem_config value to cmap runtime section
153 if (strlen("runtime.config.") + strlen(key_name
) >= ICMAP_KEYNAME_MAXLEN
) {
155 * This shouldn't happen
160 strcpy(runtime_key_name
, "runtime.config.");
161 strcat(runtime_key_name
, key_name
);
163 icmap_set_uint32(runtime_key_name
, *totem_get_param_by_name(totem_config
, key_name
));
168 * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
169 * default value is stored. deleted_key is name of key beeing processed by delete operation
170 * from cmap. It is considered as non existing even if it can be read. Can be NULL.
172 static void totem_volatile_config_read (struct totem_config
*totem_config
, const char *deleted_key
)
176 totem_volatile_config_set_value(totem_config
, "totem.token_retransmits_before_loss_const", deleted_key
,
177 TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
, 0);
179 totem_volatile_config_set_value(totem_config
, "totem.token", deleted_key
, TOKEN_TIMEOUT
, 0);
181 if (totem_config
->interface_count
> 0 && totem_config
->interfaces
[0].member_count
> 2) {
182 u32
= TOKEN_COEFFICIENT
;
183 icmap_get_uint32("totem.token_coefficient", &u32
);
184 totem_config
->token_timeout
+= (totem_config
->interfaces
[0].member_count
- 2) * u32
;
187 * Store totem_config value to cmap runtime section
189 icmap_set_uint32("runtime.config.totem.token", totem_config
->token_timeout
);
192 totem_volatile_config_set_value(totem_config
, "totem.max_network_delay", deleted_key
, MAX_NETWORK_DELAY
, 0);
194 totem_volatile_config_set_value(totem_config
, "totem.window_size", deleted_key
, WINDOW_SIZE
, 0);
196 totem_volatile_config_set_value(totem_config
, "totem.max_messages", deleted_key
, MAX_MESSAGES
, 0);
198 totem_volatile_config_set_value(totem_config
, "totem.miss_count_const", deleted_key
, MISS_COUNT_CONST
, 0);
199 totem_volatile_config_set_value(totem_config
, "totem.knet_pmtud_interval", deleted_key
, KNET_PMTUD_INTERVAL
, 0);
201 totem_volatile_config_set_value(totem_config
, "totem.token_retransmit", deleted_key
,
202 (int)(totem_config
->token_timeout
/ (totem_config
->token_retransmits_before_loss_const
+ 0.2)), 0);
204 totem_volatile_config_set_value(totem_config
, "totem.hold", deleted_key
,
205 (int)(totem_config
->token_retransmit_timeout
* 0.8 - (1000/HZ
)), 0);
207 totem_volatile_config_set_value(totem_config
, "totem.join", deleted_key
, JOIN_TIMEOUT
, 0);
209 totem_volatile_config_set_value(totem_config
, "totem.consensus", deleted_key
,
210 (int)(float)(1.2 * totem_config
->token_timeout
), 0);
212 totem_volatile_config_set_value(totem_config
, "totem.merge", deleted_key
, MERGE_TIMEOUT
, 0);
214 totem_volatile_config_set_value(totem_config
, "totem.downcheck", deleted_key
, DOWNCHECK_TIMEOUT
, 0);
216 totem_volatile_config_set_value(totem_config
, "totem.fail_recv_const", deleted_key
, FAIL_TO_RECV_CONST
, 0);
218 totem_volatile_config_set_value(totem_config
, "totem.seqno_unchanged_const", deleted_key
,
219 SEQNO_UNCHANGED_CONST
, 0);
221 totem_volatile_config_set_value(totem_config
, "totem.send_join", deleted_key
, 0, 1);
223 totem_volatile_config_set_value(totem_config
, "totem.heartbeat_failures_allowed", deleted_key
, 0, 1);
226 static int totem_volatile_config_validate (
227 struct totem_config
*totem_config
,
228 const char **error_string
)
230 static char local_error_reason
[512];
231 const char *error_reason
= local_error_reason
;
233 if (totem_config
->max_network_delay
< MINIMUM_TIMEOUT
) {
234 snprintf (local_error_reason
, sizeof(local_error_reason
),
235 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
236 totem_config
->max_network_delay
, MINIMUM_TIMEOUT
);
240 if (totem_config
->token_timeout
< MINIMUM_TIMEOUT
) {
241 snprintf (local_error_reason
, sizeof(local_error_reason
),
242 "The token timeout parameter (%d ms) may not be less than (%d ms).",
243 totem_config
->token_timeout
, MINIMUM_TIMEOUT
);
247 if (totem_config
->token_retransmit_timeout
< MINIMUM_TIMEOUT
) {
248 snprintf (local_error_reason
, sizeof(local_error_reason
),
249 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
250 totem_config
->token_retransmit_timeout
, MINIMUM_TIMEOUT
);
254 if (totem_config
->token_hold_timeout
< MINIMUM_TIMEOUT
) {
255 snprintf (local_error_reason
, sizeof(local_error_reason
),
256 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
257 totem_config
->token_hold_timeout
, MINIMUM_TIMEOUT
);
261 if (totem_config
->join_timeout
< MINIMUM_TIMEOUT
) {
262 snprintf (local_error_reason
, sizeof(local_error_reason
),
263 "The join timeout parameter (%d ms) may not be less than (%d ms).",
264 totem_config
->join_timeout
, MINIMUM_TIMEOUT
);
268 if (totem_config
->consensus_timeout
< MINIMUM_TIMEOUT
) {
269 snprintf (local_error_reason
, sizeof(local_error_reason
),
270 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
271 totem_config
->consensus_timeout
, MINIMUM_TIMEOUT
);
275 if (totem_config
->consensus_timeout
< totem_config
->join_timeout
) {
276 snprintf (local_error_reason
, sizeof(local_error_reason
),
277 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
278 totem_config
->consensus_timeout
, totem_config
->join_timeout
);
282 if (totem_config
->merge_timeout
< MINIMUM_TIMEOUT
) {
283 snprintf (local_error_reason
, sizeof(local_error_reason
),
284 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
285 totem_config
->merge_timeout
, MINIMUM_TIMEOUT
);
289 if (totem_config
->downcheck_timeout
< MINIMUM_TIMEOUT
) {
290 snprintf (local_error_reason
, sizeof(local_error_reason
),
291 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
292 totem_config
->downcheck_timeout
, MINIMUM_TIMEOUT
);
299 snprintf (error_string_response
, sizeof(error_string_response
),
300 "parse error in config: %s\n", error_reason
);
301 *error_string
= error_string_response
;
306 static int totem_get_crypto(struct totem_config
*totem_config
)
309 const char *tmp_cipher
;
310 const char *tmp_hash
;
315 if (icmap_get_string("totem.crypto_cipher", &str
) == CS_OK
) {
316 if (strcmp(str
, "none") == 0) {
319 if (strcmp(str
, "aes256") == 0) {
320 tmp_cipher
= "aes256";
322 if (strcmp(str
, "aes192") == 0) {
323 tmp_cipher
= "aes192";
325 if (strcmp(str
, "aes128") == 0) {
326 tmp_cipher
= "aes128";
328 if (strcmp(str
, "aes256") == 0) {
329 tmp_cipher
= "aes256";
331 if (strcmp(str
, "3des") == 0) {
337 if (icmap_get_string("totem.crypto_hash", &str
) == CS_OK
) {
338 if (strcmp(str
, "none") == 0) {
341 if (strcmp(str
, "md5") == 0) {
344 if (strcmp(str
, "sha1") == 0) {
347 if (strcmp(str
, "sha256") == 0) {
350 if (strcmp(str
, "sha384") == 0) {
353 if (strcmp(str
, "sha512") == 0) {
359 if ((strcmp(tmp_cipher
, "none") != 0) &&
360 (strcmp(tmp_hash
, "none") == 0)) {
364 free(totem_config
->crypto_cipher_type
);
365 free(totem_config
->crypto_hash_type
);
367 totem_config
->crypto_cipher_type
= strdup(tmp_cipher
);
368 totem_config
->crypto_hash_type
= strdup(tmp_hash
);
373 static int totem_config_get_ip_version(void)
379 if (icmap_get_string("totem.ip_version", &str
) == CS_OK
) {
380 if (strcmp(str
, "ipv4") == 0) {
383 if (strcmp(str
, "ipv6") == 0) {
392 static uint16_t generate_cluster_id (const char *cluster_name
)
397 for (i
= 0; i
< strlen(cluster_name
); i
++) {
399 value
+= cluster_name
[i
];
402 return (value
& 0xFFFF);
405 static int get_cluster_mcast_addr (
406 const char *cluster_name
,
407 unsigned int linknumber
,
409 struct totem_ip_address
*res
)
412 char addr
[INET6_ADDRSTRLEN
+ 1];
415 if (cluster_name
== NULL
) {
419 clusterid
= generate_cluster_id(cluster_name
) + linknumber
;
420 memset (res
, 0, sizeof(*res
));
422 switch (ip_version
) {
424 snprintf(addr
, sizeof(addr
), "239.192.%d.%d", clusterid
>> 8, clusterid
% 0xFF);
427 snprintf(addr
, sizeof(addr
), "ff15::%x", clusterid
);
436 err
= totemip_parse (res
, addr
, ip_version
);
441 static unsigned int generate_nodeid_for_duplicate_test(
442 struct totem_config
*totem_config
,
446 struct totem_ip_address totemip
;
448 /* AF_INET hard-coded here because auto-generated nodeids
450 if (totemip_parse(&totemip
, addr
, AF_INET
) != 0)
453 memcpy (&nodeid
, &totemip
.addr
, sizeof (unsigned int));
455 #if __BYTE_ORDER == __LITTLE_ENDIAN
456 nodeid
= swab32 (nodeid
);
459 if (totem_config
->clear_node_high_bit
) {
460 nodeid
&= 0x7FFFFFFF;
465 static int check_for_duplicate_nodeids(
466 struct totem_config
*totem_config
,
467 const char **error_string
)
470 icmap_iter_t subiter
;
471 const char *iter_key
;
474 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
475 char *ring0_addr
=NULL
;
476 char *ring0_addr1
=NULL
;
477 unsigned int node_pos
;
478 unsigned int node_pos1
;
480 unsigned int nodeid1
;
483 iter
= icmap_iter_init("nodelist.node.");
484 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
485 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, tmp_key
);
490 if (strcmp(tmp_key
, "ring0_addr") != 0) {
494 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos
);
496 if (icmap_get_uint32(tmp_key
, &nodeid
) != CS_OK
) {
498 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos
);
499 if (icmap_get_string(tmp_key
, &ring0_addr
) != CS_OK
) {
503 /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
504 nodeid
= generate_nodeid_for_duplicate_test(totem_config
, ring0_addr
);
512 subiter
= icmap_iter_init("nodelist.node.");
513 while (((iter_key
= icmap_iter_next(subiter
, NULL
, NULL
)) != NULL
) && (node_pos1
< node_pos
)) {
514 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos1
, tmp_key
);
515 if ((res
!= 2) || (node_pos1
>= node_pos
)) {
519 if (strcmp(tmp_key
, "ring0_addr") != 0) {
523 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos1
);
524 if (icmap_get_uint32(tmp_key
, &nodeid1
) != CS_OK
) {
526 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos1
);
527 if (icmap_get_string(tmp_key
, &ring0_addr1
) != CS_OK
) {
530 nodeid1
= generate_nodeid_for_duplicate_test(totem_config
, ring0_addr1
);
536 if (nodeid
== nodeid1
) {
538 snprintf (error_string_response
, sizeof(error_string_response
),
539 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid
,
540 autogenerated
?"(autogenerated from ":"",
541 autogenerated
?ring0_addr
:"",
542 autogenerated
?")":"");
543 log_printf (LOGSYS_LEVEL_ERROR
, error_string_response
);
544 *error_string
= error_string_response
;
548 icmap_iter_finalize(subiter
);
550 icmap_iter_finalize(iter
);
555 static int find_local_node_in_nodelist(struct totem_config
*totem_config
)
558 const char *iter_key
;
560 unsigned int node_pos
;
561 int local_node_pos
= -1;
562 struct totem_ip_address bind_addr
;
563 int interface_up
, interface_num
;
564 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
566 struct totem_ip_address node_addr
;
568 res
= totemip_iface_check(&totem_config
->interfaces
[0].bindnet
,
569 &bind_addr
, &interface_up
, &interface_num
,
570 totem_config
->clear_node_high_bit
);
575 iter
= icmap_iter_init("nodelist.node.");
576 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
577 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, tmp_key
);
582 if (strcmp(tmp_key
, "ring0_addr") != 0) {
586 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", node_pos
);
587 if (icmap_get_string(tmp_key
, &node_addr_str
) != CS_OK
) {
591 res
= totemip_parse (&node_addr
, node_addr_str
, totem_config
->ip_version
);
597 if (totemip_equal(&bind_addr
, &node_addr
)) {
598 local_node_pos
= node_pos
;
601 icmap_iter_finalize(iter
);
603 return (local_node_pos
);
607 * Compute difference between two set of totem interface arrays. set1 and set2
608 * are changed so for same ring, ip existing in both set1 and set2 are cleared
609 * (set to 0), and ips which are only in set1 or set2 remains untouched.
610 * totempg_node_add/remove is called.
612 static void compute_interfaces_diff(int interface_count
,
613 struct totem_interface
*set1
,
614 struct totem_interface
*set2
)
616 int ring_no
, set1_pos
, set2_pos
;
617 struct totem_ip_address empty_ip_address
;
619 memset(&empty_ip_address
, 0, sizeof(empty_ip_address
));
621 for (ring_no
= 0; ring_no
< interface_count
; ring_no
++) {
622 for (set1_pos
= 0; set1_pos
< set1
[ring_no
].member_count
; set1_pos
++) {
623 for (set2_pos
= 0; set2_pos
< set2
[ring_no
].member_count
; set2_pos
++) {
625 * For current ring_no remove all set1 items existing
628 if (memcmp(&set1
[ring_no
].member_list
[set1_pos
],
629 &set2
[ring_no
].member_list
[set2_pos
],
630 sizeof(struct totem_ip_address
)) == 0) {
631 memset(&set1
[ring_no
].member_list
[set1_pos
], 0,
632 sizeof(struct totem_ip_address
));
633 memset(&set2
[ring_no
].member_list
[set2_pos
], 0,
634 sizeof(struct totem_ip_address
));
640 for (ring_no
= 0; ring_no
< interface_count
; ring_no
++) {
641 for (set1_pos
= 0; set1_pos
< set1
[ring_no
].member_count
; set1_pos
++) {
643 * All items which remained in set1 doesn't exists in set2 any longer so
644 * node has to be removed.
646 if (memcmp(&set1
[ring_no
].member_list
[set1_pos
], &empty_ip_address
, sizeof(empty_ip_address
)) != 0) {
647 log_printf(LOGSYS_LEVEL_DEBUG
,
648 "removing dynamic member %s for ring %u",
649 totemip_print(&set1
[ring_no
].member_list
[set1_pos
]),
652 totempg_member_remove(&set1
[ring_no
].member_list
[set1_pos
], ring_no
);
655 for (set2_pos
= 0; set2_pos
< set2
[ring_no
].member_count
; set2_pos
++) {
657 * All items which remained in set2 doesn't existed in set1 so this is no node
658 * and has to be added.
660 if (memcmp(&set2
[ring_no
].member_list
[set2_pos
], &empty_ip_address
, sizeof(empty_ip_address
)) != 0) {
661 log_printf(LOGSYS_LEVEL_DEBUG
,
662 "adding dynamic member %s for ring %u",
663 totemip_print(&set2
[ring_no
].member_list
[set2_pos
]),
666 totempg_member_add(&set2
[ring_no
].member_list
[set2_pos
], ring_no
);
672 static void put_nodelist_members_to_config(struct totem_config
*totem_config
, int reload
)
674 icmap_iter_t iter
, iter2
;
675 const char *iter_key
, *iter_key2
;
677 unsigned int node_pos
;
678 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
679 char tmp_key2
[ICMAP_KEYNAME_MAXLEN
];
682 unsigned int linknumber
= 0;
684 struct totem_interface
*orig_interfaces
= NULL
;
685 struct totem_interface
*new_interfaces
= NULL
;
689 * We need to compute diff only for reload. Also for initial configuration
690 * not all totem structures are initialized so corosync will crash during
693 orig_interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
694 assert(orig_interfaces
!= NULL
);
695 new_interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
696 assert(new_interfaces
!= NULL
);
698 memcpy(orig_interfaces
, totem_config
->interfaces
, sizeof (struct totem_interface
) * INTERFACE_MAX
);
701 /* Clear out nodelist so we can put the new one in if needed */
702 for (i
= 0; i
< totem_config
->interface_count
; i
++) {
703 for (j
= 0; j
< PROCESSOR_COUNT_MAX
; j
++) {
704 memset(&totem_config
->interfaces
[i
].member_list
[j
], 0, sizeof(struct totem_ip_address
));
706 totem_config
->interfaces
[i
].member_count
= 0;
709 iter
= icmap_iter_init("nodelist.node.");
710 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
711 res
= sscanf(iter_key
, "nodelist.node.%u.%s", &node_pos
, tmp_key
);
716 if (strcmp(tmp_key
, "ring0_addr") != 0) {
720 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.", node_pos
);
721 iter2
= icmap_iter_init(tmp_key
);
722 while ((iter_key2
= icmap_iter_next(iter2
, NULL
, NULL
)) != NULL
) {
725 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", node_pos
);
726 if (icmap_get_uint32(tmp_key
, &nodeid
) != CS_OK
) {
729 res
= sscanf(iter_key2
, "nodelist.node.%u.ring%u%s", &node_pos
, &linknumber
, tmp_key2
);
730 if (res
!= 3 || strcmp(tmp_key2
, "_addr") != 0) {
734 if (icmap_get_string(iter_key2
, &node_addr_str
) != CS_OK
) {
738 member_count
= totem_config
->interfaces
[linknumber
].member_count
;
740 res
= totemip_parse(&totem_config
->interfaces
[linknumber
].member_list
[member_count
],
741 node_addr_str
, totem_config
->ip_version
);
743 totem_config
->interfaces
[linknumber
].member_list
[member_count
].nodeid
= nodeid
;
744 totem_config
->interfaces
[linknumber
].member_count
++;
749 icmap_iter_finalize(iter2
);
752 icmap_iter_finalize(iter
);
755 memcpy(new_interfaces
, totem_config
->interfaces
, sizeof (struct totem_interface
) * INTERFACE_MAX
);
757 compute_interfaces_diff(totem_config
->interface_count
, orig_interfaces
, new_interfaces
);
759 free(new_interfaces
);
760 free(orig_interfaces
);
764 static void nodelist_dynamic_notify(
766 const char *key_name
,
767 struct icmap_notify_value new_val
,
768 struct icmap_notify_value old_val
,
772 unsigned int ring_no
;
773 unsigned int member_no
;
774 char tmp_str
[ICMAP_KEYNAME_MAXLEN
];
776 struct totem_config
*totem_config
= (struct totem_config
*)user_data
;
779 * If a full reload is in progress then don't do anything until it's done and
780 * can reconfigure it all atomically
782 if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading
) == CS_OK
&& reloading
) {
786 res
= sscanf(key_name
, "nodelist.node.%u.ring%u%s", &member_no
, &ring_no
, tmp_str
);
790 if (strcmp(tmp_str
, "_addr") != 0) {
794 put_nodelist_members_to_config(totem_config
, 1);
799 * Tries to find node (node_pos) in config nodelist which address matches any
800 * local interface. Address can be stored in ring0_addr or if ipaddr_key_prefix is not NULL
801 * key with prefix ipaddr_key is used (there can be multiuple of them)
802 * This function differs * from find_local_node_in_nodelist because it doesn't need bindnetaddr,
803 * but doesn't work when bind addr is network address (so IP must be exact
806 * Returns 1 on success (address was found, node_pos is then correctly set) or 0 on failure.
808 int totem_config_find_local_addr_in_nodelist(const char *ipaddr_key_prefix
, unsigned int *node_pos
)
810 struct qb_list_head addrs
;
811 struct totem_ip_if_address
*if_addr
;
812 icmap_iter_t iter
, iter2
;
813 const char *iter_key
, *iter_key2
;
814 struct qb_list_head
*list
;
815 const char *ipaddr_key
;
817 struct totem_ip_address node_addr
;
821 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
823 if (totemip_getifaddrs(&addrs
) == -1) {
827 ip_version
= totem_config_get_ip_version();
829 iter
= icmap_iter_init("nodelist.node.");
831 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
832 res
= sscanf(iter_key
, "nodelist.node.%u.%s", node_pos
, tmp_key
);
837 if (strcmp(tmp_key
, "ring0_addr") != 0) {
841 if (icmap_get_string(iter_key
, &node_addr_str
) != CS_OK
) {
848 * ring0_addr found -> let's iterate thru ipaddr_key_prefix
850 snprintf(tmp_key
, sizeof(tmp_key
), "nodelist.node.%u.%s", *node_pos
,
851 (ipaddr_key_prefix
!= NULL
? ipaddr_key_prefix
: "ring0_addr"));
853 iter2
= icmap_iter_init(tmp_key
);
854 while ((iter_key2
= icmap_iter_next(iter2
, NULL
, NULL
)) != NULL
) {
856 * ring0_addr must be exact match, not prefix
858 ipaddr_key
= (ipaddr_key_prefix
!= NULL
? iter_key2
: tmp_key
);
859 if (icmap_get_string(ipaddr_key
, &node_addr_str
) != CS_OK
) {
863 if (totemip_parse(&node_addr
, node_addr_str
, ip_version
) == -1) {
870 * Try to match ip with if_addrs
873 qb_list_for_each(list
, &(addrs
)) {
874 if_addr
= qb_list_entry(list
, struct totem_ip_if_address
, list
);
876 if (totemip_equal(&node_addr
, &if_addr
->ip_addr
)) {
887 icmap_iter_finalize(iter2
);
894 icmap_iter_finalize(iter
);
895 totemip_freeifaddrs(&addrs
);
900 static void config_convert_nodelist_to_interface(struct totem_config
*totem_config
)
903 unsigned int node_pos
;
904 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
905 char tmp_key2
[ICMAP_KEYNAME_MAXLEN
];
907 unsigned int linknumber
= 0;
909 const char *iter_key
;
911 if (totem_config_find_local_addr_in_nodelist(NULL
, &node_pos
)) {
913 * We found node, so create interface section
915 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.", node_pos
);
916 iter
= icmap_iter_init(tmp_key
);
917 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
918 res
= sscanf(iter_key
, "nodelist.node.%u.ring%u%s", &node_pos
, &linknumber
, tmp_key2
);
919 if (res
!= 3 || strcmp(tmp_key2
, "_addr") != 0) {
923 if (icmap_get_string(iter_key
, &node_addr_str
) != CS_OK
) {
927 snprintf(tmp_key2
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.bindnetaddr", linknumber
);
928 icmap_set_string(tmp_key2
, node_addr_str
);
931 icmap_iter_finalize(iter
);
936 extern int totem_config_read (
937 struct totem_config
*totem_config
,
938 const char **error_string
,
942 char *str
, *ring0_addr_str
;
943 unsigned int linknumber
= 0;
944 int member_count
= 0;
945 icmap_iter_t iter
, member_iter
;
946 const char *iter_key
;
947 const char *member_iter_key
;
948 char linknumber_key
[ICMAP_KEYNAME_MAXLEN
];
949 char tmp_key
[ICMAP_KEYNAME_MAXLEN
];
953 char *cluster_name
= NULL
;
960 memset (totem_config
, 0, sizeof (struct totem_config
));
961 totem_config
->interfaces
= malloc (sizeof (struct totem_interface
) * INTERFACE_MAX
);
962 if (totem_config
->interfaces
== 0) {
963 *error_string
= "Out of memory trying to allocate ethernet interface storage area";
967 memset (totem_config
->interfaces
, 0,
968 sizeof (struct totem_interface
) * INTERFACE_MAX
);
970 strcpy (totem_config
->link_mode
, "passive");
972 icmap_get_uint32("totem.version", (uint32_t *)&totem_config
->version
);
974 if (totem_get_crypto(totem_config
) != 0) {
975 *error_string
= "crypto_cipher requires crypto_hash with value other than none";
979 if (icmap_get_string("totem.link_mode", &str
) == CS_OK
) {
980 if (strlen(str
) >= TOTEM_LINK_MODE_BYTES
) {
981 *error_string
= "totem.link_mode is too long";
986 strcpy (totem_config
->link_mode
, str
);
990 icmap_get_uint32("totem.nodeid", &totem_config
->node_id
);
992 totem_config
->clear_node_high_bit
= 0;
993 if (icmap_get_string("totem.clear_node_high_bit", &str
) == CS_OK
) {
994 if (strcmp (str
, "yes") == 0) {
995 totem_config
->clear_node_high_bit
= 1;
1000 icmap_get_uint32("totem.threads", &totem_config
->threads
);
1002 icmap_get_uint32("totem.netmtu", &totem_config
->net_mtu
);
1004 if (icmap_get_string("totem.cluster_name", &cluster_name
) != CS_OK
) {
1005 cluster_name
= NULL
;
1008 totem_config
->ip_version
= totem_config_get_ip_version();
1010 if (icmap_get_string("totem.interface.0.bindnetaddr", &str
) != CS_OK
) {
1012 * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
1014 config_convert_nodelist_to_interface(totem_config
);
1016 if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str
) == CS_OK
) {
1018 * Both bindnetaddr and ring0_addr are set.
1019 * Log warning information, and use nodelist instead
1021 *warnings
|= TOTEM_CONFIG_BINDNETADDR_NODELIST_SET
;
1023 config_convert_nodelist_to_interface(totem_config
);
1025 free(ring0_addr_str
);
1032 * Broadcast option is global but set in interface section,
1033 * so reset before processing interfaces.
1035 totem_config
->broadcast_use
= 0;
1037 iter
= icmap_iter_init("totem.interface.");
1038 while ((iter_key
= icmap_iter_next(iter
, NULL
, NULL
)) != NULL
) {
1039 res
= sscanf(iter_key
, "totem.interface.%[^.].%s", linknumber_key
, tmp_key
);
1044 if (strcmp(tmp_key
, "bindnetaddr") != 0) {
1050 linknumber
= atoi(linknumber_key
);
1052 if (linknumber
>= INTERFACE_MAX
) {
1055 snprintf (error_string_response
, sizeof(error_string_response
),
1056 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1057 linknumber
, INTERFACE_MAX
- 1);
1059 *error_string
= error_string_response
;
1064 * Get the bind net address
1066 if (icmap_get_string(iter_key
, &str
) == CS_OK
) {
1067 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].bindnet
, str
,
1068 totem_config
->ip_version
);
1073 * Get interface multicast address
1075 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastaddr", linknumber
);
1076 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1077 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].mcast_addr
, str
, totem_config
->ip_version
);
1081 * User not specified address -> autogenerate one from cluster_name key
1082 * (if available). Return code is intentionally ignored, because
1083 * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
1084 * checked later anyway.
1086 (void)get_cluster_mcast_addr (cluster_name
,
1088 totem_config
->ip_version
,
1089 &totem_config
->interfaces
[linknumber
].mcast_addr
);
1092 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.broadcast", linknumber
);
1093 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1094 if (strcmp (str
, "yes") == 0) {
1095 totem_config
->broadcast_use
= 1;
1103 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastport", linknumber
);
1104 if (icmap_get_uint16(tmp_key
, &totem_config
->interfaces
[linknumber
].ip_port
) != CS_OK
) {
1105 if (totem_config
->broadcast_use
) {
1106 totem_config
->interfaces
[linknumber
].ip_port
= DEFAULT_PORT
+ (2 * linknumber
);
1108 totem_config
->interfaces
[linknumber
].ip_port
= DEFAULT_PORT
;
1115 totem_config
->interfaces
[linknumber
].ttl
= 1;
1117 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.ttl", linknumber
);
1119 if (icmap_get_uint8(tmp_key
, &u8
) == CS_OK
) {
1120 totem_config
->interfaces
[linknumber
].ttl
= u8
;
1124 * Get the knet link params
1126 totem_config
->interfaces
[linknumber
].knet_link_priority
= 1;
1127 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_link_priority", linknumber
);
1129 if (icmap_get_uint8(tmp_key
, &u8
) == CS_OK
) {
1130 totem_config
->interfaces
[linknumber
].knet_link_priority
= u8
;
1133 totem_config
->interfaces
[linknumber
].knet_ping_interval
= KNET_PING_INTERVAL
;
1134 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_interval", linknumber
);
1135 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1136 totem_config
->interfaces
[linknumber
].knet_ping_interval
= u32
;
1138 totem_config
->interfaces
[linknumber
].knet_ping_timeout
= KNET_PING_TIMEOUT
;
1139 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_timeout", linknumber
);
1140 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1141 totem_config
->interfaces
[linknumber
].knet_ping_timeout
= u32
;
1143 totem_config
->interfaces
[linknumber
].knet_ping_precision
= KNET_PING_PRECISION
;
1144 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_ping_precision", linknumber
);
1145 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1146 totem_config
->interfaces
[linknumber
].knet_ping_precision
= u32
;
1148 totem_config
->interfaces
[linknumber
].knet_pong_count
= KNET_PONG_COUNT
;
1149 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_pong_count", linknumber
);
1150 if (icmap_get_uint32(tmp_key
, &u32
) == CS_OK
) {
1151 totem_config
->interfaces
[linknumber
].knet_pong_count
= u32
;
1154 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_DEFAULT_TRANSPORT
;
1155 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.knet_transport", linknumber
);
1156 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1157 if (strcmp(str
, "sctp") == 0) {
1158 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_TRANSPORT_SCTP
;
1160 else if (strcmp(str
, "udp") == 0) {
1161 totem_config
->interfaces
[linknumber
].knet_transport
= KNET_TRANSPORT_UDP
;
1164 *error_string
= "Unrecognised knet_transport. expected 'udp' or 'sctp'";
1169 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.member.", linknumber
);
1170 member_iter
= icmap_iter_init(tmp_key
);
1171 while ((member_iter_key
= icmap_iter_next(member_iter
, NULL
, NULL
)) != NULL
) {
1172 if (member_count
== 0) {
1173 if (icmap_get_string("nodelist.node.0.ring0_addr", &str
) == CS_OK
) {
1175 *warnings
|= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
;
1178 *warnings
|= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
;
1182 if (icmap_get_string(member_iter_key
, &str
) == CS_OK
) {
1183 res
= totemip_parse (&totem_config
->interfaces
[linknumber
].member_list
[member_count
++],
1184 str
, totem_config
->ip_version
);
1187 icmap_iter_finalize(member_iter
);
1189 totem_config
->interfaces
[linknumber
].member_count
= member_count
;
1190 totem_config
->interface_count
++;
1192 icmap_iter_finalize(iter
);
1195 * Use broadcast is global, so if set, make sure to fill mcast addr correctly
1197 if (totem_config
->broadcast_use
) {
1198 for (linknumber
= 0; linknumber
< totem_config
->interface_count
; linknumber
++) {
1199 totemip_parse (&totem_config
->interfaces
[linknumber
].mcast_addr
,
1200 "255.255.255.255", 0);
1205 * Store automatically generated items back to icmap
1207 for (i
= 0; i
< totem_config
->interface_count
; i
++) {
1208 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastaddr", i
);
1209 if (icmap_get_string(tmp_key
, &str
) == CS_OK
) {
1212 str
= (char *)totemip_print(&totem_config
->interfaces
[i
].mcast_addr
);
1213 icmap_set_string(tmp_key
, str
);
1216 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "totem.interface.%u.mcastport", i
);
1217 if (icmap_get_uint16(tmp_key
, &u16
) != CS_OK
) {
1218 icmap_set_uint16(tmp_key
, totem_config
->interfaces
[i
].ip_port
);
1222 totem_config
->transport_number
= TOTEM_TRANSPORT_KNET
;
1223 if (icmap_get_string("totem.transport", &str
) == CS_OK
) {
1224 if (strcmp (str
, "udpu") == 0) {
1225 totem_config
->transport_number
= TOTEM_TRANSPORT_UDPU
;
1228 if (strcmp (str
, "udp") == 0) {
1229 totem_config
->transport_number
= TOTEM_TRANSPORT_UDP
;
1232 if (strcmp (str
, "knet") == 0) {
1233 totem_config
->transport_number
= TOTEM_TRANSPORT_KNET
;
1242 * Check existence of nodelist
1244 if (icmap_get_string("nodelist.node.0.ring0_addr", &str
) == CS_OK
) {
1249 local_node_pos
= find_local_node_in_nodelist(totem_config
);
1250 if (local_node_pos
!= -1) {
1251 icmap_set_uint32("nodelist.local_node_pos", local_node_pos
);
1253 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.nodeid", local_node_pos
);
1255 nodeid_set
= (totem_config
->node_id
!= 0);
1256 if (icmap_get_uint32(tmp_key
, &totem_config
->node_id
) == CS_OK
&& nodeid_set
) {
1257 *warnings
|= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
;
1261 * Make localnode ring0_addr read only, so we can be sure that local
1262 * node never changes. If rebinding to other IP would be in future
1263 * supported, this must be changed and handled properly!
1265 snprintf(tmp_key
, ICMAP_KEYNAME_MAXLEN
, "nodelist.node.%u.ring0_addr", local_node_pos
);
1266 icmap_set_ro_access(tmp_key
, 0, 1);
1267 icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
1270 put_nodelist_members_to_config(totem_config
, 0);
1274 * Get things that might change in the future (and can depend on totem_config->interfaces);
1276 totem_volatile_config_read(totem_config
, NULL
);
1278 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1280 add_totem_config_notification(totem_config
);
1286 int totem_config_validate (
1287 struct totem_config
*totem_config
,
1288 const char **error_string
)
1290 static char local_error_reason
[512];
1291 char parse_error
[512];
1292 const char *error_reason
= local_error_reason
;
1294 unsigned int interface_max
= INTERFACE_MAX
;
1295 unsigned int port1
, port2
;
1297 if (totem_config
->interface_count
== 0) {
1298 error_reason
= "No interfaces defined";
1302 for (i
= 0; i
< totem_config
->interface_count
; i
++) {
1304 * Some error checking of parsed data to make sure its valid
1307 struct totem_ip_address null_addr
;
1308 memset (&null_addr
, 0, sizeof (struct totem_ip_address
));
1310 if ((totem_config
->transport_number
== 0) &&
1311 memcmp (&totem_config
->interfaces
[i
].mcast_addr
, &null_addr
,
1312 sizeof (struct totem_ip_address
)) == 0) {
1313 error_reason
= "No multicast address specified";
1317 if (totem_config
->interfaces
[i
].ip_port
== 0) {
1318 error_reason
= "No multicast port specified";
1322 if (totem_config
->interfaces
[i
].ttl
> 255) {
1323 error_reason
= "Invalid TTL (should be 0..255)";
1326 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_UDP
&&
1327 totem_config
->interfaces
[i
].ttl
!= 1) {
1328 error_reason
= "Can only set ttl on multicast transport types";
1331 if (totem_config
->interfaces
[i
].knet_link_priority
> 255) {
1332 error_reason
= "Invalid link priority (should be 0..255)";
1335 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
&&
1336 totem_config
->interfaces
[i
].knet_link_priority
!= 1) {
1337 error_reason
= "Can only set link priority on knet transport type";
1341 if (totem_config
->interfaces
[i
].mcast_addr
.family
== AF_INET6
&&
1342 totem_config
->node_id
== 0) {
1344 error_reason
= "An IPV6 network requires that a node ID be specified.";
1348 if (totem_config
->broadcast_use
== 0 && totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1349 if (totem_config
->interfaces
[i
].mcast_addr
.family
!= totem_config
->interfaces
[i
].bindnet
.family
) {
1350 error_reason
= "Multicast address family does not match bind address family";
1354 if (totemip_is_mcast (&totem_config
->interfaces
[i
].mcast_addr
) != 0) {
1355 error_reason
= "mcastaddr is not a correct multicast address.";
1360 if (totem_config
->interfaces
[0].bindnet
.family
!= totem_config
->interfaces
[i
].bindnet
.family
) {
1361 error_reason
= "Not all bind address belong to the same IP family";
1366 * Ensure mcast address/port differs
1368 if (totem_config
->transport_number
== TOTEM_TRANSPORT_UDP
) {
1369 for (j
= i
+ 1; j
< totem_config
->interface_count
; j
++) {
1370 port1
= totem_config
->interfaces
[i
].ip_port
;
1371 port2
= totem_config
->interfaces
[j
].ip_port
;
1372 if (totemip_equal(&totem_config
->interfaces
[i
].mcast_addr
,
1373 &totem_config
->interfaces
[j
].mcast_addr
) &&
1374 (((port1
> port2
? port1
: port2
) - (port1
< port2
? port1
: port2
)) <= 1)) {
1375 error_reason
= "Interfaces multicast address/port pair must differ";
1382 if (totem_config
->version
!= 2) {
1383 error_reason
= "This totem parser can only parse version 2 configurations.";
1387 if (totem_volatile_config_validate(totem_config
, error_string
) == -1) {
1391 if (check_for_duplicate_nodeids(totem_config
, error_string
) == -1) {
1396 * KNET Link values validation
1398 if (strcmp (totem_config
->link_mode
, "active") &&
1399 strcmp (totem_config
->link_mode
, "rr") &&
1400 strcmp (totem_config
->link_mode
, "passive")) {
1401 snprintf (local_error_reason
, sizeof(local_error_reason
),
1402 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config
->link_mode
);
1406 /* Only Knet does multiple interfaces */
1407 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
) {
1411 if (interface_max
< totem_config
->interface_count
) {
1412 snprintf (parse_error
, sizeof(parse_error
),
1413 "%d is too many configured interfaces for non-Knet transport.",
1414 totem_config
->interface_count
);
1415 error_reason
= parse_error
;
1419 /* Only knet allows crypto */
1420 if (totem_config
->transport_number
!= TOTEM_TRANSPORT_KNET
) {
1421 if ((strcmp(totem_config
->crypto_cipher_type
, "none") != 0) ||
1422 (strcmp(totem_config
->crypto_hash_type
, "none") != 0)) {
1424 snprintf (parse_error
, sizeof(parse_error
),
1425 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
1426 error_reason
= parse_error
;
1431 if (totem_config
->net_mtu
== 0) {
1432 if (totem_config
->transport_number
== TOTEM_TRANSPORT_KNET
) {
1433 totem_config
->net_mtu
= KNET_MAX_PACKET_SIZE
;
1436 totem_config
->net_mtu
= 1500;
1443 snprintf (error_string_response
, sizeof(error_string_response
),
1444 "parse error in config: %s\n", error_reason
);
1445 *error_string
= error_string_response
;
1450 static int read_keyfile (
1451 const char *key_location
,
1452 struct totem_config
*totem_config
,
1453 const char **error_string
)
1458 char error_str
[100];
1459 const char *error_ptr
;
1461 fd
= open (key_location
, O_RDONLY
);
1463 error_ptr
= qb_strerror_r(errno
, error_str
, sizeof(error_str
));
1464 snprintf (error_string_response
, sizeof(error_string_response
),
1465 "Could not open %s: %s\n",
1466 key_location
, error_ptr
);
1470 res
= read (fd
, totem_config
->private_key
, TOTEM_PRIVATE_KEY_LEN_MAX
);
1471 saved_errno
= errno
;
1475 error_ptr
= qb_strerror_r (saved_errno
, error_str
, sizeof(error_str
));
1476 snprintf (error_string_response
, sizeof(error_string_response
),
1477 "Could not read %s: %s\n",
1478 key_location
, error_ptr
);
1482 if (res
< TOTEM_PRIVATE_KEY_LEN_MIN
) {
1483 snprintf (error_string_response
, sizeof(error_string_response
),
1484 "Could only read %d bits of minimum %u bits from %s.\n",
1485 res
* 8, TOTEM_PRIVATE_KEY_LEN_MIN
* 8, key_location
);
1489 totem_config
->private_key_len
= res
;
1494 *error_string
= error_string_response
;
1498 int totem_config_keyread (
1499 struct totem_config
*totem_config
,
1500 const char **error_string
)
1503 char *key_location
= NULL
;
1507 memset (totem_config
->private_key
, 0, sizeof(totem_config
->private_key
));
1508 totem_config
->private_key_len
= 0;
1510 if (strcmp(totem_config
->crypto_cipher_type
, "none") == 0 &&
1511 strcmp(totem_config
->crypto_hash_type
, "none") == 0) {
1515 /* cmap may store the location of the key file */
1516 if (icmap_get_string("totem.keyfile", &key_location
) == CS_OK
) {
1517 res
= read_keyfile(key_location
, totem_config
, error_string
);
1523 } else { /* Or the key itself may be in the cmap */
1524 if (icmap_get("totem.key", NULL
, &key_len
, NULL
) == CS_OK
) {
1525 if (key_len
> sizeof(totem_config
->private_key
)) {
1526 sprintf(error_string_response
, "key is too long");
1529 if (key_len
< TOTEM_PRIVATE_KEY_LEN_MIN
) {
1530 sprintf(error_string_response
, "key is too short");
1533 if (icmap_get("totem.key", totem_config
->private_key
, &key_len
, NULL
) == CS_OK
) {
1534 totem_config
->private_key_len
= key_len
;
1537 sprintf(error_string_response
, "can't load private key");
1543 /* In desperation we read the default filename */
1545 const char *filename
= getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
1547 filename
= COROSYSCONFDIR
"/authkey";
1548 res
= read_keyfile(filename
, totem_config
, error_string
);
1557 *error_string
= error_string_response
;
1562 static void debug_dump_totem_config(const struct totem_config
*totem_config
)
1565 log_printf(LOGSYS_LEVEL_DEBUG
, "Token Timeout (%d ms) retransmit timeout (%d ms)",
1566 totem_config
->token_timeout
, totem_config
->token_retransmit_timeout
);
1567 log_printf(LOGSYS_LEVEL_DEBUG
, "token hold (%d ms) retransmits before loss (%d retrans)",
1568 totem_config
->token_hold_timeout
, totem_config
->token_retransmits_before_loss_const
);
1569 log_printf(LOGSYS_LEVEL_DEBUG
, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
1570 totem_config
->join_timeout
, totem_config
->send_join_timeout
, totem_config
->consensus_timeout
,
1571 totem_config
->merge_timeout
);
1572 log_printf(LOGSYS_LEVEL_DEBUG
, "downcheck (%d ms) fail to recv const (%d msgs)",
1573 totem_config
->downcheck_timeout
, totem_config
->fail_to_recv_const
);
1574 log_printf(LOGSYS_LEVEL_DEBUG
,
1575 "seqno unchanged const (%d rotations) Maximum network MTU %d",
1576 totem_config
->seqno_unchanged_const
, totem_config
->net_mtu
);
1577 log_printf(LOGSYS_LEVEL_DEBUG
,
1578 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
1579 totem_config
->window_size
, totem_config
->max_messages
);
1580 log_printf(LOGSYS_LEVEL_DEBUG
, "missed count const (%d messages)", totem_config
->miss_count_const
);
1581 log_printf(LOGSYS_LEVEL_DEBUG
, "heartbeat_failures_allowed (%d)",
1582 totem_config
->heartbeat_failures_allowed
);
1583 log_printf(LOGSYS_LEVEL_DEBUG
, "max_network_delay (%d ms)", totem_config
->max_network_delay
);
1586 static void totem_change_notify(
1588 const char *key_name
,
1589 struct icmap_notify_value new_val
,
1590 struct icmap_notify_value old_val
,
1593 struct totem_config
*totem_config
= (struct totem_config
*)user_data
;
1596 const char *deleted_key
= NULL
;
1597 const char *error_string
;
1600 * If a full reload is in progress then don't do anything until it's done and
1601 * can reconfigure it all atomically
1603 if (icmap_get_uint8("config.reload_in_progress", &reloading
) == CS_OK
&& reloading
)
1606 param
= totem_get_param_by_name((struct totem_config
*)user_data
, key_name
);
1608 * Process change only if changed key is found in totem_config (-> param is not NULL)
1609 * or for special key token_coefficient. token_coefficient key is not stored in
1610 * totem_config, but it is used for computation of token timeout.
1612 if (!param
&& strcmp(key_name
, "totem.token_coefficient") != 0)
1616 * Values other than UINT32 are not supported, or needed (yet)
1619 case ICMAP_TRACK_DELETE
:
1620 deleted_key
= key_name
;
1622 case ICMAP_TRACK_ADD
:
1623 case ICMAP_TRACK_MODIFY
:
1630 totem_volatile_config_read (totem_config
, deleted_key
);
1631 log_printf(LOGSYS_LEVEL_DEBUG
, "Totem related config key changed. Dumping actual totem config.");
1632 debug_dump_totem_config(totem_config
);
1633 if (totem_volatile_config_validate(totem_config
, &error_string
) == -1) {
1634 log_printf (LOGSYS_LEVEL_ERROR
, "%s", error_string
);
1636 * TODO: Consider corosync exit and/or load defaults for volatile
1637 * values. For now, log error seems to be enough
1642 static void totem_reload_notify(
1644 const char *key_name
,
1645 struct icmap_notify_value new_val
,
1646 struct icmap_notify_value old_val
,
1649 struct totem_config
*totem_config
= (struct totem_config
*)user_data
;
1650 uint32_t local_node_pos
;
1651 const char *error_string
;
1653 /* Reload has completed */
1654 if (*(uint8_t *)new_val
.data
== 0) {
1655 put_nodelist_members_to_config (totem_config
, 1);
1656 totem_volatile_config_read (totem_config
, NULL
);
1657 log_printf(LOGSYS_LEVEL_DEBUG
, "Configuration reloaded. Dumping actual totem config.");
1658 debug_dump_totem_config(totem_config
);
1659 if (totem_volatile_config_validate(totem_config
, &error_string
) == -1) {
1660 log_printf (LOGSYS_LEVEL_ERROR
, "%s", error_string
);
1662 * TODO: Consider corosync exit and/or load defaults for volatile
1663 * values. For now, log error seems to be enough
1667 /* Reinstate the local_node_pos */
1668 local_node_pos
= find_local_node_in_nodelist(totem_config
);
1669 if (local_node_pos
!= -1) {
1670 icmap_set_uint32("nodelist.local_node_pos", local_node_pos
);
1673 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1675 icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
1679 static void add_totem_config_notification(struct totem_config
*totem_config
)
1681 icmap_track_t icmap_track
;
1683 icmap_track_add("totem.",
1684 ICMAP_TRACK_ADD
| ICMAP_TRACK_DELETE
| ICMAP_TRACK_MODIFY
| ICMAP_TRACK_PREFIX
,
1685 totem_change_notify
,
1689 icmap_track_add("config.reload_in_progress",
1690 ICMAP_TRACK_ADD
| ICMAP_TRACK_MODIFY
,
1691 totem_reload_notify
,
1695 icmap_track_add("nodelist.node.",
1696 ICMAP_TRACK_ADD
| ICMAP_TRACK_DELETE
| ICMAP_TRACK_MODIFY
| ICMAP_TRACK_PREFIX
,
1697 nodelist_dynamic_notify
,
1698 (void *)totem_config
,