totemrrp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. };
  110. struct totemrrp_instance {
  111. poll_handle totemrrp_poll_handle;
  112. struct totem_interface *totemrrp_interfaces;
  113. struct rrp_algo *rrp_algo;
  114. void *context;
  115. void (*totemrrp_deliver_fn) (
  116. void *context,
  117. struct totem_ip_address *system_from,
  118. void *msg,
  119. int msg_len);
  120. void (*totemrrp_iface_change_fn) (
  121. void *context,
  122. struct totem_ip_address *iface_addr);
  123. void (*totemrrp_token_seqid_get) (
  124. void *msg,
  125. unsigned int *seqid,
  126. unsigned int *token_is);
  127. /*
  128. * Function and data used to log messages
  129. */
  130. int totemrrp_log_level_security;
  131. int totemrrp_log_level_error;
  132. int totemrrp_log_level_warning;
  133. int totemrrp_log_level_notice;
  134. int totemrrp_log_level_debug;
  135. void (*totemrrp_log_printf) (int level, char *format, ...);
  136. totemrrp_handle handle;
  137. totemnet_handle *net_handles;
  138. totemnet_handle net_handle;
  139. void *rrp_algo_instance;
  140. int interface_count;
  141. int poll_handle;
  142. int processor_count;
  143. };
  144. void passive_mcast_recv (
  145. struct totemrrp_instance *instance,
  146. void *context,
  147. struct totem_ip_address *system_from,
  148. void *msg,
  149. unsigned int msg_len);
  150. void passive_mcast_noflush_send (
  151. struct totemrrp_instance *instance,
  152. struct iovec *iovec,
  153. unsigned int iov_len);
  154. void passive_mcast_flush_send (
  155. struct totemrrp_instance *instance,
  156. struct iovec *iovec,
  157. unsigned int iov_len);
  158. void passive_token_recv (
  159. struct totemrrp_instance *instance,
  160. unsigned int interface_no,
  161. struct totem_ip_address *system_from,
  162. void *msg,
  163. unsigned int msg_len,
  164. unsigned int token_seqid);
  165. void passive_token_send (
  166. struct totemrrp_instance *instance,
  167. struct totem_ip_address *system_to,
  168. struct iovec *iovec,
  169. unsigned int iov_len);
  170. void active_mcast_recv (
  171. struct totemrrp_instance *instance,
  172. void *context,
  173. struct totem_ip_address *system_from,
  174. void *msg,
  175. unsigned int msg_len);
  176. void active_mcast_noflush_send (
  177. struct totemrrp_instance *instance,
  178. struct iovec *iovec,
  179. unsigned int iov_len);
  180. void active_mcast_flush_send (
  181. struct totemrrp_instance *instance,
  182. struct iovec *iovec,
  183. unsigned int iov_len);
  184. void active_token_recv (
  185. struct totemrrp_instance *instance,
  186. unsigned int interface_no,
  187. void *context,
  188. struct totem_ip_address *system_from,
  189. void *msg,
  190. unsigned int msg_len,
  191. unsigned int token_seqid);
  192. void active_token_send (
  193. struct totemrrp_instance *instance,
  194. struct totem_ip_address *system_to,
  195. struct iovec *iovec,
  196. unsigned int iov_len);
  197. /*
  198. struct rrp_algo passive_algo = {
  199. .mcast_recv = passive_mcast_recv,
  200. .mcast_noflush_send = passive_mcast_noflush_send,
  201. .mcast_flush_send = passive_mcast_flush_send,
  202. .token_recv = passive_token_recv,
  203. .token_send = passive_token_send
  204. };
  205. */
  206. struct rrp_algo active_algo = {
  207. .mcast_recv = active_mcast_recv,
  208. .mcast_noflush_send = active_mcast_noflush_send,
  209. .mcast_flush_send = active_mcast_flush_send,
  210. .token_recv = active_token_recv,
  211. .token_send = active_token_send
  212. };
  213. /*
  214. * All instances in one database
  215. */
  216. static struct hdb_handle_database totemrrp_instance_database = {
  217. .handle_count = 0,
  218. .handles = 0,
  219. .iterator = 0
  220. };
  221. struct passive_instance *passive_instance_initialize (
  222. int interface_count)
  223. {
  224. struct passive_instance *instance;
  225. int i;
  226. instance = malloc (sizeof (struct passive_instance));
  227. if (instance == 0) {
  228. goto error_exit;
  229. }
  230. instance->faulty = malloc (sizeof (int) * interface_count);
  231. if (instance->faulty == 0) {
  232. free (instance);
  233. instance = 0;
  234. goto error_exit;
  235. }
  236. instance->last_seq = malloc (sizeof (int) * interface_count);
  237. if (instance->last_seq == 0) {
  238. free (instance->faulty);
  239. free (instance);
  240. instance = 0;
  241. goto error_exit;
  242. }
  243. instance->counter_problems = malloc (sizeof (int) * interface_count);
  244. if (instance->counter_problems == 0) {
  245. free (instance->last_seq);
  246. free (instance->faulty);
  247. free (instance);
  248. instance = 0;
  249. goto error_exit;
  250. }
  251. for (i = 0; i < interface_count; i++) {
  252. instance->faulty[i] = 0;
  253. instance->last_seq[i] = 0;
  254. instance->counter_problems[i] = 0;
  255. }
  256. error_exit:
  257. return (instance);
  258. }
  259. struct active_instance *active_instance_initialize (
  260. struct totemrrp_instance *rrp_instance,
  261. int interface_count)
  262. {
  263. struct active_instance *instance;
  264. int i;
  265. instance = malloc (sizeof (struct active_instance));
  266. if (instance == 0) {
  267. goto error_exit;
  268. }
  269. instance->faulty = malloc (sizeof (int) * interface_count);
  270. if (instance->faulty == 0) {
  271. free (instance);
  272. instance = 0;
  273. goto error_exit;
  274. }
  275. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  276. if (instance->last_token_recv == 0) {
  277. free (instance->faulty);
  278. free (instance);
  279. instance = 0;
  280. goto error_exit;
  281. }
  282. instance->counter_problems = malloc (sizeof (int) * interface_count);
  283. if (instance->counter_problems == 0) {
  284. free (instance->last_token_recv);
  285. free (instance->faulty);
  286. free (instance);
  287. instance = 0;
  288. goto error_exit;
  289. }
  290. instance->faulty = malloc (sizeof (int) * interface_count);
  291. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  292. instance->counter_problems = malloc (sizeof (int) * interface_count);
  293. for (i = 0; i < interface_count; i++) {
  294. instance->faulty[i] = 0;
  295. instance->last_token_recv[i] = 0;
  296. instance->counter_problems[i] = 0;
  297. }
  298. instance->timer_active_token = 0;
  299. instance->rrp_instance = rrp_instance;
  300. error_exit:
  301. return (instance);
  302. }
  303. static void timer_function_active_token (void *context)
  304. {
  305. // struct active_instance *instance = (struct active_instance *)context;
  306. }
  307. void active_token_timer_start (struct active_instance *active_instance)
  308. {
  309. poll_timer_add (
  310. active_instance->rrp_instance->poll_handle,
  311. 10, /* 10 msec */
  312. (void *)active_instance,
  313. timer_function_active_token,
  314. &active_instance->timer_active_token);
  315. }
  316. void active_token_timer_cancel (struct active_instance *active_instance)
  317. {
  318. poll_timer_delete (
  319. active_instance->rrp_instance->poll_handle,
  320. active_instance->timer_active_token);
  321. }
  322. void active_mcast_recv (
  323. struct totemrrp_instance *instance,
  324. void *context,
  325. struct totem_ip_address *system_from,
  326. void *msg,
  327. unsigned int msg_len)
  328. {
  329. instance->totemrrp_deliver_fn (
  330. context,
  331. system_from,
  332. msg,
  333. msg_len);
  334. }
  335. void active_mcast_flush_send (
  336. struct totemrrp_instance *instance,
  337. struct iovec *iovec,
  338. unsigned int iov_len)
  339. {
  340. int i;
  341. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  342. for (i = 0; i < instance->interface_count; i++) {
  343. if (rrp_algo_instance->faulty[i] == 0) {
  344. totemnet_mcast_flush_send (instance->net_handle, iovec, iov_len);
  345. }
  346. }
  347. }
  348. void active_mcast_noflush_send (
  349. struct totemrrp_instance *instance,
  350. struct iovec *iovec,
  351. unsigned int iov_len)
  352. {
  353. int i;
  354. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  355. for (i = 0; i < instance->interface_count; i++) {
  356. if (rrp_algo_instance->faulty[i] == 0) {
  357. totemnet_mcast_noflush_send (instance->net_handle, iovec, iov_len);
  358. }
  359. }
  360. }
  361. void active_token_recv (
  362. struct totemrrp_instance *instance,
  363. unsigned int interface_no,
  364. void *context,
  365. struct totem_ip_address *system_from,
  366. void *msg,
  367. unsigned int msg_len,
  368. unsigned int token_seqid)
  369. {
  370. unsigned int cur_token_seq;
  371. unsigned int last_token_seq;
  372. unsigned int token_is;
  373. int i;
  374. struct active_instance *active_instance = (struct active_instance *)instance->rrp_algo_instance;
  375. instance->totemrrp_token_seqid_get (
  376. msg,
  377. &cur_token_seq,
  378. &token_is);
  379. assert (token_is);
  380. if (token_seqid > cur_token_seq) {
  381. memcpy (active_instance->token, msg, msg_len);
  382. active_instance->token_len = msg_len;
  383. for (i = 0; i < instance->interface_count; i++) {
  384. active_instance->last_token_recv[i] = 0;
  385. }
  386. active_instance->last_token_recv[interface_no] = 1;
  387. active_token_timer_start (active_instance);
  388. }
  389. instance->totemrrp_token_seqid_get (
  390. msg,
  391. &last_token_seq,
  392. &token_is);
  393. assert (token_is);
  394. if (cur_token_seq == last_token_seq) {
  395. active_instance->last_token_recv[interface_no] = 1;
  396. for (i = 0; i < instance->interface_count; i++) {
  397. if ((active_instance->last_token_recv[i] == 0) &&
  398. active_instance->faulty[i] == 0) {
  399. return; /* don't deliver token */
  400. }
  401. }
  402. active_token_timer_cancel (active_instance);
  403. instance->totemrrp_deliver_fn (
  404. context,
  405. system_from,
  406. msg,
  407. msg_len);
  408. }
  409. }
  410. void active_token_send (
  411. struct totemrrp_instance *instance,
  412. struct totem_ip_address *system_to,
  413. struct iovec *iovec,
  414. unsigned int iov_len)
  415. {
  416. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  417. int i;
  418. for (i = 0; i < instance->interface_count; i++) {
  419. if (rrp_algo_instance->faulty[i] == 0) {
  420. totemnet_token_send (
  421. instance->net_handle, system_to,
  422. iovec, iov_len);
  423. }
  424. }
  425. }
  426. struct deliver_fn_context {
  427. struct totemrrp_instance *instance;
  428. void *context;
  429. int interface_no;
  430. };
  431. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  432. {
  433. memset (instance, 0, sizeof (struct totemrrp_instance));
  434. instance->rrp_algo = &active_algo;
  435. }
  436. void rrp_deliver_fn (
  437. void *context,
  438. struct totem_ip_address *system_from,
  439. void *msg,
  440. int msg_len)
  441. {
  442. unsigned int token_seqid;
  443. unsigned int token_is;
  444. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  445. deliver_fn_context->instance->totemrrp_token_seqid_get (
  446. msg,
  447. &token_seqid,
  448. &token_is);
  449. if (token_is) {
  450. /*
  451. * Deliver to the token receiver for this rrp algorithm
  452. */
  453. deliver_fn_context->instance->rrp_algo->token_recv (
  454. deliver_fn_context->instance,
  455. deliver_fn_context->interface_no,
  456. deliver_fn_context->context,
  457. system_from,
  458. msg,
  459. msg_len,
  460. token_seqid);
  461. } else {
  462. /*
  463. * Deliver to the mcast receiver for this rrp algorithm
  464. */
  465. deliver_fn_context->instance->rrp_algo->mcast_recv (
  466. deliver_fn_context->instance,
  467. deliver_fn_context->context,
  468. system_from,
  469. msg,
  470. msg_len);
  471. }
  472. }
  473. void rrp_iface_change_fn (
  474. void *context,
  475. struct totem_ip_address *iface_addr)
  476. {
  477. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  478. deliver_fn_context->instance->totemrrp_iface_change_fn (
  479. deliver_fn_context->context,
  480. iface_addr);
  481. }
  482. int totemrrp_finalize (
  483. totemrrp_handle handle)
  484. {
  485. struct totemrrp_instance *instance;
  486. int res = 0;
  487. res = hdb_handle_get (&totemrrp_instance_database, handle,
  488. (void *)&instance);
  489. if (res != 0) {
  490. res = ENOENT;
  491. goto error_exit;
  492. }
  493. totemnet_finalize (instance->net_handle);
  494. hdb_handle_put (&totemrrp_instance_database, handle);
  495. error_exit:
  496. return (res);
  497. }
  498. /*
  499. * Totem Redundant Ring interface
  500. * depends on poll abstraction, POSIX, IPV4
  501. */
  502. /*
  503. * Create an instance
  504. */
  505. int totemrrp_initialize (
  506. poll_handle poll_handle,
  507. totemrrp_handle *handle,
  508. struct totem_config *totem_config,
  509. void *context,
  510. void (*deliver_fn) (
  511. void *context,
  512. struct totem_ip_address *system_from,
  513. void *msg,
  514. int msg_len),
  515. void (*iface_change_fn) (
  516. void *context,
  517. struct totem_ip_address *iface_addr),
  518. void (*token_seqid_get) (
  519. void *msg,
  520. unsigned int *seqid,
  521. unsigned int *token_is))
  522. {
  523. struct totemrrp_instance *instance;
  524. unsigned int res;
  525. int i;
  526. res = hdb_handle_create (&totemrrp_instance_database,
  527. sizeof (struct totemrrp_instance), handle);
  528. if (res != 0) {
  529. goto error_exit;
  530. }
  531. res = hdb_handle_get (&totemrrp_instance_database, *handle,
  532. (void *)&instance);
  533. if (res != 0) {
  534. goto error_destroy;
  535. }
  536. totemrrp_instance_initialize (instance);
  537. /*
  538. * Configure logging
  539. */
  540. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  541. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  542. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  543. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  544. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  545. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  546. instance->totemrrp_interfaces = totem_config->interfaces;
  547. instance->totemrrp_poll_handle = poll_handle;
  548. instance->totemrrp_deliver_fn = deliver_fn;
  549. instance->totemrrp_iface_change_fn = iface_change_fn;
  550. instance->totemrrp_token_seqid_get = token_seqid_get;
  551. instance->interface_count = totem_config->interface_count;
  552. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  553. instance->context = context;
  554. instance->poll_handle = poll_handle;
  555. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  556. assert (instance->rrp_algo_instance);
  557. instance->rrp_algo_instance = active_instance_initialize (
  558. instance,
  559. totem_config->interface_count);
  560. for (i = 0; i < totem_config->interface_count; i++) {
  561. struct deliver_fn_context *deliver_fn_context;
  562. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  563. assert (deliver_fn_context);
  564. deliver_fn_context->instance = instance;
  565. deliver_fn_context->context = context;
  566. deliver_fn_context->interface_no = i;
  567. totemnet_initialize (
  568. poll_handle,
  569. &instance->net_handles[i],
  570. totem_config,
  571. i,
  572. (void *)deliver_fn_context,
  573. rrp_deliver_fn,
  574. rrp_iface_change_fn);
  575. }
  576. instance->net_handle = instance->net_handles[0];
  577. totemnet_net_mtu_adjust (totem_config);
  578. error_exit:
  579. hdb_handle_put (&totemrrp_instance_database, *handle);
  580. return (0);
  581. error_destroy:
  582. hdb_handle_destroy (&totemrrp_instance_database, *handle);
  583. return (-1);
  584. }
  585. int totemrrp_processor_count_set (
  586. totemrrp_handle handle,
  587. unsigned int processor_count)
  588. {
  589. struct totemrrp_instance *instance;
  590. int res = 0;
  591. res = hdb_handle_get (&totemrrp_instance_database, handle,
  592. (void *)&instance);
  593. if (res != 0) {
  594. res = ENOENT;
  595. goto error_exit;
  596. }
  597. totemnet_processor_count_set (instance->net_handle, processor_count);
  598. instance->processor_count = processor_count;
  599. hdb_handle_put (&totemrrp_instance_database, handle);
  600. error_exit:
  601. return (res);
  602. }
  603. int totemrrp_recv_flush (totemrrp_handle handle)
  604. {
  605. struct totemrrp_instance *instance;
  606. int res = 0;
  607. res = hdb_handle_get (&totemrrp_instance_database, handle,
  608. (void *)&instance);
  609. if (res != 0) {
  610. res = ENOENT;
  611. goto error_exit;
  612. }
  613. totemnet_recv_flush (instance->net_handle);
  614. hdb_handle_put (&totemrrp_instance_database, handle);
  615. error_exit:
  616. return (res);
  617. }
  618. int totemrrp_send_flush (totemrrp_handle handle)
  619. {
  620. struct totemrrp_instance *instance;
  621. int res = 0;
  622. res = hdb_handle_get (&totemrrp_instance_database, handle,
  623. (void *)&instance);
  624. if (res != 0) {
  625. res = ENOENT;
  626. goto error_exit;
  627. }
  628. totemnet_send_flush (instance->net_handle);
  629. hdb_handle_put (&totemrrp_instance_database, handle);
  630. error_exit:
  631. return (res);
  632. }
  633. int totemrrp_token_send (
  634. totemrrp_handle handle,
  635. struct totem_ip_address *system_to,
  636. struct iovec *iovec,
  637. unsigned int iov_len)
  638. {
  639. struct totemrrp_instance *instance;
  640. int res = 0;
  641. res = hdb_handle_get (&totemrrp_instance_database, handle,
  642. (void *)&instance);
  643. if (res != 0) {
  644. res = ENOENT;
  645. goto error_exit;
  646. }
  647. instance->rrp_algo->token_send (instance, system_to, iovec, iov_len);
  648. hdb_handle_put (&totemrrp_instance_database, handle);
  649. error_exit:
  650. return (res);
  651. }
  652. int totemrrp_mcast_flush_send (
  653. totemrrp_handle handle,
  654. struct iovec *iovec,
  655. unsigned int iov_len)
  656. {
  657. struct totemrrp_instance *instance;
  658. int res = 0;
  659. res = hdb_handle_get (&totemrrp_instance_database, handle,
  660. (void *)&instance);
  661. if (res != 0) {
  662. res = ENOENT;
  663. goto error_exit;
  664. }
  665. // TODO this needs to return the result
  666. instance->rrp_algo->mcast_flush_send (instance, iovec, iov_len);
  667. hdb_handle_put (&totemrrp_instance_database, handle);
  668. error_exit:
  669. return (res);
  670. }
  671. int totemrrp_mcast_noflush_send (
  672. totemrrp_handle handle,
  673. struct iovec *iovec,
  674. unsigned int iov_len)
  675. {
  676. struct totemrrp_instance *instance;
  677. int res = 0;
  678. res = hdb_handle_get (&totemrrp_instance_database, handle,
  679. (void *)&instance);
  680. if (res != 0) {
  681. res = ENOENT;
  682. goto error_exit;
  683. }
  684. /*
  685. * merge detects go out through mcast_flush_send so it is safe to
  686. * flush these messages if we are only one processor. This avoids
  687. * an encryption/hmac and decryption/hmac
  688. */
  689. if (instance->processor_count > 1) {
  690. // TODO this needs to return the result
  691. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  692. }
  693. hdb_handle_put (&totemrrp_instance_database, handle);
  694. error_exit:
  695. return (res);
  696. }
  697. int totemrrp_iface_check (totemrrp_handle handle)
  698. {
  699. struct totemrrp_instance *instance;
  700. int res = 0;
  701. res = hdb_handle_get (&totemrrp_instance_database, handle,
  702. (void *)&instance);
  703. if (res != 0) {
  704. res = ENOENT;
  705. goto error_exit;
  706. }
  707. totemnet_iface_check (instance->net_handle);
  708. hdb_handle_put (&totemrrp_instance_database, handle);
  709. error_exit:
  710. return (res);
  711. }