corosync
totemknet.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2022 Red Hat, Inc.
3 *
4 * All rights reserved.
5 *
6 * Author: Christine Caulfield (ccaulfie@redhat.com)
7
8 * This software licensed under BSD license, the text of which follows:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <config.h>
36
37#include <assert.h>
38#include <sys/mman.h>
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <sys/socket.h>
42#include <netdb.h>
43#include <sys/un.h>
44#include <sys/ioctl.h>
45#include <sys/param.h>
46#include <netinet/in.h>
47#include <arpa/inet.h>
48#include <unistd.h>
49#include <fcntl.h>
50#include <stdlib.h>
51#include <stdio.h>
52#include <errno.h>
53#include <pthread.h>
54#include <sched.h>
55#include <time.h>
56#include <sys/time.h>
57#include <poll.h>
58#include <sys/uio.h>
59#include <limits.h>
60
61#include <qb/qbdefs.h>
62#include <qb/qbloop.h>
63#ifdef HAVE_LIBNOZZLE
64#include <libgen.h>
65#include <libnozzle.h>
66#endif
67
68#include <corosync/sq.h>
69#include <corosync/swab.h>
70#include <corosync/logsys.h>
71#include <corosync/icmap.h>
73#include "totemknet.h"
74
75#include "main.h"
76#include "util.h"
77
78#include <libknet.h>
80
81#ifndef MSG_NOSIGNAL
82#define MSG_NOSIGNAL 0
83#endif
84
85#ifdef HAVE_LIBNOZZLE
86static int setup_nozzle(void *knet_context);
87#endif
88
89/* Should match that used by cfg */
90#define CFG_INTERFACE_STATUS_MAX_LEN 512
91
92#ifdef KNET_DATAFD_FLAG_RX_RETURN_INFO
93#define KNET_IOV_LEN_MAX KNET_MAX_PACKET_SIZE + 1 + sizeof(struct knet_datafd_header)
94#else
95#define KNET_IOV_LEN_MAX KNET_MAX_PACKET_SIZE + 1
96#endif
97
100
102
104
106
108
109 void *context;
110
112 void *context,
113 const void *msg,
114 unsigned int msg_len,
115 const struct sockaddr_storage *system_from);
116
118 void *context,
119 const struct totem_ip_address *iface_address,
120 unsigned int link_no);
121
123 void *context,
124 int net_mtu);
125
127
128 /*
129 * Function and data used to log messages
130 */
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
155
157
159
161
163
165
167
169
171
173
175
177
179
180 int logpipes[2];
182
184#ifdef HAVE_LIBNOZZLE
185 char *nozzle_name;
186 char *nozzle_ipaddr;
187 char *nozzle_prefix;
188 char *nozzle_macaddr;
190#endif
191};
192
193/* Awkward. But needed to get stats from knet */
195
196struct work_item {
197 const void *msg;
198 unsigned int msg_len;
200};
201
203 void *knet_context);
204
205
206static int totemknet_configure_compression (
207 struct totemknet_instance *instance,
208 struct totem_config *totem_config);
209
210static void totemknet_start_merge_detect_timeout(
211 void *knet_context);
212
213static void totemknet_stop_merge_detect_timeout(
214 void *knet_context);
215
216static void log_flush_messages (
217 void *knet_context);
218
219static void totemknet_instance_initialize (struct totemknet_instance *instance)
220{
221 int res;
222
223 memset (instance, 0, sizeof (struct totemknet_instance));
224 res = pthread_mutex_init(&instance->log_mutex, NULL);
225 /*
226 * There is not too much else what can be done.
227 */
228 assert(res == 0);
229}
230
231#define knet_log_printf_lock(level, subsys, function, file, line, format, args...) \
232do { \
233 (void)pthread_mutex_lock(&instance->log_mutex); \
234 instance->totemknet_log_printf ( \
235 level, subsys, function, file, line, \
236 (const char *)format, ##args); \
237 (void)pthread_mutex_unlock(&instance->log_mutex); \
238} while (0);
239
240#define knet_log_printf(level, format, args...) \
241do { \
242 knet_log_printf_lock ( \
243 level, instance->totemknet_subsys_id, \
244 __FUNCTION__, __FILE__, __LINE__, \
245 (const char *)format, ##args); \
246} while (0);
247
248#define libknet_log_printf(level, format, args...) \
249do { \
250 knet_log_printf_lock ( \
251 level, instance->knet_subsys_id, \
252 __FUNCTION__, "libknet.h", __LINE__, \
253 (const char *)format, ##args); \
254} while (0);
255
256#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
257do { \
258 char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
259 const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
260 instance->totemknet_log_printf ( \
261 level, instance->totemknet_subsys_id, \
262 __FUNCTION__, __FILE__, __LINE__, \
263 fmt ": %s (%d)", ##args, _error_ptr, err_num); \
264 } while(0)
265
266
267#ifdef HAVE_LIBNOZZLE
268static inline uint8_t *ether_get_dst_mac(const unsigned char *packet, ssize_t packet_len)
269{
270 /*
271 * Packet must be at least as long as one MAC address
272 */
273 if (packet_len < 6) {
274 return NULL;
275 }
276
277 /*
278 * To ensure portability, this implementation parses raw packet data directly
279 * according to the Ethernet II standard.
280 *
281 * The system-provided struct ether_header is not used because its definition
282 * and the location of its header file vary between platforms like Linux, BSD,
283 * and Illumos. In the Ethernet II standard, the destination MAC address is
284 * always the first 6 bytes of the frame.
285 */
286 return (uint8_t *)packet;
287}
288
289static inline int is_ether_addr_multicast(const uint8_t *addr)
290{
291 return (addr[0] & 0x01);
292}
293static inline int is_ether_addr_zero(const uint8_t *addr)
294{
295 return (!addr[0] && !addr[1] && !addr[2] && !addr[3] && !addr[4] && !addr[5]);
296}
297
298static int ether_host_filter_fn(void *private_data,
299 const unsigned char *outdata,
306 size_t *dst_host_ids_entries)
307{
310
311 if (dst_mac == NULL) {
312 return -1;
313 }
314
316 return -1;
317
319 return 1;
320 }
321
322 memmove(&dst_host_id, &dst_mac[4], 2);
323
326
327 return 0;
328}
329#endif
330
331static int dst_host_filter_callback_fn(void *private_data,
332 const unsigned char *outdata,
339 size_t *dst_host_ids_entries)
340{
342 int res;
343
344#ifdef HAVE_LIBNOZZLE
345 if (*channel != 0) {
348 tx_rx,
350 channel,
353 }
354#endif
355 if (header->target_nodeid) {
358 res = 0; /* unicast message */
359 }
360 else {
362 res = 1; /* multicast message */
363 }
364 return res;
365}
366
367static void socket_error_callback_fn(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)
368{
369 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
370
371 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet socket ERROR notification called: txrx=%d, error=%d, errorno=%d", tx_rx, error, errorno);
372 if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
374 }
375}
376
377static void host_change_callback_fn(void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
378{
379 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
380
381 // TODO: what? if anything.
382 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet host change callback. nodeid: " CS_PRI_NODE_ID " reachable: %d", host_id, reachable);
383}
384
385static void pmtu_change_callback_fn(void *private_data, unsigned int data_mtu)
386{
387 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
388 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet pMTU change: %d", data_mtu);
389
390 /* We don't need to tell corosync the actual knet MTU */
391// instance->totemknet_mtu_changed(instance->context, data_mtu);
392}
393
395 void *knet_context,
396 const char *cipher_type,
397 const char *hash_type)
398{
399 return (0);
400}
401
402
403static inline void ucast_sendmsg (
404 struct totemknet_instance *instance,
406 const void *msg,
407 unsigned int msg_len)
408{
409 int res = 0;
410 struct totem_message_header *header = (struct totem_message_header *)msg;
411 struct msghdr msg_ucast;
412 struct iovec iovec;
413
414 header->target_nodeid = system_to->nodeid;
415
416 iovec.iov_base = (void *)msg;
417 iovec.iov_len = msg_len;
418
419 /*
420 * Build unicast message
421 */
422 memset(&msg_ucast, 0, sizeof(msg_ucast));
423 msg_ucast.msg_iov = (void *)&iovec;
424 msg_ucast.msg_iovlen = 1;
425
426 /*
427 * Transmit unicast message
428 * An error here is recovered by totemsrp
429 */
430
431 res = sendmsg (instance->knet_fd, &msg_ucast, MSG_NOSIGNAL);
432 if (res < 0) {
434 "sendmsg(ucast) failed (non-critical)");
435 }
436}
437
438static inline void mcast_sendmsg (
439 struct totemknet_instance *instance,
440 const void *msg,
441 unsigned int msg_len,
442 int only_active)
443{
444 int res;
445 struct totem_message_header *header = (struct totem_message_header *)msg;
446 struct msghdr msg_mcast;
447 struct iovec iovec;
448
449 iovec.iov_base = (void *)msg;
450 iovec.iov_len = msg_len;
451
453
454 /*
455 * Build multicast message
456 */
457 memset(&msg_mcast, 0, sizeof(msg_mcast));
458 msg_mcast.msg_iov = (void *)&iovec;
459 msg_mcast.msg_iovlen = 1;
460
461// log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_sendmsg. only_active=%d, len=%d", only_active, msg_len);
462
463 res = sendmsg (instance->knet_fd, &msg_mcast, MSG_NOSIGNAL);
464 if (res < msg_len) {
465 knet_log_printf (LOGSYS_LEVEL_DEBUG, "totemknet: mcast_send sendmsg returned %d", res);
466 }
467
468 if (!only_active || instance->send_merge_detect_message) {
469 /*
470 * Current message was sent to all nodes
471 */
473 instance->send_merge_detect_message = 0;
474 }
475}
476
477static int node_compare(const void *aptr, const void *bptr)
478{
479 uint16_t a,b;
480
481 a = *(uint16_t *)aptr;
482 b = *(uint16_t *)bptr;
483
484 return a > b;
485}
486
487#ifndef OWN_INDEX_NONE
488#define OWN_INDEX_NONE -1
489#endif
490
492 void *knet_context,
493 unsigned int nodeid,
495{
496 int i;
497 int res = 0;
498 struct knet_link_status link_status;
499 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
502 size_t num_links;
503
504 if (!instance->knet_handle) {
505 return CS_ERR_NOT_EXIST; /* Not using knet */
506 }
507
508 if (!node_status) {
510 }
511
513 nodeid,
515 if (res) {
516 knet_log_printf (LOGSYS_LEVEL_WARNING, "knet_handle_get_host_status(%d) failed: %d", nodeid, res);
517 return (-1);
518 }
519 node_status->nodeid = nodeid;
520 node_status->reachable = knet_host_status.reachable;
521 node_status->remote = knet_host_status.remote;
522 node_status->external = knet_host_status.external;
523
524#ifdef HAVE_KNET_ONWIRE_VER
526 nodeid,
527 &node_status->onwire_min,
528 &node_status->onwire_max,
529 &node_status->onwire_ver);
530 if (res) {
531 knet_log_printf (LOGSYS_LEVEL_WARNING, "knet_handle_get_onwire_ver(%d) failed: %d", nodeid, res);
532 return (-1);
533 }
534#endif
535 /* Get link info */
538 if (res) {
539 knet_log_printf (LOGSYS_LEVEL_WARNING, "knet_link_get_link_list(%d) failed: %d", nodeid, res);
540 return (-1);
541 }
542
543 /* node_status[] has been zeroed for us in totempg.c */
544 for (i=0; i < num_links; i++) {
545 if (!instance->totem_config->interfaces[link_list[i]].configured) {
546 continue;
547 }
549 nodeid,
550 link_list[i],
551 &link_status,
552 sizeof(link_status));
553 if (res == 0) {
554 node_status->link_status[link_list[i]].enabled = link_status.enabled;
555 node_status->link_status[link_list[i]].connected = link_status.connected;
556 node_status->link_status[link_list[i]].dynconnected = link_status.dynconnected;
557 node_status->link_status[link_list[i]].mtu = link_status.mtu;
558 memcpy(node_status->link_status[link_list[i]].src_ipaddr, link_status.src_ipaddr, KNET_MAX_HOST_LEN);
559 memcpy(node_status->link_status[link_list[i]].dst_ipaddr, link_status.dst_ipaddr, KNET_MAX_HOST_LEN);
560 } else {
561 knet_log_printf (LOGSYS_LEVEL_WARNING, "knet_link_get_link_status(%d, %d) failed: %d", nodeid, link_list[i], res);
562 }
563 }
564 return res;
565}
566
567
568
569int totemknet_ifaces_get (void *knet_context,
570 char ***status,
571 unsigned int *iface_count)
572{
573 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
574 struct knet_link_status link_status;
577 size_t num_hosts;
578 size_t num_links;
579 size_t link_idx;
580 int i,j;
581 char *ptr;
582 int res = 0;
583
584 /*
585 * Don't do the whole 'link_info' bit if the caller just wants
586 * a count of interfaces.
587 */
588 if (status) {
590
593 if (res) {
594 return (-1);
595 }
596 qsort(host_list, num_hosts, sizeof(uint16_t), node_compare);
597
598 for (j=0; j<num_hosts; j++) {
599 if (host_list[j] == instance->our_nodeid) {
600 own_idx = j;
601 break;
602 }
603 }
604
605 for (i=0; i<INTERFACE_MAX; i++) {
607 if (own_idx != OWN_INDEX_NONE) {
608 instance->link_status[i][own_idx] = 'n';
609 }
610 instance->link_status[i][num_hosts] = '\0';
611 }
612
613 /* This is all a bit "inside-out" because "status" is a set of strings per link
614 * and knet orders things by host
615 */
616 for (j=0; j<num_hosts; j++) {
617 if (own_idx != OWN_INDEX_NONE && j == own_idx) {
618 continue ;
619 }
620
623 if (res) {
624 return (-1);
625 }
626
627 link_idx = 0;
628 for (i=0; i < num_links; i++) {
629 /*
630 * Skip over links that are unconfigured to corosync. This is basically
631 * link0 if corosync isn't using it for comms, as we will still
632 * have it set up for loopback.
633 */
634 if (!instance->totem_config->interfaces[link_list[i]].configured) {
635 continue;
636 }
637 ptr = instance->link_status[link_idx++];
638
640 host_list[j],
641 link_list[i],
642 &link_status,
643 sizeof(link_status));
644 if (res == 0) {
645 ptr[j] = '0' + (link_status.enabled |
646 link_status.connected<<1 |
647 link_status.dynconnected<<2);
648 }
649 else {
651 "totemknet_ifaces_get: Cannot get link status: %s", strerror(errno));
652 ptr[j] = '?';
653 }
654 }
655 }
656 *status = instance->link_status;
657 }
658
660
661 return (res);
662}
663
665 void *knet_context)
666{
667 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
668 int res = 0;
669 int i,j;
670 static knet_node_id_t nodes[KNET_MAX_HOST]; /* static to save stack */
672 size_t num_nodes;
673 size_t num_links;
674
675 knet_log_printf(LOG_DEBUG, "totemknet: finalize");
676
677 qb_loop_poll_del (instance->poll_handle, instance->logpipes[0]);
678 qb_loop_poll_del (instance->poll_handle, instance->knet_fd);
679
680 /*
681 * Disable forwarding to make knet flush send queue. This ensures that the LEAVE message will be sent.
682 */
683 res = knet_handle_setfwd(instance->knet_handle, 0);
684 if (res) {
685 knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_setfwd failed: %s", strerror(errno));
686 }
687
689 if (res) {
690 knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet node list for shutdown: %s", strerror(errno));
691 /* Crash out anyway */
692 goto finalise_error;
693 }
694
695 /* Tidily shut down all nodes & links. */
696 for (i=0; i<num_nodes; i++) {
697
699 if (res) {
700 knet_log_printf (LOGSYS_LEVEL_ERROR, "Cannot get knet link list for node " CS_PRI_NODE_ID ": %s", nodes[i], strerror(errno));
701 goto finalise_error;
702 }
703 for (j=0; j<num_links; j++) {
704 res = knet_link_set_enable(instance->knet_handle, nodes[i], links[j], 0);
705 if (res) {
706 knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_set_enable(node " CS_PRI_NODE_ID ", link %d) failed: %s", nodes[i], links[j], strerror(errno));
707 }
709 if (res) {
710 knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_link_clear_config(node " CS_PRI_NODE_ID ", link %d) failed: %s", nodes[i], links[j], strerror(errno));
711 }
712 }
713 res = knet_host_remove(instance->knet_handle, nodes[i]);
714 if (res) {
715 knet_log_printf (LOGSYS_LEVEL_ERROR, "totemknet: knet_host_remove(node " CS_PRI_NODE_ID ") failed: %s", nodes[i], strerror(errno));
716 }
717 }
718
720 res = knet_handle_free(instance->knet_handle);
721 if (res) {
722 knet_log_printf (LOGSYS_LEVEL_CRIT, "totemknet: knet_handle_free failed: %s", strerror(errno));
723 }
724
725 totemknet_stop_merge_detect_timeout(instance);
726
727 log_flush_messages(instance);
728
729 /*
730 * Error is deliberately ignored
731 */
733
734 return (res);
735}
736
737static int log_deliver_fn (
738 int fd,
739 int revents,
740 void *data)
741{
742 struct totemknet_instance *instance = (struct totemknet_instance *)data;
743 char buffer[sizeof(struct knet_log_msg)*4];
744 char *bufptr = buffer;
745 int done = 0;
746 int len;
747
748 len = read(fd, buffer, sizeof(buffer));
749 while (done < len) {
750 struct knet_log_msg *msg = (struct knet_log_msg *)bufptr;
751 switch (msg->msglevel) {
752 case KNET_LOG_ERR:
754 knet_log_get_subsystem_name(msg->subsystem),
755 msg->msg);
756 break;
757 case KNET_LOG_WARN:
759 knet_log_get_subsystem_name(msg->subsystem),
760 msg->msg);
761 break;
762 case KNET_LOG_INFO:
764 knet_log_get_subsystem_name(msg->subsystem),
765 msg->msg);
766 break;
767 case KNET_LOG_DEBUG:
769 knet_log_get_subsystem_name(msg->subsystem),
770 msg->msg);
771 break;
772#ifdef KNET_LOG_TRACE
773 case KNET_LOG_TRACE:
775 knet_log_get_subsystem_name(msg->subsystem),
776 msg->msg);
777 break;
778#endif
779 }
780 bufptr += sizeof(struct knet_log_msg);
781 done += sizeof(struct knet_log_msg);
782 }
783 return 0;
784}
785
786static int data_deliver_fn (
787 int fd,
788 int revents,
789 void *data)
790{
791 struct totemknet_instance *instance = (struct totemknet_instance *)data;
792 struct msghdr msg_hdr;
793 struct iovec iov_recv;
795 ssize_t msg_len;
796 char *data_ptr = instance->iov_buffer;
797
798 iov_recv.iov_base = instance->iov_buffer;
799 iov_recv.iov_len = KNET_IOV_LEN_MAX;
800
801 memset(&msg_hdr, 0, sizeof(msg_hdr));
802 msg_hdr.msg_name = &system_from;
803 msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
804 msg_hdr.msg_iov = &iov_recv;
805 msg_hdr.msg_iovlen = 1;
806
807 msg_len = recvmsg (fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
808 if (msg_len <= 0) {
809 return (0);
810 }
811
812 if (msg_len >= KNET_IOV_LEN_MAX) {
813 /*
814 * It this happens it is real bug, because knet always sends packet with maximum size
815 * of KNET_MAX_PACKET_SIZE.
816 * If received packet is MAX_PACKET_SIZE + 1 it means packet was truncated
817 * (iov_buffer size and iov_len are intentionally set to KNET_MAX_PACKET_SIZE + 1).
818 */
820 "Received truncated packet. Please report this bug. Dropping packet.");
821 return (0);
822 }
823
824 /*
825 * If it's from the knet fd then it will have the optional knet header on it
826 */
827#ifdef KNET_DATAFD_FLAG_RX_RETURN_INFO
828 if (fd == instance->knet_fd) {
830
831/* knet_log_printf (LOGSYS_LEVEL_DEBUG, "Packet from knet_fd nodeid: %d\n", datafd_header->src_nodeid); */
832
833 /* Advance past the ACTUAL header size, not the size we think it might be */
834 data_ptr += datafd_header->size;
835 msg_len -= datafd_header->size;
836 }
837#endif
838
839
840 /*
841 * Handle incoming message
842 */
843 instance->totemknet_deliver_fn (
844 instance->context,
845 data_ptr,
846 msg_len,
847 &system_from);
848
849 return (0);
850}
851
852static void timer_function_netif_check_timeout (
853 void *data)
854{
855 struct totemknet_instance *instance = (struct totemknet_instance *)data;
856 int i;
857 int res = 0;
858
859 for (i=0; i < INTERFACE_MAX; i++) {
860 if (!instance->totem_config->interfaces[i].configured) {
861 continue;
862 }
863 res = instance->totemknet_iface_change_fn (instance->context,
864 &instance->my_ids[i],
865 i);
866 }
867 if (res != 0) {
868 /* This is only called at startup, so we can quit here.
869 Refresh takes a different path */
871 }
872}
873
874static void knet_set_access_list_config(struct totemknet_instance *instance)
875{
876#ifdef HAVE_KNET_ACCESS_LIST
879
881 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_enable access list: %d", value);
882
884 if (err) {
885 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_access_lists failed");
886 }
887#endif
888}
889
891{
892 int logsys_log_mode;
894 uint8_t s;
895 int err;
896
898 return;
899 }
900
901 /* Reconfigure logging level */
903
904 switch (logsys_log_mode) {
905 case LOGSYS_DEBUG_OFF:
907 break;
908 case LOGSYS_DEBUG_ON:
910 break;
912#ifdef KNET_LOG_TRACE
914#else
916#endif
917 break;
918 }
919 log_printf (LOGSYS_LEVEL_DEBUG, "totemknet setting log level %s", knet_log_get_loglevel_name(knet_log_mode));
920 err = 0;
921 for (s = 0; s<KNET_MAX_SUBSYSTEMS; s++) {
923 }
924
925 /* If one fails, they all fail. no point in issuing KNET_MAX_SUBSYSTEMS errors */
926 if (err) {
927 log_printf (LOGSYS_LEVEL_ERROR, "totemknet failed to set log level: %s", strerror(errno));
928 }
929}
930
931
932/* NOTE: this relies on the fact that totem_reload_notify() is called first */
933static void totemknet_refresh_config(
934 int32_t event,
935 const char *key_name,
938 void *user_data)
939{
941 int after_reload;
943 size_t num_nodes;
945 int i;
946 int err;
947 struct totemknet_instance *instance = (struct totemknet_instance *)user_data;
948
949 ENTER();
950
951 /*
952 * If a full reload is in progress then don't do anything until it's done and
953 * can reconfigure it all atomically
954 */
955 if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
956 return;
957 }
958
959 after_reload = (strcmp(key_name, "config.totemconfig_reload_in_progress") == 0);
960
961 knet_set_access_list_config(instance);
962
963 if (strcmp(key_name, "totem.knet_pmtud_interval") == 0 || after_reload) {
964 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pmtud_interval now %u",
967 if (err) {
968 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
969 }
970 }
971
972 if (strcmp(key_name, "totem.knet_mtu") == 0 || after_reload) {
973 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_mtu now %u", instance->totem_config->knet_mtu);
975 if (err) {
976 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud failed");
977 }
978 }
979
980 /* Configure link parameters for each node */
982 if (err != 0) {
983 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list failed");
984 }
985
986 for (i=0; i<num_nodes; i++) {
987 int linkerr = 0;
988 for (link_no = 0; link_no < INTERFACE_MAX; link_no++) {
989 if (host_ids[i] == instance->our_nodeid || !instance->totem_config->interfaces[link_no].configured) {
990 continue;
991 }
992
997 if (err) {
998 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for node " CS_PRI_NODE_ID " link %d failed", host_ids[i], link_no);
999 linkerr = err;
1000 }
1003 if (err) {
1004 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for node " CS_PRI_NODE_ID " link %d failed",host_ids[i], link_no);
1005 linkerr = err;
1006 }
1009 if (err) {
1010 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for node " CS_PRI_NODE_ID " link %d failed", host_ids[i], link_no);
1011 linkerr = err;
1012 }
1013
1014 }
1015 if (linkerr) {
1016 icmap_set_string("config.reload_error_message", "Failed to set knet ping timers(2)");
1017 }
1018 }
1019
1020 /* Log levels get reconfigured from logconfig.c as that happens last in the reload */
1021 LEAVE();
1022}
1023
1024static void totemknet_add_config_notifications(struct totemknet_instance *instance)
1025{
1028
1029 ENTER();
1030
1031 icmap_track_add("totem.",
1033 totemknet_refresh_config,
1034 instance,
1036
1037 icmap_track_add("config.totemconfig_reload_in_progress",
1039 totemknet_refresh_config,
1040 instance,
1042
1043 LEAVE();
1044}
1045
1046static int totemknet_is_crypto_enabled(const struct totemknet_instance *instance)
1047{
1048
1049 return (!(strcmp(instance->totem_config->crypto_cipher_type, "none") == 0 &&
1050 strcmp(instance->totem_config->crypto_hash_type, "none") == 0));
1051
1052}
1053
1054static int totemknet_set_knet_crypto(struct totemknet_instance *instance)
1055{
1057 int res;
1058
1059 /* These have already been validated */
1060 memcpy(crypto_cfg.crypto_model, instance->totem_config->crypto_model, sizeof(crypto_cfg.crypto_model));
1061 memcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type, sizeof(crypto_cfg.crypto_model));
1062 memcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type, sizeof(crypto_cfg.crypto_model));
1063 memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
1064 crypto_cfg.private_key_len = instance->totem_config->private_key_len;
1065
1066#ifdef HAVE_KNET_CRYPTO_RECONF
1067
1068 knet_log_printf(LOGSYS_LEVEL_DEBUG, "Configuring crypto %s/%s/%s on index %d",
1069 crypto_cfg.crypto_model,
1070 crypto_cfg.crypto_cipher_type,
1071 crypto_cfg.crypto_hash_type,
1072 instance->totem_config->crypto_index
1073 );
1074
1075 /* If crypto is being disabled we need to explicitly allow cleartext traffic in knet */
1076 if (!totemknet_is_crypto_enabled(instance)) {
1078 if (res) {
1079 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(ALLOW) failed %s", strerror(errno));
1080 }
1081 }
1082
1083 /* use_config will be called later when all nodes are synced */
1085 if (res == 0) {
1086 /* Keep a copy in case it fails in future */
1087 memcpy(&instance->last_good_crypto_cfg, &crypto_cfg, sizeof(crypto_cfg));
1088 }
1089 if (res == -1) {
1090 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config (index %d) failed: %s", instance->totem_config->crypto_index, strerror(errno));
1091 goto exit_error;
1092 }
1093 if (res == -2) {
1094 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config (index %d) failed: -2", instance->totem_config->crypto_index);
1095 goto exit_error;
1096 }
1097#else
1098 knet_log_printf(LOGSYS_LEVEL_DEBUG, "Configuring crypto %s/%s/%s",
1099 crypto_cfg.crypto_model,
1100 crypto_cfg.crypto_cipher_type,
1101 crypto_cfg.crypto_hash_type
1102 );
1103
1105 if (res == -1) {
1106 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: %s", strerror(errno));
1107 goto exit_error;
1108 }
1109 if (res == -2) {
1110 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto failed: -2");
1111 goto exit_error;
1112 }
1113#endif
1114
1116#ifdef HAVE_KNET_CRYPTO_RECONF
1117 if (res) {
1118 icmap_set_string("config.reload_error_message", "Failed to set crypto parameters");
1119
1120 /* Restore the old values in cmap & totem_config */
1121 icmap_set_string("totem.crypto_cipher", instance->last_good_crypto_cfg.crypto_cipher_type);
1122 icmap_set_string("totem.crypto_hash", instance->last_good_crypto_cfg.crypto_hash_type);
1123 icmap_set_string("totem.crypto_model", instance->last_good_crypto_cfg.crypto_model);
1124
1125 memcpy(instance->totem_config->crypto_hash_type, instance->last_good_crypto_cfg.crypto_hash_type,
1126 sizeof(instance->last_good_crypto_cfg.crypto_hash_type));
1127 memcpy(instance->totem_config->crypto_cipher_type, instance->last_good_crypto_cfg.crypto_cipher_type,
1128 sizeof(instance->last_good_crypto_cfg.crypto_cipher_type));
1129 memcpy(instance->totem_config->crypto_model, instance->last_good_crypto_cfg.crypto_model,
1130 sizeof(instance->last_good_crypto_cfg.crypto_model));
1131 }
1132#endif
1133 return res;
1134}
1135
1136/*
1137 * Create an instance
1138 */
1140 qb_loop_t *poll_handle,
1141 void **knet_context,
1142 struct totem_config *totem_config,
1143 totemsrp_stats_t *stats,
1144 void *context,
1145
1146 int (*deliver_fn) (
1147 void *context,
1148 const void *msg,
1149 unsigned int msg_len,
1150 const struct sockaddr_storage *system_from),
1151
1152 int (*iface_change_fn) (
1153 void *context,
1154 const struct totem_ip_address *iface_address,
1155 unsigned int link_no),
1156
1157 void (*mtu_changed) (
1158 void *context,
1159 int net_mtu),
1160
1161 void (*target_set_completed) (
1162 void *context))
1163{
1164 struct totemknet_instance *instance;
1165 char *tmp_str;
1166 int8_t channel=0;
1168 int res;
1169 int i;
1170
1171 instance = malloc (sizeof (struct totemknet_instance));
1172 if (instance == NULL) {
1173 return (-1);
1174 }
1175
1176 totemknet_instance_initialize (instance);
1177
1178 instance->totem_config = totem_config;
1179
1180 /*
1181 * Configure logging
1182 */
1183 instance->totemknet_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1190
1191 instance->knet_subsys_id = _logsys_subsys_create("KNET", "libknet.h");
1192
1193 /*
1194 * Initialize local variables for totemknet
1195 */
1196
1197 instance->our_nodeid = instance->totem_config->node_id;
1198
1199 for (i=0; i< INTERFACE_MAX; i++) {
1201 instance->my_ids[i].nodeid = instance->our_nodeid;
1202 instance->ip_port[i] = totem_config->interfaces[i].ip_port;
1203
1204 /* Needed for totemsrp */
1206 }
1207
1208 instance->poll_handle = poll_handle;
1209
1210 instance->context = context;
1211 instance->totemknet_deliver_fn = deliver_fn;
1212
1214
1216
1217 instance->totemknet_target_set_completed = target_set_completed;
1218
1219 instance->loopback_link = 0;
1220
1221 res = pipe(instance->logpipes);
1222 if (res == -1) {
1223 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to create pipe for instance->logpipes");
1224 goto exit_error;
1225 }
1226 if (fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK) == -1 ||
1227 fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK) == -1) {
1228 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to set O_NONBLOCK flag for instance->logpipes");
1229 goto exit_error;
1230 }
1231
1232 if (icmap_get_string("system.allow_knet_handle_fallback", &tmp_str) == CS_OK) {
1233 if (strcmp(tmp_str, "yes") == 0) {
1235 }
1236 free(tmp_str);
1237 }
1238
1239#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1241#else
1242 instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
1243#endif
1244
1245 if (allow_knet_handle_fallback && !instance->knet_handle && errno == ENAMETOOLONG) {
1246 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_new failed, trying unprivileged");
1247#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1248 instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
1249#else
1250 instance->knet_handle = knet_handle_new_ex(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
1251#endif
1252 }
1253
1254 if (!instance->knet_handle) {
1255 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
1256 goto exit_error;
1257 }
1258
1259 knet_set_access_list_config(instance);
1260
1262 if (res) {
1263 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
1264 }
1266 if (res) {
1267 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_set failed");
1268 }
1269#ifdef HAVE_KNET_SETPRIO_DSCP
1271 if (res) {
1272 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_setprio_dscp failed");
1273 }
1274#else
1275 if (instance->totem_config->ip_dscp) {
1276 knet_log_printf(LOGSYS_LEVEL_WARNING, "Ignoring 'ip_dscp' option: Corosync was"
1277 " compiled without knet_handle_setprio_dscp support.");
1278 }
1279#endif
1280 res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
1281 if (res) {
1282 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
1283 }
1284 res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
1285 if (res) {
1286 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
1287 }
1288 res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
1289 if (res) {
1290 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
1291 }
1292 res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
1293 if (res) {
1294 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
1295 }
1296 global_instance = instance;
1297
1298 /* Setup knet logging level */
1300
1301 /* Get an fd into knet */
1302 instance->knet_fd = 0;
1303#ifdef KNET_DATAFD_FLAG_RX_RETURN_INFO
1305#else
1306 res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
1307#endif
1308 if (res) {
1309 knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
1310 goto exit_error;
1311 }
1312
1313 /* Enable crypto if requested */
1314#ifdef HAVE_KNET_CRYPTO_RECONF
1315 if (totemknet_is_crypto_enabled(instance)) {
1316 res = totemknet_set_knet_crypto(instance);
1317 if (res == 0) {
1319 if (res) {
1320 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_use_config failed: %s", strerror(errno));
1321 goto exit_error;
1322 }
1323 } else {
1324 knet_log_printf(LOG_DEBUG, "Failed to set up knet crypto");
1325 goto exit_error;
1326 }
1328 if (res) {
1329 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_rx_clear_traffic (DISALLOW) failed: %s", strerror(errno));
1330 goto exit_error;
1331 }
1332
1333 } else {
1335 if (res) {
1336 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_rx_clear_traffic (ALLOW) failed: %s", strerror(errno));
1337 goto exit_error;
1338 }
1339 }
1340#else
1341 if (totemknet_is_crypto_enabled(instance)) {
1342 res = totemknet_set_knet_crypto(instance);
1343 if (res) {
1344 knet_log_printf(LOG_DEBUG, "Failed to set up knet crypto");
1345 goto exit_error;
1346 }
1347 }
1348#endif
1349
1350 /* Set up compression */
1351 if (strcmp(totem_config->knet_compression_model, "none") != 0) {
1352 /* Not fatal, but will log */
1353 (void)totemknet_configure_compression(instance, totem_config);
1354 }
1355
1356 knet_handle_setfwd(instance->knet_handle, 1);
1357
1359 if (strcmp(instance->totem_config->link_mode, "active")==0) {
1361 }
1362 if (strcmp(instance->totem_config->link_mode, "rr")==0) {
1363 instance->link_mode = KNET_LINK_POLICY_RR;
1364 }
1365
1366 for (i=0; i<INTERFACE_MAX; i++) {
1368 if (!instance->link_status[i]) {
1369 goto exit_error;
1370 }
1371 }
1372
1373 qb_loop_poll_add (instance->poll_handle,
1375 instance->logpipes[0],
1376 POLLIN, instance, log_deliver_fn);
1377
1378 qb_loop_poll_add (instance->poll_handle,
1380 instance->knet_fd,
1381 POLLIN, instance, data_deliver_fn);
1382
1383 /*
1384 * Upper layer isn't ready to receive message because it hasn't
1385 * initialized yet. Add short timer to check the interfaces.
1386 */
1387 qb_loop_timer_add (instance->poll_handle,
1390 (void *)instance,
1391 timer_function_netif_check_timeout,
1392 &instance->timer_netif_check_timeout);
1393
1394 totemknet_start_merge_detect_timeout(instance);
1395
1396 /* Start listening for config changes */
1397 totemknet_add_config_notifications(instance);
1398
1399 /* Add stats keys to icmap */
1401
1402 knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
1403 *knet_context = instance;
1404
1405 return (0);
1406
1408 log_flush_messages(instance);
1409 free(instance);
1410 return (-1);
1411}
1412
1414{
1415 /* Need to have space for a message AND a struct mcast in case of encapsulated messages */
1416 return malloc(KNET_MAX_PACKET_SIZE + 512);
1417}
1418
1420{
1421 return free (ptr);
1422}
1423
1425 void *knet_context,
1426 int processor_count)
1427{
1428 return (0);
1429}
1430
1432{
1433 return (0);
1434}
1435
1437{
1438 return (0);
1439}
1440
1442 void *knet_context,
1443 const void *msg,
1444 unsigned int msg_len)
1445{
1446 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1447 int res = 0;
1448
1449 ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1450
1451 return (res);
1452}
1454 void *knet_context,
1455 const void *msg,
1456 unsigned int msg_len)
1457{
1458 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1459 int res = 0;
1460
1461 mcast_sendmsg (instance, msg, msg_len, 0);
1462
1463 return (res);
1464}
1465
1467 void *knet_context,
1468 const void *msg,
1469 unsigned int msg_len)
1470{
1471 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1472 int res = 0;
1473
1474 mcast_sendmsg (instance, msg, msg_len, 1);
1475
1476 return (res);
1477}
1478
1479
1481{
1482 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1483 int res = 0;
1484
1485 knet_log_printf(LOG_DEBUG, "totemknet: iface_check");
1486
1487 return (res);
1488}
1489
1491{
1492 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1493
1494 knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
1495}
1496
1498 void *knet_context,
1499 unsigned int nodeid)
1500{
1501 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1502 int res = 0;
1503
1504 instance->token_target.nodeid = nodeid;
1505
1506 instance->totemknet_target_set_completed (instance->context);
1507
1508 return (res);
1509}
1510
1512 void *knet_context)
1513{
1514 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1515 unsigned int res;
1517 struct msghdr msg_hdr;
1518 struct iovec iov_recv;
1519 struct pollfd ufd;
1520 int nfds;
1521 int msg_processed = 0;
1522
1523 iov_recv.iov_base = instance->iov_buffer;
1525
1526 memset(&msg_hdr, 0, sizeof(msg_hdr));
1527 msg_hdr.msg_name = &system_from;
1528 msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
1529 msg_hdr.msg_iov = &iov_recv;
1530 msg_hdr.msg_iovlen = 1;
1531
1532 do {
1533 ufd.fd = instance->knet_fd;
1534 ufd.events = POLLIN;
1535 nfds = poll (&ufd, 1, 0);
1536 if (nfds == 1 && ufd.revents & POLLIN) {
1538 if (res != -1) {
1539 msg_processed = 1;
1540 } else {
1541 msg_processed = -1;
1542 }
1543 }
1544 } while (nfds == 1);
1545
1546 return (msg_processed);
1547}
1548
1549int totemknet_iface_set (void *knet_context,
1550 const struct totem_ip_address *local_addr,
1551 unsigned short ip_port,
1552 unsigned int iface_no)
1553{
1554 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1555
1556 totemip_copy(&instance->my_ids[iface_no], local_addr);
1557
1558 knet_log_printf(LOG_INFO, "Configured link number %d: local addr: %s, port=%d", iface_no, totemip_print(local_addr), ip_port);
1559
1560 instance->ip_port[iface_no] = ip_port;
1561
1562 return 0;
1563}
1564
1565
1567 void *knet_context,
1568 const struct totem_ip_address *local,
1569 const struct totem_ip_address *member,
1570 int link_no)
1571{
1572 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1573 int err;
1574 int port = instance->ip_port[link_no];
1577 int addrlen;
1578 int i;
1579 int host_found = 0;
1581 size_t num_host_ids;
1582
1583 /* Only create 1 loopback link and use link 0 */
1584 if (member->nodeid == instance->our_nodeid) {
1585 if (!instance->loopback_link) {
1586 link_no = 0;
1587 instance->loopback_link = 1;
1588 } else {
1589 /* Already done */
1590 return 0;
1591 }
1592 }
1593
1594 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: " CS_PRI_NODE_ID " (%s), link=%d", member->nodeid, totemip_print(member), link_no);
1595 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: " CS_PRI_NODE_ID " (%s)", local->nodeid, totemip_print(local));
1596
1597
1598 /* Only add the host if it doesn't already exist in knet */
1600 if (err) {
1601 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list");
1602 return -1;
1603 }
1604 for (i=0; i<num_host_ids; i++) {
1605 if (host_ids[i] == member->nodeid) {
1606 host_found = 1;
1607 }
1608 }
1609
1610 if (!host_found) {
1611 err = knet_host_add(instance->knet_handle, member->nodeid);
1612 if (err != 0 && errno != EEXIST) {
1613 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
1614 return -1;
1615 }
1616 } else {
1617 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nodeid " CS_PRI_NODE_ID " already added", member->nodeid);
1618 }
1619
1620
1621 if (err == 0) {
1622 if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
1623 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
1624 return -1;
1625 }
1626 }
1627
1628 memset(&local_ss, 0, sizeof(local_ss));
1629 memset(&remote_ss, 0, sizeof(remote_ss));
1630 /* Casts to remove const */
1633
1634 if (member->nodeid == instance->our_nodeid) {
1635 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: loopback link is %d\n", link_no);
1636
1637 err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1640 }
1641 else {
1642 err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1645 }
1646 if (err) {
1647 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
1648 return -1;
1649 }
1650
1651 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
1653
1654 err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
1656 if (err) {
1657 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1658 }
1659
1660 /*
1661 * Ping timeouts may be 0 here for a newly added interface (on a reload),
1662 * so we leave this till later, it will get done in totemknet_refresh_config.
1663 * For the initial startup, we are all preset and ready to go from here.
1664 */
1665 if (instance->totem_config->interfaces[link_no].knet_ping_interval != 0) {
1670 if (err) {
1671 /* Flush logs before reporting this error so that the knet message prints before ours */
1672 int saved_errno = errno;
1673 log_flush_messages(instance);
1675 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_ping_timers for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1676
1677 icmap_set_string("config.reload_error_message", "Failed to set knet ping timers");
1678
1679 return -1;
1680 }
1683 if (err) {
1684 /* Flush logs before reporting this error so that the knet message prints before ours */
1685 int saved_errno = errno;
1686 log_flush_messages(instance);
1688 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_pong_count for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1689 icmap_set_string("config.reload_error_message", "Failed to set knet pong count");
1690 return -1;
1691 }
1692 }
1693
1694 err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
1695 if (err) {
1696 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1697 return -1;
1698 }
1699
1700 /* register stats */
1702 return (0);
1703}
1704
1706 void *knet_context,
1707 const struct totem_ip_address *token_target,
1708 int link_no)
1709{
1710 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1711 int res;
1713 size_t num_links;
1714
1715 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: " CS_PRI_NODE_ID ", link=%d", token_target->nodeid, link_no);
1716
1717 /* Don't remove the link with the loopback on it until we shut down */
1718 if (token_target->nodeid == instance->our_nodeid) {
1719 return 0;
1720 }
1721
1722 /* Tidy stats */
1724
1725 /* Remove the link first */
1727 if (res != 0) {
1728 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set enable(off) for nodeid " CS_PRI_NODE_ID ", link %d failed", token_target->nodeid, link_no);
1729 return res;
1730 }
1731
1733 if (res != 0) {
1734 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_clear_config for nodeid " CS_PRI_NODE_ID ", link %d failed", token_target->nodeid, link_no);
1735 return res;
1736 }
1737
1738 /* If this is the last link, then remove the node */
1741 if (res) {
1742 return (0); /* not really failure */
1743 }
1744
1745 if (num_links == 0) {
1747 }
1748 return res;
1749}
1750
1752 void *knet_context)
1753{
1754 return (0);
1755}
1756
1757
1758static int totemknet_configure_compression (
1759 struct totemknet_instance *instance,
1760 struct totem_config *totem_config)
1761{
1763 int res = 0;
1764
1765 assert(strlen(totem_config->knet_compression_model) < sizeof(compress_cfg.compress_model));
1767
1770
1772 if (res) {
1773 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_handle_compress failed");
1774 }
1775 return res;
1776}
1777
1779 void *knet_context,
1780 struct totem_config *totem_config)
1781{
1782 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1783 int res = 0;
1784
1785 (void)totemknet_configure_compression(instance, totem_config);
1786
1787#ifdef HAVE_LIBNOZZLE
1788 /* Set up nozzle device(s). Return code is ignored, because inability
1789 * configure nozzle is not fatal problem, errors are logged and
1790 * there is not much else we can do */
1791 (void)setup_nozzle(instance);
1792#endif
1793
1795 /* Flip crypto_index */
1797 res = totemknet_set_knet_crypto(instance);
1798 if (res == 0) {
1799 knet_log_printf(LOG_INFO, "kronosnet crypto reconfigured on index %d: %s/%s/%s", totem_config->crypto_index,
1803 } else {
1804 icmap_set_string("config.reload_error_message", "Failed to set knet crypto");
1805 }
1806 }
1807 return (res);
1808}
1809
1810
1812 void *knet_context,
1813 struct totem_config *totem_config,
1815{
1816#ifdef HAVE_KNET_CRYPTO_RECONF
1817 int res;
1818 int config_to_use;
1819 int config_to_clear;
1821 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1822
1823 knet_log_printf(LOGSYS_LEVEL_DEBUG, "totemknet_crypto_reconfigure_phase %d, index=%d\n", phase, totem_config->crypto_index);
1824
1825 switch (phase) {
1828 if (!totemknet_is_crypto_enabled(instance)) {
1829 config_to_use = 0; /* we are clearing it */
1830 }
1831
1832 /* Enable the new config on this node */
1834 if (res == -1) {
1835 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_use_config %d failed: %s", config_to_use, strerror(errno));
1836 }
1837 break;
1838
1840 /*
1841 * All nodes should now have the new config. clear the old one out
1842 * OR disable crypto entirely if that's what the new config insists on.
1843 */
1845 knet_log_printf(LOGSYS_LEVEL_DEBUG, "Clearing old knet crypto config %d\n", config_to_clear);
1846
1847 strcpy(crypto_cfg.crypto_model, "none");
1848 strcpy(crypto_cfg.crypto_cipher_type, "none");
1849 strcpy(crypto_cfg.crypto_hash_type, "none");
1851 if (res == -1) {
1852 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config to clear index %d failed: %s", config_to_clear, strerror(errno));
1853 }
1854 if (res == -2) {
1855 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config to clear index %d failed: -2", config_to_clear);
1856 }
1857
1858 /* If crypto is enabled then disable all cleartext reception */
1859 if (totemknet_is_crypto_enabled(instance)) {
1861 if (res) {
1862 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(DISALLOW) failed %s", strerror(errno));
1863 }
1864 }
1865 }
1866#endif
1867 return 0;
1868}
1869
1877
1878/* For the stats module */
1881 struct knet_link_status *status)
1882{
1883 int res;
1884 int ret = CS_OK;
1885
1886 /* We are probably not using knet */
1887 if (!global_instance) {
1888 return CS_ERR_NOT_EXIST;
1889 }
1890
1891 if (link_no >= INTERFACE_MAX) {
1892 return CS_ERR_NOT_EXIST; /* Invalid link number */
1893 }
1894
1896 if (res) {
1897 switch (errno) {
1898 case EINVAL:
1900 break;
1901 case EBUSY:
1902 ret = CS_ERR_BUSY;
1903 break;
1904 case EDEADLK:
1906 break;
1907 default:
1909 break;
1910 }
1911 }
1912
1913 return (ret);
1914}
1915
1917 struct knet_handle_stats *stats)
1918{
1919 int res;
1920
1921 /* We are probably not using knet */
1922 if (!global_instance) {
1923 return CS_ERR_NOT_EXIST;
1924 }
1925
1927 if (res != 0) {
1928 return (qb_to_cs_error(-errno));
1929 }
1930
1931 return CS_OK;
1932}
1933
1934static void timer_function_merge_detect_timeout (
1935 void *data)
1936{
1937 struct totemknet_instance *instance = (struct totemknet_instance *)data;
1938
1939 if (instance->merge_detect_messages_sent_before_timeout == 0) {
1940 instance->send_merge_detect_message = 1;
1941 }
1942
1944
1945 totemknet_start_merge_detect_timeout(instance);
1946}
1947
1948static void totemknet_start_merge_detect_timeout(
1949 void *knet_context)
1950{
1951 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1952
1956 (void *)instance,
1957 timer_function_merge_detect_timeout,
1958 &instance->timer_merge_detect_timeout);
1959
1960}
1961
1962static void totemknet_stop_merge_detect_timeout(
1963 void *knet_context)
1964{
1965 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1966
1968 instance->timer_merge_detect_timeout);
1969}
1970
1971static void log_flush_messages (void *knet_context)
1972{
1973 struct pollfd pfd;
1974 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1975 int cont;
1976
1977 cont = 1;
1978
1979 while (cont) {
1980 pfd.fd = instance->logpipes[0];
1981 pfd.events = POLLIN;
1982 pfd.revents = 0;
1983
1984 if ((poll(&pfd, 1, 0) > 0) &&
1985 (pfd.revents & POLLIN) &&
1986 (log_deliver_fn(instance->logpipes[0], POLLIN, instance) == 0)) {
1987 cont = 1;
1988 } else {
1989 cont = 0;
1990 }
1991 }
1992}
1993
1994
1995#ifdef HAVE_LIBNOZZLE
1996#define NOZZLE_NAME "nozzle.name"
1997#define NOZZLE_IPADDR "nozzle.ipaddr"
1998#define NOZZLE_PREFIX "nozzle.ipprefix"
1999#define NOZZLE_MACADDR "nozzle.macaddr"
2000
2001#define NOZZLE_CHANNEL 1
2002
2003
2004static char *get_nozzle_script_dir(void *knet_context)
2005{
2006 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2007 char filename[PATH_MAX + FILENAME_MAX + 1];
2008 static char updown_dirname[PATH_MAX + FILENAME_MAX + 1];
2009 int res;
2010 const char *dirname_res;
2011
2012 /*
2013 * Build script directory based on corosync.conf file location
2014 */
2015 res = snprintf(filename, sizeof(filename), "%s",
2017 if (res >= sizeof(filename)) {
2018 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
2019 return NULL;
2020 }
2021
2023
2024 res = snprintf(updown_dirname, sizeof(updown_dirname), "%s/%s",
2025 dirname_res, "updown.d");
2026 if (res >= sizeof(updown_dirname)) {
2027 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
2028 return NULL;
2029 }
2030 return updown_dirname;
2031}
2032
2033/*
2034 * Deliberately doesn't return the status as caller doesn't care.
2035 * The result will be logged though
2036 */
2037static void run_nozzle_script(struct totemknet_instance *instance, int type, const char *typename)
2038{
2039 int res;
2040 char *exec_string;
2041
2042 res = nozzle_run_updown(instance->nozzle_handle, type, &exec_string);
2043 if (res == -1 && errno != ENOENT) {
2044 knet_log_printf (LOGSYS_LEVEL_INFO, "exec nozzle %s script failed: %s", typename, strerror(errno));
2045 } else if (res == -2) {
2046 knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle %s script failed", typename);
2048 }
2049}
2050
2051/*
2052 * Reparse IP address to add in our node ID
2053 * IPv6 addresses must end in '::'
2054 * IPv4 addresses must just be valid
2055 * '/xx' lengths are optional for IPv6, mandatory for IPv4
2056 *
2057 * Returns the modified IP address as a string to pass into libnozzle
2058 */
2059static int reparse_nozzle_ip_address(struct totemknet_instance *instance,
2060 const char *input_addr,
2061 const char *prefix, int nodeid,
2062 char *output_addr, size_t output_len)
2063{
2064 const char *coloncolon;
2065 int bits;
2066 int max_prefix = 64;
2070 struct in_addr *addr;
2072
2073 coloncolon = strstr(input_addr, "::");
2074 if (!coloncolon) {
2075 max_prefix = 30;
2076 }
2077
2078 bits = atoi(prefix);
2080 knet_log_printf(LOGSYS_LEVEL_ERROR, "nozzle IP address prefix must be >= 8 and <= %d (got %d)", max_prefix, bits);
2081 return -1;
2082 }
2083
2084 /* IPv6 is easy */
2085 if (coloncolon) {
2088 return 0;
2089 }
2090
2091 /* For IPv4 we need to parse the address into binary, mask off the required bits,
2092 * add in the masked_nodeid and 'print' it out again
2093 */
2094 nodeid_mask = UINT32_MAX & ((1<<(32 - bits)) - 1);
2097
2099 knet_log_printf(LOGSYS_LEVEL_ERROR, "Failed to parse IPv4 nozzle IP address");
2100 return -1;
2101 }
2102 addr = (struct in_addr *)&totemip.addr;
2103 addr->s_addr &= htonl(addr_mask);
2104 addr->s_addr |= htonl(masked_nodeid);
2105
2107 return 0;
2108}
2109
2110static int create_nozzle_device(void *knet_context, const char *name,
2111 const char *ipaddr, const char *prefix,
2112 const char *macaddr)
2113{
2114 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2115 char device_name[IFNAMSIZ+1];
2116 size_t size = IFNAMSIZ;
2119 int nozzle_fd;
2120 int res;
2121 char *updown_dir;
2123 char mac[19];
2124
2125 memset(device_name, 0, size);
2126 memset(&mac, 0, sizeof(mac));
2127 strncpy(device_name, name, size);
2128
2130 knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle script dir is %s", updown_dir);
2131
2133 if (!nozzle_dev) {
2134 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to init nozzle device %s: %s", device_name, strerror(errno));
2135 return -1;
2136 }
2137 instance->nozzle_handle = nozzle_dev;
2138
2139 if (nozzle_set_mac(nozzle_dev, macaddr) < 0) {
2140 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle MAC to %s: %s", mac, strerror(errno));
2141 goto out_clean;
2142 }
2143
2144 if (reparse_nozzle_ip_address(instance, ipaddr, prefix, instance->our_nodeid, parsed_ipaddr, sizeof(parsed_ipaddr))) {
2145 /* Prints its own errors */
2146 goto out_clean;
2147 }
2148 knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle IP address is %s / %d", parsed_ipaddr, atoi(prefix));
2149 if (nozzle_add_ip(nozzle_dev, parsed_ipaddr, prefix) < 0) {
2150 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle IP addr to %s/%s: %s", parsed_ipaddr, prefix, strerror(errno));
2151 goto out_clean;
2152 }
2153
2155 knet_log_printf (LOGSYS_LEVEL_INFO, "Opened '%s' on fd %d", device_name, nozzle_fd);
2156
2157#ifdef KNET_DATAFD_FLAG_RX_RETURN_INFO
2159#else
2161#endif
2162 if (res != 0) {
2163 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add nozzle FD to knet: %s", strerror(errno));
2164 goto out_clean;
2165 }
2166
2167 run_nozzle_script(instance, NOZZLE_PREUP, "pre-up");
2168
2170 if (res != 0) {
2171 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to set nozzle interface UP: %s", strerror(errno));
2172 goto out_clean;
2173 }
2174 run_nozzle_script(instance, NOZZLE_UP, "up");
2175
2176 return 0;
2177
2178out_clean:
2180 return -1;
2181}
2182
2183static int remove_nozzle_device(void *knet_context)
2184{
2185 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2186 int res;
2187 int datafd;
2188
2190 if (res != 0) {
2191 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't find datafd for channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
2192 return -1;
2193 }
2194
2196 if (res != 0) {
2197 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't remove datafd for nozzle channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
2198 return -1;
2199 }
2200
2201 run_nozzle_script(instance, NOZZLE_DOWN, "pre-down");
2202 res = nozzle_set_down(instance->nozzle_handle);
2203 if (res != 0) {
2204 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't set nozzle device down: %s", strerror(errno));
2205 return -1;
2206 }
2207 run_nozzle_script(instance, NOZZLE_POSTDOWN, "post-down");
2208
2209 res = nozzle_close(instance->nozzle_handle);
2210 if (res != 0) {
2211 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't close nozzle device: %s", strerror(errno));
2212 return -1;
2213 }
2214 knet_log_printf (LOGSYS_LEVEL_INFO, "Removed nozzle device");
2215 return 0;
2216}
2217
2218static void free_nozzle(struct totemknet_instance *instance)
2219{
2220 free(instance->nozzle_name);
2221 free(instance->nozzle_ipaddr);
2222 free(instance->nozzle_prefix);
2223 free(instance->nozzle_macaddr);
2224
2225 instance->nozzle_name = instance->nozzle_ipaddr = instance->nozzle_prefix =
2226 instance->nozzle_macaddr = NULL;
2227}
2228
2229static int setup_nozzle(void *knet_context)
2230{
2231 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2232 char *ipaddr_str = NULL;
2233 char *name_str = NULL;
2234 char *prefix_str = NULL;
2235 char *macaddr_str = NULL;
2236 char mac[32];
2237 int name_res;
2238 int macaddr_res;
2239 int res = -1;
2240
2241 /*
2242 * Return value ignored on purpose. icmap_get_string changes
2243 * ipaddr_str/prefix_str only on success.
2244 */
2249
2250 /* Is is being removed? */
2251 if (name_res == CS_ERR_NOT_EXIST && instance->nozzle_handle) {
2252 remove_nozzle_device(instance);
2253 free_nozzle(instance);
2254 goto out_free;
2255 }
2256
2257 if (!name_str) {
2258 /* no nozzle */
2259 goto out_free;
2260 }
2261
2262 if (!ipaddr_str) {
2263 knet_log_printf (LOGSYS_LEVEL_ERROR, "No IP address supplied for Nozzle device");
2264 goto out_free;
2265 }
2266
2267 if (!prefix_str) {
2268 knet_log_printf (LOGSYS_LEVEL_ERROR, "No prefix supplied for Nozzle IP address");
2269 goto out_free;
2270 }
2271
2272 if (macaddr_str && strlen(macaddr_str) != 17) {
2273 knet_log_printf (LOGSYS_LEVEL_ERROR, "macaddr for nozzle device is not in the correct format '%s'", macaddr_str);
2274 goto out_free;
2275 }
2276 if (!macaddr_str) {
2277 macaddr_str = (char*)"54:54:01:00:00:00";
2278 }
2279
2280 if (instance->nozzle_name &&
2281 (strcmp(name_str, instance->nozzle_name) == 0) &&
2282 (strcmp(ipaddr_str, instance->nozzle_ipaddr) == 0) &&
2283 (strcmp(prefix_str, instance->nozzle_prefix) == 0) &&
2284 (instance->nozzle_macaddr == NULL ||
2285 strcmp(macaddr_str, instance->nozzle_macaddr) == 0)) {
2286 /* Nothing has changed */
2287 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Nozzle device info not changed");
2288 goto out_free;
2289 }
2290
2291 /* Add nodeid into MAC address */
2292 memcpy(mac, macaddr_str, 12);
2293 snprintf(mac+12, sizeof(mac) - 13, "%02x:%02x",
2294 instance->our_nodeid >> 8,
2295 instance->our_nodeid & 0xFF);
2296 knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle MAC address is %s", mac);
2297
2298 if (name_res == CS_OK && name_str) {
2299 /* Reconfigure */
2300 if (instance->nozzle_name) {
2301 remove_nozzle_device(instance);
2302 free_nozzle(instance);
2303 }
2304
2306 mac);
2307
2308 instance->nozzle_name = strdup(name_str);
2309 instance->nozzle_ipaddr = strdup(ipaddr_str);
2310 instance->nozzle_prefix = strdup(prefix_str);
2311 instance->nozzle_macaddr = strdup(macaddr_str);
2312 if (!instance->nozzle_name || !instance->nozzle_ipaddr ||
2313 !instance->nozzle_prefix) {
2314 knet_log_printf (LOGSYS_LEVEL_ERROR, "strdup failed in nozzle allocation");
2315 /*
2316 * This 'free' will cause a complete reconfigure of the device next time we reload
2317 * but will also let the the current device keep working until then.
2318 * remove_nozzle() only needs the, statically-allocated, nozzle_handle
2319 */
2320 free_nozzle(instance);
2321 }
2322 }
2323
2324out_free:
2325 free(name_str);
2328 if (macaddr_res == CS_OK) {
2330 }
2331
2332 return res;
2333}
2334#endif // HAVE_LIBNOZZLE
#define INTERFACE_MAX
Definition coroapi.h:88
unsigned int nodeid
the ID of the node whose info needs updating
Definition coroapi.h:0
unsigned char addr[TOTEMIP_ADDRLEN]
Definition coroapi.h:2
#define CS_PRI_NODE_ID
Definition corotypes.h:59
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
cs_error_t
The cs_error_t enum.
Definition corotypes.h:98
@ CS_ERR_BUSY
Definition corotypes.h:108
@ CS_ERR_TRY_AGAIN
Definition corotypes.h:104
@ CS_OK
Definition corotypes.h:99
@ CS_ERR_INVALID_PARAM
Definition corotypes.h:105
@ CS_ERR_LIBRARY
Definition corotypes.h:100
@ CS_ERR_NOT_EXIST
Definition corotypes.h:110
#define corosync_exit_error(err)
Definition exec/util.h:72
@ COROSYNC_DONE_MAINCONFIGREAD
Definition exec/util.h:51
uint32_t value
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition icmap.c:872
#define ICMAP_TRACK_MODIFY
Definition icmap.h:78
#define ICMAP_TRACK_DELETE
Definition icmap.h:77
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
Definition icmap.c:1163
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition icmap.c:631
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
Definition icmap.h:85
#define ICMAP_TRACK_ADD
Definition icmap.h:76
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition icmap.c:860
#define LOGSYS_LEVEL_ERROR
Definition logsys.h:72
#define LEAVE
Definition logsys.h:334
#define log_printf(level, format, args...)
Definition logsys.h:332
#define LOGSYS_LEVEL_INFO
Definition logsys.h:75
#define LOGSYS_LEVEL_CRIT
Definition logsys.h:71
int logsys_config_debug_get(const char *subsys)
Return the debug flag for this subsys.
Definition logsys.c:780
#define LOGSYS_DEBUG_OFF
Definition logsys.h:92
#define LOGSYS_DEBUG_TRACE
Definition logsys.h:94
#define LOGSYS_DEBUG_ON
Definition logsys.h:93
#define LOGSYS_LEVEL_WARNING
Definition logsys.h:73
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
Definition logsys.c:427
#define LOGSYS_LEVEL_DEBUG
Definition logsys.h:76
#define LOGSYS_LEVEL_TRACE
Definition logsys.h:77
#define ENTER
Definition logsys.h:333
const char * corosync_get_config_file(void)
Definition main.c:212
void * user_data
Definition sam.c:127
Structure passed as new_value and old_value in change callback.
Definition icmap.h:91
char crypto_model[CONFIG_STRING_LEN_MAX]
Definition totem.h:230
unsigned int private_key_len
Definition totem.h:183
unsigned int knet_mtu
Definition totem.h:176
unsigned int node_id
Definition totem.h:173
uint32_t knet_compression_threshold
Definition totem.h:242
struct totem_logging_configuration totem_logging_configuration
Definition totem.h:214
struct totem_interface * interfaces
Definition totem.h:171
int crypto_changed
Definition totem.h:238
unsigned int merge_timeout
Definition totem.h:204
unsigned char ip_dscp
Definition totem.h:256
int knet_compression_level
Definition totem.h:244
unsigned int net_mtu
Definition totem.h:216
char knet_compression_model[CONFIG_STRING_LEN_MAX]
Definition totem.h:240
unsigned int block_unlisted_ips
Definition totem.h:252
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
Definition totem.h:181
int crypto_index
Definition totem.h:236
unsigned int knet_pmtud_interval
Definition totem.h:175
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
Definition totem.h:232
char link_mode[TOTEM_LINK_MODE_BYTES]
Definition totem.h:212
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
Definition totem.h:234
int knet_ping_timeout
Definition totem.h:93
int knet_link_priority
Definition totem.h:91
struct totem_ip_address boundto
Definition totem.h:84
uint16_t ip_port
Definition totem.h:87
int knet_ping_interval
Definition totem.h:92
uint8_t configured
Definition totem.h:89
int knet_ping_precision
Definition totem.h:94
int knet_pong_count
Definition totem.h:95
int knet_transport
Definition totem.h:96
struct totem_ip_address bindnet
Definition totem.h:83
The totem_ip_address struct.
Definition coroapi.h:111
unsigned int nodeid
Definition coroapi.h:112
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:101
unsigned int target_nodeid
Definition totem.h:132
void(* totemknet_target_set_completed)(void *context)
Definition totemknet.c:126
pthread_mutex_t log_mutex
Definition totemknet.c:183
void(* totemknet_mtu_changed)(void *context, int net_mtu)
Definition totemknet.c:122
struct crypto_instance * crypto_inst
Definition totemknet.c:99
struct totem_config * totem_config
Definition totemknet.c:168
qb_loop_timer_handle timer_netif_check_timeout
Definition totemknet.c:172
char * link_status[INTERFACE_MAX]
Definition totemknet.c:158
void(* totemknet_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
Definition totemknet.c:145
knet_handle_t knet_handle
Definition totemknet.c:105
uint16_t ip_port[INTERFACE_MAX]
Definition totemknet.c:162
int(* totemknet_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no)
Definition totemknet.c:117
int totemknet_log_level_debug
Definition totemknet.c:139
struct knet_handle_crypto_cfg last_good_crypto_cfg
Definition totemknet.c:101
struct totem_ip_address token_target
Definition totemknet.c:170
qb_loop_timer_handle timer_merge_detect_timeout
Definition totemknet.c:174
void(*) void knet_context)
Definition totemknet.c:154
int totemknet_log_level_warning
Definition totemknet.c:135
struct totem_ip_address my_ids[INTERFACE_MAX]
Definition totemknet.c:160
int(* totemknet_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
Definition totemknet.c:111
char iov_buffer[KNET_IOV_LEN_MAX]
Definition totemknet.c:156
unsigned int merge_detect_messages_sent_before_timeout
Definition totemknet.c:178
int send_merge_detect_message
Definition totemknet.c:176
int totemknet_log_level_error
Definition totemknet.c:133
int totemknet_log_level_security
Definition totemknet.c:131
qb_loop_t * poll_handle
Definition totemknet.c:103
int totemknet_log_level_notice
Definition totemknet.c:137
const void * msg
Definition totemknet.c:197
unsigned int msg_len
Definition totemknet.c:198
struct totemknet_instance * instance
Definition totemknet.c:199
typedef __attribute__
cfg_message_crypto_reconfig_phase_t
Definition totem.h:160
@ CRYPTO_RECONFIG_PHASE_CLEANUP
Definition totem.h:162
@ CRYPTO_RECONFIG_PHASE_ACTIVATE
Definition totem.h:161
char type
Definition totem.h:2
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
Definition totemip.c:306
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition totemip.c:123
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
Definition totemip.c:264
const char * totemip_print(const struct totem_ip_address *addr)
Definition totemip.c:256
int totemknet_mcast_flush_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition totemknet.c:1453
int totemknet_iface_set(void *knet_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
Definition totemknet.c:1549
int totemknet_finalize(void *knet_context)
Definition totemknet.c:664
int totemknet_recv_flush(void *knet_context)
Definition totemknet.c:1431
int totemknet_member_list_rebind_ip(void *knet_context)
Definition totemknet.c:1751
void * totemknet_buffer_alloc(void)
Definition totemknet.c:1413
int totemknet_processor_count_set(void *knet_context, int processor_count)
Definition totemknet.c:1424
int totemknet_mcast_noflush_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition totemknet.c:1466
struct totemknet_instance * global_instance
Definition totemknet.c:194
void totemknet_buffer_release(void *ptr)
Definition totemknet.c:1419
int totemknet_initialize(qb_loop_t *poll_handle, void **knet_context, struct totem_config *totem_config, totemsrp_stats_t *stats, void *context, int(*deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from), int(*iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no), void(*mtu_changed)(void *context, int net_mtu), void(*target_set_completed)(void *context))
Definition totemknet.c:1139
int totemknet_ifaces_get(void *knet_context, char ***status, unsigned int *iface_count)
Definition totemknet.c:569
int totemknet_member_add(void *knet_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int link_no)
Definition totemknet.c:1566
int totemknet_crypto_set(void *knet_context, const char *cipher_type, const char *hash_type)
Definition totemknet.c:394
int totemknet_member_remove(void *knet_context, const struct totem_ip_address *token_target, int link_no)
Definition totemknet.c:1705
int totemknet_token_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition totemknet.c:1441
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition totemknet.c:90
int totemknet_link_get_status(knet_node_id_t node, uint8_t link_no, struct knet_link_status *status)
Definition totemknet.c:1879
#define OWN_INDEX_NONE
Definition totemknet.c:488
int totemknet_nodestatus_get(void *knet_context, unsigned int nodeid, struct totem_node_status *node_status)
Definition totemknet.c:491
int totemknet_handle_get_stats(struct knet_handle_stats *stats)
Definition totemknet.c:1916
#define MSG_NOSIGNAL
Definition totemknet.c:82
void totemknet_stats_clear(void *knet_context)
Definition totemknet.c:1870
int totemknet_send_flush(void *knet_context)
Definition totemknet.c:1436
void totemknet_net_mtu_adjust(void *knet_context, struct totem_config *totem_config)
Definition totemknet.c:1490
#define KNET_IOV_LEN_MAX
Definition totemknet.c:95
#define knet_log_printf(level, format, args...)
Definition totemknet.c:240
int totemknet_token_target_set(void *knet_context, unsigned int nodeid)
Definition totemknet.c:1497
#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...)
Definition totemknet.c:256
void totemknet_configure_log_level(void)
Definition totemknet.c:890
int totemknet_reconfigure(void *knet_context, struct totem_config *totem_config)
Definition totemknet.c:1778
int totemknet_crypto_reconfigure_phase(void *knet_context, struct totem_config *totem_config, cfg_message_crypto_reconfig_phase_t phase)
Definition totemknet.c:1811
#define libknet_log_printf(level, format, args...)
Definition totemknet.c:248
int totemknet_recv_mcast_empty(void *knet_context)
Definition totemknet.c:1511
int totemknet_iface_check(void *knet_context)
Definition totemknet.c:1480
struct totem_message_header header
Definition totemsrp.c:0
struct srp_addr system_from
Definition totemsrp.c:1
void stats_knet_add_handle(void)
Definition stats.c:753
void stats_knet_del_member(knet_node_id_t nodeid, uint8_t link)
Definition stats.c:740
void stats_knet_add_member(knet_node_id_t nodeid, uint8_t link)
Definition stats.c:730