totemrrp.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <assert.h>
  35. #include <pthread.h>
  36. #include <sys/mman.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/socket.h>
  40. #include <netdb.h>
  41. #include <sys/un.h>
  42. #include <sys/ioctl.h>
  43. #include <sys/param.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <unistd.h>
  47. #include <fcntl.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <signal.h>
  52. #include <sched.h>
  53. #include <time.h>
  54. #include <sys/time.h>
  55. #include <sys/poll.h>
  56. #include "../include/queue.h"
  57. #include "../include/sq.h"
  58. #include "../include/list.h"
  59. #include "../include/hdb.h"
  60. #include "swab.h"
  61. #include "aispoll.h"
  62. #include "totemnet.h"
  63. #include "totemrrp.h"
  64. struct totemrrp_instance;
  65. struct passive_instance {
  66. unsigned int *faulty;
  67. unsigned int *last_seq;
  68. unsigned int *counter_problems;
  69. unsigned char token[15000];
  70. unsigned int token_len;
  71. };
  72. struct active_instance {
  73. struct totemrrp_instance *rrp_instance;
  74. unsigned int *faulty;
  75. unsigned int *last_token_recv;
  76. unsigned int *counter_problems;
  77. unsigned char token[15000];
  78. unsigned int token_len;
  79. poll_timer_handle timer_active_token;
  80. };
  81. struct rrp_algo {
  82. void (*mcast_recv) (
  83. struct totemrrp_instance *instance,
  84. void *context,
  85. struct totem_ip_address *system_from,
  86. void *msg,
  87. unsigned int msg_len);
  88. void (*mcast_noflush_send) (
  89. struct totemrrp_instance *instance,
  90. struct iovec *iovec,
  91. unsigned int iov_len);
  92. void (*mcast_flush_send) (
  93. struct totemrrp_instance *instance,
  94. struct iovec *iovec,
  95. unsigned int iov_len);
  96. void (*token_recv) (
  97. struct totemrrp_instance *instance,
  98. unsigned int interface_no,
  99. void *context,
  100. struct totem_ip_address *system_from,
  101. void *msg,
  102. unsigned int msg_len,
  103. unsigned int token_seqid);
  104. void (*token_send) (
  105. struct totemrrp_instance *instance,
  106. struct totem_ip_address *system_to,
  107. struct iovec *iovec,
  108. unsigned int iov_len);
  109. void (*recv_flush) (
  110. struct totemrrp_instance *instance);
  111. void (*send_flush) (
  112. struct totemrrp_instance *instance);
  113. void (*iface_check) (
  114. struct totemrrp_instance *instance);
  115. void (*processor_count_set) (
  116. struct totemrrp_instance *instance,
  117. unsigned int processor_count);
  118. };
  119. struct totemrrp_instance {
  120. poll_handle totemrrp_poll_handle;
  121. struct totem_interface *totemrrp_interfaces;
  122. struct rrp_algo *rrp_algo;
  123. void *context;
  124. void (*totemrrp_deliver_fn) (
  125. void *context,
  126. struct totem_ip_address *system_from,
  127. void *msg,
  128. int msg_len);
  129. void (*totemrrp_iface_change_fn) (
  130. void *context,
  131. struct totem_ip_address *iface_addr);
  132. void (*totemrrp_token_seqid_get) (
  133. void *msg,
  134. unsigned int *seqid,
  135. unsigned int *token_is);
  136. /*
  137. * Function and data used to log messages
  138. */
  139. int totemrrp_log_level_security;
  140. int totemrrp_log_level_error;
  141. int totemrrp_log_level_warning;
  142. int totemrrp_log_level_notice;
  143. int totemrrp_log_level_debug;
  144. void (*totemrrp_log_printf) (int level, char *format, ...);
  145. totemrrp_handle handle;
  146. totemnet_handle *net_handles;
  147. void *rrp_algo_instance;
  148. int interface_count;
  149. int poll_handle;
  150. int processor_count;
  151. };
  152. static void passive_mcast_recv (
  153. struct totemrrp_instance *instance,
  154. void *context,
  155. struct totem_ip_address *system_from,
  156. void *msg,
  157. unsigned int msg_len);
  158. static void passive_mcast_noflush_send (
  159. struct totemrrp_instance *instance,
  160. struct iovec *iovec,
  161. unsigned int iov_len);
  162. static void passive_mcast_flush_send (
  163. struct totemrrp_instance *instance,
  164. struct iovec *iovec,
  165. unsigned int iov_len);
  166. static void passive_token_recv (
  167. struct totemrrp_instance *instance,
  168. unsigned int interface_no,
  169. struct totem_ip_address *system_from,
  170. void *msg,
  171. unsigned int msg_len,
  172. unsigned int token_seqid);
  173. static void passive_token_send (
  174. struct totemrrp_instance *instance,
  175. struct totem_ip_address *system_to,
  176. struct iovec *iovec,
  177. unsigned int iov_len);
  178. static void active_mcast_recv (
  179. struct totemrrp_instance *instance,
  180. void *context,
  181. struct totem_ip_address *system_from,
  182. void *msg,
  183. unsigned int msg_len);
  184. static void active_mcast_noflush_send (
  185. struct totemrrp_instance *instance,
  186. struct iovec *iovec,
  187. unsigned int iov_len);
  188. static void active_mcast_flush_send (
  189. struct totemrrp_instance *instance,
  190. struct iovec *iovec,
  191. unsigned int iov_len);
  192. static void active_token_recv (
  193. struct totemrrp_instance *instance,
  194. unsigned int interface_no,
  195. void *context,
  196. struct totem_ip_address *system_from,
  197. void *msg,
  198. unsigned int msg_len,
  199. unsigned int token_seqid);
  200. static void active_token_send (
  201. struct totemrrp_instance *instance,
  202. struct totem_ip_address *system_to,
  203. struct iovec *iovec,
  204. unsigned int iov_len);
  205. static void active_recv_flush (
  206. struct totemrrp_instance *instance);
  207. static void active_send_flush (
  208. struct totemrrp_instance *instance);
  209. static void active_iface_check (
  210. struct totemrrp_instance *instance);
  211. static void active_processor_count_set (
  212. struct totemrrp_instance *instance,
  213. unsigned int processor_count_set);
  214. /*
  215. struct rrp_algo passive_algo = {
  216. .mcast_recv = passive_mcast_recv,
  217. .mcast_noflush_send = passive_mcast_noflush_send,
  218. .mcast_flush_send = passive_mcast_flush_send,
  219. .token_recv = passive_token_recv,
  220. .token_send = passive_token_send
  221. };
  222. */
  223. struct rrp_algo active_algo = {
  224. .mcast_recv = active_mcast_recv,
  225. .mcast_noflush_send = active_mcast_noflush_send,
  226. .mcast_flush_send = active_mcast_flush_send,
  227. .token_recv = active_token_recv,
  228. .token_send = active_token_send,
  229. .recv_flush = active_recv_flush,
  230. .send_flush = active_recv_flush,
  231. .iface_check = active_iface_check,
  232. .processor_count_set = active_processor_count_set,
  233. };
  234. /*
  235. * All instances in one database
  236. */
  237. static struct hdb_handle_database totemrrp_instance_database = {
  238. .handle_count = 0,
  239. .handles = 0,
  240. .iterator = 0
  241. };
  242. struct passive_instance *passive_instance_initialize (
  243. int interface_count)
  244. {
  245. struct passive_instance *instance;
  246. int i;
  247. instance = malloc (sizeof (struct passive_instance));
  248. if (instance == 0) {
  249. goto error_exit;
  250. }
  251. instance->faulty = malloc (sizeof (int) * interface_count);
  252. if (instance->faulty == 0) {
  253. free (instance);
  254. instance = 0;
  255. goto error_exit;
  256. }
  257. instance->last_seq = malloc (sizeof (int) * interface_count);
  258. if (instance->last_seq == 0) {
  259. free (instance->faulty);
  260. free (instance);
  261. instance = 0;
  262. goto error_exit;
  263. }
  264. instance->counter_problems = malloc (sizeof (int) * interface_count);
  265. if (instance->counter_problems == 0) {
  266. free (instance->last_seq);
  267. free (instance->faulty);
  268. free (instance);
  269. instance = 0;
  270. goto error_exit;
  271. }
  272. for (i = 0; i < interface_count; i++) {
  273. instance->faulty[i] = 0;
  274. instance->last_seq[i] = 0;
  275. instance->counter_problems[i] = 0;
  276. }
  277. error_exit:
  278. return (instance);
  279. }
  280. struct active_instance *active_instance_initialize (
  281. struct totemrrp_instance *rrp_instance,
  282. int interface_count)
  283. {
  284. struct active_instance *instance;
  285. int i;
  286. instance = malloc (sizeof (struct active_instance));
  287. if (instance == 0) {
  288. goto error_exit;
  289. }
  290. instance->faulty = malloc (sizeof (int) * interface_count);
  291. if (instance->faulty == 0) {
  292. free (instance);
  293. instance = 0;
  294. goto error_exit;
  295. }
  296. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  297. if (instance->last_token_recv == 0) {
  298. free (instance->faulty);
  299. free (instance);
  300. instance = 0;
  301. goto error_exit;
  302. }
  303. instance->counter_problems = malloc (sizeof (int) * interface_count);
  304. if (instance->counter_problems == 0) {
  305. free (instance->last_token_recv);
  306. free (instance->faulty);
  307. free (instance);
  308. instance = 0;
  309. goto error_exit;
  310. }
  311. instance->faulty = malloc (sizeof (int) * interface_count);
  312. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  313. instance->counter_problems = malloc (sizeof (int) * interface_count);
  314. for (i = 0; i < interface_count; i++) {
  315. instance->faulty[i] = 0;
  316. instance->last_token_recv[i] = 0;
  317. instance->counter_problems[i] = 0;
  318. }
  319. instance->timer_active_token = 0;
  320. instance->rrp_instance = rrp_instance;
  321. error_exit:
  322. return (instance);
  323. }
  324. static void timer_function_active_token (void *context)
  325. {
  326. // struct active_instance *instance = (struct active_instance *)context;
  327. }
  328. static void active_token_timer_start (struct active_instance *active_instance)
  329. {
  330. poll_timer_add (
  331. active_instance->rrp_instance->poll_handle,
  332. 10, /* 10 msec */
  333. (void *)active_instance,
  334. timer_function_active_token,
  335. &active_instance->timer_active_token);
  336. }
  337. static void active_token_timer_cancel (struct active_instance *active_instance)
  338. {
  339. poll_timer_delete (
  340. active_instance->rrp_instance->poll_handle,
  341. active_instance->timer_active_token);
  342. }
  343. static void active_mcast_recv (
  344. struct totemrrp_instance *instance,
  345. void *context,
  346. struct totem_ip_address *system_from,
  347. void *msg,
  348. unsigned int msg_len)
  349. {
  350. instance->totemrrp_deliver_fn (
  351. context,
  352. system_from,
  353. msg,
  354. msg_len);
  355. }
  356. static void active_mcast_flush_send (
  357. struct totemrrp_instance *instance,
  358. struct iovec *iovec,
  359. unsigned int iov_len)
  360. {
  361. int i;
  362. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  363. for (i = 0; i < instance->interface_count; i++) {
  364. if (rrp_algo_instance->faulty[i] == 0) {
  365. totemnet_mcast_flush_send (instance->net_handles[i], iovec, iov_len);
  366. }
  367. }
  368. }
  369. static void active_mcast_noflush_send (
  370. struct totemrrp_instance *instance,
  371. struct iovec *iovec,
  372. unsigned int iov_len)
  373. {
  374. int i;
  375. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  376. for (i = 0; i < instance->interface_count; i++) {
  377. if (rrp_algo_instance->faulty[i] == 0) {
  378. totemnet_mcast_noflush_send (instance->net_handles[i], iovec, iov_len);
  379. }
  380. }
  381. }
  382. static void active_token_recv (
  383. struct totemrrp_instance *instance,
  384. unsigned int interface_no,
  385. void *context,
  386. struct totem_ip_address *system_from,
  387. void *msg,
  388. unsigned int msg_len,
  389. unsigned int token_seqid)
  390. {
  391. unsigned int cur_token_seq;
  392. unsigned int last_token_seq;
  393. unsigned int token_is;
  394. int i;
  395. struct active_instance *active_instance = (struct active_instance *)instance->rrp_algo_instance;
  396. instance->totemrrp_token_seqid_get (
  397. msg,
  398. &cur_token_seq,
  399. &token_is);
  400. assert (token_is);
  401. if (token_seqid > cur_token_seq) {
  402. memcpy (active_instance->token, msg, msg_len);
  403. active_instance->token_len = msg_len;
  404. for (i = 0; i < instance->interface_count; i++) {
  405. active_instance->last_token_recv[i] = 0;
  406. }
  407. active_instance->last_token_recv[interface_no] = 1;
  408. active_token_timer_start (active_instance);
  409. }
  410. instance->totemrrp_token_seqid_get (
  411. msg,
  412. &last_token_seq,
  413. &token_is);
  414. assert (token_is);
  415. if (cur_token_seq == last_token_seq) {
  416. active_instance->last_token_recv[interface_no] = 1;
  417. for (i = 0; i < instance->interface_count; i++) {
  418. if ((active_instance->last_token_recv[i] == 0) &&
  419. active_instance->faulty[i] == 0) {
  420. return; /* don't deliver token */
  421. }
  422. }
  423. active_token_timer_cancel (active_instance);
  424. instance->totemrrp_deliver_fn (
  425. context,
  426. system_from,
  427. msg,
  428. msg_len);
  429. }
  430. }
  431. static void active_token_send (
  432. struct totemrrp_instance *instance,
  433. struct totem_ip_address *system_to,
  434. struct iovec *iovec,
  435. unsigned int iov_len)
  436. {
  437. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  438. int i;
  439. for (i = 0; i < instance->interface_count; i++) {
  440. if (rrp_algo_instance->faulty[i] == 0) {
  441. totemnet_token_send (
  442. instance->net_handles[i], system_to,
  443. iovec, iov_len);
  444. }
  445. }
  446. }
  447. static void active_recv_flush (struct totemrrp_instance *instance)
  448. {
  449. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  450. unsigned int i;
  451. for (i = 0; i < instance->interface_count; i++) {
  452. if (rrp_algo_instance->faulty[i] == 0) {
  453. totemnet_recv_flush (instance->net_handles[i]);
  454. }
  455. }
  456. }
  457. static void active_send_flush (struct totemrrp_instance *instance)
  458. {
  459. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  460. unsigned int i;
  461. for (i = 0; i < instance->interface_count; i++) {
  462. if (rrp_algo_instance->faulty[i] == 0) {
  463. totemnet_send_flush (instance->net_handles[i]);
  464. }
  465. }
  466. }
  467. static void active_iface_check (struct totemrrp_instance *instance)
  468. {
  469. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  470. unsigned int i;
  471. for (i = 0; i < instance->interface_count; i++) {
  472. if (rrp_algo_instance->faulty[i] == 0) {
  473. totemnet_iface_check (instance->net_handles[i]);
  474. }
  475. }
  476. }
  477. static void active_processor_count_set (
  478. struct totemrrp_instance *instance,
  479. unsigned int processor_count)
  480. {
  481. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  482. unsigned int i;
  483. for (i = 0; i < instance->interface_count; i++) {
  484. if (rrp_algo_instance->faulty[i] == 0) {
  485. totemnet_processor_count_set (instance->net_handles[i],
  486. processor_count);
  487. }
  488. }
  489. }
  490. struct deliver_fn_context {
  491. struct totemrrp_instance *instance;
  492. void *context;
  493. int interface_no;
  494. };
  495. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  496. {
  497. memset (instance, 0, sizeof (struct totemrrp_instance));
  498. instance->rrp_algo = &active_algo;
  499. }
  500. void rrp_deliver_fn (
  501. void *context,
  502. struct totem_ip_address *system_from,
  503. void *msg,
  504. int msg_len)
  505. {
  506. unsigned int token_seqid;
  507. unsigned int token_is;
  508. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  509. deliver_fn_context->instance->totemrrp_token_seqid_get (
  510. msg,
  511. &token_seqid,
  512. &token_is);
  513. if (token_is) {
  514. /*
  515. * Deliver to the token receiver for this rrp algorithm
  516. */
  517. deliver_fn_context->instance->rrp_algo->token_recv (
  518. deliver_fn_context->instance,
  519. deliver_fn_context->interface_no,
  520. deliver_fn_context->context,
  521. system_from,
  522. msg,
  523. msg_len,
  524. token_seqid);
  525. } else {
  526. /*
  527. * Deliver to the mcast receiver for this rrp algorithm
  528. */
  529. deliver_fn_context->instance->rrp_algo->mcast_recv (
  530. deliver_fn_context->instance,
  531. deliver_fn_context->context,
  532. system_from,
  533. msg,
  534. msg_len);
  535. }
  536. }
  537. void rrp_iface_change_fn (
  538. void *context,
  539. struct totem_ip_address *iface_addr)
  540. {
  541. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  542. deliver_fn_context->instance->totemrrp_iface_change_fn (
  543. deliver_fn_context->context,
  544. iface_addr);
  545. }
  546. int totemrrp_finalize (
  547. totemrrp_handle handle)
  548. {
  549. struct totemrrp_instance *instance;
  550. int res = 0;
  551. int i;
  552. res = hdb_handle_get (&totemrrp_instance_database, handle,
  553. (void *)&instance);
  554. if (res != 0) {
  555. res = ENOENT;
  556. goto error_exit;
  557. }
  558. for (i = 0; i < instance->interface_count; i++) {
  559. totemnet_finalize (instance->net_handles[i]);
  560. }
  561. hdb_handle_put (&totemrrp_instance_database, handle);
  562. error_exit:
  563. return (res);
  564. }
  565. /*
  566. * Totem Redundant Ring interface
  567. * depends on poll abstraction, POSIX, IPV4
  568. */
  569. /*
  570. * Create an instance
  571. */
  572. int totemrrp_initialize (
  573. poll_handle poll_handle,
  574. totemrrp_handle *handle,
  575. struct totem_config *totem_config,
  576. void *context,
  577. void (*deliver_fn) (
  578. void *context,
  579. struct totem_ip_address *system_from,
  580. void *msg,
  581. int msg_len),
  582. void (*iface_change_fn) (
  583. void *context,
  584. struct totem_ip_address *iface_addr),
  585. void (*token_seqid_get) (
  586. void *msg,
  587. unsigned int *seqid,
  588. unsigned int *token_is))
  589. {
  590. struct totemrrp_instance *instance;
  591. unsigned int res;
  592. int i;
  593. res = hdb_handle_create (&totemrrp_instance_database,
  594. sizeof (struct totemrrp_instance), handle);
  595. if (res != 0) {
  596. goto error_exit;
  597. }
  598. res = hdb_handle_get (&totemrrp_instance_database, *handle,
  599. (void *)&instance);
  600. if (res != 0) {
  601. goto error_destroy;
  602. }
  603. totemrrp_instance_initialize (instance);
  604. /*
  605. * Configure logging
  606. */
  607. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  608. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  609. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  610. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  611. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  612. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  613. instance->totemrrp_interfaces = totem_config->interfaces;
  614. instance->totemrrp_poll_handle = poll_handle;
  615. instance->totemrrp_deliver_fn = deliver_fn;
  616. instance->totemrrp_iface_change_fn = iface_change_fn;
  617. instance->totemrrp_token_seqid_get = token_seqid_get;
  618. instance->interface_count = totem_config->interface_count;
  619. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  620. instance->context = context;
  621. instance->poll_handle = poll_handle;
  622. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  623. assert (instance->rrp_algo_instance);
  624. instance->rrp_algo_instance = active_instance_initialize (
  625. instance,
  626. totem_config->interface_count);
  627. for (i = 0; i < totem_config->interface_count; i++) {
  628. struct deliver_fn_context *deliver_fn_context;
  629. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  630. assert (deliver_fn_context);
  631. deliver_fn_context->instance = instance;
  632. deliver_fn_context->context = context;
  633. deliver_fn_context->interface_no = i;
  634. totemnet_initialize (
  635. poll_handle,
  636. &instance->net_handles[i],
  637. totem_config,
  638. i,
  639. (void *)deliver_fn_context,
  640. rrp_deliver_fn,
  641. rrp_iface_change_fn);
  642. }
  643. totemnet_net_mtu_adjust (totem_config);
  644. error_exit:
  645. hdb_handle_put (&totemrrp_instance_database, *handle);
  646. return (0);
  647. error_destroy:
  648. hdb_handle_destroy (&totemrrp_instance_database, *handle);
  649. return (-1);
  650. }
  651. int totemrrp_processor_count_set (
  652. totemrrp_handle handle,
  653. unsigned int processor_count)
  654. {
  655. struct totemrrp_instance *instance;
  656. int res = 0;
  657. res = hdb_handle_get (&totemrrp_instance_database, handle,
  658. (void *)&instance);
  659. if (res != 0) {
  660. res = ENOENT;
  661. goto error_exit;
  662. }
  663. instance->rrp_algo->processor_count_set (instance, processor_count);
  664. instance->processor_count = processor_count;
  665. hdb_handle_put (&totemrrp_instance_database, handle);
  666. error_exit:
  667. return (res);
  668. }
  669. int totemrrp_recv_flush (totemrrp_handle handle)
  670. {
  671. struct totemrrp_instance *instance;
  672. int res = 0;
  673. res = hdb_handle_get (&totemrrp_instance_database, handle,
  674. (void *)&instance);
  675. if (res != 0) {
  676. res = ENOENT;
  677. goto error_exit;
  678. }
  679. instance->rrp_algo->recv_flush (instance);
  680. hdb_handle_put (&totemrrp_instance_database, handle);
  681. error_exit:
  682. return (res);
  683. }
  684. int totemrrp_send_flush (totemrrp_handle handle)
  685. {
  686. struct totemrrp_instance *instance;
  687. int res = 0;
  688. res = hdb_handle_get (&totemrrp_instance_database, handle,
  689. (void *)&instance);
  690. if (res != 0) {
  691. res = ENOENT;
  692. goto error_exit;
  693. }
  694. instance->rrp_algo->send_flush (instance);
  695. hdb_handle_put (&totemrrp_instance_database, handle);
  696. error_exit:
  697. return (res);
  698. }
  699. int totemrrp_token_send (
  700. totemrrp_handle handle,
  701. struct totem_ip_address *system_to,
  702. struct iovec *iovec,
  703. unsigned int iov_len)
  704. {
  705. struct totemrrp_instance *instance;
  706. int res = 0;
  707. res = hdb_handle_get (&totemrrp_instance_database, handle,
  708. (void *)&instance);
  709. if (res != 0) {
  710. res = ENOENT;
  711. goto error_exit;
  712. }
  713. instance->rrp_algo->token_send (instance, system_to, iovec, iov_len);
  714. hdb_handle_put (&totemrrp_instance_database, handle);
  715. error_exit:
  716. return (res);
  717. }
  718. int totemrrp_mcast_flush_send (
  719. totemrrp_handle handle,
  720. struct iovec *iovec,
  721. unsigned int iov_len)
  722. {
  723. struct totemrrp_instance *instance;
  724. int res = 0;
  725. res = hdb_handle_get (&totemrrp_instance_database, handle,
  726. (void *)&instance);
  727. if (res != 0) {
  728. res = ENOENT;
  729. goto error_exit;
  730. }
  731. // TODO this needs to return the result
  732. instance->rrp_algo->mcast_flush_send (instance, iovec, iov_len);
  733. hdb_handle_put (&totemrrp_instance_database, handle);
  734. error_exit:
  735. return (res);
  736. }
  737. int totemrrp_mcast_noflush_send (
  738. totemrrp_handle handle,
  739. struct iovec *iovec,
  740. unsigned int iov_len)
  741. {
  742. struct totemrrp_instance *instance;
  743. int res = 0;
  744. res = hdb_handle_get (&totemrrp_instance_database, handle,
  745. (void *)&instance);
  746. if (res != 0) {
  747. res = ENOENT;
  748. goto error_exit;
  749. }
  750. /*
  751. * merge detects go out through mcast_flush_send so it is safe to
  752. * flush these messages if we are only one processor. This avoids
  753. * an encryption/hmac and decryption/hmac
  754. */
  755. if (instance->processor_count > 1) {
  756. // TODO this needs to return the result
  757. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  758. }
  759. hdb_handle_put (&totemrrp_instance_database, handle);
  760. error_exit:
  761. return (res);
  762. }
  763. int totemrrp_iface_check (totemrrp_handle handle)
  764. {
  765. struct totemrrp_instance *instance;
  766. int res = 0;
  767. res = hdb_handle_get (&totemrrp_instance_database, handle,
  768. (void *)&instance);
  769. if (res != 0) {
  770. res = ENOENT;
  771. goto error_exit;
  772. }
  773. instance->rrp_algo->iface_check (instance);
  774. hdb_handle_put (&totemrrp_instance_database, handle);
  775. error_exit:
  776. return (res);
  777. }