totemconfig.c 73 KB

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