corosync  3.0.2
totemknet.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Christine Caulfield (ccaulfie@redhat.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 
35 #include <config.h>
36 
37 #include <assert.h>
38 #include <sys/mman.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <sys/socket.h>
42 #include <netdb.h>
43 #include <sys/un.h>
44 #include <sys/ioctl.h>
45 #include <sys/param.h>
46 #include <netinet/in.h>
47 #include <net/ethernet.h>
48 #include <arpa/inet.h>
49 #include <unistd.h>
50 #include <fcntl.h>
51 #include <stdlib.h>
52 #include <stdio.h>
53 #include <errno.h>
54 #include <sched.h>
55 #include <time.h>
56 #include <sys/time.h>
57 #include <sys/poll.h>
58 #include <sys/uio.h>
59 #include <limits.h>
60 
61 #include <qb/qbdefs.h>
62 #include <qb/qbloop.h>
63 #ifdef HAVE_LIBNOZZLE
64 #include <libgen.h>
65 #include <libnozzle.h>
66 #endif
67 
68 #include <corosync/sq.h>
69 #include <corosync/swab.h>
70 #include <corosync/logsys.h>
71 #include <corosync/icmap.h>
72 #include <corosync/totem/totemip.h>
73 #include "totemknet.h"
74 
75 #include "main.h"
76 #include "util.h"
77 
78 #include <libknet.h>
80 
81 #ifndef MSG_NOSIGNAL
82 #define MSG_NOSIGNAL 0
83 #endif
84 
85 #ifdef HAVE_LIBNOZZLE
86 static int setup_nozzle(void *knet_context);
87 #endif
88 
89 /* Should match that used by cfg */
90 #define CFG_INTERFACE_STATUS_MAX_LEN 512
91 
93  struct crypto_instance *crypto_inst;
94 
95  qb_loop_t *poll_handle;
96 
97  knet_handle_t knet_handle;
98 
99  int link_mode;
100 
101  void *context;
102 
104  void *context,
105  const void *msg,
106  unsigned int msg_len,
107  const struct sockaddr_storage *system_from);
108 
110  void *context,
111  const struct totem_ip_address *iface_address,
112  unsigned int link_no);
113 
115  void *context,
116  int net_mtu);
117 
119 
120  /*
121  * Function and data used to log messages
122  */
124 
126 
128 
130 
132 
134 
136 
138  int level,
139  int subsys,
140  const char *function,
141  const char *file,
142  int line,
143  const char *format,
144  ...)__attribute__((format(printf, 6, 7)));
145 
146  void *knet_context;
147 
148  char iov_buffer[KNET_MAX_PACKET_SIZE];
149 
151 
153 
155 
157 
159 
161 
163 
164  qb_loop_timer_handle timer_netif_check_timeout;
165 
166  qb_loop_timer_handle timer_merge_detect_timeout;
167 
169 
171 
172  int logpipes[2];
173  int knet_fd;
174 #ifdef HAVE_LIBNOZZLE
175  char *nozzle_name;
176  char *nozzle_ipaddr;
177  char *nozzle_prefix;
178  char *nozzle_macaddr;
179  nozzle_t nozzle_handle;
180 #endif
181 };
182 
183 /* Awkward. But needed to get stats from knet */
185 
186 struct work_item {
187  const void *msg;
188  unsigned int msg_len;
190 };
191 
193  void *knet_context);
194 
195 static void totemknet_start_merge_detect_timeout(
196  void *knet_context);
197 
198 static void totemknet_stop_merge_detect_timeout(
199  void *knet_context);
200 
201 static void log_flush_messages (
202  void *knet_context);
203 
204 static void totemknet_instance_initialize (struct totemknet_instance *instance)
205 {
206  memset (instance, 0, sizeof (struct totemknet_instance));
207 }
208 
209 #define knet_log_printf(level, format, args...) \
210 do { \
211  instance->totemknet_log_printf ( \
212  level, instance->totemknet_subsys_id, \
213  __FUNCTION__, __FILE__, __LINE__, \
214  (const char *)format, ##args); \
215 } while (0);
216 
217 #define libknet_log_printf(level, format, args...) \
218 do { \
219  instance->totemknet_log_printf ( \
220  level, instance->knet_subsys_id, \
221  __FUNCTION__, "libknet.h", __LINE__, \
222  (const char *)format, ##args); \
223 } while (0);
224 
225 #define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
226 do { \
227  char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
228  const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
229  instance->totemknet_log_printf ( \
230  level, instance->totemknet_subsys_id, \
231  __FUNCTION__, __FILE__, __LINE__, \
232  fmt ": %s (%d)", ##args, _error_ptr, err_num); \
233  } while(0)
234 
235 
236 #ifdef HAVE_LIBNOZZLE
237 static inline int is_ether_addr_multicast(const uint8_t *addr)
238 {
239  return (addr[0] & 0x01);
240 }
241 static inline int is_ether_addr_zero(const uint8_t *addr)
242 {
243  return (!addr[0] && !addr[1] && !addr[2] && !addr[3] && !addr[4] && !addr[5]);
244 }
245 
246 static int ether_host_filter_fn(void *private_data,
247  const unsigned char *outdata,
248  ssize_t outdata_len,
249  uint8_t tx_rx,
250  knet_node_id_t this_host_id,
251  knet_node_id_t src_host_id,
252  int8_t *channel,
253  knet_node_id_t *dst_host_ids,
254  size_t *dst_host_ids_entries)
255 {
256  struct ether_header *eth_h = (struct ether_header *)outdata;
257  uint8_t *dst_mac = (uint8_t *)eth_h->ether_dhost;
258  uint16_t dst_host_id;
259 
260  if (is_ether_addr_zero(dst_mac))
261  return -1;
262 
263  if (is_ether_addr_multicast(dst_mac)) {
264  return 1;
265  }
266 
267  memmove(&dst_host_id, &dst_mac[4], 2);
268 
269  dst_host_ids[0] = ntohs(dst_host_id);
270  *dst_host_ids_entries = 1;
271 
272  return 0;
273 }
274 #endif
275 
276 static int dst_host_filter_callback_fn(void *private_data,
277  const unsigned char *outdata,
278  ssize_t outdata_len,
279  uint8_t tx_rx,
280  knet_node_id_t this_host_id,
281  knet_node_id_t src_host_id,
282  int8_t *channel,
283  knet_node_id_t *dst_host_ids,
284  size_t *dst_host_ids_entries)
285 {
286  struct totem_message_header *header = (struct totem_message_header *)outdata;
287  int res;
288 
289 #ifdef HAVE_LIBNOZZLE
290  if (*channel != 0) {
291  return ether_host_filter_fn(private_data,
292  outdata, outdata_len,
293  tx_rx,
294  this_host_id, src_host_id,
295  channel,
296  dst_host_ids,
297  dst_host_ids_entries);
298  }
299 #endif
300  if (header->target_nodeid) {
301  dst_host_ids[0] = header->target_nodeid;
302  *dst_host_ids_entries = 1;
303  res = 0; /* unicast message */
304  }
305  else {
306  *dst_host_ids_entries = 0;
307  res = 1; /* multicast message */
308  }
309  return res;
310 }
311 
312 static void socket_error_callback_fn(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)
313 {
314  struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
315 
316  knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet socket ERROR notification called: txrx=%d, error=%d, errorno=%d", tx_rx, error, errorno);
317  if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
318  knet_handle_remove_datafd(instance->knet_handle, datafd);
319  }
320 }
321 
322 static void host_change_callback_fn(void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
323 {
324  struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
325 
326  // TODO: what? if anything.
327  knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet host change callback. nodeid: %d reachable: %d", host_id, reachable);
328 }
329 
330 static void pmtu_change_callback_fn(void *private_data, unsigned int data_mtu)
331 {
332  struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
333  knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet pMTU change: %d", data_mtu);
334 
335  /* We don't need to tell corosync the actual knet MTU */
336 // instance->totemknet_mtu_changed(instance->context, data_mtu);
337 }
338 
340  void *knet_context,
341  const char *cipher_type,
342  const char *hash_type)
343 {
344  return (0);
345 }
346 
347 
348 static inline void ucast_sendmsg (
349  struct totemknet_instance *instance,
350  struct totem_ip_address *system_to,
351  const void *msg,
352  unsigned int msg_len)
353 {
354  int res = 0;
355  struct totem_message_header *header = (struct totem_message_header *)msg;
356  struct msghdr msg_ucast;
357  struct iovec iovec;
358 
359  header->target_nodeid = system_to->nodeid;
360 
361  iovec.iov_base = (void *)msg;
362  iovec.iov_len = msg_len;
363 
364  /*
365  * Build unicast message
366  */
367  memset(&msg_ucast, 0, sizeof(msg_ucast));
368  msg_ucast.msg_iov = (void *)&iovec;
369  msg_ucast.msg_iovlen = 1;
370 #ifdef HAVE_MSGHDR_CONTROL
371  msg_ucast.msg_control = 0;
372 #endif
373 #ifdef HAVE_MSGHDR_CONTROLLEN
374  msg_ucast.msg_controllen = 0;
375 #endif
376 #ifdef HAVE_MSGHDR_FLAGS
377  msg_ucast.msg_flags = 0;
378 #endif
379 #ifdef HAVE_MSGHDR_ACCRIGHTS
380  msg_ucast.msg_accrights = NULL;
381 #endif
382 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
383  msg_ucast.msg_accrightslen = 0;
384 #endif
385 
386  /*
387  * Transmit unicast message
388  * An error here is recovered by totemsrp
389  */
390 
391  res = sendmsg (instance->knet_fd, &msg_ucast, MSG_NOSIGNAL);
392  if (res < 0) {
394  "sendmsg(ucast) failed (non-critical)");
395  }
396 }
397 
398 static inline void mcast_sendmsg (
399  struct totemknet_instance *instance,
400  const void *msg,
401  unsigned int msg_len,
402  int only_active)
403 {
404  int res;
405  struct totem_message_header *header = (struct totem_message_header *)msg;
406  struct msghdr msg_mcast;
407  struct iovec iovec;
408 
409  iovec.iov_base = (void *)msg;
410  iovec.iov_len = msg_len;
411 
412  header->target_nodeid = 0;
413 
414  /*
415  * Build multicast message
416  */
417  memset(&msg_mcast, 0, sizeof(msg_mcast));
418  msg_mcast.msg_iov = (void *)&iovec;
419  msg_mcast.msg_iovlen = 1;
420 #ifdef HAVE_MSGHDR_CONTROL
421  msg_mcast.msg_control = 0;
422 #endif
423 #ifdef HAVE_MSGHDR_CONTROLLEN
424  msg_mcast.msg_controllen = 0;
425 #endif
426 #ifdef HAVE_MSGHDR_FLAGS
427  msg_mcast.msg_flags = 0;
428 #endif
429 #ifdef HAVE_MSGHDR_ACCRIGHTS
430  msg_mcast.msg_accrights = NULL;
431 #endif
432 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
433  msg_mcast.msg_accrightslen = 0;
434 #endif
435 
436 
437 // log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_sendmsg. only_active=%d, len=%d", only_active, msg_len);
438 
439  res = sendmsg (instance->knet_fd, &msg_mcast, MSG_NOSIGNAL);
440  if (res < msg_len) {
441  knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg returned %d", res);
442  }
443 
444  if (!only_active || instance->send_merge_detect_message) {
445  /*
446  * Current message was sent to all nodes
447  */
449  instance->send_merge_detect_message = 0;
450  }
451 }
452 
453 static int node_compare(const void *aptr, const void *bptr)
454 {
455  uint16_t a,b;
456 
457  a = *(uint16_t *)aptr;
458  b = *(uint16_t *)bptr;
459 
460  return a > b;
461 }
462 
464  char ***status,
465  unsigned int *iface_count)
466 {
467  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
468  struct knet_link_status link_status;
469  knet_node_id_t host_list[KNET_MAX_HOST];
470  uint8_t link_list[KNET_MAX_LINK];
471  size_t num_hosts;
472  size_t num_links;
473  size_t link_idx;
474  int i,j;
475  char *ptr;
476  int res = 0;
477 
478  /*
479  * Don't do the whole 'link_info' bit if the caller just wants
480  * a count of interfaces.
481  */
482  if (status) {
483 
484  res = knet_host_get_host_list(instance->knet_handle,
485  host_list, &num_hosts);
486  if (res) {
487  return (-1);
488  }
489  qsort(host_list, num_hosts, sizeof(uint16_t), node_compare);
490 
491  for (i=0; i<INTERFACE_MAX; i++) {
492  memset(instance->link_status[i], 'n', CFG_INTERFACE_STATUS_MAX_LEN-1);
493  instance->link_status[i][num_hosts] = '\0';
494  }
495 
496  /* This is all a bit "inside-out" because "status" is a set of strings per link
497  * and knet orders things by host
498  */
499  for (j=0; j<num_hosts; j++) {
500  res = knet_link_get_link_list(instance->knet_handle,
501  host_list[j], link_list, &num_links);
502  if (res) {
503  return (-1);
504  }
505 
506  link_idx = 0;
507  for (i=0; i < num_links; i++) {
508  /*
509  * Skip over links that are unconfigured to corosync. This is basically
510  * link0 if corosync isn't using it for comms, as we will still
511  * have it set up for loopback.
512  */
513  if (!instance->totem_config->interfaces[link_list[i]].configured) {
514  continue;
515  }
516  ptr = instance->link_status[link_idx++];
517 
518  res = knet_link_get_status(instance->knet_handle,
519  host_list[j],
520  link_list[i],
521  &link_status,
522  sizeof(link_status));
523  if (res == 0) {
524  ptr[j] = '0' + (link_status.enabled |
525  link_status.connected<<1 |
526  link_status.dynconnected<<2);
527  }
528  else {
529  ptr[j] = '?';
530  }
531  }
532  }
533  *status = instance->link_status;
534  }
535 
536  *iface_count = INTERFACE_MAX;
537 
538  return (res);
539 }
540 
542  void *knet_context)
543 {
544  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
545  int res = 0;
546  int i,j;
547  static knet_node_id_t nodes[KNET_MAX_HOST]; /* static to save stack */
548  uint8_t links[KNET_MAX_LINK];
549  size_t num_nodes;
550  size_t num_links;
551 
552  knet_log_printf(LOG_DEBUG, "totemknet: finalize");
553 
554  qb_loop_poll_del (instance->poll_handle, instance->logpipes[0]);
555  qb_loop_poll_del (instance->poll_handle, instance->knet_fd);
556 
557  res = knet_host_get_host_list(instance->knet_handle, nodes, &num_nodes);
558  if (res) {
559  knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet node list for shutdown: %s", strerror(errno));
560  /* Crash out anyway */
561  goto finalise_error;
562  }
563 
564  /* Tidily shut down all nodes & links. This ensures that the LEAVE message will be sent */
565  for (i=0; i<num_nodes; i++) {
566 
567  res = knet_link_get_link_list(instance->knet_handle, nodes[i], links, &num_links);
568  if (res) {
569  knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet link list for node %d: %s", nodes[i], strerror(errno));
570  goto finalise_error;
571  }
572  for (j=0; j<num_links; j++) {
573  res = knet_link_set_enable(instance->knet_handle, nodes[i], links[j], 0);
574  if (res) {
575  knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_set_enable(node %d, link %d) failed: %s", nodes[i], links[j], strerror(errno));
576  }
577  res = knet_link_clear_config(instance->knet_handle, nodes[i], links[j]);
578  if (res) {
579  knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_clear_config(node %d, link %d) failed: %s", nodes[i], links[j], strerror(errno));
580  }
581  }
582  res = knet_host_remove(instance->knet_handle, nodes[i]);
583  if (res) {
584  knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_host_remove(node %d) failed: %s", nodes[i], strerror(errno));
585  }
586  }
587 
588 finalise_error:
589  res = knet_handle_setfwd(instance->knet_handle, 0);
590  if (res) {
591  knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_setfwd failed: %s", strerror(errno));
592  }
593  res = knet_handle_free(instance->knet_handle);
594  if (res) {
595  knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_free failed: %s", strerror(errno));
596  }
597 
598  totemknet_stop_merge_detect_timeout(instance);
599 
600  log_flush_messages(instance);
601 
602  return (res);
603 }
604 
605 static int log_deliver_fn (
606  int fd,
607  int revents,
608  void *data)
609 {
610  struct totemknet_instance *instance = (struct totemknet_instance *)data;
611  char buffer[sizeof(struct knet_log_msg)*4];
612  char *bufptr = buffer;
613  int done = 0;
614  int len;
615 
616  len = read(fd, buffer, sizeof(buffer));
617  while (done < len) {
618  struct knet_log_msg *msg = (struct knet_log_msg *)bufptr;
619  switch (msg->msglevel) {
620  case KNET_LOG_ERR:
622  knet_log_get_subsystem_name(msg->subsystem),
623  msg->msg);
624  break;
625  case KNET_LOG_WARN:
627  knet_log_get_subsystem_name(msg->subsystem),
628  msg->msg);
629  break;
630  case KNET_LOG_INFO:
632  knet_log_get_subsystem_name(msg->subsystem),
633  msg->msg);
634  break;
635  case KNET_LOG_DEBUG:
637  knet_log_get_subsystem_name(msg->subsystem),
638  msg->msg);
639  break;
640  }
641  bufptr += sizeof(struct knet_log_msg);
642  done += sizeof(struct knet_log_msg);
643  }
644  return 0;
645 }
646 
647 static int data_deliver_fn (
648  int fd,
649  int revents,
650  void *data)
651 {
652  struct totemknet_instance *instance = (struct totemknet_instance *)data;
653  struct msghdr msg_hdr;
654  struct iovec iov_recv;
655  struct sockaddr_storage system_from;
656  ssize_t msg_len;
657  int truncated_packet;
658 
659  iov_recv.iov_base = instance->iov_buffer;
660  iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
661 
662  msg_hdr.msg_name = &system_from;
663  msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
664  msg_hdr.msg_iov = &iov_recv;
665  msg_hdr.msg_iovlen = 1;
666 #ifdef HAVE_MSGHDR_CONTROL
667  msg_hdr.msg_control = 0;
668 #endif
669 #ifdef HAVE_MSGHDR_CONTROLLEN
670  msg_hdr.msg_controllen = 0;
671 #endif
672 #ifdef HAVE_MSGHDR_FLAGS
673  msg_hdr.msg_flags = 0;
674 #endif
675 #ifdef HAVE_MSGHDR_ACCRIGHTS
676  msg_hdr.msg_accrights = NULL;
677 #endif
678 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
679  msg_hdr.msg_accrightslen = 0;
680 #endif
681 
682  msg_len = recvmsg (fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
683  if (msg_len <= 0) {
684  return (0);
685  }
686 
687  truncated_packet = 0;
688 
689 #ifdef HAVE_MSGHDR_FLAGS
690  if (msg_hdr.msg_flags & MSG_TRUNC) {
691  truncated_packet = 1;
692  }
693 #else
694  /*
695  * We don't have MSGHDR_FLAGS, but we can (hopefully) safely make assumption that
696  * if bytes_received == KNET_MAX_PACKET_SIZE then packet is truncated
697  */
698  if (bytes_received == KNET_MAX_PACKET_SIZE) {
699  truncated_packet = 1;
700  }
701 #endif
702 
703  if (truncated_packet) {
705  "Received too big message. This may be because something bad is happening"
706  "on the network (attack?), or you tried join more nodes than corosync is"
707  "compiled with (%u) or bug in the code (bad estimation of "
708  "the KNET_MAX_PACKET_SIZE). Dropping packet.", PROCESSOR_COUNT_MAX);
709  return (0);
710  }
711 
712  /*
713  * Handle incoming message
714  */
715  instance->totemknet_deliver_fn (
716  instance->context,
717  instance->iov_buffer,
718  msg_len,
719  &system_from);
720 
721  return (0);
722 }
723 
724 static void timer_function_netif_check_timeout (
725  void *data)
726 {
727  struct totemknet_instance *instance = (struct totemknet_instance *)data;
728  int i;
729 
730  for (i=0; i < INTERFACE_MAX; i++) {
731  if (!instance->totem_config->interfaces[i].configured) {
732  continue;
733  }
734  instance->totemknet_iface_change_fn (instance->context,
735  &instance->my_ids[i],
736  i);
737  }
738 }
739 
740 static void knet_set_access_list_config(struct totemknet_instance *instance)
741 {
742 #ifdef HAVE_KNET_ACCESS_LIST
743  uint32_t value;
744  cs_error_t err;
745 
746  value = instance->totem_config->block_unlisted_ips;
747  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_enable access list: %d", value);
748 
749  err = knet_handle_enable_access_lists(instance->knet_handle, value);
750  if (err) {
751  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_access_lists failed");
752  }
753 #endif
754 }
755 
756 
757 /* NOTE: this relies on the fact that totem_reload_notify() is called first */
758 static void totemknet_refresh_config(
759  int32_t event,
760  const char *key_name,
761  struct icmap_notify_value new_val,
762  struct icmap_notify_value old_val,
763  void *user_data)
764 {
765  uint8_t reloading;
766  uint32_t value;
767  uint32_t link_no;
768  size_t num_nodes;
769  knet_node_id_t host_ids[KNET_MAX_HOST];
770  int i;
771  int err;
772  struct totemknet_instance *instance = (struct totemknet_instance *)user_data;
773 
774  ENTER();
775 
776  /*
777  * If a full reload is in progress then don't do anything until it's done and
778  * can reconfigure it all atomically
779  */
780  if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
781  return;
782  }
783 
784  knet_set_access_list_config(instance);
785 
786  if (icmap_get_uint32("totem.knet_pmtud_interval", &value) == CS_OK) {
787 
789  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pmtud_interval now %d", value);
790  err = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
791  if (err) {
792  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
793  }
794  }
795 
796  /* Configure link parameters for each node */
797  err = knet_host_get_host_list(instance->knet_handle, host_ids, &num_nodes);
798  if (err != 0) {
799  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list failed");
800  }
801 
802  for (i=0; i<num_nodes; i++) {
803  for (link_no = 0; link_no < INTERFACE_MAX; link_no++) {
804  if (host_ids[i] == instance->our_nodeid || !instance->totem_config->interfaces[link_no].configured) {
805  continue;
806  }
807 
808  err = knet_link_set_ping_timers(instance->knet_handle, host_ids[i], link_no,
809  instance->totem_config->interfaces[link_no].knet_ping_interval,
810  instance->totem_config->interfaces[link_no].knet_ping_timeout,
811  instance->totem_config->interfaces[link_no].knet_ping_precision);
812  if (err) {
813  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for node %d link %d failed", host_ids[i], link_no);
814  }
815  err = knet_link_set_pong_count(instance->knet_handle, host_ids[i], link_no,
816  instance->totem_config->interfaces[link_no].knet_pong_count);
817  if (err) {
818  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for node %d link %d failed",host_ids[i], link_no);
819  }
820  err = knet_link_set_priority(instance->knet_handle, host_ids[i], link_no,
821  instance->totem_config->interfaces[link_no].knet_link_priority);
822  if (err) {
823  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for node %d link %d failed", host_ids[i], link_no);
824  }
825 
826  }
827  }
828 
829  LEAVE();
830 }
831 
832 static void totemknet_add_config_notifications(struct totemknet_instance *instance)
833 {
834  icmap_track_t icmap_track_totem = NULL;
835  icmap_track_t icmap_track_reload = NULL;
836 
837  ENTER();
838 
839  icmap_track_add("totem.",
841  totemknet_refresh_config,
842  instance,
843  &icmap_track_totem);
844 
845  icmap_track_add("config.totemconfig_reload_in_progress",
847  totemknet_refresh_config,
848  instance,
849  &icmap_track_reload);
850 
851  LEAVE();
852 }
853 
854 /*
855  * Create an instance
856  */
858  qb_loop_t *poll_handle,
859  void **knet_context,
860  struct totem_config *totem_config,
861  totemsrp_stats_t *stats,
862  void *context,
863 
864  void (*deliver_fn) (
865  void *context,
866  const void *msg,
867  unsigned int msg_len,
868  const struct sockaddr_storage *system_from),
869 
870  void (*iface_change_fn) (
871  void *context,
872  const struct totem_ip_address *iface_address,
873  unsigned int link_no),
874 
875  void (*mtu_changed) (
876  void *context,
877  int net_mtu),
878 
879  void (*target_set_completed) (
880  void *context))
881 {
882  struct totemknet_instance *instance;
883  int8_t channel=0;
884  int res;
885  int i;
886 
887  instance = malloc (sizeof (struct totemknet_instance));
888  if (instance == NULL) {
889  return (-1);
890  }
891 
892  totemknet_instance_initialize (instance);
893 
894  instance->totem_config = totem_config;
895 
896  /*
897  * Configure logging
898  */
899  instance->totemknet_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
906 
907  instance->knet_subsys_id = _logsys_subsys_create("KNET", "libknet.h");
908 
909  /*
910  * Initialize local variables for totemknet
911  */
912 
913  instance->our_nodeid = instance->totem_config->node_id;
914 
915  for (i=0; i< INTERFACE_MAX; i++) {
916  totemip_copy(&instance->my_ids[i], &totem_config->interfaces[i].bindnet);
917  instance->my_ids[i].nodeid = instance->our_nodeid;
918  instance->ip_port[i] = totem_config->interfaces[i].ip_port;
919 
920  /* Needed for totemsrp */
921  totem_config->interfaces[i].boundto.nodeid = instance->our_nodeid;
922  }
923 
924  instance->poll_handle = poll_handle;
925 
926  instance->context = context;
927  instance->totemknet_deliver_fn = deliver_fn;
928 
929  instance->totemknet_iface_change_fn = iface_change_fn;
930 
931  instance->totemknet_mtu_changed = mtu_changed;
932 
933  instance->totemknet_target_set_completed = target_set_completed;
934 
935  instance->loopback_link = 0;
936 
937  res = pipe(instance->logpipes);
938  if (res == -1) {
939  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to create pipe for instance->logpipes");
940  goto exit_error;
941  }
942  fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK);
943  fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK);
944 
945 #if !defined(KNET_API_VER) || (KNET_API_VER == 1)
946  instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
947 #endif
948 #if KNET_API_VER == 2
949  instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, KNET_HANDLE_FLAG_PRIVILEGED);
950 #endif
951 
952  if (!instance->knet_handle) {
953  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
954  goto exit_error;
955  }
956 
957  knet_set_access_list_config(instance);
958 
959  res = knet_handle_pmtud_setfreq(instance->knet_handle, instance->totem_config->knet_pmtud_interval);
960  if (res) {
961  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
962  }
963  res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
964  if (res) {
965  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
966  }
967  res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
968  if (res) {
969  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
970  }
971  res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
972  if (res) {
973  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
974  }
975  res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
976  if (res) {
977  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
978  }
979  global_instance = instance;
980 
981  /* Get an fd into knet */
982  instance->knet_fd = 0;
983  res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
984  if (res) {
985  knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
986  goto exit_error;
987  }
988 
989  /* Enable crypto if requested */
990  if (strcmp(instance->totem_config->crypto_cipher_type, "none") != 0) {
991  struct knet_handle_crypto_cfg crypto_cfg;
992 
993  strcpy(crypto_cfg.crypto_model, instance->totem_config->crypto_model);
994  strcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type);
995  strcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type);
996  memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
997  crypto_cfg.private_key_len = instance->totem_config->private_key_len;
998 
999  res = knet_handle_crypto(instance->knet_handle, &crypto_cfg);
1000  if (res == -1) {
1001  knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: %s", strerror(errno));
1002  goto exit_error;
1003  }
1004  if (res == -2) {
1005  knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: -2");
1006  goto exit_error;
1007  }
1008  knet_log_printf(LOG_INFO, "kronosnet crypto initialized: %s/%s", crypto_cfg.crypto_cipher_type, crypto_cfg.crypto_hash_type);
1009  }
1010 
1011  /* Set up compression */
1012  totemknet_reconfigure(instance, instance->totem_config);
1013 
1014  knet_handle_setfwd(instance->knet_handle, 1);
1015 
1016  instance->link_mode = KNET_LINK_POLICY_PASSIVE;
1017  if (strcmp(instance->totem_config->link_mode, "active")==0) {
1018  instance->link_mode = KNET_LINK_POLICY_ACTIVE;
1019  }
1020  if (strcmp(instance->totem_config->link_mode, "rr")==0) {
1021  instance->link_mode = KNET_LINK_POLICY_RR;
1022  }
1023 
1024  for (i=0; i<INTERFACE_MAX; i++) {
1025  instance->link_status[i] = malloc(CFG_INTERFACE_STATUS_MAX_LEN);
1026  if (!instance->link_status[i]) {
1027  goto exit_error;
1028  }
1029  }
1030 
1031  qb_loop_poll_add (instance->poll_handle,
1032  QB_LOOP_MED,
1033  instance->logpipes[0],
1034  POLLIN, instance, log_deliver_fn);
1035 
1036  qb_loop_poll_add (instance->poll_handle,
1037  QB_LOOP_HIGH,
1038  instance->knet_fd,
1039  POLLIN, instance, data_deliver_fn);
1040 
1041  /*
1042  * Upper layer isn't ready to receive message because it hasn't
1043  * initialized yet. Add short timer to check the interfaces.
1044  */
1045  qb_loop_timer_add (instance->poll_handle,
1046  QB_LOOP_MED,
1047  100*QB_TIME_NS_IN_MSEC,
1048  (void *)instance,
1049  timer_function_netif_check_timeout,
1050  &instance->timer_netif_check_timeout);
1051 
1052  totemknet_start_merge_detect_timeout(instance);
1053 
1054  /* Start listening for config changes */
1055  totemknet_add_config_notifications(instance);
1056 
1057  /* Add stats keys to icmap */
1059 
1060  knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
1061  *knet_context = instance;
1062 
1063  return (0);
1064 
1065 exit_error:
1066  log_flush_messages(instance);
1067  free(instance);
1068  return (-1);
1069 }
1070 
1072 {
1073  /* Need to have space for a message AND a struct mcast in case of encapsulated messages */
1074  return malloc(KNET_MAX_PACKET_SIZE + 512);
1075 }
1076 
1078 {
1079  return free (ptr);
1080 }
1081 
1083  void *knet_context,
1084  int processor_count)
1085 {
1086  return (0);
1087 }
1088 
1089 int totemknet_recv_flush (void *knet_context)
1090 {
1091  return (0);
1092 }
1093 
1094 int totemknet_send_flush (void *knet_context)
1095 {
1096  return (0);
1097 }
1098 
1100  void *knet_context,
1101  const void *msg,
1102  unsigned int msg_len)
1103 {
1104  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1105  int res = 0;
1106 
1107  ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1108 
1109  return (res);
1110 }
1112  void *knet_context,
1113  const void *msg,
1114  unsigned int msg_len)
1115 {
1116  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1117  int res = 0;
1118 
1119  mcast_sendmsg (instance, msg, msg_len, 0);
1120 
1121  return (res);
1122 }
1123 
1125  void *knet_context,
1126  const void *msg,
1127  unsigned int msg_len)
1128 {
1129  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1130  int res = 0;
1131 
1132  mcast_sendmsg (instance, msg, msg_len, 1);
1133 
1134  return (res);
1135 }
1136 
1137 
1138 extern int totemknet_iface_check (void *knet_context)
1139 {
1140  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1141  int res = 0;
1142 
1143  knet_log_printf(LOG_DEBUG, "totemknet: iface_check");
1144 
1145  return (res);
1146 }
1147 
1148 extern void totemknet_net_mtu_adjust (void *knet_context, struct totem_config *totem_config)
1149 {
1150  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1151 
1152  knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
1153 }
1154 
1156  void *knet_context,
1157  unsigned int nodeid)
1158 {
1159  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1160  int res = 0;
1161 
1162  instance->token_target.nodeid = nodeid;
1163 
1164  instance->totemknet_target_set_completed (instance->context);
1165 
1166  return (res);
1167 }
1168 
1170  void *knet_context)
1171 {
1172  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1173  unsigned int res;
1174  struct sockaddr_storage system_from;
1175  struct msghdr msg_hdr;
1176  struct iovec iov_recv;
1177  struct pollfd ufd;
1178  int nfds;
1179  int msg_processed = 0;
1180 
1181  iov_recv.iov_base = instance->iov_buffer;
1182  iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
1183 
1184  msg_hdr.msg_name = &system_from;
1185  msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
1186  msg_hdr.msg_iov = &iov_recv;
1187  msg_hdr.msg_iovlen = 1;
1188 #ifdef HAVE_MSGHDR_CONTROL
1189  msg_hdr.msg_control = 0;
1190 #endif
1191 #ifdef HAVE_MSGHDR_CONTROLLEN
1192  msg_hdr.msg_controllen = 0;
1193 #endif
1194 #ifdef HAVE_MSGHDR_FLAGS
1195  msg_hdr.msg_flags = 0;
1196 #endif
1197 #ifdef HAVE_MSGHDR_ACCRIGHTS
1198  msg_msg_hdr.msg_accrights = NULL;
1199 #endif
1200 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1201  msg_msg_hdr.msg_accrightslen = 0;
1202 #endif
1203 
1204  do {
1205  ufd.fd = instance->knet_fd;
1206  ufd.events = POLLIN;
1207  nfds = poll (&ufd, 1, 0);
1208  if (nfds == 1 && ufd.revents & POLLIN) {
1209  res = recvmsg (instance->knet_fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
1210  if (res != -1) {
1211  msg_processed = 1;
1212  } else {
1213  msg_processed = -1;
1214  }
1215  }
1216  } while (nfds == 1);
1217 
1218  return (msg_processed);
1219 }
1220 
1221 int totemknet_iface_set (void *knet_context,
1222  const struct totem_ip_address *local_addr,
1223  unsigned short ip_port,
1224  unsigned int iface_no)
1225 {
1226  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1227 
1228  totemip_copy(&instance->my_ids[iface_no], local_addr);
1229 
1230  knet_log_printf(LOG_INFO, "Configured link number %d: local addr: %s, port=%d", iface_no, totemip_print(local_addr), ip_port);
1231 
1232  instance->ip_port[iface_no] = ip_port;
1233 
1234  return 0;
1235 }
1236 
1237 
1239  void *knet_context,
1240  const struct totem_ip_address *local,
1241  const struct totem_ip_address *member,
1242  int link_no)
1243 {
1244  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1245  int err;
1246  int port = instance->ip_port[link_no];
1247  struct sockaddr_storage remote_ss;
1248  struct sockaddr_storage local_ss;
1249  int addrlen;
1250  int i;
1251  int host_found = 0;
1252  knet_node_id_t host_ids[KNET_MAX_HOST];
1253  size_t num_host_ids;
1254 
1255  /* Only create 1 loopback link and use link 0 */
1256  if (member->nodeid == instance->our_nodeid) {
1257  if (!instance->loopback_link) {
1258  link_no = 0;
1259  instance->loopback_link = 1;
1260  } else {
1261  /* Already done */
1262  return 0;
1263  }
1264  }
1265 
1266  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: %d (%s), link=%d", member->nodeid, totemip_print(member), link_no);
1267  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: %d (%s)", local->nodeid, totemip_print(local));
1268 
1269 
1270  /* Only add the host if it doesn't already exist in knet */
1271  err = knet_host_get_host_list(instance->knet_handle, host_ids, &num_host_ids);
1272  if (err) {
1273  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list");
1274  return -1;
1275  }
1276  for (i=0; i<num_host_ids; i++) {
1277  if (host_ids[i] == member->nodeid) {
1278  host_found = 1;
1279  }
1280  }
1281 
1282  if (!host_found) {
1283  err = knet_host_add(instance->knet_handle, member->nodeid);
1284  if (err != 0 && errno != EEXIST) {
1285  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
1286  return -1;
1287  }
1288  } else {
1289  knet_log_printf (LOGSYS_LEVEL_DEBUG, "nodeid %d already added", member->nodeid);
1290  }
1291 
1292 
1293  if (err == 0) {
1294  if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
1295  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
1296  return -1;
1297  }
1298  }
1299 
1300  memset(&local_ss, 0, sizeof(local_ss));
1301  /* Casts to remove const */
1302  totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)member, port, &remote_ss, &addrlen);
1303  totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)local, port, &local_ss, &addrlen);
1304 
1305  if (member->nodeid == instance->our_nodeid) {
1306  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: loopback link is %d\n", link_no);
1307 
1308  err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1309  KNET_TRANSPORT_LOOPBACK,
1310  &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1311  }
1312  else {
1313  err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1314  instance->totem_config->interfaces[link_no].knet_transport,
1315  &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1316  }
1317  if (err) {
1318  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
1319  return -1;
1320  }
1321 
1322  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
1323  instance->totem_config->interfaces[link_no].knet_link_priority);
1324 
1325  err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
1326  instance->totem_config->interfaces[link_no].knet_link_priority);
1327  if (err) {
1328  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid %d, link %d failed", member->nodeid, link_no);
1329  }
1330 
1331  /* ping timeouts maybe 0 here for a newly added interface so we leave this till later, it will
1332  get done in totemknet_refresh_config */
1333  if (instance->totem_config->interfaces[link_no].knet_ping_interval != 0) {
1334  err = knet_link_set_ping_timers(instance->knet_handle, member->nodeid, link_no,
1335  instance->totem_config->interfaces[link_no].knet_ping_interval,
1336  instance->totem_config->interfaces[link_no].knet_ping_timeout,
1337  instance->totem_config->interfaces[link_no].knet_ping_precision);
1338  if (err) {
1339  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for nodeid %d, link %d failed", member->nodeid, link_no);
1340  }
1341  err = knet_link_set_pong_count(instance->knet_handle, member->nodeid, link_no,
1342  instance->totem_config->interfaces[link_no].knet_pong_count);
1343  if (err) {
1344  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for nodeid %d, link %d failed", member->nodeid, link_no);
1345  }
1346  }
1347 
1348  err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
1349  if (err) {
1350  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid %d, link %d failed", member->nodeid, link_no);
1351  return -1;
1352  }
1353 
1354  /* register stats */
1355  stats_knet_add_member(member->nodeid, link_no);
1356  return (0);
1357 }
1358 
1360  void *knet_context,
1361  const struct totem_ip_address *token_target,
1362  int link_no)
1363 {
1364  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1365  int res;
1366  uint8_t link_list[KNET_MAX_LINK];
1367  size_t num_links;
1368 
1369  knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: %d, link=%d", token_target->nodeid, link_no);
1370 
1371  /* Don't remove the link with the loopback on it until we shut down */
1372  if (token_target->nodeid == instance->our_nodeid) {
1373  return 0;
1374  }
1375 
1376  /* Tidy stats */
1377  stats_knet_del_member(token_target->nodeid, link_no);
1378 
1379  /* Remove the link first */
1380  res = knet_link_set_enable(instance->knet_handle, token_target->nodeid, link_no, 0);
1381  if (res != 0) {
1382  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set enable(off) for nodeid %d, link %d failed", token_target->nodeid, link_no);
1383  return res;
1384  }
1385 
1386  res = knet_link_clear_config(instance->knet_handle, token_target->nodeid, link_no);
1387  if (res != 0) {
1388  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_clear_config for nodeid %d, link %d failed", token_target->nodeid, link_no);
1389  return res;
1390  }
1391 
1392  /* If this is the last link, then remove the node */
1393  res = knet_link_get_link_list(instance->knet_handle,
1394  token_target->nodeid, link_list, &num_links);
1395  if (res) {
1396  return (0); /* not really failure */
1397  }
1398 
1399  if (num_links == 0) {
1400  res = knet_host_remove(instance->knet_handle, token_target->nodeid);
1401  }
1402  return res;
1403 }
1404 
1406  void *knet_context)
1407 {
1408  return (0);
1409 }
1410 
1412  void *knet_context,
1413  struct totem_config *totem_config)
1414 {
1415  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1416  struct knet_handle_compress_cfg compress_cfg;
1417  int res = 0;
1418 
1419  if (totem_config->knet_compression_model) {
1420  strcpy(compress_cfg.compress_model, totem_config->knet_compression_model);
1421  compress_cfg.compress_threshold = totem_config->knet_compression_threshold;
1422  compress_cfg.compress_level = totem_config->knet_compression_level;
1423 
1424  res = knet_handle_compress(instance->knet_handle, &compress_cfg);
1425  if (res) {
1426  KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_handle_compress failed");
1427  }
1428  }
1429 
1430 #ifdef HAVE_LIBNOZZLE
1431  /* Set up nozzle device(s). Return code is ignored, because unability
1432  * configure nozzle is not fatal problem, errors are logged and
1433  * there is not much else we can do */
1434  (void)setup_nozzle(instance);
1435 #endif
1436  return (res);
1437 }
1438 
1439 
1441  void *knet_context)
1442 {
1443  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1444 
1445  (void) knet_handle_clear_stats(instance->knet_handle, KNET_CLEARSTATS_HANDLE_AND_LINK);
1446 }
1447 
1448 /* For the stats module */
1450  knet_node_id_t node, uint8_t link_no,
1451  struct knet_link_status *status)
1452 {
1453  int res;
1454  int ret = CS_OK;
1455 
1456  /* We are probably not using knet */
1457  if (!global_instance) {
1458  return CS_ERR_NOT_EXIST;
1459  }
1460 
1461  if (link_no >= INTERFACE_MAX) {
1462  return CS_ERR_NOT_EXIST; /* Invalid link number */
1463  }
1464 
1465  res = knet_link_get_status(global_instance->knet_handle, node, link_no, status, sizeof(struct knet_link_status));
1466  if (res) {
1467  switch (errno) {
1468  case EINVAL:
1469  ret = CS_ERR_INVALID_PARAM;
1470  break;
1471  case EBUSY:
1472  ret = CS_ERR_BUSY;
1473  break;
1474  case EDEADLK:
1475  ret = CS_ERR_TRY_AGAIN;
1476  break;
1477  default:
1478  ret = CS_ERR_LIBRARY;
1479  break;
1480  }
1481  }
1482 
1483  return (ret);
1484 }
1485 
1487  struct knet_handle_stats *stats)
1488 {
1489  /* We are probably not using knet */
1490  if (!global_instance) {
1491  return CS_ERR_NOT_EXIST;
1492  }
1493 
1494  return knet_handle_get_stats(global_instance->knet_handle, stats, sizeof(struct knet_handle_stats));
1495 }
1496 
1497 static void timer_function_merge_detect_timeout (
1498  void *data)
1499 {
1500  struct totemknet_instance *instance = (struct totemknet_instance *)data;
1501 
1502  if (instance->merge_detect_messages_sent_before_timeout == 0) {
1503  instance->send_merge_detect_message = 1;
1504  }
1505 
1507 
1508  totemknet_start_merge_detect_timeout(instance);
1509 }
1510 
1511 static void totemknet_start_merge_detect_timeout(
1512  void *knet_context)
1513 {
1514  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1515 
1516  qb_loop_timer_add(instance->poll_handle,
1517  QB_LOOP_MED,
1518  instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
1519  (void *)instance,
1520  timer_function_merge_detect_timeout,
1521  &instance->timer_merge_detect_timeout);
1522 
1523 }
1524 
1525 static void totemknet_stop_merge_detect_timeout(
1526  void *knet_context)
1527 {
1528  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1529 
1530  qb_loop_timer_del(instance->poll_handle,
1531  instance->timer_merge_detect_timeout);
1532 }
1533 
1534 static void log_flush_messages (void *knet_context)
1535 {
1536  struct pollfd pfd;
1537  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1538  int cont;
1539 
1540  cont = 1;
1541 
1542  while (cont) {
1543  pfd.fd = instance->logpipes[0];
1544  pfd.events = POLLIN;
1545  pfd.revents = 0;
1546 
1547  if ((poll(&pfd, 1, 0) > 0) &&
1548  (pfd.revents & POLLIN) &&
1549  (log_deliver_fn(instance->logpipes[0], POLLIN, instance) == 0)) {
1550  cont = 1;
1551  } else {
1552  cont = 0;
1553  }
1554  }
1555 }
1556 
1557 
1558 #ifdef HAVE_LIBNOZZLE
1559 #define NOZZLE_NAME "nozzle.name"
1560 #define NOZZLE_IPADDR "nozzle.ipaddr"
1561 #define NOZZLE_PREFIX "nozzle.ipprefix"
1562 #define NOZZLE_MACADDR "nozzle.macaddr"
1563 
1564 #define NOZZLE_CHANNEL 1
1565 
1566 
1567 static char *get_nozzle_script_dir(void *knet_context)
1568 {
1569  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1570  char filename[PATH_MAX + FILENAME_MAX + 1];
1571  static char updown_dirname[PATH_MAX + FILENAME_MAX + 1];
1572  int res;
1573  const char *dirname_res;
1574 
1575  /*
1576  * Build script directory based on corosync.conf file location
1577  */
1578  res = snprintf(filename, sizeof(filename), "%s",
1580  if (res >= sizeof(filename)) {
1581  knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
1582  return NULL;
1583  }
1584 
1585  dirname_res = dirname(filename);
1586 
1587  res = snprintf(updown_dirname, sizeof(updown_dirname), "%s/%s",
1588  dirname_res, "updown.d");
1589  if (res >= sizeof(updown_dirname)) {
1590  knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
1591  return NULL;
1592  }
1593  return updown_dirname;
1594 }
1595 
1596 /*
1597  * Deliberately doesn't return the status as caller doesn't care.
1598  * The result will be logged though
1599  */
1600 static void run_nozzle_script(struct totemknet_instance *instance, int type, const char *typename)
1601 {
1602  int res;
1603  char *exec_string;
1604 
1605  res = nozzle_run_updown(instance->nozzle_handle, type, &exec_string);
1606  if (res == -1 && errno != ENOENT) {
1607  knet_log_printf (LOGSYS_LEVEL_INFO, "exec nozzle %s script failed: %s", typename, strerror(errno));
1608  } else if (res == -2) {
1609  knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle %s script failed", typename);
1610  knet_log_printf (LOGSYS_LEVEL_INFO, "%s", exec_string);
1611  }
1612 }
1613 
1614 /*
1615  * Reparse IP address to add in our node ID
1616  * IPv6 addresses must end in '::'
1617  * IPv4 addresses must just be valid
1618  * '/xx' lengths are optional for IPv6, mandatory for IPv4
1619  *
1620  * Returns the modified IP address as a string to pass into libnozzle
1621  */
1622 static int reparse_nozzle_ip_address(struct totemknet_instance *instance,
1623  const char *input_addr,
1624  const char *prefix, int nodeid,
1625  char *output_addr, size_t output_len)
1626 {
1627  char *coloncolon;
1628  int bits;
1629  int max_prefix = 64;
1630  uint32_t nodeid_mask;
1631  uint32_t addr_mask;
1632  uint32_t masked_nodeid;
1633  struct in_addr *addr;
1634  struct totem_ip_address totemip;
1635 
1636  coloncolon = strstr(input_addr, "::");
1637  if (!coloncolon) {
1638  max_prefix = 30;
1639  }
1640 
1641  bits = atoi(prefix);
1642  if (bits < 8 || bits > max_prefix) {
1643  knet_log_printf(LOGSYS_LEVEL_ERROR, "nozzle IP address prefix must be >= 8 and <= %d (got %d)", max_prefix, bits);
1644  return -1;
1645  }
1646 
1647  /* IPv6 is easy */
1648  if (coloncolon) {
1649  memcpy(output_addr, input_addr, coloncolon-input_addr);
1650  sprintf(output_addr + (coloncolon-input_addr), "::%x", nodeid);
1651  return 0;
1652  }
1653 
1654  /* For IPv4 we need to parse the address into binary, mask off the required bits,
1655  * add in the masked_nodeid and 'print' it out again
1656  */
1657  nodeid_mask = UINT32_MAX & ((1<<(32 - bits)) - 1);
1658  addr_mask = UINT32_MAX ^ nodeid_mask;
1659  masked_nodeid = nodeid & nodeid_mask;
1660 
1661  if (totemip_parse(&totemip, input_addr, AF_INET)) {
1662  knet_log_printf(LOGSYS_LEVEL_ERROR, "Failed to parse IPv4 nozzle IP address");
1663  return -1;
1664  }
1665  addr = (struct in_addr *)&totemip.addr;
1666  addr->s_addr &= htonl(addr_mask);
1667  addr->s_addr |= htonl(masked_nodeid);
1668 
1669  inet_ntop(AF_INET, addr, output_addr, output_len);
1670  return 0;
1671 }
1672 
1673 static int create_nozzle_device(void *knet_context, const char *name,
1674  const char *ipaddr, const char *prefix,
1675  const char *macaddr)
1676 {
1677  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1678  char device_name[IFNAMSIZ+1];
1679  size_t size = IFNAMSIZ;
1680  int8_t channel = NOZZLE_CHANNEL;
1681  nozzle_t nozzle_dev;
1682  int nozzle_fd;
1683  int res;
1684  char *updown_dir;
1685  char parsed_ipaddr[INET6_ADDRSTRLEN];
1686  char mac[19];
1687 
1688  memset(device_name, 0, size);
1689  memset(&mac, 0, sizeof(mac));
1690  strncpy(device_name, name, size);
1691 
1692  updown_dir = get_nozzle_script_dir(knet_context);
1693  knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle script dir is %s", updown_dir);
1694 
1695  nozzle_dev = nozzle_open(device_name, size, updown_dir);
1696  if (!nozzle_dev) {
1697  knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to init nozzle device %s: %s", device_name, strerror(errno));
1698  return -1;
1699  }
1700  instance->nozzle_handle = nozzle_dev;
1701 
1702  if (nozzle_set_mac(nozzle_dev, macaddr) < 0) {
1703  knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle MAC to %s: %s", mac, strerror(errno));
1704  goto out_clean;
1705  }
1706 
1707  if (reparse_nozzle_ip_address(instance, ipaddr, prefix, instance->our_nodeid, parsed_ipaddr, sizeof(parsed_ipaddr))) {
1708  /* Prints its own errors */
1709  goto out_clean;
1710  }
1711  knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle IP address is %s / %d", parsed_ipaddr, atoi(prefix));
1712  if (nozzle_add_ip(nozzle_dev, parsed_ipaddr, prefix) < 0) {
1713  knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle IP addr to %s/%s: %s", parsed_ipaddr, prefix, strerror(errno));
1714  goto out_clean;
1715  }
1716 
1717  nozzle_fd = nozzle_get_fd(nozzle_dev);
1718  knet_log_printf (LOGSYS_LEVEL_INFO, "Opened '%s' on fd %d", device_name, nozzle_fd);
1719 
1720  res = knet_handle_add_datafd(instance->knet_handle, &nozzle_fd, &channel);
1721  if (res != 0) {
1722  knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add nozzle FD to knet: %s", strerror(errno));
1723  goto out_clean;
1724  }
1725 
1726  run_nozzle_script(instance, NOZZLE_PREUP, "pre-up");
1727 
1728  res = nozzle_set_up(nozzle_dev);
1729  if (res != 0) {
1730  knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to set nozzle interface UP: %s", strerror(errno));
1731  goto out_clean;
1732  }
1733  run_nozzle_script(instance, NOZZLE_UP, "up");
1734 
1735  return 0;
1736 
1737 out_clean:
1738  nozzle_close(nozzle_dev);
1739  return -1;
1740 }
1741 
1742 static int remove_nozzle_device(void *knet_context)
1743 {
1744  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1745  int res;
1746  int datafd;
1747 
1748  res = knet_handle_get_datafd(instance->knet_handle, NOZZLE_CHANNEL, &datafd);
1749  if (res != 0) {
1750  knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't find datafd for channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
1751  return -1;
1752  }
1753 
1754  res = knet_handle_remove_datafd(instance->knet_handle, datafd);
1755  if (res != 0) {
1756  knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't remove datafd for nozzle channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
1757  return -1;
1758  }
1759 
1760  run_nozzle_script(instance, NOZZLE_DOWN, "pre-down");
1761  res = nozzle_set_down(instance->nozzle_handle);
1762  if (res != 0) {
1763  knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't set nozzle device down: %s", strerror(errno));
1764  return -1;
1765  }
1766  run_nozzle_script(instance, NOZZLE_POSTDOWN, "post-down");
1767 
1768  res = nozzle_close(instance->nozzle_handle);
1769  if (res != 0) {
1770  knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't close nozzle device: %s", strerror(errno));
1771  return -1;
1772  }
1773  knet_log_printf (LOGSYS_LEVEL_INFO, "Removed nozzle device");
1774  return 0;
1775 }
1776 
1777 static void free_nozzle(struct totemknet_instance *instance)
1778 {
1779  free(instance->nozzle_name);
1780  free(instance->nozzle_ipaddr);
1781  free(instance->nozzle_prefix);
1782  free(instance->nozzle_macaddr);
1783 
1784  instance->nozzle_name = instance->nozzle_ipaddr = instance->nozzle_prefix =
1785  instance->nozzle_macaddr = NULL;
1786 }
1787 
1788 static int setup_nozzle(void *knet_context)
1789 {
1790  struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1791  char *ipaddr_str = NULL;
1792  char *name_str = NULL;
1793  char *prefix_str = NULL;
1794  char *macaddr_str = NULL;
1795  char mac[32];
1796  int name_res;
1797  int macaddr_res;
1798  int res = -1;
1799 
1800  /*
1801  * Return value ignored on purpose. icmap_get_string changes
1802  * ipaddr_str/prefix_str only on success.
1803  */
1804  (void)icmap_get_string(NOZZLE_IPADDR, &ipaddr_str);
1805  (void)icmap_get_string(NOZZLE_PREFIX, &prefix_str);
1806  macaddr_res = icmap_get_string(NOZZLE_MACADDR, &macaddr_str);
1807  name_res = icmap_get_string(NOZZLE_NAME, &name_str);
1808 
1809  /* Is is being removed? */
1810  if (name_res == CS_ERR_NOT_EXIST && instance->nozzle_handle) {
1811  remove_nozzle_device(instance);
1812  free_nozzle(instance);
1813  goto out_free;
1814  }
1815 
1816  if (!name_str) {
1817  /* no nozzle */
1818  goto out_free;
1819  }
1820 
1821  if (!ipaddr_str) {
1822  knet_log_printf (LOGSYS_LEVEL_ERROR, "No IP address supplied for Nozzle device");
1823  goto out_free;
1824  }
1825 
1826  if (!prefix_str) {
1827  knet_log_printf (LOGSYS_LEVEL_ERROR, "No prefix supplied for Nozzle IP address");
1828  goto out_free;
1829  }
1830 
1831  if (macaddr_str && strlen(macaddr_str) != 17) {
1832  knet_log_printf (LOGSYS_LEVEL_ERROR, "macaddr for nozzle device is not in the correct format '%s'", macaddr_str);
1833  goto out_free;
1834  }
1835  if (!macaddr_str) {
1836  macaddr_str = (char*)"54:54:01:00:00:00";
1837  }
1838 
1839  if (instance->nozzle_name &&
1840  (strcmp(name_str, instance->nozzle_name) == 0) &&
1841  (strcmp(ipaddr_str, instance->nozzle_ipaddr) == 0) &&
1842  (strcmp(prefix_str, instance->nozzle_prefix) == 0) &&
1843  (instance->nozzle_macaddr == NULL ||
1844  strcmp(macaddr_str, instance->nozzle_macaddr) == 0)) {
1845  /* Nothing has changed */
1846  knet_log_printf (LOGSYS_LEVEL_DEBUG, "Nozzle device info not changed");
1847  goto out_free;
1848  }
1849 
1850  /* Add nodeid into MAC address */
1851  memcpy(mac, macaddr_str, 12);
1852  snprintf(mac+12, sizeof(mac) - 13, "%02x:%02x",
1853  instance->our_nodeid >> 8,
1854  instance->our_nodeid & 0xFF);
1855  knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle MAC address is %s", mac);
1856 
1857  if (name_res == CS_OK && name_str) {
1858  /* Reconfigure */
1859  if (instance->nozzle_name) {
1860  remove_nozzle_device(instance);
1861  free_nozzle(instance);
1862  }
1863 
1864  res = create_nozzle_device(knet_context, name_str, ipaddr_str, prefix_str,
1865  mac);
1866 
1867  instance->nozzle_name = strdup(name_str);
1868  instance->nozzle_ipaddr = strdup(ipaddr_str);
1869  instance->nozzle_prefix = strdup(prefix_str);
1870  instance->nozzle_macaddr = strdup(macaddr_str);
1871  if (!instance->nozzle_name || !instance->nozzle_ipaddr ||
1872  !instance->nozzle_prefix) {
1873  knet_log_printf (LOGSYS_LEVEL_ERROR, "strdup failed in nozzle allocation");
1874  /*
1875  * This 'free' will cause a complete reconfigure of the device next time we reload
1876  * but will also let the the current device keep working until then.
1877  * remove_nozzle() only needs the, statically-allocated, nozzle_handle
1878  */
1879  free_nozzle(instance);
1880  }
1881  }
1882 
1883 out_free:
1884  free(name_str);
1885  free(ipaddr_str);
1886  free(prefix_str);
1887  if (macaddr_res == CS_OK) {
1888  free(macaddr_str);
1889  }
1890 
1891  return res;
1892 }
1893 #endif // HAVE_LIBNOZZLE
uint16_t ip_port[INTERFACE_MAX]
Definition: totemknet.c:154
int knet_ping_precision
Definition: totem.h:92
int totemknet_log_level_security
Definition: totemknet.c:123
qb_loop_t * poll_handle
Definition: totemknet.c:95
char * link_status[INTERFACE_MAX]
Definition: totemknet.c:150
int totemknet_member_remove(void *knet_context, const struct totem_ip_address *token_target, int link_no)
Definition: totemknet.c:1359
#define MSG_NOSIGNAL
Definition: totemknet.c:82
#define LOGSYS_LEVEL_INFO
Definition: logsys.h:75
int knet_link_priority
Definition: totem.h:89
uint32_t value
qb_loop_timer_handle timer_merge_detect_timeout
Definition: totemknet.c:166
struct totem_interface * interfaces
Definition: totem.h:158
void stats_knet_add_handle(void)
Definition: stats.c:637
int totemknet_log_level_error
Definition: totemknet.c:125
unsigned int merge_detect_messages_sent_before_timeout
Definition: totemknet.c:170
#define libknet_log_printf(level, format, args...)
Definition: totemknet.c:217
struct totem_ip_address my_ids[INTERFACE_MAX]
Definition: totemknet.c:152
The totem_ip_address struct.
Definition: coroapi.h:111
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition: totemknet.c:90
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:264
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:114
#define knet_log_printf(level, format, args...)
Definition: totemknet.c:209
int send_merge_detect_message
Definition: totemknet.c:168
int totemknet_finalize(void *knet_context)
Definition: totemknet.c:541
uint32_t knet_compression_threshold
Definition: totem.h:226
void(* totemknet_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no)
Definition: totemknet.c:109
char link_mode[TOTEM_LINK_MODE_BYTES]
Definition: totem.h:198
unsigned int knet_pmtud_interval
Definition: totem.h:162
char * crypto_model
Definition: totem.h:218
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
int totemknet_link_get_status(knet_node_id_t node, uint8_t link_no, struct knet_link_status *status)
Definition: totemknet.c:1449
void totemknet_buffer_release(void *ptr)
Definition: totemknet.c:1077
void totemknet_stats_clear(void *knet_context)
Definition: totemknet.c:1440
#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...)
Definition: totemknet.c:225
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:123
void stats_knet_del_member(knet_node_id_t nodeid, uint8_t link)
Definition: stats.c:624
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
Definition: logsys.c:433
unsigned int private_key_len
Definition: totem.h:169
int totemknet_log_level_notice
Definition: totemknet.c:129
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
#define INTERFACE_MAX
Definition: coroapi.h:88
int totemknet_crypto_set(void *knet_context, const char *cipher_type, const char *hash_type)
Definition: totemknet.c:339
unsigned int block_unlisted_ips
Definition: totem.h:236
qb_loop_timer_handle timer_netif_check_timeout
Definition: totemknet.c:164
int totemknet_mcast_flush_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition: totemknet.c:1111
int totemknet_iface_check(void *knet_context)
Definition: totemknet.c:1138
void(*) void knet_context)
Definition: totemknet.c:144
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:826
unsigned int node_id
Definition: totem.h:160
#define LOGSYS_LEVEL_WARNING
Definition: logsys.h:73
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
uint8_t configured
Definition: totem.h:87
int totemknet_log_level_warning
Definition: totemknet.c:127
char * knet_compression_model
Definition: totem.h:224
const char * corosync_get_config_file(void)
Definition: main.c:204
void * user_data
Definition: sam.c:127
int totemknet_token_target_set(void *knet_context, unsigned int nodeid)
Definition: totemknet.c:1155
struct totem_config * totem_config
Definition: totemknet.c:160
unsigned int nodeid
Definition: coroapi.h:112
int totemknet_reconfigure(void *knet_context, struct totem_config *totem_config)
Definition: totemknet.c:1411
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
int totemknet_iface_set(void *knet_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
Definition: totemknet.c:1221
int knet_transport
Definition: totem.h:94
char * crypto_hash_type
Definition: totem.h:222
int totemknet_processor_count_set(void *knet_context, int processor_count)
Definition: totemknet.c:1082
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:72
int totemknet_recv_flush(void *knet_context)
Definition: totemknet.c:1089
int totemknet_send_flush(void *knet_context)
Definition: totemknet.c:1094
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
Definition: totem.h:167
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:94
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:76
struct totem_ip_address boundto
Definition: totem.h:83
typedef __attribute__
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:850
char iov_buffer[KNET_MAX_PACKET_SIZE]
Definition: totemknet.c:148
void(* log_printf)(int level, int subsys, const char *function_name, const char *file_name, int file_line, const char *format,...) __attribute__((format(printf
Definition: totem.h:99
int totemknet_handle_get_stats(struct knet_handle_stats *stats)
Definition: totemknet.c:1486
struct totemknet_instance * global_instance
Definition: totemknet.c:184
struct totem_message_header header
Definition: totemsrp.c:260
uint16_t ip_port
Definition: totem.h:85
int knet_compression_level
Definition: totem.h:228
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
Definition: totemip.c:314
struct crypto_instance * crypto_inst
Definition: totemknet.c:93
#define ENTER
Definition: logsys.h:324
unsigned int net_mtu
Definition: totem.h:202
void(* totemknet_target_set_completed)(void *context)
Definition: totemknet.c:118
struct totem_ip_address token_target
Definition: totemknet.c:162
#define PROCESSOR_COUNT_MAX
Definition: coroapi.h:96
int totemknet_member_add(void *knet_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int link_no)
Definition: totemknet.c:1238
int knet_pong_count
Definition: totem.h:93
struct totemknet_instance * instance
Definition: totemknet.c:189
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition: icmap.c:880
#define LOGSYS_LEVEL_CRIT
Definition: logsys.h:71
int knet_ping_interval
Definition: totem.h:90
const void * msg
Definition: totemknet.c:187
void(* totemknet_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
Definition: totemknet.c:103
int knet_ping_timeout
Definition: totem.h:91
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
Definition: totemip.c:272
void(* totemknet_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
Definition: totemknet.c:137
struct totem_logging_configuration totem_logging_configuration
Definition: totem.h:200
void(* totemknet_mtu_changed)(void *context, int net_mtu)
Definition: totemknet.c:114
void stats_knet_add_member(knet_node_id_t nodeid, uint8_t link)
Definition: stats.c:614
struct srp_addr system_from
Definition: totemsrp.c:261
char * crypto_cipher_type
Definition: totem.h:220
char type
Definition: totem.h:55
void totemknet_net_mtu_adjust(void *knet_context, struct totem_config *totem_config)
Definition: totemknet.c:1148
int totemknet_member_list_rebind_ip(void *knet_context)
Definition: totemknet.c:1405
unsigned int merge_timeout
Definition: totem.h:190
int totemknet_mcast_noflush_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition: totemknet.c:1124
int totemknet_log_level_debug
Definition: totemknet.c:131
unsigned int target_nodeid
Definition: totem.h:130
int totemknet_token_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition: totemknet.c:1099
struct totem_ip_address bindnet
Definition: totem.h:82
unsigned int nodeid
Definition: coroapi.h:75
int totemknet_recv_mcast_empty(void *knet_context)
Definition: totemknet.c:1169
unsigned int msg_len
Definition: totemknet.c:188
#define LEAVE
Definition: logsys.h:325
int totemknet_initialize(qb_loop_t *poll_handle, void **knet_context, struct totem_config *totem_config, totemsrp_stats_t *stats, void *context, void(*deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from), void(*iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no), void(*mtu_changed)(void *context, int net_mtu), void(*target_set_completed)(void *context))
Definition: totemknet.c:857
int totemknet_ifaces_get(void *knet_context, char ***status, unsigned int *iface_count)
Definition: totemknet.c:463
Structure passed as new_value and old_value in change callback.
Definition: icmap.h:91
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
Definition: icmap.c:1151
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
Definition: icmap.h:85
void * totemknet_buffer_alloc(void)
Definition: totemknet.c:1071
knet_handle_t knet_handle
Definition: totemknet.c:97