totemconfig.c 39 KB

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