totemrrp.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <assert.h>
  35. #include <pthread.h>
  36. #include <sys/mman.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/socket.h>
  40. #include <netdb.h>
  41. #include <sys/un.h>
  42. #include <sys/ioctl.h>
  43. #include <sys/param.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <unistd.h>
  47. #include <fcntl.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <signal.h>
  52. #include <sched.h>
  53. #include <time.h>
  54. #include <sys/time.h>
  55. #include <sys/poll.h>
  56. #include "../include/queue.h"
  57. #include "../include/sq.h"
  58. #include "../include/list.h"
  59. #include "../include/hdb.h"
  60. #include "swab.h"
  61. #include "aispoll.h"
  62. #include "totemnet.h"
  63. #include "totemrrp.h"
  64. struct totemrrp_instance;
  65. struct passive_instance {
  66. unsigned int *faulty;
  67. unsigned int *last_seq;
  68. unsigned int *counter_problems;
  69. unsigned char token[15000];
  70. unsigned int token_len;
  71. };
  72. struct active_instance {
  73. struct totemrrp_instance *rrp_instance;
  74. unsigned int *faulty;
  75. unsigned int *last_token_recv;
  76. unsigned int *counter_problems;
  77. unsigned char token[15000];
  78. unsigned int token_len;
  79. poll_timer_handle timer_active_token;
  80. };
  81. struct rrp_algo {
  82. void (*mcast_recv) (
  83. struct totemrrp_instance *instance,
  84. void *context,
  85. struct totem_ip_address *system_from,
  86. void *msg,
  87. unsigned int msg_len);
  88. void (*mcast_noflush_send) (
  89. struct totemrrp_instance *instance,
  90. struct iovec *iovec,
  91. unsigned int iov_len);
  92. void (*mcast_flush_send) (
  93. struct totemrrp_instance *instance,
  94. struct iovec *iovec,
  95. unsigned int iov_len);
  96. void (*token_recv) (
  97. struct totemrrp_instance *instance,
  98. unsigned int interface_no,
  99. void *context,
  100. struct totem_ip_address *system_from,
  101. void *msg,
  102. unsigned int msg_len,
  103. unsigned int token_seqid);
  104. void (*token_send) (
  105. struct totemrrp_instance *instance,
  106. struct totem_ip_address *system_to,
  107. struct iovec *iovec,
  108. unsigned int iov_len);
  109. void (*recv_flush) (
  110. struct totemrrp_instance *instance);
  111. void (*send_flush) (
  112. struct totemrrp_instance *instance);
  113. void (*iface_check) (
  114. struct totemrrp_instance *instance);
  115. void (*processor_count_set) (
  116. struct totemrrp_instance *instance,
  117. unsigned int processor_count);
  118. };
  119. struct totemrrp_instance {
  120. poll_handle totemrrp_poll_handle;
  121. struct totem_interface *totemrrp_interfaces;
  122. struct rrp_algo *rrp_algo;
  123. void *context;
  124. void (*totemrrp_deliver_fn) (
  125. void *context,
  126. struct totem_ip_address *system_from,
  127. void *msg,
  128. int msg_len);
  129. void (*totemrrp_iface_change_fn) (
  130. void *context,
  131. struct totem_ip_address *iface_addr);
  132. void (*totemrrp_token_seqid_get) (
  133. void *msg,
  134. unsigned int *seqid,
  135. unsigned int *token_is);
  136. /*
  137. * Function and data used to log messages
  138. */
  139. int totemrrp_log_level_security;
  140. int totemrrp_log_level_error;
  141. int totemrrp_log_level_warning;
  142. int totemrrp_log_level_notice;
  143. int totemrrp_log_level_debug;
  144. void (*totemrrp_log_printf) (int level, char *format, ...);
  145. totemrrp_handle handle;
  146. totemnet_handle *net_handles;
  147. void *rrp_algo_instance;
  148. int interface_count;
  149. int poll_handle;
  150. int processor_count;
  151. };
  152. #ifdef TODO
  153. static void passive_mcast_recv (
  154. struct totemrrp_instance *instance,
  155. void *context,
  156. struct totem_ip_address *system_from,
  157. void *msg,
  158. unsigned int msg_len);
  159. static void passive_mcast_noflush_send (
  160. struct totemrrp_instance *instance,
  161. struct iovec *iovec,
  162. unsigned int iov_len);
  163. static void passive_mcast_flush_send (
  164. struct totemrrp_instance *instance,
  165. struct iovec *iovec,
  166. unsigned int iov_len);
  167. static void passive_token_recv (
  168. struct totemrrp_instance *instance,
  169. unsigned int interface_no,
  170. struct totem_ip_address *system_from,
  171. void *msg,
  172. unsigned int msg_len,
  173. unsigned int token_seqid);
  174. static void passive_token_send (
  175. struct totemrrp_instance *instance,
  176. struct totem_ip_address *system_to,
  177. struct iovec *iovec,
  178. unsigned int iov_len);
  179. #endif
  180. static void active_mcast_recv (
  181. struct totemrrp_instance *instance,
  182. void *context,
  183. struct totem_ip_address *system_from,
  184. void *msg,
  185. unsigned int msg_len);
  186. static void active_mcast_noflush_send (
  187. struct totemrrp_instance *instance,
  188. struct iovec *iovec,
  189. unsigned int iov_len);
  190. static void active_mcast_flush_send (
  191. struct totemrrp_instance *instance,
  192. struct iovec *iovec,
  193. unsigned int iov_len);
  194. static void active_token_recv (
  195. struct totemrrp_instance *instance,
  196. unsigned int interface_no,
  197. void *context,
  198. struct totem_ip_address *system_from,
  199. void *msg,
  200. unsigned int msg_len,
  201. unsigned int token_seqid);
  202. static void active_token_send (
  203. struct totemrrp_instance *instance,
  204. struct totem_ip_address *system_to,
  205. struct iovec *iovec,
  206. unsigned int iov_len);
  207. static void active_recv_flush (
  208. struct totemrrp_instance *instance);
  209. static void active_send_flush (
  210. struct totemrrp_instance *instance);
  211. static void active_iface_check (
  212. struct totemrrp_instance *instance);
  213. static void active_processor_count_set (
  214. struct totemrrp_instance *instance,
  215. unsigned int processor_count_set);
  216. /*
  217. struct rrp_algo passive_algo = {
  218. .mcast_recv = passive_mcast_recv,
  219. .mcast_noflush_send = passive_mcast_noflush_send,
  220. .mcast_flush_send = passive_mcast_flush_send,
  221. .token_recv = passive_token_recv,
  222. .token_send = passive_token_send
  223. };
  224. */
  225. struct rrp_algo active_algo = {
  226. .mcast_recv = active_mcast_recv,
  227. .mcast_noflush_send = active_mcast_noflush_send,
  228. .mcast_flush_send = active_mcast_flush_send,
  229. .token_recv = active_token_recv,
  230. .token_send = active_token_send,
  231. .recv_flush = active_recv_flush,
  232. .send_flush = active_send_flush,
  233. .iface_check = active_iface_check,
  234. .processor_count_set = active_processor_count_set,
  235. };
  236. /*
  237. * All instances in one database
  238. */
  239. static struct hdb_handle_database totemrrp_instance_database = {
  240. .handle_count = 0,
  241. .handles = 0,
  242. .iterator = 0
  243. };
  244. struct passive_instance *passive_instance_initialize (
  245. int interface_count)
  246. {
  247. struct passive_instance *instance;
  248. int i;
  249. instance = malloc (sizeof (struct passive_instance));
  250. if (instance == 0) {
  251. goto error_exit;
  252. }
  253. instance->faulty = malloc (sizeof (int) * interface_count);
  254. if (instance->faulty == 0) {
  255. free (instance);
  256. instance = 0;
  257. goto error_exit;
  258. }
  259. instance->last_seq = malloc (sizeof (int) * interface_count);
  260. if (instance->last_seq == 0) {
  261. free (instance->faulty);
  262. free (instance);
  263. instance = 0;
  264. goto error_exit;
  265. }
  266. instance->counter_problems = malloc (sizeof (int) * interface_count);
  267. if (instance->counter_problems == 0) {
  268. free (instance->last_seq);
  269. free (instance->faulty);
  270. free (instance);
  271. instance = 0;
  272. goto error_exit;
  273. }
  274. for (i = 0; i < interface_count; i++) {
  275. instance->faulty[i] = 0;
  276. instance->last_seq[i] = 0;
  277. instance->counter_problems[i] = 0;
  278. }
  279. error_exit:
  280. return (instance);
  281. }
  282. struct active_instance *active_instance_initialize (
  283. struct totemrrp_instance *rrp_instance,
  284. int interface_count)
  285. {
  286. struct active_instance *instance;
  287. int i;
  288. instance = malloc (sizeof (struct active_instance));
  289. if (instance == 0) {
  290. goto error_exit;
  291. }
  292. instance->faulty = malloc (sizeof (int) * interface_count);
  293. if (instance->faulty == 0) {
  294. free (instance);
  295. instance = 0;
  296. goto error_exit;
  297. }
  298. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  299. if (instance->last_token_recv == 0) {
  300. free (instance->faulty);
  301. free (instance);
  302. instance = 0;
  303. goto error_exit;
  304. }
  305. instance->counter_problems = malloc (sizeof (int) * interface_count);
  306. if (instance->counter_problems == 0) {
  307. free (instance->last_token_recv);
  308. free (instance->faulty);
  309. free (instance);
  310. instance = 0;
  311. goto error_exit;
  312. }
  313. instance->faulty = malloc (sizeof (int) * interface_count);
  314. instance->last_token_recv = malloc (sizeof (int) * interface_count);
  315. instance->counter_problems = malloc (sizeof (int) * interface_count);
  316. for (i = 0; i < interface_count; i++) {
  317. instance->faulty[i] = 0;
  318. instance->last_token_recv[i] = 0;
  319. instance->counter_problems[i] = 0;
  320. }
  321. instance->timer_active_token = 0;
  322. instance->rrp_instance = rrp_instance;
  323. error_exit:
  324. return (instance);
  325. }
  326. static void timer_function_active_token (void *context)
  327. {
  328. // struct active_instance *instance = (struct active_instance *)context;
  329. }
  330. static void active_token_timer_start (struct active_instance *active_instance)
  331. {
  332. poll_timer_add (
  333. active_instance->rrp_instance->poll_handle,
  334. 10, /* 10 msec */
  335. (void *)active_instance,
  336. timer_function_active_token,
  337. &active_instance->timer_active_token);
  338. }
  339. static void active_token_timer_cancel (struct active_instance *active_instance)
  340. {
  341. poll_timer_delete (
  342. active_instance->rrp_instance->poll_handle,
  343. active_instance->timer_active_token);
  344. }
  345. static void active_mcast_recv (
  346. struct totemrrp_instance *instance,
  347. void *context,
  348. struct totem_ip_address *system_from,
  349. void *msg,
  350. unsigned int msg_len)
  351. {
  352. instance->totemrrp_deliver_fn (
  353. context,
  354. system_from,
  355. msg,
  356. msg_len);
  357. }
  358. static void active_mcast_flush_send (
  359. struct totemrrp_instance *instance,
  360. struct iovec *iovec,
  361. unsigned int iov_len)
  362. {
  363. int i;
  364. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  365. for (i = 0; i < instance->interface_count; i++) {
  366. if (rrp_algo_instance->faulty[i] == 0) {
  367. totemnet_mcast_flush_send (instance->net_handles[i], iovec, iov_len);
  368. }
  369. }
  370. }
  371. static void active_mcast_noflush_send (
  372. struct totemrrp_instance *instance,
  373. struct iovec *iovec,
  374. unsigned int iov_len)
  375. {
  376. int i;
  377. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  378. for (i = 0; i < instance->interface_count; i++) {
  379. if (rrp_algo_instance->faulty[i] == 0) {
  380. totemnet_mcast_noflush_send (instance->net_handles[i], iovec, iov_len);
  381. }
  382. }
  383. }
  384. static void active_token_recv (
  385. struct totemrrp_instance *instance,
  386. unsigned int interface_no,
  387. void *context,
  388. struct totem_ip_address *system_from,
  389. void *msg,
  390. unsigned int msg_len,
  391. unsigned int token_seqid)
  392. {
  393. unsigned int cur_token_seq;
  394. unsigned int last_token_seq;
  395. unsigned int token_is;
  396. int i;
  397. struct active_instance *active_instance = (struct active_instance *)instance->rrp_algo_instance;
  398. instance->totemrrp_token_seqid_get (
  399. msg,
  400. &cur_token_seq,
  401. &token_is);
  402. assert (token_is);
  403. if (token_seqid > cur_token_seq) {
  404. memcpy (active_instance->token, msg, msg_len);
  405. active_instance->token_len = msg_len;
  406. for (i = 0; i < instance->interface_count; i++) {
  407. active_instance->last_token_recv[i] = 0;
  408. }
  409. active_instance->last_token_recv[interface_no] = 1;
  410. active_token_timer_start (active_instance);
  411. }
  412. instance->totemrrp_token_seqid_get (
  413. msg,
  414. &last_token_seq,
  415. &token_is);
  416. assert (token_is);
  417. if (cur_token_seq == last_token_seq) {
  418. active_instance->last_token_recv[interface_no] = 1;
  419. for (i = 0; i < instance->interface_count; i++) {
  420. if ((active_instance->last_token_recv[i] == 0) &&
  421. active_instance->faulty[i] == 0) {
  422. return; /* don't deliver token */
  423. }
  424. }
  425. active_token_timer_cancel (active_instance);
  426. instance->totemrrp_deliver_fn (
  427. context,
  428. system_from,
  429. msg,
  430. msg_len);
  431. }
  432. }
  433. static void active_token_send (
  434. struct totemrrp_instance *instance,
  435. struct totem_ip_address *system_to,
  436. struct iovec *iovec,
  437. unsigned int iov_len)
  438. {
  439. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  440. int i;
  441. for (i = 0; i < instance->interface_count; i++) {
  442. if (rrp_algo_instance->faulty[i] == 0) {
  443. totemnet_token_send (
  444. instance->net_handles[i], system_to,
  445. iovec, iov_len);
  446. }
  447. }
  448. }
  449. static void active_recv_flush (struct totemrrp_instance *instance)
  450. {
  451. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  452. unsigned int i;
  453. for (i = 0; i < instance->interface_count; i++) {
  454. if (rrp_algo_instance->faulty[i] == 0) {
  455. totemnet_recv_flush (instance->net_handles[i]);
  456. }
  457. }
  458. }
  459. static void active_send_flush (struct totemrrp_instance *instance)
  460. {
  461. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  462. unsigned int i;
  463. for (i = 0; i < instance->interface_count; i++) {
  464. if (rrp_algo_instance->faulty[i] == 0) {
  465. totemnet_send_flush (instance->net_handles[i]);
  466. }
  467. }
  468. }
  469. static void active_iface_check (struct totemrrp_instance *instance)
  470. {
  471. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  472. unsigned int i;
  473. for (i = 0; i < instance->interface_count; i++) {
  474. if (rrp_algo_instance->faulty[i] == 0) {
  475. totemnet_iface_check (instance->net_handles[i]);
  476. }
  477. }
  478. }
  479. static void active_processor_count_set (
  480. struct totemrrp_instance *instance,
  481. unsigned int processor_count)
  482. {
  483. struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
  484. unsigned int i;
  485. for (i = 0; i < instance->interface_count; i++) {
  486. if (rrp_algo_instance->faulty[i] == 0) {
  487. totemnet_processor_count_set (instance->net_handles[i],
  488. processor_count);
  489. }
  490. }
  491. }
  492. struct deliver_fn_context {
  493. struct totemrrp_instance *instance;
  494. void *context;
  495. int interface_no;
  496. };
  497. static void totemrrp_instance_initialize (struct totemrrp_instance *instance)
  498. {
  499. memset (instance, 0, sizeof (struct totemrrp_instance));
  500. instance->rrp_algo = &active_algo;
  501. }
  502. void rrp_deliver_fn (
  503. void *context,
  504. struct totem_ip_address *system_from,
  505. void *msg,
  506. int msg_len)
  507. {
  508. unsigned int token_seqid;
  509. unsigned int token_is;
  510. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  511. deliver_fn_context->instance->totemrrp_token_seqid_get (
  512. msg,
  513. &token_seqid,
  514. &token_is);
  515. if (token_is) {
  516. /*
  517. * Deliver to the token receiver for this rrp algorithm
  518. */
  519. deliver_fn_context->instance->rrp_algo->token_recv (
  520. deliver_fn_context->instance,
  521. deliver_fn_context->interface_no,
  522. deliver_fn_context->context,
  523. system_from,
  524. msg,
  525. msg_len,
  526. token_seqid);
  527. } else {
  528. /*
  529. * Deliver to the mcast receiver for this rrp algorithm
  530. */
  531. deliver_fn_context->instance->rrp_algo->mcast_recv (
  532. deliver_fn_context->instance,
  533. deliver_fn_context->context,
  534. system_from,
  535. msg,
  536. msg_len);
  537. }
  538. }
  539. void rrp_iface_change_fn (
  540. void *context,
  541. struct totem_ip_address *iface_addr)
  542. {
  543. struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
  544. deliver_fn_context->instance->totemrrp_iface_change_fn (
  545. deliver_fn_context->context,
  546. iface_addr);
  547. }
  548. int totemrrp_finalize (
  549. totemrrp_handle handle)
  550. {
  551. struct totemrrp_instance *instance;
  552. int res = 0;
  553. int i;
  554. res = hdb_handle_get (&totemrrp_instance_database, handle,
  555. (void *)&instance);
  556. if (res != 0) {
  557. res = ENOENT;
  558. goto error_exit;
  559. }
  560. for (i = 0; i < instance->interface_count; i++) {
  561. totemnet_finalize (instance->net_handles[i]);
  562. }
  563. hdb_handle_put (&totemrrp_instance_database, handle);
  564. error_exit:
  565. return (res);
  566. }
  567. /*
  568. * Totem Redundant Ring interface
  569. * depends on poll abstraction, POSIX, IPV4
  570. */
  571. /*
  572. * Create an instance
  573. */
  574. int totemrrp_initialize (
  575. poll_handle poll_handle,
  576. totemrrp_handle *handle,
  577. struct totem_config *totem_config,
  578. void *context,
  579. void (*deliver_fn) (
  580. void *context,
  581. struct totem_ip_address *system_from,
  582. void *msg,
  583. int msg_len),
  584. void (*iface_change_fn) (
  585. void *context,
  586. struct totem_ip_address *iface_addr),
  587. void (*token_seqid_get) (
  588. void *msg,
  589. unsigned int *seqid,
  590. unsigned int *token_is))
  591. {
  592. struct totemrrp_instance *instance;
  593. unsigned int res;
  594. int i;
  595. res = hdb_handle_create (&totemrrp_instance_database,
  596. sizeof (struct totemrrp_instance), handle);
  597. if (res != 0) {
  598. goto error_exit;
  599. }
  600. res = hdb_handle_get (&totemrrp_instance_database, *handle,
  601. (void *)&instance);
  602. if (res != 0) {
  603. goto error_destroy;
  604. }
  605. totemrrp_instance_initialize (instance);
  606. /*
  607. * Configure logging
  608. */
  609. instance->totemrrp_log_level_security = totem_config->totem_logging_configuration.log_level_security;
  610. instance->totemrrp_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  611. instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  612. instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  613. instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  614. instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
  615. instance->totemrrp_interfaces = totem_config->interfaces;
  616. instance->totemrrp_poll_handle = poll_handle;
  617. instance->totemrrp_deliver_fn = deliver_fn;
  618. instance->totemrrp_iface_change_fn = iface_change_fn;
  619. instance->totemrrp_token_seqid_get = token_seqid_get;
  620. instance->interface_count = totem_config->interface_count;
  621. instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
  622. instance->context = context;
  623. instance->poll_handle = poll_handle;
  624. instance->rrp_algo_instance = malloc (sizeof (struct active_instance));
  625. assert (instance->rrp_algo_instance);
  626. instance->rrp_algo_instance = active_instance_initialize (
  627. instance,
  628. totem_config->interface_count);
  629. for (i = 0; i < totem_config->interface_count; i++) {
  630. struct deliver_fn_context *deliver_fn_context;
  631. deliver_fn_context = malloc (sizeof (struct deliver_fn_context));
  632. assert (deliver_fn_context);
  633. deliver_fn_context->instance = instance;
  634. deliver_fn_context->context = context;
  635. deliver_fn_context->interface_no = i;
  636. totemnet_initialize (
  637. poll_handle,
  638. &instance->net_handles[i],
  639. totem_config,
  640. i,
  641. (void *)deliver_fn_context,
  642. rrp_deliver_fn,
  643. rrp_iface_change_fn);
  644. }
  645. totemnet_net_mtu_adjust (totem_config);
  646. error_exit:
  647. hdb_handle_put (&totemrrp_instance_database, *handle);
  648. return (0);
  649. error_destroy:
  650. hdb_handle_destroy (&totemrrp_instance_database, *handle);
  651. return (-1);
  652. }
  653. int totemrrp_processor_count_set (
  654. totemrrp_handle handle,
  655. unsigned int processor_count)
  656. {
  657. struct totemrrp_instance *instance;
  658. int res = 0;
  659. res = hdb_handle_get (&totemrrp_instance_database, handle,
  660. (void *)&instance);
  661. if (res != 0) {
  662. res = ENOENT;
  663. goto error_exit;
  664. }
  665. instance->rrp_algo->processor_count_set (instance, processor_count);
  666. instance->processor_count = processor_count;
  667. hdb_handle_put (&totemrrp_instance_database, handle);
  668. error_exit:
  669. return (res);
  670. }
  671. int totemrrp_recv_flush (totemrrp_handle handle)
  672. {
  673. struct totemrrp_instance *instance;
  674. int res = 0;
  675. res = hdb_handle_get (&totemrrp_instance_database, handle,
  676. (void *)&instance);
  677. if (res != 0) {
  678. res = ENOENT;
  679. goto error_exit;
  680. }
  681. instance->rrp_algo->recv_flush (instance);
  682. hdb_handle_put (&totemrrp_instance_database, handle);
  683. error_exit:
  684. return (res);
  685. }
  686. int totemrrp_send_flush (totemrrp_handle handle)
  687. {
  688. struct totemrrp_instance *instance;
  689. int res = 0;
  690. res = hdb_handle_get (&totemrrp_instance_database, handle,
  691. (void *)&instance);
  692. if (res != 0) {
  693. res = ENOENT;
  694. goto error_exit;
  695. }
  696. instance->rrp_algo->send_flush (instance);
  697. hdb_handle_put (&totemrrp_instance_database, handle);
  698. error_exit:
  699. return (res);
  700. }
  701. int totemrrp_token_send (
  702. totemrrp_handle handle,
  703. struct totem_ip_address *system_to,
  704. struct iovec *iovec,
  705. unsigned int iov_len)
  706. {
  707. struct totemrrp_instance *instance;
  708. int res = 0;
  709. res = hdb_handle_get (&totemrrp_instance_database, handle,
  710. (void *)&instance);
  711. if (res != 0) {
  712. res = ENOENT;
  713. goto error_exit;
  714. }
  715. instance->rrp_algo->token_send (instance, system_to, iovec, iov_len);
  716. hdb_handle_put (&totemrrp_instance_database, handle);
  717. error_exit:
  718. return (res);
  719. }
  720. int totemrrp_mcast_flush_send (
  721. totemrrp_handle handle,
  722. struct iovec *iovec,
  723. unsigned int iov_len)
  724. {
  725. struct totemrrp_instance *instance;
  726. int res = 0;
  727. res = hdb_handle_get (&totemrrp_instance_database, handle,
  728. (void *)&instance);
  729. if (res != 0) {
  730. res = ENOENT;
  731. goto error_exit;
  732. }
  733. // TODO this needs to return the result
  734. instance->rrp_algo->mcast_flush_send (instance, iovec, iov_len);
  735. hdb_handle_put (&totemrrp_instance_database, handle);
  736. error_exit:
  737. return (res);
  738. }
  739. int totemrrp_mcast_noflush_send (
  740. totemrrp_handle handle,
  741. struct iovec *iovec,
  742. unsigned int iov_len)
  743. {
  744. struct totemrrp_instance *instance;
  745. int res = 0;
  746. res = hdb_handle_get (&totemrrp_instance_database, handle,
  747. (void *)&instance);
  748. if (res != 0) {
  749. res = ENOENT;
  750. goto error_exit;
  751. }
  752. /*
  753. * merge detects go out through mcast_flush_send so it is safe to
  754. * flush these messages if we are only one processor. This avoids
  755. * an encryption/hmac and decryption/hmac
  756. */
  757. if (instance->processor_count > 1) {
  758. // TODO this needs to return the result
  759. instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
  760. }
  761. hdb_handle_put (&totemrrp_instance_database, handle);
  762. error_exit:
  763. return (res);
  764. }
  765. int totemrrp_iface_check (totemrrp_handle handle)
  766. {
  767. struct totemrrp_instance *instance;
  768. int res = 0;
  769. res = hdb_handle_get (&totemrrp_instance_database, handle,
  770. (void *)&instance);
  771. if (res != 0) {
  772. res = ENOENT;
  773. goto error_exit;
  774. }
  775. instance->rrp_algo->iface_check (instance);
  776. hdb_handle_put (&totemrrp_instance_database, handle);
  777. error_exit:
  778. return (res);
  779. }