totemrrp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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 in_addr *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 in_addr *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 in_addr *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 in_addr *system_from,
  121. void *msg,
  122. int msg_len);
  123. void (*totemrrp_iface_change_fn) (
  124. void *context,
  125. struct sockaddr_in *iface_sockaddr_in);
  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 in_addr *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 in_addr *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 in_addr *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 in_addr *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 in_addr *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 in_addr *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. printf ("active instance %p\n", instance);
  310. }
  311. void active_token_timer_start (struct active_instance *active_instance)
  312. {
  313. poll_timer_add (
  314. active_instance->rrp_instance->poll_handle,
  315. 10, /* 10 msec */
  316. (void *)active_instance,
  317. timer_function_active_token,
  318. &active_instance->timer_active_token);
  319. }
  320. void active_token_timer_cancel (struct active_instance *active_instance)
  321. {
  322. poll_timer_delete (
  323. active_instance->rrp_instance->poll_handle,
  324. active_instance->timer_active_token);
  325. }
  326. void active_mcast_recv (
  327. struct totemrrp_instance *instance,
  328. void *context,
  329. struct in_addr *system_from,
  330. void *msg,
  331. unsigned int msg_len)
  332. {
  333. instance->totemrrp_deliver_fn (
  334. context,
  335. system_from,
  336. msg,
  337. msg_len);
  338. }
  339. void active_mcast_flush_send (
  340. struct totemrrp_instance *instance,
  341. void *msg,
  342. unsigned int msg_len)
  343. {
  344. int i;
  345. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  346. for (i = 0; i < instance->interface_count; i++) {
  347. if (rrp_algo_instance->faulty[i] == 0) {
  348. totemnet_mcast_flush_send (instance->net_handle, msg, msg_len);
  349. }
  350. }
  351. }
  352. void active_mcast_noflush_send (
  353. struct totemrrp_instance *instance,
  354. struct iovec *iovec,
  355. unsigned int iov_len)
  356. {
  357. int i;
  358. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  359. for (i = 0; i < instance->interface_count; i++) {
  360. if (rrp_algo_instance->faulty[i] == 0) {
  361. totemnet_mcast_noflush_send (instance->net_handle, iovec, iov_len);
  362. }
  363. }
  364. }
  365. void active_token_recv (
  366. struct totemrrp_instance *instance,
  367. unsigned int interface_no,
  368. void *context,
  369. struct in_addr *system_from,
  370. void *msg,
  371. unsigned int msg_len,
  372. unsigned int token_seqid)
  373. {
  374. unsigned int cur_token_seq;
  375. unsigned int last_token_seq;
  376. int token_is;
  377. int i;
  378. struct active_instance *active_instance = (struct active_instance *)instance->rrp_algo_instance;
  379. instance->totemrrp_token_seqid_get (
  380. msg,
  381. &cur_token_seq,
  382. &token_is);
  383. assert (token_is);
  384. if (token_seqid > cur_token_seq) {
  385. memcpy (active_instance->token, msg, msg_len);
  386. active_instance->token_len = msg_len;
  387. for (i = 0; i < instance->interface_count; i++) {
  388. active_instance->last_token_recv[i] = 0;
  389. }
  390. active_instance->last_token_recv[interface_no] = 1;
  391. active_token_timer_start (active_instance);
  392. }
  393. instance->totemrrp_token_seqid_get (
  394. msg,
  395. &last_token_seq,
  396. &token_is);
  397. assert (token_is);
  398. if (cur_token_seq == last_token_seq) {
  399. active_instance->last_token_recv[interface_no] = 1;
  400. for (i = 0; i < instance->interface_count; i++) {
  401. if ((active_instance->last_token_recv[i] == 0) &&
  402. active_instance->faulty[i] == 0) {
  403. return; /* don't deliver token */
  404. }
  405. }
  406. active_token_timer_cancel (active_instance);
  407. instance->totemrrp_deliver_fn (
  408. context,
  409. system_from,
  410. msg,
  411. msg_len);
  412. }
  413. }
  414. void active_token_send (
  415. struct totemrrp_instance *instance,
  416. struct in_addr *system_to,
  417. void *msg,
  418. unsigned int msg_len)
  419. {
  420. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  421. int i;
  422. for (i = 0; i < instance->interface_count; i++) {
  423. if (rrp_algo_instance->faulty[i] == 0) {
  424. totemnet_token_send (
  425. instance->net_handle,
  426. system_to,
  427. msg,
  428. msg_len);
  429. }
  430. }
  431. }
  432. struct deliver_fn_context {
  433. struct totemrrp_instance *instance;
  434. void *context;
  435. int interface_no;
  436. };
  437. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  438. {
  439. memset (instance, 0, sizeof (struct totemrrp_instance));
  440. instance->rrp_algo = &active_algo;
  441. }
  442. void rrp_deliver_fn (
  443. void *context,
  444. struct in_addr *system_from,
  445. void *msg,
  446. int msg_len)
  447. {
  448. int token_seqid;
  449. int token_is;
  450. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  451. deliver_fn_context->instance->totemrrp_token_seqid_get (
  452. msg,
  453. &token_seqid,
  454. &token_is);
  455. if (token_is) {
  456. /*
  457. * Deliver to the token receiver for this rrp algorithm
  458. */
  459. deliver_fn_context->instance->rrp_algo->token_recv (
  460. deliver_fn_context->instance,
  461. deliver_fn_context->interface_no,
  462. deliver_fn_context->context,
  463. system_from,
  464. msg,
  465. msg_len,
  466. token_seqid);
  467. } else {
  468. /*
  469. * Deliver to the mcast receiver for this rrp algorithm
  470. */
  471. deliver_fn_context->instance->rrp_algo->mcast_recv (
  472. deliver_fn_context->instance,
  473. deliver_fn_context->context,
  474. system_from,
  475. msg,
  476. msg_len);
  477. }
  478. }
  479. void rrp_iface_change_fn (
  480. void *context,
  481. struct sockaddr_in *iface_sockaddr_in)
  482. {
  483. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  484. deliver_fn_context->instance->totemrrp_iface_change_fn (
  485. deliver_fn_context->context,
  486. iface_sockaddr_in);
  487. }
  488. int totemrrp_finalize (
  489. totemrrp_handle handle)
  490. {
  491. struct totemrrp_instance *instance;
  492. SaErrorT error;
  493. int res = 0;
  494. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  495. (void *)&instance);
  496. if (error != SA_OK) {
  497. res = ENOENT;
  498. goto error_exit;
  499. }
  500. totemnet_finalize (instance->net_handle);
  501. saHandleInstancePut (&totemrrp_instance_database, handle);
  502. error_exit:
  503. return (res);
  504. }
  505. /*
  506. * Totem Redundant Ring interface
  507. * depends on poll abstraction, POSIX, IPV4
  508. */
  509. /*
  510. * Create an instance
  511. */
  512. int totemrrp_initialize (
  513. poll_handle poll_handle,
  514. totemrrp_handle *handle,
  515. struct totem_config *totem_config,
  516. void *context,
  517. void (*deliver_fn) (
  518. void *context,
  519. struct in_addr *system_from,
  520. void *msg,
  521. int msg_len),
  522. void (*iface_change_fn) (
  523. void *context,
  524. struct sockaddr_in *iface_sockaddr_in),
  525. void (*token_seqid_get) (
  526. void *msg,
  527. unsigned int *seqid,
  528. unsigned int *token_is))
  529. {
  530. SaAisErrorT error;
  531. struct totemrrp_instance *instance;
  532. int i;
  533. error = saHandleCreate (&totemrrp_instance_database,
  534. sizeof (struct totemrrp_instance), handle);
  535. if (error != SA_OK) {
  536. goto error_exit;
  537. }
  538. error = saHandleInstanceGet (&totemrrp_instance_database, *handle,
  539. (void *)&instance);
  540. if (error != SA_OK) {
  541. goto error_destroy;
  542. }
  543. totemrrp_instance_initialize (instance);
  544. /*
  545. * Configure logging
  546. */
  547. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  548. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  549. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  550. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  551. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  552. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  553. instance->totemrrp_interfaces = totem_config->interfaces;
  554. instance->totemrrp_poll_handle = poll_handle;
  555. instance->totemrrp_deliver_fn = deliver_fn;
  556. instance->totemrrp_iface_change_fn = iface_change_fn;
  557. instance->totemrrp_token_seqid_get = token_seqid_get;
  558. instance->interface_count = totem_config->interface_count;
  559. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  560. instance->context = context;
  561. instance->poll_handle = poll_handle;
  562. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  563. assert (instance->rrp_algo_instance);
  564. instance->rrp_algo_instance = active_instance_initialize (
  565. instance,
  566. totem_config->interface_count);
  567. for (i = 0; i < totem_config->interface_count; i++) {
  568. struct deliver_fn_context *deliver_fn_context;
  569. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  570. assert (deliver_fn_context);
  571. deliver_fn_context->instance = instance;
  572. deliver_fn_context->context = context;
  573. deliver_fn_context->interface_no = i;
  574. totemnet_initialize (
  575. poll_handle,
  576. &instance->net_handles[i],
  577. totem_config,
  578. i,
  579. (void *)deliver_fn_context,
  580. rrp_deliver_fn,
  581. rrp_iface_change_fn);
  582. }
  583. instance->net_handle = instance->net_handles[0];
  584. totemnet_net_mtu_adjust (totem_config);
  585. error_exit:
  586. saHandleInstancePut (&totemrrp_instance_database, *handle);
  587. return (0);
  588. error_destroy:
  589. saHandleDestroy (&totemrrp_instance_database, *handle);
  590. return (-1);
  591. }
  592. int totemrrp_processor_count_set (
  593. totemrrp_handle handle,
  594. int processor_count)
  595. {
  596. SaAisErrorT error;
  597. struct totemrrp_instance *instance;
  598. int res = 0;
  599. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  600. (void *)&instance);
  601. if (error != SA_OK) {
  602. res = ENOENT;
  603. goto error_exit;
  604. }
  605. totemnet_processor_count_set (instance->net_handle, processor_count);
  606. instance->processor_count = processor_count;
  607. saHandleInstancePut (&totemrrp_instance_database, handle);
  608. error_exit:
  609. return (res);
  610. }
  611. int totemrrp_recv_flush (totemrrp_handle handle)
  612. {
  613. SaAisErrorT error;
  614. struct totemrrp_instance *instance;
  615. int res = 0;
  616. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  617. (void *)&instance);
  618. if (error != SA_OK) {
  619. res = ENOENT;
  620. goto error_exit;
  621. }
  622. totemnet_recv_flush (instance->net_handle);
  623. saHandleInstancePut (&totemrrp_instance_database, handle);
  624. error_exit:
  625. return (res);
  626. }
  627. int totemrrp_send_flush (totemrrp_handle handle)
  628. {
  629. SaAisErrorT error;
  630. struct totemrrp_instance *instance;
  631. int res = 0;
  632. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  633. (void *)&instance);
  634. if (error != SA_OK) {
  635. res = ENOENT;
  636. goto error_exit;
  637. }
  638. totemnet_send_flush (instance->net_handle);
  639. saHandleInstancePut (&totemrrp_instance_database, handle);
  640. error_exit:
  641. return (res);
  642. }
  643. int totemrrp_token_send (
  644. totemrrp_handle handle,
  645. struct in_addr *system_to,
  646. void *msg,
  647. int msg_len)
  648. {
  649. SaAisErrorT error;
  650. struct totemrrp_instance *instance;
  651. int res = 0;
  652. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  653. (void *)&instance);
  654. if (error != SA_OK) {
  655. res = ENOENT;
  656. goto error_exit;
  657. }
  658. instance->rrp_algo->token_send (instance, system_to, msg, msg_len);
  659. saHandleInstancePut (&totemrrp_instance_database, handle);
  660. error_exit:
  661. return (res);
  662. }
  663. int totemrrp_mcast_flush_send (
  664. totemrrp_handle handle,
  665. void *msg,
  666. int msg_len)
  667. {
  668. SaAisErrorT error;
  669. struct totemrrp_instance *instance;
  670. int res = 0;
  671. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  672. (void *)&instance);
  673. if (error != SA_OK) {
  674. res = ENOENT;
  675. goto error_exit;
  676. }
  677. instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
  678. saHandleInstancePut (&totemrrp_instance_database, handle);
  679. error_exit:
  680. return (res);
  681. }
  682. int totemrrp_mcast_noflush_send (
  683. totemrrp_handle handle,
  684. struct iovec *iovec,
  685. int iov_len)
  686. {
  687. SaAisErrorT error;
  688. struct totemrrp_instance *instance;
  689. int res = 0;
  690. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  691. (void *)&instance);
  692. if (error != SA_OK) {
  693. res = ENOENT;
  694. goto error_exit;
  695. }
  696. /*
  697. * merge detects go out through mcast_flush_send so it is safe to
  698. * flush these messages if we are only one processor. This avoids
  699. * an encryption/hmac and decryption/hmac
  700. */
  701. if (instance->processor_count > 1) {
  702. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  703. }
  704. saHandleInstancePut (&totemrrp_instance_database, handle);
  705. error_exit:
  706. return (res);
  707. }
  708. int totemrrp_iface_check (totemrrp_handle handle)
  709. {
  710. SaAisErrorT error;
  711. struct totemrrp_instance *instance;
  712. int res = 0;
  713. error = saHandleInstanceGet (&totemrrp_instance_database, handle,
  714. (void *)&instance);
  715. if (error != SA_OK) {
  716. res = ENOENT;
  717. goto error_exit;
  718. }
  719. totemnet_iface_check (instance->net_handle);
  720. saHandleInstancePut (&totemrrp_instance_database, handle);
  721. error_exit:
  722. return (res);
  723. }