totemconfig.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2018 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 <ifaddrs.h>
  47. #include <netdb.h>
  48. #include <netinet/in.h>
  49. #include <arpa/inet.h>
  50. #include <sys/param.h>
  51. #include <sys/utsname.h>
  52. #include <corosync/swab.h>
  53. #include <qb/qblist.h>
  54. #include <qb/qbdefs.h>
  55. #include <libknet.h>
  56. #include <corosync/totem/totem.h>
  57. #include <corosync/config.h>
  58. #include <corosync/logsys.h>
  59. #include <corosync/icmap.h>
  60. #include "util.h"
  61. #include "totemconfig.h"
  62. #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
  63. #define TOKEN_TIMEOUT 1000
  64. #define TOKEN_WARNING 75
  65. #define TOKEN_COEFFICIENT 650
  66. #define JOIN_TIMEOUT 50
  67. #define MERGE_TIMEOUT 200
  68. #define DOWNCHECK_TIMEOUT 1000
  69. #define FAIL_TO_RECV_CONST 2500
  70. #define SEQNO_UNCHANGED_CONST 30
  71. #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
  72. #define MINIMUM_TIMEOUT_HOLD (int)(MINIMUM_TIMEOUT * 0.8 - (1000/HZ))
  73. #define MAX_NETWORK_DELAY 50
  74. #define WINDOW_SIZE 50
  75. #define MAX_MESSAGES 17
  76. #define MISS_COUNT_CONST 5
  77. #define BLOCK_UNLISTED_IPS 1
  78. /* Currently all but PONG_COUNT match the defaults in libknet.h */
  79. #define KNET_PING_INTERVAL 1000
  80. #define KNET_PING_TIMEOUT 2000
  81. #define KNET_PING_PRECISION 2048
  82. #define KNET_PONG_COUNT 2
  83. #define KNET_PMTUD_INTERVAL 30
  84. #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP
  85. #define DEFAULT_PORT 5405
  86. static char error_string_response[768];
  87. static void add_totem_config_notification(struct totem_config *totem_config);
  88. static void *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
  89. {
  90. if (strcmp(param_name, "totem.token") == 0)
  91. return &totem_config->token_timeout;
  92. if (strcmp(param_name, "totem.token_warning") == 0)
  93. return &totem_config->token_warning;
  94. if (strcmp(param_name, "totem.token_retransmit") == 0)
  95. return &totem_config->token_retransmit_timeout;
  96. if (strcmp(param_name, "totem.hold") == 0)
  97. return &totem_config->token_hold_timeout;
  98. if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
  99. return &totem_config->token_retransmits_before_loss_const;
  100. if (strcmp(param_name, "totem.join") == 0)
  101. return &totem_config->join_timeout;
  102. if (strcmp(param_name, "totem.send_join") == 0)
  103. return &totem_config->send_join_timeout;
  104. if (strcmp(param_name, "totem.consensus") == 0)
  105. return &totem_config->consensus_timeout;
  106. if (strcmp(param_name, "totem.merge") == 0)
  107. return &totem_config->merge_timeout;
  108. if (strcmp(param_name, "totem.downcheck") == 0)
  109. return &totem_config->downcheck_timeout;
  110. if (strcmp(param_name, "totem.fail_recv_const") == 0)
  111. return &totem_config->fail_to_recv_const;
  112. if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
  113. return &totem_config->seqno_unchanged_const;
  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.knet_pmtud_interval") == 0)
  125. return &totem_config->knet_pmtud_interval;
  126. if (strcmp(param_name, "totem.knet_compression_threshold") == 0)
  127. return &totem_config->knet_compression_threshold;
  128. if (strcmp(param_name, "totem.knet_compression_level") == 0)
  129. return &totem_config->knet_compression_level;
  130. if (strcmp(param_name, "totem.knet_compression_model") == 0)
  131. return &totem_config->knet_compression_model;
  132. if (strcmp(param_name, "totem.block_unlisted_ips") == 0)
  133. return &totem_config->block_unlisted_ips;
  134. return NULL;
  135. }
  136. /*
  137. * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
  138. * and readed value is zero, default value is used and stored into totem_config.
  139. */
  140. static void totem_volatile_config_set_uint32_value (struct totem_config *totem_config,
  141. const char *key_name, const char *deleted_key, unsigned int default_value,
  142. int allow_zero_value)
  143. {
  144. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  145. if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
  146. (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  147. (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
  148. *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
  149. }
  150. /*
  151. * Store totem_config value to cmap runtime section
  152. */
  153. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  154. /*
  155. * This shouldn't happen
  156. */
  157. return ;
  158. }
  159. strcpy(runtime_key_name, "runtime.config.");
  160. strcat(runtime_key_name, key_name);
  161. icmap_set_uint32(runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
  162. }
  163. static void totem_volatile_config_set_int32_value (struct totem_config *totem_config,
  164. const char *key_name, const char *deleted_key, int default_value,
  165. int allow_zero_value)
  166. {
  167. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  168. if (icmap_get_int32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
  169. (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  170. (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
  171. *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
  172. }
  173. /*
  174. * Store totem_config value to cmap runtime section
  175. */
  176. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  177. /*
  178. * This shouldn't happen
  179. */
  180. return ;
  181. }
  182. strcpy(runtime_key_name, "runtime.config.");
  183. strcat(runtime_key_name, key_name);
  184. icmap_set_int32(runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
  185. }
  186. static void totem_volatile_config_set_string_value (struct totem_config *totem_config,
  187. const char *key_name, const char *deleted_key, const char *default_value)
  188. {
  189. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  190. void **config_value;
  191. void *old_config_ptr;
  192. config_value = totem_get_param_by_name(totem_config, key_name);
  193. old_config_ptr = *config_value;
  194. if (icmap_get_string(key_name, (char **)config_value) != CS_OK ||
  195. (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
  196. /* Need to strdup() here so that the free() below works for a default and a configured value */
  197. *config_value = strdup(default_value);
  198. }
  199. free(old_config_ptr);
  200. /*
  201. * Store totem_config value to cmap runtime section
  202. */
  203. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  204. /*
  205. * This shouldn't happen
  206. */
  207. return ;
  208. }
  209. strcpy(runtime_key_name, "runtime.config.");
  210. strcat(runtime_key_name, key_name);
  211. icmap_set_string(runtime_key_name, (char *)*config_value);
  212. }
  213. /*
  214. * Read string value stored in key_name from icmap, use it as a boolean (yes/no) type, convert it
  215. * to integer value (1/0) and store into totem_config.
  216. *
  217. * If key is not found or key_name == delete_key default value is used
  218. * and stored into totem_config.
  219. */
  220. static void totem_volatile_config_set_boolean_value (struct totem_config *totem_config,
  221. const char *key_name, const char *deleted_key, unsigned int default_value)
  222. {
  223. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  224. char *str;
  225. int val;
  226. str = NULL;
  227. val = default_value;
  228. if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
  229. (icmap_get_string(key_name, &str) != CS_OK)) {
  230. /*
  231. * Do nothing. str is NULL (icmap_get_string ether not called or
  232. * not changed str).
  233. */
  234. } else {
  235. if (strcmp(str, "yes") == 0) {
  236. val = 1;
  237. } else if (strcmp(str, "no") == 0) {
  238. val = 0;
  239. }
  240. free(str);
  241. }
  242. /*
  243. * Store totem_config value to cmap runtime section
  244. */
  245. if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
  246. /*
  247. * This shouldn't happen
  248. */
  249. return ;
  250. }
  251. strcpy(runtime_key_name, "runtime.config.");
  252. strcat(runtime_key_name, key_name);
  253. *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = val;
  254. icmap_set_uint32(runtime_key_name, val);
  255. }
  256. /*
  257. * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
  258. * default value is stored. deleted_key is name of key beeing processed by delete operation
  259. * from cmap. It is considered as non existing even if it can be read. Can be NULL.
  260. */
  261. static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
  262. {
  263. uint32_t u32;
  264. totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
  265. TOKEN_RETRANSMITS_BEFORE_LOSS_CONST, 0);
  266. totem_volatile_config_set_uint32_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
  267. totem_volatile_config_set_uint32_value(totem_config, "totem.token_warning", deleted_key, TOKEN_WARNING, 1);
  268. if (totem_config->interfaces[0].member_count > 2) {
  269. u32 = TOKEN_COEFFICIENT;
  270. icmap_get_uint32("totem.token_coefficient", &u32);
  271. totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
  272. /*
  273. * Store totem_config value to cmap runtime section
  274. */
  275. icmap_set_uint32("runtime.config.totem.token", totem_config->token_timeout);
  276. }
  277. totem_volatile_config_set_uint32_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
  278. totem_volatile_config_set_uint32_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
  279. totem_volatile_config_set_uint32_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
  280. totem_volatile_config_set_uint32_value(totem_config, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
  281. totem_volatile_config_set_uint32_value(totem_config, "totem.knet_pmtud_interval", deleted_key, KNET_PMTUD_INTERVAL, 0);
  282. totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmit", deleted_key,
  283. (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
  284. totem_volatile_config_set_uint32_value(totem_config, "totem.hold", deleted_key,
  285. (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
  286. totem_volatile_config_set_uint32_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
  287. totem_volatile_config_set_uint32_value(totem_config, "totem.consensus", deleted_key,
  288. (int)(float)(1.2 * totem_config->token_timeout), 0);
  289. totem_volatile_config_set_uint32_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
  290. totem_volatile_config_set_uint32_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
  291. totem_volatile_config_set_uint32_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
  292. totem_volatile_config_set_uint32_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
  293. SEQNO_UNCHANGED_CONST, 0);
  294. totem_volatile_config_set_uint32_value(totem_config, "totem.send_join", deleted_key, 0, 1);
  295. totem_volatile_config_set_uint32_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
  296. totem_volatile_config_set_uint32_value(totem_config, "totem.knet_compression_threshold", deleted_key, 0, 1);
  297. totem_volatile_config_set_int32_value(totem_config, "totem.knet_compression_level", deleted_key, 0, 1);
  298. totem_volatile_config_set_string_value(totem_config, "totem.knet_compression_model", deleted_key, "none");
  299. totem_volatile_config_set_boolean_value(totem_config, "totem.block_unlisted_ips", deleted_key,
  300. BLOCK_UNLISTED_IPS);
  301. }
  302. static int totem_volatile_config_validate (
  303. struct totem_config *totem_config,
  304. const char **error_string)
  305. {
  306. static char local_error_reason[512];
  307. const char *error_reason = local_error_reason;
  308. char name_key[ICMAP_KEYNAME_MAXLEN];
  309. char *name_str;
  310. int i, num_configured, members;
  311. uint32_t tmp_config_value;
  312. if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
  313. snprintf (local_error_reason, sizeof(local_error_reason),
  314. "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
  315. totem_config->max_network_delay, MINIMUM_TIMEOUT);
  316. goto parse_error;
  317. }
  318. if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
  319. snprintf (local_error_reason, sizeof(local_error_reason),
  320. "The token timeout parameter (%d ms) may not be less than (%d ms).",
  321. totem_config->token_timeout, MINIMUM_TIMEOUT);
  322. goto parse_error;
  323. }
  324. if (totem_config->token_warning > 100 || totem_config->token_warning < 0) {
  325. snprintf (local_error_reason, sizeof(local_error_reason),
  326. "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
  327. totem_config->token_warning);
  328. goto parse_error;
  329. }
  330. if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
  331. if (icmap_get_uint32("totem.token_retransmit", &tmp_config_value) == CS_OK) {
  332. snprintf (local_error_reason, sizeof(local_error_reason),
  333. "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
  334. totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT);
  335. goto parse_error;
  336. } else {
  337. snprintf (local_error_reason, sizeof(local_error_reason),
  338. "Not appropriate token or token_retransmits_before_loss_const value set");
  339. goto parse_error;
  340. }
  341. }
  342. if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT_HOLD) {
  343. snprintf (local_error_reason, sizeof(local_error_reason),
  344. "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
  345. totem_config->token_hold_timeout, MINIMUM_TIMEOUT_HOLD);
  346. goto parse_error;
  347. }
  348. if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
  349. snprintf (local_error_reason, sizeof(local_error_reason),
  350. "The join timeout parameter (%d ms) may not be less than (%d ms).",
  351. totem_config->join_timeout, MINIMUM_TIMEOUT);
  352. goto parse_error;
  353. }
  354. if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
  355. snprintf (local_error_reason, sizeof(local_error_reason),
  356. "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
  357. totem_config->consensus_timeout, MINIMUM_TIMEOUT);
  358. goto parse_error;
  359. }
  360. if (totem_config->consensus_timeout < totem_config->join_timeout) {
  361. snprintf (local_error_reason, sizeof(local_error_reason),
  362. "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
  363. totem_config->consensus_timeout, totem_config->join_timeout);
  364. goto parse_error;
  365. }
  366. if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
  367. snprintf (local_error_reason, sizeof(local_error_reason),
  368. "The merge timeout parameter (%d ms) may not be less than (%d ms).",
  369. totem_config->merge_timeout, MINIMUM_TIMEOUT);
  370. goto parse_error;
  371. }
  372. if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
  373. snprintf (local_error_reason, sizeof(local_error_reason),
  374. "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
  375. totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
  376. goto parse_error;
  377. }
  378. /* Check that we have nodelist 'name' if there is more than one link */
  379. num_configured = 0;
  380. members = -1;
  381. for (i = 0; i < INTERFACE_MAX; i++) {
  382. if (totem_config->interfaces[i].configured) {
  383. if (num_configured == 0) {
  384. members = totem_config->interfaces[i].member_count;
  385. }
  386. num_configured++;
  387. }
  388. }
  389. if (num_configured > 1) {
  390. /*
  391. * This assert is here just to make compiler happy
  392. */
  393. assert(members != -1);
  394. for (i=0; i < members; i++) {
  395. snprintf(name_key, sizeof(name_key), "nodelist.node.%d.name", i);
  396. if (icmap_get_string(name_key, &name_str) != CS_OK) {
  397. snprintf (local_error_reason, sizeof(local_error_reason),
  398. "for a multi-link configuration, all nodes must have a 'name' attribute");
  399. goto parse_error;
  400. }
  401. free(name_str);
  402. }
  403. for (i=0; i < INTERFACE_MAX; i++) {
  404. if (!totem_config->interfaces[i].configured) {
  405. continue;
  406. }
  407. if (totem_config->interfaces[i].member_count != members) {
  408. snprintf (local_error_reason, sizeof(local_error_reason),
  409. "Not all nodes have the same number of links");
  410. goto parse_error;
  411. }
  412. }
  413. }
  414. return 0;
  415. parse_error:
  416. snprintf (error_string_response, sizeof(error_string_response),
  417. "parse error in config: %s\n", error_reason);
  418. *error_string = error_string_response;
  419. return (-1);
  420. }
  421. static int totem_get_crypto(struct totem_config *totem_config, const char **error_string)
  422. {
  423. char *str;
  424. const char *tmp_cipher;
  425. const char *tmp_hash;
  426. const char *tmp_model;
  427. tmp_hash = "none";
  428. tmp_cipher = "none";
  429. tmp_model = "none";
  430. if (icmap_get_string("totem.crypto_model", &str) == CS_OK) {
  431. if (strcmp(str, "nss") == 0) {
  432. tmp_model = "nss";
  433. }
  434. if (strcmp(str, "openssl") == 0) {
  435. tmp_model = "openssl";
  436. }
  437. free(str);
  438. } else {
  439. tmp_model = "nss";
  440. }
  441. if (icmap_get_string("totem.secauth", &str) == CS_OK) {
  442. if (strcmp(str, "on") == 0) {
  443. tmp_cipher = "aes256";
  444. tmp_hash = "sha256";
  445. }
  446. free(str);
  447. }
  448. if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
  449. if (strcmp(str, "none") == 0) {
  450. tmp_cipher = "none";
  451. }
  452. if (strcmp(str, "aes256") == 0) {
  453. tmp_cipher = "aes256";
  454. }
  455. if (strcmp(str, "aes192") == 0) {
  456. tmp_cipher = "aes192";
  457. }
  458. if (strcmp(str, "aes128") == 0) {
  459. tmp_cipher = "aes128";
  460. }
  461. free(str);
  462. }
  463. if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
  464. if (strcmp(str, "none") == 0) {
  465. tmp_hash = "none";
  466. }
  467. if (strcmp(str, "md5") == 0) {
  468. tmp_hash = "md5";
  469. }
  470. if (strcmp(str, "sha1") == 0) {
  471. tmp_hash = "sha1";
  472. }
  473. if (strcmp(str, "sha256") == 0) {
  474. tmp_hash = "sha256";
  475. }
  476. if (strcmp(str, "sha384") == 0) {
  477. tmp_hash = "sha384";
  478. }
  479. if (strcmp(str, "sha512") == 0) {
  480. tmp_hash = "sha512";
  481. }
  482. free(str);
  483. }
  484. if ((strcmp(tmp_cipher, "none") != 0) &&
  485. (strcmp(tmp_hash, "none") == 0)) {
  486. *error_string = "crypto_cipher requires crypto_hash with value other than none";
  487. return -1;
  488. }
  489. if (strcmp(tmp_model, "none") == 0) {
  490. *error_string = "crypto_model should be 'nss' or 'openssl'";
  491. return -1;
  492. }
  493. free(totem_config->crypto_cipher_type);
  494. free(totem_config->crypto_hash_type);
  495. free(totem_config->crypto_model);
  496. totem_config->crypto_cipher_type = strdup(tmp_cipher);
  497. totem_config->crypto_hash_type = strdup(tmp_hash);
  498. totem_config->crypto_model = strdup(tmp_model);
  499. return 0;
  500. }
  501. static int nodelist_byname(const char *find_name, int strip_domain)
  502. {
  503. icmap_iter_t iter;
  504. const char *iter_key;
  505. char name_str[ICMAP_KEYNAME_MAXLEN];
  506. int res = 0;
  507. unsigned int node_pos;
  508. char *name;
  509. unsigned int namelen;
  510. iter = icmap_iter_init("nodelist.node.");
  511. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  512. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
  513. if (res != 2) {
  514. continue;
  515. }
  516. /* ring0_addr is allowed as a fallback */
  517. if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
  518. continue;
  519. }
  520. if (icmap_get_string(iter_key, &name) != CS_OK) {
  521. continue;
  522. }
  523. namelen = strlen(name);
  524. if (strip_domain) {
  525. char *dot;
  526. dot = strchr(name, '.');
  527. if (dot) {
  528. namelen = name - dot - 1;
  529. }
  530. }
  531. if (strncmp(find_name, name, namelen) == 0 &&
  532. strlen(find_name) == strlen(name)) {
  533. icmap_iter_finalize(iter);
  534. return node_pos;
  535. }
  536. }
  537. icmap_iter_finalize(iter);
  538. return -1;
  539. }
  540. /* Compare two addresses - only address part (sin_addr/sin6_addr) is checked */
  541. static int ipaddr_equal(const struct sockaddr *addr1, const struct sockaddr *addr2)
  542. {
  543. int addrlen = 0;
  544. const void *addr1p, *addr2p;
  545. if (addr1->sa_family != addr2->sa_family)
  546. return 0;
  547. switch (addr1->sa_family) {
  548. case AF_INET:
  549. addrlen = sizeof(struct in_addr);
  550. addr1p = &((struct sockaddr_in *)addr1)->sin_addr;
  551. addr2p = &((struct sockaddr_in *)addr2)->sin_addr;
  552. break;
  553. case AF_INET6:
  554. addrlen = sizeof(struct in6_addr);
  555. addr1p = &((struct sockaddr_in6 *)addr1)->sin6_addr;
  556. addr2p = &((struct sockaddr_in6 *)addr2)->sin6_addr;
  557. break;
  558. default:
  559. assert(0);
  560. }
  561. return (memcmp(addr1p, addr2p, addrlen) == 0);
  562. }
  563. /* Finds the local node and returns its position in the nodelist.
  564. * Uses nodelist.local_node_pos as a cache to save effort
  565. */
  566. static int find_local_node(int use_cache)
  567. {
  568. char nodename2[PATH_MAX];
  569. char name_str[ICMAP_KEYNAME_MAXLEN];
  570. icmap_iter_t iter;
  571. const char *iter_key;
  572. unsigned int cached_pos;
  573. char *dot = NULL;
  574. const char *node;
  575. struct ifaddrs *ifa, *ifa_list;
  576. struct sockaddr *sa;
  577. int found = 0;
  578. int node_pos = -1;
  579. int res;
  580. struct utsname utsname;
  581. /* Check for cached value first */
  582. if (use_cache) {
  583. if (icmap_get_uint32("nodelist.local_node_pos", &cached_pos) == CS_OK) {
  584. return cached_pos;
  585. }
  586. }
  587. res = uname(&utsname);
  588. if (res) {
  589. return -1;
  590. }
  591. node = utsname.nodename;
  592. /* 1. Exact match */
  593. node_pos = nodelist_byname(node, 0);
  594. if (node_pos > -1) {
  595. found = 1;
  596. goto ret_found;
  597. }
  598. /* 2. Try to match with increasingly more
  599. * specific versions of it
  600. */
  601. strcpy(nodename2, node);
  602. dot = strrchr(nodename2, '.');
  603. while (dot) {
  604. *dot = '\0';
  605. node_pos = nodelist_byname(nodename2, 0);
  606. if (node_pos > -1) {
  607. found = 1;
  608. goto ret_found;
  609. }
  610. dot = strrchr(nodename2, '.');
  611. }
  612. node_pos = nodelist_byname(nodename2, 1);
  613. if (node_pos > -1) {
  614. found = 1;
  615. goto ret_found;
  616. }
  617. /*
  618. * The corosync.conf name may not be related to uname at all,
  619. * they may match a hostname on some network interface.
  620. */
  621. if (getifaddrs(&ifa_list))
  622. return -1;
  623. for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
  624. socklen_t salen = 0;
  625. /* Restore this */
  626. strcpy(nodename2, node);
  627. sa = ifa->ifa_addr;
  628. if (!sa) {
  629. continue;
  630. }
  631. if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
  632. continue;
  633. }
  634. if (sa->sa_family == AF_INET) {
  635. salen = sizeof(struct sockaddr_in);
  636. }
  637. if (sa->sa_family == AF_INET6) {
  638. salen = sizeof(struct sockaddr_in6);
  639. }
  640. if (getnameinfo(sa, salen,
  641. nodename2, sizeof(nodename2),
  642. NULL, 0, 0) == 0) {
  643. node_pos = nodelist_byname(nodename2, 0);
  644. if (node_pos > -1) {
  645. found = 1;
  646. goto out;
  647. }
  648. /* Truncate this name and try again */
  649. dot = strchr(nodename2, '.');
  650. if (dot) {
  651. *dot = '\0';
  652. node_pos = nodelist_byname(nodename2, 0);
  653. if (node_pos > -1) {
  654. found = 1;
  655. goto out;
  656. }
  657. }
  658. }
  659. /* See if it's the IP address that's in corosync.conf */
  660. if (getnameinfo(sa, sizeof(*sa),
  661. nodename2, sizeof(nodename2),
  662. NULL, 0, NI_NUMERICHOST))
  663. continue;
  664. node_pos = nodelist_byname(nodename2, 0);
  665. if (node_pos > -1) {
  666. found = 1;
  667. goto out;
  668. }
  669. }
  670. out:
  671. if (found) {
  672. freeifaddrs(ifa_list);
  673. goto ret_found;
  674. }
  675. /*
  676. * This section covers the usecase where the nodename specified in cluster.conf
  677. * is an alias specified in /etc/hosts. For example:
  678. * <ipaddr> hostname alias1 alias2
  679. * and <clusternode name="alias2">
  680. * the above calls use uname and getnameinfo does not return aliases.
  681. * here we take the name specified in cluster.conf, resolve it to an address
  682. * and then compare against all known local ip addresses.
  683. * if we have a match, we found our nodename. In theory this chunk of code
  684. * could replace all the checks above, but let's avoid any possible regressions
  685. * and use it as last.
  686. */
  687. iter = icmap_iter_init("nodelist.node.");
  688. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  689. char *dbnodename = NULL;
  690. struct addrinfo hints;
  691. struct addrinfo *result = NULL, *rp = NULL;
  692. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
  693. if (res != 2) {
  694. continue;
  695. }
  696. /* 'ring0_addr' is allowed as a fallback, but 'name' will be found first
  697. * because the names are in alpha order.
  698. */
  699. if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
  700. continue;
  701. }
  702. if (icmap_get_string(iter_key, &dbnodename) != CS_OK) {
  703. continue;
  704. }
  705. memset(&hints, 0, sizeof(struct addrinfo));
  706. hints.ai_family = AF_UNSPEC;
  707. hints.ai_socktype = SOCK_DGRAM;
  708. hints.ai_flags = 0;
  709. hints.ai_protocol = IPPROTO_UDP;
  710. if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
  711. continue;
  712. }
  713. for (rp = result; rp != NULL; rp = rp->ai_next) {
  714. for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
  715. if (ifa->ifa_addr &&
  716. ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
  717. freeaddrinfo(result);
  718. found = 1;
  719. goto out2;
  720. }
  721. }
  722. }
  723. freeaddrinfo(result);
  724. }
  725. out2:
  726. icmap_iter_finalize(iter);
  727. freeifaddrs(ifa_list);
  728. ret_found:
  729. if (found) {
  730. res = icmap_set_uint32("nodelist.local_node_pos", node_pos);
  731. }
  732. return node_pos;
  733. }
  734. static enum totem_ip_version_enum totem_config_get_ip_version(struct totem_config *totem_config)
  735. {
  736. enum totem_ip_version_enum res;
  737. char *str;
  738. res = TOTEM_IP_VERSION_6_4;
  739. if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  740. res = TOTEM_IP_VERSION_4;
  741. }
  742. if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
  743. if (strcmp(str, "ipv4") == 0) {
  744. res = TOTEM_IP_VERSION_4;
  745. }
  746. if (strcmp(str, "ipv6") == 0) {
  747. res = TOTEM_IP_VERSION_6;
  748. }
  749. if (strcmp(str, "ipv6-4") == 0) {
  750. res = TOTEM_IP_VERSION_6_4;
  751. }
  752. if (strcmp(str, "ipv4-6") == 0) {
  753. res = TOTEM_IP_VERSION_4_6;
  754. }
  755. free(str);
  756. }
  757. return (res);
  758. }
  759. static uint16_t generate_cluster_id (const char *cluster_name)
  760. {
  761. int i;
  762. int value = 0;
  763. for (i = 0; i < strlen(cluster_name); i++) {
  764. value <<= 1;
  765. value += cluster_name[i];
  766. }
  767. return (value & 0xFFFF);
  768. }
  769. static int get_cluster_mcast_addr (
  770. const char *cluster_name,
  771. unsigned int linknumber,
  772. enum totem_ip_version_enum ip_version,
  773. struct totem_ip_address *res)
  774. {
  775. uint16_t clusterid;
  776. char addr[INET6_ADDRSTRLEN + 1];
  777. int err;
  778. if (cluster_name == NULL) {
  779. return (-1);
  780. }
  781. clusterid = generate_cluster_id(cluster_name) + linknumber;
  782. memset (res, 0, sizeof(*res));
  783. switch (ip_version) {
  784. case TOTEM_IP_VERSION_4:
  785. case TOTEM_IP_VERSION_4_6:
  786. snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
  787. break;
  788. case TOTEM_IP_VERSION_6:
  789. case TOTEM_IP_VERSION_6_4:
  790. snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
  791. break;
  792. default:
  793. /*
  794. * Unknown family
  795. */
  796. return (-1);
  797. }
  798. err = totemip_parse (res, addr, ip_version);
  799. return (err);
  800. }
  801. static unsigned int generate_nodeid(
  802. struct totem_config *totem_config,
  803. char *addr)
  804. {
  805. unsigned int nodeid;
  806. struct totem_ip_address totemip;
  807. /* AF_INET hard-coded here because auto-generated nodeids
  808. are only for IPv4 */
  809. if (totemip_parse(&totemip, addr, TOTEM_IP_VERSION_4) != 0)
  810. return -1;
  811. memcpy (&nodeid, &totemip.addr, sizeof (unsigned int));
  812. #if __BYTE_ORDER == __LITTLE_ENDIAN
  813. nodeid = swab32 (nodeid);
  814. #endif
  815. if (totem_config->clear_node_high_bit) {
  816. nodeid &= 0x7FFFFFFF;
  817. }
  818. return nodeid;
  819. }
  820. static int check_for_duplicate_nodeids(
  821. struct totem_config *totem_config,
  822. const char **error_string)
  823. {
  824. icmap_iter_t iter;
  825. icmap_iter_t subiter;
  826. const char *iter_key;
  827. int res = 0;
  828. int retval = 0;
  829. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  830. char *ring0_addr=NULL;
  831. char *ring0_addr1=NULL;
  832. unsigned int node_pos;
  833. unsigned int node_pos1;
  834. unsigned int last_node_pos = -1;
  835. unsigned int nodeid;
  836. unsigned int nodeid1;
  837. int autogenerated;
  838. iter = icmap_iter_init("nodelist.node.");
  839. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  840. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  841. if (res != 2) {
  842. continue;
  843. }
  844. /*
  845. * This relies on the fact the icmap keys are always returned in order
  846. * so all of the keys for a node will be grouped together. We're basically
  847. * just running the code below once for each node.
  848. */
  849. if (last_node_pos == node_pos) {
  850. continue;
  851. }
  852. last_node_pos = node_pos;
  853. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
  854. autogenerated = 0;
  855. /* Generated nodeids are only allowed for UDP/UDPU so ring0_addr is valid here */
  856. if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
  857. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  858. if (icmap_get_string(tmp_key, &ring0_addr) != CS_OK) {
  859. continue;
  860. }
  861. /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
  862. nodeid = generate_nodeid(totem_config, ring0_addr);
  863. if (nodeid == -1) {
  864. continue;
  865. }
  866. autogenerated = 1;
  867. }
  868. node_pos1 = 0;
  869. subiter = icmap_iter_init("nodelist.node.");
  870. while (((iter_key = icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
  871. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos1, tmp_key);
  872. if ((res != 2) || (node_pos1 >= node_pos)) {
  873. continue;
  874. }
  875. if (strcmp(tmp_key, "nodeid") != 0) {
  876. continue;
  877. }
  878. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
  879. if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
  880. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos1);
  881. if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
  882. continue;
  883. }
  884. nodeid1 = generate_nodeid(totem_config, ring0_addr1);
  885. if (nodeid1 == -1) {
  886. continue;
  887. }
  888. }
  889. if (nodeid == nodeid1) {
  890. retval = -1;
  891. snprintf (error_string_response, sizeof(error_string_response),
  892. "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
  893. autogenerated?"(autogenerated from ":"",
  894. autogenerated?ring0_addr:"",
  895. autogenerated?")":"");
  896. log_printf (LOGSYS_LEVEL_ERROR, error_string_response);
  897. *error_string = error_string_response;
  898. break;
  899. }
  900. }
  901. icmap_iter_finalize(subiter);
  902. }
  903. icmap_iter_finalize(iter);
  904. return retval;
  905. }
  906. /*
  907. * This needs to be done last of all. It would be nice to do it when reading the
  908. * interface params, but the totem params need to have them to be read first. We
  909. * need both, so this is a way round that circular dependancy.
  910. */
  911. static void calc_knet_ping_timers(struct totem_config *totem_config)
  912. {
  913. char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
  914. int interface;
  915. for (interface = 0; interface < INTERFACE_MAX; interface++) {
  916. if (totem_config->interfaces[interface].configured) {
  917. if (!totem_config->interfaces[interface].knet_pong_count) {
  918. totem_config->interfaces[interface].knet_pong_count = KNET_PONG_COUNT;
  919. }
  920. if (!totem_config->interfaces[interface].knet_ping_timeout) {
  921. totem_config->interfaces[interface].knet_ping_timeout =
  922. totem_config->token_timeout / totem_config->interfaces[interface].knet_pong_count;
  923. }
  924. snprintf(runtime_key_name, sizeof(runtime_key_name),
  925. "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
  926. icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_timeout);
  927. if (!totem_config->interfaces[interface].knet_ping_interval) {
  928. totem_config->interfaces[interface].knet_ping_interval =
  929. totem_config->token_timeout / (totem_config->interfaces[interface].knet_pong_count * 2);
  930. }
  931. snprintf(runtime_key_name, sizeof(runtime_key_name),
  932. "runtime.config.totem.interface.%d.knet_ping_interval", interface);
  933. icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_interval);
  934. }
  935. }
  936. }
  937. /*
  938. * Compute difference between two set of totem interface arrays. set1 and set2
  939. * are changed so for same ring, ip existing in both set1 and set2 are cleared
  940. * (set to 0), and ips which are only in set1 or set2 remains untouched.
  941. * totempg_node_add/remove is called.
  942. */
  943. static void compute_interfaces_diff(struct totem_interface *set1,
  944. struct totem_interface *set2)
  945. {
  946. int ring_no, set1_pos, set2_pos;
  947. struct totem_ip_address empty_ip_address;
  948. memset(&empty_ip_address, 0, sizeof(empty_ip_address));
  949. for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
  950. if (!set1[ring_no].configured && !set2[ring_no].configured) {
  951. continue;
  952. }
  953. for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
  954. for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
  955. /*
  956. * For current ring_no remove all set1 items existing
  957. * in set2
  958. */
  959. if (memcmp(&set1[ring_no].member_list[set1_pos],
  960. &set2[ring_no].member_list[set2_pos],
  961. sizeof(struct totem_ip_address)) == 0) {
  962. memset(&set1[ring_no].member_list[set1_pos], 0,
  963. sizeof(struct totem_ip_address));
  964. memset(&set2[ring_no].member_list[set2_pos], 0,
  965. sizeof(struct totem_ip_address));
  966. }
  967. }
  968. }
  969. }
  970. for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
  971. for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
  972. /*
  973. * All items which remained in set1 doesn't exists in set2 any longer so
  974. * node has to be removed.
  975. */
  976. if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
  977. log_printf(LOGSYS_LEVEL_DEBUG,
  978. "removing dynamic member %s for ring %u",
  979. totemip_print(&set1[ring_no].member_list[set1_pos]),
  980. ring_no);
  981. totempg_member_remove(&set1[ring_no].member_list[set1_pos], ring_no);
  982. }
  983. }
  984. if (!set2[ring_no].configured) {
  985. continue;
  986. }
  987. for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
  988. /*
  989. * All items which remained in set2 doesn't existed in set1 so this is no node
  990. * and has to be added.
  991. */
  992. if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address, sizeof(empty_ip_address)) != 0) {
  993. log_printf(LOGSYS_LEVEL_DEBUG,
  994. "adding dynamic member %s for ring %u",
  995. totemip_print(&set2[ring_no].member_list[set2_pos]),
  996. ring_no);
  997. totempg_member_add(&set2[ring_no].member_list[set2_pos], ring_no);
  998. }
  999. }
  1000. }
  1001. }
  1002. /*
  1003. * Reconfigure links in totempg. Sets new local IP address and adds params for new links.
  1004. */
  1005. static void reconfigure_links(struct totem_config *totem_config)
  1006. {
  1007. int i;
  1008. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  1009. char *addr_string;
  1010. struct totem_ip_address local_ip;
  1011. int err;
  1012. int local_node_pos = find_local_node(0);
  1013. for (i = 0; i<INTERFACE_MAX; i++) {
  1014. if (!totem_config->interfaces[i].configured) {
  1015. continue;
  1016. }
  1017. log_printf(LOGSYS_LEVEL_INFO, "Configuring link %d\n", i);
  1018. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring%u_addr", local_node_pos, i);
  1019. if (icmap_get_string(tmp_key, &addr_string) != CS_OK) {
  1020. continue;
  1021. }
  1022. err = totemip_parse(&local_ip, addr_string, totem_config->ip_version);
  1023. if (err != 0) {
  1024. continue;
  1025. }
  1026. local_ip.nodeid = totem_config->node_id;
  1027. /* In case this is a new link, fill in the defaults if there was no interface{} section for it */
  1028. if (!totem_config->interfaces[i].knet_link_priority)
  1029. totem_config->interfaces[i].knet_link_priority = 1;
  1030. /* knet_ping_interval & knet_ping_timeout are set later once we know all the other params */
  1031. if (!totem_config->interfaces[i].knet_ping_precision)
  1032. totem_config->interfaces[i].knet_ping_precision = KNET_PING_PRECISION;
  1033. if (!totem_config->interfaces[i].knet_pong_count)
  1034. totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
  1035. if (!totem_config->interfaces[i].knet_transport)
  1036. totem_config->interfaces[i].knet_transport = KNET_TRANSPORT_UDP;
  1037. if (!totem_config->interfaces[i].ip_port)
  1038. totem_config->interfaces[i].ip_port = DEFAULT_PORT + i;
  1039. totempg_iface_set(&local_ip, totem_config->interfaces[i].ip_port, i);
  1040. }
  1041. }
  1042. /* Check for differences in config that can't be done on-the-fly and print an error */
  1043. static void check_things_have_not_changed(struct totem_config *totem_config)
  1044. {
  1045. int i,j;
  1046. const char *ip_str;
  1047. char addr_buf[INET6_ADDRSTRLEN];
  1048. int changed = 0;
  1049. for (i = 0; i<INTERFACE_MAX; i++) {
  1050. if (totem_config->interfaces[i].configured &&
  1051. totem_config->orig_interfaces[i].configured) {
  1052. if (totem_config->interfaces[i].knet_transport !=
  1053. totem_config->orig_interfaces[i].knet_transport) {
  1054. log_printf(LOGSYS_LEVEL_ERROR,
  1055. "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
  1056. changed = 1;
  1057. }
  1058. for (j=0; j < min(totem_config->interfaces[i].member_count, totem_config->orig_interfaces[i].member_count); j++) {
  1059. if (memcmp(&totem_config->interfaces[i].member_list[j],
  1060. &totem_config->orig_interfaces[i].member_list[j],
  1061. sizeof(struct totem_ip_address))) {
  1062. ip_str = totemip_print(&totem_config->orig_interfaces[i].member_list[j]);
  1063. /* if ip_str is NULL then the old address was invalid and is allowed to change */
  1064. if (ip_str) {
  1065. strncpy(addr_buf, ip_str, sizeof(addr_buf));
  1066. addr_buf[sizeof(addr_buf) - 1] = '\0';
  1067. log_printf(LOGSYS_LEVEL_ERROR,
  1068. "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
  1069. i, addr_buf, totemip_print(&totem_config->interfaces[i].member_list[j]));
  1070. changed = 1;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. if (changed) {
  1077. log_printf(LOGSYS_LEVEL_ERROR, "To reconfigure an interface it must be deleted and recreated. A working interface needs to be available to corosync at all times");
  1078. }
  1079. }
  1080. static int put_nodelist_members_to_config(struct totem_config *totem_config, int reload, const char **error_string)
  1081. {
  1082. icmap_iter_t iter, iter2;
  1083. const char *iter_key, *iter_key2;
  1084. int res = 0;
  1085. unsigned int node_pos;
  1086. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  1087. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  1088. char *node_addr_str;
  1089. int member_count;
  1090. unsigned int linknumber = 0;
  1091. int i, j;
  1092. int last_node_pos = -1;
  1093. struct totem_interface *new_interfaces = NULL;
  1094. if (reload) {
  1095. /*
  1096. * We need to compute diff only for reload. Also for initial configuration
  1097. * not all totem structures are initialized so corosync will crash during
  1098. * member_add/remove
  1099. */
  1100. new_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  1101. assert(new_interfaces != NULL);
  1102. }
  1103. /* Clear out nodelist so we can put the new one in if needed */
  1104. for (i = 0; i < INTERFACE_MAX; i++) {
  1105. for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
  1106. memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
  1107. }
  1108. totem_config->interfaces[i].member_count = 0;
  1109. }
  1110. iter = icmap_iter_init("nodelist.node.");
  1111. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  1112. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  1113. if (res != 2) {
  1114. continue;
  1115. }
  1116. /* If it's the same as the last node_pos then skip it */
  1117. if (node_pos == last_node_pos) {
  1118. continue;
  1119. }
  1120. last_node_pos = node_pos;
  1121. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  1122. iter2 = icmap_iter_init(tmp_key);
  1123. while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
  1124. unsigned int nodeid;
  1125. char *str;
  1126. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
  1127. if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
  1128. nodeid = 0;
  1129. }
  1130. res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
  1131. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  1132. continue;
  1133. }
  1134. if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
  1135. continue;
  1136. }
  1137. /* Generate nodeids if they are not provided and transport is UDP/U */
  1138. if (!nodeid &&
  1139. (totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
  1140. totem_config->transport_number == TOTEM_TRANSPORT_UDPU)) {
  1141. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
  1142. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1143. nodeid = generate_nodeid(totem_config, str);
  1144. if (nodeid == -1) {
  1145. sprintf(error_string_response,
  1146. "An IPV6 network requires that a node ID be specified "
  1147. "for address '%s'.", node_addr_str);
  1148. *error_string = error_string_response;
  1149. free(str);
  1150. return (-1);
  1151. }
  1152. log_printf(LOGSYS_LEVEL_DEBUG,
  1153. "Generated nodeid = " CS_PRI_NODE_ID " for %s", nodeid, str);
  1154. free(str);
  1155. }
  1156. }
  1157. member_count = totem_config->interfaces[linknumber].member_count;
  1158. res = totemip_parse(&totem_config->interfaces[linknumber].member_list[member_count],
  1159. node_addr_str, totem_config->ip_version);
  1160. if (res == 0) {
  1161. totem_config->interfaces[linknumber].member_list[member_count].nodeid = nodeid;
  1162. totem_config->interfaces[linknumber].member_count++;
  1163. totem_config->interfaces[linknumber].configured = 1;
  1164. } else {
  1165. sprintf(error_string_response, "failed to parse node address '%s'\n", node_addr_str);
  1166. *error_string = error_string_response;
  1167. memset(&totem_config->interfaces[linknumber].member_list[member_count], 0,
  1168. sizeof(struct totem_ip_address));
  1169. free(node_addr_str);
  1170. icmap_iter_finalize(iter2);
  1171. icmap_iter_finalize(iter);
  1172. return -1;
  1173. }
  1174. free(node_addr_str);
  1175. }
  1176. icmap_iter_finalize(iter2);
  1177. }
  1178. icmap_iter_finalize(iter);
  1179. if (reload) {
  1180. log_printf(LOGSYS_LEVEL_DEBUG, "About to reconfigure links from nodelist.\n");
  1181. reconfigure_links(totem_config);
  1182. memcpy(new_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
  1183. check_things_have_not_changed(totem_config);
  1184. compute_interfaces_diff(totem_config->orig_interfaces, new_interfaces);
  1185. free(new_interfaces);
  1186. }
  1187. return 0;
  1188. }
  1189. static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
  1190. {
  1191. int res = 0;
  1192. int node_pos;
  1193. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  1194. char tmp_key2[ICMAP_KEYNAME_MAXLEN];
  1195. char *node_addr_str;
  1196. unsigned int linknumber = 0;
  1197. icmap_iter_t iter;
  1198. const char *iter_key;
  1199. node_pos = find_local_node(1);
  1200. if (node_pos > -1) {
  1201. /*
  1202. * We found node, so create interface section
  1203. */
  1204. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
  1205. iter = icmap_iter_init(tmp_key);
  1206. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  1207. res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
  1208. if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
  1209. continue ;
  1210. }
  1211. if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
  1212. continue;
  1213. }
  1214. snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
  1215. icmap_set_string(tmp_key2, node_addr_str);
  1216. free(node_addr_str);
  1217. }
  1218. icmap_iter_finalize(iter);
  1219. }
  1220. }
  1221. static int get_interface_params(struct totem_config *totem_config,
  1222. const char **error_string, uint64_t *warnings,
  1223. int reload)
  1224. {
  1225. int res = 0;
  1226. unsigned int linknumber = 0;
  1227. int member_count = 0;
  1228. int i;
  1229. icmap_iter_t iter, member_iter;
  1230. const char *iter_key;
  1231. const char *member_iter_key;
  1232. char linknumber_key[ICMAP_KEYNAME_MAXLEN];
  1233. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  1234. uint8_t u8;
  1235. uint32_t u32;
  1236. char *str;
  1237. char *cluster_name = NULL;
  1238. enum totem_ip_version_enum tmp_ip_version = TOTEM_IP_VERSION_4;
  1239. int ret = 0;
  1240. if (reload) {
  1241. for (i=0; i<INTERFACE_MAX; i++) {
  1242. /*
  1243. * Set back to defaults things that might have been configured and
  1244. * now have been taken out of corosync.conf. These won't be caught by the
  1245. * code below which only looks at interface{} sections that actually exist.
  1246. */
  1247. totem_config->interfaces[i].configured = 0;
  1248. totem_config->interfaces[i].knet_ping_timeout = 0;
  1249. totem_config->interfaces[i].knet_ping_interval = 0;
  1250. totem_config->interfaces[i].knet_ping_precision = KNET_PING_PRECISION;
  1251. totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
  1252. }
  1253. }
  1254. if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
  1255. cluster_name = NULL;
  1256. }
  1257. iter = icmap_iter_init("totem.interface.");
  1258. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  1259. res = sscanf(iter_key, "totem.interface.%[^.].%s", linknumber_key, tmp_key);
  1260. if (res != 2) {
  1261. continue;
  1262. }
  1263. if (strcmp(tmp_key, "bindnetaddr") != 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1264. continue;
  1265. }
  1266. member_count = 0;
  1267. linknumber = atoi(linknumber_key);
  1268. if (linknumber >= INTERFACE_MAX) {
  1269. snprintf (error_string_response, sizeof(error_string_response),
  1270. "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
  1271. linknumber, INTERFACE_MAX - 1);
  1272. *error_string = error_string_response;
  1273. ret = -1;
  1274. goto out;
  1275. }
  1276. /* These things are only valid for the initial read */
  1277. if (!reload) {
  1278. /*
  1279. * Get the bind net address
  1280. */
  1281. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
  1282. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1283. res = totemip_parse (&totem_config->interfaces[linknumber].bindnet, str,
  1284. totem_config->ip_version);
  1285. if (res) {
  1286. sprintf(error_string_response, "failed to parse bindnet address '%s'\n", str);
  1287. *error_string = error_string_response;
  1288. free(str);
  1289. ret = -1;
  1290. goto out;
  1291. }
  1292. free(str);
  1293. }
  1294. /*
  1295. * Get interface multicast address
  1296. */
  1297. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", linknumber);
  1298. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1299. res = totemip_parse (&totem_config->interfaces[linknumber].mcast_addr, str,
  1300. totem_config->ip_version);
  1301. if (res) {
  1302. sprintf(error_string_response, "failed to parse mcast address '%s'\n", str);
  1303. *error_string = error_string_response;
  1304. free(str);
  1305. ret = -1;
  1306. goto out;
  1307. }
  1308. free(str);
  1309. } else if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1310. /*
  1311. * User not specified address -> autogenerate one from cluster_name key
  1312. * (if available). Return code is intentionally ignored, because
  1313. * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
  1314. * checked later anyway.
  1315. */
  1316. if (totem_config->interfaces[0].bindnet.family == AF_INET) {
  1317. tmp_ip_version = TOTEM_IP_VERSION_4;
  1318. } else if (totem_config->interfaces[0].bindnet.family == AF_INET6) {
  1319. tmp_ip_version = TOTEM_IP_VERSION_6;
  1320. }
  1321. (void)get_cluster_mcast_addr (cluster_name,
  1322. linknumber,
  1323. tmp_ip_version,
  1324. &totem_config->interfaces[linknumber].mcast_addr);
  1325. }
  1326. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", linknumber);
  1327. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1328. if (strcmp (str, "yes") == 0) {
  1329. totem_config->broadcast_use = 1;
  1330. }
  1331. free(str);
  1332. }
  1333. }
  1334. /* These things are only valid for the initial read OR a newly-defined link */
  1335. if (!reload || (totem_config->interfaces[linknumber].configured == 0)) {
  1336. /*
  1337. * Get mcast port
  1338. */
  1339. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", linknumber);
  1340. if (icmap_get_uint16(tmp_key, &totem_config->interfaces[linknumber].ip_port) != CS_OK) {
  1341. if (totem_config->broadcast_use) {
  1342. totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + (2 * linknumber);
  1343. } else {
  1344. totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + linknumber;
  1345. }
  1346. }
  1347. /*
  1348. * Get the TTL
  1349. */
  1350. totem_config->interfaces[linknumber].ttl = 1;
  1351. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", linknumber);
  1352. if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
  1353. totem_config->interfaces[linknumber].ttl = u8;
  1354. }
  1355. totem_config->interfaces[linknumber].knet_transport = KNET_DEFAULT_TRANSPORT;
  1356. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_transport", linknumber);
  1357. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1358. if (strcmp(str, "sctp") == 0) {
  1359. totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_SCTP;
  1360. }
  1361. else if (strcmp(str, "udp") == 0) {
  1362. totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_UDP;
  1363. }
  1364. else {
  1365. *error_string = "Unrecognised knet_transport. expected 'udp' or 'sctp'";
  1366. ret = -1;
  1367. goto out;
  1368. }
  1369. }
  1370. }
  1371. totem_config->interfaces[linknumber].configured = 1;
  1372. /*
  1373. * Get the knet link params
  1374. */
  1375. totem_config->interfaces[linknumber].knet_link_priority = 1;
  1376. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_link_priority", linknumber);
  1377. if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
  1378. totem_config->interfaces[linknumber].knet_link_priority = u8;
  1379. }
  1380. totem_config->interfaces[linknumber].knet_ping_interval = 0; /* real default applied later */
  1381. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_interval", linknumber);
  1382. if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
  1383. totem_config->interfaces[linknumber].knet_ping_interval = u32;
  1384. }
  1385. totem_config->interfaces[linknumber].knet_ping_timeout = 0; /* real default applied later */
  1386. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_timeout", linknumber);
  1387. if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
  1388. totem_config->interfaces[linknumber].knet_ping_timeout = u32;
  1389. }
  1390. totem_config->interfaces[linknumber].knet_ping_precision = KNET_PING_PRECISION;
  1391. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_precision", linknumber);
  1392. if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
  1393. totem_config->interfaces[linknumber].knet_ping_precision = u32;
  1394. }
  1395. totem_config->interfaces[linknumber].knet_pong_count = KNET_PONG_COUNT;
  1396. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_pong_count", linknumber);
  1397. if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
  1398. totem_config->interfaces[linknumber].knet_pong_count = u32;
  1399. }
  1400. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", linknumber);
  1401. member_iter = icmap_iter_init(tmp_key);
  1402. while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
  1403. if (member_count == 0) {
  1404. if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
  1405. free(str);
  1406. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_IGNORED;
  1407. break;
  1408. } else {
  1409. *warnings |= TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED;
  1410. }
  1411. }
  1412. if (icmap_get_string(member_iter_key, &str) == CS_OK) {
  1413. res = totemip_parse (&totem_config->interfaces[linknumber].member_list[member_count++],
  1414. str, totem_config->ip_version);
  1415. if (res) {
  1416. sprintf(error_string_response, "failed to parse node address '%s'\n", str);
  1417. *error_string = error_string_response;
  1418. icmap_iter_finalize(member_iter);
  1419. free(str);
  1420. ret = -1;
  1421. goto out;
  1422. }
  1423. free(str);
  1424. }
  1425. }
  1426. icmap_iter_finalize(member_iter);
  1427. totem_config->interfaces[linknumber].member_count = member_count;
  1428. }
  1429. out:
  1430. icmap_iter_finalize(iter);
  1431. free(cluster_name);
  1432. return (ret);
  1433. }
  1434. extern int totem_config_read (
  1435. struct totem_config *totem_config,
  1436. const char **error_string,
  1437. uint64_t *warnings)
  1438. {
  1439. int res = 0;
  1440. char *str, *ring0_addr_str;
  1441. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  1442. uint16_t u16;
  1443. int i;
  1444. int local_node_pos;
  1445. int nodeid_set;
  1446. *warnings = 0;
  1447. memset (totem_config, 0, sizeof (struct totem_config));
  1448. totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  1449. if (totem_config->interfaces == 0) {
  1450. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  1451. return -1;
  1452. }
  1453. totem_config->transport_number = TOTEM_TRANSPORT_KNET;
  1454. if (icmap_get_string("totem.transport", &str) == CS_OK) {
  1455. if (strcmp (str, "udpu") == 0) {
  1456. totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
  1457. }
  1458. if (strcmp (str, "udp") == 0) {
  1459. totem_config->transport_number = TOTEM_TRANSPORT_UDP;
  1460. }
  1461. if (strcmp (str, "knet") == 0) {
  1462. totem_config->transport_number = TOTEM_TRANSPORT_KNET;
  1463. }
  1464. free(str);
  1465. }
  1466. memset (totem_config->interfaces, 0,
  1467. sizeof (struct totem_interface) * INTERFACE_MAX);
  1468. strcpy (totem_config->link_mode, "passive");
  1469. icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
  1470. if (totem_get_crypto(totem_config, error_string) != 0) {
  1471. return -1;
  1472. }
  1473. if (icmap_get_string("totem.link_mode", &str) == CS_OK) {
  1474. if (strlen(str) >= TOTEM_LINK_MODE_BYTES) {
  1475. *error_string = "totem.link_mode is too long";
  1476. free(str);
  1477. return -1;
  1478. }
  1479. strcpy (totem_config->link_mode, str);
  1480. free(str);
  1481. }
  1482. icmap_get_uint32("totem.nodeid", &totem_config->node_id);
  1483. totem_config->clear_node_high_bit = 0;
  1484. if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
  1485. if (strcmp (str, "yes") == 0) {
  1486. totem_config->clear_node_high_bit = 1;
  1487. }
  1488. free(str);
  1489. }
  1490. icmap_get_uint32("totem.threads", &totem_config->threads);
  1491. icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
  1492. totem_config->ip_version = totem_config_get_ip_version(totem_config);
  1493. if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
  1494. /*
  1495. * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
  1496. */
  1497. config_convert_nodelist_to_interface(totem_config);
  1498. } else {
  1499. if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str) == CS_OK) {
  1500. /*
  1501. * Both bindnetaddr and ring0_addr are set.
  1502. * Log warning information, and use nodelist instead
  1503. */
  1504. *warnings |= TOTEM_CONFIG_BINDNETADDR_NODELIST_SET;
  1505. config_convert_nodelist_to_interface(totem_config);
  1506. free(ring0_addr_str);
  1507. }
  1508. free(str);
  1509. }
  1510. /*
  1511. * Broadcast option is global but set in interface section,
  1512. * so reset before processing interfaces.
  1513. */
  1514. totem_config->broadcast_use = 0;
  1515. res = get_interface_params(totem_config, error_string, warnings, 0);
  1516. if (res < 0) {
  1517. return res;
  1518. }
  1519. /*
  1520. * Use broadcast is global, so if set, make sure to fill mcast addr correctly
  1521. * broadcast is only supported for UDP so just do interface 0;
  1522. */
  1523. if (totem_config->broadcast_use) {
  1524. totemip_parse (&totem_config->interfaces[0].mcast_addr,
  1525. "255.255.255.255", TOTEM_IP_VERSION_4);
  1526. }
  1527. /*
  1528. * Store automatically generated items back to icmap only for UDP
  1529. */
  1530. if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1531. for (i = 0; i < INTERFACE_MAX; i++) {
  1532. if (!totem_config->interfaces[i].configured) {
  1533. continue;
  1534. }
  1535. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
  1536. if (icmap_get_string(tmp_key, &str) == CS_OK) {
  1537. free(str);
  1538. } else {
  1539. str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
  1540. icmap_set_string(tmp_key, str);
  1541. }
  1542. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
  1543. if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
  1544. icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
  1545. }
  1546. }
  1547. }
  1548. /*
  1549. * Check existence of nodelist
  1550. */
  1551. if ((icmap_get_string("nodelist.node.0.name", &str) == CS_OK) ||
  1552. (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK)) {
  1553. free(str);
  1554. /*
  1555. * find local node
  1556. */
  1557. local_node_pos = find_local_node(1);
  1558. if (local_node_pos != -1) {
  1559. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
  1560. nodeid_set = (totem_config->node_id != 0);
  1561. if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
  1562. *warnings |= TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED;
  1563. }
  1564. if ((totem_config->transport_number == TOTEM_TRANSPORT_KNET) && (!totem_config->node_id)) {
  1565. *error_string = "Knet requires an explicit nodeid for the local node";
  1566. return -1;
  1567. }
  1568. if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
  1569. totem_config->transport_number == TOTEM_TRANSPORT_UDPU) && (!totem_config->node_id)) {
  1570. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
  1571. icmap_get_string(tmp_key, &str);
  1572. totem_config->node_id = generate_nodeid(totem_config, str);
  1573. if (totem_config->node_id == -1) {
  1574. *error_string = "An IPV6 network requires that a node ID be specified";
  1575. free(str);
  1576. return (-1);
  1577. }
  1578. totem_config->interfaces[0].member_list[local_node_pos].nodeid = totem_config->node_id;
  1579. free(str);
  1580. }
  1581. /* Users must not change this */
  1582. icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
  1583. }
  1584. if (put_nodelist_members_to_config(totem_config, 0, error_string)) {
  1585. return -1;
  1586. }
  1587. }
  1588. /*
  1589. * Get things that might change in the future (and can depend on totem_config->interfaces);
  1590. */
  1591. totem_volatile_config_read(totem_config, NULL);
  1592. calc_knet_ping_timers(totem_config);
  1593. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  1594. add_totem_config_notification(totem_config);
  1595. return 0;
  1596. }
  1597. int totem_config_validate (
  1598. struct totem_config *totem_config,
  1599. const char **error_string)
  1600. {
  1601. static char local_error_reason[512];
  1602. char parse_error[512];
  1603. static char addr_str_buf[INET6_ADDRSTRLEN];
  1604. const char *error_reason = local_error_reason;
  1605. int i,j;
  1606. uint32_t u32;
  1607. int num_configured = 0;
  1608. unsigned int interface_max = INTERFACE_MAX;
  1609. for (i = 0; i < INTERFACE_MAX; i++) {
  1610. if (totem_config->interfaces[i].configured) {
  1611. num_configured++;
  1612. }
  1613. }
  1614. if (num_configured == 0) {
  1615. error_reason = "No interfaces defined";
  1616. goto parse_error;
  1617. }
  1618. /* Check we found a local node name */
  1619. if (icmap_get_uint32("nodelist.local_node_pos", &u32) != CS_OK) {
  1620. error_reason = "No valid name found for local host";
  1621. goto parse_error;
  1622. }
  1623. for (i = 0; i < INTERFACE_MAX; i++) {
  1624. /*
  1625. * Some error checking of parsed data to make sure its valid
  1626. */
  1627. struct totem_ip_address null_addr;
  1628. if (!totem_config->interfaces[i].configured) {
  1629. continue;
  1630. }
  1631. memset (&null_addr, 0, sizeof (struct totem_ip_address));
  1632. if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP) &&
  1633. memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
  1634. sizeof (struct totem_ip_address)) == 0) {
  1635. error_reason = "No multicast address specified";
  1636. goto parse_error;
  1637. }
  1638. if (totem_config->interfaces[i].ip_port == 0) {
  1639. error_reason = "No multicast port specified";
  1640. goto parse_error;
  1641. }
  1642. if (totem_config->interfaces[i].ttl > 255) {
  1643. error_reason = "Invalid TTL (should be 0..255)";
  1644. goto parse_error;
  1645. }
  1646. if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
  1647. totem_config->interfaces[i].ttl != 1) {
  1648. error_reason = "Can only set ttl on multicast transport types";
  1649. goto parse_error;
  1650. }
  1651. if (totem_config->interfaces[i].knet_link_priority > 255) {
  1652. error_reason = "Invalid link priority (should be 0..255)";
  1653. goto parse_error;
  1654. }
  1655. if (totem_config->transport_number != TOTEM_TRANSPORT_KNET &&
  1656. totem_config->interfaces[i].knet_link_priority != 1) {
  1657. error_reason = "Can only set link priority on knet transport type";
  1658. goto parse_error;
  1659. }
  1660. if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
  1661. totem_config->node_id == 0) {
  1662. error_reason = "An IPV6 network requires that a node ID be specified.";
  1663. goto parse_error;
  1664. }
  1665. if (totem_config->broadcast_use == 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
  1666. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  1667. error_reason = "Multicast address family does not match bind address family";
  1668. goto parse_error;
  1669. }
  1670. if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
  1671. error_reason = "mcastaddr is not a correct multicast address.";
  1672. goto parse_error;
  1673. }
  1674. }
  1675. /* Verify that all nodes on the same knet link have the same IP family */
  1676. for (j=1; j<totem_config->interfaces[i].member_count; j++) {
  1677. if (totem_config->interfaces[i].configured) {
  1678. if (totem_config->interfaces[i].member_list[j].family !=
  1679. totem_config->interfaces[i].member_list[0].family) {
  1680. memcpy(addr_str_buf,
  1681. totemip_print(&(totem_config->interfaces[i].member_list[j])),
  1682. sizeof(addr_str_buf));
  1683. snprintf (local_error_reason, sizeof(local_error_reason),
  1684. "Nodes for link %d have different IP families "
  1685. "(compared %s with %s)", i,
  1686. addr_str_buf,
  1687. totemip_print(&(totem_config->interfaces[i].member_list[0])));
  1688. goto parse_error;
  1689. }
  1690. }
  1691. }
  1692. }
  1693. if (totem_config->version != 2) {
  1694. error_reason = "This totem parser can only parse version 2 configurations.";
  1695. goto parse_error;
  1696. }
  1697. if (totem_volatile_config_validate(totem_config, error_string) == -1) {
  1698. return (-1);
  1699. }
  1700. if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
  1701. return (-1);
  1702. }
  1703. /*
  1704. * KNET Link values validation
  1705. */
  1706. if (strcmp (totem_config->link_mode, "active") &&
  1707. strcmp (totem_config->link_mode, "rr") &&
  1708. strcmp (totem_config->link_mode, "passive")) {
  1709. snprintf (local_error_reason, sizeof(local_error_reason),
  1710. "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->link_mode);
  1711. goto parse_error;
  1712. }
  1713. /* Only Knet does multiple interfaces */
  1714. if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
  1715. interface_max = 1;
  1716. }
  1717. if (interface_max < num_configured) {
  1718. snprintf (parse_error, sizeof(parse_error),
  1719. "%d is too many configured interfaces for non-Knet transport.",
  1720. num_configured);
  1721. error_reason = parse_error;
  1722. goto parse_error;
  1723. }
  1724. /* Only knet allows crypto */
  1725. if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
  1726. if ((strcmp(totem_config->crypto_cipher_type, "none") != 0) ||
  1727. (strcmp(totem_config->crypto_hash_type, "none") != 0)) {
  1728. snprintf (parse_error, sizeof(parse_error),
  1729. "crypto_cipher & crypto_hash are only valid for the Knet transport.");
  1730. error_reason = parse_error;
  1731. goto parse_error;
  1732. }
  1733. }
  1734. if (totem_config->net_mtu == 0) {
  1735. if (totem_config->transport_number == TOTEM_TRANSPORT_KNET) {
  1736. totem_config->net_mtu = KNET_MAX_PACKET_SIZE;
  1737. }
  1738. else {
  1739. totem_config->net_mtu = 1500;
  1740. }
  1741. }
  1742. return 0;
  1743. parse_error:
  1744. snprintf (error_string_response, sizeof(error_string_response),
  1745. "parse error in config: %s\n", error_reason);
  1746. *error_string = error_string_response;
  1747. return (-1);
  1748. }
  1749. static int read_keyfile (
  1750. const char *key_location,
  1751. struct totem_config *totem_config,
  1752. const char **error_string)
  1753. {
  1754. int fd;
  1755. int res;
  1756. int saved_errno;
  1757. char error_str[100];
  1758. const char *error_ptr;
  1759. fd = open (key_location, O_RDONLY);
  1760. if (fd == -1) {
  1761. error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  1762. snprintf (error_string_response, sizeof(error_string_response),
  1763. "Could not open %s: %s\n",
  1764. key_location, error_ptr);
  1765. goto parse_error;
  1766. }
  1767. res = read (fd, totem_config->private_key, TOTEM_PRIVATE_KEY_LEN_MAX);
  1768. saved_errno = errno;
  1769. close (fd);
  1770. if (res == -1) {
  1771. error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
  1772. snprintf (error_string_response, sizeof(error_string_response),
  1773. "Could not read %s: %s\n",
  1774. key_location, error_ptr);
  1775. goto parse_error;
  1776. }
  1777. if (res < TOTEM_PRIVATE_KEY_LEN_MIN) {
  1778. snprintf (error_string_response, sizeof(error_string_response),
  1779. "Could only read %d bits of minimum %u bits from %s.\n",
  1780. res * 8, TOTEM_PRIVATE_KEY_LEN_MIN * 8, key_location);
  1781. goto parse_error;
  1782. }
  1783. totem_config->private_key_len = res;
  1784. return 0;
  1785. parse_error:
  1786. *error_string = error_string_response;
  1787. return (-1);
  1788. }
  1789. int totem_config_keyread (
  1790. struct totem_config *totem_config,
  1791. const char **error_string)
  1792. {
  1793. int got_key = 0;
  1794. char *key_location = NULL;
  1795. int res;
  1796. size_t key_len;
  1797. memset (totem_config->private_key, 0, sizeof(totem_config->private_key));
  1798. totem_config->private_key_len = 0;
  1799. if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
  1800. strcmp(totem_config->crypto_hash_type, "none") == 0) {
  1801. return (0);
  1802. }
  1803. /* cmap may store the location of the key file */
  1804. if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
  1805. res = read_keyfile(key_location, totem_config, error_string);
  1806. free(key_location);
  1807. if (res) {
  1808. goto key_error;
  1809. }
  1810. got_key = 1;
  1811. } else { /* Or the key itself may be in the cmap */
  1812. if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
  1813. if (key_len > sizeof(totem_config->private_key)) {
  1814. sprintf(error_string_response, "key is too long");
  1815. goto key_error;
  1816. }
  1817. if (key_len < TOTEM_PRIVATE_KEY_LEN_MIN) {
  1818. sprintf(error_string_response, "key is too short");
  1819. goto key_error;
  1820. }
  1821. if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
  1822. totem_config->private_key_len = key_len;
  1823. got_key = 1;
  1824. } else {
  1825. sprintf(error_string_response, "can't load private key");
  1826. goto key_error;
  1827. }
  1828. }
  1829. }
  1830. /* In desperation we read the default filename */
  1831. if (!got_key) {
  1832. res = read_keyfile(COROSYSCONFDIR "/authkey", totem_config, error_string);
  1833. if (res)
  1834. goto key_error;
  1835. }
  1836. return (0);
  1837. key_error:
  1838. *error_string = error_string_response;
  1839. return (-1);
  1840. }
  1841. static void debug_dump_totem_config(const struct totem_config *totem_config)
  1842. {
  1843. log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
  1844. totem_config->token_timeout, totem_config->token_retransmit_timeout);
  1845. if (totem_config->token_warning) {
  1846. uint32_t token_warning_ms = totem_config->token_warning * totem_config->token_timeout / 100;
  1847. log_printf(LOGSYS_LEVEL_DEBUG, "Token warning every %d ms (%d%% of Token Timeout)",
  1848. token_warning_ms, totem_config->token_warning);
  1849. if (token_warning_ms < totem_config->token_retransmit_timeout)
  1850. log_printf (LOGSYS_LEVEL_DEBUG,
  1851. "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) "
  1852. "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
  1853. token_warning_ms, totem_config->token_retransmit_timeout);
  1854. } else
  1855. log_printf(LOGSYS_LEVEL_DEBUG, "Token warnings disabled");
  1856. log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
  1857. totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
  1858. log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
  1859. totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
  1860. totem_config->merge_timeout);
  1861. log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
  1862. totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
  1863. log_printf(LOGSYS_LEVEL_DEBUG,
  1864. "seqno unchanged const (%d rotations) Maximum network MTU %d",
  1865. totem_config->seqno_unchanged_const, totem_config->net_mtu);
  1866. log_printf(LOGSYS_LEVEL_DEBUG,
  1867. "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
  1868. totem_config->window_size, totem_config->max_messages);
  1869. log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
  1870. log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
  1871. totem_config->heartbeat_failures_allowed);
  1872. log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
  1873. }
  1874. static void totem_change_notify(
  1875. int32_t event,
  1876. const char *key_name,
  1877. struct icmap_notify_value new_val,
  1878. struct icmap_notify_value old_val,
  1879. void *user_data)
  1880. {
  1881. struct totem_config *totem_config = (struct totem_config *)user_data;
  1882. uint32_t *param;
  1883. uint8_t reloading;
  1884. const char *deleted_key = NULL;
  1885. const char *error_string;
  1886. /*
  1887. * If a full reload is in progress then don't do anything until it's done and
  1888. * can reconfigure it all atomically
  1889. */
  1890. if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
  1891. return;
  1892. param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
  1893. /*
  1894. * Process change only if changed key is found in totem_config (-> param is not NULL)
  1895. * or for special key token_coefficient. token_coefficient key is not stored in
  1896. * totem_config, but it is used for computation of token timeout.
  1897. */
  1898. if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
  1899. return;
  1900. /*
  1901. * Values other than UINT32 are not supported, or needed (yet)
  1902. */
  1903. switch (event) {
  1904. case ICMAP_TRACK_DELETE:
  1905. deleted_key = key_name;
  1906. break;
  1907. case ICMAP_TRACK_ADD:
  1908. case ICMAP_TRACK_MODIFY:
  1909. deleted_key = NULL;
  1910. break;
  1911. default:
  1912. break;
  1913. }
  1914. totem_volatile_config_read (totem_config, deleted_key);
  1915. log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
  1916. debug_dump_totem_config(totem_config);
  1917. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1918. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1919. /*
  1920. * TODO: Consider corosync exit and/or load defaults for volatile
  1921. * values. For now, log error seems to be enough
  1922. */
  1923. }
  1924. }
  1925. static void totem_reload_notify(
  1926. int32_t event,
  1927. const char *key_name,
  1928. struct icmap_notify_value new_val,
  1929. struct icmap_notify_value old_val,
  1930. void *user_data)
  1931. {
  1932. struct totem_config *totem_config = (struct totem_config *)user_data;
  1933. const char *error_string;
  1934. uint64_t warnings = 0;
  1935. /* Reload has completed */
  1936. if (*(uint8_t *)new_val.data == 0) {
  1937. totem_config->orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  1938. assert(totem_config->orig_interfaces != NULL);
  1939. memcpy(totem_config->orig_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
  1940. get_interface_params(totem_config, &error_string, &warnings, 1);
  1941. if (put_nodelist_members_to_config (totem_config, 1, &error_string)) {
  1942. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1943. }
  1944. totem_volatile_config_read (totem_config, NULL);
  1945. calc_knet_ping_timers(totem_config);
  1946. log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
  1947. debug_dump_totem_config(totem_config);
  1948. if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
  1949. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  1950. /*
  1951. * TODO: Consider corosync exit and/or load defaults for volatile
  1952. * values. For now, log error seems to be enough
  1953. */
  1954. }
  1955. /* Reinstate the local_node_pos */
  1956. (void)find_local_node(0);
  1957. /* Reconfigure network params as appropriate */
  1958. totempg_reconfigure();
  1959. free(totem_config->orig_interfaces);
  1960. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  1961. } else {
  1962. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  1963. }
  1964. }
  1965. static void add_totem_config_notification(struct totem_config *totem_config)
  1966. {
  1967. icmap_track_t icmap_track;
  1968. icmap_track_add("totem.",
  1969. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1970. totem_change_notify,
  1971. totem_config,
  1972. &icmap_track);
  1973. icmap_track_add("config.reload_in_progress",
  1974. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1975. totem_reload_notify,
  1976. totem_config,
  1977. &icmap_track);
  1978. }