totemconfig.c 70 KB

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