corosync  2.3.5
totemudp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 MontaVista Software, Inc.
3  * Copyright (c) 2006-2012 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Steven Dake (sdake@redhat.com)
8 
9  * This software licensed under BSD license, the text of which follows:
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * - Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * - Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  * - Neither the name of the MontaVista Software, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <config.h>
37 
38 #include <assert.h>
39 #include <pthread.h>
40 #include <sys/mman.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/socket.h>
44 #include <netdb.h>
45 #include <sys/un.h>
46 #include <sys/ioctl.h>
47 #include <sys/param.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <unistd.h>
51 #include <fcntl.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <errno.h>
55 #include <sched.h>
56 #include <time.h>
57 #include <sys/time.h>
58 #include <sys/poll.h>
59 #include <sys/uio.h>
60 #include <limits.h>
61 
62 #include <corosync/sq.h>
63 #include <corosync/swab.h>
64 #include <corosync/list.h>
65 #include <qb/qbdefs.h>
66 #include <qb/qbloop.h>
67 #define LOGSYS_UTILS_ONLY 1
68 #include <corosync/logsys.h>
69 #include "totemudp.h"
70 
71 #include "util.h"
72 #include "totemcrypto.h"
73 
74 #include <nss.h>
75 #include <pk11pub.h>
76 #include <pkcs11.h>
77 #include <prerror.h>
78 
79 #ifndef MSG_NOSIGNAL
80 #define MSG_NOSIGNAL 0
81 #endif
82 
83 #define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * FRAME_SIZE_MAX)
84 #define NETIF_STATE_REPORT_UP 1
85 #define NETIF_STATE_REPORT_DOWN 2
86 
87 #define BIND_STATE_UNBOUND 0
88 #define BIND_STATE_REGULAR 1
89 #define BIND_STATE_LOOPBACK 2
90 
91 #define MESSAGE_TYPE_MEMB_JOIN 3
92 
96  int token;
97  /*
98  * Socket used for local multicast delivery. We don't rely on multicast
99  * loop and rather this UNIX DGRAM socket is used. Socket is created by
100  * socketpair call and they are used in same way as pipe (so [0] is read
101  * end and [1] is write end)
102  */
104 };
105 
108 
110 
112 
114 
116 
117  void *context;
118 
119  void (*totemudp_deliver_fn) (
120  void *context,
121  const void *msg,
122  unsigned int msg_len);
123 
124  void (*totemudp_iface_change_fn) (
125  void *context,
126  const struct totem_ip_address *iface_address);
127 
128  void (*totemudp_target_set_completed) (void *context);
129 
130  /*
131  * Function and data used to log messages
132  */
134 
136 
138 
140 
142 
144 
145  void (*totemudp_log_printf) (
146  int level,
147  int subsys,
148  const char *function,
149  const char *file,
150  int line,
151  const char *format,
152  ...)__attribute__((format(printf, 6, 7)));
153 
154  void *udp_context;
155 
156  char iov_buffer[FRAME_SIZE_MAX];
157 
158  char iov_buffer_flush[FRAME_SIZE_MAX];
159 
160  struct iovec totemudp_iov_recv;
161 
162  struct iovec totemudp_iov_recv_flush;
163 
164  struct totemudp_socket totemudp_sockets;
165 
166  struct totem_ip_address mcast_address;
167 
169 
171 
173 
175 
177 
178  struct timeval stats_tv_start;
179 
180  struct totem_ip_address my_id;
181 
182  int firstrun;
183 
184  qb_loop_timer_handle timer_netif_check_timeout;
185 
186  unsigned int my_memb_entries;
187 
188  int flushing;
189 
191 
193 
194  struct totem_ip_address token_target;
195 };
196 
197 struct work_item {
198  const void *msg;
199  unsigned int msg_len;
201 };
202 
203 static int totemudp_build_sockets (
204  struct totemudp_instance *instance,
205  struct totem_ip_address *bindnet_address,
206  struct totem_ip_address *mcastaddress,
207  struct totemudp_socket *sockets,
208  struct totem_ip_address *bound_to);
209 
210 static struct totem_ip_address localhost;
211 
212 static void totemudp_instance_initialize (struct totemudp_instance *instance)
213 {
214  memset (instance, 0, sizeof (struct totemudp_instance));
215 
217 
218  instance->totemudp_iov_recv.iov_base = instance->iov_buffer;
219 
220  instance->totemudp_iov_recv.iov_len = FRAME_SIZE_MAX; //sizeof (instance->iov_buffer);
221  instance->totemudp_iov_recv_flush.iov_base = instance->iov_buffer_flush;
222 
223  instance->totemudp_iov_recv_flush.iov_len = FRAME_SIZE_MAX; //sizeof (instance->iov_buffer);
224 
225  /*
226  * There is always atleast 1 processor
227  */
228  instance->my_memb_entries = 1;
229 }
230 
231 #define log_printf(level, format, args...) \
232 do { \
233  instance->totemudp_log_printf ( \
234  level, instance->totemudp_subsys_id, \
235  __FUNCTION__, __FILE__, __LINE__, \
236  (const char *)format, ##args); \
237 } while (0);
238 
239 #define LOGSYS_PERROR(err_num, level, fmt, args...) \
240 do { \
241  char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
242  const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
243  instance->totemudp_log_printf ( \
244  level, instance->totemudp_subsys_id, \
245  __FUNCTION__, __FILE__, __LINE__, \
246  fmt ": %s (%d)\n", ##args, _error_ptr, err_num); \
247  } while(0)
248 
250  void *udp_context,
251  const char *cipher_type,
252  const char *hash_type)
253 {
254 
255  return (0);
256 }
257 
258 
259 static inline void ucast_sendmsg (
260  struct totemudp_instance *instance,
261  struct totem_ip_address *system_to,
262  const void *msg,
263  unsigned int msg_len)
264 {
265  struct msghdr msg_ucast;
266  int res = 0;
267  size_t buf_out_len;
268  unsigned char buf_out[FRAME_SIZE_MAX];
269  struct sockaddr_storage sockaddr;
270  struct iovec iovec;
271  int addrlen;
272 
273  /*
274  * Encrypt and digest the message
275  */
277  instance->crypto_inst,
278  (const unsigned char *)msg,
279  msg_len,
280  buf_out,
281  &buf_out_len) != 0) {
282  log_printf(LOGSYS_LEVEL_CRIT, "Error encrypting/signing packet (non-critical)");
283  return;
284  }
285 
286  iovec.iov_base = (void *)buf_out;
287  iovec.iov_len = buf_out_len;
288 
289  /*
290  * Build unicast message
291  */
292  memset(&msg_ucast, 0, sizeof(msg_ucast));
294  instance->totem_interface->ip_port, &sockaddr, &addrlen);
295  msg_ucast.msg_name = &sockaddr;
296  msg_ucast.msg_namelen = addrlen;
297  msg_ucast.msg_iov = (void *)&iovec;
298  msg_ucast.msg_iovlen = 1;
299 #ifdef HAVE_MSGHDR_CONTROL
300  msg_ucast.msg_control = 0;
301 #endif
302 #ifdef HAVE_MSGHDR_CONTROLLEN
303  msg_ucast.msg_controllen = 0;
304 #endif
305 #ifdef HAVE_MSGHDR_FLAGS
306  msg_ucast.msg_flags = 0;
307 #endif
308 #ifdef HAVE_MSGHDR_ACCRIGHTS
309  msg_ucast.msg_accrights = NULL;
310 #endif
311 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
312  msg_ucast.msg_accrightslen = 0;
313 #endif
314 
315 
316  /*
317  * Transmit unicast message
318  * An error here is recovered by totemsrp
319  */
320  res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_ucast,
321  MSG_NOSIGNAL);
322  if (res < 0) {
323  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
324  "sendmsg(ucast) failed (non-critical)");
325  }
326 }
327 
328 static inline void mcast_sendmsg (
329  struct totemudp_instance *instance,
330  const void *msg,
331  unsigned int msg_len)
332 {
333  struct msghdr msg_mcast;
334  int res = 0;
335  size_t buf_out_len;
336  unsigned char buf_out[FRAME_SIZE_MAX];
337  struct iovec iovec;
338  struct sockaddr_storage sockaddr;
339  int addrlen;
340 
341  /*
342  * Encrypt and digest the message
343  */
345  instance->crypto_inst,
346  (const unsigned char *)msg,
347  msg_len,
348  buf_out,
349  &buf_out_len) != 0) {
350  log_printf(LOGSYS_LEVEL_CRIT, "Error encrypting/signing packet (non-critical)");
351  return;
352  }
353 
354  iovec.iov_base = (void *)&buf_out;
355  iovec.iov_len = buf_out_len;
356 
357  /*
358  * Build multicast message
359  */
361  instance->totem_interface->ip_port, &sockaddr, &addrlen);
362  memset(&msg_mcast, 0, sizeof(msg_mcast));
363  msg_mcast.msg_name = &sockaddr;
364  msg_mcast.msg_namelen = addrlen;
365  msg_mcast.msg_iov = (void *)&iovec;
366  msg_mcast.msg_iovlen = 1;
367 #ifdef HAVE_MSGHDR_CONTROL
368  msg_mcast.msg_control = 0;
369 #endif
370 #ifdef HAVE_MSGHDR_CONTROLLEN
371  msg_mcast.msg_controllen = 0;
372 #endif
373 #ifdef HAVE_MSGHDR_FLAGS
374  msg_mcast.msg_flags = 0;
375 #endif
376 #ifdef HAVE_MSGHDR_ACCRIGHTS
377  msg_mcast.msg_accrights = NULL;
378 #endif
379 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
380  msg_mcast.msg_accrightslen = 0;
381 #endif
382 
383  /*
384  * Transmit multicast message
385  * An error here is recovered by totemsrp
386  */
387  res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_mcast,
388  MSG_NOSIGNAL);
389  if (res < 0) {
390  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
391  "sendmsg(mcast) failed (non-critical)");
392  instance->stats->continuous_sendmsg_failures++;
393  } else {
394  instance->stats->continuous_sendmsg_failures = 0;
395  }
396 
397  /*
398  * Transmit multicast message to local unix mcast loop
399  * An error here is recovered by totemsrp
400  */
401  msg_mcast.msg_name = NULL;
402  msg_mcast.msg_namelen = 0;
403 
404  res = sendmsg (instance->totemudp_sockets.local_mcast_loop[1], &msg_mcast,
405  MSG_NOSIGNAL);
406  if (res < 0) {
407  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
408  "sendmsg(local mcast loop) failed (non-critical)");
409  }
410 }
411 
412 
414  void *udp_context)
415 {
416  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
417  int res = 0;
418 
419  if (instance->totemudp_sockets.mcast_recv > 0) {
420  qb_loop_poll_del (instance->totemudp_poll_handle,
421  instance->totemudp_sockets.mcast_recv);
422  close (instance->totemudp_sockets.mcast_recv);
423  }
424  if (instance->totemudp_sockets.mcast_send > 0) {
425  close (instance->totemudp_sockets.mcast_send);
426  }
427  if (instance->totemudp_sockets.local_mcast_loop[0] > 0) {
428  qb_loop_poll_del (instance->totemudp_poll_handle,
429  instance->totemudp_sockets.local_mcast_loop[0]);
430  close (instance->totemudp_sockets.local_mcast_loop[0]);
431  close (instance->totemudp_sockets.local_mcast_loop[1]);
432  }
433  if (instance->totemudp_sockets.token > 0) {
434  qb_loop_poll_del (instance->totemudp_poll_handle,
435  instance->totemudp_sockets.token);
436  close (instance->totemudp_sockets.token);
437  }
438 
439  return (res);
440 }
441 
442 /*
443  * Only designed to work with a message with one iov
444  */
445 
446 static int net_deliver_fn (
447  int fd,
448  int revents,
449  void *data)
450 {
451  struct totemudp_instance *instance = (struct totemudp_instance *)data;
452  struct msghdr msg_recv;
453  struct iovec *iovec;
454  struct sockaddr_storage system_from;
455  int bytes_received;
456  int res = 0;
457  char *message_type;
458 
459  if (instance->flushing == 1) {
460  iovec = &instance->totemudp_iov_recv_flush;
461  } else {
462  iovec = &instance->totemudp_iov_recv;
463  }
464 
465  /*
466  * Receive datagram
467  */
468  msg_recv.msg_name = &system_from;
469  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
470  msg_recv.msg_iov = iovec;
471  msg_recv.msg_iovlen = 1;
472 #ifdef HAVE_MSGHDR_CONTROL
473  msg_recv.msg_control = 0;
474 #endif
475 #ifdef HAVE_MSGHDR_CONTROLLEN
476  msg_recv.msg_controllen = 0;
477 #endif
478 #ifdef HAVE_MSGHDR_FLAGS
479  msg_recv.msg_flags = 0;
480 #endif
481 #ifdef HAVE_MSGHDR_ACCRIGHTS
482  msg_recv.msg_accrights = NULL;
483 #endif
484 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
485  msg_recv.msg_accrightslen = 0;
486 #endif
487 
488  bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
489  if (bytes_received == -1) {
490  return (0);
491  } else {
492  instance->stats_recv += bytes_received;
493  }
494 
495  /*
496  * Authenticate and if authenticated, decrypt datagram
497  */
498  res = crypto_authenticate_and_decrypt (instance->crypto_inst, iovec->iov_base, &bytes_received);
499  if (res == -1) {
500  log_printf (instance->totemudp_log_level_security, "Received message has invalid digest... ignoring.");
502  "Invalid packet data");
503  iovec->iov_len = FRAME_SIZE_MAX;
504  return 0;
505  }
506  iovec->iov_len = bytes_received;
507 
508  /*
509  * Drop all non-mcast messages (more specifically join
510  * messages should be dropped)
511  */
512  message_type = (char *)iovec->iov_base;
513  if (instance->flushing == 1 && *message_type == MESSAGE_TYPE_MEMB_JOIN) {
514  log_printf(instance->totemudp_log_level_warning, "JOIN or LEAVE message was thrown away during flush operation.");
515  iovec->iov_len = FRAME_SIZE_MAX;
516  return (0);
517  }
518 
519  /*
520  * Handle incoming message
521  */
522  instance->totemudp_deliver_fn (
523  instance->context,
524  iovec->iov_base,
525  iovec->iov_len);
526 
527  iovec->iov_len = FRAME_SIZE_MAX;
528  return (0);
529 }
530 
531 static int netif_determine (
532  struct totemudp_instance *instance,
533  struct totem_ip_address *bindnet,
534  struct totem_ip_address *bound_to,
535  int *interface_up,
536  int *interface_num)
537 {
538  int res;
539 
540  res = totemip_iface_check (bindnet, bound_to,
541  interface_up, interface_num,
542  instance->totem_config->clear_node_high_bit);
543 
544 
545  return (res);
546 }
547 
548 
549 /*
550  * If the interface is up, the sockets for totem are built. If the interface is down
551  * this function is requeued in the timer list to retry building the sockets later.
552  */
553 static void timer_function_netif_check_timeout (
554  void *data)
555 {
556  struct totemudp_instance *instance = (struct totemudp_instance *)data;
557  int interface_up;
558  int interface_num;
559  struct totem_ip_address *bind_address;
560 
561  /*
562  * Build sockets for every interface
563  */
564  netif_determine (instance,
565  &instance->totem_interface->bindnet,
566  &instance->totem_interface->boundto,
567  &interface_up, &interface_num);
568  /*
569  * If the network interface isn't back up and we are already
570  * in loopback mode, add timer to check again and return
571  */
572  if ((instance->netif_bind_state == BIND_STATE_LOOPBACK &&
573  interface_up == 0) ||
574 
575  (instance->my_memb_entries == 1 &&
576  instance->netif_bind_state == BIND_STATE_REGULAR &&
577  interface_up == 1)) {
578 
579  qb_loop_timer_add (instance->totemudp_poll_handle,
580  QB_LOOP_MED,
581  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
582  (void *)instance,
583  timer_function_netif_check_timeout,
584  &instance->timer_netif_check_timeout);
585 
586  /*
587  * Add a timer to check for a downed regular interface
588  */
589  return;
590  }
591 
592  if (instance->totemudp_sockets.mcast_recv > 0) {
593  qb_loop_poll_del (instance->totemudp_poll_handle,
594  instance->totemudp_sockets.mcast_recv);
595  close (instance->totemudp_sockets.mcast_recv);
596  }
597  if (instance->totemudp_sockets.mcast_send > 0) {
598  close (instance->totemudp_sockets.mcast_send);
599  }
600  if (instance->totemudp_sockets.local_mcast_loop[0] > 0) {
601  qb_loop_poll_del (instance->totemudp_poll_handle,
602  instance->totemudp_sockets.local_mcast_loop[0]);
603  close (instance->totemudp_sockets.local_mcast_loop[0]);
604  close (instance->totemudp_sockets.local_mcast_loop[1]);
605  }
606  if (instance->totemudp_sockets.token > 0) {
607  qb_loop_poll_del (instance->totemudp_poll_handle,
608  instance->totemudp_sockets.token);
609  close (instance->totemudp_sockets.token);
610  }
611 
612  if (interface_up == 0) {
613  /*
614  * Interface is not up
615  */
617  bind_address = &localhost;
618 
619  /*
620  * Add a timer to retry building interfaces and request memb_gather_enter
621  */
622  qb_loop_timer_add (instance->totemudp_poll_handle,
623  QB_LOOP_MED,
624  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
625  (void *)instance,
626  timer_function_netif_check_timeout,
627  &instance->timer_netif_check_timeout);
628  } else {
629  /*
630  * Interface is up
631  */
633  bind_address = &instance->totem_interface->bindnet;
634  }
635  /*
636  * Create and bind the multicast and unicast sockets
637  */
638  (void)totemudp_build_sockets (instance,
639  &instance->mcast_address,
640  bind_address,
641  &instance->totemudp_sockets,
642  &instance->totem_interface->boundto);
643 
644  qb_loop_poll_add (
645  instance->totemudp_poll_handle,
646  QB_LOOP_MED,
647  instance->totemudp_sockets.mcast_recv,
648  POLLIN, instance, net_deliver_fn);
649 
650  qb_loop_poll_add (
651  instance->totemudp_poll_handle,
652  QB_LOOP_MED,
653  instance->totemudp_sockets.local_mcast_loop[0],
654  POLLIN, instance, net_deliver_fn);
655 
656  qb_loop_poll_add (
657  instance->totemudp_poll_handle,
658  QB_LOOP_MED,
659  instance->totemudp_sockets.token,
660  POLLIN, instance, net_deliver_fn);
661 
662  totemip_copy (&instance->my_id, &instance->totem_interface->boundto);
663 
664  /*
665  * This reports changes in the interface to the user and totemsrp
666  */
667  if (instance->netif_bind_state == BIND_STATE_REGULAR) {
668  if (instance->netif_state_report & NETIF_STATE_REPORT_UP) {
670  "The network interface [%s] is now up.",
671  totemip_print (&instance->totem_interface->boundto));
673  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
674  }
675  /*
676  * Add a timer to check for interface going down in single membership
677  */
678  if (instance->my_memb_entries == 1) {
679  qb_loop_timer_add (instance->totemudp_poll_handle,
680  QB_LOOP_MED,
681  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
682  (void *)instance,
683  timer_function_netif_check_timeout,
684  &instance->timer_netif_check_timeout);
685  }
686 
687  } else {
690  "The network interface is down.");
691  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
692  }
694 
695  }
696 }
697 
698 /* Set the socket priority to INTERACTIVE to ensure
699  that our messages don't get queued behind anything else */
700 static void totemudp_traffic_control_set(struct totemudp_instance *instance, int sock)
701 {
702 #ifdef SO_PRIORITY
703  int prio = 6; /* TC_PRIO_INTERACTIVE */
704 
705  if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) {
706  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning, "Could not set traffic priority");
707  }
708 #endif
709 }
710 
711 static int totemudp_build_sockets_ip (
712  struct totemudp_instance *instance,
713  struct totem_ip_address *mcast_address,
714  struct totem_ip_address *bindnet_address,
715  struct totemudp_socket *sockets,
716  struct totem_ip_address *bound_to,
717  int interface_num)
718 {
719  struct sockaddr_storage sockaddr;
720  struct ipv6_mreq mreq6;
721  struct ip_mreq mreq;
722  struct sockaddr_storage mcast_ss, boundto_ss;
723  struct sockaddr_in6 *mcast_sin6 = (struct sockaddr_in6 *)&mcast_ss;
724  struct sockaddr_in *mcast_sin = (struct sockaddr_in *)&mcast_ss;
725  struct sockaddr_in *boundto_sin = (struct sockaddr_in *)&boundto_ss;
726  unsigned int sendbuf_size;
727  unsigned int recvbuf_size;
728  unsigned int optlen = sizeof (sendbuf_size);
729  int addrlen;
730  int res;
731  int flag;
732  uint8_t sflag;
733  int i;
734 
735  /*
736  * Create multicast recv socket
737  */
738  sockets->mcast_recv = socket (bindnet_address->family, SOCK_DGRAM, 0);
739  if (sockets->mcast_recv == -1) {
740  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
741  "socket() failed");
742  return (-1);
743  }
744 
745  totemip_nosigpipe (sockets->mcast_recv);
746  res = fcntl (sockets->mcast_recv, F_SETFL, O_NONBLOCK);
747  if (res == -1) {
748  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
749  "Could not set non-blocking operation on multicast socket");
750  return (-1);
751  }
752 
753  /*
754  * Force reuse
755  */
756  flag = 1;
757  if ( setsockopt(sockets->mcast_recv, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
758  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
759  "setsockopt(SO_REUSEADDR) failed");
760  return (-1);
761  }
762 
763  /*
764  * Bind to multicast socket used for multicast receives
765  */
767  instance->totem_interface->ip_port, &sockaddr, &addrlen);
768  res = bind (sockets->mcast_recv, (struct sockaddr *)&sockaddr, addrlen);
769  if (res == -1) {
770  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
771  "Unable to bind the socket to receive multicast packets");
772  return (-1);
773  }
774 
775  /*
776  * Create local multicast loop socket
777  */
778  if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets->local_mcast_loop) == -1) {
779  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
780  "socket() failed");
781  return (-1);
782  }
783 
784  for (i = 0; i < 2; i++) {
785  totemip_nosigpipe (sockets->local_mcast_loop[i]);
786  res = fcntl (sockets->local_mcast_loop[i], F_SETFL, O_NONBLOCK);
787  if (res == -1) {
788  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
789  "Could not set non-blocking operation on multicast socket");
790  return (-1);
791  }
792  }
793 
794 
795 
796  /*
797  * Setup mcast send socket
798  */
799  sockets->mcast_send = socket (bindnet_address->family, SOCK_DGRAM, 0);
800  if (sockets->mcast_send == -1) {
801  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
802  "socket() failed");
803  return (-1);
804  }
805 
806  totemip_nosigpipe (sockets->mcast_send);
807  res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK);
808  if (res == -1) {
809  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
810  "Could not set non-blocking operation on multicast socket");
811  return (-1);
812  }
813 
814  /*
815  * Force reuse
816  */
817  flag = 1;
818  if ( setsockopt(sockets->mcast_send, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
819  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
820  "setsockopt(SO_REUSEADDR) failed");
821  return (-1);
822  }
823 
825  &sockaddr, &addrlen);
826  res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen);
827  if (res == -1) {
828  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
829  "Unable to bind the socket to send multicast packets");
830  return (-1);
831  }
832 
833  /*
834  * Setup unicast socket
835  */
836  sockets->token = socket (bindnet_address->family, SOCK_DGRAM, 0);
837  if (sockets->token == -1) {
838  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
839  "socket() failed");
840  return (-1);
841  }
842 
843  totemip_nosigpipe (sockets->token);
844  res = fcntl (sockets->token, F_SETFL, O_NONBLOCK);
845  if (res == -1) {
846  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
847  "Could not set non-blocking operation on token socket");
848  return (-1);
849  }
850 
851  /*
852  * Force reuse
853  */
854  flag = 1;
855  if ( setsockopt(sockets->token, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
856  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
857  "setsockopt(SO_REUSEADDR) failed");
858  return (-1);
859  }
860 
861  /*
862  * Bind to unicast socket used for token send/receives
863  * This has the side effect of binding to the correct interface
864  */
865  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
866  res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen);
867  if (res == -1) {
868  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
869  "Unable to bind UDP unicast socket");
870  return (-1);
871  }
872 
873  recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
874  sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
875  /*
876  * Set buffer sizes to avoid overruns
877  */
878  res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
879  if (res == -1) {
880  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
881  "Unable to set SO_RCVBUF size on UDP mcast socket");
882  return (-1);
883  }
884  res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
885  if (res == -1) {
886  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
887  "Unable to set SO_SNDBUF size on UDP mcast socket");
888  return (-1);
889  }
890  res = setsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
891  if (res == -1) {
892  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
893  "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
894  return (-1);
895  }
896  res = setsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
897  if (res == -1) {
898  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
899  "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
900  return (-1);
901  }
902 
903  res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
904  if (res == 0) {
906  "Receive multicast socket recv buffer size (%d bytes).", recvbuf_size);
907  }
908 
909  res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
910  if (res == 0) {
912  "Transmit multicast socket send buffer size (%d bytes).", sendbuf_size);
913  }
914 
915  res = getsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
916  if (res == 0) {
918  "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
919  }
920 
921  res = getsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
922  if (res == 0) {
924  "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
925  }
926 
927 
928  /*
929  * Join group membership on socket
930  */
931  totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_interface->ip_port, &mcast_ss, &addrlen);
932  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &boundto_ss, &addrlen);
933 
934  if (instance->totem_config->broadcast_use == 1) {
935  unsigned int broadcast = 1;
936 
937  if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
938  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
939  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
940  "setting broadcast option failed");
941  return (-1);
942  }
943  if ((setsockopt(sockets->mcast_send, SOL_SOCKET,
944  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
945  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
946  "setting broadcast option failed");
947  return (-1);
948  }
949  } else {
950  switch (bindnet_address->family) {
951  case AF_INET:
952  memset(&mreq, 0, sizeof(mreq));
953  mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
954  mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
955  res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
956  &mreq, sizeof (mreq));
957  if (res == -1) {
958  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
959  "join ipv4 multicast group failed");
960  return (-1);
961  }
962  break;
963  case AF_INET6:
964  memset(&mreq6, 0, sizeof(mreq6));
965  memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
966  mreq6.ipv6mr_interface = interface_num;
967 
968  res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
969  &mreq6, sizeof (mreq6));
970  if (res == -1) {
971  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
972  "join ipv6 multicast group failed");
973  return (-1);
974  }
975  break;
976  }
977  }
978 
979  /*
980  * Turn off multicast loopback
981  */
982 
983  flag = 0;
984  switch ( bindnet_address->family ) {
985  case AF_INET:
986  sflag = 0;
987  res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP,
988  &sflag, sizeof (sflag));
989  break;
990  case AF_INET6:
991  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
992  &flag, sizeof (flag));
993  }
994  if (res == -1) {
995  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
996  "Unable to turn off multicast loopback");
997  return (-1);
998  }
999 
1000  /*
1001  * Set multicast packets TTL
1002  */
1003  flag = instance->totem_interface->ttl;
1004  if (bindnet_address->family == AF_INET6) {
1005  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
1006  &flag, sizeof (flag));
1007  if (res == -1) {
1008  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1009  "set mcast v6 TTL failed");
1010  return (-1);
1011  }
1012  } else {
1013  sflag = flag;
1014  res = setsockopt(sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_TTL,
1015  &sflag, sizeof(sflag));
1016  if (res == -1) {
1017  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1018  "set mcast v4 TTL failed");
1019  return (-1);
1020  }
1021  }
1022 
1023  /*
1024  * Bind to a specific interface for multicast send and receive
1025  */
1026  switch ( bindnet_address->family ) {
1027  case AF_INET:
1028  if (setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_IF,
1029  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1030  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1031  "cannot select interface for multicast packets (send)");
1032  return (-1);
1033  }
1034  if (setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_IF,
1035  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1036  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1037  "cannot select interface for multicast packets (recv)");
1038  return (-1);
1039  }
1040  break;
1041  case AF_INET6:
1042  if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1043  &interface_num, sizeof (interface_num)) < 0) {
1044  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1045  "cannot select interface for multicast packets (send v6)");
1046  return (-1);
1047  }
1048  if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1049  &interface_num, sizeof (interface_num)) < 0) {
1050  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1051  "cannot select interface for multicast packets (recv v6)");
1052  return (-1);
1053  }
1054  break;
1055  }
1056 
1057  return 0;
1058 }
1059 
1060 static int totemudp_build_sockets (
1061  struct totemudp_instance *instance,
1062  struct totem_ip_address *mcast_address,
1063  struct totem_ip_address *bindnet_address,
1064  struct totemudp_socket *sockets,
1065  struct totem_ip_address *bound_to)
1066 {
1067  int interface_num;
1068  int interface_up;
1069  int res;
1070 
1071  /*
1072  * Determine the ip address bound to and the interface name
1073  */
1074  res = netif_determine (instance,
1075  bindnet_address,
1076  bound_to,
1077  &interface_up,
1078  &interface_num);
1079 
1080  if (res == -1) {
1081  return (-1);
1082  }
1083 
1084  totemip_copy(&instance->my_id, bound_to);
1085 
1086  res = totemudp_build_sockets_ip (instance, mcast_address,
1087  bindnet_address, sockets, bound_to, interface_num);
1088 
1089  /* We only send out of the token socket */
1090  totemudp_traffic_control_set(instance, sockets->token);
1091  return res;
1092 }
1093 
1094 /*
1095  * Totem Network interface - also does encryption/decryption
1096  * depends on poll abstraction, POSIX, IPV4
1097  */
1098 
1099 /*
1100  * Create an instance
1101  */
1103  qb_loop_t *poll_handle,
1104  void **udp_context,
1105  struct totem_config *totem_config,
1106  totemsrp_stats_t *stats,
1107  int interface_no,
1108  void *context,
1109 
1110  void (*deliver_fn) (
1111  void *context,
1112  const void *msg,
1113  unsigned int msg_len),
1114 
1115  void (*iface_change_fn) (
1116  void *context,
1117  const struct totem_ip_address *iface_address),
1118 
1119  void (*target_set_completed) (
1120  void *context))
1121 {
1122  struct totemudp_instance *instance;
1123 
1124  instance = malloc (sizeof (struct totemudp_instance));
1125  if (instance == NULL) {
1126  return (-1);
1127  }
1128 
1129  totemudp_instance_initialize (instance);
1130 
1131  instance->totem_config = totem_config;
1132  instance->stats = stats;
1133 
1134  /*
1135  * Configure logging
1136  */
1137  instance->totemudp_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1144 
1145  /*
1146  * Initialize random number generator for later use to generate salt
1147  */
1148  instance->crypto_inst = crypto_init (totem_config->private_key,
1149  totem_config->private_key_len,
1150  totem_config->crypto_cipher_type,
1151  totem_config->crypto_hash_type,
1152  instance->totemudp_log_printf,
1153  instance->totemudp_log_level_security,
1154  instance->totemudp_log_level_notice,
1155  instance->totemudp_log_level_error,
1156  instance->totemudp_subsys_id);
1157  if (instance->crypto_inst == NULL) {
1158  free(instance);
1159  return (-1);
1160  }
1161  /*
1162  * Initialize local variables for totemudp
1163  */
1164  instance->totem_interface = &totem_config->interfaces[interface_no];
1165  totemip_copy (&instance->mcast_address, &instance->totem_interface->mcast_addr);
1166  memset (instance->iov_buffer, 0, FRAME_SIZE_MAX);
1167 
1168  instance->totemudp_poll_handle = poll_handle;
1169 
1170  instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
1171 
1172  instance->context = context;
1173  instance->totemudp_deliver_fn = deliver_fn;
1174 
1175  instance->totemudp_iface_change_fn = iface_change_fn;
1176 
1177  instance->totemudp_target_set_completed = target_set_completed;
1178 
1179  totemip_localhost (instance->mcast_address.family, &localhost);
1180  localhost.nodeid = instance->totem_config->node_id;
1181 
1182  /*
1183  * RRP layer isn't ready to receive message because it hasn't
1184  * initialized yet. Add short timer to check the interfaces.
1185  */
1186  qb_loop_timer_add (instance->totemudp_poll_handle,
1187  QB_LOOP_MED,
1188  100*QB_TIME_NS_IN_MSEC,
1189  (void *)instance,
1190  timer_function_netif_check_timeout,
1191  &instance->timer_netif_check_timeout);
1192 
1193  *udp_context = instance;
1194  return (0);
1195 }
1196 
1198 {
1199  return malloc (FRAME_SIZE_MAX);
1200 }
1201 
1202 void totemudp_buffer_release (void *ptr)
1203 {
1204  return free (ptr);
1205 }
1206 
1208  void *udp_context,
1209  int processor_count)
1210 {
1211  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1212  int res = 0;
1213 
1214  instance->my_memb_entries = processor_count;
1215  qb_loop_timer_del (instance->totemudp_poll_handle,
1216  instance->timer_netif_check_timeout);
1217  if (processor_count == 1) {
1218  qb_loop_timer_add (instance->totemudp_poll_handle,
1219  QB_LOOP_MED,
1220  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
1221  (void *)instance,
1222  timer_function_netif_check_timeout,
1223  &instance->timer_netif_check_timeout);
1224  }
1225 
1226  return (res);
1227 }
1228 
1229 int totemudp_recv_flush (void *udp_context)
1230 {
1231  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1232  struct pollfd ufd;
1233  int nfds;
1234  int res = 0;
1235  int i;
1236  int sock;
1237 
1238  instance->flushing = 1;
1239 
1240  for (i = 0; i < 2; i++) {
1241  sock = -1;
1242  if (i == 0) {
1243  sock = instance->totemudp_sockets.mcast_recv;
1244  }
1245  if (i == 1) {
1246  sock = instance->totemudp_sockets.local_mcast_loop[0];
1247  }
1248  assert(sock != -1);
1249 
1250  do {
1251  ufd.fd = sock;
1252  ufd.events = POLLIN;
1253  nfds = poll (&ufd, 1, 0);
1254  if (nfds == 1 && ufd.revents & POLLIN) {
1255  net_deliver_fn (sock, ufd.revents, instance);
1256  }
1257  } while (nfds == 1);
1258  }
1259 
1260  instance->flushing = 0;
1261 
1262  return (res);
1263 }
1264 
1265 int totemudp_send_flush (void *udp_context)
1266 {
1267  return 0;
1268 }
1269 
1271  void *udp_context,
1272  const void *msg,
1273  unsigned int msg_len)
1274 {
1275  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1276  int res = 0;
1277 
1278  ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1279 
1280  return (res);
1281 }
1283  void *udp_context,
1284  const void *msg,
1285  unsigned int msg_len)
1286 {
1287  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1288  int res = 0;
1289 
1290  mcast_sendmsg (instance, msg, msg_len);
1291 
1292  return (res);
1293 }
1294 
1296  void *udp_context,
1297  const void *msg,
1298  unsigned int msg_len)
1299 {
1300  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1301  int res = 0;
1302 
1303  mcast_sendmsg (instance, msg, msg_len);
1304 
1305  return (res);
1306 }
1307 
1308 extern int totemudp_iface_check (void *udp_context)
1309 {
1310  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1311  int res = 0;
1312 
1313  timer_function_netif_check_timeout (instance);
1314 
1315  return (res);
1316 }
1317 
1318 extern void totemudp_net_mtu_adjust (void *udp_context, struct totem_config *totem_config)
1319 {
1320 
1321  assert(totem_config->interface_count > 0);
1322 
1323  totem_config->net_mtu -= crypto_sec_header_size(totem_config->crypto_cipher_type,
1324  totem_config->crypto_hash_type) +
1326 }
1327 
1328 const char *totemudp_iface_print (void *udp_context) {
1329  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1330  const char *ret_char;
1331 
1332  ret_char = totemip_print (&instance->my_id);
1333 
1334  return (ret_char);
1335 }
1336 
1338  void *udp_context,
1339  struct totem_ip_address *addr)
1340 {
1341  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1342  int res = 0;
1343 
1344  memcpy (addr, &instance->my_id, sizeof (struct totem_ip_address));
1345 
1346  return (res);
1347 }
1348 
1350  void *udp_context,
1351  const struct totem_ip_address *token_target)
1352 {
1353  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1354  int res = 0;
1355 
1356  memcpy (&instance->token_target, token_target,
1357  sizeof (struct totem_ip_address));
1358 
1359  instance->totemudp_target_set_completed (instance->context);
1360 
1361  return (res);
1362 }
1363 
1365  void *udp_context)
1366 {
1367  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1368  unsigned int res;
1369  struct sockaddr_storage system_from;
1370  struct msghdr msg_recv;
1371  struct pollfd ufd;
1372  int nfds;
1373  int msg_processed = 0;
1374  int i;
1375  int sock;
1376 
1377  /*
1378  * Receive datagram
1379  */
1380  msg_recv.msg_name = &system_from;
1381  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
1382  msg_recv.msg_iov = &instance->totemudp_iov_recv_flush;
1383  msg_recv.msg_iovlen = 1;
1384 #ifdef HAVE_MSGHDR_CONTROL
1385  msg_recv.msg_control = 0;
1386 #endif
1387 #ifdef HAVE_MSGHDR_CONTROLLEN
1388  msg_recv.msg_controllen = 0;
1389 #endif
1390 #ifdef HAVE_MSGHDR_FLAGS
1391  msg_recv.msg_flags = 0;
1392 #endif
1393 #ifdef HAVE_MSGHDR_ACCRIGHTS
1394  msg_recv.msg_accrights = NULL;
1395 #endif
1396 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1397  msg_recv.msg_accrightslen = 0;
1398 #endif
1399 
1400  for (i = 0; i < 2; i++) {
1401  sock = -1;
1402  if (i == 0) {
1403  sock = instance->totemudp_sockets.mcast_recv;
1404  }
1405  if (i == 1) {
1406  sock = instance->totemudp_sockets.local_mcast_loop[0];
1407  }
1408  assert(sock != -1);
1409 
1410  do {
1411  ufd.fd = sock;
1412  ufd.events = POLLIN;
1413  nfds = poll (&ufd, 1, 0);
1414  if (nfds == 1 && ufd.revents & POLLIN) {
1415  res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
1416  if (res != -1) {
1417  msg_processed = 1;
1418  } else {
1419  msg_processed = -1;
1420  }
1421  }
1422  } while (nfds == 1);
1423  }
1424 
1425  return (msg_processed);
1426 }
1427 
unsigned int clear_node_high_bit
Definition: totem.h:117
unsigned short family
Definition: coroapi.h:97
int totemudp_crypto_set(void *udp_context, const char *cipher_type, const char *hash_type)
Definition: totemudp.c:249
int totemudp_processor_count_set(void *udp_context, int processor_count)
Definition: totemudp.c:1207
int totemip_localhost(int family, struct totem_ip_address *localhost)
Definition: totemip.c:182
int totemudp_subsys_id
Definition: totemudp.c:143
struct iovec totemudp_iov_recv_flush
Definition: totemudp.c:162
struct totem_interface * interfaces
Definition: totem.h:114
unsigned int interface_count
Definition: totem.h:115
totemsrp_stats_t * stats
Definition: totemudp.c:192
struct totemudp_instance * instance
Definition: totemudp.c:200
struct crypto_instance * crypto_inst
Definition: totemudp.c:107
size_t crypto_sec_header_size(const char *crypto_cipher_type, const char *crypto_hash_type)
Definition: totemcrypto.c:662
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:214
void(* totemudp_iface_change_fn)(void *context, const struct totem_ip_address *iface_address)
Definition: totemudp.c:124
void(* totemudp_deliver_fn)(void *context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:119
void totemudp_net_mtu_adjust(void *udp_context, struct totem_config *totem_config)
Definition: totemudp.c:1318
void * totemudp_buffer_alloc(void)
Definition: totemudp.c:1197
int totemudp_mcast_flush_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1282
int totemudp_token_target_set(void *udp_context, const struct totem_ip_address *token_target)
Definition: totemudp.c:1349
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN]
Definition: totem.h:122
char iov_buffer[FRAME_SIZE_MAX]
Definition: totemudp.c:156
#define MSG_NOSIGNAL
Definition: totemudp.c:80
struct totemudp_socket totemudp_sockets
Definition: totemudp.c:164
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:67
struct crypto_instance * crypto_init(const unsigned char *private_key, unsigned int private_key_len, const char *crypto_cipher_type, const char *crypto_hash_type, void(*log_printf_func)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf, 6, 7))), int log_level_security, int log_level_notice, int log_level_error, int log_subsys_id)
Definition: totemcrypto.c:786
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:95
struct totem_ip_address mcast_address
Definition: totemudp.c:166
unsigned int downcheck_timeout
Definition: totem.h:145
int totemudp_mcast_noflush_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1295
unsigned int private_key_len
Definition: totem.h:124
int totemudp_log_level_security
Definition: totemudp.c:133
#define BIND_STATE_REGULAR
Definition: totemudp.c:88
struct totem_config * totem_config
Definition: totemudp.c:190
#define NETIF_STATE_REPORT_DOWN
Definition: totemudp.c:85
#define totemip_nosigpipe(s)
Definition: totemip.h:56
int totemudp_log_level_error
Definition: totemudp.c:135
message_type
Definition: totemsrp.c:139
int totemudp_send_flush(void *udp_context)
Definition: totemudp.c:1265
uint16_t ttl
Definition: totem.h:69
int totemudp_recv_flush(void *udp_context)
Definition: totemudp.c:1229
unsigned int node_id
Definition: totem.h:116
struct iovec totemudp_iov_recv
Definition: totemudp.c:160
int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit)
Definition: totemip.c:405
int crypto_encrypt_and_sign(struct crypto_instance *instance, const unsigned char *buf_in, const size_t buf_in_len, unsigned char *buf_out, size_t *buf_out_len)
Definition: totemcrypto.c:711
int totemudp_token_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1270
struct totem_interface * totem_interface
Definition: totemudp.c:111
int totemudp_initialize(qb_loop_t *poll_handle, void **udp_context, struct totem_config *totem_config, totemsrp_stats_t *stats, int interface_no, void *context, void(*deliver_fn)(void *context, const void *msg, unsigned int msg_len), void(*iface_change_fn)(void *context, const struct totem_ip_address *iface_address), void(*target_set_completed)(void *context))
Create an instance.
Definition: totemudp.c:1102
unsigned int nodeid
Definition: coroapi.h:96
qb_loop_t * totemudp_poll_handle
Definition: totemudp.c:109
char * crypto_hash_type
Definition: totem.h:183
int netif_state_report
Definition: totemudp.c:113
unsigned int my_memb_entries
Definition: totemudp.c:186
struct totem_ip_address mcast_addr
Definition: totem.h:67
Linked list API.
void(* totemudp_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
Definition: totemudp.c:145
int totemudp_finalize(void *udp_context)
Definition: totemudp.c:413
struct totem_ip_address boundto
Definition: totem.h:66
#define BIND_STATE_LOOPBACK
Definition: totemudp.c:89
typedef __attribute__
size_t totemip_udpip_header_size(int family)
Definition: totemip.c:496
const char * totemudp_iface_print(void *udp_context)
Definition: totemudp.c:1328
#define NETIF_STATE_REPORT_UP
Definition: totemudp.c:84
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:75
uint16_t ip_port
Definition: totem.h:68
#define MCAST_SOCKET_BUFFER_SIZE
Definition: totemudp.c:83
void(*) void udp_context)
Definition: totemudp.c:152
unsigned int net_mtu
Definition: totem.h:165
char iov_buffer_flush[FRAME_SIZE_MAX]
Definition: totemudp.c:158
int totemudp_log_level_debug
Definition: totemudp.c:141
int crypto_authenticate_and_decrypt(struct crypto_instance *instance, unsigned char *buf, int *buf_len)
Definition: totemcrypto.c:733
int totemudp_log_level_notice
Definition: totemudp.c:139
#define MESSAGE_TYPE_MEMB_JOIN
Definition: totemudp.c:91
unsigned int broadcast_use
Definition: totem.h:179
int totemudp_iface_get(void *udp_context, struct totem_ip_address *addr)
Definition: totemudp.c:1337
#define FRAME_SIZE_MAX
Definition: totem.h:50
#define LOGSYS_LEVEL_CRIT
Definition: logsys.h:69
void(* totemudp_target_set_completed)(void *context)
Definition: totemudp.c:128
const void * msg
Definition: totemudp.c:198
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
Definition: totemip.c:222
struct totem_logging_configuration totem_logging_configuration
Definition: totem.h:163
#define LOGSYS_PERROR(err_num, level, fmt, args...)
Definition: totemudp.c:239
struct srp_addr system_from
Definition: totemsrp.c:61
#define log_printf(level, format, args...)
Definition: totemudp.c:231
char * crypto_cipher_type
Definition: totem.h:181
struct totem_ip_address my_id
Definition: totemudp.c:180
int totemudp_recv_mcast_empty(void *udp_context)
Definition: totemudp.c:1364
int totemudp_iface_check(void *udp_context)
Definition: totemudp.c:1308
struct totem_ip_address bindnet
Definition: totem.h:65
uint32_t continuous_sendmsg_failures
Definition: totem.h:269
unsigned int msg_len
Definition: totemudp.c:199
int local_mcast_loop[2]
Definition: totemudp.c:103
struct totem_ip_address token_target
Definition: totemudp.c:194
qb_loop_timer_handle timer_netif_check_timeout
Definition: totemudp.c:184
void totemudp_buffer_release(void *ptr)
Definition: totemudp.c:1202
int totemudp_log_level_warning
Definition: totemudp.c:137