totemrrp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. void *msg,
  95. unsigned int msg_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. void *msg,
  108. unsigned int msg_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. void *msg,
  157. unsigned int msg_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. void *msg,
  169. unsigned int msg_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. void *msg,
  183. unsigned int msg_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. void *msg,
  196. unsigned int msg_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. void *msg,
  338. unsigned int msg_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, msg, msg_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. void *msg,
  414. unsigned int msg_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,
  422. system_to,
  423. msg,
  424. msg_len);
  425. }
  426. }
  427. }
  428. struct deliver_fn_context {
  429. struct totemrrp_instance *instance;
  430. void *context;
  431. int interface_no;
  432. };
  433. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  434. {
  435. memset (instance, 0, sizeof (struct totemrrp_instance));
  436. instance->rrp_algo = &active_algo;
  437. }
  438. void rrp_deliver_fn (
  439. void *context,
  440. struct totem_ip_address *system_from,
  441. void *msg,
  442. int msg_len)
  443. {
  444. unsigned int token_seqid;
  445. unsigned int token_is;
  446. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  447. deliver_fn_context->instance->totemrrp_token_seqid_get (
  448. msg,
  449. &token_seqid,
  450. &token_is);
  451. if (token_is) {
  452. /*
  453. * Deliver to the token receiver for this rrp algorithm
  454. */
  455. deliver_fn_context->instance->rrp_algo->token_recv (
  456. deliver_fn_context->instance,
  457. deliver_fn_context->interface_no,
  458. deliver_fn_context->context,
  459. system_from,
  460. msg,
  461. msg_len,
  462. token_seqid);
  463. } else {
  464. /*
  465. * Deliver to the mcast receiver for this rrp algorithm
  466. */
  467. deliver_fn_context->instance->rrp_algo->mcast_recv (
  468. deliver_fn_context->instance,
  469. deliver_fn_context->context,
  470. system_from,
  471. msg,
  472. msg_len);
  473. }
  474. }
  475. void rrp_iface_change_fn (
  476. void *context,
  477. struct totem_ip_address *iface_addr)
  478. {
  479. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  480. deliver_fn_context->instance->totemrrp_iface_change_fn (
  481. deliver_fn_context->context,
  482. iface_addr);
  483. }
  484. int totemrrp_finalize (
  485. totemrrp_handle handle)
  486. {
  487. struct totemrrp_instance *instance;
  488. int res = 0;
  489. res = hdb_handle_get (&totemrrp_instance_database, handle,
  490. (void *)&instance);
  491. if (res != 0) {
  492. res = ENOENT;
  493. goto error_exit;
  494. }
  495. totemnet_finalize (instance->net_handle);
  496. hdb_handle_put (&totemrrp_instance_database, handle);
  497. error_exit:
  498. return (res);
  499. }
  500. /*
  501. * Totem Redundant Ring interface
  502. * depends on poll abstraction, POSIX, IPV4
  503. */
  504. /*
  505. * Create an instance
  506. */
  507. int totemrrp_initialize (
  508. poll_handle poll_handle,
  509. totemrrp_handle *handle,
  510. struct totem_config *totem_config,
  511. void *context,
  512. void (*deliver_fn) (
  513. void *context,
  514. struct totem_ip_address *system_from,
  515. void *msg,
  516. int msg_len),
  517. void (*iface_change_fn) (
  518. void *context,
  519. struct totem_ip_address *iface_addr),
  520. void (*token_seqid_get) (
  521. void *msg,
  522. unsigned int *seqid,
  523. unsigned int *token_is))
  524. {
  525. struct totemrrp_instance *instance;
  526. unsigned int res;
  527. int i;
  528. res = hdb_handle_create (&totemrrp_instance_database,
  529. sizeof (struct totemrrp_instance), handle);
  530. if (res != 0) {
  531. goto error_exit;
  532. }
  533. res = hdb_handle_get (&totemrrp_instance_database, *handle,
  534. (void *)&instance);
  535. if (res != 0) {
  536. goto error_destroy;
  537. }
  538. totemrrp_instance_initialize (instance);
  539. /*
  540. * Configure logging
  541. */
  542. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  543. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  544. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  545. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  546. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  547. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  548. instance->totemrrp_interfaces = totem_config->interfaces;
  549. instance->totemrrp_poll_handle = poll_handle;
  550. instance->totemrrp_deliver_fn = deliver_fn;
  551. instance->totemrrp_iface_change_fn = iface_change_fn;
  552. instance->totemrrp_token_seqid_get = token_seqid_get;
  553. instance->interface_count = totem_config->interface_count;
  554. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  555. instance->context = context;
  556. instance->poll_handle = poll_handle;
  557. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  558. assert (instance->rrp_algo_instance);
  559. instance->rrp_algo_instance = active_instance_initialize (
  560. instance,
  561. totem_config->interface_count);
  562. for (i = 0; i < totem_config->interface_count; i++) {
  563. struct deliver_fn_context *deliver_fn_context;
  564. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  565. assert (deliver_fn_context);
  566. deliver_fn_context->instance = instance;
  567. deliver_fn_context->context = context;
  568. deliver_fn_context->interface_no = i;
  569. totemnet_initialize (
  570. poll_handle,
  571. &instance->net_handles[i],
  572. totem_config,
  573. i,
  574. (void *)deliver_fn_context,
  575. rrp_deliver_fn,
  576. rrp_iface_change_fn);
  577. }
  578. instance->net_handle = instance->net_handles[0];
  579. totemnet_net_mtu_adjust (totem_config);
  580. error_exit:
  581. hdb_handle_put (&totemrrp_instance_database, *handle);
  582. return (0);
  583. error_destroy:
  584. hdb_handle_destroy (&totemrrp_instance_database, *handle);
  585. return (-1);
  586. }
  587. int totemrrp_processor_count_set (
  588. totemrrp_handle handle,
  589. int processor_count)
  590. {
  591. struct totemrrp_instance *instance;
  592. int res = 0;
  593. res = hdb_handle_get (&totemrrp_instance_database, handle,
  594. (void *)&instance);
  595. if (res != 0) {
  596. res = ENOENT;
  597. goto error_exit;
  598. }
  599. totemnet_processor_count_set (instance->net_handle, processor_count);
  600. instance->processor_count = processor_count;
  601. hdb_handle_put (&totemrrp_instance_database, handle);
  602. error_exit:
  603. return (res);
  604. }
  605. int totemrrp_recv_flush (totemrrp_handle handle)
  606. {
  607. struct totemrrp_instance *instance;
  608. int res = 0;
  609. res = hdb_handle_get (&totemrrp_instance_database, handle,
  610. (void *)&instance);
  611. if (res != 0) {
  612. res = ENOENT;
  613. goto error_exit;
  614. }
  615. totemnet_recv_flush (instance->net_handle);
  616. hdb_handle_put (&totemrrp_instance_database, handle);
  617. error_exit:
  618. return (res);
  619. }
  620. int totemrrp_send_flush (totemrrp_handle handle)
  621. {
  622. struct totemrrp_instance *instance;
  623. int res = 0;
  624. res = hdb_handle_get (&totemrrp_instance_database, handle,
  625. (void *)&instance);
  626. if (res != 0) {
  627. res = ENOENT;
  628. goto error_exit;
  629. }
  630. totemnet_send_flush (instance->net_handle);
  631. hdb_handle_put (&totemrrp_instance_database, handle);
  632. error_exit:
  633. return (res);
  634. }
  635. int totemrrp_token_send (
  636. totemrrp_handle handle,
  637. struct totem_ip_address *system_to,
  638. void *msg,
  639. int msg_len)
  640. {
  641. struct totemrrp_instance *instance;
  642. int res = 0;
  643. res = hdb_handle_get (&totemrrp_instance_database, handle,
  644. (void *)&instance);
  645. if (res != 0) {
  646. res = ENOENT;
  647. goto error_exit;
  648. }
  649. instance->rrp_algo->token_send (instance, system_to, msg, msg_len);
  650. hdb_handle_put (&totemrrp_instance_database, handle);
  651. error_exit:
  652. return (res);
  653. }
  654. int totemrrp_mcast_flush_send (
  655. totemrrp_handle handle,
  656. void *msg,
  657. int msg_len)
  658. {
  659. struct totemrrp_instance *instance;
  660. int res = 0;
  661. res = hdb_handle_get (&totemrrp_instance_database, handle,
  662. (void *)&instance);
  663. if (res != 0) {
  664. res = ENOENT;
  665. goto error_exit;
  666. }
  667. // TODO this needs to return the result
  668. instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
  669. hdb_handle_put (&totemrrp_instance_database, handle);
  670. error_exit:
  671. return (res);
  672. }
  673. int totemrrp_mcast_noflush_send (
  674. totemrrp_handle handle,
  675. struct iovec *iovec,
  676. int iov_len)
  677. {
  678. struct totemrrp_instance *instance;
  679. int res = 0;
  680. res = hdb_handle_get (&totemrrp_instance_database, handle,
  681. (void *)&instance);
  682. if (res != 0) {
  683. res = ENOENT;
  684. goto error_exit;
  685. }
  686. /*
  687. * merge detects go out through mcast_flush_send so it is safe to
  688. * flush these messages if we are only one processor. This avoids
  689. * an encryption/hmac and decryption/hmac
  690. */
  691. if (instance->processor_count > 1) {
  692. // TODO this needs to return the result
  693. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  694. }
  695. hdb_handle_put (&totemrrp_instance_database, handle);
  696. error_exit:
  697. return (res);
  698. }
  699. int totemrrp_iface_check (totemrrp_handle handle)
  700. {
  701. struct totemrrp_instance *instance;
  702. int res = 0;
  703. res = hdb_handle_get (&totemrrp_instance_database, handle,
  704. (void *)&instance);
  705. if (res != 0) {
  706. res = ENOENT;
  707. goto error_exit;
  708. }
  709. totemnet_iface_check (instance->net_handle);
  710. hdb_handle_put (&totemrrp_instance_database, handle);
  711. error_exit:
  712. return (res);
  713. }