corosync  2.4.2-dirty
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  * Create local multicast loop socket
765  */
766  if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets->local_mcast_loop) == -1) {
767  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
768  "socket() failed");
769  return (-1);
770  }
771 
772  for (i = 0; i < 2; i++) {
773  totemip_nosigpipe (sockets->local_mcast_loop[i]);
774  res = fcntl (sockets->local_mcast_loop[i], F_SETFL, O_NONBLOCK);
775  if (res == -1) {
776  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
777  "Could not set non-blocking operation on multicast socket");
778  return (-1);
779  }
780  }
781 
782 
783 
784  /*
785  * Setup mcast send socket
786  */
787  sockets->mcast_send = socket (bindnet_address->family, SOCK_DGRAM, 0);
788  if (sockets->mcast_send == -1) {
789  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
790  "socket() failed");
791  return (-1);
792  }
793 
794  totemip_nosigpipe (sockets->mcast_send);
795  res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK);
796  if (res == -1) {
797  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
798  "Could not set non-blocking operation on multicast socket");
799  return (-1);
800  }
801 
802  /*
803  * Force reuse
804  */
805  flag = 1;
806  if ( setsockopt(sockets->mcast_send, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
807  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
808  "setsockopt(SO_REUSEADDR) failed");
809  return (-1);
810  }
811 
813  &sockaddr, &addrlen);
814  res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen);
815  if (res == -1) {
816  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
817  "Unable to bind the socket to send multicast packets");
818  return (-1);
819  }
820 
821  /*
822  * Setup unicast socket
823  */
824  sockets->token = socket (bindnet_address->family, SOCK_DGRAM, 0);
825  if (sockets->token == -1) {
826  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
827  "socket() failed");
828  return (-1);
829  }
830 
831  totemip_nosigpipe (sockets->token);
832  res = fcntl (sockets->token, F_SETFL, O_NONBLOCK);
833  if (res == -1) {
834  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
835  "Could not set non-blocking operation on token socket");
836  return (-1);
837  }
838 
839  /*
840  * Force reuse
841  */
842  flag = 1;
843  if ( setsockopt(sockets->token, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
844  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
845  "setsockopt(SO_REUSEADDR) failed");
846  return (-1);
847  }
848 
849  /*
850  * Bind to unicast socket used for token send/receives
851  * This has the side effect of binding to the correct interface
852  */
853  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
854  res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen);
855  if (res == -1) {
856  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
857  "Unable to bind UDP unicast socket");
858  return (-1);
859  }
860 
861  recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
862  sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
863  /*
864  * Set buffer sizes to avoid overruns
865  */
866  res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
867  if (res == -1) {
868  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
869  "Unable to set SO_RCVBUF size on UDP mcast socket");
870  return (-1);
871  }
872  res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
873  if (res == -1) {
874  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
875  "Unable to set SO_SNDBUF size on UDP mcast socket");
876  return (-1);
877  }
878  res = setsockopt (sockets->local_mcast_loop[0], 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 local mcast loop socket");
882  return (-1);
883  }
884  res = setsockopt (sockets->local_mcast_loop[1], 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 local mcast loop socket");
888  return (-1);
889  }
890 
891  res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
892  if (res == 0) {
894  "Receive multicast socket recv buffer size (%d bytes).", recvbuf_size);
895  }
896 
897  res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
898  if (res == 0) {
900  "Transmit multicast socket send buffer size (%d bytes).", sendbuf_size);
901  }
902 
903  res = getsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
904  if (res == 0) {
906  "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
907  }
908 
909  res = getsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
910  if (res == 0) {
912  "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
913  }
914 
915 
916  /*
917  * Join group membership on socket
918  */
919  totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_interface->ip_port, &mcast_ss, &addrlen);
920  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &boundto_ss, &addrlen);
921 
922  if (instance->totem_config->broadcast_use == 1) {
923  unsigned int broadcast = 1;
924 
925  if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
926  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
927  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
928  "setting broadcast option failed");
929  return (-1);
930  }
931  if ((setsockopt(sockets->mcast_send, SOL_SOCKET,
932  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
933  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
934  "setting broadcast option failed");
935  return (-1);
936  }
937  } else {
938  switch (bindnet_address->family) {
939  case AF_INET:
940  memset(&mreq, 0, sizeof(mreq));
941  mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
942  mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
943  res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
944  &mreq, sizeof (mreq));
945  if (res == -1) {
946  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
947  "join ipv4 multicast group failed");
948  return (-1);
949  }
950  break;
951  case AF_INET6:
952  memset(&mreq6, 0, sizeof(mreq6));
953  memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
954  mreq6.ipv6mr_interface = interface_num;
955 
956  res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
957  &mreq6, sizeof (mreq6));
958  if (res == -1) {
959  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
960  "join ipv6 multicast group failed");
961  return (-1);
962  }
963  break;
964  }
965  }
966 
967  /*
968  * Turn off multicast loopback
969  */
970 
971  flag = 0;
972  switch ( bindnet_address->family ) {
973  case AF_INET:
974  sflag = 0;
975  res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP,
976  &sflag, sizeof (sflag));
977  break;
978  case AF_INET6:
979  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
980  &flag, sizeof (flag));
981  }
982  if (res == -1) {
983  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
984  "Unable to turn off multicast loopback");
985  return (-1);
986  }
987 
988  /*
989  * Set multicast packets TTL
990  */
991  flag = instance->totem_interface->ttl;
992  if (bindnet_address->family == AF_INET6) {
993  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
994  &flag, sizeof (flag));
995  if (res == -1) {
996  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
997  "set mcast v6 TTL failed");
998  return (-1);
999  }
1000  } else {
1001  sflag = flag;
1002  res = setsockopt(sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_TTL,
1003  &sflag, sizeof(sflag));
1004  if (res == -1) {
1005  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1006  "set mcast v4 TTL failed");
1007  return (-1);
1008  }
1009  }
1010 
1011  /*
1012  * Bind to a specific interface for multicast send and receive
1013  */
1014  switch ( bindnet_address->family ) {
1015  case AF_INET:
1016  if (setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_IF,
1017  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1018  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1019  "cannot select interface for multicast packets (send)");
1020  return (-1);
1021  }
1022  if (setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_IF,
1023  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1024  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1025  "cannot select interface for multicast packets (recv)");
1026  return (-1);
1027  }
1028  break;
1029  case AF_INET6:
1030  if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1031  &interface_num, sizeof (interface_num)) < 0) {
1032  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1033  "cannot select interface for multicast packets (send v6)");
1034  return (-1);
1035  }
1036  if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1037  &interface_num, sizeof (interface_num)) < 0) {
1038  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1039  "cannot select interface for multicast packets (recv v6)");
1040  return (-1);
1041  }
1042  break;
1043  }
1044 
1045  /*
1046  * Bind to multicast socket used for multicast receives
1047  * This needs to happen after all of the multicast setsockopt() calls
1048  * as the kernel seems to only put them into effect (for IPV6) when bind()
1049  * is called.
1050  */
1052  instance->totem_interface->ip_port, &sockaddr, &addrlen);
1053  res = bind (sockets->mcast_recv, (struct sockaddr *)&sockaddr, addrlen);
1054  if (res == -1) {
1055  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1056  "Unable to bind the socket to receive multicast packets");
1057  return (-1);
1058  }
1059  return 0;
1060 }
1061 
1062 static int totemudp_build_sockets (
1063  struct totemudp_instance *instance,
1064  struct totem_ip_address *mcast_address,
1065  struct totem_ip_address *bindnet_address,
1066  struct totemudp_socket *sockets,
1067  struct totem_ip_address *bound_to)
1068 {
1069  int interface_num;
1070  int interface_up;
1071  int res;
1072 
1073  /*
1074  * Determine the ip address bound to and the interface name
1075  */
1076  res = netif_determine (instance,
1077  bindnet_address,
1078  bound_to,
1079  &interface_up,
1080  &interface_num);
1081 
1082  if (res == -1) {
1083  return (-1);
1084  }
1085 
1086  totemip_copy(&instance->my_id, bound_to);
1087 
1088  res = totemudp_build_sockets_ip (instance, mcast_address,
1089  bindnet_address, sockets, bound_to, interface_num);
1090 
1091  /* We only send out of the token socket */
1092  totemudp_traffic_control_set(instance, sockets->token);
1093  return res;
1094 }
1095 
1096 /*
1097  * Totem Network interface - also does encryption/decryption
1098  * depends on poll abstraction, POSIX, IPV4
1099  */
1100 
1101 /*
1102  * Create an instance
1103  */
1105  qb_loop_t *poll_handle,
1106  void **udp_context,
1107  struct totem_config *totem_config,
1108  totemsrp_stats_t *stats,
1109  int interface_no,
1110  void *context,
1111 
1112  void (*deliver_fn) (
1113  void *context,
1114  const void *msg,
1115  unsigned int msg_len),
1116 
1117  void (*iface_change_fn) (
1118  void *context,
1119  const struct totem_ip_address *iface_address),
1120 
1121  void (*target_set_completed) (
1122  void *context))
1123 {
1124  struct totemudp_instance *instance;
1125 
1126  instance = malloc (sizeof (struct totemudp_instance));
1127  if (instance == NULL) {
1128  return (-1);
1129  }
1130 
1131  totemudp_instance_initialize (instance);
1132 
1133  instance->totem_config = totem_config;
1134  instance->stats = stats;
1135 
1136  /*
1137  * Configure logging
1138  */
1139  instance->totemudp_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1146 
1147  /*
1148  * Initialize random number generator for later use to generate salt
1149  */
1150  instance->crypto_inst = crypto_init (totem_config->private_key,
1151  totem_config->private_key_len,
1152  totem_config->crypto_cipher_type,
1153  totem_config->crypto_hash_type,
1154  instance->totemudp_log_printf,
1155  instance->totemudp_log_level_security,
1156  instance->totemudp_log_level_notice,
1157  instance->totemudp_log_level_error,
1158  instance->totemudp_subsys_id);
1159  if (instance->crypto_inst == NULL) {
1160  free(instance);
1161  return (-1);
1162  }
1163  /*
1164  * Initialize local variables for totemudp
1165  */
1166  instance->totem_interface = &totem_config->interfaces[interface_no];
1167  totemip_copy (&instance->mcast_address, &instance->totem_interface->mcast_addr);
1168  memset (instance->iov_buffer, 0, FRAME_SIZE_MAX);
1169 
1170  instance->totemudp_poll_handle = poll_handle;
1171 
1172  instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
1173 
1174  instance->context = context;
1175  instance->totemudp_deliver_fn = deliver_fn;
1176 
1177  instance->totemudp_iface_change_fn = iface_change_fn;
1178 
1179  instance->totemudp_target_set_completed = target_set_completed;
1180 
1181  totemip_localhost (instance->mcast_address.family, &localhost);
1182  localhost.nodeid = instance->totem_config->node_id;
1183 
1184  /*
1185  * RRP layer isn't ready to receive message because it hasn't
1186  * initialized yet. Add short timer to check the interfaces.
1187  */
1188  qb_loop_timer_add (instance->totemudp_poll_handle,
1189  QB_LOOP_MED,
1190  100*QB_TIME_NS_IN_MSEC,
1191  (void *)instance,
1192  timer_function_netif_check_timeout,
1193  &instance->timer_netif_check_timeout);
1194 
1195  *udp_context = instance;
1196  return (0);
1197 }
1198 
1200 {
1201  return malloc (FRAME_SIZE_MAX);
1202 }
1203 
1204 void totemudp_buffer_release (void *ptr)
1205 {
1206  return free (ptr);
1207 }
1208 
1210  void *udp_context,
1211  int processor_count)
1212 {
1213  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1214  int res = 0;
1215 
1216  instance->my_memb_entries = processor_count;
1217  qb_loop_timer_del (instance->totemudp_poll_handle,
1218  instance->timer_netif_check_timeout);
1219  if (processor_count == 1) {
1220  qb_loop_timer_add (instance->totemudp_poll_handle,
1221  QB_LOOP_MED,
1222  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
1223  (void *)instance,
1224  timer_function_netif_check_timeout,
1225  &instance->timer_netif_check_timeout);
1226  }
1227 
1228  return (res);
1229 }
1230 
1231 int totemudp_recv_flush (void *udp_context)
1232 {
1233  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1234  struct pollfd ufd;
1235  int nfds;
1236  int res = 0;
1237  int i;
1238  int sock;
1239 
1240  instance->flushing = 1;
1241 
1242  for (i = 0; i < 2; i++) {
1243  sock = -1;
1244  if (i == 0) {
1245  sock = instance->totemudp_sockets.mcast_recv;
1246  }
1247  if (i == 1) {
1248  sock = instance->totemudp_sockets.local_mcast_loop[0];
1249  }
1250  assert(sock != -1);
1251 
1252  do {
1253  ufd.fd = sock;
1254  ufd.events = POLLIN;
1255  nfds = poll (&ufd, 1, 0);
1256  if (nfds == 1 && ufd.revents & POLLIN) {
1257  net_deliver_fn (sock, ufd.revents, instance);
1258  }
1259  } while (nfds == 1);
1260  }
1261 
1262  instance->flushing = 0;
1263 
1264  return (res);
1265 }
1266 
1267 int totemudp_send_flush (void *udp_context)
1268 {
1269  return 0;
1270 }
1271 
1273  void *udp_context,
1274  const void *msg,
1275  unsigned int msg_len)
1276 {
1277  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1278  int res = 0;
1279 
1280  ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1281 
1282  return (res);
1283 }
1285  void *udp_context,
1286  const void *msg,
1287  unsigned int msg_len)
1288 {
1289  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1290  int res = 0;
1291 
1292  mcast_sendmsg (instance, msg, msg_len);
1293 
1294  return (res);
1295 }
1296 
1298  void *udp_context,
1299  const void *msg,
1300  unsigned int msg_len)
1301 {
1302  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1303  int res = 0;
1304 
1305  mcast_sendmsg (instance, msg, msg_len);
1306 
1307  return (res);
1308 }
1309 
1310 extern int totemudp_iface_check (void *udp_context)
1311 {
1312  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1313  int res = 0;
1314 
1315  timer_function_netif_check_timeout (instance);
1316 
1317  return (res);
1318 }
1319 
1320 extern void totemudp_net_mtu_adjust (void *udp_context, struct totem_config *totem_config)
1321 {
1322 
1323  assert(totem_config->interface_count > 0);
1324 
1325  totem_config->net_mtu -= crypto_sec_header_size(totem_config->crypto_cipher_type,
1326  totem_config->crypto_hash_type) +
1328 }
1329 
1330 const char *totemudp_iface_print (void *udp_context) {
1331  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1332  const char *ret_char;
1333 
1334  ret_char = totemip_print (&instance->my_id);
1335 
1336  return (ret_char);
1337 }
1338 
1340  void *udp_context,
1341  struct totem_ip_address *addr)
1342 {
1343  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1344  int res = 0;
1345 
1346  memcpy (addr, &instance->my_id, sizeof (struct totem_ip_address));
1347 
1348  return (res);
1349 }
1350 
1352  void *udp_context,
1353  const struct totem_ip_address *token_target)
1354 {
1355  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1356  int res = 0;
1357 
1358  memcpy (&instance->token_target, token_target,
1359  sizeof (struct totem_ip_address));
1360 
1361  instance->totemudp_target_set_completed (instance->context);
1362 
1363  return (res);
1364 }
1365 
1367  void *udp_context)
1368 {
1369  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1370  unsigned int res;
1371  struct sockaddr_storage system_from;
1372  struct msghdr msg_recv;
1373  struct pollfd ufd;
1374  int nfds;
1375  int msg_processed = 0;
1376  int i;
1377  int sock;
1378 
1379  /*
1380  * Receive datagram
1381  */
1382  msg_recv.msg_name = &system_from;
1383  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
1384  msg_recv.msg_iov = &instance->totemudp_iov_recv_flush;
1385  msg_recv.msg_iovlen = 1;
1386 #ifdef HAVE_MSGHDR_CONTROL
1387  msg_recv.msg_control = 0;
1388 #endif
1389 #ifdef HAVE_MSGHDR_CONTROLLEN
1390  msg_recv.msg_controllen = 0;
1391 #endif
1392 #ifdef HAVE_MSGHDR_FLAGS
1393  msg_recv.msg_flags = 0;
1394 #endif
1395 #ifdef HAVE_MSGHDR_ACCRIGHTS
1396  msg_recv.msg_accrights = NULL;
1397 #endif
1398 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1399  msg_recv.msg_accrightslen = 0;
1400 #endif
1401 
1402  for (i = 0; i < 2; i++) {
1403  sock = -1;
1404  if (i == 0) {
1405  sock = instance->totemudp_sockets.mcast_recv;
1406  }
1407  if (i == 1) {
1408  sock = instance->totemudp_sockets.local_mcast_loop[0];
1409  }
1410  assert(sock != -1);
1411 
1412  do {
1413  ufd.fd = sock;
1414  ufd.events = POLLIN;
1415  nfds = poll (&ufd, 1, 0);
1416  if (nfds == 1 && ufd.revents & POLLIN) {
1417  res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
1418  if (res != -1) {
1419  msg_processed = 1;
1420  } else {
1421  msg_processed = -1;
1422  }
1423  }
1424  } while (nfds == 1);
1425  }
1426 
1427  return (msg_processed);
1428 }
1429 
unsigned int clear_node_high_bit
Definition: totem.h:117
unsigned short family
Definition: coroapi.h:113
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:1209
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
The totem_ip_address struct.
Definition: coroapi.h:111
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:1320
void * totemudp_buffer_alloc(void)
Definition: totemudp.c:1199
int totemudp_mcast_flush_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1284
int totemudp_token_target_set(void *udp_context, const struct totem_ip_address *token_target)
Definition: totemudp.c:1351
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:77
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:1297
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:1267
uint16_t ttl
Definition: totem.h:69
int totemudp_recv_flush(void *udp_context)
Definition: totemudp.c:1231
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:1272
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:1104
unsigned int nodeid
Definition: coroapi.h:112
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:1330
#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:1339
#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:1366
int totemudp_iface_check(void *udp_context)
Definition: totemudp.c:1310
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:1204
int totemudp_log_level_warning
Definition: totemudp.c:137