totemconfig.c 70 KB

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