totemconfig.c 36 KB

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