totemknet.c 36 KB

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