4
0

totemconfig.c 71 KB

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