totemconfig.c 71 KB

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