4
0

totemconfig.c 74 KB

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