corosync  2.3.4
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 
120  void *context,
121  const void *msg,
122  unsigned int msg_len);
123 
125  void *context,
126  const struct totem_ip_address *iface_address);
127 
129 
130  /*
131  * Function and data used to log messages
132  */
134 
136 
138 
140 
142 
144 
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 
157 
159 
160  struct iovec totemudp_iov_recv;
161 
163 
165 
167 
169 
171 
173 
175 
177 
178  struct timeval stats_tv_start;
179 
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 
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  iovec->iov_len = FRAME_SIZE_MAX;
515  return (0);
516  }
517 
518  /*
519  * Handle incoming message
520  */
521  instance->totemudp_deliver_fn (
522  instance->context,
523  iovec->iov_base,
524  iovec->iov_len);
525 
526  iovec->iov_len = FRAME_SIZE_MAX;
527  return (0);
528 }
529 
530 static int netif_determine (
531  struct totemudp_instance *instance,
532  struct totem_ip_address *bindnet,
533  struct totem_ip_address *bound_to,
534  int *interface_up,
535  int *interface_num)
536 {
537  int res;
538 
539  res = totemip_iface_check (bindnet, bound_to,
540  interface_up, interface_num,
541  instance->totem_config->clear_node_high_bit);
542 
543 
544  return (res);
545 }
546 
547 
548 /*
549  * If the interface is up, the sockets for totem are built. If the interface is down
550  * this function is requeued in the timer list to retry building the sockets later.
551  */
552 static void timer_function_netif_check_timeout (
553  void *data)
554 {
555  struct totemudp_instance *instance = (struct totemudp_instance *)data;
556  int interface_up;
557  int interface_num;
558  struct totem_ip_address *bind_address;
559 
560  /*
561  * Build sockets for every interface
562  */
563  netif_determine (instance,
564  &instance->totem_interface->bindnet,
565  &instance->totem_interface->boundto,
566  &interface_up, &interface_num);
567  /*
568  * If the network interface isn't back up and we are already
569  * in loopback mode, add timer to check again and return
570  */
571  if ((instance->netif_bind_state == BIND_STATE_LOOPBACK &&
572  interface_up == 0) ||
573 
574  (instance->my_memb_entries == 1 &&
575  instance->netif_bind_state == BIND_STATE_REGULAR &&
576  interface_up == 1)) {
577 
578  qb_loop_timer_add (instance->totemudp_poll_handle,
579  QB_LOOP_MED,
580  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
581  (void *)instance,
582  timer_function_netif_check_timeout,
583  &instance->timer_netif_check_timeout);
584 
585  /*
586  * Add a timer to check for a downed regular interface
587  */
588  return;
589  }
590 
591  if (instance->totemudp_sockets.mcast_recv > 0) {
592  qb_loop_poll_del (instance->totemudp_poll_handle,
593  instance->totemudp_sockets.mcast_recv);
594  close (instance->totemudp_sockets.mcast_recv);
595  }
596  if (instance->totemudp_sockets.mcast_send > 0) {
597  close (instance->totemudp_sockets.mcast_send);
598  }
599  if (instance->totemudp_sockets.local_mcast_loop[0] > 0) {
600  qb_loop_poll_del (instance->totemudp_poll_handle,
601  instance->totemudp_sockets.local_mcast_loop[0]);
602  close (instance->totemudp_sockets.local_mcast_loop[0]);
603  close (instance->totemudp_sockets.local_mcast_loop[1]);
604  }
605  if (instance->totemudp_sockets.token > 0) {
606  qb_loop_poll_del (instance->totemudp_poll_handle,
607  instance->totemudp_sockets.token);
608  close (instance->totemudp_sockets.token);
609  }
610 
611  if (interface_up == 0) {
612  /*
613  * Interface is not up
614  */
616  bind_address = &localhost;
617 
618  /*
619  * Add a timer to retry building interfaces and request memb_gather_enter
620  */
621  qb_loop_timer_add (instance->totemudp_poll_handle,
622  QB_LOOP_MED,
623  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
624  (void *)instance,
625  timer_function_netif_check_timeout,
626  &instance->timer_netif_check_timeout);
627  } else {
628  /*
629  * Interface is up
630  */
632  bind_address = &instance->totem_interface->bindnet;
633  }
634  /*
635  * Create and bind the multicast and unicast sockets
636  */
637  (void)totemudp_build_sockets (instance,
638  &instance->mcast_address,
639  bind_address,
640  &instance->totemudp_sockets,
641  &instance->totem_interface->boundto);
642 
643  qb_loop_poll_add (
644  instance->totemudp_poll_handle,
645  QB_LOOP_MED,
646  instance->totemudp_sockets.mcast_recv,
647  POLLIN, instance, net_deliver_fn);
648 
649  qb_loop_poll_add (
650  instance->totemudp_poll_handle,
651  QB_LOOP_MED,
652  instance->totemudp_sockets.local_mcast_loop[0],
653  POLLIN, instance, net_deliver_fn);
654 
655  qb_loop_poll_add (
656  instance->totemudp_poll_handle,
657  QB_LOOP_MED,
658  instance->totemudp_sockets.token,
659  POLLIN, instance, net_deliver_fn);
660 
661  totemip_copy (&instance->my_id, &instance->totem_interface->boundto);
662 
663  /*
664  * This reports changes in the interface to the user and totemsrp
665  */
666  if (instance->netif_bind_state == BIND_STATE_REGULAR) {
667  if (instance->netif_state_report & NETIF_STATE_REPORT_UP) {
669  "The network interface [%s] is now up.",
670  totemip_print (&instance->totem_interface->boundto));
672  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
673  }
674  /*
675  * Add a timer to check for interface going down in single membership
676  */
677  if (instance->my_memb_entries == 1) {
678  qb_loop_timer_add (instance->totemudp_poll_handle,
679  QB_LOOP_MED,
680  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
681  (void *)instance,
682  timer_function_netif_check_timeout,
683  &instance->timer_netif_check_timeout);
684  }
685 
686  } else {
689  "The network interface is down.");
690  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
691  }
693 
694  }
695 }
696 
697 /* Set the socket priority to INTERACTIVE to ensure
698  that our messages don't get queued behind anything else */
699 static void totemudp_traffic_control_set(struct totemudp_instance *instance, int sock)
700 {
701 #ifdef SO_PRIORITY
702  int prio = 6; /* TC_PRIO_INTERACTIVE */
703 
704  if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) {
705  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning, "Could not set traffic priority");
706  }
707 #endif
708 }
709 
710 static int totemudp_build_sockets_ip (
711  struct totemudp_instance *instance,
712  struct totem_ip_address *mcast_address,
713  struct totem_ip_address *bindnet_address,
714  struct totemudp_socket *sockets,
715  struct totem_ip_address *bound_to,
716  int interface_num)
717 {
718  struct sockaddr_storage sockaddr;
719  struct ipv6_mreq mreq6;
720  struct ip_mreq mreq;
721  struct sockaddr_storage mcast_ss, boundto_ss;
722  struct sockaddr_in6 *mcast_sin6 = (struct sockaddr_in6 *)&mcast_ss;
723  struct sockaddr_in *mcast_sin = (struct sockaddr_in *)&mcast_ss;
724  struct sockaddr_in *boundto_sin = (struct sockaddr_in *)&boundto_ss;
725  unsigned int sendbuf_size;
726  unsigned int recvbuf_size;
727  unsigned int optlen = sizeof (sendbuf_size);
728  int addrlen;
729  int res;
730  int flag;
731  uint8_t sflag;
732  int i;
733 
734  /*
735  * Create multicast recv socket
736  */
737  sockets->mcast_recv = socket (bindnet_address->family, SOCK_DGRAM, 0);
738  if (sockets->mcast_recv == -1) {
739  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
740  "socket() failed");
741  return (-1);
742  }
743 
744  totemip_nosigpipe (sockets->mcast_recv);
745  res = fcntl (sockets->mcast_recv, F_SETFL, O_NONBLOCK);
746  if (res == -1) {
747  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
748  "Could not set non-blocking operation on multicast socket");
749  return (-1);
750  }
751 
752  /*
753  * Force reuse
754  */
755  flag = 1;
756  if ( setsockopt(sockets->mcast_recv, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
757  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
758  "setsockopt(SO_REUSEADDR) failed");
759  return (-1);
760  }
761 
762  /*
763  * Bind to multicast socket used for multicast receives
764  */
766  instance->totem_interface->ip_port, &sockaddr, &addrlen);
767  res = bind (sockets->mcast_recv, (struct sockaddr *)&sockaddr, addrlen);
768  if (res == -1) {
769  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
770  "Unable to bind the socket to receive multicast packets");
771  return (-1);
772  }
773 
774  /*
775  * Create local multicast loop socket
776  */
777  if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets->local_mcast_loop) == -1) {
778  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
779  "socket() failed");
780  return (-1);
781  }
782 
783  for (i = 0; i < 2; i++) {
784  totemip_nosigpipe (sockets->local_mcast_loop[i]);
785  res = fcntl (sockets->local_mcast_loop[i], F_SETFL, O_NONBLOCK);
786  if (res == -1) {
787  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
788  "Could not set non-blocking operation on multicast socket");
789  return (-1);
790  }
791  }
792 
793 
794 
795  /*
796  * Setup mcast send socket
797  */
798  sockets->mcast_send = socket (bindnet_address->family, SOCK_DGRAM, 0);
799  if (sockets->mcast_send == -1) {
800  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
801  "socket() failed");
802  return (-1);
803  }
804 
805  totemip_nosigpipe (sockets->mcast_send);
806  res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK);
807  if (res == -1) {
808  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
809  "Could not set non-blocking operation on multicast socket");
810  return (-1);
811  }
812 
813  /*
814  * Force reuse
815  */
816  flag = 1;
817  if ( setsockopt(sockets->mcast_send, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
818  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
819  "setsockopt(SO_REUSEADDR) failed");
820  return (-1);
821  }
822 
824  &sockaddr, &addrlen);
825  res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen);
826  if (res == -1) {
827  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
828  "Unable to bind the socket to send multicast packets");
829  return (-1);
830  }
831 
832  /*
833  * Setup unicast socket
834  */
835  sockets->token = socket (bindnet_address->family, SOCK_DGRAM, 0);
836  if (sockets->token == -1) {
837  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
838  "socket() failed");
839  return (-1);
840  }
841 
842  totemip_nosigpipe (sockets->token);
843  res = fcntl (sockets->token, F_SETFL, O_NONBLOCK);
844  if (res == -1) {
845  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
846  "Could not set non-blocking operation on token socket");
847  return (-1);
848  }
849 
850  /*
851  * Force reuse
852  */
853  flag = 1;
854  if ( setsockopt(sockets->token, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
855  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
856  "setsockopt(SO_REUSEADDR) failed");
857  return (-1);
858  }
859 
860  /*
861  * Bind to unicast socket used for token send/receives
862  * This has the side effect of binding to the correct interface
863  */
864  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
865  res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen);
866  if (res == -1) {
867  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
868  "Unable to bind UDP unicast socket");
869  return (-1);
870  }
871 
872  recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
873  sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
874  /*
875  * Set buffer sizes to avoid overruns
876  */
877  res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
878  if (res == -1) {
879  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
880  "Unable to set SO_RCVBUF size on UDP mcast socket");
881  return (-1);
882  }
883  res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
884  if (res == -1) {
885  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
886  "Unable to set SO_SNDBUF size on UDP mcast socket");
887  return (-1);
888  }
889  res = setsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
890  if (res == -1) {
891  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
892  "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
893  return (-1);
894  }
895  res = setsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
896  if (res == -1) {
897  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
898  "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
899  return (-1);
900  }
901 
902  res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
903  if (res == 0) {
905  "Receive multicast socket recv buffer size (%d bytes).", recvbuf_size);
906  }
907 
908  res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
909  if (res == 0) {
911  "Transmit multicast socket send buffer size (%d bytes).", sendbuf_size);
912  }
913 
914  res = getsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
915  if (res == 0) {
917  "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
918  }
919 
920  res = getsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
921  if (res == 0) {
923  "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
924  }
925 
926 
927  /*
928  * Join group membership on socket
929  */
930  totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_interface->ip_port, &mcast_ss, &addrlen);
931  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &boundto_ss, &addrlen);
932 
933  if (instance->totem_config->broadcast_use == 1) {
934  unsigned int broadcast = 1;
935 
936  if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
937  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
938  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
939  "setting broadcast option failed");
940  return (-1);
941  }
942  if ((setsockopt(sockets->mcast_send, SOL_SOCKET,
943  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
944  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
945  "setting broadcast option failed");
946  return (-1);
947  }
948  } else {
949  switch (bindnet_address->family) {
950  case AF_INET:
951  memset(&mreq, 0, sizeof(mreq));
952  mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
953  mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
954  res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
955  &mreq, sizeof (mreq));
956  if (res == -1) {
957  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
958  "join ipv4 multicast group failed");
959  return (-1);
960  }
961  break;
962  case AF_INET6:
963  memset(&mreq6, 0, sizeof(mreq6));
964  memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
965  mreq6.ipv6mr_interface = interface_num;
966 
967  res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
968  &mreq6, sizeof (mreq6));
969  if (res == -1) {
970  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
971  "join ipv6 multicast group failed");
972  return (-1);
973  }
974  break;
975  }
976  }
977 
978  /*
979  * Turn off multicast loopback
980  */
981 
982  flag = 0;
983  switch ( bindnet_address->family ) {
984  case AF_INET:
985  sflag = 0;
986  res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP,
987  &sflag, sizeof (sflag));
988  break;
989  case AF_INET6:
990  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
991  &flag, sizeof (flag));
992  }
993  if (res == -1) {
994  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
995  "Unable to turn off multicast loopback");
996  return (-1);
997  }
998 
999  /*
1000  * Set multicast packets TTL
1001  */
1002  flag = instance->totem_interface->ttl;
1003  if (bindnet_address->family == AF_INET6) {
1004  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
1005  &flag, sizeof (flag));
1006  if (res == -1) {
1007  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1008  "set mcast v6 TTL failed");
1009  return (-1);
1010  }
1011  } else {
1012  sflag = flag;
1013  res = setsockopt(sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_TTL,
1014  &sflag, sizeof(sflag));
1015  if (res == -1) {
1016  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1017  "set mcast v4 TTL failed");
1018  return (-1);
1019  }
1020  }
1021 
1022  /*
1023  * Bind to a specific interface for multicast send and receive
1024  */
1025  switch ( bindnet_address->family ) {
1026  case AF_INET:
1027  if (setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_IF,
1028  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1029  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1030  "cannot select interface for multicast packets (send)");
1031  return (-1);
1032  }
1033  if (setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_IF,
1034  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1035  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1036  "cannot select interface for multicast packets (recv)");
1037  return (-1);
1038  }
1039  break;
1040  case AF_INET6:
1041  if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1042  &interface_num, sizeof (interface_num)) < 0) {
1043  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1044  "cannot select interface for multicast packets (send v6)");
1045  return (-1);
1046  }
1047  if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1048  &interface_num, sizeof (interface_num)) < 0) {
1049  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1050  "cannot select interface for multicast packets (recv v6)");
1051  return (-1);
1052  }
1053  break;
1054  }
1055 
1056  return 0;
1057 }
1058 
1059 static int totemudp_build_sockets (
1060  struct totemudp_instance *instance,
1061  struct totem_ip_address *mcast_address,
1062  struct totem_ip_address *bindnet_address,
1063  struct totemudp_socket *sockets,
1064  struct totem_ip_address *bound_to)
1065 {
1066  int interface_num;
1067  int interface_up;
1068  int res;
1069 
1070  /*
1071  * Determine the ip address bound to and the interface name
1072  */
1073  res = netif_determine (instance,
1074  bindnet_address,
1075  bound_to,
1076  &interface_up,
1077  &interface_num);
1078 
1079  if (res == -1) {
1080  return (-1);
1081  }
1082 
1083  totemip_copy(&instance->my_id, bound_to);
1084 
1085  res = totemudp_build_sockets_ip (instance, mcast_address,
1086  bindnet_address, sockets, bound_to, interface_num);
1087 
1088  /* We only send out of the token socket */
1089  totemudp_traffic_control_set(instance, sockets->token);
1090  return res;
1091 }
1092 
1093 /*
1094  * Totem Network interface - also does encryption/decryption
1095  * depends on poll abstraction, POSIX, IPV4
1096  */
1097 
1098 /*
1099  * Create an instance
1100  */
1102  qb_loop_t *poll_handle,
1103  void **udp_context,
1104  struct totem_config *totem_config,
1105  totemsrp_stats_t *stats,
1106  int interface_no,
1107  void *context,
1108 
1109  void (*deliver_fn) (
1110  void *context,
1111  const void *msg,
1112  unsigned int msg_len),
1113 
1114  void (*iface_change_fn) (
1115  void *context,
1116  const struct totem_ip_address *iface_address),
1117 
1118  void (*target_set_completed) (
1119  void *context))
1120 {
1121  struct totemudp_instance *instance;
1122 
1123  instance = malloc (sizeof (struct totemudp_instance));
1124  if (instance == NULL) {
1125  return (-1);
1126  }
1127 
1128  totemudp_instance_initialize (instance);
1129 
1130  instance->totem_config = totem_config;
1131  instance->stats = stats;
1132 
1133  /*
1134  * Configure logging
1135  */
1136  instance->totemudp_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1143 
1144  /*
1145  * Initialize random number generator for later use to generate salt
1146  */
1147  instance->crypto_inst = crypto_init (totem_config->private_key,
1148  totem_config->private_key_len,
1149  totem_config->crypto_cipher_type,
1150  totem_config->crypto_hash_type,
1151  instance->totemudp_log_printf,
1152  instance->totemudp_log_level_security,
1153  instance->totemudp_log_level_notice,
1154  instance->totemudp_log_level_error,
1155  instance->totemudp_subsys_id);
1156  if (instance->crypto_inst == NULL) {
1157  free(instance);
1158  return (-1);
1159  }
1160  /*
1161  * Initialize local variables for totemudp
1162  */
1163  instance->totem_interface = &totem_config->interfaces[interface_no];
1164  totemip_copy (&instance->mcast_address, &instance->totem_interface->mcast_addr);
1165  memset (instance->iov_buffer, 0, FRAME_SIZE_MAX);
1166 
1167  instance->totemudp_poll_handle = poll_handle;
1168 
1169  instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
1170 
1171  instance->context = context;
1172  instance->totemudp_deliver_fn = deliver_fn;
1173 
1174  instance->totemudp_iface_change_fn = iface_change_fn;
1175 
1176  instance->totemudp_target_set_completed = target_set_completed;
1177 
1178  totemip_localhost (instance->mcast_address.family, &localhost);
1179  localhost.nodeid = instance->totem_config->node_id;
1180 
1181  /*
1182  * RRP layer isn't ready to receive message because it hasn't
1183  * initialized yet. Add short timer to check the interfaces.
1184  */
1185  qb_loop_timer_add (instance->totemudp_poll_handle,
1186  QB_LOOP_MED,
1187  100*QB_TIME_NS_IN_MSEC,
1188  (void *)instance,
1189  timer_function_netif_check_timeout,
1190  &instance->timer_netif_check_timeout);
1191 
1192  *udp_context = instance;
1193  return (0);
1194 }
1195 
1197 {
1198  return malloc (FRAME_SIZE_MAX);
1199 }
1200 
1201 void totemudp_buffer_release (void *ptr)
1202 {
1203  return free (ptr);
1204 }
1205 
1207  void *udp_context,
1208  int processor_count)
1209 {
1210  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1211  int res = 0;
1212 
1213  instance->my_memb_entries = processor_count;
1214  qb_loop_timer_del (instance->totemudp_poll_handle,
1215  instance->timer_netif_check_timeout);
1216  if (processor_count == 1) {
1217  qb_loop_timer_add (instance->totemudp_poll_handle,
1218  QB_LOOP_MED,
1219  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
1220  (void *)instance,
1221  timer_function_netif_check_timeout,
1222  &instance->timer_netif_check_timeout);
1223  }
1224 
1225  return (res);
1226 }
1227 
1228 int totemudp_recv_flush (void *udp_context)
1229 {
1230  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1231  struct pollfd ufd;
1232  int nfds;
1233  int res = 0;
1234  int i;
1235  int sock;
1236 
1237  instance->flushing = 1;
1238 
1239  for (i = 0; i < 2; i++) {
1240  sock = -1;
1241  if (i == 0) {
1242  sock = instance->totemudp_sockets.mcast_recv;
1243  }
1244  if (i == 1) {
1245  sock = instance->totemudp_sockets.local_mcast_loop[0];
1246  }
1247  assert(sock != -1);
1248 
1249  do {
1250  ufd.fd = sock;
1251  ufd.events = POLLIN;
1252  nfds = poll (&ufd, 1, 0);
1253  if (nfds == 1 && ufd.revents & POLLIN) {
1254  net_deliver_fn (sock, ufd.revents, instance);
1255  }
1256  } while (nfds == 1);
1257  }
1258 
1259  instance->flushing = 0;
1260 
1261  return (res);
1262 }
1263 
1264 int totemudp_send_flush (void *udp_context)
1265 {
1266  return 0;
1267 }
1268 
1270  void *udp_context,
1271  const void *msg,
1272  unsigned int msg_len)
1273 {
1274  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1275  int res = 0;
1276 
1277  ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1278 
1279  return (res);
1280 }
1282  void *udp_context,
1283  const void *msg,
1284  unsigned int msg_len)
1285 {
1286  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1287  int res = 0;
1288 
1289  mcast_sendmsg (instance, msg, msg_len);
1290 
1291  return (res);
1292 }
1293 
1295  void *udp_context,
1296  const void *msg,
1297  unsigned int msg_len)
1298 {
1299  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1300  int res = 0;
1301 
1302  mcast_sendmsg (instance, msg, msg_len);
1303 
1304  return (res);
1305 }
1306 
1307 extern int totemudp_iface_check (void *udp_context)
1308 {
1309  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1310  int res = 0;
1311 
1312  timer_function_netif_check_timeout (instance);
1313 
1314  return (res);
1315 }
1316 
1317 extern void totemudp_net_mtu_adjust (void *udp_context, struct totem_config *totem_config)
1318 {
1319 #define UDPIP_HEADER_SIZE (20 + 8) /* 20 bytes for ip 8 bytes for udp */
1320  totem_config->net_mtu -= crypto_sec_header_size(totem_config->crypto_cipher_type,
1321  totem_config->crypto_hash_type) +
1323 }
1324 
1325 const char *totemudp_iface_print (void *udp_context) {
1326  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1327  const char *ret_char;
1328 
1329  ret_char = totemip_print (&instance->my_id);
1330 
1331  return (ret_char);
1332 }
1333 
1335  void *udp_context,
1336  struct totem_ip_address *addr)
1337 {
1338  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1339  int res = 0;
1340 
1341  memcpy (addr, &instance->my_id, sizeof (struct totem_ip_address));
1342 
1343  return (res);
1344 }
1345 
1347  void *udp_context,
1348  const struct totem_ip_address *token_target)
1349 {
1350  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1351  int res = 0;
1352 
1353  memcpy (&instance->token_target, token_target,
1354  sizeof (struct totem_ip_address));
1355 
1356  instance->totemudp_target_set_completed (instance->context);
1357 
1358  return (res);
1359 }
1360 
1362  void *udp_context)
1363 {
1364  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1365  unsigned int res;
1366  struct sockaddr_storage system_from;
1367  struct msghdr msg_recv;
1368  struct pollfd ufd;
1369  int nfds;
1370  int msg_processed = 0;
1371  int i;
1372  int sock;
1373 
1374  /*
1375  * Receive datagram
1376  */
1377  msg_recv.msg_name = &system_from;
1378  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
1379  msg_recv.msg_iov = &instance->totemudp_iov_recv_flush;
1380  msg_recv.msg_iovlen = 1;
1381 #ifdef HAVE_MSGHDR_CONTROL
1382  msg_recv.msg_control = 0;
1383 #endif
1384 #ifdef HAVE_MSGHDR_CONTROLLEN
1385  msg_recv.msg_controllen = 0;
1386 #endif
1387 #ifdef HAVE_MSGHDR_FLAGS
1388  msg_recv.msg_flags = 0;
1389 #endif
1390 #ifdef HAVE_MSGHDR_ACCRIGHTS
1391  msg_recv.msg_accrights = NULL;
1392 #endif
1393 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1394  msg_recv.msg_accrightslen = 0;
1395 #endif
1396 
1397  for (i = 0; i < 2; i++) {
1398  sock = -1;
1399  if (i == 0) {
1400  sock = instance->totemudp_sockets.mcast_recv;
1401  }
1402  if (i == 1) {
1403  sock = instance->totemudp_sockets.local_mcast_loop[0];
1404  }
1405  assert(sock != -1);
1406 
1407  do {
1408  ufd.fd = sock;
1409  ufd.events = POLLIN;
1410  nfds = poll (&ufd, 1, 0);
1411  if (nfds == 1 && ufd.revents & POLLIN) {
1412  res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
1413  if (res != -1) {
1414  msg_processed = 1;
1415  } else {
1416  msg_processed = -1;
1417  }
1418  }
1419  } while (nfds == 1);
1420  }
1421 
1422  return (msg_processed);
1423 }
1424 
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:1206
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
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
struct timeval stats_tv_start
Definition: totemudp.c:178
void totemudp_net_mtu_adjust(void *udp_context, struct totem_config *totem_config)
Definition: totemudp.c:1317
void(* totemudp_target_set_completed)(void *context)
Definition: totemudp.c:128
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
void * totemudp_buffer_alloc(void)
Definition: totemudp.c:1196
int totemudp_mcast_flush_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1281
int totemudp_token_target_set(void *udp_context, const struct totem_ip_address *token_target)
Definition: totemudp.c:1346
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:773
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:1294
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:1264
void(* totemudp_iface_change_fn)(void *context, const struct totem_ip_address *iface_address)
Definition: totemudp.c:124
uint16_t ttl
Definition: totem.h:69
int totemudp_recv_flush(void *udp_context)
Definition: totemudp.c:1228
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:698
int totemudp_token_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1269
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:1101
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(* 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
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
#define UDPIP_HEADER_SIZE
typedef __attribute__
const char * totemudp_iface_print(void *udp_context)
Definition: totemudp.c:1325
#define NETIF_STATE_REPORT_UP
Definition: totemudp.c:84
uint16_t ip_port
Definition: totem.h:68
#define MCAST_SOCKET_BUFFER_SIZE
Definition: totemudp.c:83
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:720
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:1334
#define FRAME_SIZE_MAX
Definition: totem.h:50
void(*) void udp_context)
Definition: totemudp.c:152
#define LOGSYS_LEVEL_CRIT
Definition: logsys.h:69
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
void(* totemudp_deliver_fn)(void *context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:119
int totemudp_recv_mcast_empty(void *udp_context)
Definition: totemudp.c:1361
int totemudp_iface_check(void *udp_context)
Definition: totemudp.c:1307
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:1201
int totemudp_log_level_warning
Definition: totemudp.c:137