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. 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. unsigned 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. if (totem_set_volatile_defaults(totem_config, error_string) == -1) {
  861. return (-1);
  862. }
  863. /*
  864. * RRP values validation
  865. */
  866. if (strcmp (totem_config->rrp_mode, "none") &&
  867. strcmp (totem_config->rrp_mode, "active") &&
  868. strcmp (totem_config->rrp_mode, "passive")) {
  869. snprintf (local_error_reason, sizeof(local_error_reason),
  870. "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
  871. goto parse_error;
  872. }
  873. if (strcmp (totem_config->rrp_mode, "none") == 0) {
  874. interface_max = 1;
  875. }
  876. if (interface_max < totem_config->interface_count) {
  877. snprintf (parse_error, sizeof(parse_error),
  878. "%d is too many configured interfaces for the rrp_mode setting %s.",
  879. totem_config->interface_count,
  880. totem_config->rrp_mode);
  881. error_reason = parse_error;
  882. goto parse_error;
  883. }
  884. if (totem_config->net_mtu == 0) {
  885. totem_config->net_mtu = 1500;
  886. }
  887. return 0;
  888. parse_error:
  889. snprintf (error_string_response, sizeof(error_string_response),
  890. "parse error in config: %s\n", error_reason);
  891. *error_string = error_string_response;
  892. return (-1);
  893. }
  894. static int read_keyfile (
  895. const char *key_location,
  896. struct totem_config *totem_config,
  897. const char **error_string)
  898. {
  899. int fd;
  900. int res;
  901. ssize_t expected_key_len = sizeof (totem_config->private_key);
  902. int saved_errno;
  903. char error_str[100];
  904. const char *error_ptr;
  905. fd = open (key_location, O_RDONLY);
  906. if (fd == -1) {
  907. error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  908. snprintf (error_string_response, sizeof(error_string_response),
  909. "Could not open %s: %s\n",
  910. key_location, error_ptr);
  911. goto parse_error;
  912. }
  913. res = read (fd, totem_config->private_key, expected_key_len);
  914. saved_errno = errno;
  915. close (fd);
  916. if (res == -1) {
  917. error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
  918. snprintf (error_string_response, sizeof(error_string_response),
  919. "Could not read %s: %s\n",
  920. key_location, error_ptr);
  921. goto parse_error;
  922. }
  923. totem_config->private_key_len = expected_key_len;
  924. if (res != expected_key_len) {
  925. snprintf (error_string_response, sizeof(error_string_response),
  926. "Could only read %d bits of 1024 bits from %s.\n",
  927. res * 8, key_location);
  928. goto parse_error;
  929. }
  930. return 0;
  931. parse_error:
  932. *error_string = error_string_response;
  933. return (-1);
  934. }
  935. int totem_config_keyread (
  936. struct totem_config *totem_config,
  937. const char **error_string)
  938. {
  939. int got_key = 0;
  940. char *key_location = NULL;
  941. int res;
  942. size_t key_len;
  943. memset (totem_config->private_key, 0, 128);
  944. totem_config->private_key_len = 128;
  945. if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
  946. strcmp(totem_config->crypto_hash_type, "none") == 0) {
  947. return (0);
  948. }
  949. /* cmap may store the location of the key file */
  950. if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
  951. res = read_keyfile(key_location, totem_config, error_string);
  952. free(key_location);
  953. if (res) {
  954. goto key_error;
  955. }
  956. got_key = 1;
  957. } else { /* Or the key itself may be in the cmap */
  958. if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
  959. if (key_len > sizeof (totem_config->private_key)) {
  960. sprintf(error_string_response, "key is too long");
  961. goto key_error;
  962. }
  963. if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
  964. totem_config->private_key_len = key_len;
  965. got_key = 1;
  966. } else {
  967. sprintf(error_string_response, "can't store private key");
  968. goto key_error;
  969. }
  970. }
  971. }
  972. /* In desperation we read the default filename */
  973. if (!got_key) {
  974. const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
  975. if (!filename)
  976. filename = COROSYSCONFDIR "/authkey";
  977. res = read_keyfile(filename, totem_config, error_string);
  978. if (res)
  979. goto key_error;
  980. }
  981. return (0);
  982. key_error:
  983. *error_string = error_string_response;
  984. return (-1);
  985. }
  986. static void totem_change_notify(
  987. int32_t event,
  988. const char *key_name,
  989. struct icmap_notify_value new_val,
  990. struct icmap_notify_value old_val,
  991. void *user_data)
  992. {
  993. uint32_t *param;
  994. const char *error_string;
  995. uint8_t reloading;
  996. /*
  997. * If a full reload is in progress then don't do anything until it's done and
  998. * can reconfigure it all atomically
  999. */
  1000. if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
  1001. return;
  1002. param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
  1003. if (!param)
  1004. return;
  1005. switch (event)
  1006. {
  1007. case ICMAP_TRACK_DELETE:
  1008. if (new_val.type == ICMAP_VALUETYPE_UINT32)
  1009. *param = 0;
  1010. totem_set_volatile_defaults((struct totem_config *)user_data, &error_string);
  1011. break;
  1012. case ICMAP_TRACK_ADD:
  1013. case ICMAP_TRACK_MODIFY:
  1014. if (new_val.type == ICMAP_VALUETYPE_UINT32)
  1015. memcpy(param, new_val.data, new_val.len);
  1016. /* Other value types not supported, or needed (yet) */
  1017. break;
  1018. default:
  1019. break;
  1020. }
  1021. }
  1022. static void totem_reload_notify(
  1023. int32_t event,
  1024. const char *key_name,
  1025. struct icmap_notify_value new_val,
  1026. struct icmap_notify_value old_val,
  1027. void *user_data)
  1028. {
  1029. struct totem_config *totem_config = (struct totem_config *)user_data;
  1030. uint32_t local_node_pos;
  1031. /* Reload has completed */
  1032. if (*(uint8_t *)new_val.data == 0) {
  1033. int i, j;
  1034. /* Clear out udpu nodelist so we can put the new one in if neede */
  1035. for (i=0; i<totem_config->interface_count; i++) {
  1036. for (j=0; j<PROCESSOR_COUNT_MAX; j++) {
  1037. memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
  1038. }
  1039. }
  1040. put_nodelist_members_to_config (totem_config);
  1041. totem_volatile_config_read (totem_config);
  1042. /* Reinstate the local_node_pos */
  1043. local_node_pos = find_local_node_in_nodelist(totem_config);
  1044. if (local_node_pos != -1) {
  1045. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  1046. }
  1047. }
  1048. }
  1049. static void add_totem_config_notification(struct totem_config *totem_config)
  1050. {
  1051. icmap_track_t icmap_track;
  1052. icmap_track_add("totem.",
  1053. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1054. totem_change_notify,
  1055. totem_config,
  1056. &icmap_track);
  1057. icmap_track_add("config.reload_in_progress",
  1058. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1059. totem_reload_notify,
  1060. totem_config,
  1061. &icmap_track);
  1062. }