totemconfig.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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 int totem_config_get_ip_version(void)
  333. {
  334. int res;
  335. char *str;
  336. res = AF_INET;
  337. if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
  338. if (strcmp(str, "ipv4") == 0) {
  339. res = AF_INET;
  340. }
  341. if (strcmp(str, "ipv6") == 0) {
  342. res = AF_INET6;
  343. }
  344. free(str);
  345. }
  346. return (res);
  347. }
  348. static uint16_t generate_cluster_id (const char *cluster_name)
  349. {
  350. int i;
  351. int value = 0;
  352. for (i = 0; i < strlen(cluster_name); i++) {
  353. value <<= 1;
  354. value += cluster_name[i];
  355. }
  356. return (value & 0xFFFF);
  357. }
  358. static int get_cluster_mcast_addr (
  359. const char *cluster_name,
  360. const struct totem_ip_address *bindnet,
  361. unsigned int ringnumber,
  362. int ip_version,
  363. struct totem_ip_address *res)
  364. {
  365. uint16_t clusterid;
  366. char addr[INET6_ADDRSTRLEN + 1];
  367. int err;
  368. if (cluster_name == NULL) {
  369. return (-1);
  370. }
  371. clusterid = generate_cluster_id(cluster_name) + ringnumber;
  372. memset (res, 0, sizeof(*res));
  373. switch (bindnet->family) {
  374. case AF_INET:
  375. snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
  376. break;
  377. case AF_INET6:
  378. snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
  379. break;
  380. default:
  381. /*
  382. * Unknown family
  383. */
  384. return (-1);
  385. }
  386. err = totemip_parse (res, addr, ip_version);
  387. return (err);
  388. }
  389. static int find_local_node_in_nodelist(struct totem_config *totem_config)
  390. {
  391. icmap_iter_t iter;
  392. const char *iter_key;
  393. int res = 0;
  394. unsigned int node_pos;
  395. int local_node_pos = -1;
  396. struct totem_ip_address bind_addr;
  397. int interface_up, interface_num;
  398. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  399. char *node_addr_str;
  400. struct totem_ip_address node_addr;
  401. res = totemip_iface_check(&totem_config->interfaces[0].bindnet,
  402. &bind_addr, &interface_up, &interface_num,
  403. totem_config->clear_node_high_bit);
  404. if (res == -1) {
  405. return (-1);
  406. }
  407. iter = icmap_iter_init("nodelist.node.");
  408. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  409. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  410. if (res != 2) {
  411. continue;
  412. }
  413. if (strcmp(tmp_key, "ring0_addr") != 0) {
  414. continue;
  415. }
  416. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  417. if (icmap_get_string(tmp_key, &node_addr_str) != CS_OK) {
  418. continue;
  419. }
  420. res = totemip_parse (&node_addr, node_addr_str, totem_config->ip_version);
  421. free(node_addr_str);
  422. if (res == -1) {
  423. continue ;
  424. }
  425. if (totemip_equal(&bind_addr, &node_addr)) {
  426. local_node_pos = node_pos;
  427. }
  428. }
  429. icmap_iter_finalize(iter);
  430. return (local_node_pos);
  431. }
  432. static void put_nodelist_members_to_config(struct totem_config *totem_config)
  433. {
  434. icmap_iter_t iter, iter2;
  435. const char *iter_key, *iter_key2;
  436. int res = 0;
  437. unsigned int node_pos;
  438. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  439. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  440. char *node_addr_str;
  441. int member_count;
  442. unsigned int ringnumber = 0;
  443. int i, j;
  444. /* Clear out nodelist so we can put the new one in if needed */
  445. for (i = 0; i < totem_config->interface_count; i++) {
  446. for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
  447. memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
  448. }
  449. totem_config->interfaces[i].member_count = 0;
  450. }
  451. iter = icmap_iter_init("nodelist.node.");
  452. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  453. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  454. if (res != 2) {
  455. continue;
  456. }
  457. if (strcmp(tmp_key, "ring0_addr") != 0) {
  458. continue;
  459. }
  460. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  461. iter2 = icmap_iter_init(tmp_key);
  462. while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
  463. res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  464. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  465. continue;
  466. }
  467. if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
  468. continue;
  469. }
  470. member_count = totem_config->interfaces[ringnumber].member_count;
  471. res = totemip_parse(&totem_config->interfaces[ringnumber].member_list[member_count],
  472. node_addr_str, totem_config->ip_version);
  473. if (res != -1) {
  474. totem_config->interfaces[ringnumber].member_count++;
  475. }
  476. free(node_addr_str);
  477. }
  478. icmap_iter_finalize(iter2);
  479. }
  480. icmap_iter_finalize(iter);
  481. }
  482. static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
  483. {
  484. icmap_iter_t iter;
  485. const char *iter_key;
  486. int res = 0;
  487. unsigned int node_pos;
  488. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  489. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  490. char *node_addr_str;
  491. unsigned int ringnumber = 0;
  492. struct list_head addrs;
  493. struct list_head *list;
  494. struct totem_ip_if_address *if_addr;
  495. struct totem_ip_address node_addr;
  496. int node_found = 0;
  497. if (totemip_getifaddrs(&addrs) == -1) {
  498. return ;
  499. }
  500. iter = icmap_iter_init("nodelist.node.");
  501. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  502. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  503. if (res != 2) {
  504. continue;
  505. }
  506. if (strcmp(tmp_key, "ring0_addr") != 0) {
  507. continue;
  508. }
  509. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  510. continue ;
  511. }
  512. if (totemip_parse(&node_addr, node_addr_str, totem_config->ip_version) == -1) {
  513. free(node_addr_str);
  514. continue ;
  515. }
  516. free(node_addr_str);
  517. /*
  518. * Try to find node in if_addrs
  519. */
  520. node_found = 0;
  521. for (list = addrs.next; list != &addrs; list = list->next) {
  522. if_addr = list_entry(list, struct totem_ip_if_address, list);
  523. if (totemip_equal(&node_addr, &if_addr->ip_addr)) {
  524. node_found = 1;
  525. break;
  526. }
  527. }
  528. if (node_found) {
  529. break ;
  530. }
  531. }
  532. icmap_iter_finalize(iter);
  533. totemip_freeifaddrs(&addrs);
  534. if (node_found) {
  535. /*
  536. * We found node, so create interface section
  537. */
  538. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  539. iter = icmap_iter_init(tmp_key);
  540. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  541. res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  542. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  543. continue ;
  544. }
  545. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  546. continue;
  547. }
  548. snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", ringnumber);
  549. icmap_set_string(tmp_key2, node_addr_str);
  550. free(node_addr_str);
  551. }
  552. icmap_iter_finalize(iter);
  553. }
  554. }
  555. extern int totem_config_read (
  556. struct totem_config *totem_config,
  557. const char **error_string,
  558. uint64_t *warnings)
  559. {
  560. int res = 0;
  561. char *str;
  562. unsigned int ringnumber = 0;
  563. int member_count = 0;
  564. icmap_iter_t iter, member_iter;
  565. const char *iter_key;
  566. const char *member_iter_key;
  567. char ringnumber_key[ICMAP_KEYNAME_MAXLEN];
  568. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  569. uint8_t u8;
  570. uint16_t u16;
  571. char *cluster_name = NULL;
  572. int i;
  573. int local_node_pos;
  574. int nodeid_set;
  575. *warnings = 0;
  576. memset (totem_config, 0, sizeof (struct totem_config));
  577. totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  578. if (totem_config->interfaces == 0) {
  579. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  580. return -1;
  581. }
  582. memset (totem_config->interfaces, 0,
  583. sizeof (struct totem_interface) * INTERFACE_MAX);
  584. strcpy (totem_config->rrp_mode, "none");
  585. icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
  586. if (totem_get_crypto(totem_config) != 0) {
  587. *error_string = "crypto_cipher requires crypto_hash with value other than none";
  588. return -1;
  589. }
  590. if (icmap_get_string("totem.rrp_mode", &str) == CS_OK) {
  591. if (strlen(str) >= TOTEM_RRP_MODE_BYTES) {
  592. *error_string = "totem.rrp_mode is too long";
  593. free(str);
  594. return -1;
  595. }
  596. strcpy (totem_config->rrp_mode, str);
  597. free(str);
  598. }
  599. icmap_get_uint32("totem.nodeid", &totem_config->node_id);
  600. totem_config->clear_node_high_bit = 0;
  601. if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
  602. if (strcmp (str, "yes") == 0) {
  603. totem_config->clear_node_high_bit = 1;
  604. }
  605. free(str);
  606. }
  607. icmap_get_uint32("totem.threads", &totem_config->threads);
  608. icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
  609. if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
  610. cluster_name = NULL;
  611. }
  612. totem_config->ip_version = totem_config_get_ip_version();
  613. if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
  614. /*
  615. * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
  616. */
  617. config_convert_nodelist_to_interface(totem_config);
  618. } else {
  619. free(str);
  620. }
  621. iter = icmap_iter_init("totem.interface.");
  622. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  623. res = sscanf(iter_key, "totem.interface.%[^.].%s", ringnumber_key, tmp_key);
  624. if (res != 2) {
  625. continue;
  626. }
  627. if (strcmp(tmp_key, "bindnetaddr") != 0) {
  628. continue;
  629. }
  630. member_count = 0;
  631. ringnumber = atoi(ringnumber_key);
  632. if (ringnumber >= INTERFACE_MAX) {
  633. free(cluster_name);
  634. snprintf (error_string_response, sizeof(error_string_response),
  635. "parse error in config: interface ring number %u is bigger then allowed maximum %u\n",
  636. ringnumber, INTERFACE_MAX - 1);
  637. *error_string = error_string_response;
  638. return -1;
  639. }
  640. /*
  641. * Get the bind net address
  642. */
  643. if (icmap_get_string(iter_key, &str) == CS_OK) {
  644. res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
  645. totem_config->interfaces[ringnumber].mcast_addr.family);
  646. free(str);
  647. }
  648. /*
  649. * Get interface multicast address
  650. */
  651. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", ringnumber);
  652. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  653. res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, totem_config->ip_version);
  654. free(str);
  655. } else {
  656. /*
  657. * User not specified address -> autogenerate one from cluster_name key
  658. * (if available)
  659. */
  660. res = get_cluster_mcast_addr (cluster_name,
  661. &totem_config->interfaces[ringnumber].bindnet,
  662. ringnumber,
  663. totem_config->ip_version,
  664. &totem_config->interfaces[ringnumber].mcast_addr);
  665. }
  666. totem_config->broadcast_use = 0;
  667. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", ringnumber);
  668. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  669. if (strcmp (str, "yes") == 0) {
  670. totem_config->broadcast_use = 1;
  671. totemip_parse (
  672. &totem_config->interfaces[ringnumber].mcast_addr,
  673. "255.255.255.255", totem_config->ip_version);
  674. }
  675. free(str);
  676. }
  677. /*
  678. * Get mcast port
  679. */
  680. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", ringnumber);
  681. if (icmap_get_uint16(tmp_key, &totem_config->interfaces[ringnumber].ip_port) != CS_OK) {
  682. if (totem_config->broadcast_use) {
  683. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT + (2 * ringnumber);
  684. } else {
  685. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT;
  686. }
  687. }
  688. /*
  689. * Get the TTL
  690. */
  691. totem_config->interfaces[ringnumber].ttl = 1;
  692. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", ringnumber);
  693. if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
  694. totem_config->interfaces[ringnumber].ttl = u8;
  695. }
  696. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", ringnumber);
  697. member_iter = icmap_iter_init(tmp_key);
  698. while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
  699. if (member_count == 0) {
  700. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  701. free(str);
  702. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED;
  703. break;
  704. } else {
  705. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED;
  706. }
  707. }
  708. if (icmap_get_string(member_iter_key, &str) == CS_OK) {
  709. res = totemip_parse (&totem_config->interfaces[ringnumber].member_list[member_count++],
  710. str, totem_config->ip_version);
  711. }
  712. }
  713. icmap_iter_finalize(member_iter);
  714. totem_config->interfaces[ringnumber].member_count = member_count;
  715. totem_config->interface_count++;
  716. }
  717. icmap_iter_finalize(iter);
  718. /*
  719. * Store automatically generated items back to icmap
  720. */
  721. for (i = 0; i < totem_config->interface_count; i++) {
  722. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
  723. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  724. free(str);
  725. } else {
  726. str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
  727. icmap_set_string(tmp_key, str);
  728. }
  729. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
  730. if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
  731. icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
  732. }
  733. }
  734. totem_config->transport_number = TOTEM_TRANSPORT_UDP;
  735. if (icmap_get_string("totem.transport", &str) == CS_OK) {
  736. if (strcmp (str, "udpu") == 0) {
  737. totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
  738. }
  739. if (strcmp (str, "iba") == 0) {
  740. totem_config->transport_number = TOTEM_TRANSPORT_RDMA;
  741. }
  742. free(str);
  743. }
  744. free(cluster_name);
  745. /*
  746. * Check existence of nodelist
  747. */
  748. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  749. free(str);
  750. /*
  751. * find local node
  752. */
  753. local_node_pos = find_local_node_in_nodelist(totem_config);
  754. if (local_node_pos != -1) {
  755. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  756. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
  757. nodeid_set = (totem_config->node_id != 0);
  758. if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
  759. *warnings |= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED;
  760. }
  761. /*
  762. * Make localnode ring0_addr read only, so we can be sure that local
  763. * node never changes. If rebinding to other IP would be in future
  764. * supported, this must be changed and handled properly!
  765. */
  766. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
  767. icmap_set_ro_access(tmp_key, 0, 1);
  768. icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
  769. }
  770. put_nodelist_members_to_config(totem_config);
  771. }
  772. /*
  773. * Get things that might change in the future (and can depend on totem_config->interfaces);
  774. */
  775. totem_volatile_config_read(totem_config, NULL);
  776. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  777. add_totem_config_notification(totem_config);
  778. return 0;
  779. }
  780. int totem_config_validate (
  781. struct totem_config *totem_config,
  782. const char **error_string)
  783. {
  784. static char local_error_reason[512];
  785. char parse_error[512];
  786. const char *error_reason = local_error_reason;
  787. int i;
  788. unsigned int interface_max = INTERFACE_MAX;
  789. if (totem_config->interface_count == 0) {
  790. error_reason = "No interfaces defined";
  791. goto parse_error;
  792. }
  793. for (i = 0; i < totem_config->interface_count; i++) {
  794. /*
  795. * Some error checking of parsed data to make sure its valid
  796. */
  797. struct totem_ip_address null_addr;
  798. memset (&null_addr, 0, sizeof (struct totem_ip_address));
  799. if ((totem_config->transport_number == 0) &&
  800. memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
  801. sizeof (struct totem_ip_address)) == 0) {
  802. error_reason = "No multicast address specified";
  803. goto parse_error;
  804. }
  805. if (totem_config->interfaces[i].ip_port == 0) {
  806. error_reason = "No multicast port specified";
  807. goto parse_error;
  808. }
  809. if (totem_config->interfaces[i].ttl > 255) {
  810. error_reason = "Invalid TTL (should be 0..255)";
  811. goto parse_error;
  812. }
  813. if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
  814. totem_config->interfaces[i].ttl != 1) {
  815. error_reason = "Can only set ttl on multicast transport types";
  816. goto parse_error;
  817. }
  818. if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
  819. totem_config->node_id == 0) {
  820. error_reason = "An IPV6 network requires that a node ID be specified.";
  821. goto parse_error;
  822. }
  823. if (totem_config->broadcast_use == 0 && totem_config->transport_number == 0) {
  824. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  825. error_reason = "Multicast address family does not match bind address family";
  826. goto parse_error;
  827. }
  828. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  829. error_reason = "Not all bind address belong to the same IP family";
  830. goto parse_error;
  831. }
  832. if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
  833. error_reason = "mcastaddr is not a correct multicast address.";
  834. goto parse_error;
  835. }
  836. }
  837. }
  838. if (totem_config->version != 2) {
  839. error_reason = "This totem parser can only parse version 2 configurations.";
  840. goto parse_error;
  841. }
  842. if (totem_volatile_config_validate(totem_config, error_string) == -1) {
  843. return (-1);
  844. }
  845. /*
  846. * RRP values validation
  847. */
  848. if (strcmp (totem_config->rrp_mode, "none") &&
  849. strcmp (totem_config->rrp_mode, "active") &&
  850. strcmp (totem_config->rrp_mode, "passive")) {
  851. snprintf (local_error_reason, sizeof(local_error_reason),
  852. "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
  853. goto parse_error;
  854. }
  855. if (strcmp (totem_config->rrp_mode, "none") == 0) {
  856. interface_max = 1;
  857. }
  858. if (interface_max < totem_config->interface_count) {
  859. snprintf (parse_error, sizeof(parse_error),
  860. "%d is too many configured interfaces for the rrp_mode setting %s.",
  861. totem_config->interface_count,
  862. totem_config->rrp_mode);
  863. error_reason = parse_error;
  864. goto parse_error;
  865. }
  866. if (totem_config->net_mtu == 0) {
  867. totem_config->net_mtu = 1500;
  868. }
  869. return 0;
  870. parse_error:
  871. snprintf (error_string_response, sizeof(error_string_response),
  872. "parse error in config: %s\n", error_reason);
  873. *error_string = error_string_response;
  874. return (-1);
  875. }
  876. static int read_keyfile (
  877. const char *key_location,
  878. struct totem_config *totem_config,
  879. const char **error_string)
  880. {
  881. int fd;
  882. int res;
  883. ssize_t expected_key_len = sizeof (totem_config->private_key);
  884. int saved_errno;
  885. char error_str[100];
  886. const char *error_ptr;
  887. fd = open (key_location, O_RDONLY);
  888. if (fd == -1) {
  889. error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  890. snprintf (error_string_response, sizeof(error_string_response),
  891. "Could not open %s: %s\n",
  892. key_location, error_ptr);
  893. goto parse_error;
  894. }
  895. res = read (fd, totem_config->private_key, expected_key_len);
  896. saved_errno = errno;
  897. close (fd);
  898. if (res == -1) {
  899. error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
  900. snprintf (error_string_response, sizeof(error_string_response),
  901. "Could not read %s: %s\n",
  902. key_location, error_ptr);
  903. goto parse_error;
  904. }
  905. totem_config->private_key_len = expected_key_len;
  906. if (res != expected_key_len) {
  907. snprintf (error_string_response, sizeof(error_string_response),
  908. "Could only read %d bits of 1024 bits from %s.\n",
  909. res * 8, key_location);
  910. goto parse_error;
  911. }
  912. return 0;
  913. parse_error:
  914. *error_string = error_string_response;
  915. return (-1);
  916. }
  917. int totem_config_keyread (
  918. struct totem_config *totem_config,
  919. const char **error_string)
  920. {
  921. int got_key = 0;
  922. char *key_location = NULL;
  923. int res;
  924. size_t key_len;
  925. memset (totem_config->private_key, 0, 128);
  926. totem_config->private_key_len = 128;
  927. if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
  928. strcmp(totem_config->crypto_hash_type, "none") == 0) {
  929. return (0);
  930. }
  931. /* cmap may store the location of the key file */
  932. if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
  933. res = read_keyfile(key_location, totem_config, error_string);
  934. free(key_location);
  935. if (res) {
  936. goto key_error;
  937. }
  938. got_key = 1;
  939. } else { /* Or the key itself may be in the cmap */
  940. if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
  941. if (key_len > sizeof (totem_config->private_key)) {
  942. sprintf(error_string_response, "key is too long");
  943. goto key_error;
  944. }
  945. if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
  946. totem_config->private_key_len = key_len;
  947. got_key = 1;
  948. } else {
  949. sprintf(error_string_response, "can't store private key");
  950. goto key_error;
  951. }
  952. }
  953. }
  954. /* In desperation we read the default filename */
  955. if (!got_key) {
  956. const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
  957. if (!filename)
  958. filename = COROSYSCONFDIR "/authkey";
  959. res = read_keyfile(filename, totem_config, error_string);
  960. if (res)
  961. goto key_error;
  962. }
  963. return (0);
  964. key_error:
  965. *error_string = error_string_response;
  966. return (-1);
  967. }
  968. static void debug_dump_totem_config(const struct totem_config *totem_config)
  969. {
  970. log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
  971. totem_config->token_timeout, totem_config->token_retransmit_timeout);
  972. log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
  973. totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
  974. log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
  975. totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
  976. totem_config->merge_timeout);
  977. log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
  978. totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
  979. log_printf(LOGSYS_LEVEL_DEBUG,
  980. "seqno unchanged const (%d rotations) Maximum network MTU %d",
  981. totem_config->seqno_unchanged_const, totem_config->net_mtu);
  982. log_printf(LOGSYS_LEVEL_DEBUG,
  983. "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
  984. totem_config->window_size, totem_config->max_messages);
  985. log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
  986. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token expired timeout (%d ms)",
  987. totem_config->rrp_token_expired_timeout);
  988. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token problem counter (%d ms)",
  989. totem_config->rrp_problem_count_timeout);
  990. log_printf(LOGSYS_LEVEL_DEBUG, "RRP threshold (%d problem count)",
  991. totem_config->rrp_problem_count_threshold);
  992. log_printf(LOGSYS_LEVEL_DEBUG, "RRP multicast threshold (%d problem count)",
  993. totem_config->rrp_problem_count_mcast_threshold);
  994. log_printf(LOGSYS_LEVEL_DEBUG, "RRP automatic recovery check timeout (%d ms)",
  995. totem_config->rrp_autorecovery_check_timeout);
  996. log_printf(LOGSYS_LEVEL_DEBUG, "RRP mode set to %s.",
  997. totem_config->rrp_mode);
  998. log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
  999. totem_config->heartbeat_failures_allowed);
  1000. log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
  1001. }
  1002. static void totem_change_notify(
  1003. int32_t event,
  1004. const char *key_name,
  1005. struct icmap_notify_value new_val,
  1006. struct icmap_notify_value old_val,
  1007. void *user_data)
  1008. {
  1009. struct totem_config *totem_config = (struct totem_config *)user_data;
  1010. uint32_t *param;
  1011. uint8_t reloading;
  1012. const char *deleted_key = NULL;
  1013. const char *error_string;
  1014. /*
  1015. * If a full reload is in progress then don't do anything until it's done and
  1016. * can reconfigure it all atomically
  1017. */
  1018. if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
  1019. return;
  1020. param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
  1021. /*
  1022. * Process change only if changed key is found in totem_config (-> param is not NULL)
  1023. * or for special key token_coefficient. token_coefficient key is not stored in
  1024. * totem_config, but it is used for computation of token timeout.
  1025. */
  1026. if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
  1027. return;
  1028. /*
  1029. * Values other then UINT32 are not supported, or needed (yet)
  1030. */
  1031. switch (event) {
  1032. case ICMAP_TRACK_DELETE:
  1033. deleted_key = key_name;
  1034. break;
  1035. case ICMAP_TRACK_ADD:
  1036. case ICMAP_TRACK_MODIFY:
  1037. deleted_key = NULL;
  1038. break;
  1039. default:
  1040. break;
  1041. }
  1042. totem_volatile_config_read (totem_config, deleted_key);
  1043. log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
  1044. debug_dump_totem_config(totem_config);
  1045. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1046. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1047. /*
  1048. * TODO: Consider corosync exit and/or load defaults for volatile
  1049. * values. For now, log error seems to be enough
  1050. */
  1051. }
  1052. }
  1053. static void totem_reload_notify(
  1054. int32_t event,
  1055. const char *key_name,
  1056. struct icmap_notify_value new_val,
  1057. struct icmap_notify_value old_val,
  1058. void *user_data)
  1059. {
  1060. struct totem_config *totem_config = (struct totem_config *)user_data;
  1061. uint32_t local_node_pos;
  1062. const char *error_string;
  1063. /* Reload has completed */
  1064. if (*(uint8_t *)new_val.data == 0) {
  1065. put_nodelist_members_to_config (totem_config);
  1066. totem_volatile_config_read (totem_config, NULL);
  1067. log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
  1068. debug_dump_totem_config(totem_config);
  1069. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1070. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1071. /*
  1072. * TODO: Consider corosync exit and/or load defaults for volatile
  1073. * values. For now, log error seems to be enough
  1074. */
  1075. }
  1076. /* Reinstate the local_node_pos */
  1077. local_node_pos = find_local_node_in_nodelist(totem_config);
  1078. if (local_node_pos != -1) {
  1079. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  1080. }
  1081. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  1082. } else {
  1083. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  1084. }
  1085. }
  1086. static void add_totem_config_notification(struct totem_config *totem_config)
  1087. {
  1088. icmap_track_t icmap_track;
  1089. icmap_track_add("totem.",
  1090. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1091. totem_change_notify,
  1092. totem_config,
  1093. &icmap_track);
  1094. icmap_track_add("config.reload_in_progress",
  1095. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1096. totem_reload_notify,
  1097. totem_config,
  1098. &icmap_track);
  1099. }