corosync  2.4.2
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  if (msg_len + crypto_get_current_sec_header_size(instance->crypto_inst) > sizeof(buf_out)) {
274  log_printf(LOGSYS_LEVEL_CRIT, "UDP message for ucast is too big. Ignoring message");
275 
276  return ;
277  }
278 
279  /*
280  * Encrypt and digest the message
281  */
283  instance->crypto_inst,
284  (const unsigned char *)msg,
285  msg_len,
286  buf_out,
287  &buf_out_len) != 0) {
288  log_printf(LOGSYS_LEVEL_CRIT, "Error encrypting/signing packet (non-critical)");
289  return;
290  }
291 
292  iovec.iov_base = (void *)buf_out;
293  iovec.iov_len = buf_out_len;
294 
295  /*
296  * Build unicast message
297  */
298  memset(&msg_ucast, 0, sizeof(msg_ucast));
300  instance->totem_interface->ip_port, &sockaddr, &addrlen);
301  msg_ucast.msg_name = &sockaddr;
302  msg_ucast.msg_namelen = addrlen;
303  msg_ucast.msg_iov = (void *)&iovec;
304  msg_ucast.msg_iovlen = 1;
305 #ifdef HAVE_MSGHDR_CONTROL
306  msg_ucast.msg_control = 0;
307 #endif
308 #ifdef HAVE_MSGHDR_CONTROLLEN
309  msg_ucast.msg_controllen = 0;
310 #endif
311 #ifdef HAVE_MSGHDR_FLAGS
312  msg_ucast.msg_flags = 0;
313 #endif
314 #ifdef HAVE_MSGHDR_ACCRIGHTS
315  msg_ucast.msg_accrights = NULL;
316 #endif
317 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
318  msg_ucast.msg_accrightslen = 0;
319 #endif
320 
321 
322  /*
323  * Transmit unicast message
324  * An error here is recovered by totemsrp
325  */
326  res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_ucast,
327  MSG_NOSIGNAL);
328  if (res < 0) {
329  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
330  "sendmsg(ucast) failed (non-critical)");
331  }
332 }
333 
334 static inline void mcast_sendmsg (
335  struct totemudp_instance *instance,
336  const void *msg,
337  unsigned int msg_len)
338 {
339  struct msghdr msg_mcast;
340  int res = 0;
341  size_t buf_out_len;
342  unsigned char buf_out[FRAME_SIZE_MAX];
343  struct iovec iovec;
344  struct sockaddr_storage sockaddr;
345  int addrlen;
346 
347  if (msg_len + crypto_get_current_sec_header_size(instance->crypto_inst) > sizeof(buf_out)) {
348  log_printf(LOGSYS_LEVEL_CRIT, "UDP message for mcast is too big. Ignoring message");
349 
350  return ;
351  }
352 
353  /*
354  * Encrypt and digest the message
355  */
357  instance->crypto_inst,
358  (const unsigned char *)msg,
359  msg_len,
360  buf_out,
361  &buf_out_len) != 0) {
362  log_printf(LOGSYS_LEVEL_CRIT, "Error encrypting/signing packet (non-critical)");
363  return;
364  }
365 
366  iovec.iov_base = (void *)&buf_out;
367  iovec.iov_len = buf_out_len;
368 
369  /*
370  * Build multicast message
371  */
373  instance->totem_interface->ip_port, &sockaddr, &addrlen);
374  memset(&msg_mcast, 0, sizeof(msg_mcast));
375  msg_mcast.msg_name = &sockaddr;
376  msg_mcast.msg_namelen = addrlen;
377  msg_mcast.msg_iov = (void *)&iovec;
378  msg_mcast.msg_iovlen = 1;
379 #ifdef HAVE_MSGHDR_CONTROL
380  msg_mcast.msg_control = 0;
381 #endif
382 #ifdef HAVE_MSGHDR_CONTROLLEN
383  msg_mcast.msg_controllen = 0;
384 #endif
385 #ifdef HAVE_MSGHDR_FLAGS
386  msg_mcast.msg_flags = 0;
387 #endif
388 #ifdef HAVE_MSGHDR_ACCRIGHTS
389  msg_mcast.msg_accrights = NULL;
390 #endif
391 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
392  msg_mcast.msg_accrightslen = 0;
393 #endif
394 
395  /*
396  * Transmit multicast message
397  * An error here is recovered by totemsrp
398  */
399  res = sendmsg (instance->totemudp_sockets.mcast_send, &msg_mcast,
400  MSG_NOSIGNAL);
401  if (res < 0) {
402  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
403  "sendmsg(mcast) failed (non-critical)");
404  instance->stats->continuous_sendmsg_failures++;
405  } else {
406  instance->stats->continuous_sendmsg_failures = 0;
407  }
408 
409  /*
410  * Transmit multicast message to local unix mcast loop
411  * An error here is recovered by totemsrp
412  */
413  msg_mcast.msg_name = NULL;
414  msg_mcast.msg_namelen = 0;
415 
416  res = sendmsg (instance->totemudp_sockets.local_mcast_loop[1], &msg_mcast,
417  MSG_NOSIGNAL);
418  if (res < 0) {
419  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
420  "sendmsg(local mcast loop) failed (non-critical)");
421  }
422 }
423 
424 
426  void *udp_context)
427 {
428  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
429  int res = 0;
430 
431  if (instance->totemudp_sockets.mcast_recv > 0) {
432  qb_loop_poll_del (instance->totemudp_poll_handle,
433  instance->totemudp_sockets.mcast_recv);
434  close (instance->totemudp_sockets.mcast_recv);
435  }
436  if (instance->totemudp_sockets.mcast_send > 0) {
437  close (instance->totemudp_sockets.mcast_send);
438  }
439  if (instance->totemudp_sockets.local_mcast_loop[0] > 0) {
440  qb_loop_poll_del (instance->totemudp_poll_handle,
441  instance->totemudp_sockets.local_mcast_loop[0]);
442  close (instance->totemudp_sockets.local_mcast_loop[0]);
443  close (instance->totemudp_sockets.local_mcast_loop[1]);
444  }
445  if (instance->totemudp_sockets.token > 0) {
446  qb_loop_poll_del (instance->totemudp_poll_handle,
447  instance->totemudp_sockets.token);
448  close (instance->totemudp_sockets.token);
449  }
450 
451  return (res);
452 }
453 
454 /*
455  * Only designed to work with a message with one iov
456  */
457 
458 static int net_deliver_fn (
459  int fd,
460  int revents,
461  void *data)
462 {
463  struct totemudp_instance *instance = (struct totemudp_instance *)data;
464  struct msghdr msg_recv;
465  struct iovec *iovec;
466  struct sockaddr_storage system_from;
467  int bytes_received;
468  int res = 0;
469  char *message_type;
470 
471  if (instance->flushing == 1) {
472  iovec = &instance->totemudp_iov_recv_flush;
473  } else {
474  iovec = &instance->totemudp_iov_recv;
475  }
476 
477  /*
478  * Receive datagram
479  */
480  msg_recv.msg_name = &system_from;
481  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
482  msg_recv.msg_iov = iovec;
483  msg_recv.msg_iovlen = 1;
484 #ifdef HAVE_MSGHDR_CONTROL
485  msg_recv.msg_control = 0;
486 #endif
487 #ifdef HAVE_MSGHDR_CONTROLLEN
488  msg_recv.msg_controllen = 0;
489 #endif
490 #ifdef HAVE_MSGHDR_FLAGS
491  msg_recv.msg_flags = 0;
492 #endif
493 #ifdef HAVE_MSGHDR_ACCRIGHTS
494  msg_recv.msg_accrights = NULL;
495 #endif
496 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
497  msg_recv.msg_accrightslen = 0;
498 #endif
499 
500  bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
501  if (bytes_received == -1) {
502  return (0);
503  } else {
504  instance->stats_recv += bytes_received;
505  }
506 
507  /*
508  * Authenticate and if authenticated, decrypt datagram
509  */
510  res = crypto_authenticate_and_decrypt (instance->crypto_inst, iovec->iov_base, &bytes_received);
511  if (res == -1) {
512  log_printf (instance->totemudp_log_level_security, "Received message has invalid digest... ignoring.");
514  "Invalid packet data");
515  iovec->iov_len = FRAME_SIZE_MAX;
516  return 0;
517  }
518  iovec->iov_len = bytes_received;
519 
520  /*
521  * Drop all non-mcast messages (more specifically join
522  * messages should be dropped)
523  */
524  message_type = (char *)iovec->iov_base;
525  if (instance->flushing == 1 && *message_type == MESSAGE_TYPE_MEMB_JOIN) {
526  log_printf(instance->totemudp_log_level_warning, "JOIN or LEAVE message was thrown away during flush operation.");
527  iovec->iov_len = FRAME_SIZE_MAX;
528  return (0);
529  }
530 
531  /*
532  * Handle incoming message
533  */
534  instance->totemudp_deliver_fn (
535  instance->context,
536  iovec->iov_base,
537  iovec->iov_len);
538 
539  iovec->iov_len = FRAME_SIZE_MAX;
540  return (0);
541 }
542 
543 static int netif_determine (
544  struct totemudp_instance *instance,
545  struct totem_ip_address *bindnet,
546  struct totem_ip_address *bound_to,
547  int *interface_up,
548  int *interface_num)
549 {
550  int res;
551 
552  res = totemip_iface_check (bindnet, bound_to,
553  interface_up, interface_num,
554  instance->totem_config->clear_node_high_bit);
555 
556 
557  return (res);
558 }
559 
560 
561 /*
562  * If the interface is up, the sockets for totem are built. If the interface is down
563  * this function is requeued in the timer list to retry building the sockets later.
564  */
565 static void timer_function_netif_check_timeout (
566  void *data)
567 {
568  struct totemudp_instance *instance = (struct totemudp_instance *)data;
569  int interface_up;
570  int interface_num;
571  struct totem_ip_address *bind_address;
572 
573  /*
574  * Build sockets for every interface
575  */
576  netif_determine (instance,
577  &instance->totem_interface->bindnet,
578  &instance->totem_interface->boundto,
579  &interface_up, &interface_num);
580  /*
581  * If the network interface isn't back up and we are already
582  * in loopback mode, add timer to check again and return
583  */
584  if ((instance->netif_bind_state == BIND_STATE_LOOPBACK &&
585  interface_up == 0) ||
586 
587  (instance->my_memb_entries == 1 &&
588  instance->netif_bind_state == BIND_STATE_REGULAR &&
589  interface_up == 1)) {
590 
591  qb_loop_timer_add (instance->totemudp_poll_handle,
592  QB_LOOP_MED,
593  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
594  (void *)instance,
595  timer_function_netif_check_timeout,
596  &instance->timer_netif_check_timeout);
597 
598  /*
599  * Add a timer to check for a downed regular interface
600  */
601  return;
602  }
603 
604  if (instance->totemudp_sockets.mcast_recv > 0) {
605  qb_loop_poll_del (instance->totemudp_poll_handle,
606  instance->totemudp_sockets.mcast_recv);
607  close (instance->totemudp_sockets.mcast_recv);
608  }
609  if (instance->totemudp_sockets.mcast_send > 0) {
610  close (instance->totemudp_sockets.mcast_send);
611  }
612  if (instance->totemudp_sockets.local_mcast_loop[0] > 0) {
613  qb_loop_poll_del (instance->totemudp_poll_handle,
614  instance->totemudp_sockets.local_mcast_loop[0]);
615  close (instance->totemudp_sockets.local_mcast_loop[0]);
616  close (instance->totemudp_sockets.local_mcast_loop[1]);
617  }
618  if (instance->totemudp_sockets.token > 0) {
619  qb_loop_poll_del (instance->totemudp_poll_handle,
620  instance->totemudp_sockets.token);
621  close (instance->totemudp_sockets.token);
622  }
623 
624  if (interface_up == 0) {
625  /*
626  * Interface is not up
627  */
629  bind_address = &localhost;
630 
631  /*
632  * Add a timer to retry building interfaces and request memb_gather_enter
633  */
634  qb_loop_timer_add (instance->totemudp_poll_handle,
635  QB_LOOP_MED,
636  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
637  (void *)instance,
638  timer_function_netif_check_timeout,
639  &instance->timer_netif_check_timeout);
640  } else {
641  /*
642  * Interface is up
643  */
645  bind_address = &instance->totem_interface->bindnet;
646  }
647  /*
648  * Create and bind the multicast and unicast sockets
649  */
650  (void)totemudp_build_sockets (instance,
651  &instance->mcast_address,
652  bind_address,
653  &instance->totemudp_sockets,
654  &instance->totem_interface->boundto);
655 
656  qb_loop_poll_add (
657  instance->totemudp_poll_handle,
658  QB_LOOP_MED,
659  instance->totemudp_sockets.mcast_recv,
660  POLLIN, instance, net_deliver_fn);
661 
662  qb_loop_poll_add (
663  instance->totemudp_poll_handle,
664  QB_LOOP_MED,
665  instance->totemudp_sockets.local_mcast_loop[0],
666  POLLIN, instance, net_deliver_fn);
667 
668  qb_loop_poll_add (
669  instance->totemudp_poll_handle,
670  QB_LOOP_MED,
671  instance->totemudp_sockets.token,
672  POLLIN, instance, net_deliver_fn);
673 
674  totemip_copy (&instance->my_id, &instance->totem_interface->boundto);
675 
676  /*
677  * This reports changes in the interface to the user and totemsrp
678  */
679  if (instance->netif_bind_state == BIND_STATE_REGULAR) {
680  if (instance->netif_state_report & NETIF_STATE_REPORT_UP) {
682  "The network interface [%s] is now up.",
683  totemip_print (&instance->totem_interface->boundto));
685  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
686  }
687  /*
688  * Add a timer to check for interface going down in single membership
689  */
690  if (instance->my_memb_entries == 1) {
691  qb_loop_timer_add (instance->totemudp_poll_handle,
692  QB_LOOP_MED,
693  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
694  (void *)instance,
695  timer_function_netif_check_timeout,
696  &instance->timer_netif_check_timeout);
697  }
698 
699  } else {
702  "The network interface is down.");
703  instance->totemudp_iface_change_fn (instance->context, &instance->my_id);
704  }
706 
707  }
708 }
709 
710 /* Set the socket priority to INTERACTIVE to ensure
711  that our messages don't get queued behind anything else */
712 static void totemudp_traffic_control_set(struct totemudp_instance *instance, int sock)
713 {
714 #ifdef SO_PRIORITY
715  int prio = 6; /* TC_PRIO_INTERACTIVE */
716 
717  if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) {
718  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning, "Could not set traffic priority");
719  }
720 #endif
721 }
722 
723 static int totemudp_build_sockets_ip (
724  struct totemudp_instance *instance,
725  struct totem_ip_address *mcast_address,
726  struct totem_ip_address *bindnet_address,
727  struct totemudp_socket *sockets,
728  struct totem_ip_address *bound_to,
729  int interface_num)
730 {
731  struct sockaddr_storage sockaddr;
732  struct ipv6_mreq mreq6;
733  struct ip_mreq mreq;
734  struct sockaddr_storage mcast_ss, boundto_ss;
735  struct sockaddr_in6 *mcast_sin6 = (struct sockaddr_in6 *)&mcast_ss;
736  struct sockaddr_in *mcast_sin = (struct sockaddr_in *)&mcast_ss;
737  struct sockaddr_in *boundto_sin = (struct sockaddr_in *)&boundto_ss;
738  unsigned int sendbuf_size;
739  unsigned int recvbuf_size;
740  unsigned int optlen = sizeof (sendbuf_size);
741  int addrlen;
742  int res;
743  int flag;
744  uint8_t sflag;
745  int i;
746 
747  /*
748  * Create multicast recv socket
749  */
750  sockets->mcast_recv = socket (bindnet_address->family, SOCK_DGRAM, 0);
751  if (sockets->mcast_recv == -1) {
752  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
753  "socket() failed");
754  return (-1);
755  }
756 
757  totemip_nosigpipe (sockets->mcast_recv);
758  res = fcntl (sockets->mcast_recv, F_SETFL, O_NONBLOCK);
759  if (res == -1) {
760  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
761  "Could not set non-blocking operation on multicast socket");
762  return (-1);
763  }
764 
765  /*
766  * Force reuse
767  */
768  flag = 1;
769  if ( setsockopt(sockets->mcast_recv, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
770  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
771  "setsockopt(SO_REUSEADDR) failed");
772  return (-1);
773  }
774 
775  /*
776  * Create local multicast loop socket
777  */
778  if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets->local_mcast_loop) == -1) {
779  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
780  "socket() failed");
781  return (-1);
782  }
783 
784  for (i = 0; i < 2; i++) {
785  totemip_nosigpipe (sockets->local_mcast_loop[i]);
786  res = fcntl (sockets->local_mcast_loop[i], F_SETFL, O_NONBLOCK);
787  if (res == -1) {
788  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
789  "Could not set non-blocking operation on multicast socket");
790  return (-1);
791  }
792  }
793 
794 
795 
796  /*
797  * Setup mcast send socket
798  */
799  sockets->mcast_send = socket (bindnet_address->family, SOCK_DGRAM, 0);
800  if (sockets->mcast_send == -1) {
801  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
802  "socket() failed");
803  return (-1);
804  }
805 
806  totemip_nosigpipe (sockets->mcast_send);
807  res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK);
808  if (res == -1) {
809  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
810  "Could not set non-blocking operation on multicast socket");
811  return (-1);
812  }
813 
814  /*
815  * Force reuse
816  */
817  flag = 1;
818  if ( setsockopt(sockets->mcast_send, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
819  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
820  "setsockopt(SO_REUSEADDR) failed");
821  return (-1);
822  }
823 
825  &sockaddr, &addrlen);
826  res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen);
827  if (res == -1) {
828  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
829  "Unable to bind the socket to send multicast packets");
830  return (-1);
831  }
832 
833  /*
834  * Setup unicast socket
835  */
836  sockets->token = socket (bindnet_address->family, SOCK_DGRAM, 0);
837  if (sockets->token == -1) {
838  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
839  "socket() failed");
840  return (-1);
841  }
842 
843  totemip_nosigpipe (sockets->token);
844  res = fcntl (sockets->token, F_SETFL, O_NONBLOCK);
845  if (res == -1) {
846  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
847  "Could not set non-blocking operation on token socket");
848  return (-1);
849  }
850 
851  /*
852  * Force reuse
853  */
854  flag = 1;
855  if ( setsockopt(sockets->token, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) {
856  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
857  "setsockopt(SO_REUSEADDR) failed");
858  return (-1);
859  }
860 
861  /*
862  * Bind to unicast socket used for token send/receives
863  * This has the side effect of binding to the correct interface
864  */
865  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
866  res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen);
867  if (res == -1) {
868  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
869  "Unable to bind UDP unicast socket");
870  return (-1);
871  }
872 
873  recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
874  sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
875  /*
876  * Set buffer sizes to avoid overruns
877  */
878  res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
879  if (res == -1) {
880  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
881  "Unable to set SO_RCVBUF size on UDP mcast socket");
882  return (-1);
883  }
884  res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
885  if (res == -1) {
886  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
887  "Unable to set SO_SNDBUF size on UDP mcast socket");
888  return (-1);
889  }
890  res = setsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
891  if (res == -1) {
892  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
893  "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
894  return (-1);
895  }
896  res = setsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
897  if (res == -1) {
898  LOGSYS_PERROR (errno, instance->totemudp_log_level_debug,
899  "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
900  return (-1);
901  }
902 
903  res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
904  if (res == 0) {
906  "Receive multicast socket recv buffer size (%d bytes).", recvbuf_size);
907  }
908 
909  res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
910  if (res == 0) {
912  "Transmit multicast socket send buffer size (%d bytes).", sendbuf_size);
913  }
914 
915  res = getsockopt (sockets->local_mcast_loop[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
916  if (res == 0) {
918  "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
919  }
920 
921  res = getsockopt (sockets->local_mcast_loop[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
922  if (res == 0) {
924  "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
925  }
926 
927 
928  /*
929  * Join group membership on socket
930  */
931  totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_interface->ip_port, &mcast_ss, &addrlen);
932  totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &boundto_ss, &addrlen);
933 
934  if (instance->totem_config->broadcast_use == 1) {
935  unsigned int broadcast = 1;
936 
937  if ((setsockopt(sockets->mcast_recv, SOL_SOCKET,
938  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
939  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
940  "setting broadcast option failed");
941  return (-1);
942  }
943  if ((setsockopt(sockets->mcast_send, SOL_SOCKET,
944  SO_BROADCAST, &broadcast, sizeof (broadcast))) == -1) {
945  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
946  "setting broadcast option failed");
947  return (-1);
948  }
949  } else {
950  switch (bindnet_address->family) {
951  case AF_INET:
952  memset(&mreq, 0, sizeof(mreq));
953  mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr;
954  mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr;
955  res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_ADD_MEMBERSHIP,
956  &mreq, sizeof (mreq));
957  if (res == -1) {
958  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
959  "join ipv4 multicast group failed");
960  return (-1);
961  }
962  break;
963  case AF_INET6:
964  memset(&mreq6, 0, sizeof(mreq6));
965  memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr));
966  mreq6.ipv6mr_interface = interface_num;
967 
968  res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP,
969  &mreq6, sizeof (mreq6));
970  if (res == -1) {
971  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
972  "join ipv6 multicast group failed");
973  return (-1);
974  }
975  break;
976  }
977  }
978 
979  /*
980  * Turn off multicast loopback
981  */
982 
983  flag = 0;
984  switch ( bindnet_address->family ) {
985  case AF_INET:
986  sflag = 0;
987  res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP,
988  &sflag, sizeof (sflag));
989  break;
990  case AF_INET6:
991  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
992  &flag, sizeof (flag));
993  }
994  if (res == -1) {
995  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
996  "Unable to turn off multicast loopback");
997  return (-1);
998  }
999 
1000  /*
1001  * Set multicast packets TTL
1002  */
1003  flag = instance->totem_interface->ttl;
1004  if (bindnet_address->family == AF_INET6) {
1005  res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
1006  &flag, sizeof (flag));
1007  if (res == -1) {
1008  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1009  "set mcast v6 TTL failed");
1010  return (-1);
1011  }
1012  } else {
1013  sflag = flag;
1014  res = setsockopt(sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_TTL,
1015  &sflag, sizeof(sflag));
1016  if (res == -1) {
1017  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1018  "set mcast v4 TTL failed");
1019  return (-1);
1020  }
1021  }
1022 
1023  /*
1024  * Bind to a specific interface for multicast send and receive
1025  */
1026  switch ( bindnet_address->family ) {
1027  case AF_INET:
1028  if (setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_IF,
1029  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1030  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1031  "cannot select interface for multicast packets (send)");
1032  return (-1);
1033  }
1034  if (setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_IF,
1035  &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) {
1036  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1037  "cannot select interface for multicast packets (recv)");
1038  return (-1);
1039  }
1040  break;
1041  case AF_INET6:
1042  if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1043  &interface_num, sizeof (interface_num)) < 0) {
1044  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1045  "cannot select interface for multicast packets (send v6)");
1046  return (-1);
1047  }
1048  if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1049  &interface_num, sizeof (interface_num)) < 0) {
1050  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1051  "cannot select interface for multicast packets (recv v6)");
1052  return (-1);
1053  }
1054  break;
1055  }
1056 
1057  /*
1058  * Bind to multicast socket used for multicast receives
1059  * This needs to happen after all of the multicast setsockopt() calls
1060  * as the kernel seems to only put them into effect (for IPV6) when bind()
1061  * is called.
1062  */
1064  instance->totem_interface->ip_port, &sockaddr, &addrlen);
1065  res = bind (sockets->mcast_recv, (struct sockaddr *)&sockaddr, addrlen);
1066  if (res == -1) {
1067  LOGSYS_PERROR (errno, instance->totemudp_log_level_warning,
1068  "Unable to bind the socket to receive multicast packets");
1069  return (-1);
1070  }
1071  return 0;
1072 }
1073 
1074 static int totemudp_build_sockets (
1075  struct totemudp_instance *instance,
1076  struct totem_ip_address *mcast_address,
1077  struct totem_ip_address *bindnet_address,
1078  struct totemudp_socket *sockets,
1079  struct totem_ip_address *bound_to)
1080 {
1081  int interface_num;
1082  int interface_up;
1083  int res;
1084 
1085  /*
1086  * Determine the ip address bound to and the interface name
1087  */
1088  res = netif_determine (instance,
1089  bindnet_address,
1090  bound_to,
1091  &interface_up,
1092  &interface_num);
1093 
1094  if (res == -1) {
1095  return (-1);
1096  }
1097 
1098  totemip_copy(&instance->my_id, bound_to);
1099 
1100  res = totemudp_build_sockets_ip (instance, mcast_address,
1101  bindnet_address, sockets, bound_to, interface_num);
1102 
1103  /* We only send out of the token socket */
1104  totemudp_traffic_control_set(instance, sockets->token);
1105  return res;
1106 }
1107 
1108 /*
1109  * Totem Network interface - also does encryption/decryption
1110  * depends on poll abstraction, POSIX, IPV4
1111  */
1112 
1113 /*
1114  * Create an instance
1115  */
1117  qb_loop_t *poll_handle,
1118  void **udp_context,
1119  struct totem_config *totem_config,
1120  totemsrp_stats_t *stats,
1121  int interface_no,
1122  void *context,
1123 
1124  void (*deliver_fn) (
1125  void *context,
1126  const void *msg,
1127  unsigned int msg_len),
1128 
1129  void (*iface_change_fn) (
1130  void *context,
1131  const struct totem_ip_address *iface_address),
1132 
1133  void (*target_set_completed) (
1134  void *context))
1135 {
1136  struct totemudp_instance *instance;
1137 
1138  instance = malloc (sizeof (struct totemudp_instance));
1139  if (instance == NULL) {
1140  return (-1);
1141  }
1142 
1143  totemudp_instance_initialize (instance);
1144 
1145  instance->totem_config = totem_config;
1146  instance->stats = stats;
1147 
1148  /*
1149  * Configure logging
1150  */
1151  instance->totemudp_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1158 
1159  /*
1160  * Initialize random number generator for later use to generate salt
1161  */
1162  instance->crypto_inst = crypto_init (totem_config->private_key,
1163  totem_config->private_key_len,
1164  totem_config->crypto_cipher_type,
1165  totem_config->crypto_hash_type,
1166  instance->totemudp_log_printf,
1167  instance->totemudp_log_level_security,
1168  instance->totemudp_log_level_notice,
1169  instance->totemudp_log_level_error,
1170  instance->totemudp_subsys_id);
1171  if (instance->crypto_inst == NULL) {
1172  free(instance);
1173  return (-1);
1174  }
1175  /*
1176  * Initialize local variables for totemudp
1177  */
1178  instance->totem_interface = &totem_config->interfaces[interface_no];
1179  totemip_copy (&instance->mcast_address, &instance->totem_interface->mcast_addr);
1180  memset (instance->iov_buffer, 0, FRAME_SIZE_MAX);
1181 
1182  instance->totemudp_poll_handle = poll_handle;
1183 
1184  instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
1185 
1186  instance->context = context;
1187  instance->totemudp_deliver_fn = deliver_fn;
1188 
1189  instance->totemudp_iface_change_fn = iface_change_fn;
1190 
1191  instance->totemudp_target_set_completed = target_set_completed;
1192 
1193  totemip_localhost (instance->mcast_address.family, &localhost);
1194  localhost.nodeid = instance->totem_config->node_id;
1195 
1196  /*
1197  * RRP layer isn't ready to receive message because it hasn't
1198  * initialized yet. Add short timer to check the interfaces.
1199  */
1200  qb_loop_timer_add (instance->totemudp_poll_handle,
1201  QB_LOOP_MED,
1202  100*QB_TIME_NS_IN_MSEC,
1203  (void *)instance,
1204  timer_function_netif_check_timeout,
1205  &instance->timer_netif_check_timeout);
1206 
1207  *udp_context = instance;
1208  return (0);
1209 }
1210 
1212 {
1213  return malloc (FRAME_SIZE_MAX);
1214 }
1215 
1216 void totemudp_buffer_release (void *ptr)
1217 {
1218  return free (ptr);
1219 }
1220 
1222  void *udp_context,
1223  int processor_count)
1224 {
1225  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1226  int res = 0;
1227 
1228  instance->my_memb_entries = processor_count;
1229  qb_loop_timer_del (instance->totemudp_poll_handle,
1230  instance->timer_netif_check_timeout);
1231  if (processor_count == 1) {
1232  qb_loop_timer_add (instance->totemudp_poll_handle,
1233  QB_LOOP_MED,
1234  instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
1235  (void *)instance,
1236  timer_function_netif_check_timeout,
1237  &instance->timer_netif_check_timeout);
1238  }
1239 
1240  return (res);
1241 }
1242 
1243 int totemudp_recv_flush (void *udp_context)
1244 {
1245  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1246  struct pollfd ufd;
1247  int nfds;
1248  int res = 0;
1249  int i;
1250  int sock;
1251 
1252  instance->flushing = 1;
1253 
1254  for (i = 0; i < 2; i++) {
1255  sock = -1;
1256  if (i == 0) {
1257  sock = instance->totemudp_sockets.mcast_recv;
1258  }
1259  if (i == 1) {
1260  sock = instance->totemudp_sockets.local_mcast_loop[0];
1261  }
1262  assert(sock != -1);
1263 
1264  do {
1265  ufd.fd = sock;
1266  ufd.events = POLLIN;
1267  nfds = poll (&ufd, 1, 0);
1268  if (nfds == 1 && ufd.revents & POLLIN) {
1269  net_deliver_fn (sock, ufd.revents, instance);
1270  }
1271  } while (nfds == 1);
1272  }
1273 
1274  instance->flushing = 0;
1275 
1276  return (res);
1277 }
1278 
1279 int totemudp_send_flush (void *udp_context)
1280 {
1281  return 0;
1282 }
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  ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1293 
1294  return (res);
1295 }
1297  void *udp_context,
1298  const void *msg,
1299  unsigned int msg_len)
1300 {
1301  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1302  int res = 0;
1303 
1304  mcast_sendmsg (instance, msg, msg_len);
1305 
1306  return (res);
1307 }
1308 
1310  void *udp_context,
1311  const void *msg,
1312  unsigned int msg_len)
1313 {
1314  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1315  int res = 0;
1316 
1317  mcast_sendmsg (instance, msg, msg_len);
1318 
1319  return (res);
1320 }
1321 
1322 extern int totemudp_iface_check (void *udp_context)
1323 {
1324  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1325  int res = 0;
1326 
1327  timer_function_netif_check_timeout (instance);
1328 
1329  return (res);
1330 }
1331 
1332 extern void totemudp_net_mtu_adjust (void *udp_context, struct totem_config *totem_config)
1333 {
1334 
1335  assert(totem_config->interface_count > 0);
1336 
1337  totem_config->net_mtu -= crypto_sec_header_size(totem_config->crypto_cipher_type,
1338  totem_config->crypto_hash_type) +
1340 }
1341 
1342 const char *totemudp_iface_print (void *udp_context) {
1343  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1344  const char *ret_char;
1345 
1346  ret_char = totemip_print (&instance->my_id);
1347 
1348  return (ret_char);
1349 }
1350 
1352  void *udp_context,
1353  struct totem_ip_address *addr)
1354 {
1355  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1356  int res = 0;
1357 
1358  memcpy (addr, &instance->my_id, sizeof (struct totem_ip_address));
1359 
1360  return (res);
1361 }
1362 
1364  void *udp_context,
1365  const struct totem_ip_address *token_target)
1366 {
1367  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1368  int res = 0;
1369 
1370  memcpy (&instance->token_target, token_target,
1371  sizeof (struct totem_ip_address));
1372 
1373  instance->totemudp_target_set_completed (instance->context);
1374 
1375  return (res);
1376 }
1377 
1379  void *udp_context)
1380 {
1381  struct totemudp_instance *instance = (struct totemudp_instance *)udp_context;
1382  unsigned int res;
1383  struct sockaddr_storage system_from;
1384  struct msghdr msg_recv;
1385  struct pollfd ufd;
1386  int nfds;
1387  int msg_processed = 0;
1388  int i;
1389  int sock;
1390 
1391  /*
1392  * Receive datagram
1393  */
1394  msg_recv.msg_name = &system_from;
1395  msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
1396  msg_recv.msg_iov = &instance->totemudp_iov_recv_flush;
1397  msg_recv.msg_iovlen = 1;
1398 #ifdef HAVE_MSGHDR_CONTROL
1399  msg_recv.msg_control = 0;
1400 #endif
1401 #ifdef HAVE_MSGHDR_CONTROLLEN
1402  msg_recv.msg_controllen = 0;
1403 #endif
1404 #ifdef HAVE_MSGHDR_FLAGS
1405  msg_recv.msg_flags = 0;
1406 #endif
1407 #ifdef HAVE_MSGHDR_ACCRIGHTS
1408  msg_recv.msg_accrights = NULL;
1409 #endif
1410 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1411  msg_recv.msg_accrightslen = 0;
1412 #endif
1413 
1414  for (i = 0; i < 2; i++) {
1415  sock = -1;
1416  if (i == 0) {
1417  sock = instance->totemudp_sockets.mcast_recv;
1418  }
1419  if (i == 1) {
1420  sock = instance->totemudp_sockets.local_mcast_loop[0];
1421  }
1422  assert(sock != -1);
1423 
1424  do {
1425  ufd.fd = sock;
1426  ufd.events = POLLIN;
1427  nfds = poll (&ufd, 1, 0);
1428  if (nfds == 1 && ufd.revents & POLLIN) {
1429  res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
1430  if (res != -1) {
1431  msg_processed = 1;
1432  } else {
1433  msg_processed = -1;
1434  }
1435  }
1436  } while (nfds == 1);
1437  }
1438 
1439  return (msg_processed);
1440 }
1441 
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:1221
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:667
The totem_ip_address struct.
Definition: coroapi.h:111
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:214
size_t crypto_get_current_sec_header_size(const struct crypto_instance *instance)
Definition: totemcrypto.c:702
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:1332
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:1211
int totemudp_mcast_flush_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1296
int totemudp_token_target_set(void *udp_context, const struct totem_ip_address *token_target)
Definition: totemudp.c:1363
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:803
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:1309
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:1279
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:1243
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:723
int totemudp_token_send(void *udp_context, const void *msg, unsigned int msg_len)
Definition: totemudp.c:1284
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:1116
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(* 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:425
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:1342
#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:745
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:1351
#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:1378
int totemudp_iface_check(void *udp_context)
Definition: totemudp.c:1322
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:1216
int totemudp_log_level_warning
Definition: totemudp.c:137