totemrrp.c 20 KB

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