]> git.proxmox.com Git - mirror_corosync.git/blob - exec/totemconfig.c
totemconfig: remove duplicate aes256 test
[mirror_corosync.git] / exec / totemconfig.c
1 /*
2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
3 * Copyright (c) 2006-2013 Red Hat, Inc.
4 *
5 * All rights reserved.
6 *
7 * Author: Steven Dake (sdake@redhat.com)
8 * Jan Friesse (jfriesse@redhat.com)
9 *
10 * This software licensed under BSD license, the text of which follows:
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
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.
23 *
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.
35 */
36
37 #include <config.h>
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <errno.h>
43 #include <unistd.h>
44 #include <sys/socket.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <fcntl.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/param.h>
51
52 #include <corosync/swab.h>
53 #include <qb/qblist.h>
54 #include <qb/qbdefs.h>
55 #include <libknet.h>
56 #include <corosync/totem/totem.h>
57 #include <corosync/config.h>
58 #include <corosync/logsys.h>
59 #include <corosync/icmap.h>
60
61 #include "util.h"
62 #include "totemconfig.h"
63
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
77
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
85
86 #define DEFAULT_PORT 5405
87
88 static char error_string_response[512];
89
90 static void add_totem_config_notification(struct totem_config *totem_config);
91
92 static void *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
93 {
94 if (strcmp(param_name, "totem.token") == 0)
95 return &totem_config->token_timeout;
96 if (strcmp(param_name, "totem.token_retransmit") == 0)
97 return &totem_config->token_retransmit_timeout;
98 if (strcmp(param_name, "totem.hold") == 0)
99 return &totem_config->token_hold_timeout;
100 if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
101 return &totem_config->token_retransmits_before_loss_const;
102 if (strcmp(param_name, "totem.join") == 0)
103 return &totem_config->join_timeout;
104 if (strcmp(param_name, "totem.send_join") == 0)
105 return &totem_config->send_join_timeout;
106 if (strcmp(param_name, "totem.consensus") == 0)
107 return &totem_config->consensus_timeout;
108 if (strcmp(param_name, "totem.merge") == 0)
109 return &totem_config->merge_timeout;
110 if (strcmp(param_name, "totem.downcheck") == 0)
111 return &totem_config->downcheck_timeout;
112 if (strcmp(param_name, "totem.fail_recv_const") == 0)
113 return &totem_config->fail_to_recv_const;
114 if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
115 return &totem_config->seqno_unchanged_const;
116 if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
117 return &totem_config->heartbeat_failures_allowed;
118 if (strcmp(param_name, "totem.max_network_delay") == 0)
119 return &totem_config->max_network_delay;
120 if (strcmp(param_name, "totem.window_size") == 0)
121 return &totem_config->window_size;
122 if (strcmp(param_name, "totem.max_messages") == 0)
123 return &totem_config->max_messages;
124 if (strcmp(param_name, "totem.miss_count_const") == 0)
125 return &totem_config->miss_count_const;
126 if (strcmp(param_name, "totem.knet_pmtud_interval") == 0)
127 return &totem_config->knet_pmtud_interval;
128 if (strcmp(param_name, "totem.knet_compression_threshold") == 0)
129 return &totem_config->knet_compression_threshold;
130 if (strcmp(param_name, "totem.knet_compression_level") == 0)
131 return &totem_config->knet_compression_level;
132 if (strcmp(param_name, "totem.knet_compression_model") == 0)
133 return &totem_config->knet_compression_model;
134
135 return NULL;
136 }
137
138 /*
139 * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
140 * and readed value is zero, default value is used and stored into totem_config.
141 */
142 static void totem_volatile_config_set_uint32_value (struct totem_config *totem_config,
143 const char *key_name, const char *deleted_key, unsigned int default_value,
144 int allow_zero_value)
145 {
146 char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
147
148 if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
149 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
150 (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
151 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
152 }
153
154 /*
155 * Store totem_config value to cmap runtime section
156 */
157 if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
158 /*
159 * This shouldn't happen
160 */
161 return ;
162 }
163
164 strcpy(runtime_key_name, "runtime.config.");
165 strcat(runtime_key_name, key_name);
166
167 icmap_set_uint32(runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
168 }
169
170 static void totem_volatile_config_set_int32_value (struct totem_config *totem_config,
171 const char *key_name, const char *deleted_key, int default_value,
172 int allow_zero_value)
173 {
174 char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
175
176 if (icmap_get_int32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
177 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
178 (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
179 *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
180 }
181
182 /*
183 * Store totem_config value to cmap runtime section
184 */
185 if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
186 /*
187 * This shouldn't happen
188 */
189 return ;
190 }
191
192 strcpy(runtime_key_name, "runtime.config.");
193 strcat(runtime_key_name, key_name);
194
195 icmap_set_int32(runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
196 }
197
198 static void totem_volatile_config_set_string_value (struct totem_config *totem_config,
199 const char *key_name, const char *deleted_key, const char *default_value)
200 {
201 char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
202 void **config_value;
203 void *old_config_ptr;
204
205 config_value = totem_get_param_by_name(totem_config, key_name);
206 old_config_ptr = *config_value;
207 if (icmap_get_string(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
208 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
209
210 /* Need to strdup() here so that the free() below works for a default and a configured value */
211 *config_value = strdup(default_value);
212 }
213 free(old_config_ptr);
214
215 /*
216 * Store totem_config value to cmap runtime section
217 */
218 if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
219 /*
220 * This shouldn't happen
221 */
222 return ;
223 }
224
225 strcpy(runtime_key_name, "runtime.config.");
226 strcat(runtime_key_name, key_name);
227
228 icmap_set_string(runtime_key_name, (char *)*config_value);
229 }
230
231
232 /*
233 * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
234 * default value is stored. deleted_key is name of key beeing processed by delete operation
235 * from cmap. It is considered as non existing even if it can be read. Can be NULL.
236 */
237 static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
238 {
239 uint32_t u32;
240
241 totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
242 TOKEN_RETRANSMITS_BEFORE_LOSS_CONST, 0);
243
244 totem_volatile_config_set_uint32_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
245
246 if (totem_config->interfaces[0].member_count > 2) {
247 u32 = TOKEN_COEFFICIENT;
248 icmap_get_uint32("totem.token_coefficient", &u32);
249 totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
250
251 /*
252 * Store totem_config value to cmap runtime section
253 */
254 icmap_set_uint32("runtime.config.totem.token", totem_config->token_timeout);
255 }
256
257 totem_volatile_config_set_uint32_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
258
259 totem_volatile_config_set_uint32_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
260
261 totem_volatile_config_set_uint32_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
262
263 totem_volatile_config_set_uint32_value(totem_config, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
264 totem_volatile_config_set_uint32_value(totem_config, "totem.knet_pmtud_interval", deleted_key, KNET_PMTUD_INTERVAL, 0);
265
266 totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmit", deleted_key,
267 (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
268
269 totem_volatile_config_set_uint32_value(totem_config, "totem.hold", deleted_key,
270 (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
271
272 totem_volatile_config_set_uint32_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
273
274 totem_volatile_config_set_uint32_value(totem_config, "totem.consensus", deleted_key,
275 (int)(float)(1.2 * totem_config->token_timeout), 0);
276
277 totem_volatile_config_set_uint32_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
278
279 totem_volatile_config_set_uint32_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
280
281 totem_volatile_config_set_uint32_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
282
283 totem_volatile_config_set_uint32_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
284 SEQNO_UNCHANGED_CONST, 0);
285
286 totem_volatile_config_set_uint32_value(totem_config, "totem.send_join", deleted_key, 0, 1);
287
288 totem_volatile_config_set_uint32_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
289
290 totem_volatile_config_set_uint32_value(totem_config, "totem.knet_compression_threshold", deleted_key, 0, 1);
291
292 totem_volatile_config_set_int32_value(totem_config, "totem.knet_compression_level", deleted_key, 0, 1);
293
294 totem_volatile_config_set_string_value(totem_config, "totem.knet_compression_model", deleted_key, "none");
295
296
297 }
298
299 static int totem_volatile_config_validate (
300 struct totem_config *totem_config,
301 const char **error_string)
302 {
303 static char local_error_reason[512];
304 const char *error_reason = local_error_reason;
305
306 if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
307 snprintf (local_error_reason, sizeof(local_error_reason),
308 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
309 totem_config->max_network_delay, MINIMUM_TIMEOUT);
310 goto parse_error;
311 }
312
313 if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
314 snprintf (local_error_reason, sizeof(local_error_reason),
315 "The token timeout parameter (%d ms) may not be less than (%d ms).",
316 totem_config->token_timeout, MINIMUM_TIMEOUT);
317 goto parse_error;
318 }
319
320 if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
321 snprintf (local_error_reason, sizeof(local_error_reason),
322 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
323 totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT);
324 goto parse_error;
325 }
326
327 if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) {
328 snprintf (local_error_reason, sizeof(local_error_reason),
329 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
330 totem_config->token_hold_timeout, MINIMUM_TIMEOUT);
331 goto parse_error;
332 }
333
334 if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
335 snprintf (local_error_reason, sizeof(local_error_reason),
336 "The join timeout parameter (%d ms) may not be less than (%d ms).",
337 totem_config->join_timeout, MINIMUM_TIMEOUT);
338 goto parse_error;
339 }
340
341 if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
342 snprintf (local_error_reason, sizeof(local_error_reason),
343 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
344 totem_config->consensus_timeout, MINIMUM_TIMEOUT);
345 goto parse_error;
346 }
347
348 if (totem_config->consensus_timeout < totem_config->join_timeout) {
349 snprintf (local_error_reason, sizeof(local_error_reason),
350 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
351 totem_config->consensus_timeout, totem_config->join_timeout);
352 goto parse_error;
353 }
354
355 if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
356 snprintf (local_error_reason, sizeof(local_error_reason),
357 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
358 totem_config->merge_timeout, MINIMUM_TIMEOUT);
359 goto parse_error;
360 }
361
362 if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
363 snprintf (local_error_reason, sizeof(local_error_reason),
364 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
365 totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
366 goto parse_error;
367 }
368
369 return 0;
370
371 parse_error:
372 snprintf (error_string_response, sizeof(error_string_response),
373 "parse error in config: %s\n", error_reason);
374 *error_string = error_string_response;
375 return (-1);
376
377 }
378
379 static int totem_get_crypto(struct totem_config *totem_config)
380 {
381 char *str;
382 const char *tmp_cipher;
383 const char *tmp_hash;
384
385 tmp_hash = "none";
386 tmp_cipher = "none";
387
388 if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
389 if (strcmp(str, "none") == 0) {
390 tmp_cipher = "none";
391 }
392 if (strcmp(str, "aes256") == 0) {
393 tmp_cipher = "aes256";
394 }
395 if (strcmp(str, "aes192") == 0) {
396 tmp_cipher = "aes192";
397 }
398 if (strcmp(str, "aes128") == 0) {
399 tmp_cipher = "aes128";
400 }
401 if (strcmp(str, "3des") == 0) {
402 tmp_cipher = "3des";
403 }
404 free(str);
405 }
406
407 if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
408 if (strcmp(str, "none") == 0) {
409 tmp_hash = "none";
410 }
411 if (strcmp(str, "md5") == 0) {
412 tmp_hash = "md5";
413 }
414 if (strcmp(str, "sha1") == 0) {
415 tmp_hash = "sha1";
416 }
417 if (strcmp(str, "sha256") == 0) {
418 tmp_hash = "sha256";
419 }
420 if (strcmp(str, "sha384") == 0) {
421 tmp_hash = "sha384";
422 }
423 if (strcmp(str, "sha512") == 0) {
424 tmp_hash = "sha512";
425 }
426 free(str);
427 }
428
429 if ((strcmp(tmp_cipher, "none") != 0) &&
430 (strcmp(tmp_hash, "none") == 0)) {
431 return -1;
432 }
433
434 free(totem_config->crypto_cipher_type);
435 free(totem_config->crypto_hash_type);
436
437 totem_config->crypto_cipher_type = strdup(tmp_cipher);
438 totem_config->crypto_hash_type = strdup(tmp_hash);
439
440 return 0;
441 }
442
443 static int totem_config_get_ip_version(void)
444 {
445 int res;
446 char *str;
447
448 res = AF_INET;
449 if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
450 if (strcmp(str, "ipv4") == 0) {
451 res = AF_INET;
452 }
453 if (strcmp(str, "ipv6") == 0) {
454 res = AF_INET6;
455 }
456 free(str);
457 }
458
459 return (res);
460 }
461
462 static uint16_t generate_cluster_id (const char *cluster_name)
463 {
464 int i;
465 int value = 0;
466
467 for (i = 0; i < strlen(cluster_name); i++) {
468 value <<= 1;
469 value += cluster_name[i];
470 }
471
472 return (value & 0xFFFF);
473 }
474
475 static int get_cluster_mcast_addr (
476 const char *cluster_name,
477 unsigned int linknumber,
478 int ip_version,
479 struct totem_ip_address *res)
480 {
481 uint16_t clusterid;
482 char addr[INET6_ADDRSTRLEN + 1];
483 int err;
484
485 if (cluster_name == NULL) {
486 return (-1);
487 }
488
489 clusterid = generate_cluster_id(cluster_name) + linknumber;
490 memset (res, 0, sizeof(*res));
491
492 switch (ip_version) {
493 case AF_INET:
494 snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
495 break;
496 case AF_INET6:
497 snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
498 break;
499 default:
500 /*
501 * Unknown family
502 */
503 return (-1);
504 }
505
506 err = totemip_parse (res, addr, ip_version);
507
508 return (err);
509 }
510
511 static unsigned int generate_nodeid_for_duplicate_test(
512 struct totem_config *totem_config,
513 char *addr)
514 {
515 unsigned int nodeid;
516 struct totem_ip_address totemip;
517
518 /* AF_INET hard-coded here because auto-generated nodeids
519 are only for IPv4 */
520 if (totemip_parse(&totemip, addr, AF_INET) != 0)
521 return -1;
522
523 memcpy (&nodeid, &totemip.addr, sizeof (unsigned int));
524
525 #if __BYTE_ORDER == __LITTLE_ENDIAN
526 nodeid = swab32 (nodeid);
527 #endif
528
529 if (totem_config->clear_node_high_bit) {
530 nodeid &= 0x7FFFFFFF;
531 }
532 return nodeid;
533 }
534
535 static int check_for_duplicate_nodeids(
536 struct totem_config *totem_config,
537 const char **error_string)
538 {
539 icmap_iter_t iter;
540 icmap_iter_t subiter;
541 const char *iter_key;
542 int res = 0;
543 int retval = 0;
544 char tmp_key[ICMAP_KEYNAME_MAXLEN];
545 char *ring0_addr=NULL;
546 char *ring0_addr1=NULL;
547 unsigned int node_pos;
548 unsigned int node_pos1;
549 unsigned int nodeid;
550 unsigned int nodeid1;
551 int autogenerated;
552
553 iter = icmap_iter_init("nodelist.node.");
554 while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
555 res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
556 if (res != 2) {
557 continue;
558 }
559
560 if (strcmp(tmp_key, "ring0_addr") != 0) {
561 continue;
562 }
563
564 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
565 autogenerated = 0;
566 if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
567
568 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
569 if (icmap_get_string(tmp_key, &ring0_addr) != CS_OK) {
570 continue;
571 }
572
573 /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
574 nodeid = generate_nodeid_for_duplicate_test(totem_config, ring0_addr);
575 if (nodeid == -1) {
576 continue;
577 }
578 autogenerated = 1;
579 }
580
581 node_pos1 = 0;
582 subiter = icmap_iter_init("nodelist.node.");
583 while (((iter_key = icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
584 res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos1, tmp_key);
585 if ((res != 2) || (node_pos1 >= node_pos)) {
586 continue;
587 }
588
589 if (strcmp(tmp_key, "ring0_addr") != 0) {
590 continue;
591 }
592
593 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
594 if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
595
596 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos1);
597 if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
598 continue;
599 }
600 nodeid1 = generate_nodeid_for_duplicate_test(totem_config, ring0_addr1);
601 if (nodeid1 == -1) {
602 continue;
603 }
604 }
605
606 if (nodeid == nodeid1) {
607 retval = -1;
608 snprintf (error_string_response, sizeof(error_string_response),
609 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
610 autogenerated?"(autogenerated from ":"",
611 autogenerated?ring0_addr:"",
612 autogenerated?")":"");
613 log_printf (LOGSYS_LEVEL_ERROR, error_string_response);
614 *error_string = error_string_response;
615 break;
616 }
617 }
618 icmap_iter_finalize(subiter);
619 }
620 icmap_iter_finalize(iter);
621 return retval;
622 }
623
624
625 static int find_local_node_in_nodelist(struct totem_config *totem_config)
626 {
627 icmap_iter_t iter;
628 const char *iter_key;
629 int res = 0;
630 unsigned int node_pos;
631 int local_node_pos = -1;
632 struct totem_ip_address bind_addr;
633 int interface_up, interface_num;
634 char tmp_key[ICMAP_KEYNAME_MAXLEN];
635 char *node_addr_str;
636 struct totem_ip_address node_addr;
637
638 res = totemip_iface_check(&totem_config->interfaces[0].bindnet,
639 &bind_addr, &interface_up, &interface_num,
640 totem_config->clear_node_high_bit);
641 if (res == -1) {
642 return (-1);
643 }
644
645 iter = icmap_iter_init("nodelist.node.");
646 while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
647 res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
648 if (res != 2) {
649 continue;
650 }
651
652 if (strcmp(tmp_key, "ring0_addr") != 0) {
653 continue;
654 }
655
656 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
657 if (icmap_get_string(tmp_key, &node_addr_str) != CS_OK) {
658 continue;
659 }
660
661 res = totemip_parse (&node_addr, node_addr_str, totem_config->ip_version);
662 free(node_addr_str);
663 if (res == -1) {
664 continue ;
665 }
666
667 if (totemip_equal(&bind_addr, &node_addr)) {
668 local_node_pos = node_pos;
669 }
670 }
671 icmap_iter_finalize(iter);
672
673 return (local_node_pos);
674 }
675
676 /*
677 * Compute difference between two set of totem interface arrays. set1 and set2
678 * are changed so for same ring, ip existing in both set1 and set2 are cleared
679 * (set to 0), and ips which are only in set1 or set2 remains untouched.
680 * totempg_node_add/remove is called.
681 */
682 static void compute_interfaces_diff(struct totem_interface *set1,
683 struct totem_interface *set2)
684 {
685 int ring_no, set1_pos, set2_pos;
686 struct totem_ip_address empty_ip_address;
687
688 memset(&empty_ip_address, 0, sizeof(empty_ip_address));
689
690 for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
691 if (!set1[ring_no].configured && !set2[ring_no].configured) {
692 continue;
693 }
694
695 for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
696 for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
697 /*
698 * For current ring_no remove all set1 items existing
699 * in set2
700 */
701 if (memcmp(&set1[ring_no].member_list[set1_pos],
702 &set2[ring_no].member_list[set2_pos],
703 sizeof(struct totem_ip_address)) == 0) {
704 memset(&set1[ring_no].member_list[set1_pos], 0,
705 sizeof(struct totem_ip_address));
706 memset(&set2[ring_no].member_list[set2_pos], 0,
707 sizeof(struct totem_ip_address));
708 }
709 }
710 }
711 }
712
713 for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
714 for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
715 /*
716 * All items which remained in set1 doesn't exists in set2 any longer so
717 * node has to be removed.
718 */
719 if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
720 log_printf(LOGSYS_LEVEL_DEBUG,
721 "removing dynamic member %s for ring %u",
722 totemip_print(&set1[ring_no].member_list[set1_pos]),
723 ring_no);
724
725 totempg_member_remove(&set1[ring_no].member_list[set1_pos], ring_no);
726 }
727 }
728 if (!set2[ring_no].configured) {
729 continue;
730 }
731 for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
732 /*
733 * All items which remained in set2 doesn't existed in set1 so this is no node
734 * and has to be added.
735 */
736 if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
737 log_printf(LOGSYS_LEVEL_DEBUG,
738 "adding dynamic member %s for ring %u",
739 totemip_print(&set2[ring_no].member_list[set2_pos]),
740 ring_no);
741
742 totempg_member_add(&set2[ring_no].member_list[set2_pos], ring_no);
743 }
744 }
745 }
746 }
747
748 /*
749 * Reconfigure links in totempg. Sets new local IP address and adds params for new links.
750 */
751 static void reconfigure_links(struct totem_config *totem_config)
752 {
753 int i;
754 char tmp_key[ICMAP_KEYNAME_MAXLEN];
755 char *addr_string;
756 struct totem_ip_address local_ip;
757 int err;
758 unsigned int local_node_pos = find_local_node_in_nodelist(totem_config);
759
760 for (i = 0; i<INTERFACE_MAX; i++) {
761 if (!totem_config->interfaces[i].configured) {
762 continue;
763 }
764
765 log_printf(LOGSYS_LEVEL_INFO, "Configuring link %d\n", i);
766
767 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring%u_addr", local_node_pos, i);
768 if (icmap_get_string(tmp_key, &addr_string) != CS_OK) {
769 continue;
770 }
771
772 err = totemip_parse(&local_ip, addr_string, AF_UNSPEC);
773 if (err != 0) {
774 continue;
775 }
776 local_ip.nodeid = totem_config->node_id;
777
778 /* In case this is a new link, fill in the defaults if there was no interface{} section for it */
779 if (!totem_config->interfaces[i].knet_link_priority)
780 totem_config->interfaces[i].knet_link_priority = 1;
781 if (!totem_config->interfaces[i].knet_ping_interval)
782 totem_config->interfaces[i].knet_ping_interval = KNET_PING_INTERVAL;
783 if (!totem_config->interfaces[i].knet_ping_timeout)
784 totem_config->interfaces[i].knet_ping_timeout = KNET_PING_TIMEOUT;
785 if (!totem_config->interfaces[i].knet_ping_precision)
786 totem_config->interfaces[i].knet_ping_precision = KNET_PING_PRECISION;
787 if (!totem_config->interfaces[i].knet_pong_count)
788 totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
789 if (!totem_config->interfaces[i].knet_transport)
790 totem_config->interfaces[i].knet_transport = KNET_TRANSPORT_UDP;
791 if (!totem_config->interfaces[i].ip_port)
792 totem_config->interfaces[i].ip_port = DEFAULT_PORT;
793
794 totempg_iface_set(&local_ip, totem_config->interfaces[i].ip_port, i);
795 }
796 }
797
798 static void put_nodelist_members_to_config(struct totem_config *totem_config, int reload)
799 {
800 icmap_iter_t iter, iter2;
801 const char *iter_key, *iter_key2;
802 int res = 0;
803 unsigned int node_pos;
804 char tmp_key[ICMAP_KEYNAME_MAXLEN];
805 char tmp_key2[ICMAP_KEYNAME_MAXLEN];
806 char *node_addr_str;
807 int member_count;
808 unsigned int linknumber = 0;
809 int i, j;
810 struct totem_interface *new_interfaces = NULL;
811
812 if (reload) {
813 /*
814 * We need to compute diff only for reload. Also for initial configuration
815 * not all totem structures are initialized so corosync will crash during
816 * member_add/remove
817 */
818 new_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
819 assert(new_interfaces != NULL);
820 }
821
822 /* Clear out nodelist so we can put the new one in if needed */
823 for (i = 0; i < INTERFACE_MAX; i++) {
824 for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
825 memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
826 }
827 totem_config->interfaces[i].member_count = 0;
828 }
829
830 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);
833 if (res != 2) {
834 continue;
835 }
836
837 if (strcmp(tmp_key, "ring0_addr") != 0) {
838 continue;
839 }
840
841 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
842 iter2 = icmap_iter_init(tmp_key);
843 while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
844 unsigned int nodeid;
845
846 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
847 if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
848 }
849
850 res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
851 if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
852 continue;
853 }
854
855 if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
856 continue;
857 }
858
859 member_count = totem_config->interfaces[linknumber].member_count;
860
861 res = totemip_parse(&totem_config->interfaces[linknumber].member_list[member_count],
862 node_addr_str, totem_config->ip_version);
863 if (res != -1) {
864 totem_config->interfaces[linknumber].member_list[member_count].nodeid = nodeid;
865 totem_config->interfaces[linknumber].member_count++;
866 }
867
868 totem_config->interfaces[linknumber].configured = 1;
869 free(node_addr_str);
870 }
871
872 icmap_iter_finalize(iter2);
873 }
874
875 icmap_iter_finalize(iter);
876
877 if (reload) {
878 log_printf(LOGSYS_LEVEL_DEBUG, "About to reconfigure links from nodelist.\n");
879 reconfigure_links(totem_config);
880
881 memcpy(new_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
882
883 compute_interfaces_diff(totem_config->orig_interfaces, new_interfaces);
884
885 free(new_interfaces);
886 }
887 }
888
889 static void nodelist_dynamic_notify(
890 int32_t event,
891 const char *key_name,
892 struct icmap_notify_value new_val,
893 struct icmap_notify_value old_val,
894 void *user_data)
895 {
896 int res;
897 unsigned int ring_no;
898 unsigned int member_no;
899 char tmp_str[ICMAP_KEYNAME_MAXLEN];
900 uint8_t reloading;
901 struct totem_config *totem_config = (struct totem_config *)user_data;
902
903 /*
904 * If a full reload is in progress then don't do anything until it's done and
905 * can reconfigure it all atomically
906 */
907 if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
908 return ;
909 }
910
911 res = sscanf(key_name, "nodelist.node.%u.ring%u%s", &member_no, &ring_no, tmp_str);
912 if (res != 3)
913 return ;
914
915 if (strcmp(tmp_str, "_addr") != 0) {
916 return;
917 }
918
919 put_nodelist_members_to_config(totem_config, 1);
920 }
921
922
923 /*
924 * Tries to find node (node_pos) in config nodelist which address matches any
925 * local interface. Address can be stored in ring0_addr or if ipaddr_key_prefix is not NULL
926 * key with prefix ipaddr_key is used (there can be multiuple of them)
927 * This function differs * from find_local_node_in_nodelist because it doesn't need bindnetaddr,
928 * but doesn't work when bind addr is network address (so IP must be exact
929 * match).
930 *
931 * Returns 1 on success (address was found, node_pos is then correctly set) or 0 on failure.
932 */
933 int totem_config_find_local_addr_in_nodelist(const char *ipaddr_key_prefix, unsigned int *node_pos)
934 {
935 struct qb_list_head addrs;
936 struct totem_ip_if_address *if_addr;
937 icmap_iter_t iter, iter2;
938 const char *iter_key, *iter_key2;
939 struct qb_list_head *list;
940 const char *ipaddr_key;
941 int ip_version;
942 struct totem_ip_address node_addr;
943 char *node_addr_str;
944 int node_found = 0;
945 int res = 0;
946 char tmp_key[ICMAP_KEYNAME_MAXLEN];
947
948 if (totemip_getifaddrs(&addrs) == -1) {
949 return 0;
950 }
951
952 ip_version = totem_config_get_ip_version();
953
954 iter = icmap_iter_init("nodelist.node.");
955
956 while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
957 res = sscanf(iter_key, "nodelist.node.%u.%s", node_pos, tmp_key);
958 if (res != 2) {
959 continue;
960 }
961
962 if (strcmp(tmp_key, "ring0_addr") != 0) {
963 continue;
964 }
965
966 if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
967 continue ;
968 }
969
970 free(node_addr_str);
971
972 /*
973 * ring0_addr found -> let's iterate thru ipaddr_key_prefix
974 */
975 snprintf(tmp_key, sizeof(tmp_key), "nodelist.node.%u.%s", *node_pos,
976 (ipaddr_key_prefix != NULL ? ipaddr_key_prefix : "ring0_addr"));
977
978 iter2 = icmap_iter_init(tmp_key);
979 while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
980 /*
981 * ring0_addr must be exact match, not prefix
982 */
983 ipaddr_key = (ipaddr_key_prefix != NULL ? iter_key2 : tmp_key);
984 if (icmap_get_string(ipaddr_key, &node_addr_str) != CS_OK) {
985 continue ;
986 }
987
988 if (totemip_parse(&node_addr, node_addr_str, ip_version) == -1) {
989 free(node_addr_str);
990 continue ;
991 }
992 free(node_addr_str);
993
994 /*
995 * Try to match ip with if_addrs
996 */
997 node_found = 0;
998 qb_list_for_each(list, &(addrs)) {
999 if_addr = qb_list_entry(list, struct totem_ip_if_address, list);
1000
1001 if (totemip_equal(&node_addr, &if_addr->ip_addr)) {
1002 node_found = 1;
1003 break;
1004 }
1005 }
1006
1007 if (node_found) {
1008 break ;
1009 }
1010 }
1011
1012 icmap_iter_finalize(iter2);
1013
1014 if (node_found) {
1015 break ;
1016 }
1017 }
1018
1019 icmap_iter_finalize(iter);
1020 totemip_freeifaddrs(&addrs);
1021
1022 return (node_found);
1023 }
1024
1025 static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
1026 {
1027 int res = 0;
1028 unsigned int node_pos;
1029 char tmp_key[ICMAP_KEYNAME_MAXLEN];
1030 char tmp_key2[ICMAP_KEYNAME_MAXLEN];
1031 char *node_addr_str;
1032 unsigned int linknumber = 0;
1033 icmap_iter_t iter;
1034 const char *iter_key;
1035
1036 if (totem_config_find_local_addr_in_nodelist(NULL, &node_pos)) {
1037 /*
1038 * We found node, so create interface section
1039 */
1040 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
1041 iter = icmap_iter_init(tmp_key);
1042 while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1043 res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1044 if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
1045 continue ;
1046 }
1047
1048 if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
1049 continue;
1050 }
1051
1052 snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
1053 icmap_set_string(tmp_key2, node_addr_str);
1054 free(node_addr_str);
1055 }
1056 icmap_iter_finalize(iter);
1057 }
1058 }
1059
1060 static int get_interface_params(struct totem_config *totem_config,
1061 const char **error_string, uint64_t *warnings,
1062 int reload)
1063 {
1064 int res = 0;
1065 unsigned int linknumber = 0;
1066 int member_count = 0;
1067 int i;
1068 icmap_iter_t iter, member_iter;
1069 const char *iter_key;
1070 const char *member_iter_key;
1071 char linknumber_key[ICMAP_KEYNAME_MAXLEN];
1072 char tmp_key[ICMAP_KEYNAME_MAXLEN];
1073 uint8_t u8;
1074 uint32_t u32;
1075 char *str;
1076 char *cluster_name = NULL;
1077
1078 if (reload) {
1079 for (i=0; i<INTERFACE_MAX; i++) {
1080 totem_config->interfaces[i].configured = 0;
1081 }
1082 }
1083 if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
1084 cluster_name = NULL;
1085 }
1086
1087 iter = icmap_iter_init("totem.interface.");
1088 while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1089 res = sscanf(iter_key, "totem.interface.%[^.].%s", linknumber_key, tmp_key);
1090 if (res != 2) {
1091 continue;
1092 }
1093
1094 if (strcmp(tmp_key, "bindnetaddr") != 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1095 continue;
1096 }
1097
1098 member_count = 0;
1099 linknumber = atoi(linknumber_key);
1100
1101 if (linknumber >= INTERFACE_MAX) {
1102 free(cluster_name);
1103
1104 snprintf (error_string_response, sizeof(error_string_response),
1105 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1106 linknumber, INTERFACE_MAX - 1);
1107
1108 *error_string = error_string_response;
1109 return -1;
1110 }
1111
1112 /* These things are only valid for the initial read */
1113 if (!reload) {
1114 /*
1115 * Get the bind net address
1116 */
1117 if (icmap_get_string(iter_key, &str) == CS_OK) {
1118 res = totemip_parse (&totem_config->interfaces[linknumber].bindnet, str,
1119 totem_config->ip_version);
1120 free(str);
1121 }
1122
1123 /*
1124 * Get interface multicast address
1125 */
1126 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", linknumber);
1127 if (icmap_get_string(tmp_key, &str) == CS_OK) {
1128 res = totemip_parse (&totem_config->interfaces[linknumber].mcast_addr, str, totem_config->ip_version);
1129 free(str);
1130 } else {
1131 /*
1132 * User not specified address -> autogenerate one from cluster_name key
1133 * (if available). Return code is intentionally ignored, because
1134 * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
1135 * checked later anyway.
1136 */
1137 (void)get_cluster_mcast_addr (cluster_name,
1138 linknumber,
1139 totem_config->ip_version,
1140 &totem_config->interfaces[linknumber].mcast_addr);
1141 }
1142
1143 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", linknumber);
1144 if (icmap_get_string(tmp_key, &str) == CS_OK) {
1145 if (strcmp (str, "yes") == 0) {
1146 totem_config->broadcast_use = 1;
1147 }
1148 free(str);
1149 }
1150 }
1151
1152 /* These things are only valid for the initial read OR a newly-defined link */
1153 if (!reload || (totem_config->interfaces[linknumber].configured == 0)) {
1154
1155 /*
1156 * Get mcast port
1157 */
1158 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", linknumber);
1159 if (icmap_get_uint16(tmp_key, &totem_config->interfaces[linknumber].ip_port) != CS_OK) {
1160 if (totem_config->broadcast_use) {
1161 totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + (2 * linknumber);
1162 } else {
1163 totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT;
1164 }
1165 }
1166
1167 /*
1168 * Get the TTL
1169 */
1170 totem_config->interfaces[linknumber].ttl = 1;
1171
1172 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", linknumber);
1173
1174 if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
1175 totem_config->interfaces[linknumber].ttl = u8;
1176 }
1177
1178 totem_config->interfaces[linknumber].knet_transport = KNET_DEFAULT_TRANSPORT;
1179 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_transport", linknumber);
1180 if (icmap_get_string(tmp_key, &str) == CS_OK) {
1181 if (strcmp(str, "sctp") == 0) {
1182 totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_SCTP;
1183 }
1184 else if (strcmp(str, "udp") == 0) {
1185 totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_UDP;
1186 }
1187 else {
1188 *error_string = "Unrecognised knet_transport. expected 'udp' or 'sctp'";
1189 return -1;
1190 }
1191 }
1192 }
1193 totem_config->interfaces[linknumber].configured = 1;
1194
1195 /*
1196 * Get the knet link params
1197 */
1198 totem_config->interfaces[linknumber].knet_link_priority = 1;
1199 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_link_priority", linknumber);
1200
1201 if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
1202 totem_config->interfaces[linknumber].knet_link_priority = u8;
1203 }
1204
1205 totem_config->interfaces[linknumber].knet_ping_interval = KNET_PING_INTERVAL;
1206 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_interval", linknumber);
1207 if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1208 totem_config->interfaces[linknumber].knet_ping_interval = u32;
1209 }
1210 totem_config->interfaces[linknumber].knet_ping_timeout = KNET_PING_TIMEOUT;
1211 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_timeout", linknumber);
1212 if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1213 totem_config->interfaces[linknumber].knet_ping_timeout = u32;
1214 }
1215 totem_config->interfaces[linknumber].knet_ping_precision = KNET_PING_PRECISION;
1216 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_precision", linknumber);
1217 if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1218 totem_config->interfaces[linknumber].knet_ping_precision = u32;
1219 }
1220 totem_config->interfaces[linknumber].knet_pong_count = KNET_PONG_COUNT;
1221 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_pong_count", linknumber);
1222 if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1223 totem_config->interfaces[linknumber].knet_pong_count = u32;
1224 }
1225
1226 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", linknumber);
1227 member_iter = icmap_iter_init(tmp_key);
1228 while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1229 if (member_count == 0) {
1230 if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
1231 free(str);
1232 *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED;
1233 break;
1234 } else {
1235 *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED;
1236 }
1237 }
1238
1239 if (icmap_get_string(member_iter_key, &str) == CS_OK) {
1240 res = totemip_parse (&totem_config->interfaces[linknumber].member_list[member_count++],
1241 str, totem_config->ip_version);
1242 }
1243 }
1244 icmap_iter_finalize(member_iter);
1245
1246 totem_config->interfaces[linknumber].member_count = member_count;
1247
1248 }
1249 icmap_iter_finalize(iter);
1250
1251 return 0;
1252 }
1253
1254 extern int totem_config_read (
1255 struct totem_config *totem_config,
1256 const char **error_string,
1257 uint64_t *warnings)
1258 {
1259 int res = 0;
1260 char *str, *ring0_addr_str;
1261 char tmp_key[ICMAP_KEYNAME_MAXLEN];
1262 uint16_t u16;
1263 int i;
1264 int local_node_pos;
1265 int nodeid_set;
1266
1267 *warnings = 0;
1268
1269 memset (totem_config, 0, sizeof (struct totem_config));
1270 totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
1271 if (totem_config->interfaces == 0) {
1272 *error_string = "Out of memory trying to allocate ethernet interface storage area";
1273 return -1;
1274 }
1275
1276 memset (totem_config->interfaces, 0,
1277 sizeof (struct totem_interface) * INTERFACE_MAX);
1278
1279 strcpy (totem_config->link_mode, "passive");
1280
1281 icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
1282
1283 if (totem_get_crypto(totem_config) != 0) {
1284 *error_string = "crypto_cipher requires crypto_hash with value other than none";
1285 return -1;
1286 }
1287
1288 if (icmap_get_string("totem.link_mode", &str) == CS_OK) {
1289 if (strlen(str) >= TOTEM_LINK_MODE_BYTES) {
1290 *error_string = "totem.link_mode is too long";
1291 free(str);
1292
1293 return -1;
1294 }
1295 strcpy (totem_config->link_mode, str);
1296 free(str);
1297 }
1298
1299 icmap_get_uint32("totem.nodeid", &totem_config->node_id);
1300
1301 totem_config->clear_node_high_bit = 0;
1302 if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
1303 if (strcmp (str, "yes") == 0) {
1304 totem_config->clear_node_high_bit = 1;
1305 }
1306 free(str);
1307 }
1308
1309 icmap_get_uint32("totem.threads", &totem_config->threads);
1310
1311 icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
1312
1313 totem_config->ip_version = totem_config_get_ip_version();
1314
1315 if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
1316 /*
1317 * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
1318 */
1319 config_convert_nodelist_to_interface(totem_config);
1320 } else {
1321 if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str) == CS_OK) {
1322 /*
1323 * Both bindnetaddr and ring0_addr are set.
1324 * Log warning information, and use nodelist instead
1325 */
1326 *warnings |= TOTEM_CONFIG_BINDNETADDR_NODELIST_SET;
1327
1328 config_convert_nodelist_to_interface(totem_config);
1329
1330 free(ring0_addr_str);
1331 }
1332
1333 free(str);
1334 }
1335
1336 /*
1337 * Broadcast option is global but set in interface section,
1338 * so reset before processing interfaces.
1339 */
1340 totem_config->broadcast_use = 0;
1341
1342 res = get_interface_params(totem_config, error_string, warnings, 0);
1343 if (res < 0) {
1344 return res;
1345 }
1346
1347 /*
1348 * Use broadcast is global, so if set, make sure to fill mcast addr correctly
1349 * broadcast is only supported for UDP so just do interface 0;
1350 */
1351 if (totem_config->broadcast_use) {
1352 totemip_parse (&totem_config->interfaces[0].mcast_addr,
1353 "255.255.255.255", 0);
1354 }
1355
1356 totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1357 if (icmap_get_string("totem.transport", &str) == CS_OK) {
1358 if (strcmp (str, "udpu") == 0) {
1359 totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
1360 }
1361
1362 if (strcmp (str, "udp") == 0) {
1363 totem_config->transport_number = TOTEM_TRANSPORT_UDP;
1364 }
1365
1366 if (strcmp (str, "knet") == 0) {
1367 totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1368 }
1369
1370 free(str);
1371 }
1372
1373 /*
1374 * Store automatically generated items back to icmap only for UDP
1375 */
1376 if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1377 for (i = 0; i < INTERFACE_MAX; i++) {
1378 if (!totem_config->interfaces[i].configured) {
1379 continue;
1380 }
1381 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
1382 if (icmap_get_string(tmp_key, &str) == CS_OK) {
1383 free(str);
1384 } else {
1385 str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
1386 icmap_set_string(tmp_key, str);
1387 }
1388
1389 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
1390 if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
1391 icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
1392 }
1393 }
1394 }
1395
1396 /*
1397 * Check existence of nodelist
1398 */
1399 if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
1400 free(str);
1401 /*
1402 * find local node
1403 */
1404 local_node_pos = find_local_node_in_nodelist(totem_config);
1405 if (local_node_pos != -1) {
1406 icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
1407
1408 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
1409
1410 nodeid_set = (totem_config->node_id != 0);
1411 if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
1412 *warnings |= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED;
1413 }
1414 if ((totem_config->transport_number == TOTEM_TRANSPORT_KNET) && (!totem_config->node_id)) {
1415 *error_string = "With knet, you must specify nodeid for current node";
1416 return -1;
1417 }
1418
1419 /*
1420 * Make localnode ring0_addr read only, so we can be sure that local
1421 * node never changes. If rebinding to other IP would be in future
1422 * supported, this must be changed and handled properly!
1423 */
1424 snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
1425 icmap_set_ro_access(tmp_key, 0, 1);
1426 icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
1427 }
1428
1429 put_nodelist_members_to_config(totem_config, 0);
1430 }
1431
1432 /*
1433 * Get things that might change in the future (and can depend on totem_config->interfaces);
1434 */
1435 totem_volatile_config_read(totem_config, NULL);
1436
1437 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1438
1439 add_totem_config_notification(totem_config);
1440
1441 return 0;
1442 }
1443
1444
1445 int totem_config_validate (
1446 struct totem_config *totem_config,
1447 const char **error_string)
1448 {
1449 static char local_error_reason[512];
1450 char parse_error[512];
1451 const char *error_reason = local_error_reason;
1452 int i;
1453 int num_configured = 0;
1454 unsigned int interface_max = INTERFACE_MAX;
1455
1456
1457
1458 for (i = 0; i < INTERFACE_MAX; i++) {
1459 if (totem_config->interfaces[i].configured) {
1460 num_configured++;
1461 }
1462 }
1463 if (num_configured == 0) {
1464 error_reason = "No interfaces defined";
1465 goto parse_error;
1466 }
1467
1468 for (i = 0; i < INTERFACE_MAX; i++) {
1469 /*
1470 * Some error checking of parsed data to make sure its valid
1471 */
1472
1473 struct totem_ip_address null_addr;
1474
1475 if (!totem_config->interfaces[i].configured) {
1476 continue;
1477 }
1478
1479 memset (&null_addr, 0, sizeof (struct totem_ip_address));
1480
1481 if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP) &&
1482 memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
1483 sizeof (struct totem_ip_address)) == 0) {
1484 error_reason = "No multicast address specified";
1485 goto parse_error;
1486 }
1487
1488 if (totem_config->interfaces[i].ip_port == 0) {
1489 error_reason = "No multicast port specified";
1490 goto parse_error;
1491 }
1492
1493 if (totem_config->interfaces[i].ttl > 255) {
1494 error_reason = "Invalid TTL (should be 0..255)";
1495 goto parse_error;
1496 }
1497 if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
1498 totem_config->interfaces[i].ttl != 1) {
1499 error_reason = "Can only set ttl on multicast transport types";
1500 goto parse_error;
1501 }
1502 if (totem_config->interfaces[i].knet_link_priority > 255) {
1503 error_reason = "Invalid link priority (should be 0..255)";
1504 goto parse_error;
1505 }
1506 if (totem_config->transport_number != TOTEM_TRANSPORT_KNET &&
1507 totem_config->interfaces[i].knet_link_priority != 1) {
1508 error_reason = "Can only set link priority on knet transport type";
1509 goto parse_error;
1510 }
1511
1512 if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
1513 totem_config->node_id == 0) {
1514
1515 error_reason = "An IPV6 network requires that a node ID be specified.";
1516 goto parse_error;
1517 }
1518
1519 if (totem_config->broadcast_use == 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1520 if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
1521 error_reason = "Multicast address family does not match bind address family";
1522 goto parse_error;
1523 }
1524
1525 if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
1526 error_reason = "mcastaddr is not a correct multicast address.";
1527 goto parse_error;
1528 }
1529 }
1530
1531 if (totem_config->interfaces[0].bindnet.family != totem_config->interfaces[i].bindnet.family) {
1532 error_reason = "Not all bind address belong to the same IP family";
1533 goto parse_error;
1534 }
1535 }
1536
1537 if (totem_config->version != 2) {
1538 error_reason = "This totem parser can only parse version 2 configurations.";
1539 goto parse_error;
1540 }
1541
1542 if (totem_volatile_config_validate(totem_config, error_string) == -1) {
1543 return (-1);
1544 }
1545
1546 if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
1547 return (-1);
1548 }
1549
1550 /*
1551 * KNET Link values validation
1552 */
1553 if (strcmp (totem_config->link_mode, "active") &&
1554 strcmp (totem_config->link_mode, "rr") &&
1555 strcmp (totem_config->link_mode, "passive")) {
1556 snprintf (local_error_reason, sizeof(local_error_reason),
1557 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->link_mode);
1558 goto parse_error;
1559 }
1560
1561 /* Only Knet does multiple interfaces */
1562 if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
1563 interface_max = 1;
1564 }
1565
1566 if (interface_max < num_configured) {
1567 snprintf (parse_error, sizeof(parse_error),
1568 "%d is too many configured interfaces for non-Knet transport.",
1569 num_configured);
1570 error_reason = parse_error;
1571 goto parse_error;
1572 }
1573
1574 /* Only knet allows crypto */
1575 if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
1576 if ((strcmp(totem_config->crypto_cipher_type, "none") != 0) ||
1577 (strcmp(totem_config->crypto_hash_type, "none") != 0)) {
1578
1579 snprintf (parse_error, sizeof(parse_error),
1580 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
1581 error_reason = parse_error;
1582 goto parse_error;
1583 }
1584 }
1585
1586 if (totem_config->net_mtu == 0) {
1587 if (totem_config->transport_number == TOTEM_TRANSPORT_KNET) {
1588 totem_config->net_mtu = KNET_MAX_PACKET_SIZE;
1589 }
1590 else {
1591 totem_config->net_mtu = 1500;
1592 }
1593 }
1594
1595 return 0;
1596
1597 parse_error:
1598 snprintf (error_string_response, sizeof(error_string_response),
1599 "parse error in config: %s\n", error_reason);
1600 *error_string = error_string_response;
1601 return (-1);
1602
1603 }
1604
1605 static int read_keyfile (
1606 const char *key_location,
1607 struct totem_config *totem_config,
1608 const char **error_string)
1609 {
1610 int fd;
1611 int res;
1612 int saved_errno;
1613 char error_str[100];
1614 const char *error_ptr;
1615
1616 fd = open (key_location, O_RDONLY);
1617 if (fd == -1) {
1618 error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
1619 snprintf (error_string_response, sizeof(error_string_response),
1620 "Could not open %s: %s\n",
1621 key_location, error_ptr);
1622 goto parse_error;
1623 }
1624
1625 res = read (fd, totem_config->private_key, TOTEM_PRIVATE_KEY_LEN_MAX);
1626 saved_errno = errno;
1627 close (fd);
1628
1629 if (res == -1) {
1630 error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
1631 snprintf (error_string_response, sizeof(error_string_response),
1632 "Could not read %s: %s\n",
1633 key_location, error_ptr);
1634 goto parse_error;
1635 }
1636
1637 if (res < TOTEM_PRIVATE_KEY_LEN_MIN) {
1638 snprintf (error_string_response, sizeof(error_string_response),
1639 "Could only read %d bits of minimum %u bits from %s.\n",
1640 res * 8, TOTEM_PRIVATE_KEY_LEN_MIN * 8, key_location);
1641 goto parse_error;
1642 }
1643
1644 totem_config->private_key_len = res;
1645
1646 return 0;
1647
1648 parse_error:
1649 *error_string = error_string_response;
1650 return (-1);
1651 }
1652
1653 int totem_config_keyread (
1654 struct totem_config *totem_config,
1655 const char **error_string)
1656 {
1657 int got_key = 0;
1658 char *key_location = NULL;
1659 int res;
1660 size_t key_len;
1661
1662 memset (totem_config->private_key, 0, sizeof(totem_config->private_key));
1663 totem_config->private_key_len = 0;
1664
1665 if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
1666 strcmp(totem_config->crypto_hash_type, "none") == 0) {
1667 return (0);
1668 }
1669
1670 /* cmap may store the location of the key file */
1671 if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
1672 res = read_keyfile(key_location, totem_config, error_string);
1673 free(key_location);
1674 if (res) {
1675 goto key_error;
1676 }
1677 got_key = 1;
1678 } else { /* Or the key itself may be in the cmap */
1679 if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
1680 if (key_len > sizeof(totem_config->private_key)) {
1681 sprintf(error_string_response, "key is too long");
1682 goto key_error;
1683 }
1684 if (key_len < TOTEM_PRIVATE_KEY_LEN_MIN) {
1685 sprintf(error_string_response, "key is too short");
1686 goto key_error;
1687 }
1688 if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
1689 totem_config->private_key_len = key_len;
1690 got_key = 1;
1691 } else {
1692 sprintf(error_string_response, "can't load private key");
1693 goto key_error;
1694 }
1695 }
1696 }
1697
1698 /* In desperation we read the default filename */
1699 if (!got_key) {
1700 const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
1701 if (!filename)
1702 filename = COROSYSCONFDIR "/authkey";
1703 res = read_keyfile(filename, totem_config, error_string);
1704 if (res)
1705 goto key_error;
1706
1707 }
1708
1709 return (0);
1710
1711 key_error:
1712 *error_string = error_string_response;
1713 return (-1);
1714
1715 }
1716
1717 static void debug_dump_totem_config(const struct totem_config *totem_config)
1718 {
1719
1720 log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
1721 totem_config->token_timeout, totem_config->token_retransmit_timeout);
1722 log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
1723 totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
1724 log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
1725 totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
1726 totem_config->merge_timeout);
1727 log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
1728 totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
1729 log_printf(LOGSYS_LEVEL_DEBUG,
1730 "seqno unchanged const (%d rotations) Maximum network MTU %d",
1731 totem_config->seqno_unchanged_const, totem_config->net_mtu);
1732 log_printf(LOGSYS_LEVEL_DEBUG,
1733 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
1734 totem_config->window_size, totem_config->max_messages);
1735 log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
1736 log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
1737 totem_config->heartbeat_failures_allowed);
1738 log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
1739 }
1740
1741 static void totem_change_notify(
1742 int32_t event,
1743 const char *key_name,
1744 struct icmap_notify_value new_val,
1745 struct icmap_notify_value old_val,
1746 void *user_data)
1747 {
1748 struct totem_config *totem_config = (struct totem_config *)user_data;
1749 uint32_t *param;
1750 uint8_t reloading;
1751 const char *deleted_key = NULL;
1752 const char *error_string;
1753
1754 /*
1755 * If a full reload is in progress then don't do anything until it's done and
1756 * can reconfigure it all atomically
1757 */
1758 if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
1759 return;
1760
1761 param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
1762 /*
1763 * Process change only if changed key is found in totem_config (-> param is not NULL)
1764 * or for special key token_coefficient. token_coefficient key is not stored in
1765 * totem_config, but it is used for computation of token timeout.
1766 */
1767 if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
1768 return;
1769
1770 /*
1771 * Values other than UINT32 are not supported, or needed (yet)
1772 */
1773 switch (event) {
1774 case ICMAP_TRACK_DELETE:
1775 deleted_key = key_name;
1776 break;
1777 case ICMAP_TRACK_ADD:
1778 case ICMAP_TRACK_MODIFY:
1779 deleted_key = NULL;
1780 break;
1781 default:
1782 break;
1783 }
1784
1785 totem_volatile_config_read (totem_config, deleted_key);
1786 log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
1787 debug_dump_totem_config(totem_config);
1788 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
1789 log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1790 /*
1791 * TODO: Consider corosync exit and/or load defaults for volatile
1792 * values. For now, log error seems to be enough
1793 */
1794 }
1795 }
1796
1797 static void totem_reload_notify(
1798 int32_t event,
1799 const char *key_name,
1800 struct icmap_notify_value new_val,
1801 struct icmap_notify_value old_val,
1802 void *user_data)
1803 {
1804 struct totem_config *totem_config = (struct totem_config *)user_data;
1805 uint32_t local_node_pos;
1806 const char *error_string;
1807 uint64_t warnings;
1808
1809 /* Reload has completed */
1810 if (*(uint8_t *)new_val.data == 0) {
1811
1812 totem_config->orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
1813 assert(totem_config->orig_interfaces != NULL);
1814 memcpy(totem_config->orig_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
1815
1816 get_interface_params(totem_config, &error_string, &warnings, 1);
1817 put_nodelist_members_to_config (totem_config, 1);
1818 totem_volatile_config_read (totem_config, NULL);
1819 log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
1820 debug_dump_totem_config(totem_config);
1821 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
1822 log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1823 /*
1824 * TODO: Consider corosync exit and/or load defaults for volatile
1825 * values. For now, log error seems to be enough
1826 */
1827 }
1828
1829 /* Reinstate the local_node_pos */
1830 local_node_pos = find_local_node_in_nodelist(totem_config);
1831 if (local_node_pos != -1) {
1832 icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
1833 }
1834
1835 /* Reconfigure network params as appropriate */
1836 totempg_reconfigure();
1837
1838 free(totem_config->orig_interfaces);
1839
1840 icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1841 } else {
1842 icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
1843 }
1844 }
1845
1846 static void add_totem_config_notification(struct totem_config *totem_config)
1847 {
1848 icmap_track_t icmap_track;
1849
1850 icmap_track_add("totem.",
1851 ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
1852 totem_change_notify,
1853 totem_config,
1854 &icmap_track);
1855
1856 icmap_track_add("config.reload_in_progress",
1857 ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
1858 totem_reload_notify,
1859 totem_config,
1860 &icmap_track);
1861
1862 icmap_track_add("nodelist.node.",
1863 ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
1864 nodelist_dynamic_notify,
1865 (void *)totem_config,
1866 &icmap_track);
1867 }