totemconfig.c 36 KB

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