totemconfig.c 70 KB

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