totemconfig.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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 BLOCK_UNLISTED_IPS 1
  76. #define CANCEL_TOKEN_HOLD_ON_RETRANSMIT 0
  77. #define DEFAULT_PORT 5405
  78. static char error_string_response[768];
  79. static void add_totem_config_notification(struct totem_config *totem_config);
  80. /* All the volatile parameters are uint32s, luckily */
  81. static uint32_t *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
  82. {
  83. if (strcmp(param_name, "totem.token") == 0)
  84. return &totem_config->token_timeout;
  85. if (strcmp(param_name, "totem.token_retransmit") == 0)
  86. return &totem_config->token_retransmit_timeout;
  87. if (strcmp(param_name, "totem.hold") == 0)
  88. return &totem_config->token_hold_timeout;
  89. if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
  90. return &totem_config->token_retransmits_before_loss_const;
  91. if (strcmp(param_name, "totem.join") == 0)
  92. return &totem_config->join_timeout;
  93. if (strcmp(param_name, "totem.send_join") == 0)
  94. return &totem_config->send_join_timeout;
  95. if (strcmp(param_name, "totem.consensus") == 0)
  96. return &totem_config->consensus_timeout;
  97. if (strcmp(param_name, "totem.merge") == 0)
  98. return &totem_config->merge_timeout;
  99. if (strcmp(param_name, "totem.downcheck") == 0)
  100. return &totem_config->downcheck_timeout;
  101. if (strcmp(param_name, "totem.fail_recv_const") == 0)
  102. return &totem_config->fail_to_recv_const;
  103. if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
  104. return &totem_config->seqno_unchanged_const;
  105. if (strcmp(param_name, "totem.rrp_token_expired_timeout") == 0)
  106. return &totem_config->rrp_token_expired_timeout;
  107. if (strcmp(param_name, "totem.rrp_problem_count_timeout") == 0)
  108. return &totem_config->rrp_problem_count_timeout;
  109. if (strcmp(param_name, "totem.rrp_problem_count_threshold") == 0)
  110. return &totem_config->rrp_problem_count_threshold;
  111. if (strcmp(param_name, "totem.rrp_problem_count_mcast_threshold") == 0)
  112. return &totem_config->rrp_problem_count_mcast_threshold;
  113. if (strcmp(param_name, "totem.rrp_autorecovery_check_timeout") == 0)
  114. return &totem_config->rrp_autorecovery_check_timeout;
  115. if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
  116. return &totem_config->heartbeat_failures_allowed;
  117. if (strcmp(param_name, "totem.max_network_delay") == 0)
  118. return &totem_config->max_network_delay;
  119. if (strcmp(param_name, "totem.window_size") == 0)
  120. return &totem_config->window_size;
  121. if (strcmp(param_name, "totem.max_messages") == 0)
  122. return &totem_config->max_messages;
  123. if (strcmp(param_name, "totem.miss_count_const") == 0)
  124. return &totem_config->miss_count_const;
  125. if (strcmp(param_name, "totem.block_unlisted_ips") == 0)
  126. return &totem_config->block_unlisted_ips;
  127. if (strcmp(param_name, "totem.cancel_token_hold_on_retransmit") == 0)
  128. return &totem_config->cancel_token_hold_on_retransmit;
  129. return NULL;
  130. }
  131. /*
  132. * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
  133. * and readed value is zero, default value is used and stored into totem_config.
  134. */
  135. static void totem_volatile_config_set_value (struct totem_config *totem_config,
  136. const char *key_name, const char *deleted_key, unsigned int default_value,
  137. int allow_zero_value)
  138. {
  139. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  140. if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
  141. (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  142. (!allow_zero_value && *totem_get_param_by_name(totem_config, key_name) == 0)) {
  143. *totem_get_param_by_name(totem_config, key_name) = default_value;
  144. }
  145. /*
  146. * Store totem_config value to cmap runtime section
  147. */
  148. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  149. /*
  150. * This shouldn't happen
  151. */
  152. return ;
  153. }
  154. strcpy(runtime_key_name, "runtime.config.");
  155. strcat(runtime_key_name, key_name);
  156. icmap_set_uint32(runtime_key_name, *totem_get_param_by_name(totem_config, key_name));
  157. }
  158. /*
  159. * Read string value stored in key_name from icmap, use it as a boolean (yes/no) type, convert it
  160. * to integer value (1/0) and store into totem_config.
  161. *
  162. * If key is not found or key_name == delete_key default value is used
  163. * and stored into totem_config.
  164. */
  165. static void totem_volatile_config_set_boolean_value (struct totem_config *totem_config,
  166. const char *key_name, const char *deleted_key, unsigned int default_value)
  167. {
  168. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  169. char *str;
  170. int val;
  171. str = NULL;
  172. val = default_value;
  173. if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  174. (icmap_get_string(key_name, &str) != CS_OK)) {
  175. /*
  176. * Do nothing. str is NULL (icmap_get_string ether not called or
  177. * not changed str).
  178. */
  179. } else {
  180. if (strcmp(str, "yes") == 0) {
  181. val = 1;
  182. } else if (strcmp(str, "no") == 0) {
  183. val = 0;
  184. }
  185. free(str);
  186. }
  187. /*
  188. * Store totem_config value to cmap runtime section
  189. */
  190. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  191. /*
  192. * This shouldn't happen
  193. */
  194. return ;
  195. }
  196. strcpy(runtime_key_name, "runtime.config.");
  197. strcat(runtime_key_name, key_name);
  198. *totem_get_param_by_name(totem_config, key_name) = val;
  199. icmap_set_uint32(runtime_key_name, val);
  200. }
  201. /*
  202. * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
  203. * default value is stored. deleted_key is name of key beeing processed by delete operation
  204. * from cmap. It is considered as non existing even if it can be read. Can be NULL.
  205. */
  206. static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
  207. {
  208. uint32_t u32;
  209. totem_volatile_config_set_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
  210. TOKEN_RETRANSMITS_BEFORE_LOSS_CONST, 0);
  211. totem_volatile_config_set_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
  212. if (totem_config->interface_count > 0 && totem_config->interfaces[0].member_count > 2) {
  213. u32 = TOKEN_COEFFICIENT;
  214. icmap_get_uint32("totem.token_coefficient", &u32);
  215. totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
  216. /*
  217. * Store totem_config value to cmap runtime section
  218. */
  219. icmap_set_uint32("runtime.config.totem.token", totem_config->token_timeout);
  220. }
  221. totem_volatile_config_set_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
  222. totem_volatile_config_set_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
  223. totem_volatile_config_set_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
  224. totem_volatile_config_set_value(totem_config, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
  225. totem_volatile_config_set_value(totem_config, "totem.token_retransmit", deleted_key,
  226. (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
  227. totem_volatile_config_set_value(totem_config, "totem.hold", deleted_key,
  228. (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
  229. totem_volatile_config_set_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
  230. totem_volatile_config_set_value(totem_config, "totem.consensus", deleted_key,
  231. (int)(float)(1.2 * totem_config->token_timeout), 0);
  232. totem_volatile_config_set_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
  233. totem_volatile_config_set_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
  234. totem_volatile_config_set_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
  235. totem_volatile_config_set_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
  236. SEQNO_UNCHANGED_CONST, 0);
  237. totem_volatile_config_set_value(totem_config, "totem.send_join", deleted_key, 0, 1);
  238. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_timeout", deleted_key,
  239. RRP_PROBLEM_COUNT_TIMEOUT, 0);
  240. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_threshold", deleted_key,
  241. RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT, 0);
  242. totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_mcast_threshold", deleted_key,
  243. totem_config->rrp_problem_count_threshold * 10, 0);
  244. totem_volatile_config_set_value(totem_config, "totem.rrp_token_expired_timeout", deleted_key,
  245. totem_config->token_retransmit_timeout, 0);
  246. totem_volatile_config_set_value(totem_config, "totem.rrp_autorecovery_check_timeout", deleted_key,
  247. RRP_AUTORECOVERY_CHECK_TIMEOUT, 0);
  248. totem_volatile_config_set_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
  249. totem_volatile_config_set_boolean_value(totem_config, "totem.block_unlisted_ips", deleted_key,
  250. BLOCK_UNLISTED_IPS);
  251. totem_volatile_config_set_boolean_value(totem_config, "totem.cancel_token_hold_on_retransmit",
  252. deleted_key, CANCEL_TOKEN_HOLD_ON_RETRANSMIT);
  253. }
  254. static int totem_volatile_config_validate (
  255. struct totem_config *totem_config,
  256. const char **error_string)
  257. {
  258. static char local_error_reason[512];
  259. const char *error_reason = local_error_reason;
  260. if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
  261. snprintf (local_error_reason, sizeof(local_error_reason),
  262. "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
  263. totem_config->max_network_delay, MINIMUM_TIMEOUT);
  264. goto parse_error;
  265. }
  266. if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
  267. snprintf (local_error_reason, sizeof(local_error_reason),
  268. "The token timeout parameter (%d ms) may not be less than (%d ms).",
  269. totem_config->token_timeout, MINIMUM_TIMEOUT);
  270. goto parse_error;
  271. }
  272. if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
  273. snprintf (local_error_reason, sizeof(local_error_reason),
  274. "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
  275. totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT);
  276. goto parse_error;
  277. }
  278. if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) {
  279. snprintf (local_error_reason, sizeof(local_error_reason),
  280. "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
  281. totem_config->token_hold_timeout, MINIMUM_TIMEOUT);
  282. goto parse_error;
  283. }
  284. if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
  285. snprintf (local_error_reason, sizeof(local_error_reason),
  286. "The join timeout parameter (%d ms) may not be less than (%d ms).",
  287. totem_config->join_timeout, MINIMUM_TIMEOUT);
  288. goto parse_error;
  289. }
  290. if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
  291. snprintf (local_error_reason, sizeof(local_error_reason),
  292. "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
  293. totem_config->consensus_timeout, MINIMUM_TIMEOUT);
  294. goto parse_error;
  295. }
  296. if (totem_config->consensus_timeout < totem_config->join_timeout) {
  297. snprintf (local_error_reason, sizeof(local_error_reason),
  298. "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
  299. totem_config->consensus_timeout, totem_config->join_timeout);
  300. goto parse_error;
  301. }
  302. if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
  303. snprintf (local_error_reason, sizeof(local_error_reason),
  304. "The merge timeout parameter (%d ms) may not be less than (%d ms).",
  305. totem_config->merge_timeout, MINIMUM_TIMEOUT);
  306. goto parse_error;
  307. }
  308. if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
  309. snprintf (local_error_reason, sizeof(local_error_reason),
  310. "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
  311. totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
  312. goto parse_error;
  313. }
  314. if (totem_config->rrp_problem_count_timeout < MINIMUM_TIMEOUT) {
  315. snprintf (local_error_reason, sizeof(local_error_reason),
  316. "The RRP problem count timeout parameter (%d ms) may not be less than (%d ms).",
  317. totem_config->rrp_problem_count_timeout, MINIMUM_TIMEOUT);
  318. goto parse_error;
  319. }
  320. if (totem_config->rrp_problem_count_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) {
  321. snprintf (local_error_reason, sizeof(local_error_reason),
  322. "The RRP problem count threshold (%d problem count) may not be less than (%d problem count).",
  323. totem_config->rrp_problem_count_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN);
  324. goto parse_error;
  325. }
  326. if (totem_config->rrp_problem_count_mcast_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) {
  327. snprintf (local_error_reason, sizeof(local_error_reason),
  328. "The RRP multicast problem count threshold (%d problem count) may not be less than (%d problem count).",
  329. totem_config->rrp_problem_count_mcast_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN);
  330. goto parse_error;
  331. }
  332. if (totem_config->rrp_token_expired_timeout < MINIMUM_TIMEOUT) {
  333. snprintf (local_error_reason, sizeof(local_error_reason),
  334. "The RRP token expired timeout parameter (%d ms) may not be less than (%d ms).",
  335. totem_config->rrp_token_expired_timeout, MINIMUM_TIMEOUT);
  336. goto parse_error;
  337. }
  338. return 0;
  339. parse_error:
  340. snprintf (error_string_response, sizeof(error_string_response),
  341. "parse error in config: %s\n", error_reason);
  342. *error_string = error_string_response;
  343. return (-1);
  344. }
  345. static int totem_get_crypto(struct totem_config *totem_config)
  346. {
  347. char *str;
  348. const char *tmp_cipher;
  349. const char *tmp_hash;
  350. tmp_hash = "sha1";
  351. tmp_cipher = "aes256";
  352. if (icmap_get_string("totem.secauth", &str) == CS_OK) {
  353. if (strcmp (str, "off") == 0) {
  354. tmp_hash = "none";
  355. tmp_cipher = "none";
  356. }
  357. free(str);
  358. }
  359. if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
  360. if (strcmp(str, "none") == 0) {
  361. tmp_cipher = "none";
  362. }
  363. if (strcmp(str, "aes256") == 0) {
  364. tmp_cipher = "aes256";
  365. }
  366. if (strcmp(str, "aes192") == 0) {
  367. tmp_cipher = "aes192";
  368. }
  369. if (strcmp(str, "aes128") == 0) {
  370. tmp_cipher = "aes128";
  371. }
  372. if (strcmp(str, "3des") == 0) {
  373. tmp_cipher = "3des";
  374. }
  375. free(str);
  376. }
  377. if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
  378. if (strcmp(str, "none") == 0) {
  379. tmp_hash = "none";
  380. }
  381. if (strcmp(str, "md5") == 0) {
  382. tmp_hash = "md5";
  383. }
  384. if (strcmp(str, "sha1") == 0) {
  385. tmp_hash = "sha1";
  386. }
  387. if (strcmp(str, "sha256") == 0) {
  388. tmp_hash = "sha256";
  389. }
  390. if (strcmp(str, "sha384") == 0) {
  391. tmp_hash = "sha384";
  392. }
  393. if (strcmp(str, "sha512") == 0) {
  394. tmp_hash = "sha512";
  395. }
  396. free(str);
  397. }
  398. if ((strcmp(tmp_cipher, "none") != 0) &&
  399. (strcmp(tmp_hash, "none") == 0)) {
  400. return -1;
  401. }
  402. free(totem_config->crypto_cipher_type);
  403. free(totem_config->crypto_hash_type);
  404. totem_config->crypto_cipher_type = strdup(tmp_cipher);
  405. totem_config->crypto_hash_type = strdup(tmp_hash);
  406. return 0;
  407. }
  408. static int totem_config_get_ip_version(void)
  409. {
  410. int res;
  411. char *str;
  412. res = AF_INET;
  413. if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
  414. if (strcmp(str, "ipv4") == 0) {
  415. res = AF_INET;
  416. }
  417. if (strcmp(str, "ipv6") == 0) {
  418. res = AF_INET6;
  419. }
  420. free(str);
  421. }
  422. return (res);
  423. }
  424. static uint16_t generate_cluster_id (const char *cluster_name)
  425. {
  426. int i;
  427. int value = 0;
  428. for (i = 0; i < strlen(cluster_name); i++) {
  429. value <<= 1;
  430. value += cluster_name[i];
  431. }
  432. return (value & 0xFFFF);
  433. }
  434. static int get_cluster_mcast_addr (
  435. const char *cluster_name,
  436. unsigned int ringnumber,
  437. int ip_version,
  438. struct totem_ip_address *res)
  439. {
  440. uint16_t clusterid;
  441. char addr[INET6_ADDRSTRLEN + 1];
  442. int err;
  443. if (cluster_name == NULL) {
  444. return (-1);
  445. }
  446. clusterid = generate_cluster_id(cluster_name) + ringnumber;
  447. memset (res, 0, sizeof(*res));
  448. switch (ip_version) {
  449. case AF_INET:
  450. snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
  451. break;
  452. case AF_INET6:
  453. snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
  454. break;
  455. default:
  456. /*
  457. * Unknown family
  458. */
  459. return (-1);
  460. }
  461. err = totemip_parse (res, addr, ip_version);
  462. return (err);
  463. }
  464. static unsigned int generate_nodeid_for_duplicate_test(
  465. struct totem_config *totem_config,
  466. char *addr)
  467. {
  468. unsigned int nodeid;
  469. struct totem_ip_address totemip;
  470. /* AF_INET hard-coded here because auto-generated nodeids
  471. are only for IPv4 */
  472. if (totemip_parse(&totemip, addr, AF_INET) != 0)
  473. return -1;
  474. memcpy (&nodeid, &totemip.addr, sizeof (unsigned int));
  475. #if __BYTE_ORDER == __LITTLE_ENDIAN
  476. nodeid = swab32 (nodeid);
  477. #endif
  478. if (totem_config->clear_node_high_bit) {
  479. nodeid &= 0x7FFFFFFF;
  480. }
  481. return nodeid;
  482. }
  483. static int check_for_duplicate_nodeids(
  484. struct totem_config *totem_config,
  485. const char **error_string)
  486. {
  487. icmap_iter_t iter;
  488. icmap_iter_t subiter;
  489. const char *iter_key;
  490. int res = 0;
  491. int retval = 0;
  492. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  493. char *ring0_addr=NULL;
  494. char *ring0_addr1=NULL;
  495. unsigned int node_pos;
  496. unsigned int node_pos1;
  497. unsigned int nodeid;
  498. unsigned int nodeid1;
  499. int autogenerated;
  500. iter = icmap_iter_init("nodelist.node.");
  501. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  502. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  503. if (res != 2) {
  504. continue;
  505. }
  506. if (strcmp(tmp_key, "ring0_addr") != 0) {
  507. continue;
  508. }
  509. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
  510. autogenerated = 0;
  511. if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
  512. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  513. if (icmap_get_string(tmp_key, &ring0_addr) != CS_OK) {
  514. continue;
  515. }
  516. /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
  517. nodeid = generate_nodeid_for_duplicate_test(totem_config, ring0_addr);
  518. if (nodeid == -1) {
  519. continue;
  520. }
  521. autogenerated = 1;
  522. }
  523. node_pos1 = 0;
  524. subiter = icmap_iter_init("nodelist.node.");
  525. while (((iter_key = icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
  526. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos1, tmp_key);
  527. if ((res != 2) || (node_pos1 >= node_pos)) {
  528. continue;
  529. }
  530. if (strcmp(tmp_key, "ring0_addr") != 0) {
  531. continue;
  532. }
  533. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
  534. if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
  535. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos1);
  536. if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
  537. continue;
  538. }
  539. nodeid1 = generate_nodeid_for_duplicate_test(totem_config, ring0_addr1);
  540. if (nodeid1 == -1) {
  541. continue;
  542. }
  543. }
  544. if (nodeid == nodeid1) {
  545. retval = -1;
  546. snprintf (error_string_response, sizeof(error_string_response),
  547. "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
  548. autogenerated?"(autogenerated from ":"",
  549. autogenerated?ring0_addr:"",
  550. autogenerated?")":"");
  551. log_printf (LOGSYS_LEVEL_ERROR, error_string_response);
  552. *error_string = error_string_response;
  553. break;
  554. }
  555. }
  556. icmap_iter_finalize(subiter);
  557. }
  558. icmap_iter_finalize(iter);
  559. return retval;
  560. }
  561. static int find_local_node_in_nodelist(struct totem_config *totem_config)
  562. {
  563. icmap_iter_t iter;
  564. const char *iter_key;
  565. int res = 0;
  566. unsigned int node_pos;
  567. int local_node_pos = -1;
  568. struct totem_ip_address bind_addr;
  569. int interface_up, interface_num;
  570. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  571. char *node_addr_str;
  572. struct totem_ip_address node_addr;
  573. res = totemip_iface_check(&totem_config->interfaces[0].bindnet,
  574. &bind_addr, &interface_up, &interface_num,
  575. totem_config->clear_node_high_bit);
  576. if (res == -1) {
  577. return (-1);
  578. }
  579. iter = icmap_iter_init("nodelist.node.");
  580. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  581. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  582. if (res != 2) {
  583. continue;
  584. }
  585. if (strcmp(tmp_key, "ring0_addr") != 0) {
  586. continue;
  587. }
  588. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  589. if (icmap_get_string(tmp_key, &node_addr_str) != CS_OK) {
  590. continue;
  591. }
  592. res = totemip_parse (&node_addr, node_addr_str, totem_config->ip_version);
  593. free(node_addr_str);
  594. if (res == -1) {
  595. continue ;
  596. }
  597. if (totemip_equal(&bind_addr, &node_addr)) {
  598. local_node_pos = node_pos;
  599. }
  600. }
  601. icmap_iter_finalize(iter);
  602. return (local_node_pos);
  603. }
  604. /*
  605. * Compute difference between two set of totem interface arrays. set1 and set2
  606. * are changed so for same ring, ip existing in both set1 and set2 are cleared
  607. * (set to 0), and ips which are only in set1 or set2 remains untouched.
  608. * totempg_node_add/remove is called.
  609. */
  610. static void compute_interfaces_diff(int interface_count,
  611. struct totem_interface *set1,
  612. struct totem_interface *set2)
  613. {
  614. int ring_no, set1_pos, set2_pos;
  615. struct totem_ip_address empty_ip_address;
  616. memset(&empty_ip_address, 0, sizeof(empty_ip_address));
  617. for (ring_no = 0; ring_no < interface_count; ring_no++) {
  618. for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
  619. for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
  620. /*
  621. * For current ring_no remove all set1 items existing
  622. * in set2
  623. */
  624. if (memcmp(&set1[ring_no].member_list[set1_pos],
  625. &set2[ring_no].member_list[set2_pos],
  626. sizeof(struct totem_ip_address)) == 0) {
  627. memset(&set1[ring_no].member_list[set1_pos], 0,
  628. sizeof(struct totem_ip_address));
  629. memset(&set2[ring_no].member_list[set2_pos], 0,
  630. sizeof(struct totem_ip_address));
  631. }
  632. }
  633. }
  634. }
  635. for (ring_no = 0; ring_no < interface_count; ring_no++) {
  636. for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
  637. /*
  638. * All items which remained in set1 doesn't exists in set2 any longer so
  639. * node has to be removed.
  640. */
  641. if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
  642. log_printf(LOGSYS_LEVEL_DEBUG,
  643. "removing dynamic member %s for ring %u",
  644. totemip_print(&set1[ring_no].member_list[set1_pos]),
  645. ring_no);
  646. totempg_member_remove(&set1[ring_no].member_list[set1_pos], ring_no);
  647. }
  648. }
  649. for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
  650. /*
  651. * All items which remained in set2 doesn't existed in set1 so this is no node
  652. * and has to be added.
  653. */
  654. if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
  655. log_printf(LOGSYS_LEVEL_DEBUG,
  656. "adding dynamic member %s for ring %u",
  657. totemip_print(&set2[ring_no].member_list[set2_pos]),
  658. ring_no);
  659. totempg_member_add(&set2[ring_no].member_list[set2_pos], ring_no);
  660. }
  661. }
  662. }
  663. }
  664. static void put_nodelist_members_to_config(struct totem_config *totem_config, int reload)
  665. {
  666. icmap_iter_t iter, iter2;
  667. const char *iter_key, *iter_key2;
  668. int res = 0;
  669. unsigned int node_pos;
  670. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  671. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  672. char *node_addr_str;
  673. int member_count;
  674. unsigned int ringnumber = 0;
  675. int i, j;
  676. struct totem_interface *orig_interfaces = NULL;
  677. struct totem_interface *new_interfaces = NULL;
  678. if (reload) {
  679. /*
  680. * We need to compute diff only for reload. Also for initial configuration
  681. * not all totem structures are initialized so corosync will crash during
  682. * member_add/remove
  683. */
  684. orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  685. assert(orig_interfaces != NULL);
  686. new_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  687. assert(new_interfaces != NULL);
  688. memcpy(orig_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
  689. }
  690. /* Clear out nodelist so we can put the new one in if needed */
  691. for (i = 0; i < totem_config->interface_count; i++) {
  692. for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
  693. memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
  694. }
  695. totem_config->interfaces[i].member_count = 0;
  696. }
  697. iter = icmap_iter_init("nodelist.node.");
  698. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  699. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  700. if (res != 2) {
  701. continue;
  702. }
  703. if (strcmp(tmp_key, "ring0_addr") != 0) {
  704. continue;
  705. }
  706. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  707. iter2 = icmap_iter_init(tmp_key);
  708. while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
  709. res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  710. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  711. continue;
  712. }
  713. if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
  714. continue;
  715. }
  716. member_count = totem_config->interfaces[ringnumber].member_count;
  717. res = totemip_parse(&totem_config->interfaces[ringnumber].member_list[member_count],
  718. node_addr_str, totem_config->ip_version);
  719. if (res != -1) {
  720. totem_config->interfaces[ringnumber].member_count++;
  721. }
  722. free(node_addr_str);
  723. }
  724. icmap_iter_finalize(iter2);
  725. }
  726. icmap_iter_finalize(iter);
  727. if (reload) {
  728. memcpy(new_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
  729. compute_interfaces_diff(totem_config->interface_count, orig_interfaces, new_interfaces);
  730. free(new_interfaces);
  731. free(orig_interfaces);
  732. }
  733. }
  734. static void nodelist_dynamic_notify(
  735. int32_t event,
  736. const char *key_name,
  737. struct icmap_notify_value new_val,
  738. struct icmap_notify_value old_val,
  739. void *user_data)
  740. {
  741. int res;
  742. unsigned int ring_no;
  743. unsigned int member_no;
  744. char tmp_str[ICMAP_KEYNAME_MAXLEN];
  745. uint8_t reloading;
  746. struct totem_config *totem_config = (struct totem_config *)user_data;
  747. /*
  748. * If a full reload is in progress then don't do anything until it's done and
  749. * can reconfigure it all atomically
  750. */
  751. if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
  752. return ;
  753. }
  754. res = sscanf(key_name, "nodelist.node.%u.ring%u%s", &member_no, &ring_no, tmp_str);
  755. if (res != 3)
  756. return ;
  757. if (strcmp(tmp_str, "_addr") != 0) {
  758. return;
  759. }
  760. put_nodelist_members_to_config(totem_config, 1);
  761. }
  762. /*
  763. * Tries to find node (node_pos) in config nodelist which address matches any
  764. * local interface. Address can be stored in ring0_addr or if ipaddr_key_prefix is not NULL
  765. * key with prefix ipaddr_key is used (there can be multiuple of them)
  766. * This function differs * from find_local_node_in_nodelist because it doesn't need bindnetaddr,
  767. * but doesn't work when bind addr is network address (so IP must be exact
  768. * match).
  769. *
  770. * Returns 1 on success (address was found, node_pos is then correctly set) or 0 on failure.
  771. */
  772. int totem_config_find_local_addr_in_nodelist(const char *ipaddr_key_prefix, unsigned int *node_pos)
  773. {
  774. struct list_head addrs;
  775. struct totem_ip_if_address *if_addr;
  776. icmap_iter_t iter, iter2;
  777. const char *iter_key, *iter_key2;
  778. struct list_head *list;
  779. const char *ipaddr_key;
  780. int ip_version;
  781. struct totem_ip_address node_addr;
  782. char *node_addr_str;
  783. int node_found = 0;
  784. int res = 0;
  785. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  786. if (totemip_getifaddrs(&addrs) == -1) {
  787. return 0;
  788. }
  789. ip_version = totem_config_get_ip_version();
  790. iter = icmap_iter_init("nodelist.node.");
  791. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  792. res = sscanf(iter_key, "nodelist.node.%u.%s", node_pos, tmp_key);
  793. if (res != 2) {
  794. continue;
  795. }
  796. if (strcmp(tmp_key, "ring0_addr") != 0) {
  797. continue;
  798. }
  799. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  800. continue ;
  801. }
  802. free(node_addr_str);
  803. /*
  804. * ring0_addr found -> let's iterate thru ipaddr_key_prefix
  805. */
  806. snprintf(tmp_key, sizeof(tmp_key), "nodelist.node.%u.%s", *node_pos,
  807. (ipaddr_key_prefix != NULL ? ipaddr_key_prefix : "ring0_addr"));
  808. iter2 = icmap_iter_init(tmp_key);
  809. while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
  810. /*
  811. * ring0_addr must be exact match, not prefix
  812. */
  813. ipaddr_key = (ipaddr_key_prefix != NULL ? iter_key2 : tmp_key);
  814. if (icmap_get_string(ipaddr_key, &node_addr_str) != CS_OK) {
  815. continue ;
  816. }
  817. if (totemip_parse(&node_addr, node_addr_str, ip_version) == -1) {
  818. free(node_addr_str);
  819. continue ;
  820. }
  821. free(node_addr_str);
  822. /*
  823. * Try to match ip with if_addrs
  824. */
  825. node_found = 0;
  826. for (list = addrs.next; list != &addrs; list = list->next) {
  827. if_addr = list_entry(list, struct totem_ip_if_address, list);
  828. if (totemip_equal(&node_addr, &if_addr->ip_addr)) {
  829. node_found = 1;
  830. break;
  831. }
  832. }
  833. if (node_found) {
  834. break ;
  835. }
  836. }
  837. icmap_iter_finalize(iter2);
  838. if (node_found) {
  839. break ;
  840. }
  841. }
  842. icmap_iter_finalize(iter);
  843. totemip_freeifaddrs(&addrs);
  844. return (node_found);
  845. }
  846. static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
  847. {
  848. int res = 0;
  849. unsigned int node_pos;
  850. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  851. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  852. char *node_addr_str;
  853. unsigned int ringnumber = 0;
  854. icmap_iter_t iter;
  855. const char *iter_key;
  856. if (totem_config_find_local_addr_in_nodelist(NULL, &node_pos)) {
  857. /*
  858. * We found node, so create interface section
  859. */
  860. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  861. iter = icmap_iter_init(tmp_key);
  862. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  863. res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
  864. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  865. continue ;
  866. }
  867. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  868. continue;
  869. }
  870. snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", ringnumber);
  871. icmap_set_string(tmp_key2, node_addr_str);
  872. free(node_addr_str);
  873. }
  874. icmap_iter_finalize(iter);
  875. }
  876. }
  877. extern int totem_config_read (
  878. struct totem_config *totem_config,
  879. const char **error_string,
  880. uint64_t *warnings)
  881. {
  882. int res = 0;
  883. char *str, *ring0_addr_str;
  884. unsigned int ringnumber = 0;
  885. int member_count = 0;
  886. icmap_iter_t iter, member_iter;
  887. const char *iter_key;
  888. const char *member_iter_key;
  889. char ringnumber_key[ICMAP_KEYNAME_MAXLEN];
  890. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  891. uint8_t u8;
  892. uint16_t u16;
  893. char *cluster_name = NULL;
  894. int i;
  895. int local_node_pos;
  896. int nodeid_set;
  897. *warnings = 0;
  898. memset (totem_config, 0, sizeof (struct totem_config));
  899. totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  900. if (totem_config->interfaces == 0) {
  901. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  902. return -1;
  903. }
  904. memset (totem_config->interfaces, 0,
  905. sizeof (struct totem_interface) * INTERFACE_MAX);
  906. strcpy (totem_config->rrp_mode, "none");
  907. icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
  908. if (totem_get_crypto(totem_config) != 0) {
  909. *error_string = "crypto_cipher requires crypto_hash with value other than none";
  910. return -1;
  911. }
  912. if (icmap_get_string("totem.rrp_mode", &str) == CS_OK) {
  913. if (strlen(str) >= TOTEM_RRP_MODE_BYTES) {
  914. *error_string = "totem.rrp_mode is too long";
  915. free(str);
  916. return -1;
  917. }
  918. strcpy (totem_config->rrp_mode, str);
  919. free(str);
  920. }
  921. icmap_get_uint32("totem.nodeid", &totem_config->node_id);
  922. totem_config->clear_node_high_bit = 0;
  923. if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
  924. if (strcmp (str, "yes") == 0) {
  925. totem_config->clear_node_high_bit = 1;
  926. }
  927. free(str);
  928. }
  929. icmap_get_uint32("totem.threads", &totem_config->threads);
  930. icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
  931. if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
  932. cluster_name = NULL;
  933. }
  934. totem_config->ip_version = totem_config_get_ip_version();
  935. if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
  936. /*
  937. * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
  938. */
  939. config_convert_nodelist_to_interface(totem_config);
  940. } else {
  941. if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str) == CS_OK) {
  942. /*
  943. * Both bindnetaddr and ring0_addr are set.
  944. * Log warning information, and use nodelist instead
  945. */
  946. *warnings |= TOTEM_CONFIG_BINDNETADDR_NODELIST_SET;
  947. config_convert_nodelist_to_interface(totem_config);
  948. free(ring0_addr_str);
  949. }
  950. free(str);
  951. }
  952. /*
  953. * Broadcast option is global but set in interface section,
  954. * so reset before processing interfaces.
  955. */
  956. totem_config->broadcast_use = 0;
  957. iter = icmap_iter_init("totem.interface.");
  958. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  959. res = sscanf(iter_key, "totem.interface.%[^.].%s", ringnumber_key, tmp_key);
  960. if (res != 2) {
  961. continue;
  962. }
  963. if (strcmp(tmp_key, "bindnetaddr") != 0) {
  964. continue;
  965. }
  966. member_count = 0;
  967. ringnumber = atoi(ringnumber_key);
  968. if (ringnumber >= INTERFACE_MAX) {
  969. free(cluster_name);
  970. snprintf (error_string_response, sizeof(error_string_response),
  971. "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
  972. ringnumber, INTERFACE_MAX - 1);
  973. *error_string = error_string_response;
  974. return -1;
  975. }
  976. /*
  977. * Get the bind net address
  978. */
  979. if (icmap_get_string(iter_key, &str) == CS_OK) {
  980. res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
  981. totem_config->ip_version);
  982. free(str);
  983. }
  984. /*
  985. * Get interface multicast address
  986. */
  987. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", ringnumber);
  988. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  989. res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, totem_config->ip_version);
  990. free(str);
  991. } else {
  992. /*
  993. * User not specified address -> autogenerate one from cluster_name key
  994. * (if available). Return code is intentionally ignored, because
  995. * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
  996. * checked later anyway.
  997. */
  998. (void)get_cluster_mcast_addr (cluster_name,
  999. ringnumber,
  1000. totem_config->ip_version,
  1001. &totem_config->interfaces[ringnumber].mcast_addr);
  1002. }
  1003. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", ringnumber);
  1004. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1005. if (strcmp (str, "yes") == 0) {
  1006. totem_config->broadcast_use = 1;
  1007. }
  1008. free(str);
  1009. }
  1010. /*
  1011. * Get mcast port
  1012. */
  1013. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", ringnumber);
  1014. if (icmap_get_uint16(tmp_key, &totem_config->interfaces[ringnumber].ip_port) != CS_OK) {
  1015. if (totem_config->broadcast_use) {
  1016. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT + (2 * ringnumber);
  1017. } else {
  1018. totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT;
  1019. }
  1020. }
  1021. /*
  1022. * Get the TTL
  1023. */
  1024. totem_config->interfaces[ringnumber].ttl = 1;
  1025. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", ringnumber);
  1026. if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
  1027. totem_config->interfaces[ringnumber].ttl = u8;
  1028. }
  1029. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", ringnumber);
  1030. member_iter = icmap_iter_init(tmp_key);
  1031. while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
  1032. if (member_count == 0) {
  1033. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  1034. free(str);
  1035. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED;
  1036. break;
  1037. } else {
  1038. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED;
  1039. }
  1040. }
  1041. if (icmap_get_string(member_iter_key, &str) == CS_OK) {
  1042. res = totemip_parse (&totem_config->interfaces[ringnumber].member_list[member_count++],
  1043. str, totem_config->ip_version);
  1044. }
  1045. }
  1046. icmap_iter_finalize(member_iter);
  1047. totem_config->interfaces[ringnumber].member_count = member_count;
  1048. totem_config->interface_count++;
  1049. }
  1050. icmap_iter_finalize(iter);
  1051. /*
  1052. * Use broadcast is global, so if set, make sure to fill mcast addr correctly
  1053. */
  1054. if (totem_config->broadcast_use) {
  1055. for (ringnumber = 0; ringnumber < totem_config->interface_count; ringnumber++) {
  1056. totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr,
  1057. "255.255.255.255", 0);
  1058. }
  1059. }
  1060. /*
  1061. * Store automatically generated items back to icmap
  1062. */
  1063. for (i = 0; i < totem_config->interface_count; i++) {
  1064. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
  1065. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1066. free(str);
  1067. } else {
  1068. str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
  1069. icmap_set_string(tmp_key, str);
  1070. }
  1071. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
  1072. if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
  1073. icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
  1074. }
  1075. }
  1076. totem_config->transport_number = TOTEM_TRANSPORT_UDP;
  1077. if (icmap_get_string("totem.transport", &str) == CS_OK) {
  1078. if (strcmp (str, "udpu") == 0) {
  1079. totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
  1080. }
  1081. if (strcmp (str, "iba") == 0) {
  1082. totem_config->transport_number = TOTEM_TRANSPORT_RDMA;
  1083. }
  1084. free(str);
  1085. }
  1086. free(cluster_name);
  1087. /*
  1088. * Check existence of nodelist
  1089. */
  1090. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  1091. free(str);
  1092. /*
  1093. * find local node
  1094. */
  1095. local_node_pos = find_local_node_in_nodelist(totem_config);
  1096. if (local_node_pos != -1) {
  1097. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  1098. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
  1099. nodeid_set = (totem_config->node_id != 0);
  1100. if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
  1101. *warnings |= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED;
  1102. }
  1103. /*
  1104. * Make localnode ring0_addr read only, so we can be sure that local
  1105. * node never changes. If rebinding to other IP would be in future
  1106. * supported, this must be changed and handled properly!
  1107. */
  1108. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
  1109. icmap_set_ro_access(tmp_key, 0, 1);
  1110. icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
  1111. }
  1112. put_nodelist_members_to_config(totem_config, 0);
  1113. }
  1114. /*
  1115. * Get things that might change in the future (and can depend on totem_config->interfaces);
  1116. */
  1117. totem_volatile_config_read(totem_config, NULL);
  1118. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  1119. add_totem_config_notification(totem_config);
  1120. return 0;
  1121. }
  1122. int totem_config_validate (
  1123. struct totem_config *totem_config,
  1124. const char **error_string)
  1125. {
  1126. static char local_error_reason[512];
  1127. char parse_error[512];
  1128. const char *error_reason = local_error_reason;
  1129. int i, j;
  1130. unsigned int interface_max = INTERFACE_MAX;
  1131. unsigned int port1, port2;
  1132. if (totem_config->interface_count == 0) {
  1133. error_reason = "No interfaces defined";
  1134. goto parse_error;
  1135. }
  1136. for (i = 0; i < totem_config->interface_count; i++) {
  1137. /*
  1138. * Some error checking of parsed data to make sure its valid
  1139. */
  1140. struct totem_ip_address null_addr;
  1141. memset (&null_addr, 0, sizeof (struct totem_ip_address));
  1142. if ((totem_config->transport_number == 0) &&
  1143. memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
  1144. sizeof (struct totem_ip_address)) == 0) {
  1145. error_reason = "No multicast address specified";
  1146. goto parse_error;
  1147. }
  1148. if (totem_config->interfaces[i].ip_port == 0) {
  1149. error_reason = "No multicast port specified";
  1150. goto parse_error;
  1151. }
  1152. if (totem_config->interfaces[i].ttl > 255) {
  1153. error_reason = "Invalid TTL (should be 0..255)";
  1154. goto parse_error;
  1155. }
  1156. if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
  1157. totem_config->interfaces[i].ttl != 1) {
  1158. error_reason = "Can only set ttl on multicast transport types";
  1159. goto parse_error;
  1160. }
  1161. if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
  1162. totem_config->node_id == 0) {
  1163. error_reason = "An IPV6 network requires that a node ID be specified.";
  1164. goto parse_error;
  1165. }
  1166. if (totem_config->broadcast_use == 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1167. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  1168. error_reason = "Multicast address family does not match bind address family";
  1169. goto parse_error;
  1170. }
  1171. if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
  1172. error_reason = "mcastaddr is not a correct multicast address.";
  1173. goto parse_error;
  1174. }
  1175. }
  1176. if (totem_config->interfaces[0].bindnet.family != totem_config->interfaces[i].bindnet.family) {
  1177. error_reason = "Not all bind address belong to the same IP family";
  1178. goto parse_error;
  1179. }
  1180. /*
  1181. * Ensure mcast address/port differs
  1182. */
  1183. if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1184. for (j = i + 1; j < totem_config->interface_count; j++) {
  1185. port1 = totem_config->interfaces[i].ip_port;
  1186. port2 = totem_config->interfaces[j].ip_port;
  1187. if (totemip_equal(&totem_config->interfaces[i].mcast_addr,
  1188. &totem_config->interfaces[j].mcast_addr) &&
  1189. (((port1 > port2 ? port1 : port2) - (port1 < port2 ? port1 : port2)) <= 1)) {
  1190. error_reason = "Interfaces multicast address/port pair must differ";
  1191. goto parse_error;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. if (totem_config->version != 2) {
  1197. error_reason = "This totem parser can only parse version 2 configurations.";
  1198. goto parse_error;
  1199. }
  1200. if (totem_volatile_config_validate(totem_config, error_string) == -1) {
  1201. return (-1);
  1202. }
  1203. if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
  1204. return (-1);
  1205. }
  1206. /*
  1207. * RRP values validation
  1208. */
  1209. if (strcmp (totem_config->rrp_mode, "none") &&
  1210. strcmp (totem_config->rrp_mode, "active") &&
  1211. strcmp (totem_config->rrp_mode, "passive")) {
  1212. snprintf (local_error_reason, sizeof(local_error_reason),
  1213. "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
  1214. goto parse_error;
  1215. }
  1216. if (strcmp (totem_config->rrp_mode, "none") == 0) {
  1217. interface_max = 1;
  1218. }
  1219. if (interface_max < totem_config->interface_count) {
  1220. snprintf (parse_error, sizeof(parse_error),
  1221. "%d is too many configured interfaces for the rrp_mode setting %s.",
  1222. totem_config->interface_count,
  1223. totem_config->rrp_mode);
  1224. error_reason = parse_error;
  1225. goto parse_error;
  1226. }
  1227. if (totem_config->net_mtu == 0) {
  1228. totem_config->net_mtu = 1500;
  1229. }
  1230. return 0;
  1231. parse_error:
  1232. snprintf (error_string_response, sizeof(error_string_response),
  1233. "parse error in config: %s\n", error_reason);
  1234. *error_string = error_string_response;
  1235. return (-1);
  1236. }
  1237. static int read_keyfile (
  1238. const char *key_location,
  1239. struct totem_config *totem_config,
  1240. const char **error_string)
  1241. {
  1242. int fd;
  1243. int res;
  1244. ssize_t expected_key_len = sizeof (totem_config->private_key);
  1245. int saved_errno;
  1246. char error_str[100];
  1247. const char *error_ptr;
  1248. fd = open (key_location, O_RDONLY);
  1249. if (fd == -1) {
  1250. error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  1251. snprintf (error_string_response, sizeof(error_string_response),
  1252. "Could not open %s: %s\n",
  1253. key_location, error_ptr);
  1254. goto parse_error;
  1255. }
  1256. res = read (fd, totem_config->private_key, expected_key_len);
  1257. saved_errno = errno;
  1258. close (fd);
  1259. if (res == -1) {
  1260. error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
  1261. snprintf (error_string_response, sizeof(error_string_response),
  1262. "Could not read %s: %s\n",
  1263. key_location, error_ptr);
  1264. goto parse_error;
  1265. }
  1266. totem_config->private_key_len = expected_key_len;
  1267. if (res != expected_key_len) {
  1268. snprintf (error_string_response, sizeof(error_string_response),
  1269. "Could only read %d bits of 1024 bits from %s.\n",
  1270. res * 8, key_location);
  1271. goto parse_error;
  1272. }
  1273. return 0;
  1274. parse_error:
  1275. *error_string = error_string_response;
  1276. return (-1);
  1277. }
  1278. int totem_config_keyread (
  1279. struct totem_config *totem_config,
  1280. const char **error_string)
  1281. {
  1282. int got_key = 0;
  1283. char *key_location = NULL;
  1284. int res;
  1285. size_t key_len;
  1286. memset (totem_config->private_key, 0, 128);
  1287. totem_config->private_key_len = 128;
  1288. if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
  1289. strcmp(totem_config->crypto_hash_type, "none") == 0) {
  1290. return (0);
  1291. }
  1292. /* cmap may store the location of the key file */
  1293. if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
  1294. res = read_keyfile(key_location, totem_config, error_string);
  1295. free(key_location);
  1296. if (res) {
  1297. goto key_error;
  1298. }
  1299. got_key = 1;
  1300. } else { /* Or the key itself may be in the cmap */
  1301. if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
  1302. if (key_len > sizeof (totem_config->private_key)) {
  1303. sprintf(error_string_response, "key is too long");
  1304. goto key_error;
  1305. }
  1306. if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
  1307. totem_config->private_key_len = key_len;
  1308. got_key = 1;
  1309. } else {
  1310. sprintf(error_string_response, "can't store private key");
  1311. goto key_error;
  1312. }
  1313. }
  1314. }
  1315. /* In desperation we read the default filename */
  1316. if (!got_key) {
  1317. const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
  1318. if (!filename)
  1319. filename = COROSYSCONFDIR "/authkey";
  1320. res = read_keyfile(filename, totem_config, error_string);
  1321. if (res)
  1322. goto key_error;
  1323. }
  1324. return (0);
  1325. key_error:
  1326. *error_string = error_string_response;
  1327. return (-1);
  1328. }
  1329. static void debug_dump_totem_config(const struct totem_config *totem_config)
  1330. {
  1331. log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
  1332. totem_config->token_timeout, totem_config->token_retransmit_timeout);
  1333. log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
  1334. totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
  1335. log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
  1336. totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
  1337. totem_config->merge_timeout);
  1338. log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
  1339. totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
  1340. log_printf(LOGSYS_LEVEL_DEBUG,
  1341. "seqno unchanged const (%d rotations) Maximum network MTU %d",
  1342. totem_config->seqno_unchanged_const, totem_config->net_mtu);
  1343. log_printf(LOGSYS_LEVEL_DEBUG,
  1344. "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
  1345. totem_config->window_size, totem_config->max_messages);
  1346. log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
  1347. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token expired timeout (%d ms)",
  1348. totem_config->rrp_token_expired_timeout);
  1349. log_printf(LOGSYS_LEVEL_DEBUG, "RRP token problem counter (%d ms)",
  1350. totem_config->rrp_problem_count_timeout);
  1351. log_printf(LOGSYS_LEVEL_DEBUG, "RRP threshold (%d problem count)",
  1352. totem_config->rrp_problem_count_threshold);
  1353. log_printf(LOGSYS_LEVEL_DEBUG, "RRP multicast threshold (%d problem count)",
  1354. totem_config->rrp_problem_count_mcast_threshold);
  1355. log_printf(LOGSYS_LEVEL_DEBUG, "RRP automatic recovery check timeout (%d ms)",
  1356. totem_config->rrp_autorecovery_check_timeout);
  1357. log_printf(LOGSYS_LEVEL_DEBUG, "RRP mode set to %s.",
  1358. totem_config->rrp_mode);
  1359. log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
  1360. totem_config->heartbeat_failures_allowed);
  1361. log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
  1362. }
  1363. static void totem_change_notify(
  1364. int32_t event,
  1365. const char *key_name,
  1366. struct icmap_notify_value new_val,
  1367. struct icmap_notify_value old_val,
  1368. void *user_data)
  1369. {
  1370. struct totem_config *totem_config = (struct totem_config *)user_data;
  1371. uint32_t *param;
  1372. uint8_t reloading;
  1373. const char *deleted_key = NULL;
  1374. const char *error_string;
  1375. /*
  1376. * If a full reload is in progress then don't do anything until it's done and
  1377. * can reconfigure it all atomically
  1378. */
  1379. if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
  1380. return;
  1381. param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
  1382. /*
  1383. * Process change only if changed key is found in totem_config (-> param is not NULL)
  1384. * or for special key token_coefficient. token_coefficient key is not stored in
  1385. * totem_config, but it is used for computation of token timeout.
  1386. */
  1387. if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
  1388. return;
  1389. /*
  1390. * Values other than UINT32 are not supported, or needed (yet)
  1391. */
  1392. switch (event) {
  1393. case ICMAP_TRACK_DELETE:
  1394. deleted_key = key_name;
  1395. break;
  1396. case ICMAP_TRACK_ADD:
  1397. case ICMAP_TRACK_MODIFY:
  1398. deleted_key = NULL;
  1399. break;
  1400. default:
  1401. break;
  1402. }
  1403. totem_volatile_config_read (totem_config, deleted_key);
  1404. log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
  1405. debug_dump_totem_config(totem_config);
  1406. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1407. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1408. /*
  1409. * TODO: Consider corosync exit and/or load defaults for volatile
  1410. * values. For now, log error seems to be enough
  1411. */
  1412. }
  1413. }
  1414. static void totem_reload_notify(
  1415. int32_t event,
  1416. const char *key_name,
  1417. struct icmap_notify_value new_val,
  1418. struct icmap_notify_value old_val,
  1419. void *user_data)
  1420. {
  1421. struct totem_config *totem_config = (struct totem_config *)user_data;
  1422. uint32_t local_node_pos;
  1423. const char *error_string;
  1424. /* Reload has completed */
  1425. if (*(uint8_t *)new_val.data == 0) {
  1426. put_nodelist_members_to_config (totem_config, 1);
  1427. totem_volatile_config_read (totem_config, NULL);
  1428. log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
  1429. debug_dump_totem_config(totem_config);
  1430. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1431. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1432. /*
  1433. * TODO: Consider corosync exit and/or load defaults for volatile
  1434. * values. For now, log error seems to be enough
  1435. */
  1436. }
  1437. /* Reinstate the local_node_pos */
  1438. local_node_pos = find_local_node_in_nodelist(totem_config);
  1439. if (local_node_pos != -1) {
  1440. icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
  1441. }
  1442. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  1443. } else {
  1444. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  1445. }
  1446. }
  1447. static void add_totem_config_notification(struct totem_config *totem_config)
  1448. {
  1449. icmap_track_t icmap_track;
  1450. icmap_track_add("totem.",
  1451. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1452. totem_change_notify,
  1453. totem_config,
  1454. &icmap_track);
  1455. icmap_track_add("config.reload_in_progress",
  1456. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1457. totem_reload_notify,
  1458. totem_config,
  1459. &icmap_track);
  1460. icmap_track_add("nodelist.node.",
  1461. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1462. nodelist_dynamic_notify,
  1463. (void *)totem_config,
  1464. &icmap_track);
  1465. }