totemrrp.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <assert.h>
  37. #include <pthread.h>
  38. #include <sys/mman.h>
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41. #include <sys/socket.h>
  42. #include <netdb.h>
  43. #include <sys/un.h>
  44. #include <sys/ioctl.h>
  45. #include <sys/param.h>
  46. #include <netinet/in.h>
  47. #include <arpa/inet.h>
  48. #include <unistd.h>
  49. #include <fcntl.h>
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52. #include <errno.h>
  53. #include <sched.h>
  54. #include <time.h>
  55. #include <sys/time.h>
  56. #include <sys/poll.h>
  57. #include <limits.h>
  58. #include <corosync/sq.h>
  59. #include <corosync/list.h>
  60. #include <corosync/hdb.h>
  61. #include <corosync/swab.h>
  62. #include <corosync/totem/coropoll.h>
  63. #define LOGSYS_UTILS_ONLY 1
  64. #include <corosync/engine/logsys.h>
  65. #include "totemnet.h"
  66. #include "totemrrp.h"
  67. void rrp_deliver_fn (
  68. void *context,
  69. const void *msg,
  70. unsigned int msg_len);
  71. void rrp_iface_change_fn (
  72. void *context,
  73. const struct totem_ip_address *iface_addr);
  74. struct totemrrp_instance;
  75. struct passive_instance {
  76. struct totemrrp_instance *rrp_instance;
  77. unsigned int *faulty;
  78. unsigned int *token_recv_count;
  79. unsigned int *mcast_recv_count;
  80. unsigned char token[15000];
  81. unsigned int token_len;
  82. poll_timer_handle timer_expired_token;
  83. poll_timer_handle timer_problem_decrementer;
  84. void *totemrrp_context;
  85. unsigned int token_xmit_iface;
  86. unsigned int msg_xmit_iface;
  87. };
  88. struct active_instance {
  89. struct totemrrp_instance *rrp_instance;
  90. unsigned int *faulty;
  91. unsigned int *last_token_recv;
  92. unsigned int *counter_problems;
  93. unsigned char token[15000];
  94. unsigned int token_len;
  95. unsigned int last_token_seq;
  96. poll_timer_handle timer_expired_token;
  97. poll_timer_handle timer_problem_decrementer;
  98. void *totemrrp_context;
  99. };
  100. struct rrp_algo {
  101. const char *name;
  102. void * (*initialize) (
  103. struct totemrrp_instance *rrp_instance,
  104. int interface_count);
  105. void (*mcast_recv) (
  106. struct totemrrp_instance *instance,
  107. unsigned int iface_no,
  108. void *context,
  109. const void *msg,
  110. unsigned int msg_len);
  111. void (*mcast_noflush_send) (
  112. struct totemrrp_instance *instance,
  113. const void *msg,
  114. unsigned int msg_len);
  115. void (*mcast_flush_send) (
  116. struct totemrrp_instance *instance,
  117. const void *msg,
  118. unsigned int msg_len);
  119. void (*token_recv) (
  120. struct totemrrp_instance *instance,
  121. unsigned int iface_no,
  122. void *context,
  123. const void *msg,
  124. unsigned int msg_len,
  125. unsigned int token_seqid);
  126. void (*token_send) (
  127. struct totemrrp_instance *instance,
  128. const void *msg,
  129. unsigned int msg_len);
  130. void (*recv_flush) (
  131. struct totemrrp_instance *instance);
  132. void (*send_flush) (
  133. struct totemrrp_instance *instance);
  134. void (*iface_check) (
  135. struct totemrrp_instance *instance);
  136. void (*processor_count_set) (
  137. struct totemrrp_instance *instance,
  138. unsigned int processor_count);
  139. void (*token_target_set) (
  140. struct totemrrp_instance *instance,
  141. struct totem_ip_address *token_target,
  142. unsigned int iface_no);
  143. void (*ring_reenable) (
  144. struct totemrrp_instance *instance,
  145. unsigned int iface_no);
  146. int (*mcast_recv_empty) (
  147. struct totemrrp_instance *instance);
  148. int (*member_add) (
  149. struct totemrrp_instance *instance,
  150. const struct totem_ip_address *member,
  151. unsigned int iface_no);
  152. int (*member_remove) (
  153. struct totemrrp_instance *instance,
  154. const struct totem_ip_address *member,
  155. unsigned int iface_no);
  156. };
  157. struct totemrrp_instance {
  158. hdb_handle_t poll_handle;
  159. struct totem_interface *interfaces;
  160. struct rrp_algo *rrp_algo;
  161. void *context;
  162. char *status[INTERFACE_MAX];
  163. void (*totemrrp_deliver_fn) (
  164. void *context,
  165. const void *msg,
  166. unsigned int msg_len);
  167. void (*totemrrp_iface_change_fn) (
  168. void *context,
  169. const struct totem_ip_address *iface_addr,
  170. unsigned int iface_no);
  171. void (*totemrrp_token_seqid_get) (
  172. const void *msg,
  173. unsigned int *seqid,
  174. unsigned int *token_is);
  175. void (*totemrrp_target_set_completed) (
  176. void *context);
  177. unsigned int (*totemrrp_msgs_missing) (void);
  178. /*
  179. * Function and data used to log messages
  180. */
  181. int totemrrp_log_level_security;
  182. int totemrrp_log_level_error;
  183. int totemrrp_log_level_warning;
  184. int totemrrp_log_level_notice;
  185. int totemrrp_log_level_debug;
  186. int totemrrp_subsys_id;
  187. void (*totemrrp_log_printf) (
  188. unsigned int rec_ident,
  189. const char *function,
  190. const char *file,
  191. int line,
  192. const char *format, ...)__attribute__((format(printf, 5, 6)));
  193. void **net_handles;
  194. void *rrp_algo_instance;
  195. int interface_count;
  196. int processor_count;
  197. int my_nodeid;
  198. struct totem_config *totem_config;
  199. void *deliver_fn_context[INTERFACE_MAX];
  200. poll_timer_handle timer_active_test_ring_timeout[INTERFACE_MAX];
  201. };
  202. /*
  203. * None Replication Forward Declerations
  204. */
  205. static void none_mcast_recv (
  206. struct totemrrp_instance *instance,
  207. unsigned int iface_no,
  208. void *context,
  209. const void *msg,
  210. unsigned int msg_len);
  211. static void none_mcast_noflush_send (
  212. struct totemrrp_instance *instance,
  213. const void *msg,
  214. unsigned int msg_len);
  215. static void none_mcast_flush_send (
  216. struct totemrrp_instance *instance,
  217. const void *msg,
  218. unsigned int msg_len);
  219. static void none_token_recv (
  220. struct totemrrp_instance *instance,
  221. unsigned int iface_no,
  222. void *context,
  223. const void *msg,
  224. unsigned int msg_len,
  225. unsigned int token_seqid);
  226. static void none_token_send (
  227. struct totemrrp_instance *instance,
  228. const void *msg,
  229. unsigned int msg_len);
  230. static void none_recv_flush (
  231. struct totemrrp_instance *instance);
  232. static void none_send_flush (
  233. struct totemrrp_instance *instance);
  234. static void none_iface_check (
  235. struct totemrrp_instance *instance);
  236. static void none_processor_count_set (
  237. struct totemrrp_instance *instance,
  238. unsigned int processor_count_set);
  239. static void none_token_target_set (
  240. struct totemrrp_instance *instance,
  241. struct totem_ip_address *token_target,
  242. unsigned int iface_no);
  243. static void none_ring_reenable (
  244. struct totemrrp_instance *instance,
  245. unsigned int iface_no);
  246. static int none_mcast_recv_empty (
  247. struct totemrrp_instance *instance);
  248. static int none_member_add (
  249. struct totemrrp_instance *instance,
  250. const struct totem_ip_address *member,
  251. unsigned int iface_no);
  252. static int none_member_remove (
  253. struct totemrrp_instance *instance,
  254. const struct totem_ip_address *member,
  255. unsigned int iface_no);
  256. /*
  257. * Passive Replication Forward Declerations
  258. */
  259. static void *passive_instance_initialize (
  260. struct totemrrp_instance *rrp_instance,
  261. int interface_count);
  262. static void passive_mcast_recv (
  263. struct totemrrp_instance *instance,
  264. unsigned int iface_no,
  265. void *context,
  266. const void *msg,
  267. unsigned int msg_len);
  268. static void passive_mcast_noflush_send (
  269. struct totemrrp_instance *instance,
  270. const void *msg,
  271. unsigned int msg_len);
  272. static void passive_mcast_flush_send (
  273. struct totemrrp_instance *instance,
  274. const void *msg,
  275. unsigned int msg_len);
  276. static void passive_monitor (
  277. struct totemrrp_instance *rrp_instance,
  278. unsigned int iface_no,
  279. int is_token_recv_count);
  280. static void passive_token_recv (
  281. struct totemrrp_instance *instance,
  282. unsigned int iface_no,
  283. void *context,
  284. const void *msg,
  285. unsigned int msg_len,
  286. unsigned int token_seqid);
  287. static void passive_token_send (
  288. struct totemrrp_instance *instance,
  289. const void *msg,
  290. unsigned int msg_len);
  291. static void passive_recv_flush (
  292. struct totemrrp_instance *instance);
  293. static void passive_send_flush (
  294. struct totemrrp_instance *instance);
  295. static void passive_iface_check (
  296. struct totemrrp_instance *instance);
  297. static void passive_processor_count_set (
  298. struct totemrrp_instance *instance,
  299. unsigned int processor_count_set);
  300. static void passive_token_target_set (
  301. struct totemrrp_instance *instance,
  302. struct totem_ip_address *token_target,
  303. unsigned int iface_no);
  304. static void passive_ring_reenable (
  305. struct totemrrp_instance *instance,
  306. unsigned int iface_no);
  307. static int passive_mcast_recv_empty (
  308. struct totemrrp_instance *instance);
  309. static int passive_member_add (
  310. struct totemrrp_instance *instance,
  311. const struct totem_ip_address *member,
  312. unsigned int iface_no);
  313. static int passive_member_remove (
  314. struct totemrrp_instance *instance,
  315. const struct totem_ip_address *member,
  316. unsigned int iface_no);
  317. /*
  318. * Active Replication Forward Definitions
  319. */
  320. static void *active_instance_initialize (
  321. struct totemrrp_instance *rrp_instance,
  322. int interface_count);
  323. static void active_mcast_recv (
  324. struct totemrrp_instance *instance,
  325. unsigned int iface_no,
  326. void *context,
  327. const void *msg,
  328. unsigned int msg_len);
  329. static void active_mcast_noflush_send (
  330. struct totemrrp_instance *instance,
  331. const void *msg,
  332. unsigned int msg_len);
  333. static void active_mcast_flush_send (
  334. struct totemrrp_instance *instance,
  335. const void *msg,
  336. unsigned int msg_len);
  337. static void active_token_recv (
  338. struct totemrrp_instance *instance,
  339. unsigned int iface_no,
  340. void *context,
  341. const void *msg,
  342. unsigned int msg_len,
  343. unsigned int token_seqid);
  344. static void active_token_send (
  345. struct totemrrp_instance *instance,
  346. const void *msg,
  347. unsigned int msg_len);
  348. static void active_recv_flush (
  349. struct totemrrp_instance *instance);
  350. static void active_send_flush (
  351. struct totemrrp_instance *instance);
  352. static void active_iface_check (
  353. struct totemrrp_instance *instance);
  354. static void active_processor_count_set (
  355. struct totemrrp_instance *instance,
  356. unsigned int processor_count_set);
  357. static void active_token_target_set (
  358. struct totemrrp_instance *instance,
  359. struct totem_ip_address *token_target,
  360. unsigned int iface_no);
  361. static void active_ring_reenable (
  362. struct totemrrp_instance *instance,
  363. unsigned int iface_no);
  364. static int active_mcast_recv_empty (
  365. struct totemrrp_instance *instance);
  366. static int active_member_add (
  367. struct totemrrp_instance *instance,
  368. const struct totem_ip_address *member,
  369. unsigned int iface_no);
  370. static int active_member_remove (
  371. struct totemrrp_instance *instance,
  372. const struct totem_ip_address *member,
  373. unsigned int iface_no);
  374. static void active_timer_expired_token_start (
  375. struct active_instance *active_instance);
  376. static void active_timer_expired_token_cancel (
  377. struct active_instance *active_instance);
  378. static void active_timer_problem_decrementer_start (
  379. struct active_instance *active_instance);
  380. static void active_timer_problem_decrementer_cancel (
  381. struct active_instance *active_instance);
  382. /*
  383. * 0-5 reserved for totemsrp.c
  384. */
  385. #define MESSAGE_TYPE_RING_TEST_ACTIVE 6
  386. #define MESSAGE_TYPE_RING_TEST_ACTIVATE 7
  387. #define ENDIAN_LOCAL 0xff22
  388. /*
  389. * Rollover handling:
  390. *
  391. * ARR_SEQNO_START_TOKEN is the starting sequence number of last seen sequence
  392. * for a token for active redundand ring. This should remain zero, unless testing
  393. * overflow in which case 07fffff00 or 0xffffff00 are good starting values.
  394. * It should be same as on defined in totemsrp.c
  395. */
  396. #define ARR_SEQNO_START_TOKEN 0x0
  397. /*
  398. * These can be used ot test different rollover points
  399. * #define ARR_SEQNO_START_MSG 0xfffffe00
  400. */
  401. /*
  402. * Threshold value when recv_count for passive rrp should be adjusted.
  403. * Set this value to some smaller for testing of adjusting proper
  404. * functionality. Also keep in mind that this value must be smaller
  405. * then rrp_problem_count_threshold
  406. */
  407. #define PASSIVE_RECV_COUNT_THRESHOLD (INT_MAX / 2)
  408. struct message_header {
  409. char type;
  410. char encapsulated;
  411. unsigned short endian_detector;
  412. int ring_number;
  413. int nodeid_activator;
  414. } __attribute__((packed));
  415. struct deliver_fn_context {
  416. struct totemrrp_instance *instance;
  417. void *context;
  418. int iface_no;
  419. };
  420. struct rrp_algo none_algo = {
  421. .name = "none",
  422. .initialize = NULL,
  423. .mcast_recv = none_mcast_recv,
  424. .mcast_noflush_send = none_mcast_noflush_send,
  425. .mcast_flush_send = none_mcast_flush_send,
  426. .token_recv = none_token_recv,
  427. .token_send = none_token_send,
  428. .recv_flush = none_recv_flush,
  429. .send_flush = none_send_flush,
  430. .iface_check = none_iface_check,
  431. .processor_count_set = none_processor_count_set,
  432. .token_target_set = none_token_target_set,
  433. .ring_reenable = none_ring_reenable,
  434. .mcast_recv_empty = none_mcast_recv_empty,
  435. .member_add = none_member_add,
  436. .member_remove = none_member_remove
  437. };
  438. struct rrp_algo passive_algo = {
  439. .name = "passive",
  440. .initialize = passive_instance_initialize,
  441. .mcast_recv = passive_mcast_recv,
  442. .mcast_noflush_send = passive_mcast_noflush_send,
  443. .mcast_flush_send = passive_mcast_flush_send,
  444. .token_recv = passive_token_recv,
  445. .token_send = passive_token_send,
  446. .recv_flush = passive_recv_flush,
  447. .send_flush = passive_send_flush,
  448. .iface_check = passive_iface_check,
  449. .processor_count_set = passive_processor_count_set,
  450. .token_target_set = passive_token_target_set,
  451. .ring_reenable = passive_ring_reenable,
  452. .mcast_recv_empty = passive_mcast_recv_empty,
  453. .member_add = passive_member_add,
  454. .member_remove = passive_member_remove
  455. };
  456. struct rrp_algo active_algo = {
  457. .name = "active",
  458. .initialize = active_instance_initialize,
  459. .mcast_recv = active_mcast_recv,
  460. .mcast_noflush_send = active_mcast_noflush_send,
  461. .mcast_flush_send = active_mcast_flush_send,
  462. .token_recv = active_token_recv,
  463. .token_send = active_token_send,
  464. .recv_flush = active_recv_flush,
  465. .send_flush = active_send_flush,
  466. .iface_check = active_iface_check,
  467. .processor_count_set = active_processor_count_set,
  468. .token_target_set = active_token_target_set,
  469. .ring_reenable = active_ring_reenable,
  470. .mcast_recv_empty = active_mcast_recv_empty,
  471. .member_add = active_member_add,
  472. .member_remove = active_member_remove
  473. };
  474. struct rrp_algo *rrp_algos[] = {
  475. &none_algo,
  476. &passive_algo,
  477. &active_algo
  478. };
  479. #define RRP_ALGOS_COUNT 3
  480. #define log_printf(level, format, args...) \
  481. do { \
  482. rrp_instance->totemrrp_log_printf ( \
  483. LOGSYS_ENCODE_RECID(level, \
  484. rrp_instance->totemrrp_subsys_id, \
  485. LOGSYS_RECID_LOG), \
  486. __FUNCTION__, __FILE__, __LINE__, \
  487. format, ##args); \
  488. } while (0);
  489. static void test_active_msg_endian_convert(const struct message_header *in, struct message_header *out)
  490. {
  491. out->type = in->type;
  492. out->encapsulated = in->encapsulated;
  493. out->endian_detector = ENDIAN_LOCAL;
  494. out->ring_number = swab32 (in->ring_number);
  495. out->nodeid_activator = swab32(in->nodeid_activator);
  496. }
  497. static void timer_function_test_ring_timeout (void *context)
  498. {
  499. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  500. struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
  501. unsigned int *faulty = NULL;
  502. int iface_no = deliver_fn_context->iface_no;
  503. struct message_header msg = {
  504. .type = MESSAGE_TYPE_RING_TEST_ACTIVE,
  505. .endian_detector = ENDIAN_LOCAL,
  506. };
  507. if (strcmp(rrp_instance->totem_config->rrp_mode, "active") == 0)
  508. faulty = ((struct active_instance *)(rrp_instance->rrp_algo_instance))->faulty;
  509. if (strcmp(rrp_instance->totem_config->rrp_mode, "passive") == 0)
  510. faulty = ((struct passive_instance *)(rrp_instance->rrp_algo_instance))->faulty;
  511. assert (faulty != NULL);
  512. if (faulty[iface_no] == 1) {
  513. msg.ring_number = iface_no;
  514. msg.nodeid_activator = rrp_instance->my_nodeid;
  515. totemnet_token_send (
  516. rrp_instance->net_handles[iface_no],
  517. &msg, sizeof (struct message_header));
  518. poll_timer_add (rrp_instance->poll_handle,
  519. rrp_instance->totem_config->rrp_autorecovery_check_timeout,
  520. (void *)deliver_fn_context,
  521. timer_function_test_ring_timeout,
  522. &rrp_instance->timer_active_test_ring_timeout[iface_no]);
  523. }
  524. }
  525. /*
  526. * None Replication Implementation
  527. */
  528. static void none_mcast_recv (
  529. struct totemrrp_instance *rrp_instance,
  530. unsigned int iface_no,
  531. void *context,
  532. const void *msg,
  533. unsigned int msg_len)
  534. {
  535. rrp_instance->totemrrp_deliver_fn (
  536. context,
  537. msg,
  538. msg_len);
  539. }
  540. static void none_mcast_flush_send (
  541. struct totemrrp_instance *instance,
  542. const void *msg,
  543. unsigned int msg_len)
  544. {
  545. totemnet_mcast_flush_send (instance->net_handles[0], msg, msg_len);
  546. }
  547. static void none_mcast_noflush_send (
  548. struct totemrrp_instance *instance,
  549. const void *msg,
  550. unsigned int msg_len)
  551. {
  552. totemnet_mcast_noflush_send (instance->net_handles[0], msg, msg_len);
  553. }
  554. static void none_token_recv (
  555. struct totemrrp_instance *rrp_instance,
  556. unsigned int iface_no,
  557. void *context,
  558. const void *msg,
  559. unsigned int msg_len,
  560. unsigned int token_seq)
  561. {
  562. rrp_instance->totemrrp_deliver_fn (
  563. context,
  564. msg,
  565. msg_len);
  566. }
  567. static void none_token_send (
  568. struct totemrrp_instance *instance,
  569. const void *msg,
  570. unsigned int msg_len)
  571. {
  572. totemnet_token_send (
  573. instance->net_handles[0],
  574. msg, msg_len);
  575. }
  576. static void none_recv_flush (struct totemrrp_instance *instance)
  577. {
  578. totemnet_recv_flush (instance->net_handles[0]);
  579. }
  580. static void none_send_flush (struct totemrrp_instance *instance)
  581. {
  582. totemnet_send_flush (instance->net_handles[0]);
  583. }
  584. static void none_iface_check (struct totemrrp_instance *instance)
  585. {
  586. totemnet_iface_check (instance->net_handles[0]);
  587. }
  588. static void none_processor_count_set (
  589. struct totemrrp_instance *instance,
  590. unsigned int processor_count)
  591. {
  592. totemnet_processor_count_set (instance->net_handles[0],
  593. processor_count);
  594. }
  595. static void none_token_target_set (
  596. struct totemrrp_instance *instance,
  597. struct totem_ip_address *token_target,
  598. unsigned int iface_no)
  599. {
  600. totemnet_token_target_set (instance->net_handles[0], token_target);
  601. }
  602. static void none_ring_reenable (
  603. struct totemrrp_instance *instance,
  604. unsigned int iface_no)
  605. {
  606. /*
  607. * No operation
  608. */
  609. }
  610. static int none_mcast_recv_empty (
  611. struct totemrrp_instance *instance)
  612. {
  613. int res;
  614. res = totemnet_recv_mcast_empty (instance->net_handles[0]);
  615. return (res);
  616. }
  617. static int none_member_add (
  618. struct totemrrp_instance *instance,
  619. const struct totem_ip_address *member,
  620. unsigned int iface_no)
  621. {
  622. int res;
  623. res = totemnet_member_add (instance->net_handles[0], member);
  624. return (res);
  625. }
  626. static int none_member_remove (
  627. struct totemrrp_instance *instance,
  628. const struct totem_ip_address *member,
  629. unsigned int iface_no)
  630. {
  631. int res;
  632. res = totemnet_member_remove (instance->net_handles[0], member);
  633. return (res);
  634. }
  635. /*
  636. * Passive Replication Implementation
  637. */
  638. void *passive_instance_initialize (
  639. struct totemrrp_instance *rrp_instance,
  640. int interface_count)
  641. {
  642. struct passive_instance *instance;
  643. instance = malloc (sizeof (struct passive_instance));
  644. if (instance == 0) {
  645. goto error_exit;
  646. }
  647. memset (instance, 0, sizeof (struct passive_instance));
  648. instance->faulty = malloc (sizeof (int) * interface_count);
  649. if (instance->faulty == 0) {
  650. free (instance);
  651. instance = 0;
  652. goto error_exit;
  653. }
  654. memset (instance->faulty, 0, sizeof (int) * interface_count);
  655. instance->token_recv_count = malloc (sizeof (int) * interface_count);
  656. if (instance->token_recv_count == 0) {
  657. free (instance->faulty);
  658. free (instance);
  659. instance = 0;
  660. goto error_exit;
  661. }
  662. memset (instance->token_recv_count, 0, sizeof (int) * interface_count);
  663. instance->mcast_recv_count = malloc (sizeof (int) * interface_count);
  664. if (instance->mcast_recv_count == 0) {
  665. free (instance->token_recv_count);
  666. free (instance->faulty);
  667. free (instance);
  668. instance = 0;
  669. goto error_exit;
  670. }
  671. memset (instance->mcast_recv_count, 0, sizeof (int) * interface_count);
  672. error_exit:
  673. return ((void *)instance);
  674. }
  675. static void timer_function_passive_token_expired (void *context)
  676. {
  677. struct passive_instance *passive_instance = (struct passive_instance *)context;
  678. struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
  679. rrp_instance->totemrrp_deliver_fn (
  680. passive_instance->totemrrp_context,
  681. passive_instance->token,
  682. passive_instance->token_len);
  683. }
  684. /* TODO
  685. static void timer_function_passive_problem_decrementer (void *context)
  686. {
  687. // struct passive_instance *passive_instance = (struct passive_instance *)context;
  688. // struct totemrrp_instance *rrp_instance = passive_instance->rrp_instance;
  689. }
  690. */
  691. static void passive_timer_expired_token_start (
  692. struct passive_instance *passive_instance)
  693. {
  694. poll_timer_add (
  695. passive_instance->rrp_instance->poll_handle,
  696. passive_instance->rrp_instance->totem_config->rrp_token_expired_timeout,
  697. (void *)passive_instance,
  698. timer_function_passive_token_expired,
  699. &passive_instance->timer_expired_token);
  700. }
  701. static void passive_timer_expired_token_cancel (
  702. struct passive_instance *passive_instance)
  703. {
  704. poll_timer_delete (
  705. passive_instance->rrp_instance->poll_handle,
  706. passive_instance->timer_expired_token);
  707. }
  708. /*
  709. static void passive_timer_problem_decrementer_start (
  710. struct passive_instance *passive_instance)
  711. {
  712. poll_timer_add (
  713. passive_instance->rrp_instance->poll_handle,
  714. passive_instance->rrp_instance->totem_config->rrp_problem_count_timeout,
  715. (void *)passive_instance,
  716. timer_function_passive_problem_decrementer,
  717. &passive_instance->timer_problem_decrementer);
  718. }
  719. static void passive_timer_problem_decrementer_cancel (
  720. struct passive_instance *passive_instance)
  721. {
  722. poll_timer_delete (
  723. passive_instance->rrp_instance->poll_handle,
  724. passive_instance->timer_problem_decrementer);
  725. }
  726. */
  727. /*
  728. * Monitor function implementation from rrp paper.
  729. * rrp_instance is passive rrp instance, iface_no is interface with received messgae/token and
  730. * is_token_recv_count is boolean variable which donates if message is token (>1) or regular
  731. * message (= 0)
  732. */
  733. static void passive_monitor (
  734. struct totemrrp_instance *rrp_instance,
  735. unsigned int iface_no,
  736. int is_token_recv_count)
  737. {
  738. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  739. unsigned int *recv_count;
  740. unsigned int max;
  741. unsigned int i;
  742. unsigned int min_all, min_active;
  743. /*
  744. * Monitor for failures
  745. */
  746. if (is_token_recv_count) {
  747. recv_count = passive_instance->token_recv_count;
  748. } else {
  749. recv_count = passive_instance->mcast_recv_count;
  750. }
  751. recv_count[iface_no] += 1;
  752. max = 0;
  753. for (i = 0; i < rrp_instance->interface_count; i++) {
  754. if (max < recv_count[i]) {
  755. max = recv_count[i];
  756. }
  757. }
  758. /*
  759. * Max is larger then threshold -> start adjusting process
  760. */
  761. if (max > PASSIVE_RECV_COUNT_THRESHOLD) {
  762. min_all = min_active = recv_count[iface_no];
  763. for (i = 0; i < rrp_instance->interface_count; i++) {
  764. if (recv_count[i] < min_all) {
  765. min_all = recv_count[i];
  766. }
  767. if (passive_instance->faulty[i] == 0 &&
  768. recv_count[i] < min_active) {
  769. min_active = recv_count[i];
  770. }
  771. }
  772. if (min_all > 0) {
  773. /*
  774. * There is one or more faulty device with recv_count > 0
  775. */
  776. for (i = 0; i < rrp_instance->interface_count; i++) {
  777. recv_count[i] -= min_all;
  778. }
  779. } else {
  780. /*
  781. * No faulty device with recv_count > 0, adjust only active
  782. * devices
  783. */
  784. for (i = 0; i < rrp_instance->interface_count; i++) {
  785. if (passive_instance->faulty[i] == 0) {
  786. recv_count[i] -= min_active;
  787. }
  788. }
  789. }
  790. /*
  791. * Find again max
  792. */
  793. max = 0;
  794. for (i = 0; i < rrp_instance->interface_count; i++) {
  795. if (max < recv_count[i]) {
  796. max = recv_count[i];
  797. }
  798. }
  799. }
  800. for (i = 0; i < rrp_instance->interface_count; i++) {
  801. if ((passive_instance->faulty[i] == 0) &&
  802. (max - recv_count[i] >
  803. rrp_instance->totem_config->rrp_problem_count_threshold)) {
  804. passive_instance->faulty[i] = 1;
  805. poll_timer_add (rrp_instance->poll_handle,
  806. rrp_instance->totem_config->rrp_autorecovery_check_timeout,
  807. rrp_instance->deliver_fn_context[i],
  808. timer_function_test_ring_timeout,
  809. &rrp_instance->timer_active_test_ring_timeout[i]);
  810. sprintf (rrp_instance->status[i],
  811. "Marking ringid %u interface %s FAULTY",
  812. i,
  813. totemnet_iface_print (rrp_instance->net_handles[i]));
  814. log_printf (
  815. rrp_instance->totemrrp_log_level_error,
  816. "%s",
  817. rrp_instance->status[i]);
  818. }
  819. }
  820. }
  821. static void passive_mcast_recv (
  822. struct totemrrp_instance *rrp_instance,
  823. unsigned int iface_no,
  824. void *context,
  825. const void *msg,
  826. unsigned int msg_len)
  827. {
  828. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  829. rrp_instance->totemrrp_deliver_fn (
  830. context,
  831. msg,
  832. msg_len);
  833. if (rrp_instance->totemrrp_msgs_missing() == 0 &&
  834. passive_instance->timer_expired_token) {
  835. /*
  836. * Delivers the last token
  837. */
  838. rrp_instance->totemrrp_deliver_fn (
  839. passive_instance->totemrrp_context,
  840. passive_instance->token,
  841. passive_instance->token_len);
  842. passive_timer_expired_token_cancel (passive_instance);
  843. }
  844. passive_monitor (rrp_instance, iface_no, 0);
  845. }
  846. static void passive_mcast_flush_send (
  847. struct totemrrp_instance *instance,
  848. const void *msg,
  849. unsigned int msg_len)
  850. {
  851. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  852. do {
  853. passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
  854. } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
  855. totemnet_mcast_flush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
  856. }
  857. static void passive_mcast_noflush_send (
  858. struct totemrrp_instance *instance,
  859. const void *msg,
  860. unsigned int msg_len)
  861. {
  862. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  863. do {
  864. passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
  865. } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
  866. totemnet_mcast_noflush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
  867. }
  868. static void passive_token_recv (
  869. struct totemrrp_instance *rrp_instance,
  870. unsigned int iface_no,
  871. void *context,
  872. const void *msg,
  873. unsigned int msg_len,
  874. unsigned int token_seq)
  875. {
  876. struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
  877. passive_instance->totemrrp_context = context; // this should be in totemrrp_instance ? TODO
  878. if (rrp_instance->totemrrp_msgs_missing() == 0) {
  879. rrp_instance->totemrrp_deliver_fn (
  880. context,
  881. msg,
  882. msg_len);
  883. } else {
  884. memcpy (passive_instance->token, msg, msg_len);
  885. passive_timer_expired_token_start (passive_instance);
  886. }
  887. passive_monitor (rrp_instance, iface_no, 1);
  888. }
  889. static void passive_token_send (
  890. struct totemrrp_instance *instance,
  891. const void *msg,
  892. unsigned int msg_len)
  893. {
  894. struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
  895. do {
  896. passive_instance->token_xmit_iface = (passive_instance->token_xmit_iface + 1) % instance->interface_count;
  897. } while (passive_instance->faulty[passive_instance->token_xmit_iface] == 1);
  898. totemnet_token_send (
  899. instance->net_handles[passive_instance->token_xmit_iface],
  900. msg, msg_len);
  901. }
  902. static void passive_recv_flush (struct totemrrp_instance *instance)
  903. {
  904. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  905. unsigned int i;
  906. for (i = 0; i < instance->interface_count; i++) {
  907. if (rrp_algo_instance->faulty[i] == 0) {
  908. totemnet_recv_flush (instance->net_handles[i]);
  909. }
  910. }
  911. }
  912. static void passive_send_flush (struct totemrrp_instance *instance)
  913. {
  914. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  915. unsigned int i;
  916. for (i = 0; i < instance->interface_count; i++) {
  917. if (rrp_algo_instance->faulty[i] == 0) {
  918. totemnet_send_flush (instance->net_handles[i]);
  919. }
  920. }
  921. }
  922. static void passive_iface_check (struct totemrrp_instance *instance)
  923. {
  924. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  925. unsigned int i;
  926. for (i = 0; i < instance->interface_count; i++) {
  927. if (rrp_algo_instance->faulty[i] == 0) {
  928. totemnet_iface_check (instance->net_handles[i]);
  929. }
  930. }
  931. }
  932. static void passive_processor_count_set (
  933. struct totemrrp_instance *instance,
  934. unsigned int processor_count)
  935. {
  936. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  937. unsigned int i;
  938. for (i = 0; i < instance->interface_count; i++) {
  939. if (rrp_algo_instance->faulty[i] == 0) {
  940. totemnet_processor_count_set (instance->net_handles[i],
  941. processor_count);
  942. }
  943. }
  944. }
  945. static void passive_token_target_set (
  946. struct totemrrp_instance *instance,
  947. struct totem_ip_address *token_target,
  948. unsigned int iface_no)
  949. {
  950. totemnet_token_target_set (instance->net_handles[iface_no], token_target);
  951. }
  952. static int passive_mcast_recv_empty (
  953. struct totemrrp_instance *instance)
  954. {
  955. int res;
  956. int msgs_emptied = 0;
  957. int i;
  958. for (i = 0; i < instance->interface_count; i++) {
  959. res = totemnet_recv_mcast_empty (instance->net_handles[i]);
  960. if (res == -1) {
  961. return (-1);
  962. }
  963. if (res == 1) {
  964. msgs_emptied = 1;
  965. }
  966. }
  967. return (msgs_emptied);
  968. }
  969. static int passive_member_add (
  970. struct totemrrp_instance *instance,
  971. const struct totem_ip_address *member,
  972. unsigned int iface_no)
  973. {
  974. int res;
  975. res = totemnet_member_add (instance->net_handles[iface_no], member);
  976. return (res);
  977. }
  978. static int passive_member_remove (
  979. struct totemrrp_instance *instance,
  980. const struct totem_ip_address *member,
  981. unsigned int iface_no)
  982. {
  983. int res;
  984. res = totemnet_member_remove (instance->net_handles[iface_no], member);
  985. return (res);
  986. }
  987. static void passive_ring_reenable (
  988. struct totemrrp_instance *instance,
  989. unsigned int iface_no)
  990. {
  991. struct passive_instance *rrp_algo_instance = (struct passive_instance *)instance->rrp_algo_instance;
  992. memset (rrp_algo_instance->mcast_recv_count, 0, sizeof (unsigned int) *
  993. instance->interface_count);
  994. memset (rrp_algo_instance->token_recv_count, 0, sizeof (unsigned int) *
  995. instance->interface_count);
  996. if (iface_no == instance->interface_count) {
  997. memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
  998. instance->interface_count);
  999. } else {
  1000. rrp_algo_instance->faulty[iface_no] = 0;
  1001. }
  1002. }
  1003. /*
  1004. * Active Replication Implementation
  1005. */
  1006. void *active_instance_initialize (
  1007. struct totemrrp_instance *rrp_instance,
  1008. int interface_count)
  1009. {
  1010. struct active_instance *instance;
  1011. instance = malloc (sizeof (struct active_instance));
  1012. if (instance == 0) {
  1013. goto error_exit;
  1014. }
  1015. memset (instance, 0, sizeof (struct active_instance));
  1016. instance->faulty = malloc (sizeof (int) * interface_count);
  1017. if (instance->faulty == 0) {
  1018. free (instance);
  1019. instance = 0;
  1020. goto error_exit;
  1021. }
  1022. memset (instance->faulty, 0, sizeof (unsigned int) * interface_count);
  1023. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  1024. if (instance->last_token_recv == 0) {
  1025. free (instance->faulty);
  1026. free (instance);
  1027. instance = 0;
  1028. goto error_exit;
  1029. }
  1030. memset (instance->last_token_recv, 0, sizeof (unsigned int) * interface_count);
  1031. instance->counter_problems = malloc (sizeof (int) * interface_count);
  1032. if (instance->counter_problems == 0) {
  1033. free (instance->last_token_recv);
  1034. free (instance->faulty);
  1035. free (instance);
  1036. instance = 0;
  1037. goto error_exit;
  1038. }
  1039. memset (instance->counter_problems, 0, sizeof (unsigned int) * interface_count);
  1040. instance->timer_expired_token = 0;
  1041. instance->timer_problem_decrementer = 0;
  1042. instance->rrp_instance = rrp_instance;
  1043. instance->last_token_seq = ARR_SEQNO_START_TOKEN - 1;
  1044. error_exit:
  1045. return ((void *)instance);
  1046. }
  1047. static void timer_function_active_problem_decrementer (void *context)
  1048. {
  1049. struct active_instance *active_instance = (struct active_instance *)context;
  1050. struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
  1051. unsigned int problem_found = 0;
  1052. unsigned int i;
  1053. for (i = 0; i < rrp_instance->interface_count; i++) {
  1054. if (active_instance->counter_problems[i] > 0) {
  1055. problem_found = 1;
  1056. active_instance->counter_problems[i] -= 1;
  1057. if (active_instance->counter_problems[i] == 0) {
  1058. sprintf (rrp_instance->status[i],
  1059. "ring %d active with no faults", i);
  1060. } else {
  1061. sprintf (rrp_instance->status[i],
  1062. "Decrementing problem counter for iface %s to [%d of %d]",
  1063. totemnet_iface_print (rrp_instance->net_handles[i]),
  1064. active_instance->counter_problems[i],
  1065. rrp_instance->totem_config->rrp_problem_count_threshold);
  1066. }
  1067. log_printf (
  1068. rrp_instance->totemrrp_log_level_warning,
  1069. "%s",
  1070. rrp_instance->status[i]);
  1071. }
  1072. }
  1073. if (problem_found) {
  1074. active_timer_problem_decrementer_start (active_instance);
  1075. } else {
  1076. active_instance->timer_problem_decrementer = 0;
  1077. }
  1078. }
  1079. static void timer_function_active_token_expired (void *context)
  1080. {
  1081. struct active_instance *active_instance = (struct active_instance *)context;
  1082. struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
  1083. unsigned int i;
  1084. for (i = 0; i < rrp_instance->interface_count; i++) {
  1085. if (active_instance->last_token_recv[i] == 0) {
  1086. active_instance->counter_problems[i] += 1;
  1087. if (active_instance->timer_problem_decrementer == 0) {
  1088. active_timer_problem_decrementer_start (active_instance);
  1089. }
  1090. sprintf (rrp_instance->status[i],
  1091. "Incrementing problem counter for seqid %d iface %s to [%d of %d]",
  1092. active_instance->last_token_seq,
  1093. totemnet_iface_print (rrp_instance->net_handles[i]),
  1094. active_instance->counter_problems[i],
  1095. rrp_instance->totem_config->rrp_problem_count_threshold);
  1096. log_printf (
  1097. rrp_instance->totemrrp_log_level_warning,
  1098. "%s",
  1099. rrp_instance->status[i]);
  1100. }
  1101. }
  1102. for (i = 0; i < rrp_instance->interface_count; i++) {
  1103. if (active_instance->counter_problems[i] >= rrp_instance->totem_config->rrp_problem_count_threshold)
  1104. {
  1105. active_instance->faulty[i] = 1;
  1106. poll_timer_add (rrp_instance->poll_handle,
  1107. rrp_instance->totem_config->rrp_autorecovery_check_timeout,
  1108. rrp_instance->deliver_fn_context[i],
  1109. timer_function_test_ring_timeout,
  1110. &rrp_instance->timer_active_test_ring_timeout[i]);
  1111. sprintf (rrp_instance->status[i],
  1112. "Marking seqid %d ringid %u interface %s FAULTY",
  1113. active_instance->last_token_seq,
  1114. i,
  1115. totemnet_iface_print (rrp_instance->net_handles[i]));
  1116. log_printf (
  1117. rrp_instance->totemrrp_log_level_error,
  1118. "%s",
  1119. rrp_instance->status[i]);
  1120. active_timer_problem_decrementer_cancel (active_instance);
  1121. }
  1122. }
  1123. rrp_instance->totemrrp_deliver_fn (
  1124. active_instance->totemrrp_context,
  1125. active_instance->token,
  1126. active_instance->token_len);
  1127. }
  1128. static void active_timer_expired_token_start (
  1129. struct active_instance *active_instance)
  1130. {
  1131. poll_timer_add (
  1132. active_instance->rrp_instance->poll_handle,
  1133. active_instance->rrp_instance->totem_config->rrp_token_expired_timeout,
  1134. (void *)active_instance,
  1135. timer_function_active_token_expired,
  1136. &active_instance->timer_expired_token);
  1137. }
  1138. static void active_timer_expired_token_cancel (
  1139. struct active_instance *active_instance)
  1140. {
  1141. poll_timer_delete (
  1142. active_instance->rrp_instance->poll_handle,
  1143. active_instance->timer_expired_token);
  1144. }
  1145. static void active_timer_problem_decrementer_start (
  1146. struct active_instance *active_instance)
  1147. {
  1148. poll_timer_add (
  1149. active_instance->rrp_instance->poll_handle,
  1150. active_instance->rrp_instance->totem_config->rrp_problem_count_timeout,
  1151. (void *)active_instance,
  1152. timer_function_active_problem_decrementer,
  1153. &active_instance->timer_problem_decrementer);
  1154. }
  1155. static void active_timer_problem_decrementer_cancel (
  1156. struct active_instance *active_instance)
  1157. {
  1158. poll_timer_delete (
  1159. active_instance->rrp_instance->poll_handle,
  1160. active_instance->timer_problem_decrementer);
  1161. }
  1162. /*
  1163. * active replication
  1164. */
  1165. static void active_mcast_recv (
  1166. struct totemrrp_instance *instance,
  1167. unsigned int iface_no,
  1168. void *context,
  1169. const void *msg,
  1170. unsigned int msg_len)
  1171. {
  1172. instance->totemrrp_deliver_fn (
  1173. context,
  1174. msg,
  1175. msg_len);
  1176. }
  1177. static void active_mcast_flush_send (
  1178. struct totemrrp_instance *instance,
  1179. const void *msg,
  1180. unsigned int msg_len)
  1181. {
  1182. int i;
  1183. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1184. for (i = 0; i < instance->interface_count; i++) {
  1185. if (rrp_algo_instance->faulty[i] == 0) {
  1186. totemnet_mcast_flush_send (instance->net_handles[i], msg, msg_len);
  1187. }
  1188. }
  1189. }
  1190. static void active_mcast_noflush_send (
  1191. struct totemrrp_instance *instance,
  1192. const void *msg,
  1193. unsigned int msg_len)
  1194. {
  1195. int i;
  1196. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1197. for (i = 0; i < instance->interface_count; i++) {
  1198. if (rrp_algo_instance->faulty[i] == 0) {
  1199. totemnet_mcast_noflush_send (instance->net_handles[i], msg, msg_len);
  1200. }
  1201. }
  1202. }
  1203. static void active_token_recv (
  1204. struct totemrrp_instance *rrp_instance,
  1205. unsigned int iface_no,
  1206. void *context,
  1207. const void *msg,
  1208. unsigned int msg_len,
  1209. unsigned int token_seq)
  1210. {
  1211. int i;
  1212. struct active_instance *active_instance = (struct active_instance *)rrp_instance->rrp_algo_instance;
  1213. active_instance->totemrrp_context = context;
  1214. if (sq_lt_compare (active_instance->last_token_seq, token_seq)) {
  1215. memcpy (active_instance->token, msg, msg_len);
  1216. active_instance->token_len = msg_len;
  1217. for (i = 0; i < rrp_instance->interface_count; i++) {
  1218. active_instance->last_token_recv[i] = 0;
  1219. }
  1220. active_instance->last_token_recv[iface_no] = 1;
  1221. active_timer_expired_token_start (active_instance);
  1222. }
  1223. /*
  1224. * This doesn't follow spec because the spec assumes we will know
  1225. * when token resets occur.
  1226. */
  1227. active_instance->last_token_seq = token_seq;
  1228. if (token_seq == active_instance->last_token_seq) {
  1229. active_instance->last_token_recv[iface_no] = 1;
  1230. for (i = 0; i < rrp_instance->interface_count; i++) {
  1231. if ((active_instance->last_token_recv[i] == 0) &&
  1232. active_instance->faulty[i] == 0) {
  1233. return; /* don't deliver token */
  1234. }
  1235. }
  1236. active_timer_expired_token_cancel (active_instance);
  1237. rrp_instance->totemrrp_deliver_fn (
  1238. context,
  1239. msg,
  1240. msg_len);
  1241. }
  1242. }
  1243. static void active_token_send (
  1244. struct totemrrp_instance *instance,
  1245. const void *msg,
  1246. unsigned int msg_len)
  1247. {
  1248. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1249. int i;
  1250. for (i = 0; i < instance->interface_count; i++) {
  1251. if (rrp_algo_instance->faulty[i] == 0) {
  1252. totemnet_token_send (
  1253. instance->net_handles[i],
  1254. msg, msg_len);
  1255. }
  1256. }
  1257. }
  1258. static void active_recv_flush (struct totemrrp_instance *instance)
  1259. {
  1260. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1261. unsigned int i;
  1262. for (i = 0; i < instance->interface_count; i++) {
  1263. if (rrp_algo_instance->faulty[i] == 0) {
  1264. totemnet_recv_flush (instance->net_handles[i]);
  1265. }
  1266. }
  1267. }
  1268. static void active_send_flush (struct totemrrp_instance *instance)
  1269. {
  1270. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1271. unsigned int i;
  1272. for (i = 0; i < instance->interface_count; i++) {
  1273. if (rrp_algo_instance->faulty[i] == 0) {
  1274. totemnet_send_flush (instance->net_handles[i]);
  1275. }
  1276. }
  1277. }
  1278. static int active_member_add (
  1279. struct totemrrp_instance *instance,
  1280. const struct totem_ip_address *member,
  1281. unsigned int iface_no)
  1282. {
  1283. int res;
  1284. res = totemnet_member_add (instance->net_handles[iface_no], member);
  1285. return (res);
  1286. }
  1287. static int active_member_remove (
  1288. struct totemrrp_instance *instance,
  1289. const struct totem_ip_address *member,
  1290. unsigned int iface_no)
  1291. {
  1292. int res;
  1293. res = totemnet_member_remove (instance->net_handles[iface_no], member);
  1294. return (res);
  1295. }
  1296. static void active_iface_check (struct totemrrp_instance *instance)
  1297. {
  1298. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1299. unsigned int i;
  1300. for (i = 0; i < instance->interface_count; i++) {
  1301. if (rrp_algo_instance->faulty[i] == 0) {
  1302. totemnet_iface_check (instance->net_handles[i]);
  1303. }
  1304. }
  1305. }
  1306. static void active_processor_count_set (
  1307. struct totemrrp_instance *instance,
  1308. unsigned int processor_count)
  1309. {
  1310. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1311. unsigned int i;
  1312. for (i = 0; i < instance->interface_count; i++) {
  1313. if (rrp_algo_instance->faulty[i] == 0) {
  1314. totemnet_processor_count_set (instance->net_handles[i],
  1315. processor_count);
  1316. }
  1317. }
  1318. }
  1319. static void active_token_target_set (
  1320. struct totemrrp_instance *instance,
  1321. struct totem_ip_address *token_target,
  1322. unsigned int iface_no)
  1323. {
  1324. totemnet_token_target_set (instance->net_handles[iface_no], token_target);
  1325. }
  1326. static int active_mcast_recv_empty (
  1327. struct totemrrp_instance *instance)
  1328. {
  1329. int res;
  1330. int msgs_emptied = 0;
  1331. int i;
  1332. for (i = 0; i < instance->interface_count; i++) {
  1333. res = totemnet_recv_mcast_empty (instance->net_handles[i]);
  1334. if (res == -1) {
  1335. return (-1);
  1336. }
  1337. if (res == 1) {
  1338. msgs_emptied = 1;
  1339. }
  1340. }
  1341. return (msgs_emptied);
  1342. }
  1343. static void active_ring_reenable (
  1344. struct totemrrp_instance *instance,
  1345. unsigned int iface_no)
  1346. {
  1347. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  1348. if (iface_no == instance->interface_count) {
  1349. memset (rrp_algo_instance->last_token_recv, 0, sizeof (unsigned int) *
  1350. instance->interface_count);
  1351. memset (rrp_algo_instance->faulty, 0, sizeof (unsigned int) *
  1352. instance->interface_count);
  1353. memset (rrp_algo_instance->counter_problems, 0, sizeof (unsigned int) *
  1354. instance->interface_count);
  1355. } else {
  1356. rrp_algo_instance->last_token_recv[iface_no] = 0;
  1357. rrp_algo_instance->faulty[iface_no] = 0;
  1358. rrp_algo_instance->counter_problems[iface_no] = 0;
  1359. }
  1360. }
  1361. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  1362. {
  1363. memset (instance, 0, sizeof (struct totemrrp_instance));
  1364. }
  1365. static int totemrrp_algorithm_set (
  1366. struct totem_config *totem_config,
  1367. struct totemrrp_instance *instance)
  1368. {
  1369. unsigned int res = -1;
  1370. unsigned int i;
  1371. for (i = 0; i < RRP_ALGOS_COUNT; i++) {
  1372. if (strcmp (totem_config->rrp_mode, rrp_algos[i]->name) == 0) {
  1373. instance->rrp_algo = rrp_algos[i];
  1374. if (rrp_algos[i]->initialize) {
  1375. instance->rrp_algo_instance = rrp_algos[i]->initialize (
  1376. instance,
  1377. totem_config->interface_count);
  1378. }
  1379. res = 0;
  1380. break;
  1381. }
  1382. }
  1383. for (i = 0; i < totem_config->interface_count; i++) {
  1384. instance->status[i] = malloc (1024);
  1385. sprintf (instance->status[i], "ring %d active with no faults", i);
  1386. }
  1387. return (res);
  1388. }
  1389. void rrp_deliver_fn (
  1390. void *context,
  1391. const void *msg,
  1392. unsigned int msg_len)
  1393. {
  1394. unsigned int token_seqid;
  1395. unsigned int token_is;
  1396. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1397. struct totemrrp_instance *rrp_instance = deliver_fn_context->instance;
  1398. const struct message_header *hdr = msg;
  1399. struct message_header tmp_msg, activate_msg;
  1400. memset(&tmp_msg, 0, sizeof(struct message_header));
  1401. memset(&activate_msg, 0, sizeof(struct message_header));
  1402. rrp_instance->totemrrp_token_seqid_get (
  1403. msg,
  1404. &token_seqid,
  1405. &token_is);
  1406. if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVE) {
  1407. log_printf (
  1408. rrp_instance->totemrrp_log_level_debug,
  1409. "received message requesting test of ring now active\n");
  1410. if (hdr->endian_detector != ENDIAN_LOCAL) {
  1411. test_active_msg_endian_convert(hdr, &tmp_msg);
  1412. hdr = &tmp_msg;
  1413. }
  1414. if (hdr->nodeid_activator == rrp_instance->my_nodeid) {
  1415. /*
  1416. * Send an activate message
  1417. */
  1418. activate_msg.type = MESSAGE_TYPE_RING_TEST_ACTIVATE;
  1419. activate_msg.endian_detector = ENDIAN_LOCAL;
  1420. activate_msg.ring_number = hdr->ring_number;
  1421. activate_msg.nodeid_activator = rrp_instance->my_nodeid;
  1422. totemnet_token_send (
  1423. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1424. &activate_msg, sizeof (struct message_header));
  1425. } else {
  1426. /*
  1427. * Send a ring test message
  1428. */
  1429. totemnet_token_send (
  1430. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1431. msg, msg_len);
  1432. }
  1433. } else
  1434. if (hdr->type == MESSAGE_TYPE_RING_TEST_ACTIVATE) {
  1435. log_printf (
  1436. rrp_instance->totemrrp_log_level_notice,
  1437. "Automatically recovered ring %d\n", hdr->ring_number);
  1438. if (hdr->endian_detector != ENDIAN_LOCAL) {
  1439. test_active_msg_endian_convert(hdr, &tmp_msg);
  1440. hdr = &tmp_msg;
  1441. }
  1442. totemrrp_ring_reenable (rrp_instance, deliver_fn_context->iface_no);
  1443. if (hdr->nodeid_activator != rrp_instance->my_nodeid) {
  1444. totemnet_token_send (
  1445. rrp_instance->net_handles[deliver_fn_context->iface_no],
  1446. msg, msg_len);
  1447. }
  1448. } else
  1449. if (token_is) {
  1450. /*
  1451. * Deliver to the token receiver for this rrp algorithm
  1452. */
  1453. rrp_instance->rrp_algo->token_recv (
  1454. rrp_instance,
  1455. deliver_fn_context->iface_no,
  1456. deliver_fn_context->context,
  1457. msg,
  1458. msg_len,
  1459. token_seqid);
  1460. } else {
  1461. /*
  1462. * Deliver to the mcast receiver for this rrp algorithm
  1463. */
  1464. rrp_instance->rrp_algo->mcast_recv (
  1465. rrp_instance,
  1466. deliver_fn_context->iface_no,
  1467. deliver_fn_context->context,
  1468. msg,
  1469. msg_len);
  1470. }
  1471. }
  1472. void rrp_iface_change_fn (
  1473. void *context,
  1474. const struct totem_ip_address *iface_addr)
  1475. {
  1476. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1477. deliver_fn_context->instance->my_nodeid = iface_addr->nodeid;
  1478. deliver_fn_context->instance->totemrrp_iface_change_fn (
  1479. deliver_fn_context->context,
  1480. iface_addr,
  1481. deliver_fn_context->iface_no);
  1482. }
  1483. int totemrrp_finalize (
  1484. void *rrp_context)
  1485. {
  1486. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1487. int i;
  1488. for (i = 0; i < instance->interface_count; i++) {
  1489. totemnet_finalize (instance->net_handles[i]);
  1490. }
  1491. return (0);
  1492. }
  1493. static void rrp_target_set_completed (void *context)
  1494. {
  1495. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  1496. deliver_fn_context->instance->totemrrp_target_set_completed (deliver_fn_context->context);
  1497. }
  1498. /*
  1499. * Totem Redundant Ring interface
  1500. * depends on poll abstraction, POSIX, IPV4
  1501. */
  1502. /*
  1503. * Create an instance
  1504. */
  1505. int totemrrp_initialize (
  1506. hdb_handle_t poll_handle,
  1507. void **rrp_context,
  1508. struct totem_config *totem_config,
  1509. void *context,
  1510. void (*deliver_fn) (
  1511. void *context,
  1512. const void *msg,
  1513. unsigned int msg_len),
  1514. void (*iface_change_fn) (
  1515. void *context,
  1516. const struct totem_ip_address *iface_addr,
  1517. unsigned int iface_no),
  1518. void (*token_seqid_get) (
  1519. const void *msg,
  1520. unsigned int *seqid,
  1521. unsigned int *token_is),
  1522. unsigned int (*msgs_missing) (void),
  1523. void (*target_set_completed) (void *context))
  1524. {
  1525. struct totemrrp_instance *instance;
  1526. unsigned int res;
  1527. int i;
  1528. instance = malloc (sizeof (struct totemrrp_instance));
  1529. if (instance == 0) {
  1530. return (-1);
  1531. }
  1532. totemrrp_instance_initialize (instance);
  1533. instance->totem_config = totem_config;
  1534. res = totemrrp_algorithm_set (
  1535. instance->totem_config,
  1536. instance);
  1537. if (res == -1) {
  1538. goto error_destroy;
  1539. }
  1540. /*
  1541. * Configure logging
  1542. */
  1543. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  1544. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  1545. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  1546. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  1547. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  1548. instance->totemrrp_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  1549. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  1550. instance->interfaces = totem_config->interfaces;
  1551. instance->poll_handle = poll_handle;
  1552. instance->totemrrp_deliver_fn = deliver_fn;
  1553. instance->totemrrp_iface_change_fn = iface_change_fn;
  1554. instance->totemrrp_token_seqid_get = token_seqid_get;
  1555. instance->totemrrp_target_set_completed = target_set_completed;
  1556. instance->totemrrp_msgs_missing = msgs_missing;
  1557. instance->interface_count = totem_config->interface_count;
  1558. instance->net_handles = malloc (sizeof (void *) * totem_config->interface_count);
  1559. instance->context = context;
  1560. instance->poll_handle = poll_handle;
  1561. for (i = 0; i < totem_config->interface_count; i++) {
  1562. struct deliver_fn_context *deliver_fn_context;
  1563. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  1564. assert (deliver_fn_context);
  1565. deliver_fn_context->instance = instance;
  1566. deliver_fn_context->context = context;
  1567. deliver_fn_context->iface_no = i;
  1568. instance->deliver_fn_context[i] = (void *)deliver_fn_context;
  1569. totemnet_initialize (
  1570. poll_handle,
  1571. &instance->net_handles[i],
  1572. totem_config,
  1573. i,
  1574. (void *)deliver_fn_context,
  1575. rrp_deliver_fn,
  1576. rrp_iface_change_fn,
  1577. rrp_target_set_completed);
  1578. totemnet_net_mtu_adjust (instance->net_handles[i], totem_config);
  1579. }
  1580. *rrp_context = instance;
  1581. return (0);
  1582. error_destroy:
  1583. free (instance);
  1584. return (res);
  1585. }
  1586. int totemrrp_processor_count_set (
  1587. void *rrp_context,
  1588. unsigned int processor_count)
  1589. {
  1590. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1591. instance->rrp_algo->processor_count_set (instance, processor_count);
  1592. instance->processor_count = processor_count;
  1593. return (0);
  1594. }
  1595. int totemrrp_token_target_set (
  1596. void *rrp_context,
  1597. struct totem_ip_address *addr,
  1598. unsigned int iface_no)
  1599. {
  1600. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1601. instance->rrp_algo->token_target_set (instance, addr, iface_no);
  1602. return (0);
  1603. }
  1604. int totemrrp_recv_flush (void *rrp_context)
  1605. {
  1606. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1607. instance->rrp_algo->recv_flush (instance);
  1608. return (0);
  1609. }
  1610. int totemrrp_send_flush (void *rrp_context)
  1611. {
  1612. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1613. instance->rrp_algo->send_flush (instance);
  1614. return (0);
  1615. }
  1616. int totemrrp_token_send (
  1617. void *rrp_context,
  1618. const void *msg,
  1619. unsigned int msg_len)
  1620. {
  1621. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1622. instance->rrp_algo->token_send (instance, msg, msg_len);
  1623. return (0);
  1624. }
  1625. int totemrrp_mcast_flush_send (
  1626. void *rrp_context,
  1627. const void *msg,
  1628. unsigned int msg_len)
  1629. {
  1630. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1631. int res = 0;
  1632. // TODO this needs to return the result
  1633. instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
  1634. return (res);
  1635. }
  1636. int totemrrp_mcast_noflush_send (
  1637. void *rrp_context,
  1638. const void *msg,
  1639. unsigned int msg_len)
  1640. {
  1641. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1642. /*
  1643. * merge detects go out through mcast_flush_send so it is safe to
  1644. * flush these messages if we are only one processor. This avoids
  1645. * an encryption/hmac and decryption/hmac
  1646. */
  1647. if (instance->processor_count > 1) {
  1648. // TODO this needs to return the result
  1649. instance->rrp_algo->mcast_noflush_send (instance, msg, msg_len);
  1650. }
  1651. return (0);
  1652. }
  1653. int totemrrp_iface_check (void *rrp_context)
  1654. {
  1655. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1656. instance->rrp_algo->iface_check (instance);
  1657. return (0);
  1658. }
  1659. int totemrrp_ifaces_get (
  1660. void *rrp_context,
  1661. char ***status,
  1662. unsigned int *iface_count)
  1663. {
  1664. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1665. *status = instance->status;
  1666. if (iface_count) {
  1667. *iface_count = instance->interface_count;
  1668. }
  1669. return (0);
  1670. }
  1671. int totemrrp_crypto_set (
  1672. void *rrp_context,
  1673. unsigned int type)
  1674. {
  1675. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1676. int res;
  1677. res = totemnet_crypto_set(instance->net_handles[0], type);
  1678. return (res);
  1679. }
  1680. /*
  1681. * iface_no indicates the interface number [0, ..., interface_count-1] of the
  1682. * specific ring which will be reenabled. We specify iface_no == interface_count
  1683. * means reenabling all the rings.
  1684. */
  1685. int totemrrp_ring_reenable (
  1686. void *rrp_context,
  1687. unsigned int iface_no)
  1688. {
  1689. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1690. int res = 0;
  1691. unsigned int i;
  1692. instance->rrp_algo->ring_reenable (instance, iface_no);
  1693. if (iface_no == instance->interface_count) {
  1694. for (i = 0; i < instance->interface_count; i++) {
  1695. sprintf (instance->status[i], "ring %d active with no faults", i);
  1696. }
  1697. } else {
  1698. sprintf (instance->status[iface_no], "ring %d active with no faults", iface_no);
  1699. }
  1700. return (res);
  1701. }
  1702. extern int totemrrp_mcast_recv_empty (
  1703. void *rrp_context)
  1704. {
  1705. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1706. int res;
  1707. res = instance->rrp_algo->mcast_recv_empty (instance);
  1708. return (res);
  1709. }
  1710. int totemrrp_member_add (
  1711. void *rrp_context,
  1712. const struct totem_ip_address *member,
  1713. int iface_no)
  1714. {
  1715. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1716. int res;
  1717. res = instance->rrp_algo->member_add (instance, member, iface_no);
  1718. return (res);
  1719. }
  1720. int totemrrp_member_remove (
  1721. void *rrp_context,
  1722. const struct totem_ip_address *member,
  1723. int iface_no)
  1724. {
  1725. struct totemrrp_instance *instance = (struct totemrrp_instance *)rrp_context;
  1726. int res;
  1727. res = instance->rrp_algo->member_remove (instance, member, iface_no);
  1728. return (res);
  1729. }