totemconfig.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2013 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. * Jan Friesse (jfriesse@redhat.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <config.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <errno.h>
  41. #include <unistd.h>
  42. #include <sys/socket.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. #include <fcntl.h>
  46. #include <netinet/in.h>
  47. #include <arpa/inet.h>
  48. #include <sys/param.h>
  49. #include <corosync/swab.h>
  50. #include <corosync/list.h>
  51. #include <qb/qbdefs.h>
  52. #include <corosync/totem/totem.h>
  53. #include <corosync/config.h>
  54. #include <corosync/logsys.h>
  55. #include <corosync/icmap.h>
  56. #include "util.h"
  57. #include "totemconfig.h"
  58. #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
  59. #define TOKEN_TIMEOUT 1000
  60. #define TOKEN_COEFFICIENT 650
  61. #define JOIN_TIMEOUT 50
  62. #define MERGE_TIMEOUT 200
  63. #define DOWNCHECK_TIMEOUT 1000
  64. #define FAIL_TO_RECV_CONST 2500
  65. #define SEQNO_UNCHANGED_CONST 30
  66. #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
  67. #define MAX_NETWORK_DELAY 50
  68. #define WINDOW_SIZE 50
  69. #define MAX_MESSAGES 17
  70. #define MISS_COUNT_CONST 5
  71. #define RRP_PROBLEM_COUNT_TIMEOUT 2000
  72. #define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT 10
  73. #define RRP_PROBLEM_COUNT_THRESHOLD_MIN 2
  74. #define RRP_AUTORECOVERY_CHECK_TIMEOUT 1000
  75. #define DEFAULT_PORT 5405
  76. static char error_string_response[512];
  77. static void add_totem_config_notification(struct totem_config *totem_config);
  78. /* All the volatile parameters are uint32s, luckily */
  79. static uint32_t *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
  80. {
  81. if (strcmp(param_name, "totem.token") == 0)
  82. return &totem_config->token_timeout;
  83. if (strcmp(param_name, "totem.token_retransmit") == 0)
  84. return &totem_config->token_retransmit_timeout;
  85. if (strcmp(param_name, "totem.hold") == 0)
  86. return &totem_config->token_hold_timeout;
  87. if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
  88. return &totem_config->token_retransmits_before_loss_const;
  89. if (strcmp(param_name, "totem.join") == 0)
  90. return &totem_config->join_timeout;
  91. if (strcmp(param_name, "totem.send_join") == 0)
  92. return &totem_config->send_join_timeout;
  93. if (strcmp(param_name, "totem.consensus") == 0)
  94. return &totem_config->consensus_timeout;
  95. if (strcmp(param_name, "totem.merge") == 0)
  96. return &totem_config->merge_timeout;
  97. if (strcmp(param_name, "totem.downcheck") == 0)
  98. return &totem_config->downcheck_timeout;
  99. if (strcmp(param_name, "totem.fail_recv_const") == 0)
  100. return &totem_config->fail_to_recv_const;
  101. if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
  102. return &totem_config->seqno_unchanged_const;
  103. if (strcmp(param_name, "totem.rrp_token_expired_timeout") == 0)
  104. return &totem_config->rrp_token_expired_timeout;
  105. if (strcmp(param_name, "totem.rrp_problem_count_timeout") == 0)
  106. return &totem_config->rrp_problem_count_timeout;
  107. if (strcmp(param_name, "totem.rrp_problem_count_threshold") == 0)
  108. return &totem_config->rrp_problem_count_threshold;
  109. if (strcmp(param_name, "totem.rrp_problem_count_mcast_threshold") == 0)
  110. return &totem_config->rrp_problem_count_mcast_threshold;
  111. if (strcmp(param_name, "totem.rrp_autorecovery_check_timeout") == 0)
  112. return &totem_config->rrp_autorecovery_check_timeout;
  113. if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
  114. return &totem_config->heartbeat_failures_allowed;
  115. if (strcmp(param_name, "totem.max_network_delay") == 0)
  116. return &totem_config->max_network_delay;
  117. if (strcmp(param_name, "totem.window_size") == 0)
  118. return &totem_config->window_size;
  119. if (strcmp(param_name, "totem.max_messages") == 0)
  120. return &totem_config->max_messages;
  121. if (strcmp(param_name, "totem.miss_count_const") == 0)
  122. return &totem_config->miss_count_const;
  123. return NULL;
  124. }
  125. /*
  126. * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
  127. * and readed value is zero, default value is used and stored into totem_config.
  128. */
  129. static void totem_volatile_config_set_value (struct totem_config *totem_config,
  130. const char *key_name, const char *deleted_key, unsigned int default_value,
  131. int allow_zero_value)
  132. {
  133. if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
  134. (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  135. (!allow_zero_value && *totem_get_param_by_name(totem_config, key_name) == 0)) {
  136. *totem_get_param_by_name(totem_config, key_name) = default_value;
  137. }
  138. }
  139. /*
  140. * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
  141. * default value is stored. deleted_key is name of key beeing processed by delete operation
  142. * from cmap. It is considered as non existing even if it can be read. Can be NULL.
  143. */
  144. static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
  145. {
  146. uint32_t u32;
  147. totem_volatile_config_set_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
  148. TOKEN_RETRANSMITS_BEFORE_LOSS_CONST, 0);
  149. totem_volatile_config_set_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
  150. if (totem_config->interface_count > 0 && totem_config->interfaces[0].member_count > 2) {
  151. u32 = TOKEN_COEFFICIENT;
  152. icmap_get_uint32("totem.token_coefficient", &u32);
  153. totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
  154. }
  155. totem_volatile_config_set_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
  156. totem_volatile_config_set_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
  157. totem_volatile_config_set_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
  158. totem_volatile_config_set_value(totem_config, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
  159. totem_volatile_config_set_value(totem_config, "totem.token_retransmit", deleted_key,
  160. (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
  161. totem_volatile_config_set_value(totem_config, "totem.hold", deleted_key,
  162. (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
  163. totem_volatile_config_set_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
  164. totem_volatile_config_set_value(totem_config, "totem.consensus", deleted_key,
  165. (int)(float)(1.2 * totem_config->token_timeout), 0);
  166. totem_volatile_config_set_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
  167. totem_volatile_config_set_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
  168. totem_volatile_config_set_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
  169. totem_volatile_config_set_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
  170. SEQNO_UNCHANGED_CONST, 0);
  171. totem_volatile_config_set_value(totem_config, "totem.send_join", deleted_key, 0, 1);
  172. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_timeout", deleted_key,
  173. RRP_PROBLEM_COUNT_TIMEOUT, 0);
  174. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_threshold", deleted_key,
  175. RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT, 0);
  176. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_mcast_threshold", deleted_key,
  177. totem_config->rrp_problem_count_threshold * 10, 0);
  178. totem_volatile_config_set_value(totem_config, "totem.rrp_token_expired_timeout", deleted_key,
  179. totem_config->token_retransmit_timeout, 0);
  180. totem_volatile_config_set_value(totem_config, "totem.rrp_autorecovery_check_timeout", deleted_key,
  181. RRP_AUTORECOVERY_CHECK_TIMEOUT, 0);
  182. totem_volatile_config_set_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
  183. }
  184. static int totem_volatile_config_validate (
  185. struct totem_config *totem_config,
  186. const char **error_string)
  187. {
  188. static char local_error_reason[512];
  189. const char *error_reason = local_error_reason;
  190. if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
  191. snprintf (local_error_reason, sizeof(local_error_reason),
  192. "The max_network_delay parameter (%d ms) may not be less then (%d ms).",
  193. totem_config->max_network_delay, MINIMUM_TIMEOUT);
  194. goto parse_error;
  195. }
  196. if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
  197. snprintf (local_error_reason, sizeof(local_error_reason),
  198. "The token timeout parameter (%d ms) may not be less then (%d ms).",
  199. totem_config->token_timeout, MINIMUM_TIMEOUT);
  200. goto parse_error;
  201. }
  202. if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
  203. snprintf (local_error_reason, sizeof(local_error_reason),
  204. "The token retransmit timeout parameter (%d ms) may not be less then (%d ms).",
  205. totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT);
  206. goto parse_error;
  207. }
  208. if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) {
  209. snprintf (local_error_reason, sizeof(local_error_reason),
  210. "The token hold timeout parameter (%d ms) may not be less then (%d ms).",
  211. totem_config->token_hold_timeout, MINIMUM_TIMEOUT);
  212. goto parse_error;
  213. }
  214. if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
  215. snprintf (local_error_reason, sizeof(local_error_reason),
  216. "The join timeout parameter (%d ms) may not be less then (%d ms).",
  217. totem_config->join_timeout, MINIMUM_TIMEOUT);
  218. goto parse_error;
  219. }
  220. if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
  221. snprintf (local_error_reason, sizeof(local_error_reason),
  222. "The consensus timeout parameter (%d ms) may not be less then (%d ms).",
  223. totem_config->consensus_timeout, MINIMUM_TIMEOUT);
  224. goto parse_error;
  225. }
  226. if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
  227. snprintf (local_error_reason, sizeof(local_error_reason),
  228. "The merge timeout parameter (%d ms) may not be less then (%d ms).",
  229. totem_config->merge_timeout, MINIMUM_TIMEOUT);
  230. goto parse_error;
  231. }
  232. if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
  233. snprintf (local_error_reason, sizeof(local_error_reason),
  234. "The downcheck timeout parameter (%d ms) may not be less then (%d ms).",
  235. totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
  236. goto parse_error;
  237. }
  238. if (totem_config->rrp_problem_count_timeout < MINIMUM_TIMEOUT) {
  239. snprintf (local_error_reason, sizeof(local_error_reason),
  240. "The RRP problem count timeout parameter (%d ms) may not be less then (%d ms).",
  241. totem_config->rrp_problem_count_timeout, MINIMUM_TIMEOUT);
  242. goto parse_error;
  243. }
  244. if (totem_config->rrp_problem_count_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) {
  245. snprintf (local_error_reason, sizeof(local_error_reason),
  246. "The RRP problem count threshold (%d problem count) may not be less then (%d problem count).",
  247. totem_config->rrp_problem_count_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN);
  248. goto parse_error;
  249. }
  250. if (totem_config->rrp_problem_count_mcast_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) {
  251. snprintf (local_error_reason, sizeof(local_error_reason),
  252. "The RRP multicast problem count threshold (%d problem count) may not be less then (%d problem count).",
  253. totem_config->rrp_problem_count_mcast_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN);
  254. goto parse_error;
  255. }
  256. if (totem_config->rrp_token_expired_timeout < MINIMUM_TIMEOUT) {
  257. snprintf (local_error_reason, sizeof(local_error_reason),
  258. "The RRP token expired timeout parameter (%d ms) may not be less then (%d ms).",
  259. totem_config->rrp_token_expired_timeout, MINIMUM_TIMEOUT);
  260. goto parse_error;
  261. }
  262. return 0;
  263. parse_error:
  264. snprintf (error_string_response, sizeof(error_string_response),
  265. "parse error in config: %s\n", error_reason);
  266. *error_string = error_string_response;
  267. return (-1);
  268. }
  269. static int totem_get_crypto(struct totem_config *totem_config)
  270. {
  271. char *str;
  272. const char *tmp_cipher;
  273. const char *tmp_hash;
  274. tmp_hash = "sha1";
  275. tmp_cipher = "aes256";
  276. if (icmap_get_string("totem.secauth", &str) == CS_OK) {
  277. if (strcmp (str, "off") == 0) {
  278. tmp_hash = "none";
  279. tmp_cipher = "none";
  280. }
  281. free(str);
  282. }
  283. if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
  284. if (strcmp(str, "none") == 0) {
  285. tmp_cipher = "none";
  286. }
  287. if (strcmp(str, "aes256") == 0) {
  288. tmp_cipher = "aes256";
  289. }
  290. if (strcmp(str, "aes192") == 0) {
  291. tmp_cipher = "aes192";
  292. }
  293. if (strcmp(str, "aes128") == 0) {
  294. tmp_cipher = "aes128";
  295. }
  296. if (strcmp(str, "3des") == 0) {
  297. tmp_cipher = "3des";
  298. }
  299. free(str);
  300. }
  301. if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
  302. if (strcmp(str, "none") == 0) {
  303. tmp_hash = "none";
  304. }
  305. if (strcmp(str, "md5") == 0) {
  306. tmp_hash = "md5";
  307. }
  308. if (strcmp(str, "sha1") == 0) {
  309. tmp_hash = "sha1";
  310. }
  311. if (strcmp(str, "sha256") == 0) {
  312. tmp_hash = "sha256";
  313. }
  314. if (strcmp(str, "sha384") == 0) {
  315. tmp_hash = "sha384";
  316. }
  317. if (strcmp(str, "sha512") == 0) {
  318. tmp_hash = "sha512";
  319. }
  320. free(str);
  321. }
  322. if ((strcmp(tmp_cipher, "none") != 0) &&
  323. (strcmp(tmp_hash, "none") == 0)) {
  324. return -1;
  325. }
  326. free(totem_config->crypto_cipher_type);
  327. free(totem_config->crypto_hash_type);
  328. totem_config->crypto_cipher_type = strdup(tmp_cipher);
  329. totem_config->crypto_hash_type = strdup(tmp_hash);
  330. return 0;
  331. }
  332. static uint16_t generate_cluster_id (const char *cluster_name)
  333. {
  334. int i;
  335. int value = 0;
  336. for (i = 0; i < strlen(cluster_name); i++) {
  337. value <<= 1;
  338. value += cluster_name[i];
  339. }
  340. return (value & 0xFFFF);
  341. }
  342. static int get_cluster_mcast_addr (
  343. const char *cluster_name,
  344. const struct totem_ip_address *bindnet,
  345. unsigned int ringnumber,
  346. int ip_version,
  347. struct totem_ip_address *res)
  348. {
  349. uint16_t clusterid;
  350. char addr[INET6_ADDRSTRLEN + 1];
  351. int err;
  352. if (cluster_name == NULL) {
  353. return (-1);
  354. }
  355. clusterid = generate_cluster_id(cluster_name) + ringnumber;
  356. memset (res, 0, sizeof(*res));
  357. switch (bindnet->family) {
  358. case AF_INET:
  359. snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
  360. break;
  361. case AF_INET6:
  362. snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
  363. break;
  364. default:
  365. /*
  366. * Unknown family
  367. */
  368. return (-1);
  369. }
  370. err = totemip_parse (res, addr, ip_version);
  371. return (err);
  372. }
  373. static int find_local_node_in_nodelist(struct totem_config *totem_config)
  374. {
  375. icmap_iter_t iter;
  376. const char *iter_key;
  377. int res = 0;
  378. unsigned int node_pos;
  379. int local_node_pos = -1;
  380. struct totem_ip_address bind_addr;
  381. int interface_up, interface_num;
  382. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  383. char *node_addr_str;
  384. struct totem_ip_address node_addr;
  385. res = totemip_iface_check(&totem_config->interfaces[0].bindnet,
  386. &bind_addr, &interface_up, &interface_num,
  387. totem_config->clear_node_high_bit);
  388. if (res == -1) {
  389. return (-1);
  390. }
  391. iter = icmap_iter_init("nodelist.node.");
  392. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  393. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  394. if (res != 2) {
  395. continue;
  396. }
  397. if (strcmp(tmp_key, "ring0_addr") != 0) {
  398. continue;
  399. }
  400. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  401. if (icmap_get_string(tmp_key, &node_addr_str) != CS_OK) {
  402. continue;
  403. }
  404. res = totemip_parse (&node_addr, node_addr_str, totem_config->ip_version);
  405. free(node_addr_str);
  406. if (res == -1) {
  407. continue ;
  408. }
  409. if (totemip_equal(&bind_addr, &node_addr)) {
  410. local_node_pos = node_pos;
  411. }
  412. }
  413. icmap_iter_finalize(iter);
  414. return (local_node_pos);
  415. }
  416. static void put_nodelist_members_to_config(struct totem_config *totem_config)
  417. {
  418. icmap_iter_t iter, iter2;
  419. const char *iter_key, *iter_key2;
  420. int res = 0;
  421. unsigned int node_pos;
  422. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  423. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  424. char *node_addr_str;
  425. int member_count;
  426. unsigned int ringnumber = 0;
  427. int i, j;
  428. /* Clear out nodelist so we can put the new one in if needed */
  429. for (i = 0; i < totem_config->interface_count; i++) {
  430. for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
  431. memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
  432. }
  433. totem_config->interfaces[i].member_count = 0;
  434. }
  435. iter = icmap_iter_init("nodelist.node.");
  436. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  437. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  438. if (res != 2) {
  439. continue;
  440. }
  441. if (strcmp(tmp_key, "ring0_addr") != 0) {
  442. continue;
  443. }
  444. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  445. iter2 = icmap_iter_init(tmp_key);
  446. while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
  447. res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  448. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  449. continue;
  450. }
  451. if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
  452. continue;
  453. }
  454. member_count = totem_config->interfaces[ringnumber].member_count;
  455. res = totemip_parse(&totem_config->interfaces[ringnumber].member_list[member_count],
  456. node_addr_str, totem_config->ip_version);
  457. if (res != -1) {
  458. totem_config->interfaces[ringnumber].member_count++;
  459. }
  460. free(node_addr_str);
  461. }
  462. icmap_iter_finalize(iter2);
  463. }
  464. icmap_iter_finalize(iter);
  465. }
  466. static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
  467. {
  468. icmap_iter_t iter;
  469. const char *iter_key;
  470. int res = 0;
  471. unsigned int node_pos;
  472. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  473. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  474. char *node_addr_str;
  475. unsigned int ringnumber = 0;
  476. struct list_head addrs;
  477. struct list_head *list;
  478. struct totem_ip_if_address *if_addr;
  479. struct totem_ip_address node_addr;
  480. int node_found = 0;
  481. if (totemip_getifaddrs(&addrs) == -1) {
  482. return ;
  483. }
  484. iter = icmap_iter_init("nodelist.node.");
  485. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  486. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  487. if (res != 2) {
  488. continue;
  489. }
  490. if (strcmp(tmp_key, "ring0_addr") != 0) {
  491. continue;
  492. }
  493. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  494. continue ;
  495. }
  496. if (totemip_parse(&node_addr, node_addr_str, totem_config->ip_version) == -1) {
  497. free(node_addr_str);
  498. continue ;
  499. }
  500. free(node_addr_str);
  501. /*
  502. * Try to find node in if_addrs
  503. */
  504. node_found = 0;
  505. for (list = addrs.next; list != &addrs; list = list->next) {
  506. if_addr = list_entry(list, struct totem_ip_if_address, list);
  507. if (totemip_equal(&node_addr, &if_addr->ip_addr)) {
  508. node_found = 1;
  509. break;
  510. }
  511. }
  512. if (node_found) {
  513. break ;
  514. }
  515. }
  516. icmap_iter_finalize(iter);
  517. if (node_found) {
  518. /*
  519. * We found node, so create interface section
  520. */
  521. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  522. iter = icmap_iter_init(tmp_key);
  523. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  524. res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  525. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  526. continue ;
  527. }
  528. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  529. continue;
  530. }
  531. snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", ringnumber);
  532. icmap_set_string(tmp_key2, node_addr_str);
  533. free(node_addr_str);
  534. }
  535. icmap_iter_finalize(iter);
  536. }
  537. }
  538. extern int totem_config_read (
  539. struct totem_config *totem_config,
  540. const char **error_string,
  541. uint64_t *warnings)
  542. {
  543. int res = 0;
  544. char *str;
  545. unsigned int ringnumber = 0;
  546. int member_count = 0;
  547. icmap_iter_t iter, member_iter;
  548. const char *iter_key;
  549. const char *member_iter_key;
  550. char ringnumber_key[ICMAP_KEYNAME_MAXLEN];
  551. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  552. uint8_t u8;
  553. uint16_t u16;
  554. char *cluster_name = NULL;
  555. int i;
  556. int local_node_pos;
  557. int nodeid_set;
  558. *warnings = 0;
  559. memset (totem_config, 0, sizeof (struct totem_config));
  560. totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  561. if (totem_config->interfaces == 0) {
  562. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  563. return -1;
  564. }
  565. memset (totem_config->interfaces, 0,
  566. sizeof (struct totem_interface) * INTERFACE_MAX);
  567. strcpy (totem_config->rrp_mode, "none");
  568. icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
  569. if (totem_get_crypto(totem_config) != 0) {
  570. *error_string = "crypto_cipher requires crypto_hash with value other than none";
  571. return -1;
  572. }
  573. if (icmap_get_string("totem.rrp_mode", &str) == CS_OK) {
  574. if (strlen(str) >= TOTEM_RRP_MODE_BYTES) {
  575. *error_string = "totem.rrp_mode is too long";
  576. free(str);
  577. return -1;
  578. }
  579. strcpy (totem_config->rrp_mode, str);
  580. free(str);
  581. }
  582. icmap_get_uint32("totem.nodeid", &totem_config->node_id);
  583. totem_config->clear_node_high_bit = 0;
  584. if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
  585. if (strcmp (str, "yes") == 0) {
  586. totem_config->clear_node_high_bit = 1;
  587. }
  588. free(str);
  589. }
  590. icmap_get_uint32("totem.threads", &totem_config->threads);
  591. icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
  592. if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
  593. cluster_name = NULL;
  594. }
  595. totem_config->ip_version = AF_INET;
  596. if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
  597. if (strcmp(str, "ipv4") == 0) {
  598. totem_config->ip_version = AF_INET;
  599. }
  600. if (strcmp(str, "ipv6") == 0) {
  601. totem_config->ip_version = AF_INET6;
  602. }
  603. free(str);
  604. }
  605. if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
  606. /*
  607. * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
  608. */
  609. config_convert_nodelist_to_interface(totem_config);
  610. } else {
  611. free(str);
  612. }
  613. iter = icmap_iter_init("totem.interface.");
  614. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  615. res = sscanf(iter_key, "totem.interface.%[^.].%s", ringnumber_key, tmp_key);
  616. if (res != 2) {
  617. continue;
  618. }
  619. if (strcmp(tmp_key, "bindnetaddr") != 0) {
  620. continue;
  621. }
  622. member_count = 0;
  623. ringnumber = atoi(ringnumber_key);
  624. if (ringnumber >= INTERFACE_MAX) {
  625. free(cluster_name);
  626. snprintf (error_string_response, sizeof(error_string_response),
  627. "parse error in config: interface ring number %u is bigger then allowed maximum %u\n",
  628. ringnumber, INTERFACE_MAX - 1);
  629. *error_string = error_string_response;
  630. return -1;
  631. }
  632. /*
  633. * Get the bind net address
  634. */
  635. if (icmap_get_string(iter_key, &str) == CS_OK) {
  636. res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
  637. totem_config->interfaces[ringnumber].mcast_addr.family);
  638. free(str);
  639. }
  640. /*
  641. * Get interface multicast address
  642. */
  643. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", ringnumber);
  644. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  645. res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, totem_config->ip_version);
  646. free(str);
  647. } else {
  648. /*
  649. * User not specified address -> autogenerate one from cluster_name key
  650. * (if available)
  651. */
  652. res = get_cluster_mcast_addr (cluster_name,
  653. &totem_config->interfaces[ringnumber].bindnet,
  654. ringnumber,
  655. totem_config->ip_version,
  656. &totem_config->interfaces[ringnumber].mcast_addr);
  657. }
  658. totem_config->broadcast_use = 0;
  659. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", ringnumber);
  660. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  661. if (strcmp (str, "yes") == 0) {
  662. totem_config->broadcast_use = 1;
  663. totemip_parse (
  664. &totem_config->interfaces[ringnumber].mcast_addr,
  665. "255.255.255.255", totem_config->ip_version);
  666. }
  667. free(str);
  668. }
  669. /*
  670. * Get mcast port
  671. */
  672. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", ringnumber);
  673. if (icmap_get_uint16(tmp_key, &totem_config->interfaces[ringnumber].ip_port) != CS_OK) {
  674. if (totem_config->broadcast_use) {
  675. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT + (2 * ringnumber);
  676. } else {
  677. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT;
  678. }
  679. }
  680. /*
  681. * Get the TTL
  682. */
  683. totem_config->interfaces[ringnumber].ttl = 1;
  684. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", ringnumber);
  685. if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
  686. totem_config->interfaces[ringnumber].ttl = u8;
  687. }
  688. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", ringnumber);
  689. member_iter = icmap_iter_init(tmp_key);
  690. while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
  691. if (member_count == 0) {
  692. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  693. free(str);
  694. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED;
  695. break;
  696. } else {
  697. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED;
  698. }
  699. }
  700. if (icmap_get_string(member_iter_key, &str) == CS_OK) {
  701. res = totemip_parse (&totem_config->interfaces[ringnumber].member_list[member_count++],
  702. str, totem_config->ip_version);
  703. }
  704. }
  705. icmap_iter_finalize(member_iter);
  706. totem_config->interfaces[ringnumber].member_count = member_count;
  707. totem_config->interface_count++;
  708. }
  709. icmap_iter_finalize(iter);
  710. /*
  711. * Store automatically generated items back to icmap
  712. */
  713. for (i = 0; i < totem_config->interface_count; i++) {
  714. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
  715. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  716. free(str);
  717. } else {
  718. str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
  719. icmap_set_string(tmp_key, str);
  720. }
  721. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
  722. if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
  723. icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
  724. }
  725. }
  726. totem_config->transport_number = TOTEM_TRANSPORT_UDP;
  727. if (icmap_get_string("totem.transport", &str) == CS_OK) {
  728. if (strcmp (str, "udpu") == 0) {
  729. totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
  730. }
  731. if (strcmp (str, "iba") == 0) {
  732. totem_config->transport_number = TOTEM_TRANSPORT_RDMA;
  733. }
  734. free(str);
  735. }
  736. free(cluster_name);
  737. /*
  738. * Check existence of nodelist
  739. */
  740. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  741. free(str);
  742. /*
  743. * find local node
  744. */
  745. local_node_pos = find_local_node_in_nodelist(totem_config);
  746. if (local_node_pos != -1) {
  747. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  748. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
  749. nodeid_set = (totem_config->node_id != 0);
  750. if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
  751. *warnings |= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED;
  752. }
  753. /*
  754. * Make localnode ring0_addr read only, so we can be sure that local
  755. * node never changes. If rebinding to other IP would be in future
  756. * supported, this must be changed and handled properly!
  757. */
  758. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
  759. icmap_set_ro_access(tmp_key, 0, 1);
  760. icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
  761. }
  762. put_nodelist_members_to_config(totem_config);
  763. }
  764. /*
  765. * Get things that might change in the future (and can depend on totem_config->interfaces);
  766. */
  767. totem_volatile_config_read(totem_config, NULL);
  768. add_totem_config_notification(totem_config);
  769. return 0;
  770. }
  771. int totem_config_validate (
  772. struct totem_config *totem_config,
  773. const char **error_string)
  774. {
  775. static char local_error_reason[512];
  776. char parse_error[512];
  777. const char *error_reason = local_error_reason;
  778. int i;
  779. unsigned int interface_max = INTERFACE_MAX;
  780. if (totem_config->interface_count == 0) {
  781. error_reason = "No interfaces defined";
  782. goto parse_error;
  783. }
  784. for (i = 0; i < totem_config->interface_count; i++) {
  785. /*
  786. * Some error checking of parsed data to make sure its valid
  787. */
  788. struct totem_ip_address null_addr;
  789. memset (&null_addr, 0, sizeof (struct totem_ip_address));
  790. if ((totem_config->transport_number == 0) &&
  791. memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
  792. sizeof (struct totem_ip_address)) == 0) {
  793. error_reason = "No multicast address specified";
  794. goto parse_error;
  795. }
  796. if (totem_config->interfaces[i].ip_port == 0) {
  797. error_reason = "No multicast port specified";
  798. goto parse_error;
  799. }
  800. if (totem_config->interfaces[i].ttl > 255) {
  801. error_reason = "Invalid TTL (should be 0..255)";
  802. goto parse_error;
  803. }
  804. if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
  805. totem_config->interfaces[i].ttl != 1) {
  806. error_reason = "Can only set ttl on multicast transport types";
  807. goto parse_error;
  808. }
  809. if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
  810. totem_config->node_id == 0) {
  811. error_reason = "An IPV6 network requires that a node ID be specified.";
  812. goto parse_error;
  813. }
  814. if (totem_config->broadcast_use == 0 && totem_config->transport_number == 0) {
  815. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  816. error_reason = "Multicast address family does not match bind address family";
  817. goto parse_error;
  818. }
  819. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  820. error_reason = "Not all bind address belong to the same IP family";
  821. goto parse_error;
  822. }
  823. if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
  824. error_reason = "mcastaddr is not a correct multicast address.";
  825. goto parse_error;
  826. }
  827. }
  828. }
  829. if (totem_config->version != 2) {
  830. error_reason = "This totem parser can only parse version 2 configurations.";
  831. goto parse_error;
  832. }
  833. if (totem_volatile_config_validate(totem_config, error_string) == -1) {
  834. return (-1);
  835. }
  836. /*
  837. * RRP values validation
  838. */
  839. if (strcmp (totem_config->rrp_mode, "none") &&
  840. strcmp (totem_config->rrp_mode, "active") &&
  841. strcmp (totem_config->rrp_mode, "passive")) {
  842. snprintf (local_error_reason, sizeof(local_error_reason),
  843. "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
  844. goto parse_error;
  845. }
  846. if (strcmp (totem_config->rrp_mode, "none") == 0) {
  847. interface_max = 1;
  848. }
  849. if (interface_max < totem_config->interface_count) {
  850. snprintf (parse_error, sizeof(parse_error),
  851. "%d is too many configured interfaces for the rrp_mode setting %s.",
  852. totem_config->interface_count,
  853. totem_config->rrp_mode);
  854. error_reason = parse_error;
  855. goto parse_error;
  856. }
  857. if (totem_config->net_mtu == 0) {
  858. totem_config->net_mtu = 1500;
  859. }
  860. return 0;
  861. parse_error:
  862. snprintf (error_string_response, sizeof(error_string_response),
  863. "parse error in config: %s\n", error_reason);
  864. *error_string = error_string_response;
  865. return (-1);
  866. }
  867. static int read_keyfile (
  868. const char *key_location,
  869. struct totem_config *totem_config,
  870. const char **error_string)
  871. {
  872. int fd;
  873. int res;
  874. ssize_t expected_key_len = sizeof (totem_config->private_key);
  875. int saved_errno;
  876. char error_str[100];
  877. const char *error_ptr;
  878. fd = open (key_location, O_RDONLY);
  879. if (fd == -1) {
  880. error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  881. snprintf (error_string_response, sizeof(error_string_response),
  882. "Could not open %s: %s\n",
  883. key_location, error_ptr);
  884. goto parse_error;
  885. }
  886. res = read (fd, totem_config->private_key, expected_key_len);
  887. saved_errno = errno;
  888. close (fd);
  889. if (res == -1) {
  890. error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
  891. snprintf (error_string_response, sizeof(error_string_response),
  892. "Could not read %s: %s\n",
  893. key_location, error_ptr);
  894. goto parse_error;
  895. }
  896. totem_config->private_key_len = expected_key_len;
  897. if (res != expected_key_len) {
  898. snprintf (error_string_response, sizeof(error_string_response),
  899. "Could only read %d bits of 1024 bits from %s.\n",
  900. res * 8, key_location);
  901. goto parse_error;
  902. }
  903. return 0;
  904. parse_error:
  905. *error_string = error_string_response;
  906. return (-1);
  907. }
  908. int totem_config_keyread (
  909. struct totem_config *totem_config,
  910. const char **error_string)
  911. {
  912. int got_key = 0;
  913. char *key_location = NULL;
  914. int res;
  915. size_t key_len;
  916. memset (totem_config->private_key, 0, 128);
  917. totem_config->private_key_len = 128;
  918. if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
  919. strcmp(totem_config->crypto_hash_type, "none") == 0) {
  920. return (0);
  921. }
  922. /* cmap may store the location of the key file */
  923. if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
  924. res = read_keyfile(key_location, totem_config, error_string);
  925. free(key_location);
  926. if (res) {
  927. goto key_error;
  928. }
  929. got_key = 1;
  930. } else { /* Or the key itself may be in the cmap */
  931. if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
  932. if (key_len > sizeof (totem_config->private_key)) {
  933. sprintf(error_string_response, "key is too long");
  934. goto key_error;
  935. }
  936. if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
  937. totem_config->private_key_len = key_len;
  938. got_key = 1;
  939. } else {
  940. sprintf(error_string_response, "can't store private key");
  941. goto key_error;
  942. }
  943. }
  944. }
  945. /* In desperation we read the default filename */
  946. if (!got_key) {
  947. const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
  948. if (!filename)
  949. filename = COROSYSCONFDIR "/authkey";
  950. res = read_keyfile(filename, totem_config, error_string);
  951. if (res)
  952. goto key_error;
  953. }
  954. return (0);
  955. key_error:
  956. *error_string = error_string_response;
  957. return (-1);
  958. }
  959. static void debug_dump_totem_config(const struct totem_config *totem_config)
  960. {
  961. log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
  962. totem_config->token_timeout, totem_config->token_retransmit_timeout);
  963. log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
  964. totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
  965. log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
  966. totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
  967. totem_config->merge_timeout);
  968. log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
  969. totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
  970. log_printf(LOGSYS_LEVEL_DEBUG,
  971. "seqno unchanged const (%d rotations) Maximum network MTU %d",
  972. totem_config->seqno_unchanged_const, totem_config->net_mtu);
  973. log_printf(LOGSYS_LEVEL_DEBUG,
  974. "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
  975. totem_config->window_size, totem_config->max_messages);
  976. log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
  977. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token expired timeout (%d ms)",
  978. totem_config->rrp_token_expired_timeout);
  979. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token problem counter (%d ms)",
  980. totem_config->rrp_problem_count_timeout);
  981. log_printf(LOGSYS_LEVEL_DEBUG, "RRP threshold (%d problem count)",
  982. totem_config->rrp_problem_count_threshold);
  983. log_printf(LOGSYS_LEVEL_DEBUG, "RRP multicast threshold (%d problem count)",
  984. totem_config->rrp_problem_count_mcast_threshold);
  985. log_printf(LOGSYS_LEVEL_DEBUG, "RRP automatic recovery check timeout (%d ms)",
  986. totem_config->rrp_autorecovery_check_timeout);
  987. log_printf(LOGSYS_LEVEL_DEBUG, "RRP mode set to %s.",
  988. totem_config->rrp_mode);
  989. log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
  990. totem_config->heartbeat_failures_allowed);
  991. log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
  992. }
  993. static void totem_change_notify(
  994. int32_t event,
  995. const char *key_name,
  996. struct icmap_notify_value new_val,
  997. struct icmap_notify_value old_val,
  998. void *user_data)
  999. {
  1000. struct totem_config *totem_config = (struct totem_config *)user_data;
  1001. uint32_t *param;
  1002. uint8_t reloading;
  1003. const char *deleted_key = NULL;
  1004. const char *error_string;
  1005. /*
  1006. * If a full reload is in progress then don't do anything until it's done and
  1007. * can reconfigure it all atomically
  1008. */
  1009. if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
  1010. return;
  1011. param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
  1012. /*
  1013. * Process change only if changed key is found in totem_config (-> param is not NULL)
  1014. * or for special key token_coefficient. token_coefficient key is not stored in
  1015. * totem_config, but it is used for computation of token timeout.
  1016. */
  1017. if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
  1018. return;
  1019. /*
  1020. * Values other then UINT32 are not supported, or needed (yet)
  1021. */
  1022. switch (event) {
  1023. case ICMAP_TRACK_DELETE:
  1024. deleted_key = key_name;
  1025. break;
  1026. case ICMAP_TRACK_ADD:
  1027. case ICMAP_TRACK_MODIFY:
  1028. deleted_key = NULL;
  1029. break;
  1030. default:
  1031. break;
  1032. }
  1033. totem_volatile_config_read (totem_config, deleted_key);
  1034. log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
  1035. debug_dump_totem_config(totem_config);
  1036. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1037. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1038. /*
  1039. * TODO: Consider corosync exit and/or load defaults for volatile
  1040. * values. For now, log error seems to be enough
  1041. */
  1042. }
  1043. }
  1044. static void totem_reload_notify(
  1045. int32_t event,
  1046. const char *key_name,
  1047. struct icmap_notify_value new_val,
  1048. struct icmap_notify_value old_val,
  1049. void *user_data)
  1050. {
  1051. struct totem_config *totem_config = (struct totem_config *)user_data;
  1052. uint32_t local_node_pos;
  1053. const char *error_string;
  1054. /* Reload has completed */
  1055. if (*(uint8_t *)new_val.data == 0) {
  1056. put_nodelist_members_to_config (totem_config);
  1057. totem_volatile_config_read (totem_config, NULL);
  1058. log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
  1059. debug_dump_totem_config(totem_config);
  1060. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1061. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1062. /*
  1063. * TODO: Consider corosync exit and/or load defaults for volatile
  1064. * values. For now, log error seems to be enough
  1065. */
  1066. }
  1067. /* Reinstate the local_node_pos */
  1068. local_node_pos = find_local_node_in_nodelist(totem_config);
  1069. if (local_node_pos != -1) {
  1070. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  1071. }
  1072. }
  1073. }
  1074. static void add_totem_config_notification(struct totem_config *totem_config)
  1075. {
  1076. icmap_track_t icmap_track;
  1077. icmap_track_add("totem.",
  1078. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1079. totem_change_notify,
  1080. totem_config,
  1081. &icmap_track);
  1082. icmap_track_add("config.reload_in_progress",
  1083. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1084. totem_reload_notify,
  1085. totem_config,
  1086. &icmap_track);
  1087. }