totemconfig.c 52 KB

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