totemconfig.c 70 KB

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