totemknet.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. /*
  2. * Copyright (c) 2016 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. * THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <config.h>
  34. #include <assert.h>
  35. #include <sys/mman.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <sys/socket.h>
  39. #include <netdb.h>
  40. #include <sys/un.h>
  41. #include <sys/ioctl.h>
  42. #include <sys/param.h>
  43. #include <netinet/in.h>
  44. #include <arpa/inet.h>
  45. #include <unistd.h>
  46. #include <fcntl.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <errno.h>
  50. #include <sched.h>
  51. #include <time.h>
  52. #include <sys/time.h>
  53. #include <sys/poll.h>
  54. #include <sys/uio.h>
  55. #include <limits.h>
  56. #include <qb/qbdefs.h>
  57. #include <qb/qbloop.h>
  58. #include <corosync/sq.h>
  59. #include <corosync/swab.h>
  60. #include <corosync/logsys.h>
  61. #include <corosync/icmap.h>
  62. #include <corosync/totem/totemip.h>
  63. #include "totemknet.h"
  64. #include "util.h"
  65. #include <nss.h>
  66. #include <pk11pub.h>
  67. #include <pkcs11.h>
  68. #include <prerror.h>
  69. #include <libknet.h>
  70. #ifndef MSG_NOSIGNAL
  71. #define MSG_NOSIGNAL 0
  72. #endif
  73. #define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * FRAME_SIZE_MAX)
  74. /* Buffers for sendmmsg/recvmmsg */
  75. #define MAX_BUFFERS 10
  76. /* Should match that used by cfg */
  77. #define CFG_INTERFACE_STATUS_MAX_LEN 512
  78. struct totemknet_instance {
  79. struct crypto_instance *crypto_inst;
  80. qb_loop_t *poll_handle;
  81. knet_handle_t knet_handle;
  82. int link_mode;
  83. void *context;
  84. void (*totemknet_deliver_fn) (
  85. void *context,
  86. const void *msg,
  87. unsigned int msg_len);
  88. void (*totemknet_iface_change_fn) (
  89. void *context,
  90. const struct totem_ip_address *iface_address,
  91. unsigned int link_no);
  92. void (*totemknet_mtu_changed) (
  93. void *context,
  94. int net_mtu);
  95. void (*totemknet_target_set_completed) (void *context);
  96. /*
  97. * Function and data used to log messages
  98. */
  99. int totemknet_log_level_security;
  100. int totemknet_log_level_error;
  101. int totemknet_log_level_warning;
  102. int totemknet_log_level_notice;
  103. int totemknet_log_level_debug;
  104. int totemknet_subsys_id;
  105. int knet_subsys_id;
  106. void (*totemknet_log_printf) (
  107. int level,
  108. int subsys,
  109. const char *function,
  110. const char *file,
  111. int line,
  112. const char *format,
  113. ...)__attribute__((format(printf, 6, 7)));
  114. void *knet_context;
  115. char iov_buffer[MAX_BUFFERS][KNET_MAX_PACKET_SIZE];
  116. int stats_sent;
  117. int stats_recv;
  118. int stats_delv;
  119. int stats_remcasts;
  120. int stats_orf_token;
  121. struct timeval stats_tv_start;
  122. char *link_status[INTERFACE_MAX];
  123. int num_links;
  124. struct totem_ip_address my_ids[INTERFACE_MAX];
  125. uint16_t ip_port[INTERFACE_MAX];
  126. int our_nodeid;
  127. struct totem_config *totem_config;
  128. totemsrp_stats_t *stats;
  129. struct totem_ip_address token_target;
  130. qb_loop_timer_handle timer_netif_check_timeout;
  131. qb_loop_timer_handle timer_merge_detect_timeout;
  132. int send_merge_detect_message;
  133. unsigned int merge_detect_messages_sent_before_timeout;
  134. int logpipes[2];
  135. int knet_fd;
  136. };
  137. struct work_item {
  138. const void *msg;
  139. unsigned int msg_len;
  140. struct totemknet_instance *instance;
  141. };
  142. int totemknet_member_list_rebind_ip (
  143. void *knet_context);
  144. static void totemknet_start_merge_detect_timeout(
  145. void *knet_context);
  146. static void totemknet_stop_merge_detect_timeout(
  147. void *knet_context);
  148. static void totemknet_instance_initialize (struct totemknet_instance *instance)
  149. {
  150. memset (instance, 0, sizeof (struct totemknet_instance));
  151. }
  152. #define knet_log_printf(level, format, args...) \
  153. do { \
  154. instance->totemknet_log_printf ( \
  155. level, instance->totemknet_subsys_id, \
  156. __FUNCTION__, __FILE__, __LINE__, \
  157. (const char *)format, ##args); \
  158. } while (0);
  159. #define libknet_log_printf(level, format, args...) \
  160. do { \
  161. instance->totemknet_log_printf ( \
  162. level, instance->knet_subsys_id, \
  163. __FUNCTION__, "libknet.h", __LINE__, \
  164. (const char *)format, ##args); \
  165. } while (0);
  166. #define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
  167. do { \
  168. char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
  169. const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
  170. instance->totemknet_log_printf ( \
  171. level, instance->totemknet_subsys_id, \
  172. __FUNCTION__, __FILE__, __LINE__, \
  173. fmt ": %s (%d)", ##args, _error_ptr, err_num); \
  174. } while(0)
  175. static int dst_host_filter_callback_fn(void *private_data,
  176. const unsigned char *outdata,
  177. ssize_t outdata_len,
  178. uint8_t tx_rx,
  179. knet_node_id_t this_host_id,
  180. knet_node_id_t src_host_id,
  181. int8_t *channel,
  182. knet_node_id_t *dst_host_ids,
  183. size_t *dst_host_ids_entries)
  184. {
  185. struct totem_message_header *header = (struct totem_message_header *)outdata;
  186. int res;
  187. *channel = 0;
  188. if (header->target_nodeid) {
  189. dst_host_ids[0] = header->target_nodeid;
  190. *dst_host_ids_entries = 1;
  191. res = 0; /* unicast message */
  192. }
  193. else {
  194. *dst_host_ids_entries = 0;
  195. res = 1; /* multicast message */
  196. }
  197. return res;
  198. }
  199. static void socket_error_callback_fn(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)
  200. {
  201. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  202. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet socket ERROR notification called: txrx=%d, error=%d, errorno=%d", tx_rx, error, errorno);
  203. if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
  204. knet_handle_remove_datafd(instance->knet_handle, datafd);
  205. }
  206. }
  207. static void host_change_callback_fn(void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
  208. {
  209. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  210. // TODO: what? if anything.
  211. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet host change callback. nodeid: %d reachable: %d", host_id, reachable);
  212. }
  213. static void pmtu_change_callback_fn(void *private_data, unsigned int data_mtu)
  214. {
  215. struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
  216. knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet pMTU change: %d", data_mtu);
  217. /* We don't need to tell corosync the actual knet MTU */
  218. // instance->totemknet_mtu_changed(instance->context, data_mtu);
  219. }
  220. int totemknet_crypto_set (
  221. void *knet_context,
  222. const char *cipher_type,
  223. const char *hash_type)
  224. {
  225. return (0);
  226. }
  227. static inline void ucast_sendmsg (
  228. struct totemknet_instance *instance,
  229. struct totem_ip_address *system_to,
  230. const void *msg,
  231. unsigned int msg_len)
  232. {
  233. int res = 0;
  234. struct totem_message_header *header = (struct totem_message_header *)msg;
  235. struct msghdr msg_ucast;
  236. struct iovec iovec;
  237. header->target_nodeid = system_to->nodeid;
  238. iovec.iov_base = (void *)msg;
  239. iovec.iov_len = msg_len;
  240. /*
  241. * Build unicast message
  242. */
  243. memset(&msg_ucast, 0, sizeof(msg_ucast));
  244. msg_ucast.msg_iov = (void *)&iovec;
  245. msg_ucast.msg_iovlen = 1;
  246. #ifdef HAVE_MSGHDR_CONTROL
  247. msg_ucast.msg_control = 0;
  248. #endif
  249. #ifdef HAVE_MSGHDR_CONTROLLEN
  250. msg_ucast.msg_controllen = 0;
  251. #endif
  252. #ifdef HAVE_MSGHDR_FLAGS
  253. msg_ucast.msg_flags = 0;
  254. #endif
  255. #ifdef HAVE_MSGHDR_ACCRIGHTS
  256. msg_ucast.msg_accrights = NULL;
  257. #endif
  258. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  259. msg_ucast.msg_accrightslen = 0;
  260. #endif
  261. /*
  262. * Transmit unicast message
  263. * An error here is recovered by totemsrp
  264. */
  265. /*
  266. * If sending to ourself then just pass it through knet back to
  267. * the receive fn. knet does not do local->local delivery
  268. */
  269. if (system_to->nodeid == instance->our_nodeid) {
  270. res = sendmsg (instance->knet_fd+1, &msg_ucast, MSG_NOSIGNAL);
  271. if (res < 0) {
  272. KNET_LOGSYS_PERROR (errno, instance->totemknet_log_level_debug,
  273. "sendmsg(ucast-local) failed (non-critical)");
  274. }
  275. }
  276. else {
  277. res = sendmsg (instance->knet_fd, &msg_ucast, MSG_NOSIGNAL);
  278. if (res < 0) {
  279. KNET_LOGSYS_PERROR (errno, instance->totemknet_log_level_debug,
  280. "sendmsg(ucast) failed (non-critical)");
  281. }
  282. }
  283. }
  284. static inline void mcast_sendmsg (
  285. struct totemknet_instance *instance,
  286. const void *msg,
  287. unsigned int msg_len,
  288. int only_active)
  289. {
  290. int res;
  291. struct totem_message_header *header = (struct totem_message_header *)msg;
  292. struct msghdr msg_mcast;
  293. struct iovec iovec;
  294. iovec.iov_base = (void *)msg;
  295. iovec.iov_len = msg_len;
  296. header->target_nodeid = 0;
  297. /*
  298. * Build multicast message
  299. */
  300. memset(&msg_mcast, 0, sizeof(msg_mcast));
  301. msg_mcast.msg_iov = (void *)&iovec;
  302. msg_mcast.msg_iovlen = 1;
  303. #ifdef HAVE_MSGHDR_CONTROL
  304. msg_mcast.msg_control = 0;
  305. #endif
  306. #ifdef HAVE_MSGHDR_CONTROLLEN
  307. msg_mcast.msg_controllen = 0;
  308. #endif
  309. #ifdef HAVE_MSGHDR_FLAGS
  310. msg_mcast.msg_flags = 0;
  311. #endif
  312. #ifdef HAVE_MSGHDR_ACCRIGHTS
  313. msg_mcast.msg_accrights = NULL;
  314. #endif
  315. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  316. msg_mcast.msg_accrightslen = 0;
  317. #endif
  318. // log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_sendmsg. only_active=%d, len=%d", only_active, msg_len);
  319. res = sendmsg (instance->knet_fd, &msg_mcast, MSG_NOSIGNAL);
  320. if (res < msg_len) {
  321. knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg returned %d", res);
  322. }
  323. /*
  324. * Also send it to ourself, directly into
  325. * the receive fn. knet does not to local->local delivery
  326. */
  327. res = sendmsg (instance->knet_fd+1, &msg_mcast, MSG_NOSIGNAL);
  328. if (res < msg_len) {
  329. knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg (local) returned %d", res);
  330. }
  331. if (!only_active || instance->send_merge_detect_message) {
  332. /*
  333. * Current message was sent to all nodes
  334. */
  335. instance->merge_detect_messages_sent_before_timeout++;
  336. instance->send_merge_detect_message = 0;
  337. }
  338. }
  339. static int node_compare(const void *aptr, const void *bptr)
  340. {
  341. uint16_t a,b;
  342. a = *(uint16_t *)aptr;
  343. b = *(uint16_t *)bptr;
  344. return a > b;
  345. }
  346. int totemknet_ifaces_get (void *knet_context,
  347. char ***status,
  348. unsigned int *iface_count)
  349. {
  350. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  351. struct knet_link_status link_status;
  352. knet_node_id_t host_list[KNET_MAX_HOST];
  353. size_t num_hosts;
  354. int i,j;
  355. char *ptr;
  356. int res = 0;
  357. /*
  358. * Don't do the whole 'link_info' bit if the caller just wants
  359. * a count of interfaces.
  360. */
  361. if (status) {
  362. res = knet_host_get_host_list(instance->knet_handle,
  363. host_list, &num_hosts);
  364. if (res) {
  365. return (-1);
  366. }
  367. qsort(host_list, num_hosts, sizeof(uint16_t), node_compare);
  368. /* num_links is actually the highest link ID */
  369. for (i=0; i <= instance->num_links; i++) {
  370. ptr = instance->link_status[i];
  371. for (j=0; j<num_hosts; j++) {
  372. res = knet_link_get_status(instance->knet_handle,
  373. host_list[j],
  374. i,
  375. &link_status);
  376. if (res == 0) {
  377. ptr[j] = '0' + (link_status.enabled |
  378. link_status.connected<<1 |
  379. link_status.dynconnected<<2);
  380. }
  381. else {
  382. ptr[j] += '?';
  383. }
  384. }
  385. ptr[num_hosts] = '\0';
  386. }
  387. *status = instance->link_status;
  388. }
  389. *iface_count = instance->num_links+1;
  390. return (res);
  391. }
  392. int totemknet_finalize (
  393. void *knet_context)
  394. {
  395. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  396. int res = 0;
  397. knet_log_printf(LOG_DEBUG, "totemknet: finalize");
  398. qb_loop_poll_del (instance->poll_handle, instance->logpipes[0]);
  399. qb_loop_poll_del (instance->poll_handle, instance->knet_fd);
  400. knet_handle_free(instance->knet_handle);
  401. totemknet_stop_merge_detect_timeout(instance);
  402. return (res);
  403. }
  404. static int log_deliver_fn (
  405. int fd,
  406. int revents,
  407. void *data)
  408. {
  409. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  410. char buffer[KNET_MAX_LOG_MSG_SIZE*4];
  411. char *bufptr = buffer;
  412. int done = 0;
  413. int len;
  414. len = read(fd, buffer, sizeof(buffer));
  415. while (done < len) {
  416. struct knet_log_msg *msg = (struct knet_log_msg *)bufptr;
  417. switch (msg->msglevel) {
  418. case KNET_LOG_ERR:
  419. libknet_log_printf (LOGSYS_LEVEL_ERROR, "%s: %s",
  420. knet_log_get_subsystem_name(msg->subsystem),
  421. msg->msg);
  422. break;
  423. case KNET_LOG_WARN:
  424. libknet_log_printf (LOGSYS_LEVEL_WARNING, "%s: %s",
  425. knet_log_get_subsystem_name(msg->subsystem),
  426. msg->msg);
  427. break;
  428. case KNET_LOG_INFO:
  429. libknet_log_printf (LOGSYS_LEVEL_INFO, "%s: %s",
  430. knet_log_get_subsystem_name(msg->subsystem),
  431. msg->msg);
  432. break;
  433. case KNET_LOG_DEBUG:
  434. libknet_log_printf (LOGSYS_LEVEL_DEBUG, "%s: %s",
  435. knet_log_get_subsystem_name(msg->subsystem),
  436. msg->msg);
  437. break;
  438. }
  439. bufptr += KNET_MAX_LOG_MSG_SIZE;
  440. done += KNET_MAX_LOG_MSG_SIZE;
  441. }
  442. return 0;
  443. }
  444. static int data_deliver_fn (
  445. int fd,
  446. int revents,
  447. void *data)
  448. {
  449. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  450. struct mmsghdr msg_recv[MAX_BUFFERS];
  451. struct iovec iov_recv[MAX_BUFFERS];
  452. struct sockaddr_storage system_from;
  453. int msgs_received;
  454. int i;
  455. for (i=0; i<MAX_BUFFERS; i++) {
  456. iov_recv[i].iov_base = instance->iov_buffer[i];
  457. iov_recv[i].iov_len = FRAME_SIZE_MAX;
  458. msg_recv[i].msg_hdr.msg_name = &system_from;
  459. msg_recv[i].msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
  460. msg_recv[i].msg_hdr.msg_iov = &iov_recv[i];
  461. msg_recv[i].msg_hdr.msg_iovlen = 1;
  462. #ifdef HAVE_MSGHDR_CONTROL
  463. msg_recv[i].msg_hdr.msg_control = 0;
  464. #endif
  465. #ifdef HAVE_MSGHDR_CONTROLLEN
  466. msg_recv[i].msg_hdr.msg_controllen = 0;
  467. #endif
  468. #ifdef HAVE_MSGHDR_FLAGS
  469. msg_recv[i].msg_hdr.msg_flags = 0;
  470. #endif
  471. #ifdef HAVE_MSGHDR_ACCRIGHTS
  472. msg_recv[i].msg_hdr.msg_accrights = NULL;
  473. #endif
  474. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  475. msg_recv[i].msg_hdr.msg_accrightslen = 0;
  476. #endif
  477. }
  478. msgs_received = recvmmsg (fd, msg_recv, MAX_BUFFERS, MSG_NOSIGNAL | MSG_DONTWAIT, NULL);
  479. if (msgs_received == -1) {
  480. return (0);
  481. }
  482. for (i=0; i<msgs_received; i++) {
  483. instance->stats_recv += msg_recv[i].msg_len;
  484. /*
  485. * Handle incoming message
  486. */
  487. instance->totemknet_deliver_fn (
  488. instance->context,
  489. instance->iov_buffer[i],
  490. msg_recv[i].msg_len);
  491. }
  492. return (0);
  493. }
  494. static void timer_function_netif_check_timeout (
  495. void *data)
  496. {
  497. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  498. int i;
  499. for (i=0; i<instance->totem_config->interface_count; i++)
  500. instance->totemknet_iface_change_fn (instance->context,
  501. &instance->my_ids[i],
  502. i);
  503. }
  504. static void totemknet_refresh_config(
  505. int32_t event,
  506. const char *key_name,
  507. struct icmap_notify_value new_val,
  508. struct icmap_notify_value old_val,
  509. void *user_data)
  510. {
  511. uint8_t reloading;
  512. uint32_t value;
  513. uint32_t link_no;
  514. size_t num_nodes;
  515. knet_node_id_t host_ids[KNET_MAX_HOST];
  516. int i;
  517. int err;
  518. char path[ICMAP_KEYNAME_MAXLEN];
  519. struct totemknet_instance *instance = (struct totemknet_instance *)user_data;
  520. ENTER();
  521. /*
  522. * If a full reload is in progress then don't do anything until it's done and
  523. * can reconfigure it all atomically
  524. */
  525. if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
  526. return;
  527. }
  528. if (icmap_get_uint32("totem.knet_pmtud_interval", &value) == CS_OK) {
  529. instance->totem_config->knet_pmtud_interval = value;
  530. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pmtud_interval now %d", value);
  531. err = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
  532. if (err) {
  533. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
  534. }
  535. }
  536. /* Get link parameters */
  537. for (i = 0; i <= instance->num_links; i++) {
  538. sprintf(path, "totem.interface.%d.knet_link_priority", i);
  539. if (icmap_get_uint32(path, &value) == CS_OK) {
  540. instance->totem_config->interfaces[i].knet_link_priority = value;
  541. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_link_priority on link %d now %d", i, value);
  542. }
  543. sprintf(path, "totem.interface.%d.knet_ping_interval", i);
  544. if (icmap_get_uint32(path, &value) == CS_OK) {
  545. instance->totem_config->interfaces[i].knet_ping_interval = value;
  546. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_interval on link %d now %d", i, value);
  547. }
  548. sprintf(path, "totem.interface.%d.knet_ping_timeout", i);
  549. if (icmap_get_uint32(path, &value) == CS_OK) {
  550. instance->totem_config->interfaces[i].knet_ping_timeout = value;
  551. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_timeout on link %d now %d", i, value);
  552. }
  553. sprintf(path, "totem.interface.%d.knet_ping_precision", i);
  554. if (icmap_get_uint32(path, &value) == CS_OK) {
  555. instance->totem_config->interfaces[i].knet_ping_precision = value;
  556. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_ping_precision on link %d now %d", i, value);
  557. }
  558. sprintf(path, "totem.interface.%d.knet_pong_count", i);
  559. if (icmap_get_uint32(path, &value) == CS_OK) {
  560. instance->totem_config->interfaces[i].knet_pong_count = value;
  561. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pong_count on link %d now %d", i, value);
  562. }
  563. }
  564. /* Configure link parameters for each node */
  565. err = knet_host_get_host_list(instance->knet_handle, host_ids, &num_nodes);
  566. if (err != 0) {
  567. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list failed");
  568. }
  569. for (i=0; i<num_nodes; i++) {
  570. for (link_no = 0; link_no < instance->num_links; link_no++) {
  571. err = knet_link_set_ping_timers(instance->knet_handle, host_ids[i], link_no,
  572. instance->totem_config->interfaces[link_no].knet_ping_interval,
  573. instance->totem_config->interfaces[link_no].knet_ping_timeout,
  574. instance->totem_config->interfaces[link_no].knet_ping_precision);
  575. if (err) {
  576. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for node %d link %d failed", host_ids[i], link_no);
  577. }
  578. err = knet_link_set_pong_count(instance->knet_handle, host_ids[i], link_no,
  579. instance->totem_config->interfaces[link_no].knet_pong_count);
  580. if (err) {
  581. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for node %d link %d failed",host_ids[i], link_no);
  582. }
  583. err = knet_link_set_priority(instance->knet_handle, host_ids[i], link_no,
  584. instance->totem_config->interfaces[link_no].knet_link_priority);
  585. if (err) {
  586. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for node %d link %d failed", host_ids[i], link_no);
  587. }
  588. }
  589. }
  590. LEAVE();
  591. }
  592. static void totemknet_add_config_notifications(struct totemknet_instance *instance)
  593. {
  594. icmap_track_t icmap_track_totem = NULL;
  595. icmap_track_t icmap_track_reload = NULL;
  596. ENTER();
  597. icmap_track_add("totem.",
  598. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  599. totemknet_refresh_config,
  600. instance,
  601. &icmap_track_totem);
  602. icmap_track_add("config.totemconfig_reload_in_progress",
  603. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  604. totemknet_refresh_config,
  605. instance,
  606. &icmap_track_reload);
  607. LEAVE();
  608. }
  609. /*
  610. * Create an instance
  611. */
  612. int totemknet_initialize (
  613. qb_loop_t *poll_handle,
  614. void **knet_context,
  615. struct totem_config *totem_config,
  616. totemsrp_stats_t *stats,
  617. void *context,
  618. void (*deliver_fn) (
  619. void *context,
  620. const void *msg,
  621. unsigned int msg_len),
  622. void (*iface_change_fn) (
  623. void *context,
  624. const struct totem_ip_address *iface_address,
  625. unsigned int link_no),
  626. void (*mtu_changed) (
  627. void *context,
  628. int net_mtu),
  629. void (*target_set_completed) (
  630. void *context))
  631. {
  632. struct totemknet_instance *instance;
  633. int8_t channel=0;
  634. int res;
  635. int i;
  636. instance = malloc (sizeof (struct totemknet_instance));
  637. if (instance == NULL) {
  638. return (-1);
  639. }
  640. totemknet_instance_initialize (instance);
  641. instance->totem_config = totem_config;
  642. instance->stats = stats;
  643. /*
  644. * Configure logging
  645. */
  646. instance->totemknet_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
  647. instance->totemknet_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  648. instance->totemknet_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  649. instance->totemknet_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  650. instance->totemknet_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  651. instance->totemknet_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  652. instance->totemknet_log_printf = totem_config->totem_logging_configuration.log_printf;
  653. instance->knet_subsys_id = _logsys_subsys_create("KNET", "libknet.h");
  654. /*
  655. * Initialize local variables for totemknet
  656. */
  657. instance->our_nodeid = instance->totem_config->node_id;
  658. for (i=0; i< instance->totem_config->interface_count; i++) {
  659. totemip_copy(&instance->my_ids[i], &totem_config->interfaces[i].bindnet);
  660. instance->my_ids[i].nodeid = instance->our_nodeid;
  661. instance->ip_port[i] = totem_config->interfaces[i].ip_port;
  662. /* Needed for totemsrp */
  663. totem_config->interfaces[i].boundto.nodeid = instance->our_nodeid;
  664. }
  665. instance->poll_handle = poll_handle;
  666. instance->context = context;
  667. instance->totemknet_deliver_fn = deliver_fn;
  668. instance->totemknet_iface_change_fn = iface_change_fn;
  669. instance->totemknet_mtu_changed = mtu_changed;
  670. instance->totemknet_target_set_completed = target_set_completed;
  671. pipe(instance->logpipes);
  672. fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK);
  673. fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK);
  674. instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
  675. if (!instance->knet_handle) {
  676. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
  677. return (-1);
  678. }
  679. res = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
  680. if (res) {
  681. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
  682. }
  683. res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
  684. if (res) {
  685. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
  686. }
  687. res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
  688. if (res) {
  689. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
  690. }
  691. res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
  692. if (res) {
  693. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
  694. }
  695. res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
  696. if (res) {
  697. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
  698. }
  699. /* Get an fd into knet */
  700. instance->knet_fd = 0;
  701. res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
  702. if (res) {
  703. knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
  704. return -1;
  705. }
  706. /* Enable crypto if requested */
  707. if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
  708. struct knet_handle_crypto_cfg crypto_cfg;
  709. strcpy(crypto_cfg.crypto_model, "nss");
  710. strcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type);
  711. strcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type);
  712. memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
  713. crypto_cfg.private_key_len = instance->totem_config->private_key_len;
  714. res = knet_handle_crypto(instance->knet_handle, &crypto_cfg);
  715. if (res == -1) {
  716. knet_log_printf(LOG_ERR, "knet_handle_crypto failed: %s", strerror(errno));
  717. return -1;
  718. }
  719. if (res == -2) {
  720. knet_log_printf(LOG_ERR, "knet_handle_crypto failed: -2");
  721. return -1;
  722. }
  723. knet_log_printf(LOG_INFO, "kronosnet crypto initialized: %s/%s", crypto_cfg.crypto_cipher_type, crypto_cfg.crypto_hash_type);
  724. }
  725. knet_handle_setfwd(instance->knet_handle, 1);
  726. instance->link_mode = KNET_LINK_POLICY_PASSIVE;
  727. if (strcmp(instance->totem_config->link_mode, "active")==0) {
  728. instance->link_mode = KNET_LINK_POLICY_ACTIVE;
  729. }
  730. if (strcmp(instance->totem_config->link_mode, "rr")==0) {
  731. instance->link_mode = KNET_LINK_POLICY_RR;
  732. }
  733. for (i=0; i<INTERFACE_MAX; i++) {
  734. instance->link_status[i] = malloc(CFG_INTERFACE_STATUS_MAX_LEN);
  735. if (!instance->link_status[i]) {
  736. return -1;
  737. }
  738. }
  739. qb_loop_poll_add (instance->poll_handle,
  740. QB_LOOP_MED,
  741. instance->logpipes[0],
  742. POLLIN, instance, log_deliver_fn);
  743. qb_loop_poll_add (instance->poll_handle,
  744. QB_LOOP_HIGH,
  745. instance->knet_fd,
  746. POLLIN, instance, data_deliver_fn);
  747. /*
  748. * Upper layer isn't ready to receive message because it hasn't
  749. * initialized yet. Add short timer to check the interfaces.
  750. */
  751. qb_loop_timer_add (instance->poll_handle,
  752. QB_LOOP_MED,
  753. 100*QB_TIME_NS_IN_MSEC,
  754. (void *)instance,
  755. timer_function_netif_check_timeout,
  756. &instance->timer_netif_check_timeout);
  757. totemknet_start_merge_detect_timeout(instance);
  758. /* Start listening for config changes */
  759. totemknet_add_config_notifications(instance);
  760. knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
  761. *knet_context = instance;
  762. return (0);
  763. }
  764. void *totemknet_buffer_alloc (void)
  765. {
  766. return malloc(KNET_MAX_PACKET_SIZE);
  767. }
  768. void totemknet_buffer_release (void *ptr)
  769. {
  770. return free (ptr);
  771. }
  772. int totemknet_processor_count_set (
  773. void *knet_context,
  774. int processor_count)
  775. {
  776. return (0);
  777. }
  778. int totemknet_recv_flush (void *knet_context)
  779. {
  780. return (0);
  781. }
  782. int totemknet_send_flush (void *knet_context)
  783. {
  784. return (0);
  785. }
  786. int totemknet_token_send (
  787. void *knet_context,
  788. const void *msg,
  789. unsigned int msg_len)
  790. {
  791. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  792. int res = 0;
  793. ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
  794. return (res);
  795. }
  796. int totemknet_mcast_flush_send (
  797. void *knet_context,
  798. const void *msg,
  799. unsigned int msg_len)
  800. {
  801. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  802. int res = 0;
  803. mcast_sendmsg (instance, msg, msg_len, 0);
  804. return (res);
  805. }
  806. int totemknet_mcast_noflush_send (
  807. void *knet_context,
  808. const void *msg,
  809. unsigned int msg_len)
  810. {
  811. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  812. int res = 0;
  813. mcast_sendmsg (instance, msg, msg_len, 1);
  814. return (res);
  815. }
  816. extern int totemknet_iface_check (void *knet_context)
  817. {
  818. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  819. int res = 0;
  820. knet_log_printf(LOG_DEBUG, "totmeknet: iface_check");
  821. return (res);
  822. }
  823. extern void totemknet_net_mtu_adjust (void *knet_context, struct totem_config *totem_config)
  824. {
  825. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  826. knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
  827. }
  828. int totemknet_token_target_set (
  829. void *knet_context,
  830. const struct totem_ip_address *token_target)
  831. {
  832. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  833. int res = 0;
  834. memcpy (&instance->token_target, token_target,
  835. sizeof (struct totem_ip_address));
  836. instance->totemknet_target_set_completed (instance->context);
  837. return (res);
  838. }
  839. extern int totemknet_recv_mcast_empty (
  840. void *knet_context)
  841. {
  842. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  843. unsigned int res;
  844. struct sockaddr_storage system_from;
  845. struct mmsghdr msg_recv[MAX_BUFFERS];
  846. struct iovec iov_recv[MAX_BUFFERS];
  847. struct pollfd ufd;
  848. int nfds;
  849. int msg_processed = 0;
  850. int i;
  851. for (i=0; i<MAX_BUFFERS; i++) {
  852. iov_recv[i].iov_base = instance->iov_buffer[i];
  853. iov_recv[i].iov_len = FRAME_SIZE_MAX;
  854. msg_recv[i].msg_hdr.msg_name = &system_from;
  855. msg_recv[i].msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
  856. msg_recv[i].msg_hdr.msg_iov = &iov_recv[i];
  857. msg_recv[i].msg_hdr.msg_iovlen = 1;
  858. #ifdef HAVE_MSGHDR_CONTROL
  859. msg_recv[i].msg_hdr.msg_control = 0;
  860. #endif
  861. #ifdef HAVE_MSGHDR_CONTROLLEN
  862. msg_recv[i].msg_hdr.msg_controllen = 0;
  863. #endif
  864. #ifdef HAVE_MSGHDR_FLAGS
  865. msg_recv[i].msg_hdr.msg_flags = 0;
  866. #endif
  867. #ifdef HAVE_MSGHDR_ACCRIGHTS
  868. msg_recv[i].msg_hdr.msg_accrights = NULL;
  869. #endif
  870. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  871. msg_recv[i].msg_hdr.msg_accrightslen = 0;
  872. #endif
  873. }
  874. do {
  875. ufd.fd = instance->knet_fd;
  876. ufd.events = POLLIN;
  877. nfds = poll (&ufd, 1, 0);
  878. if (nfds == 1 && ufd.revents & POLLIN) {
  879. res = recvmmsg (instance->knet_fd, msg_recv, MAX_BUFFERS, MSG_NOSIGNAL | MSG_DONTWAIT, NULL);
  880. if (res != -1) {
  881. msg_processed = 1;
  882. } else {
  883. msg_processed = -1;
  884. }
  885. }
  886. } while (nfds == 1);
  887. return (msg_processed);
  888. }
  889. int totemknet_member_add (
  890. void *knet_context,
  891. const struct totem_ip_address *local,
  892. const struct totem_ip_address *member,
  893. int link_no)
  894. {
  895. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  896. int err;
  897. int port = instance->ip_port[link_no];
  898. struct sockaddr_storage remote_ss;
  899. struct sockaddr_storage local_ss;
  900. int addrlen;
  901. if (member->nodeid == instance->our_nodeid) {
  902. return 0; /* Don't add ourself, we send loopback messages directly */
  903. }
  904. /* Keep track of the number of links */
  905. if (link_no > instance->num_links) {
  906. instance->num_links = link_no;
  907. }
  908. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: %d (%s), link=%d", member->nodeid, totemip_print(member), link_no);
  909. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: %d (%s)", local->nodeid, totemip_print(local));
  910. if (link_no == 0) {
  911. if (knet_host_add(instance->knet_handle, member->nodeid)) {
  912. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
  913. return -1;
  914. }
  915. if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
  916. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
  917. return -1;
  918. }
  919. }
  920. /* Casts to remove const */
  921. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)member, port+link_no, &remote_ss, &addrlen);
  922. totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)local, port+link_no, &local_ss, &addrlen);
  923. err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
  924. instance->totem_config->interfaces[link_no].knet_transport,
  925. &local_ss, &remote_ss);
  926. if (err) {
  927. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
  928. return -1;
  929. }
  930. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
  931. instance->totem_config->interfaces[link_no].knet_link_priority);
  932. err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
  933. instance->totem_config->interfaces[link_no].knet_link_priority);
  934. if (err) {
  935. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid %d, link %d failed", member->nodeid, link_no);
  936. }
  937. err = knet_link_set_ping_timers(instance->knet_handle, member->nodeid, link_no,
  938. instance->totem_config->interfaces[link_no].knet_ping_interval,
  939. instance->totem_config->interfaces[link_no].knet_ping_timeout,
  940. instance->totem_config->interfaces[link_no].knet_ping_precision);
  941. if (err) {
  942. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for nodeid %d, link %d failed", member->nodeid, link_no);
  943. }
  944. err = knet_link_set_pong_count(instance->knet_handle, member->nodeid, link_no,
  945. instance->totem_config->interfaces[link_no].knet_pong_count);
  946. if (err) {
  947. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for nodeid %d, link %d failed", member->nodeid, link_no);
  948. }
  949. err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
  950. if (err) {
  951. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid %d, link %d failed", member->nodeid, link_no);
  952. return -1;
  953. }
  954. return (0);
  955. }
  956. int totemknet_member_remove (
  957. void *knet_context,
  958. const struct totem_ip_address *token_target,
  959. int link_no)
  960. {
  961. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  962. int res;
  963. knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: %d, link=%d", token_target->nodeid, link_no);
  964. if (token_target->nodeid == instance->our_nodeid) {
  965. return 0; /* Don't remove ourself */
  966. }
  967. /* Remove the link first */
  968. res = knet_link_set_enable(instance->knet_handle, token_target->nodeid, link_no, 0);
  969. if (res != 0) {
  970. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set enable(off) for nodeid %d, link %d failed", token_target->nodeid, link_no);
  971. return res;
  972. }
  973. res = knet_link_clear_config(instance->knet_handle, token_target->nodeid, link_no);
  974. if (res != 0) {
  975. KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_clear_config for nodeid %d, link %d failed", token_target->nodeid, link_no);
  976. return res;
  977. }
  978. return knet_host_remove(instance->knet_handle, token_target->nodeid);
  979. }
  980. int totemknet_member_list_rebind_ip (
  981. void *knet_context)
  982. {
  983. return (0);
  984. }
  985. static void timer_function_merge_detect_timeout (
  986. void *data)
  987. {
  988. struct totemknet_instance *instance = (struct totemknet_instance *)data;
  989. if (instance->merge_detect_messages_sent_before_timeout == 0) {
  990. instance->send_merge_detect_message = 1;
  991. }
  992. instance->merge_detect_messages_sent_before_timeout = 0;
  993. totemknet_start_merge_detect_timeout(instance);
  994. }
  995. static void totemknet_start_merge_detect_timeout(
  996. void *knet_context)
  997. {
  998. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  999. qb_loop_timer_add(instance->poll_handle,
  1000. QB_LOOP_MED,
  1001. instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
  1002. (void *)instance,
  1003. timer_function_merge_detect_timeout,
  1004. &instance->timer_merge_detect_timeout);
  1005. }
  1006. static void totemknet_stop_merge_detect_timeout(
  1007. void *knet_context)
  1008. {
  1009. struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
  1010. qb_loop_timer_del(instance->poll_handle,
  1011. instance->timer_merge_detect_timeout);
  1012. }