corosync  3.1.0
totemconfig.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 MontaVista Software, Inc.
3  * Copyright (c) 2006-2019 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Steven Dake (sdake@redhat.com)
8  * Jan Friesse (jfriesse@redhat.com)
9  * Chrissie Caulfield (ccaulfie@redhat.com)
10  *
11  * This software licensed under BSD license, the text of which follows:
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * - Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * - Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * - Neither the name of the MontaVista Software, Inc. nor the names of its
22  * contributors may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35  * THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include <config.h>
39 
40 #include <stdio.h>
41 #include <string.h>
42 #include <stdlib.h>
43 #include <errno.h>
44 #include <unistd.h>
45 #include <sys/socket.h>
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <fcntl.h>
49 #include <ifaddrs.h>
50 #include <netdb.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
53 #include <sys/param.h>
54 #include <sys/utsname.h>
55 
56 #include <corosync/swab.h>
57 #include <qb/qblist.h>
58 #include <qb/qbdefs.h>
59 #include <libknet.h>
60 #include <corosync/totem/totem.h>
61 #include <corosync/config.h>
62 #include <corosync/logsys.h>
63 #include <corosync/icmap.h>
64 
65 #include "util.h"
66 #include "totemconfig.h"
67 
68 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
69 #define TOKEN_TIMEOUT 3000
70 #define TOKEN_WARNING 75
71 #define TOKEN_COEFFICIENT 650
72 #define JOIN_TIMEOUT 50
73 #define MERGE_TIMEOUT 200
74 #define DOWNCHECK_TIMEOUT 1000
75 #define FAIL_TO_RECV_CONST 2500
76 #define SEQNO_UNCHANGED_CONST 30
77 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
78 #define MINIMUM_TIMEOUT_HOLD (int)(MINIMUM_TIMEOUT * 0.8 - (1000/HZ))
79 #define MAX_NETWORK_DELAY 50
80 #define WINDOW_SIZE 50
81 #define MAX_MESSAGES 17
82 #define MISS_COUNT_CONST 5
83 #define BLOCK_UNLISTED_IPS 1
84 
85 /* Currently all but PONG_COUNT match the defaults in libknet.h */
86 #define KNET_PING_INTERVAL 1000
87 #define KNET_PING_TIMEOUT 2000
88 #define KNET_PING_PRECISION 2048
89 #define KNET_PONG_COUNT 2
90 #define KNET_PMTUD_INTERVAL 30
91 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP
92 
93 #define DEFAULT_PORT 5405
94 
95 static char error_string_response[768];
96 
97 static void add_totem_config_notification(struct totem_config *totem_config);
98 
99 static void *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
100 {
101  if (strcmp(param_name, "totem.token") == 0)
102  return &totem_config->token_timeout;
103  if (strcmp(param_name, "totem.token_warning") == 0)
104  return &totem_config->token_warning;
105  if (strcmp(param_name, "totem.token_retransmit") == 0)
106  return &totem_config->token_retransmit_timeout;
107  if (strcmp(param_name, "totem.hold") == 0)
108  return &totem_config->token_hold_timeout;
109  if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
110  return &totem_config->token_retransmits_before_loss_const;
111  if (strcmp(param_name, "totem.join") == 0)
112  return &totem_config->join_timeout;
113  if (strcmp(param_name, "totem.send_join") == 0)
114  return &totem_config->send_join_timeout;
115  if (strcmp(param_name, "totem.consensus") == 0)
116  return &totem_config->consensus_timeout;
117  if (strcmp(param_name, "totem.merge") == 0)
118  return &totem_config->merge_timeout;
119  if (strcmp(param_name, "totem.downcheck") == 0)
120  return &totem_config->downcheck_timeout;
121  if (strcmp(param_name, "totem.fail_recv_const") == 0)
122  return &totem_config->fail_to_recv_const;
123  if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
124  return &totem_config->seqno_unchanged_const;
125  if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
126  return &totem_config->heartbeat_failures_allowed;
127  if (strcmp(param_name, "totem.max_network_delay") == 0)
128  return &totem_config->max_network_delay;
129  if (strcmp(param_name, "totem.window_size") == 0)
130  return &totem_config->window_size;
131  if (strcmp(param_name, "totem.max_messages") == 0)
132  return &totem_config->max_messages;
133  if (strcmp(param_name, "totem.miss_count_const") == 0)
134  return &totem_config->miss_count_const;
135  if (strcmp(param_name, "totem.knet_pmtud_interval") == 0)
136  return &totem_config->knet_pmtud_interval;
137  if (strcmp(param_name, "totem.knet_compression_threshold") == 0)
138  return &totem_config->knet_compression_threshold;
139  if (strcmp(param_name, "totem.knet_compression_level") == 0)
140  return &totem_config->knet_compression_level;
141  if (strcmp(param_name, "totem.knet_compression_model") == 0)
142  return totem_config->knet_compression_model;
143  if (strcmp(param_name, "totem.block_unlisted_ips") == 0)
144  return &totem_config->block_unlisted_ips;
145 
146  return NULL;
147 }
148 
149 /*
150  * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
151  * and readed value is zero, default value is used and stored into totem_config.
152  */
153 static void totem_volatile_config_set_uint32_value (struct totem_config *totem_config, icmap_map_t map,
154  const char *key_name, const char *deleted_key, unsigned int default_value,
155  int allow_zero_value)
156 {
157  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
158 
159  if (icmap_get_uint32_r(map, key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
160  (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
161  (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
162  *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
163  }
164 
165  /*
166  * Store totem_config value to cmap runtime section
167  */
168  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
169  /*
170  * This shouldn't happen
171  */
172  return ;
173  }
174 
175  strcpy(runtime_key_name, "runtime.config.");
176  strcat(runtime_key_name, key_name);
177 
178  icmap_set_uint32_r(map, runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
179 }
180 
181 static void totem_volatile_config_set_int32_value (struct totem_config *totem_config, icmap_map_t map,
182  const char *key_name, const char *deleted_key, int default_value,
183  int allow_zero_value)
184 {
185  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
186 
187  if (icmap_get_int32_r(map, key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
188  (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
189  (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
190  *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
191  }
192 
193  /*
194  * Store totem_config value to cmap runtime section
195  */
196  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
197  /*
198  * This shouldn't happen
199  */
200  return ;
201  }
202 
203  strcpy(runtime_key_name, "runtime.config.");
204  strcat(runtime_key_name, key_name);
205 
206  icmap_set_int32_r(map, runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
207 }
208 
209 static void totem_volatile_config_set_string_value (struct totem_config *totem_config, icmap_map_t map,
210  const char *key_name, const char *deleted_key, const char *default_value)
211 {
212  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
213  int res;
214  char *new_config_value;
215  const void *config_value;
216 
217  config_value = totem_get_param_by_name(totem_config, key_name);
218 
219  res = icmap_get_string_r(map, key_name, (char **)&new_config_value);
220  if (res != CS_OK ||
221  (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
222 
223  /* Slightly pointless use of strncpy but it keeps coverity happy */
224  strncpy((char *)config_value, default_value, CONFIG_STRING_LEN_MAX);
225  } else {
226  strncpy((char *)config_value, new_config_value, CONFIG_STRING_LEN_MAX);
227  }
228  if (res == CS_OK) {
229  free(new_config_value);
230  }
231 
232  /*
233  * Store totem_config value to cmap runtime section
234  */
235  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
236  /*
237  * This shouldn't happen
238  */
239  return ;
240  }
241 
242  strcpy(runtime_key_name, "runtime.config.");
243  strcat(runtime_key_name, key_name);
244 
245  (void)icmap_set_string_r(map, runtime_key_name, (char *)config_value);
246 }
247 
248 /*
249  * Read string value stored in key_name from icmap, use it as a boolean (yes/no) type, convert it
250  * to integer value (1/0) and store into totem_config.
251  *
252  * If key is not found or key_name == delete_key default value is used
253  * and stored into totem_config.
254  */
255 static void totem_volatile_config_set_boolean_value (struct totem_config *totem_config, icmap_map_t map,
256  const char *key_name, const char *deleted_key, unsigned int default_value)
257 {
258  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
259  char *str;
260  int val;
261 
262  str = NULL;
263  val = default_value;
264 
265  if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
266  (icmap_get_string_r(map, key_name, &str) != CS_OK)) {
267  /*
268  * Do nothing. str is NULL (icmap_get_string ether not called or
269  * not changed str).
270  */
271  } else {
272  if (strcmp(str, "yes") == 0) {
273  val = 1;
274  } else if (strcmp(str, "no") == 0) {
275  val = 0;
276  }
277  free(str);
278  }
279 
280  /*
281  * Store totem_config value to cmap runtime section
282  */
283  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
284  /*
285  * This shouldn't happen
286  */
287  return ;
288  }
289 
290  strcpy(runtime_key_name, "runtime.config.");
291  strcat(runtime_key_name, key_name);
292 
293  *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = val;
294 
295  icmap_set_uint32_r(map, runtime_key_name, val);
296 }
297 
298 /*
299  * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
300  * default value is stored. deleted_key is name of key beeing processed by delete operation
301  * from cmap. It is considered as non existing even if it can be read. Can be NULL.
302  */
303 void totem_volatile_config_read (struct totem_config *totem_config, icmap_map_t temp_map, const char *deleted_key)
304 {
305  uint32_t u32;
306 
307  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.token_retransmits_before_loss_const", deleted_key,
309 
310  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
311 
312  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.token_warning", deleted_key, TOKEN_WARNING, 1);
313 
314  if (totem_config->interfaces[0].member_count > 2) {
315  u32 = TOKEN_COEFFICIENT;
316  icmap_get_uint32_r(temp_map, "totem.token_coefficient", &u32);
317  totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
318 
319  /*
320  * Store totem_config value to cmap runtime section
321  */
322  icmap_set_uint32_r(temp_map, "runtime.config.totem.token", totem_config->token_timeout);
323  }
324 
325  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
326 
327  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
328 
329  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
330 
331  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
332  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.knet_pmtud_interval", deleted_key, KNET_PMTUD_INTERVAL, 0);
333 
334  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.token_retransmit", deleted_key,
335  (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
336 
337  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.hold", deleted_key,
338  (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
339 
340  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
341 
342  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.consensus", deleted_key,
343  (int)(float)(1.2 * totem_config->token_timeout), 0);
344 
345  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
346 
347  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
348 
349  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
350 
351  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.seqno_unchanged_const", deleted_key,
353 
354  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.send_join", deleted_key, 0, 1);
355 
356  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
357 
358  totem_volatile_config_set_uint32_value(totem_config, temp_map, "totem.knet_compression_threshold", deleted_key, 0, 1);
359 
360  totem_volatile_config_set_int32_value(totem_config, temp_map, "totem.knet_compression_level", deleted_key, 0, 1);
361 
362  totem_volatile_config_set_string_value(totem_config, temp_map, "totem.knet_compression_model", deleted_key, "none");
363 
364  totem_volatile_config_set_boolean_value(totem_config, temp_map, "totem.block_unlisted_ips", deleted_key,
366 }
367 
369  struct totem_config *totem_config,
370  icmap_map_t temp_map,
371  const char **error_string)
372 {
373  /* Static just to keep them off the stack */
374  static char local_error_reason[512];
375  static char addr_str_buf[INET6_ADDRSTRLEN];
376  const char *error_reason = local_error_reason;
377  char name_key[ICMAP_KEYNAME_MAXLEN];
378  char *name_str;
379  int i, j, num_configured, members;
380  uint32_t tmp_config_value;
381 
382  if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
383  snprintf (local_error_reason, sizeof(local_error_reason),
384  "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
385  totem_config->max_network_delay, MINIMUM_TIMEOUT);
386  goto parse_error;
387  }
388 
389  if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
390  snprintf (local_error_reason, sizeof(local_error_reason),
391  "The token timeout parameter (%d ms) may not be less than (%d ms).",
392  totem_config->token_timeout, MINIMUM_TIMEOUT);
393  goto parse_error;
394  }
395 
396  if (totem_config->token_warning > 100 || totem_config->token_warning < 0) {
397  snprintf (local_error_reason, sizeof(local_error_reason),
398  "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
399  totem_config->token_warning);
400  goto parse_error;
401  }
402 
403  if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
404  if (icmap_get_uint32_r(temp_map, "totem.token_retransmit", &tmp_config_value) == CS_OK) {
405  snprintf (local_error_reason, sizeof(local_error_reason),
406  "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
408  goto parse_error;
409  } else {
410  snprintf (local_error_reason, sizeof(local_error_reason),
411  "Not appropriate token or token_retransmits_before_loss_const value set");
412  goto parse_error;
413  }
414  }
415 
416  if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT_HOLD) {
417  snprintf (local_error_reason, sizeof(local_error_reason),
418  "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
420  goto parse_error;
421  }
422 
423  if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
424  snprintf (local_error_reason, sizeof(local_error_reason),
425  "The join timeout parameter (%d ms) may not be less than (%d ms).",
426  totem_config->join_timeout, MINIMUM_TIMEOUT);
427  goto parse_error;
428  }
429 
430  if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
431  snprintf (local_error_reason, sizeof(local_error_reason),
432  "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
433  totem_config->consensus_timeout, MINIMUM_TIMEOUT);
434  goto parse_error;
435  }
436 
437  if (totem_config->consensus_timeout < totem_config->join_timeout) {
438  snprintf (local_error_reason, sizeof(local_error_reason),
439  "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
440  totem_config->consensus_timeout, totem_config->join_timeout);
441  goto parse_error;
442  }
443 
444  if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
445  snprintf (local_error_reason, sizeof(local_error_reason),
446  "The merge timeout parameter (%d ms) may not be less than (%d ms).",
447  totem_config->merge_timeout, MINIMUM_TIMEOUT);
448  goto parse_error;
449  }
450 
451  if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
452  snprintf (local_error_reason, sizeof(local_error_reason),
453  "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
454  totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
455  goto parse_error;
456  }
457 
458  /* Check that we have nodelist 'name' if there is more than one link */
459  num_configured = 0;
460  members = -1;
461  for (i = 0; i < INTERFACE_MAX; i++) {
462  if (totem_config->interfaces[i].configured) {
463  if (num_configured == 0) {
464  members = totem_config->interfaces[i].member_count;
465  }
466  num_configured++;
467  }
468  }
469 
470  if (num_configured > 1) {
471  /*
472  * This assert is here just to make compiler happy
473  */
474  assert(members != -1);
475  for (i=0; i < members; i++) {
476  snprintf(name_key, sizeof(name_key), "nodelist.node.%d.name", i);
477 
478  if (icmap_get_string_r(temp_map, name_key, &name_str) != CS_OK) {
479  snprintf (local_error_reason, sizeof(local_error_reason),
480  "for a multi-link configuration, all nodes must have a 'name' attribute");
481  goto parse_error;
482  }
483 
484  free(name_str);
485  }
486 
487  for (i=0; i < INTERFACE_MAX; i++) {
488  if (!totem_config->interfaces[i].configured) {
489  continue;
490  }
491  if (totem_config->interfaces[i].member_count != members) {
492  snprintf (local_error_reason, sizeof(local_error_reason),
493  "Not all nodes have the same number of links");
494  goto parse_error;
495  }
496  }
497  }
498 
499  /* Verify that all nodes on the same link have the same IP family */
500  for (i=0; i < INTERFACE_MAX; i++) {
501  for (j=1; j<totem_config->interfaces[i].member_count; j++) {
502  if (totem_config->interfaces[i].configured) {
503  if (totem_config->interfaces[i].member_list[j].family !=
504  totem_config->interfaces[i].member_list[0].family) {
505  memcpy(addr_str_buf,
506  totemip_print(&(totem_config->interfaces[i].member_list[j])),
507  sizeof(addr_str_buf));
508 
509  snprintf (local_error_reason, sizeof(local_error_reason),
510  "Nodes for link %d have different IP families "
511  "(compared %s with %s)", i,
512  addr_str_buf,
513  totemip_print(&(totem_config->interfaces[i].member_list[0])));
514  goto parse_error;
515  }
516  }
517  }
518  }
519 
520  return 0;
521 
522 parse_error:
523  snprintf (error_string_response, sizeof(error_string_response),
524  "parse error in config: %s\n", error_reason);
525  *error_string = error_string_response;
526  return (-1);
527 
528 }
529 
530 static int totem_get_crypto(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
531 {
532  char *str;
533  const char *tmp_cipher;
534  const char *tmp_hash;
535  const char *tmp_model;
536 
537  tmp_hash = "none";
538  tmp_cipher = "none";
539  tmp_model = "none";
540 
541  if (icmap_get_string_r(map, "totem.crypto_model", &str) == CS_OK) {
542  if (strcmp(str, "nss") == 0) {
543  tmp_model = "nss";
544  }
545  if (strcmp(str, "openssl") == 0) {
546  tmp_model = "openssl";
547  }
548  free(str);
549  } else {
550  tmp_model = "nss";
551  }
552 
553  if (icmap_get_string_r(map, "totem.secauth", &str) == CS_OK) {
554  if (strcmp(str, "on") == 0) {
555  tmp_cipher = "aes256";
556  tmp_hash = "sha256";
557  }
558  free(str);
559  }
560 
561  if (icmap_get_string_r(map, "totem.crypto_cipher", &str) == CS_OK) {
562  if (strcmp(str, "none") == 0) {
563  tmp_cipher = "none";
564  }
565  if (strcmp(str, "aes256") == 0) {
566  tmp_cipher = "aes256";
567  }
568  if (strcmp(str, "aes192") == 0) {
569  tmp_cipher = "aes192";
570  }
571  if (strcmp(str, "aes128") == 0) {
572  tmp_cipher = "aes128";
573  }
574  free(str);
575  }
576 
577  if (icmap_get_string_r(map, "totem.crypto_hash", &str) == CS_OK) {
578  if (strcmp(str, "none") == 0) {
579  tmp_hash = "none";
580  }
581  if (strcmp(str, "md5") == 0) {
582  tmp_hash = "md5";
583  }
584  if (strcmp(str, "sha1") == 0) {
585  tmp_hash = "sha1";
586  }
587  if (strcmp(str, "sha256") == 0) {
588  tmp_hash = "sha256";
589  }
590  if (strcmp(str, "sha384") == 0) {
591  tmp_hash = "sha384";
592  }
593  if (strcmp(str, "sha512") == 0) {
594  tmp_hash = "sha512";
595  }
596  free(str);
597  }
598 
599  if ((strcmp(tmp_cipher, "none") != 0) &&
600  (strcmp(tmp_hash, "none") == 0)) {
601  *error_string = "crypto_cipher requires crypto_hash with value other than none";
602  return -1;
603  }
604 
605  if (strcmp(tmp_model, "none") == 0) {
606  *error_string = "crypto_model should be 'nss' or 'openssl'";
607  return -1;
608  }
609 
610  if (strcmp(tmp_cipher, totem_config->crypto_cipher_type) ||
611  strcmp(tmp_hash, totem_config->crypto_hash_type) ||
612  strcmp(tmp_model, totem_config->crypto_model)) {
613  totem_config->crypto_changed = 1;
614  }
615 
616  strncpy(totem_config->crypto_cipher_type, tmp_cipher, CONFIG_STRING_LEN_MAX);
617  strncpy(totem_config->crypto_hash_type, tmp_hash, CONFIG_STRING_LEN_MAX);
618  strncpy(totem_config->crypto_model, tmp_model, CONFIG_STRING_LEN_MAX);
619 
620  return 0;
621 }
622 
623 static int nodelist_byname(icmap_map_t map, const char *find_name, int strip_domain)
624 {
625  icmap_iter_t iter;
626  const char *iter_key;
627  char name_str[ICMAP_KEYNAME_MAXLEN];
628  int res = 0;
629  unsigned int node_pos;
630  char *name;
631  unsigned int namelen;
632 
633  iter = icmap_iter_init_r(map, "nodelist.node.");
634  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
635  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
636  if (res != 2) {
637  continue;
638  }
639  /* ring0_addr is allowed as a fallback */
640  if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
641  continue;
642  }
643  if (icmap_get_string_r(map, iter_key, &name) != CS_OK) {
644  continue;
645  }
646  namelen = strlen(name);
647 
648  if (strip_domain) {
649  char *dot;
650  dot = strchr(name, '.');
651  if (dot) {
652  namelen = name - dot - 1;
653  }
654  }
655  if (strncmp(find_name, name, namelen) == 0 &&
656  strlen(find_name) == strlen(name)) {
657  icmap_iter_finalize(iter);
658  return node_pos;
659  }
660  }
661  icmap_iter_finalize(iter);
662  return -1;
663 }
664 
665 /* Compare two addresses - only address part (sin_addr/sin6_addr) is checked */
666 static int ipaddr_equal(const struct sockaddr *addr1, const struct sockaddr *addr2)
667 {
668  int addrlen = 0;
669  const void *addr1p, *addr2p;
670 
671  if (addr1->sa_family != addr2->sa_family)
672  return 0;
673 
674  switch (addr1->sa_family) {
675  case AF_INET:
676  addrlen = sizeof(struct in_addr);
677  addr1p = &((struct sockaddr_in *)addr1)->sin_addr;
678  addr2p = &((struct sockaddr_in *)addr2)->sin_addr;
679  break;
680  case AF_INET6:
681  addrlen = sizeof(struct in6_addr);
682  addr1p = &((struct sockaddr_in6 *)addr1)->sin6_addr;
683  addr2p = &((struct sockaddr_in6 *)addr2)->sin6_addr;
684  break;
685  default:
686  assert(0);
687  }
688 
689  return (memcmp(addr1p, addr2p, addrlen) == 0);
690 }
691 
692 
693 /* Finds the local node and returns its position in the nodelist.
694  * Uses nodelist.local_node_pos as a cache to save effort
695  */
696 static int find_local_node(icmap_map_t map, int use_cache)
697 {
698  char nodename2[PATH_MAX];
699  char name_str[ICMAP_KEYNAME_MAXLEN];
700  icmap_iter_t iter;
701  const char *iter_key;
702  unsigned int cached_pos;
703  char *dot = NULL;
704  const char *node;
705  struct ifaddrs *ifa, *ifa_list;
706  struct sockaddr *sa;
707  int found = 0;
708  int node_pos = -1;
709  int res;
710  struct utsname utsname;
711 
712  /* Check for cached value first */
713  if (use_cache) {
714  if (icmap_get_uint32("nodelist.local_node_pos", &cached_pos) == CS_OK) {
715  return cached_pos;
716  }
717  }
718 
719  res = uname(&utsname);
720  if (res) {
721  return -1;
722  }
723  node = utsname.nodename;
724 
725  /* 1. Exact match */
726  node_pos = nodelist_byname(map, node, 0);
727  if (node_pos > -1) {
728  found = 1;
729  goto ret_found;
730  }
731 
732  /* 2. Try to match with increasingly more
733  * specific versions of it
734  */
735  strcpy(nodename2, node);
736  dot = strrchr(nodename2, '.');
737  while (dot) {
738  *dot = '\0';
739 
740  node_pos = nodelist_byname(map, nodename2, 0);
741  if (node_pos > -1) {
742  found = 1;
743  goto ret_found;
744  }
745  dot = strrchr(nodename2, '.');
746  }
747 
748  node_pos = nodelist_byname(map, nodename2, 1);
749  if (node_pos > -1) {
750  found = 1;
751  goto ret_found;
752  }
753 
754  /*
755  * The corosync.conf name may not be related to uname at all,
756  * they may match a hostname on some network interface.
757  */
758  if (getifaddrs(&ifa_list))
759  return -1;
760 
761  for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
762  socklen_t salen = 0;
763 
764  /* Restore this */
765  strcpy(nodename2, node);
766  sa = ifa->ifa_addr;
767  if (!sa) {
768  continue;
769  }
770  if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
771  continue;
772  }
773 
774  if (sa->sa_family == AF_INET) {
775  salen = sizeof(struct sockaddr_in);
776  }
777  if (sa->sa_family == AF_INET6) {
778  salen = sizeof(struct sockaddr_in6);
779  }
780 
781  if (getnameinfo(sa, salen,
782  nodename2, sizeof(nodename2),
783  NULL, 0, 0) == 0) {
784 
785  node_pos = nodelist_byname(map, nodename2, 0);
786  if (node_pos > -1) {
787  found = 1;
788  goto out;
789  }
790 
791  /* Truncate this name and try again */
792  dot = strchr(nodename2, '.');
793  if (dot) {
794  *dot = '\0';
795 
796  node_pos = nodelist_byname(map, nodename2, 0);
797  if (node_pos > -1) {
798  found = 1;
799  goto out;
800  }
801  }
802  }
803 
804  /* See if it's the IP address that's in corosync.conf */
805  if (getnameinfo(sa, sizeof(*sa),
806  nodename2, sizeof(nodename2),
807  NULL, 0, NI_NUMERICHOST))
808  continue;
809 
810  node_pos = nodelist_byname(map, nodename2, 0);
811  if (node_pos > -1) {
812  found = 1;
813  goto out;
814  }
815  }
816 
817  out:
818  if (found) {
819  freeifaddrs(ifa_list);
820  goto ret_found;
821  }
822 
823  /*
824  * This section covers the usecase where the nodename specified in cluster.conf
825  * is an alias specified in /etc/hosts. For example:
826  * <ipaddr> hostname alias1 alias2
827  * and <clusternode name="alias2">
828  * the above calls use uname and getnameinfo does not return aliases.
829  * here we take the name specified in cluster.conf, resolve it to an address
830  * and then compare against all known local ip addresses.
831  * if we have a match, we found our nodename. In theory this chunk of code
832  * could replace all the checks above, but let's avoid any possible regressions
833  * and use it as last.
834  */
835 
836  iter = icmap_iter_init_r(map, "nodelist.node.");
837  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
838  char *dbnodename = NULL;
839  struct addrinfo hints;
840  struct addrinfo *result = NULL, *rp = NULL;
841 
842  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
843  if (res != 2) {
844  continue;
845  }
846  /* 'ring0_addr' is allowed as a fallback, but 'name' will be found first
847  * because the names are in alpha order.
848  */
849  if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
850  continue;
851  }
852  if (icmap_get_string_r(map, iter_key, &dbnodename) != CS_OK) {
853  continue;
854  }
855 
856  memset(&hints, 0, sizeof(struct addrinfo));
857  hints.ai_family = AF_UNSPEC;
858  hints.ai_socktype = SOCK_DGRAM;
859  hints.ai_flags = 0;
860  hints.ai_protocol = IPPROTO_UDP;
861 
862  if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
863  continue;
864  }
865 
866  for (rp = result; rp != NULL; rp = rp->ai_next) {
867  for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
868  if (ifa->ifa_addr &&
869  ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
870  freeaddrinfo(result);
871  found = 1;
872  goto out2;
873  }
874  }
875  }
876 
877  freeaddrinfo(result);
878  }
879 out2:
880  icmap_iter_finalize(iter);
881  freeifaddrs(ifa_list);
882 
883 ret_found:
884  if (found) {
885  res = icmap_set_uint32_r(map, "nodelist.local_node_pos", node_pos);
886  }
887 
888  return node_pos;
889 }
890 
891 static enum totem_ip_version_enum totem_config_get_ip_version(struct totem_config *totem_config)
892 {
893  enum totem_ip_version_enum res;
894  char *str;
895 
896  res = TOTEM_IP_VERSION_6_4;
897 
898  if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
899  res = TOTEM_IP_VERSION_4;
900  }
901 
902  if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
903  if (strcmp(str, "ipv4") == 0) {
904  res = TOTEM_IP_VERSION_4;
905  }
906  if (strcmp(str, "ipv6") == 0) {
907  res = TOTEM_IP_VERSION_6;
908  }
909  if (strcmp(str, "ipv6-4") == 0) {
910  res = TOTEM_IP_VERSION_6_4;
911  }
912  if (strcmp(str, "ipv4-6") == 0) {
913  res = TOTEM_IP_VERSION_4_6;
914  }
915  free(str);
916  }
917 
918  return (res);
919 }
920 
921 static uint16_t generate_cluster_id (const char *cluster_name)
922 {
923  int i;
924  int value = 0;
925 
926  for (i = 0; i < strlen(cluster_name); i++) {
927  value <<= 1;
928  value += cluster_name[i];
929  }
930 
931  return (value & 0xFFFF);
932 }
933 
934 static int get_cluster_mcast_addr (
935  const char *cluster_name,
936  unsigned int linknumber,
937  enum totem_ip_version_enum ip_version,
938  struct totem_ip_address *res)
939 {
940  uint16_t clusterid;
941  char addr[INET6_ADDRSTRLEN + 1];
942  int err;
943 
944  if (cluster_name == NULL) {
945  return (-1);
946  }
947 
948  clusterid = generate_cluster_id(cluster_name) + linknumber;
949  memset (res, 0, sizeof(*res));
950 
951  switch (ip_version) {
952  case TOTEM_IP_VERSION_4:
954  snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
955  break;
956  case TOTEM_IP_VERSION_6:
958  snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
959  break;
960  default:
961  /*
962  * Unknown family
963  */
964  return (-1);
965  }
966 
967  err = totemip_parse (res, addr, ip_version);
968 
969  return (err);
970 }
971 
972 static unsigned int generate_nodeid(
973  struct totem_config *totem_config,
974  char *addr)
975 {
976  unsigned int nodeid;
977  struct totem_ip_address totemip;
978 
979  /* AF_INET hard-coded here because auto-generated nodeids
980  are only for IPv4 */
981  if (totemip_parse(&totemip, addr, TOTEM_IP_VERSION_4) != 0)
982  return -1;
983 
984  memcpy (&nodeid, &totemip.addr, sizeof (unsigned int));
985 
986 #if __BYTE_ORDER == __LITTLE_ENDIAN
987  nodeid = swab32 (nodeid);
988 #endif
989 
990  if (totem_config->clear_node_high_bit) {
991  nodeid &= 0x7FFFFFFF;
992  }
993  return nodeid;
994 }
995 
996 static int check_for_duplicate_nodeids(
997  struct totem_config *totem_config,
998  const char **error_string)
999 {
1000  icmap_iter_t iter;
1001  icmap_iter_t subiter;
1002  const char *iter_key;
1003  int res = 0;
1004  int retval = 0;
1005  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1006  char *ring0_addr=NULL;
1007  char *ring0_addr1=NULL;
1008  unsigned int node_pos;
1009  unsigned int node_pos1;
1010  unsigned int last_node_pos = -1;
1011  unsigned int nodeid;
1012  unsigned int nodeid1;
1013  int autogenerated;
1014 
1015  iter = icmap_iter_init("nodelist.node.");
1016  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1017  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
1018  if (res != 2) {
1019  continue;
1020  }
1021 
1022  /*
1023  * This relies on the fact the icmap keys are always returned in order
1024  * so all of the keys for a node will be grouped together. We're basically
1025  * just running the code below once for each node.
1026  */
1027  if (last_node_pos == node_pos) {
1028  continue;
1029  }
1030  last_node_pos = node_pos;
1031 
1032  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
1033  autogenerated = 0;
1034 
1035  /* Generated nodeids are only allowed for UDP/UDPU so ring0_addr is valid here */
1036  if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
1037 
1038  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
1039  if (icmap_get_string(tmp_key, &ring0_addr) != CS_OK) {
1040  continue;
1041  }
1042 
1043  /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
1044  nodeid = generate_nodeid(totem_config, ring0_addr);
1045  if (nodeid == -1) {
1046  continue;
1047  }
1048  autogenerated = 1;
1049  }
1050 
1051  node_pos1 = 0;
1052  subiter = icmap_iter_init("nodelist.node.");
1053  while (((iter_key = icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
1054  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos1, tmp_key);
1055  if ((res != 2) || (node_pos1 >= node_pos)) {
1056  continue;
1057  }
1058 
1059  if (strcmp(tmp_key, "nodeid") != 0) {
1060  continue;
1061  }
1062 
1063  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
1064  if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
1065 
1066  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos1);
1067  if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
1068  continue;
1069  }
1070  nodeid1 = generate_nodeid(totem_config, ring0_addr1);
1071  if (nodeid1 == -1) {
1072  continue;
1073  }
1074  }
1075 
1076  if (nodeid == nodeid1) {
1077  retval = -1;
1078  snprintf (error_string_response, sizeof(error_string_response),
1079  "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
1080  autogenerated?"(autogenerated from ":"",
1081  autogenerated?ring0_addr:"",
1082  autogenerated?")":"");
1083  *error_string = error_string_response;
1084  break;
1085  }
1086  }
1087  icmap_iter_finalize(subiter);
1088  }
1089  icmap_iter_finalize(iter);
1090  return retval;
1091 }
1092 
1093 
1094 /*
1095  * This needs to be done last of all. It would be nice to do it when reading the
1096  * interface params, but the totem params need to have them to be read first. We
1097  * need both, so this is a way round that circular dependancy.
1098  */
1099 static void calc_knet_ping_timers(struct totem_config *totem_config)
1100 {
1101  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
1102  int interface;
1103 
1104  for (interface = 0; interface < INTERFACE_MAX; interface++) {
1105 
1106  if (totem_config->interfaces[interface].configured) {
1107  if (!totem_config->interfaces[interface].knet_pong_count) {
1108  totem_config->interfaces[interface].knet_pong_count = KNET_PONG_COUNT;
1109  }
1110  if (!totem_config->interfaces[interface].knet_ping_timeout) {
1111  totem_config->interfaces[interface].knet_ping_timeout =
1112  totem_config->token_timeout / totem_config->interfaces[interface].knet_pong_count;
1113  }
1114  snprintf(runtime_key_name, sizeof(runtime_key_name),
1115  "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1116  icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_timeout);
1117 
1118  if (!totem_config->interfaces[interface].knet_ping_interval) {
1119  totem_config->interfaces[interface].knet_ping_interval =
1120  totem_config->token_timeout / (totem_config->interfaces[interface].knet_pong_count * 2);
1121  }
1122  snprintf(runtime_key_name, sizeof(runtime_key_name),
1123  "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1124  icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_interval);
1125  }
1126  }
1127 }
1128 
1129 /*
1130  * Compute difference between two set of totem interface arrays and commit it.
1131  * set1 and set2
1132  * are changed so for same ring, ip existing in both set1 and set2 are cleared
1133  * (set to 0), and ips which are only in set1 or set2 remains untouched.
1134  * totempg_node_add/remove is called.
1135  */
1136 static void compute_and_set_totempg_interfaces(struct totem_interface *set1,
1137  struct totem_interface *set2)
1138 {
1139  int ring_no, set1_pos, set2_pos;
1140  struct totem_ip_address empty_ip_address;
1141 
1142  memset(&empty_ip_address, 0, sizeof(empty_ip_address));
1143 
1144  for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
1145  if (!set1[ring_no].configured && !set2[ring_no].configured) {
1146  continue;
1147  }
1148 
1149  for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
1150  for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
1151  /*
1152  * For current ring_no remove all set1 items existing
1153  * in set2
1154  */
1155  if (memcmp(&set1[ring_no].member_list[set1_pos],
1156  &set2[ring_no].member_list[set2_pos],
1157  sizeof(struct totem_ip_address)) == 0) {
1158  memset(&set1[ring_no].member_list[set1_pos], 0,
1159  sizeof(struct totem_ip_address));
1160  memset(&set2[ring_no].member_list[set2_pos], 0,
1161  sizeof(struct totem_ip_address));
1162  }
1163  }
1164  }
1165  }
1166 
1167  for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
1168  for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
1169  /*
1170  * All items which remain in set1 and don't exist in set2 any more
1171  * have to be removed.
1172  */
1173  if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
1175  "removing dynamic member %s for ring %u",
1176  totemip_print(&set1[ring_no].member_list[set1_pos]),
1177  ring_no);
1178 
1179  totempg_member_remove(&set1[ring_no].member_list[set1_pos], ring_no);
1180  }
1181  }
1182  if (!set2[ring_no].configured) {
1183  continue;
1184  }
1185  for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
1186  /*
1187  * All items which remain in set2 and don't exist in set1 are new nodes
1188  * and have to be added.
1189  */
1190  if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
1192  "adding dynamic member %s for ring %u",
1193  totemip_print(&set2[ring_no].member_list[set2_pos]),
1194  ring_no);
1195 
1196  totempg_member_add(&set2[ring_no].member_list[set2_pos], ring_no);
1197  }
1198  }
1199  }
1200 }
1201 
1202 /*
1203  * Configure parameters for links
1204  */
1205 static void configure_link_params(struct totem_config *totem_config, icmap_map_t map)
1206 {
1207  int i;
1208  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1209  char *addr_string;
1210  int err;
1211  int local_node_pos = find_local_node(map, 0);
1212 
1213  for (i = 0; i<INTERFACE_MAX; i++) {
1214  if (!totem_config->interfaces[i].configured) {
1215  continue;
1216  }
1217 
1218  log_printf(LOGSYS_LEVEL_DEBUG, "Configuring link %d params\n", i);
1219 
1220  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring%u_addr", local_node_pos, i);
1221  if (icmap_get_string_r(map, tmp_key, &addr_string) != CS_OK) {
1222  continue;
1223  }
1224 
1225  err = totemip_parse(&totem_config->interfaces[i].local_ip, addr_string, totem_config->ip_version);
1226  if (err != 0) {
1227  continue;
1228  }
1229  totem_config->interfaces[i].local_ip.nodeid = totem_config->node_id;
1230 
1231  /* In case this is a new link, fill in the defaults if there was no interface{} section for it */
1232  if (!totem_config->interfaces[i].knet_link_priority)
1233  totem_config->interfaces[i].knet_link_priority = 1;
1234 
1235  /* knet_ping_interval & knet_ping_timeout are set later once we know all the other params */
1236  if (!totem_config->interfaces[i].knet_ping_precision)
1238  if (!totem_config->interfaces[i].knet_pong_count)
1239  totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
1240  if (!totem_config->interfaces[i].knet_transport)
1241  totem_config->interfaces[i].knet_transport = KNET_TRANSPORT_UDP;
1242  if (!totem_config->interfaces[i].ip_port)
1243  totem_config->interfaces[i].ip_port = DEFAULT_PORT + i;
1244  }
1245 }
1246 
1247 
1248 static void configure_totem_links(struct totem_config *totem_config, icmap_map_t map)
1249 {
1250  int i;
1251 
1252  for (i = 0; i<INTERFACE_MAX; i++) {
1253  if (!totem_config->interfaces[i].configured) {
1254  continue;
1255  }
1256 
1257  log_printf(LOGSYS_LEVEL_INFO, "Configuring link %d\n", i);
1258 
1259  totempg_iface_set(&totem_config->interfaces[i].local_ip, totem_config->interfaces[i].ip_port, i);
1260  }
1261 }
1262 
1263 /* Check for differences in config that can't be done on-the-fly and print an error */
1264 static int check_things_have_not_changed(struct totem_config *totem_config, const char **error_string)
1265 {
1266  int i,j,k;
1267  const char *ip_str;
1268  char addr_buf[INET6_ADDRSTRLEN];
1269  int changed = 0;
1270 
1271  for (i = 0; i<INTERFACE_MAX; i++) {
1272  if (totem_config->interfaces[i].configured &&
1273  totem_config->orig_interfaces[i].configured) {
1274  if (totem_config->interfaces[i].knet_transport !=
1275  totem_config->orig_interfaces[i].knet_transport) {
1277  "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1278  changed = 1;
1279  }
1280 
1281  /* Check each nodeid in the new configuration and make sure its IP address on this link has not changed */
1282  for (j=0; j < totem_config->interfaces[i].member_count; j++) {
1283  for (k=0; k < totem_config->orig_interfaces[i].member_count; k++) {
1284 
1285  if (totem_config->interfaces[i].member_list[j].nodeid ==
1286  totem_config->orig_interfaces[i].member_list[k].nodeid) {
1287 
1288  /* Found our nodeid - check the IP address */
1289  if (memcmp(&totem_config->interfaces[i].member_list[j],
1290  &totem_config->orig_interfaces[i].member_list[k],
1291  sizeof(struct totem_ip_address))) {
1292 
1293  ip_str = totemip_print(&totem_config->orig_interfaces[i].member_list[k]);
1294 
1295  /* if ip_str is NULL then the old address was invalid and is allowed to change */
1296  if (ip_str) {
1297  strncpy(addr_buf, ip_str, sizeof(addr_buf));
1298  addr_buf[sizeof(addr_buf) - 1] = '\0';
1300  "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1301  i, addr_buf, totemip_print(&totem_config->interfaces[i].member_list[j]));
1302  changed = 1;
1303  }
1304  }
1305  }
1306  }
1307  }
1308  }
1309  }
1310 
1311  if (changed) {
1312  snprintf (error_string_response, sizeof(error_string_response),
1313  "To reconfigure an interface it must be deleted and recreated. A working interface needs to be available to corosync at all times");
1314  *error_string = error_string_response;
1315  return -1;
1316  }
1317  return 0;
1318 }
1319 
1320 
1321 static int put_nodelist_members_to_config(struct totem_config *totem_config, icmap_map_t map,
1322  int reload, const char **error_string)
1323 {
1324  icmap_iter_t iter, iter2;
1325  const char *iter_key, *iter_key2;
1326  int res = 0;
1327  unsigned int node_pos;
1328  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1329  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
1330  char *node_addr_str;
1331  int member_count;
1332  unsigned int linknumber = 0;
1333  int i, j;
1334  int last_node_pos = -1;
1335 
1336  /* Clear out nodelist so we can put the new one in if needed */
1337  for (i = 0; i < INTERFACE_MAX; i++) {
1338  for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
1339  memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
1340  }
1341  totem_config->interfaces[i].member_count = 0;
1342  }
1343 
1344  iter = icmap_iter_init_r(map, "nodelist.node.");
1345  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1346  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
1347  if (res != 2) {
1348  continue;
1349  }
1350  /* If it's the same as the last node_pos then skip it */
1351  if (node_pos == last_node_pos) {
1352  continue;
1353  }
1354  last_node_pos = node_pos;
1355 
1356  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
1357  iter2 = icmap_iter_init_r(map, tmp_key);
1358  while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
1359  unsigned int nodeid;
1360  char *str;
1361 
1362  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
1363  if (icmap_get_uint32_r(map, tmp_key, &nodeid) != CS_OK) {
1364  nodeid = 0;
1365  }
1366 
1367  res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1368  if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
1369  continue;
1370  }
1371  if (linknumber >= INTERFACE_MAX) {
1372  snprintf (error_string_response, sizeof(error_string_response),
1373  "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1374  linknumber, INTERFACE_MAX - 1);
1375  *error_string = error_string_response;
1376 
1377  icmap_iter_finalize(iter2);
1378  icmap_iter_finalize(iter);
1379  return (-1);
1380  }
1381 
1382  if (icmap_get_string_r(map, iter_key2, &node_addr_str) != CS_OK) {
1383  continue;
1384  }
1385 
1386  /* Generate nodeids if they are not provided and transport is UDP/U */
1387  if (!nodeid &&
1388  (totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
1389  totem_config->transport_number == TOTEM_TRANSPORT_UDPU)) {
1390  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
1391  if (icmap_get_string_r(map, tmp_key, &str) == CS_OK) {
1392  nodeid = generate_nodeid(totem_config, str);
1393  if (nodeid == -1) {
1394  sprintf(error_string_response,
1395  "An IPV6 network requires that a node ID be specified "
1396  "for address '%s'.", node_addr_str);
1397  *error_string = error_string_response;
1398  free(str);
1399 
1400  return (-1);
1401  }
1402 
1404  "Generated nodeid = " CS_PRI_NODE_ID " for %s", nodeid, str);
1405  free(str);
1406  }
1407  }
1408 
1409  member_count = totem_config->interfaces[linknumber].member_count;
1410  res = totemip_parse(&totem_config->interfaces[linknumber].member_list[member_count],
1411  node_addr_str, totem_config->ip_version);
1412  if (res == 0) {
1413  totem_config->interfaces[linknumber].member_list[member_count].nodeid = nodeid;
1414  totem_config->interfaces[linknumber].member_count++;
1415  totem_config->interfaces[linknumber].configured = 1;
1416  } else {
1417  sprintf(error_string_response, "failed to parse node address '%s'\n", node_addr_str);
1418  *error_string = error_string_response;
1419 
1420  memset(&totem_config->interfaces[linknumber].member_list[member_count], 0,
1421  sizeof(struct totem_ip_address));
1422 
1423  free(node_addr_str);
1424  icmap_iter_finalize(iter2);
1425  icmap_iter_finalize(iter);
1426  return -1;
1427  }
1428 
1429  free(node_addr_str);
1430  }
1431 
1432  icmap_iter_finalize(iter2);
1433  }
1434 
1435  icmap_iter_finalize(iter);
1436 
1437  configure_link_params(totem_config, map);
1438  if (reload) {
1439  log_printf(LOGSYS_LEVEL_DEBUG, "About to reconfigure links from nodelist.\n");
1440 
1441  if (check_things_have_not_changed(totem_config, error_string) == -1) {
1442  return -1;
1443  }
1444  }
1445  return 0;
1446 }
1447 
1448 static void config_convert_nodelist_to_interface(icmap_map_t map, struct totem_config *totem_config)
1449 {
1450  int res = 0;
1451  int node_pos;
1452  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1453  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
1454  char *node_addr_str;
1455  unsigned int linknumber = 0;
1456  icmap_iter_t iter;
1457  const char *iter_key;
1458 
1459  node_pos = find_local_node(map, 1);
1460  if (node_pos > -1) {
1461  /*
1462  * We found node, so create interface section
1463  */
1464  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
1465  iter = icmap_iter_init_r(map, tmp_key);
1466  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1467  res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1468  if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
1469  continue ;
1470  }
1471 
1472  if (icmap_get_string_r(map, iter_key, &node_addr_str) != CS_OK) {
1473  continue;
1474  }
1475 
1476  snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
1477  icmap_set_string_r(map, tmp_key2, node_addr_str);
1478  free(node_addr_str);
1479  }
1480  icmap_iter_finalize(iter);
1481  }
1482 }
1483 
1484 static int get_interface_params(struct totem_config *totem_config, icmap_map_t map,
1485  const char **error_string, uint64_t *warnings,
1486  int reload)
1487 {
1488  int res = 0;
1489  unsigned int linknumber = 0;
1490  int member_count = 0;
1491  int i;
1492  icmap_iter_t iter, member_iter;
1493  const char *iter_key;
1494  const char *member_iter_key;
1495  char linknumber_key[ICMAP_KEYNAME_MAXLEN];
1496  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1497  uint8_t u8;
1498  uint32_t u32;
1499  char *str;
1500  char *cluster_name = NULL;
1501  enum totem_ip_version_enum tmp_ip_version = TOTEM_IP_VERSION_4;
1502  int ret = 0;
1503 
1504  if (reload) {
1505  for (i=0; i<INTERFACE_MAX; i++) {
1506  /*
1507  * Set back to defaults things that might have been configured and
1508  * now have been taken out of corosync.conf. These won't be caught by the
1509  * code below which only looks at interface{} sections that actually exist.
1510  */
1511  totem_config->interfaces[i].configured = 0;
1512  totem_config->interfaces[i].knet_ping_timeout = 0;
1513  totem_config->interfaces[i].knet_ping_interval = 0;
1515  totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
1516  }
1517  }
1518  if (icmap_get_string_r(map, "totem.cluster_name", &cluster_name) != CS_OK) {
1519  cluster_name = NULL;
1520  }
1521 
1522  iter = icmap_iter_init_r(map, "totem.interface.");
1523  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1524  res = sscanf(iter_key, "totem.interface.%[^.].%s", linknumber_key, tmp_key);
1525  if (res != 2) {
1526  continue;
1527  }
1528 
1529  if (strcmp(tmp_key, "bindnetaddr") != 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1530  continue;
1531  }
1532 
1533  member_count = 0;
1534  linknumber = atoi(linknumber_key);
1535 
1536  if (linknumber >= INTERFACE_MAX) {
1537  snprintf (error_string_response, sizeof(error_string_response),
1538  "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1539  linknumber, INTERFACE_MAX - 1);
1540 
1541  *error_string = error_string_response;
1542  ret = -1;
1543  goto out;
1544  }
1545 
1546  /* These things are only valid for the initial read */
1547  if (!reload) {
1548  /*
1549  * Get the bind net address
1550  */
1551  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
1552 
1553  if (icmap_get_string_r(map, tmp_key, &str) == CS_OK) {
1554  res = totemip_parse (&totem_config->interfaces[linknumber].bindnet, str,
1555  totem_config->ip_version);
1556 
1557  if (res) {
1558  sprintf(error_string_response, "failed to parse bindnet address '%s'\n", str);
1559  *error_string = error_string_response;
1560  free(str);
1561 
1562  ret = -1;
1563  goto out;
1564  }
1565 
1566  free(str);
1567  }
1568 
1569  /*
1570  * Get interface multicast address
1571  */
1572  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", linknumber);
1573  if (icmap_get_string_r(map, tmp_key, &str) == CS_OK) {
1574  res = totemip_parse (&totem_config->interfaces[linknumber].mcast_addr, str,
1575  totem_config->ip_version);
1576 
1577  if (res) {
1578  sprintf(error_string_response, "failed to parse mcast address '%s'\n", str);
1579  *error_string = error_string_response;
1580  free(str);
1581 
1582  ret = -1;
1583  goto out;
1584  }
1585 
1586  free(str);
1587  } else if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1588  /*
1589  * User not specified address -> autogenerate one from cluster_name key
1590  * (if available). Return code is intentionally ignored, because
1591  * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
1592  * checked later anyway.
1593  */
1594 
1595  if (totem_config->interfaces[0].bindnet.family == AF_INET) {
1596  tmp_ip_version = TOTEM_IP_VERSION_4;
1597  } else if (totem_config->interfaces[0].bindnet.family == AF_INET6) {
1598  tmp_ip_version = TOTEM_IP_VERSION_6;
1599  }
1600 
1601  (void)get_cluster_mcast_addr (cluster_name,
1602  linknumber,
1603  tmp_ip_version,
1604  &totem_config->interfaces[linknumber].mcast_addr);
1605  }
1606 
1607  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", linknumber);
1608  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1609  if (strcmp (str, "yes") == 0) {
1610  totem_config->broadcast_use = 1;
1611  }
1612  free(str);
1613  }
1614  }
1615 
1616  /* These things are only valid for the initial read OR a newly-defined link */
1617  if (!reload || (totem_config->interfaces[linknumber].configured == 0)) {
1618 
1619  /*
1620  * Get mcast port
1621  */
1622  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", linknumber);
1623  if (icmap_get_uint16_r(map, tmp_key, &totem_config->interfaces[linknumber].ip_port) != CS_OK) {
1624  if (totem_config->broadcast_use) {
1625  totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + (2 * linknumber);
1626  } else {
1627  totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + linknumber;
1628  }
1629  }
1630 
1631  /*
1632  * Get the TTL
1633  */
1634  totem_config->interfaces[linknumber].ttl = 1;
1635 
1636  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", linknumber);
1637 
1638  if (icmap_get_uint8_r(map, tmp_key, &u8) == CS_OK) {
1639  totem_config->interfaces[linknumber].ttl = u8;
1640  }
1641 
1642  totem_config->interfaces[linknumber].knet_transport = KNET_DEFAULT_TRANSPORT;
1643  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_transport", linknumber);
1644  if (icmap_get_string_r(map, tmp_key, &str) == CS_OK) {
1645  if (strcmp(str, "sctp") == 0) {
1646  totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_SCTP;
1647  }
1648  else if (strcmp(str, "udp") == 0) {
1649  totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_UDP;
1650  }
1651  else {
1652  *error_string = "Unrecognised knet_transport. expected 'udp' or 'sctp'";
1653  ret = -1;
1654  goto out;
1655  }
1656  }
1657  }
1658  totem_config->interfaces[linknumber].configured = 1;
1659 
1660  /*
1661  * Get the knet link params
1662  */
1663  totem_config->interfaces[linknumber].knet_link_priority = 1;
1664  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_link_priority", linknumber);
1665 
1666  if (icmap_get_uint8_r(map, tmp_key, &u8) == CS_OK) {
1667  totem_config->interfaces[linknumber].knet_link_priority = u8;
1668  }
1669 
1670  totem_config->interfaces[linknumber].knet_ping_interval = 0; /* real default applied later */
1671  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_interval", linknumber);
1672  if (icmap_get_uint32_r(map, tmp_key, &u32) == CS_OK) {
1673  totem_config->interfaces[linknumber].knet_ping_interval = u32;
1674  }
1675  totem_config->interfaces[linknumber].knet_ping_timeout = 0; /* real default applied later */
1676  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_timeout", linknumber);
1677  if (icmap_get_uint32_r(map, tmp_key, &u32) == CS_OK) {
1678  totem_config->interfaces[linknumber].knet_ping_timeout = u32;
1679  }
1680  totem_config->interfaces[linknumber].knet_ping_precision = KNET_PING_PRECISION;
1681  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_precision", linknumber);
1682  if (icmap_get_uint32_r(map, tmp_key, &u32) == CS_OK) {
1683  totem_config->interfaces[linknumber].knet_ping_precision = u32;
1684  }
1685  totem_config->interfaces[linknumber].knet_pong_count = KNET_PONG_COUNT;
1686  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_pong_count", linknumber);
1687  if (icmap_get_uint32_r(map, tmp_key, &u32) == CS_OK) {
1688  totem_config->interfaces[linknumber].knet_pong_count = u32;
1689  }
1690 
1691  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", linknumber);
1692  member_iter = icmap_iter_init_r(map, tmp_key);
1693  while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1694  if (member_count == 0) {
1695  if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
1696  free(str);
1698  break;
1699  } else {
1701  }
1702  }
1703 
1704  if (icmap_get_string_r(map, member_iter_key, &str) == CS_OK) {
1705  res = totemip_parse (&totem_config->interfaces[linknumber].member_list[member_count++],
1706  str, totem_config->ip_version);
1707  if (res) {
1708  sprintf(error_string_response, "failed to parse node address '%s'\n", str);
1709  *error_string = error_string_response;
1710 
1711  icmap_iter_finalize(member_iter);
1712  free(str);
1713  ret = -1;
1714  goto out;
1715  }
1716 
1717  free(str);
1718  }
1719  }
1720  icmap_iter_finalize(member_iter);
1721 
1722  totem_config->interfaces[linknumber].member_count = member_count;
1723 
1724  }
1725 
1726 out:
1727  icmap_iter_finalize(iter);
1728  free(cluster_name);
1729 
1730  return (ret);
1731 }
1732 
1733 extern int totem_config_read (
1734  struct totem_config *totem_config,
1735  const char **error_string,
1736  uint64_t *warnings)
1737 {
1738  int res = 0;
1739  char *str, *ring0_addr_str;
1740  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1741  uint16_t u16;
1742  int i;
1743  int local_node_pos;
1744  int nodeid_set;
1745 
1746  *warnings = 0;
1747 
1748  memset (totem_config, 0, sizeof (struct totem_config));
1749  totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
1750  if (totem_config->interfaces == 0) {
1751  *error_string = "Out of memory trying to allocate ethernet interface storage area";
1752  return -1;
1753  }
1754 
1755  totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1756  if (icmap_get_string("totem.transport", &str) == CS_OK) {
1757  if (strcmp (str, "udpu") == 0) {
1758  totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
1759  } else if (strcmp (str, "udp") == 0) {
1760  totem_config->transport_number = TOTEM_TRANSPORT_UDP;
1761  } else if (strcmp (str, "knet") == 0) {
1762  totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1763  } else {
1764  *error_string = "Invalid transport type. Should be udpu, udp or knet";
1765  free(str);
1766  return -1;
1767  }
1768 
1769  free(str);
1770  }
1771 
1772  memset (totem_config->interfaces, 0,
1773  sizeof (struct totem_interface) * INTERFACE_MAX);
1774 
1775  strcpy (totem_config->link_mode, "passive");
1776 
1777  icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
1778 
1779  /* initial crypto load */
1780  if (totem_get_crypto(totem_config, icmap_get_global_map(), error_string) != 0) {
1781  return -1;
1782  }
1783  if (totem_config_keyread(totem_config, icmap_get_global_map(), error_string) != 0) {
1784  return -1;
1785  }
1786  totem_config->crypto_index = 1;
1787  totem_config->crypto_changed = 0;
1788 
1789  if (icmap_get_string("totem.link_mode", &str) == CS_OK) {
1790  if (strlen(str) >= TOTEM_LINK_MODE_BYTES) {
1791  *error_string = "totem.link_mode is too long";
1792  free(str);
1793 
1794  return -1;
1795  }
1796  strcpy (totem_config->link_mode, str);
1797  free(str);
1798  }
1799 
1800  icmap_get_uint32("totem.nodeid", &totem_config->node_id);
1801 
1802  totem_config->clear_node_high_bit = 0;
1803  if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
1804  if (strcmp (str, "yes") == 0) {
1805  totem_config->clear_node_high_bit = 1;
1806  }
1807  free(str);
1808  }
1809 
1810  icmap_get_uint32("totem.threads", &totem_config->threads);
1811 
1812  icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
1813 
1814  totem_config->ip_version = totem_config_get_ip_version(totem_config);
1815 
1816  if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
1817  /*
1818  * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
1819  */
1820  config_convert_nodelist_to_interface(icmap_get_global_map(), totem_config);
1821  } else {
1822  if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str) == CS_OK) {
1823  /*
1824  * Both bindnetaddr and ring0_addr are set.
1825  * Log warning information, and use nodelist instead
1826  */
1828 
1829  config_convert_nodelist_to_interface(icmap_get_global_map(), totem_config);
1830 
1831  free(ring0_addr_str);
1832  }
1833 
1834  free(str);
1835  }
1836 
1837  /*
1838  * Broadcast option is global but set in interface section,
1839  * so reset before processing interfaces.
1840  */
1841  totem_config->broadcast_use = 0;
1842 
1843  res = get_interface_params(totem_config, icmap_get_global_map(), error_string, warnings, 0);
1844  if (res < 0) {
1845  return res;
1846  }
1847 
1848  /*
1849  * Use broadcast is global, so if set, make sure to fill mcast addr correctly
1850  * broadcast is only supported for UDP so just do interface 0;
1851  */
1852  if (totem_config->broadcast_use) {
1853  totemip_parse (&totem_config->interfaces[0].mcast_addr,
1854  "255.255.255.255", TOTEM_IP_VERSION_4);
1855  }
1856 
1857 
1858  /*
1859  * Store automatically generated items back to icmap only for UDP
1860  */
1861  if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1862  for (i = 0; i < INTERFACE_MAX; i++) {
1863  if (!totem_config->interfaces[i].configured) {
1864  continue;
1865  }
1866  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
1867  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1868  free(str);
1869  } else {
1870  str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
1871  icmap_set_string(tmp_key, str);
1872  }
1873 
1874  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
1875  if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
1876  icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
1877  }
1878  }
1879  }
1880 
1881  /*
1882  * Check existence of nodelist
1883  */
1884  if ((icmap_get_string("nodelist.node.0.name", &str) == CS_OK) ||
1885  (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK)) {
1886  free(str);
1887  /*
1888  * find local node
1889  */
1890  local_node_pos = find_local_node(icmap_get_global_map(), 1);
1891  if (local_node_pos != -1) {
1892 
1893  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
1894 
1895  nodeid_set = (totem_config->node_id != 0);
1896  if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
1898  }
1899  if ((totem_config->transport_number == TOTEM_TRANSPORT_KNET) && (!totem_config->node_id)) {
1900  *error_string = "Knet requires an explicit nodeid for the local node";
1901  return -1;
1902  }
1903 
1904  if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
1905  totem_config->transport_number == TOTEM_TRANSPORT_UDPU) && (!totem_config->node_id)) {
1906 
1907  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
1908  icmap_get_string(tmp_key, &str);
1909 
1910  totem_config->node_id = generate_nodeid(totem_config, str);
1911  if (totem_config->node_id == -1) {
1912  *error_string = "An IPV6 network requires that a node ID be specified";
1913 
1914  free(str);
1915  return (-1);
1916  }
1917 
1918  totem_config->interfaces[0].member_list[local_node_pos].nodeid = totem_config->node_id;
1919 
1920  free(str);
1921  }
1922 
1923  /* Users must not change this */
1924  icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
1925  }
1926 
1927  if (put_nodelist_members_to_config(totem_config, icmap_get_global_map(), 0, error_string)) {
1928  return -1;
1929  }
1930  }
1931 
1932  /*
1933  * Get things that might change in the future (and can depend on totem_config->interfaces);
1934  */
1935  totem_volatile_config_read(totem_config, icmap_get_global_map(), NULL);
1936 
1937  calc_knet_ping_timers(totem_config);
1938 
1939  /* This is now done in the totemknet interface callback */
1940  /* configure_totem_links(totem_config, icmap_get_global_map()); */
1941 
1942  add_totem_config_notification(totem_config);
1943 
1944  return 0;
1945 }
1946 
1947 
1949  struct totem_config *totem_config,
1950  const char **error_string)
1951 {
1952  static char local_error_reason[512];
1953  char parse_error[512];
1954  const char *error_reason = local_error_reason;
1955  int i;
1956  uint32_t u32;
1957  int num_configured = 0;
1958  unsigned int interface_max = INTERFACE_MAX;
1959 
1960  for (i = 0; i < INTERFACE_MAX; i++) {
1961  if (totem_config->interfaces[i].configured) {
1962  num_configured++;
1963  }
1964  }
1965  if (num_configured == 0) {
1966  error_reason = "No interfaces defined";
1967  goto parse_error;
1968  }
1969 
1970  /* Check we found a local node name */
1971  if (icmap_get_uint32("nodelist.local_node_pos", &u32) != CS_OK) {
1972  error_reason = "No valid name found for local host";
1973  goto parse_error;
1974  }
1975 
1976  for (i = 0; i < INTERFACE_MAX; i++) {
1977  /*
1978  * Some error checking of parsed data to make sure its valid
1979  */
1980 
1981  struct totem_ip_address null_addr;
1982 
1983  if (!totem_config->interfaces[i].configured) {
1984  continue;
1985  }
1986 
1987  memset (&null_addr, 0, sizeof (struct totem_ip_address));
1988 
1989  if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP) &&
1990  memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
1991  sizeof (struct totem_ip_address)) == 0) {
1992  snprintf (local_error_reason, sizeof(local_error_reason),
1993  "No multicast address specified for interface %u", i);
1994  goto parse_error;
1995  }
1996 
1997  if (totem_config->interfaces[i].ip_port == 0) {
1998  snprintf (local_error_reason, sizeof(local_error_reason),
1999  "No multicast port specified for interface %u", i);
2000  goto parse_error;
2001  }
2002 
2003  if (totem_config->interfaces[i].ttl > 255) {
2004  snprintf (local_error_reason, sizeof(local_error_reason),
2005  "Invalid TTL (should be 0..255) for interface %u", i);
2006  goto parse_error;
2007  }
2008  if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
2009  totem_config->interfaces[i].ttl != 1) {
2010  snprintf (local_error_reason, sizeof(local_error_reason),
2011  "Can only set ttl on multicast transport types for interface %u", i);
2012  goto parse_error;
2013  }
2014  if (totem_config->interfaces[i].knet_link_priority > 255) {
2015  snprintf (local_error_reason, sizeof(local_error_reason),
2016  "Invalid link priority (should be 0..255) for interface %u", i);
2017  goto parse_error;
2018  }
2019  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET &&
2020  totem_config->interfaces[i].knet_link_priority != 1) {
2021  snprintf (local_error_reason, sizeof(local_error_reason),
2022  "Can only set link priority on knet transport type for interface %u", i);
2023  goto parse_error;
2024  }
2025 
2026  if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
2027  totem_config->node_id == 0) {
2028  snprintf (local_error_reason, sizeof(local_error_reason),
2029  "An IPV6 network requires that a node ID be specified for interface %u", i);
2030  goto parse_error;
2031  }
2032 
2033  if (totem_config->broadcast_use == 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
2034  if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
2035  snprintf (local_error_reason, sizeof(local_error_reason),
2036  "Multicast address family does not match bind address family for interface %u", i);
2037  goto parse_error;
2038  }
2039 
2040  if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
2041  snprintf (local_error_reason, sizeof(local_error_reason),
2042  "mcastaddr is not a correct multicast address for interface %u", i);
2043  goto parse_error;
2044  }
2045  }
2046  }
2047 
2048  if (totem_config->version != 2) {
2049  error_reason = "This totem parser can only parse version 2 configurations.";
2050  goto parse_error;
2051  }
2052 
2053  if (totem_volatile_config_validate(totem_config, icmap_get_global_map(), error_string) == -1) {
2054  return (-1);
2055  }
2056 
2057  if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
2058  return (-1);
2059  }
2060 
2061  /*
2062  * KNET Link values validation
2063  */
2064  if (strcmp (totem_config->link_mode, "active") &&
2065  strcmp (totem_config->link_mode, "rr") &&
2066  strcmp (totem_config->link_mode, "passive")) {
2067  snprintf (local_error_reason, sizeof(local_error_reason),
2068  "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->link_mode);
2069  goto parse_error;
2070  }
2071 
2072  /* Only Knet does multiple interfaces */
2073  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
2074  interface_max = 1;
2075  }
2076 
2077  if (interface_max < num_configured) {
2078  snprintf (parse_error, sizeof(parse_error),
2079  "%d is too many configured interfaces for non-Knet transport.",
2080  num_configured);
2081  error_reason = parse_error;
2082  goto parse_error;
2083  }
2084 
2085  /* Only knet allows crypto */
2086  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
2087  if ((strcmp(totem_config->crypto_cipher_type, "none") != 0) ||
2088  (strcmp(totem_config->crypto_hash_type, "none") != 0)) {
2089 
2090  snprintf (parse_error, sizeof(parse_error),
2091  "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2092  error_reason = parse_error;
2093  goto parse_error;
2094  }
2095  }
2096 
2097  if (totem_config->net_mtu == 0) {
2098  if (totem_config->transport_number == TOTEM_TRANSPORT_KNET) {
2099  totem_config->net_mtu = KNET_MAX_PACKET_SIZE;
2100  }
2101  else {
2102  totem_config->net_mtu = 1500;
2103  }
2104  }
2105 
2106  return 0;
2107 
2108 parse_error:
2109  snprintf (error_string_response, sizeof(error_string_response),
2110  "parse error in config: %s\n", error_reason);
2111  *error_string = error_string_response;
2112  return (-1);
2113 
2114 }
2115 
2116 static int read_keyfile (
2117  const char *key_location,
2118  struct totem_config *totem_config,
2119  const char **error_string)
2120 {
2121  int fd;
2122  int res;
2123  int saved_errno;
2124  char error_str[100];
2125  const char *error_ptr;
2126 
2127  fd = open (key_location, O_RDONLY);
2128  if (fd == -1) {
2129  error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
2130  snprintf (error_string_response, sizeof(error_string_response),
2131  "Could not open %s: %s\n",
2132  key_location, error_ptr);
2133  goto parse_error;
2134  }
2135 
2136  res = read (fd, totem_config->private_key, TOTEM_PRIVATE_KEY_LEN_MAX);
2137  saved_errno = errno;
2138  close (fd);
2139 
2140  if (res == -1) {
2141  error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
2142  snprintf (error_string_response, sizeof(error_string_response),
2143  "Could not read %s: %s\n",
2144  key_location, error_ptr);
2145  goto parse_error;
2146  }
2147 
2148  if (res < TOTEM_PRIVATE_KEY_LEN_MIN) {
2149  snprintf (error_string_response, sizeof(error_string_response),
2150  "Could only read %d bits of minimum %u bits from %s.\n",
2151  res * 8, TOTEM_PRIVATE_KEY_LEN_MIN * 8, key_location);
2152  goto parse_error;
2153  }
2154 
2155  totem_config->private_key_len = res;
2156 
2157  return 0;
2158 
2159 parse_error:
2160  *error_string = error_string_response;
2161  return (-1);
2162 }
2163 
2165  struct totem_config *totem_config,
2166  icmap_map_t map,
2167  const char **error_string)
2168 {
2169  int got_key = 0;
2170  char *key_location = NULL;
2171  int res;
2172  size_t key_len;
2173  char old_key[TOTEM_PRIVATE_KEY_LEN_MAX];
2174  size_t old_key_len;
2175 
2176  /* Take a copy so we can see if it has changed */
2177  memcpy(old_key, totem_config->private_key, sizeof(totem_config->private_key));
2178  old_key_len = totem_config->private_key_len;
2179 
2180  memset (totem_config->private_key, 0, sizeof(totem_config->private_key));
2181  totem_config->private_key_len = 0;
2182 
2183  if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
2184  strcmp(totem_config->crypto_hash_type, "none") == 0) {
2185  return (0);
2186  }
2187 
2188  /* cmap may store the location of the key file */
2189  if (icmap_get_string_r(map, "totem.keyfile", &key_location) == CS_OK) {
2190  res = read_keyfile(key_location, totem_config, error_string);
2191  free(key_location);
2192  if (res) {
2193  goto key_error;
2194  }
2195  got_key = 1;
2196  } else { /* Or the key itself may be in the cmap */
2197  if (icmap_get_r(map, "totem.key", NULL, &key_len, NULL) == CS_OK) {
2198  if (key_len > sizeof(totem_config->private_key)) {
2199  sprintf(error_string_response, "key is too long");
2200  goto key_error;
2201  }
2202  if (key_len < TOTEM_PRIVATE_KEY_LEN_MIN) {
2203  sprintf(error_string_response, "key is too short");
2204  goto key_error;
2205  }
2206  if (icmap_get_r(map, "totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
2207  totem_config->private_key_len = key_len;
2208  got_key = 1;
2209  } else {
2210  sprintf(error_string_response, "can't load private key");
2211  goto key_error;
2212  }
2213  }
2214  }
2215 
2216  /* In desperation we read the default filename */
2217  if (!got_key) {
2218  res = read_keyfile(COROSYSCONFDIR "/authkey", totem_config, error_string);
2219  if (res)
2220  goto key_error;
2221  }
2222 
2223  if (old_key_len != totem_config->private_key_len ||
2224  memcmp(old_key, totem_config->private_key, sizeof(totem_config->private_key))) {
2225  totem_config->crypto_changed = 1;
2226  }
2227 
2228  return (0);
2229 
2230 key_error:
2231  *error_string = error_string_response;
2232  return (-1);
2233 
2234 }
2235 
2236 int totem_reread_crypto_config(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
2237 {
2238  if (totem_get_crypto(totem_config, map, error_string) != 0) {
2239  return -1;
2240  }
2241  if (totem_config_keyread(totem_config, map, error_string) != 0) {
2242  return -1;
2243  }
2244  return 0;
2245 }
2246 
2247 static void debug_dump_totem_config(const struct totem_config *totem_config)
2248 {
2249 
2250  log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
2251  totem_config->token_timeout, totem_config->token_retransmit_timeout);
2252  if (totem_config->token_warning) {
2253  uint32_t token_warning_ms = totem_config->token_warning * totem_config->token_timeout / 100;
2254  log_printf(LOGSYS_LEVEL_DEBUG, "Token warning every %d ms (%d%% of Token Timeout)",
2255  token_warning_ms, totem_config->token_warning);
2256  if (token_warning_ms < totem_config->token_retransmit_timeout)
2258  "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) "
2259  "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2260  token_warning_ms, totem_config->token_retransmit_timeout);
2261 
2262  } else
2263  log_printf(LOGSYS_LEVEL_DEBUG, "Token warnings disabled");
2264  log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
2265  totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
2266  log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
2267  totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
2268  totem_config->merge_timeout);
2269  log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
2270  totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
2272  "seqno unchanged const (%d rotations) Maximum network MTU %d",
2273  totem_config->seqno_unchanged_const, totem_config->net_mtu);
2275  "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2276  totem_config->window_size, totem_config->max_messages);
2277  log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
2278  log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
2279  totem_config->heartbeat_failures_allowed);
2280  log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
2281 }
2282 
2283 
2284 static void totem_change_notify(
2285  int32_t event,
2286  const char *key_name,
2287  struct icmap_notify_value new_val,
2288  struct icmap_notify_value old_val,
2289  void *user_data)
2290 {
2291  struct totem_config *totem_config = (struct totem_config *)user_data;
2292  uint32_t *param;
2293  uint8_t reloading;
2294  const char *deleted_key = NULL;
2295  const char *error_string;
2296 
2297  /*
2298  * If a full reload is in progress then don't do anything until it's done and
2299  * can reconfigure it all atomically
2300  */
2301  if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
2302  return;
2303 
2304  param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
2305  /*
2306  * Process change only if changed key is found in totem_config (-> param is not NULL)
2307  * or for special key token_coefficient. token_coefficient key is not stored in
2308  * totem_config, but it is used for computation of token timeout.
2309  */
2310  if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
2311  return;
2312 
2313  /*
2314  * Values other than UINT32 are not supported, or needed (yet)
2315  */
2316  switch (event) {
2317  case ICMAP_TRACK_DELETE:
2318  deleted_key = key_name;
2319  break;
2320  case ICMAP_TRACK_ADD:
2321  case ICMAP_TRACK_MODIFY:
2322  deleted_key = NULL;
2323  break;
2324  default:
2325  break;
2326  }
2327 
2328  totem_volatile_config_read (totem_config, icmap_get_global_map(), deleted_key);
2329  log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
2330  debug_dump_totem_config(totem_config);
2331  if (totem_volatile_config_validate(totem_config, icmap_get_global_map(), &error_string) == -1) {
2332  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
2333  /*
2334  * TODO: Consider corosync exit and/or load defaults for volatile
2335  * values. For now, log error seems to be enough
2336  */
2337  }
2338 }
2339 
2340 
2342  struct totem_config *totem_config,
2343  icmap_map_t map,
2344  const char **error_string)
2345 {
2346  uint64_t warnings = 0LL;
2347 
2348  get_interface_params(totem_config, map, error_string, &warnings, 1);
2349  if (put_nodelist_members_to_config (totem_config, map, 1, error_string)) {
2350  return -1;
2351  }
2352 
2353  calc_knet_ping_timers(totem_config);
2354 
2355  log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
2356  debug_dump_totem_config(totem_config);
2357 
2358  /* Reinstate the local_node_pos */
2359  (void)find_local_node(map, 0);
2360 
2361  return 0;
2362 }
2363 
2365  struct totem_config *totem_config,
2366  icmap_map_t map)
2367 {
2368  struct totem_interface *new_interfaces = NULL;
2369 
2370  new_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
2371  assert(new_interfaces != NULL);
2372  memcpy(new_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
2373 
2374  /* Set link parameters including local_ip */
2375  configure_totem_links(totem_config, map);
2376 
2377  /* Add & remove nodes */
2378  compute_and_set_totempg_interfaces(totem_config->orig_interfaces, new_interfaces);
2379 
2380  /* Does basic global params (like compression) */
2382 
2383  free(new_interfaces);
2384 }
2385 
2386 static void add_totem_config_notification(struct totem_config *totem_config)
2387 {
2389 
2390  icmap_track_add("totem.",
2392  totem_change_notify,
2393  totem_config,
2394  &icmap_track);
2395 }
unsigned int clear_node_high_bit
Definition: totem.h:168
unsigned short family
Definition: coroapi.h:113
int totempg_iface_set(struct totem_ip_address *interface_addr, unsigned short ip_port, unsigned int iface_no)
Definition: totempg.c:1434
int knet_ping_precision
Definition: totem.h:94
char knet_compression_model[CONFIG_STRING_LEN_MAX]
Definition: totem.h:233
#define BLOCK_UNLISTED_IPS
Definition: totemconfig.c:83
int crypto_changed
Definition: totem.h:231
cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
Definition: icmap.c:802
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
Definition: icmap.c:1095
#define LOGSYS_LEVEL_INFO
Definition: logsys.h:75
int knet_link_priority
Definition: totem.h:91
uint32_t value
struct totem_interface * interfaces
Definition: totem.h:165
totem_ip_version_enum
Definition: totemip.h:70
The totem_ip_address struct.
Definition: coroapi.h:111
#define DEFAULT_PORT
Definition: totemconfig.c:93
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:256
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:114
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1116
totem_transport_t transport_number
Definition: totem.h:239
void totemconfig_commit_new_params(struct totem_config *totem_config, icmap_map_t map)
Definition: totemconfig.c:2364
#define CS_PRI_NODE_ID
Definition: corotypes.h:59
#define DOWNCHECK_TIMEOUT
Definition: totemconfig.c:74
unsigned int token_hold_timeout
Definition: totem.h:187
int member_count
Definition: totem.h:90
struct totem_ip_address member_list[PROCESSOR_COUNT_MAX]
Definition: totem.h:97
uint32_t knet_compression_threshold
Definition: totem.h:235
cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
Definition: icmap.c:521
#define TOKEN_WARNING
Definition: totemconfig.c:70
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
Definition: totem.h:227
char link_mode[TOTEM_LINK_MODE_BYTES]
Definition: totem.h:205
unsigned int knet_pmtud_interval
Definition: totem.h:169
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
#define COROSYSCONFDIR
Definition: config.h:11
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:627
int totemip_is_mcast(struct totem_ip_address *addr)
Definition: totemip.c:134
struct totem_ip_address local_ip
Definition: totem.h:86
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:264
unsigned int downcheck_timeout
Definition: totem.h:199
#define KNET_DEFAULT_TRANSPORT
Definition: totemconfig.c:91
unsigned int private_key_len
Definition: totem.h:176
#define SEQNO_UNCHANGED_CONST
Definition: totemconfig.c:76
unsigned int max_network_delay
Definition: totem.h:215
#define log_printf(level, format, args...)
Definition: logsys.h:323
unsigned int heartbeat_failures_allowed
Definition: totem.h:213
cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
Definition: icmap.c:820
unsigned int send_join_timeout
Definition: totem.h:193
unsigned int window_size
Definition: totem.h:217
cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
Definition: icmap.c:557
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
#define INTERFACE_MAX
Definition: coroapi.h:88
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
unsigned int block_unlisted_ips
Definition: totem.h:245
#define MINIMUM_TIMEOUT
Definition: totemconfig.c:77
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:868
uint16_t ttl
Definition: totem.h:88
unsigned int node_id
Definition: totem.h:167
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
unsigned int token_retransmits_before_loss_const
Definition: totem.h:189
uint8_t configured
Definition: totem.h:89
#define FAIL_TO_RECV_CONST
Definition: totemconfig.c:75
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:597
unsigned int seqno_unchanged_const
Definition: totem.h:203
void * user_data
Definition: sam.c:127
unsigned int miss_count_const
Definition: totem.h:241
unsigned int join_timeout
Definition: totem.h:191
int totem_config_validate(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:1948
unsigned int nodeid
Definition: coroapi.h:112
#define TOTEM_CONFIG_BINDNETADDR_NODELIST_SET
Definition: totemconfig.h:48
cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
Definition: icmap.c:527
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
cs_error_t icmap_get_string_r(const icmap_map_t map, const char *key_name, char **str)
Definition: icmap.c:735
int totem_volatile_config_validate(struct totem_config *totem_config, icmap_map_t temp_map, const char **error_string)
Definition: totemconfig.c:368
int knet_transport
Definition: totem.h:96
struct totem_ip_address mcast_addr
Definition: totem.h:85
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:72
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
Definition: totem.h:174
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:76
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:585
unsigned int fail_to_recv_const
Definition: totem.h:201
cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
Definition: icmap.c:826
#define TOKEN_COEFFICIENT
Definition: totemconfig.c:71
int totempg_member_remove(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1559
#define TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
Definition: totemconfig.h:46
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:892
uint8_t param
#define TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
Definition: totemconfig.h:45
uint16_t ip_port
Definition: totem.h:87
int knet_compression_level
Definition: totem.h:237
cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
Definition: icmap.c:814
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
Definition: totemip.c:306
#define swab32(x)
The swab32 macro.
Definition: swab.h:51
#define WINDOW_SIZE
Definition: totemconfig.c:80
int version
Definition: totem.h:160
unsigned int net_mtu
Definition: totem.h:209
#define MAX_NETWORK_DELAY
Definition: totemconfig.c:79
void totem_volatile_config_read(struct totem_config *totem_config, icmap_map_t temp_map, const char *deleted_key)
Definition: totemconfig.c:303
#define TOKEN_TIMEOUT
Definition: totemconfig.c:69
#define MERGE_TIMEOUT
Definition: totemconfig.c:73
unsigned int token_timeout
Definition: totem.h:181
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
Definition: totem.h:225
#define JOIN_TIMEOUT
Definition: totemconfig.c:72
unsigned int consensus_timeout
Definition: totem.h:195
#define PROCESSOR_COUNT_MAX
Definition: coroapi.h:96
int crypto_index
Definition: totem.h:229
unsigned int token_warning
Definition: totem.h:183
int totempg_reconfigure(void)
Definition: totempg.c:1566
char crypto_model[CONFIG_STRING_LEN_MAX]
Definition: totem.h:223
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
Definition: totemconfig.c:68
#define MISS_COUNT_CONST
Definition: totemconfig.c:82
unsigned int broadcast_use
Definition: totem.h:221
cs_error_t icmap_get_r(const icmap_map_t map, const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Same as icmap_get but it&#39;s reentrant and operates on given icmap_map.
Definition: icmap.c:692
int totemconfig_configure_new_params(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2341
int totem_reread_crypto_config(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2236
#define KNET_PING_PRECISION
Definition: totemconfig.c:88
struct totem_interface * orig_interfaces
Definition: totem.h:166
#define KNET_PONG_COUNT
Definition: totemconfig.c:89
int knet_pong_count
Definition: totem.h:95
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition: icmap.c:856
int knet_ping_interval
Definition: totem.h:92
int knet_ping_timeout
Definition: totem.h:93
#define KNET_PMTUD_INTERVAL
Definition: totemconfig.c:90
unsigned int max_messages
Definition: totem.h:219
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Set read-only access for given key (key_name) or prefix, If prefix is set.
Definition: icmap.c:1225
int totem_config_keyread(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2164
unsigned int merge_timeout
Definition: totem.h:197
enum totem_ip_version_enum ip_version
Definition: totem.h:243
unsigned int token_retransmit_timeout
Definition: totem.h:185
struct totem_ip_address bindnet
Definition: totem.h:83
unsigned int nodeid
Definition: coroapi.h:75
icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
Definition: icmap.c:1084
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1089
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:880
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
Definition: totemconfig.h:47
#define MAX_MESSAGES
Definition: totemconfig.c:81
#define MINIMUM_TIMEOUT_HOLD
Definition: totemconfig.c:78
unsigned int threads
Definition: totem.h:211
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
Structure passed as new_value and old_value in change callback.
Definition: icmap.h:91
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
Definition: icmap.c:1159
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
Definition: totemconfig.c:1733
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
Definition: icmap.h:85
#define CONFIG_STRING_LEN_MAX
Definition: totem.h:54
int totempg_member_add(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1552