totemrrp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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 "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 saHandleDatabase totemrrp_instance_database = {
  220. .handleCount = 0,
  221. .handles = 0,
  222. .handleInstanceDestructor = 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. SaErrorT error;
  492. int res = 0;
  493. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  494. (void *)&instance);
  495. if (error != SA_OK) {
  496. res = ENOENT;
  497. goto error_exit;
  498. }
  499. totemnet_finalize (instance->net_handle);
  500. saHandleInstancePut (&totemrrp_instance_database, handle);
  501. error_exit:
  502. return (res);
  503. }
  504. /*
  505. * Totem Redundant Ring interface
  506. * depends on poll abstraction, POSIX, IPV4
  507. */
  508. /*
  509. * Create an instance
  510. */
  511. int totemrrp_initialize (
  512. poll_handle poll_handle,
  513. totemrrp_handle *handle,
  514. struct totem_config *totem_config,
  515. void *context,
  516. void (*deliver_fn) (
  517. void *context,
  518. struct totem_ip_address *system_from,
  519. void *msg,
  520. int msg_len),
  521. void (*iface_change_fn) (
  522. void *context,
  523. struct totem_ip_address *iface_addr),
  524. void (*token_seqid_get) (
  525. void *msg,
  526. unsigned int *seqid,
  527. unsigned int *token_is))
  528. {
  529. SaAisErrorT error;
  530. struct totemrrp_instance *instance;
  531. int i;
  532. error = saHandleCreate (&totemrrp_instance_database,
  533. sizeof (struct totemrrp_instance), handle);
  534. if (error != SA_OK) {
  535. goto error_exit;
  536. }
  537. error = saHandleInstanceGet (&totemrrp_instance_database, *handle,
  538. (void *)&instance);
  539. if (error != SA_OK) {
  540. goto error_destroy;
  541. }
  542. totemrrp_instance_initialize (instance);
  543. /*
  544. * Configure logging
  545. */
  546. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  547. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  548. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  549. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  550. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  551. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  552. instance->totemrrp_interfaces = totem_config->interfaces;
  553. instance->totemrrp_poll_handle = poll_handle;
  554. instance->totemrrp_deliver_fn = deliver_fn;
  555. instance->totemrrp_iface_change_fn = iface_change_fn;
  556. instance->totemrrp_token_seqid_get = token_seqid_get;
  557. instance->interface_count = totem_config->interface_count;
  558. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  559. instance->context = context;
  560. instance->poll_handle = poll_handle;
  561. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  562. assert (instance->rrp_algo_instance);
  563. instance->rrp_algo_instance = active_instance_initialize (
  564. instance,
  565. totem_config->interface_count);
  566. for (i = 0; i < totem_config->interface_count; i++) {
  567. struct deliver_fn_context *deliver_fn_context;
  568. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  569. assert (deliver_fn_context);
  570. deliver_fn_context->instance = instance;
  571. deliver_fn_context->context = context;
  572. deliver_fn_context->interface_no = i;
  573. totemnet_initialize (
  574. poll_handle,
  575. &instance->net_handles[i],
  576. totem_config,
  577. i,
  578. (void *)deliver_fn_context,
  579. rrp_deliver_fn,
  580. rrp_iface_change_fn);
  581. }
  582. instance->net_handle = instance->net_handles[0];
  583. totemnet_net_mtu_adjust (totem_config);
  584. error_exit:
  585. saHandleInstancePut (&totemrrp_instance_database, *handle);
  586. return (0);
  587. error_destroy:
  588. saHandleDestroy (&totemrrp_instance_database, *handle);
  589. return (-1);
  590. }
  591. int totemrrp_processor_count_set (
  592. totemrrp_handle handle,
  593. int processor_count)
  594. {
  595. SaAisErrorT error;
  596. struct totemrrp_instance *instance;
  597. int res = 0;
  598. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  599. (void *)&instance);
  600. if (error != SA_OK) {
  601. res = ENOENT;
  602. goto error_exit;
  603. }
  604. totemnet_processor_count_set (instance->net_handle, processor_count);
  605. instance->processor_count = processor_count;
  606. saHandleInstancePut (&totemrrp_instance_database, handle);
  607. error_exit:
  608. return (res);
  609. }
  610. int totemrrp_recv_flush (totemrrp_handle handle)
  611. {
  612. SaAisErrorT error;
  613. struct totemrrp_instance *instance;
  614. int res = 0;
  615. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  616. (void *)&instance);
  617. if (error != SA_OK) {
  618. res = ENOENT;
  619. goto error_exit;
  620. }
  621. totemnet_recv_flush (instance->net_handle);
  622. saHandleInstancePut (&totemrrp_instance_database, handle);
  623. error_exit:
  624. return (res);
  625. }
  626. int totemrrp_send_flush (totemrrp_handle handle)
  627. {
  628. SaAisErrorT error;
  629. struct totemrrp_instance *instance;
  630. int res = 0;
  631. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  632. (void *)&instance);
  633. if (error != SA_OK) {
  634. res = ENOENT;
  635. goto error_exit;
  636. }
  637. totemnet_send_flush (instance->net_handle);
  638. saHandleInstancePut (&totemrrp_instance_database, handle);
  639. error_exit:
  640. return (res);
  641. }
  642. int totemrrp_token_send (
  643. totemrrp_handle handle,
  644. struct totem_ip_address *system_to,
  645. void *msg,
  646. int msg_len)
  647. {
  648. SaAisErrorT error;
  649. struct totemrrp_instance *instance;
  650. int res = 0;
  651. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  652. (void *)&instance);
  653. if (error != SA_OK) {
  654. res = ENOENT;
  655. goto error_exit;
  656. }
  657. instance->rrp_algo->token_send (instance, system_to, msg, msg_len);
  658. saHandleInstancePut (&totemrrp_instance_database, handle);
  659. error_exit:
  660. return (res);
  661. }
  662. int totemrrp_mcast_flush_send (
  663. totemrrp_handle handle,
  664. void *msg,
  665. int msg_len)
  666. {
  667. SaAisErrorT error;
  668. struct totemrrp_instance *instance;
  669. int res = 0;
  670. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  671. (void *)&instance);
  672. if (error != SA_OK) {
  673. res = ENOENT;
  674. goto error_exit;
  675. }
  676. instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
  677. saHandleInstancePut (&totemrrp_instance_database, handle);
  678. error_exit:
  679. return (res);
  680. }
  681. int totemrrp_mcast_noflush_send (
  682. totemrrp_handle handle,
  683. struct iovec *iovec,
  684. int iov_len)
  685. {
  686. SaAisErrorT error;
  687. struct totemrrp_instance *instance;
  688. int res = 0;
  689. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  690. (void *)&instance);
  691. if (error != SA_OK) {
  692. res = ENOENT;
  693. goto error_exit;
  694. }
  695. /*
  696. * merge detects go out through mcast_flush_send so it is safe to
  697. * flush these messages if we are only one processor. This avoids
  698. * an encryption/hmac and decryption/hmac
  699. */
  700. if (instance->processor_count > 1) {
  701. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  702. }
  703. saHandleInstancePut (&totemrrp_instance_database, handle);
  704. error_exit:
  705. return (res);
  706. }
  707. int totemrrp_iface_check (totemrrp_handle handle)
  708. {
  709. SaAisErrorT error;
  710. struct totemrrp_instance *instance;
  711. int res = 0;
  712. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  713. (void *)&instance);
  714. if (error != SA_OK) {
  715. res = ENOENT;
  716. goto error_exit;
  717. }
  718. totemnet_iface_check (instance->net_handle);
  719. saHandleInstancePut (&totemrrp_instance_database, handle);
  720. error_exit:
  721. return (res);
  722. }