corosync 3.1.8
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 <net/ethernet.h>
48#include <arpa/inet.h>
49#include <unistd.h>
50#include <fcntl.h>
51#include <stdlib.h>
52#include <stdio.h>
53#include <errno.h>
54#include <pthread.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 <qb/qbdefs.h>
63#include <qb/qbloop.h>
64#ifdef HAVE_LIBNOZZLE
65#include <libgen.h>
66#include <libnozzle.h>
67#endif
68
69#include <corosync/sq.h>
70#include <corosync/swab.h>
71#include <corosync/logsys.h>
72#include <corosync/icmap.h>
74#include "totemknet.h"
75
76#include "main.h"
77#include "util.h"
78
79#include <libknet.h>
81
82#ifndef MSG_NOSIGNAL
83#define MSG_NOSIGNAL 0
84#endif
85
86#ifdef HAVE_LIBNOZZLE
87static int setup_nozzle(void *knet_context);
88#endif
89
90/* Should match that used by cfg */
91#define CFG_INTERFACE_STATUS_MAX_LEN 512
92
95
97
99
101
102 void *context;
103
105 void *context,
106 const void *msg,
107 unsigned int msg_len,
108 const struct sockaddr_storage *system_from);
109
111 void *context,
112 const struct totem_ip_address *iface_address,
113 unsigned int link_no);
114
116 void *context,
117 int net_mtu);
118
120
121 /*
122 * Function and data used to log messages
123 */
125
127
129
131
133
135
137
139 int level,
140 int subsys,
141 const char *function,
142 const char *file,
143 int line,
144 const char *format,
145 ...)__attribute__((format(printf, 6, 7)));
146
148
150
152
154
156
158
160
162
164
166
168
170
172
173 int logpipes[2];
175
177#ifdef HAVE_LIBNOZZLE
178 char *nozzle_name;
179 char *nozzle_ipaddr;
180 char *nozzle_prefix;
181 char *nozzle_macaddr;
183#endif
184};
185
186/* Awkward. But needed to get stats from knet */
188
189struct work_item {
190 const void *msg;
191 unsigned int msg_len;
193};
194
196 void *knet_context);
197
198
199static int totemknet_configure_compression (
200 struct totemknet_instance *instance,
201 struct totem_config *totem_config);
202
203static void totemknet_start_merge_detect_timeout(
204 void *knet_context);
205
206static void totemknet_stop_merge_detect_timeout(
207 void *knet_context);
208
209static void log_flush_messages (
210 void *knet_context);
211
212static void totemknet_instance_initialize (struct totemknet_instance *instance)
213{
214 int res;
215
216 memset (instance, 0, sizeof (struct totemknet_instance));
217 res = pthread_mutex_init(&instance->log_mutex, NULL);
218 /*
219 * There is not too much else what can be done.
220 */
221 assert(res == 0);
222}
223
224#define knet_log_printf_lock(level, subsys, function, file, line, format, args...) \
225do { \
226 (void)pthread_mutex_lock(&instance->log_mutex); \
227 instance->totemknet_log_printf ( \
228 level, subsys, function, file, line, \
229 (const char *)format, ##args); \
230 (void)pthread_mutex_unlock(&instance->log_mutex); \
231} while (0);
232
233#define knet_log_printf(level, format, args...) \
234do { \
235 knet_log_printf_lock ( \
236 level, instance->totemknet_subsys_id, \
237 __FUNCTION__, __FILE__, __LINE__, \
238 (const char *)format, ##args); \
239} while (0);
240
241#define libknet_log_printf(level, format, args...) \
242do { \
243 knet_log_printf_lock ( \
244 level, instance->knet_subsys_id, \
245 __FUNCTION__, "libknet.h", __LINE__, \
246 (const char *)format, ##args); \
247} while (0);
248
249#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
250do { \
251 char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
252 const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
253 instance->totemknet_log_printf ( \
254 level, instance->totemknet_subsys_id, \
255 __FUNCTION__, __FILE__, __LINE__, \
256 fmt ": %s (%d)", ##args, _error_ptr, err_num); \
257 } while(0)
258
259
260#ifdef HAVE_LIBNOZZLE
261static inline int is_ether_addr_multicast(const uint8_t *addr)
262{
263 return (addr[0] & 0x01);
264}
265static inline int is_ether_addr_zero(const uint8_t *addr)
266{
267 return (!addr[0] && !addr[1] && !addr[2] && !addr[3] && !addr[4] && !addr[5]);
268}
269
270static int ether_host_filter_fn(void *private_data,
271 const unsigned char *outdata,
278 size_t *dst_host_ids_entries)
279{
280 struct ether_header *eth_h = (struct ether_header *)outdata;
281 uint8_t *dst_mac = (uint8_t *)eth_h->ether_dhost;
283
285 return -1;
286
288 return 1;
289 }
290
291 memmove(&dst_host_id, &dst_mac[4], 2);
292
295
296 return 0;
297}
298#endif
299
300static int dst_host_filter_callback_fn(void *private_data,
301 const unsigned char *outdata,
308 size_t *dst_host_ids_entries)
309{
311 int res;
312
313#ifdef HAVE_LIBNOZZLE
314 if (*channel != 0) {
317 tx_rx,
319 channel,
322 }
323#endif
324 if (header->target_nodeid) {
327 res = 0; /* unicast message */
328 }
329 else {
331 res = 1; /* multicast message */
332 }
333 return res;
334}
335
336static void socket_error_callback_fn(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)
337{
338 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
339
340 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet socket ERROR notification called: txrx=%d, error=%d, errorno=%d", tx_rx, error, errorno);
341 if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
343 }
344}
345
346static void host_change_callback_fn(void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
347{
348 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
349
350 // TODO: what? if anything.
351 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet host change callback. nodeid: " CS_PRI_NODE_ID " reachable: %d", host_id, reachable);
352}
353
354static void pmtu_change_callback_fn(void *private_data, unsigned int data_mtu)
355{
356 struct totemknet_instance *instance = (struct totemknet_instance *)private_data;
357 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Knet pMTU change: %d", data_mtu);
358
359 /* We don't need to tell corosync the actual knet MTU */
360// instance->totemknet_mtu_changed(instance->context, data_mtu);
361}
362
364 void *knet_context,
365 const char *cipher_type,
366 const char *hash_type)
367{
368 return (0);
369}
370
371
372static inline void ucast_sendmsg (
373 struct totemknet_instance *instance,
375 const void *msg,
376 unsigned int msg_len)
377{
378 int res = 0;
379 struct totem_message_header *header = (struct totem_message_header *)msg;
380 struct msghdr msg_ucast;
381 struct iovec iovec;
382
383 header->target_nodeid = system_to->nodeid;
384
385 iovec.iov_base = (void *)msg;
386 iovec.iov_len = msg_len;
387
388 /*
389 * Build unicast message
390 */
391 memset(&msg_ucast, 0, sizeof(msg_ucast));
392 msg_ucast.msg_iov = (void *)&iovec;
393 msg_ucast.msg_iovlen = 1;
394#ifdef HAVE_MSGHDR_CONTROL
395 msg_ucast.msg_control = 0;
396#endif
397#ifdef HAVE_MSGHDR_CONTROLLEN
398 msg_ucast.msg_controllen = 0;
399#endif
400#ifdef HAVE_MSGHDR_FLAGS
401 msg_ucast.msg_flags = 0;
402#endif
403#ifdef HAVE_MSGHDR_ACCRIGHTS
404 msg_ucast.msg_accrights = NULL;
405#endif
406#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
407 msg_ucast.msg_accrightslen = 0;
408#endif
409
410 /*
411 * Transmit unicast message
412 * An error here is recovered by totemsrp
413 */
414
415 res = sendmsg (instance->knet_fd, &msg_ucast, MSG_NOSIGNAL);
416 if (res < 0) {
418 "sendmsg(ucast) failed (non-critical)");
419 }
420}
421
422static inline void mcast_sendmsg (
423 struct totemknet_instance *instance,
424 const void *msg,
425 unsigned int msg_len,
426 int only_active)
427{
428 int res;
429 struct totem_message_header *header = (struct totem_message_header *)msg;
430 struct msghdr msg_mcast;
431 struct iovec iovec;
432
433 iovec.iov_base = (void *)msg;
434 iovec.iov_len = msg_len;
435
437
438 /*
439 * Build multicast message
440 */
441 memset(&msg_mcast, 0, sizeof(msg_mcast));
442 msg_mcast.msg_iov = (void *)&iovec;
443 msg_mcast.msg_iovlen = 1;
444#ifdef HAVE_MSGHDR_CONTROL
445 msg_mcast.msg_control = 0;
446#endif
447#ifdef HAVE_MSGHDR_CONTROLLEN
448 msg_mcast.msg_controllen = 0;
449#endif
450#ifdef HAVE_MSGHDR_FLAGS
451 msg_mcast.msg_flags = 0;
452#endif
453#ifdef HAVE_MSGHDR_ACCRIGHTS
454 msg_mcast.msg_accrights = NULL;
455#endif
456#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
457 msg_mcast.msg_accrightslen = 0;
458#endif
459
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;
797
798 iov_recv.iov_base = instance->iov_buffer;
800
801 msg_hdr.msg_name = &system_from;
802 msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
803 msg_hdr.msg_iov = &iov_recv;
804 msg_hdr.msg_iovlen = 1;
805#ifdef HAVE_MSGHDR_CONTROL
806 msg_hdr.msg_control = 0;
807#endif
808#ifdef HAVE_MSGHDR_CONTROLLEN
809 msg_hdr.msg_controllen = 0;
810#endif
811#ifdef HAVE_MSGHDR_FLAGS
812 msg_hdr.msg_flags = 0;
813#endif
814#ifdef HAVE_MSGHDR_ACCRIGHTS
815 msg_hdr.msg_accrights = NULL;
816#endif
817#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
818 msg_hdr.msg_accrightslen = 0;
819#endif
820
821 msg_len = recvmsg (fd, &msg_hdr, MSG_NOSIGNAL | MSG_DONTWAIT);
822 if (msg_len <= 0) {
823 return (0);
824 }
825
827
828#ifdef HAVE_MSGHDR_FLAGS
829 if (msg_hdr.msg_flags & MSG_TRUNC) {
831 }
832#else
833 /*
834 * We don't have MSGHDR_FLAGS, but we can (hopefully) safely make assumption that
835 * if bytes_received == KNET_MAX_PACKET_SIZE then packet is truncated
836 */
839 }
840#endif
841
842 if (truncated_packet) {
844 "Received too big message. This may be because something bad is happening"
845 "on the network (attack?), or you tried join more nodes than corosync is"
846 "compiled with (%u) or bug in the code (bad estimation of "
847 "the KNET_MAX_PACKET_SIZE). Dropping packet.", PROCESSOR_COUNT_MAX);
848 return (0);
849 }
850
851 /*
852 * Handle incoming message
853 */
854 instance->totemknet_deliver_fn (
855 instance->context,
856 instance->iov_buffer,
857 msg_len,
858 &system_from);
859
860 return (0);
861}
862
863static void timer_function_netif_check_timeout (
864 void *data)
865{
866 struct totemknet_instance *instance = (struct totemknet_instance *)data;
867 int i;
868 int res = 0;
869
870 for (i=0; i < INTERFACE_MAX; i++) {
871 if (!instance->totem_config->interfaces[i].configured) {
872 continue;
873 }
874 res = instance->totemknet_iface_change_fn (instance->context,
875 &instance->my_ids[i],
876 i);
877 }
878 if (res != 0) {
879 /* This is only called at startup, so we can quit here.
880 Refresh takes a different path */
882 }
883}
884
885static void knet_set_access_list_config(struct totemknet_instance *instance)
886{
887#ifdef HAVE_KNET_ACCESS_LIST
890
892 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_enable access list: %d", value);
893
895 if (err) {
896 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_access_lists failed");
897 }
898#endif
899}
900
902{
903 int logsys_log_mode;
905 uint8_t s;
906 int err;
907
909 return;
910 }
911
912 /* Reconfigure logging level */
914
915 switch (logsys_log_mode) {
916 case LOGSYS_DEBUG_OFF:
918 break;
919 case LOGSYS_DEBUG_ON:
921 break;
923#ifdef KNET_LOG_TRACE
925#else
927#endif
928 break;
929 }
930 log_printf (LOGSYS_LEVEL_DEBUG, "totemknet setting log level %s", knet_log_get_loglevel_name(knet_log_mode));
931 err = 0;
932 for (s = 0; s<KNET_MAX_SUBSYSTEMS; s++) {
934 }
935
936 /* If one fails, they all fail. no point in issuing KNET_MAX_SUBSYSTEMS errors */
937 if (err) {
938 log_printf (LOGSYS_LEVEL_ERROR, "totemknet failed to set log level: %s", strerror(errno));
939 }
940}
941
942
943/* NOTE: this relies on the fact that totem_reload_notify() is called first */
944static void totemknet_refresh_config(
945 int32_t event,
946 const char *key_name,
949 void *user_data)
950{
952 int after_reload;
954 size_t num_nodes;
956 int i;
957 int err;
958 struct totemknet_instance *instance = (struct totemknet_instance *)user_data;
959
960 ENTER();
961
962 /*
963 * If a full reload is in progress then don't do anything until it's done and
964 * can reconfigure it all atomically
965 */
966 if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
967 return;
968 }
969
970 after_reload = (strcmp(key_name, "config.totemconfig_reload_in_progress") == 0);
971
972 knet_set_access_list_config(instance);
973
974 if (strcmp(key_name, "totem.knet_pmtud_interval") == 0 || after_reload) {
975 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_pmtud_interval now %u",
978 if (err) {
979 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
980 }
981 }
982
983 if (strcmp(key_name, "totem.knet_mtu") == 0 || after_reload) {
984 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet_mtu now %u", instance->totem_config->knet_mtu);
986 if (err) {
987 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud failed");
988 }
989 }
990
991 /* Configure link parameters for each node */
993 if (err != 0) {
994 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list failed");
995 }
996
997 for (i=0; i<num_nodes; i++) {
998 for (link_no = 0; link_no < INTERFACE_MAX; link_no++) {
999 if (host_ids[i] == instance->our_nodeid || !instance->totem_config->interfaces[link_no].configured) {
1000 continue;
1001 }
1002
1007 if (err) {
1008 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);
1009 }
1012 if (err) {
1013 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);
1014 }
1017 if (err) {
1018 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);
1019 }
1020
1021 }
1022 }
1023
1024 /* Log levels get reconfigured from logconfig.c as that happens last in the reload */
1025 LEAVE();
1026}
1027
1028static void totemknet_add_config_notifications(struct totemknet_instance *instance)
1029{
1032
1033 ENTER();
1034
1035 icmap_track_add("totem.",
1037 totemknet_refresh_config,
1038 instance,
1040
1041 icmap_track_add("config.totemconfig_reload_in_progress",
1043 totemknet_refresh_config,
1044 instance,
1046
1047 LEAVE();
1048}
1049
1050static int totemknet_is_crypto_enabled(const struct totemknet_instance *instance)
1051{
1052
1053 return (!(strcmp(instance->totem_config->crypto_cipher_type, "none") == 0 &&
1054 strcmp(instance->totem_config->crypto_hash_type, "none") == 0));
1055
1056}
1057
1058static int totemknet_set_knet_crypto(struct totemknet_instance *instance)
1059{
1061 int res;
1062
1063 /* These have already been validated */
1064 memcpy(crypto_cfg.crypto_model, instance->totem_config->crypto_model, sizeof(crypto_cfg.crypto_model));
1065 memcpy(crypto_cfg.crypto_cipher_type, instance->totem_config->crypto_cipher_type, sizeof(crypto_cfg.crypto_model));
1066 memcpy(crypto_cfg.crypto_hash_type, instance->totem_config->crypto_hash_type, sizeof(crypto_cfg.crypto_model));
1067 memcpy(crypto_cfg.private_key, instance->totem_config->private_key, instance->totem_config->private_key_len);
1068 crypto_cfg.private_key_len = instance->totem_config->private_key_len;
1069
1070#ifdef HAVE_KNET_CRYPTO_RECONF
1071
1072 knet_log_printf(LOGSYS_LEVEL_DEBUG, "Configuring crypto %s/%s/%s on index %d",
1073 crypto_cfg.crypto_model,
1074 crypto_cfg.crypto_cipher_type,
1075 crypto_cfg.crypto_hash_type,
1076 instance->totem_config->crypto_index
1077 );
1078
1079 /* If crypto is being disabled we need to explicitly allow cleartext traffic in knet */
1080 if (!totemknet_is_crypto_enabled(instance)) {
1082 if (res) {
1083 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(ALLOW) failed %s", strerror(errno));
1084 }
1085 }
1086
1087 /* use_config will be called later when all nodes are synced */
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
1115
1117 return res;
1118}
1119
1120/*
1121 * Create an instance
1122 */
1124 qb_loop_t *poll_handle,
1125 void **knet_context,
1126 struct totem_config *totem_config,
1127 totemsrp_stats_t *stats,
1128 void *context,
1129
1130 int (*deliver_fn) (
1131 void *context,
1132 const void *msg,
1133 unsigned int msg_len,
1134 const struct sockaddr_storage *system_from),
1135
1136 int (*iface_change_fn) (
1137 void *context,
1138 const struct totem_ip_address *iface_address,
1139 unsigned int link_no),
1140
1141 void (*mtu_changed) (
1142 void *context,
1143 int net_mtu),
1144
1145 void (*target_set_completed) (
1146 void *context))
1147{
1148 struct totemknet_instance *instance;
1149 char *tmp_str;
1150 int8_t channel=0;
1152 int res;
1153 int i;
1154
1155 instance = malloc (sizeof (struct totemknet_instance));
1156 if (instance == NULL) {
1157 return (-1);
1158 }
1159
1160 totemknet_instance_initialize (instance);
1161
1162 instance->totem_config = totem_config;
1163
1164 /*
1165 * Configure logging
1166 */
1167 instance->totemknet_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
1174
1175 instance->knet_subsys_id = _logsys_subsys_create("KNET", "libknet.h");
1176
1177 /*
1178 * Initialize local variables for totemknet
1179 */
1180
1181 instance->our_nodeid = instance->totem_config->node_id;
1182
1183 for (i=0; i< INTERFACE_MAX; i++) {
1185 instance->my_ids[i].nodeid = instance->our_nodeid;
1186 instance->ip_port[i] = totem_config->interfaces[i].ip_port;
1187
1188 /* Needed for totemsrp */
1190 }
1191
1192 instance->poll_handle = poll_handle;
1193
1194 instance->context = context;
1195 instance->totemknet_deliver_fn = deliver_fn;
1196
1198
1200
1201 instance->totemknet_target_set_completed = target_set_completed;
1202
1203 instance->loopback_link = 0;
1204
1205 res = pipe(instance->logpipes);
1206 if (res == -1) {
1207 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to create pipe for instance->logpipes");
1208 goto exit_error;
1209 }
1210 if (fcntl(instance->logpipes[0], F_SETFL, O_NONBLOCK) == -1 ||
1211 fcntl(instance->logpipes[1], F_SETFL, O_NONBLOCK) == -1) {
1212 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "failed to set O_NONBLOCK flag for instance->logpipes");
1213 goto exit_error;
1214 }
1215
1216 if (icmap_get_string("system.allow_knet_handle_fallback", &tmp_str) == CS_OK) {
1217 if (strcmp(tmp_str, "yes") == 0) {
1219 }
1220 free(tmp_str);
1221 }
1222
1223#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1225#else
1226 instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
1227#endif
1228
1229 if (allow_knet_handle_fallback && !instance->knet_handle && errno == ENAMETOOLONG) {
1230 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_new failed, trying unprivileged");
1231#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1232 instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
1233#else
1234 instance->knet_handle = knet_handle_new_ex(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
1235#endif
1236 }
1237
1238 if (!instance->knet_handle) {
1239 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
1240 goto exit_error;
1241 }
1242
1243 knet_set_access_list_config(instance);
1244
1246 if (res) {
1247 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_setfreq failed");
1248 }
1250 if (res) {
1251 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_pmtud_set failed");
1252 }
1253 res = knet_handle_enable_filter(instance->knet_handle, instance, dst_host_filter_callback_fn);
1254 if (res) {
1255 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_filter failed");
1256 }
1257 res = knet_handle_enable_sock_notify(instance->knet_handle, instance, socket_error_callback_fn);
1258 if (res) {
1259 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_sock_notify failed");
1260 }
1261 res = knet_host_enable_status_change_notify(instance->knet_handle, instance, host_change_callback_fn);
1262 if (res) {
1263 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_host_enable_status_change_notify failed");
1264 }
1265 res = knet_handle_enable_pmtud_notify(instance->knet_handle, instance, pmtu_change_callback_fn);
1266 if (res) {
1267 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_enable_pmtud_notify failed");
1268 }
1269 global_instance = instance;
1270
1271 /* Setup knet logging level */
1273
1274 /* Get an fd into knet */
1275 instance->knet_fd = 0;
1276 res = knet_handle_add_datafd(instance->knet_handle, &instance->knet_fd, &channel);
1277 if (res) {
1278 knet_log_printf(LOG_DEBUG, "knet_handle_add_datafd failed: %s", strerror(errno));
1279 goto exit_error;
1280 }
1281
1282 /* Enable crypto if requested */
1283#ifdef HAVE_KNET_CRYPTO_RECONF
1284 if (totemknet_is_crypto_enabled(instance)) {
1285 res = totemknet_set_knet_crypto(instance);
1286 if (res == 0) {
1288 if (res) {
1289 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_use_config failed: %s", strerror(errno));
1290 goto exit_error;
1291 }
1292 } else {
1293 knet_log_printf(LOG_DEBUG, "Failed to set up knet crypto");
1294 goto exit_error;
1295 }
1297 if (res) {
1298 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_rx_clear_traffic (DISALLOW) failed: %s", strerror(errno));
1299 goto exit_error;
1300 }
1301
1302 } else {
1304 if (res) {
1305 knet_log_printf(LOG_DEBUG, "knet_handle_crypto_rx_clear_traffic (ALLOW) failed: %s", strerror(errno));
1306 goto exit_error;
1307 }
1308 }
1309#else
1310 if (totemknet_is_crypto_enabled(instance)) {
1311 res = totemknet_set_knet_crypto(instance);
1312 if (res) {
1313 knet_log_printf(LOG_DEBUG, "Failed to set up knet crypto");
1314 goto exit_error;
1315 }
1316 }
1317#endif
1318
1319 /* Set up compression */
1320 if (strcmp(totem_config->knet_compression_model, "none") != 0) {
1321 /* Not fatal, but will log */
1322 (void)totemknet_configure_compression(instance, totem_config);
1323 }
1324
1325 knet_handle_setfwd(instance->knet_handle, 1);
1326
1328 if (strcmp(instance->totem_config->link_mode, "active")==0) {
1330 }
1331 if (strcmp(instance->totem_config->link_mode, "rr")==0) {
1332 instance->link_mode = KNET_LINK_POLICY_RR;
1333 }
1334
1335 for (i=0; i<INTERFACE_MAX; i++) {
1337 if (!instance->link_status[i]) {
1338 goto exit_error;
1339 }
1340 }
1341
1342 qb_loop_poll_add (instance->poll_handle,
1344 instance->logpipes[0],
1345 POLLIN, instance, log_deliver_fn);
1346
1347 qb_loop_poll_add (instance->poll_handle,
1349 instance->knet_fd,
1350 POLLIN, instance, data_deliver_fn);
1351
1352 /*
1353 * Upper layer isn't ready to receive message because it hasn't
1354 * initialized yet. Add short timer to check the interfaces.
1355 */
1356 qb_loop_timer_add (instance->poll_handle,
1359 (void *)instance,
1360 timer_function_netif_check_timeout,
1361 &instance->timer_netif_check_timeout);
1362
1363 totemknet_start_merge_detect_timeout(instance);
1364
1365 /* Start listening for config changes */
1366 totemknet_add_config_notifications(instance);
1367
1368 /* Add stats keys to icmap */
1370
1371 knet_log_printf (LOGSYS_LEVEL_INFO, "totemknet initialized");
1372 *knet_context = instance;
1373
1374 return (0);
1375
1377 log_flush_messages(instance);
1378 free(instance);
1379 return (-1);
1380}
1381
1383{
1384 /* Need to have space for a message AND a struct mcast in case of encapsulated messages */
1385 return malloc(KNET_MAX_PACKET_SIZE + 512);
1386}
1387
1389{
1390 return free (ptr);
1391}
1392
1394 void *knet_context,
1395 int processor_count)
1396{
1397 return (0);
1398}
1399
1401{
1402 return (0);
1403}
1404
1406{
1407 return (0);
1408}
1409
1411 void *knet_context,
1412 const void *msg,
1413 unsigned int msg_len)
1414{
1415 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1416 int res = 0;
1417
1418 ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
1419
1420 return (res);
1421}
1423 void *knet_context,
1424 const void *msg,
1425 unsigned int msg_len)
1426{
1427 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1428 int res = 0;
1429
1430 mcast_sendmsg (instance, msg, msg_len, 0);
1431
1432 return (res);
1433}
1434
1436 void *knet_context,
1437 const void *msg,
1438 unsigned int msg_len)
1439{
1440 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1441 int res = 0;
1442
1443 mcast_sendmsg (instance, msg, msg_len, 1);
1444
1445 return (res);
1446}
1447
1448
1450{
1451 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1452 int res = 0;
1453
1454 knet_log_printf(LOG_DEBUG, "totemknet: iface_check");
1455
1456 return (res);
1457}
1458
1460{
1461 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1462
1463 knet_log_printf(LOG_DEBUG, "totemknet: Returning MTU of %d", totem_config->net_mtu);
1464}
1465
1467 void *knet_context,
1468 unsigned int nodeid)
1469{
1470 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1471 int res = 0;
1472
1473 instance->token_target.nodeid = nodeid;
1474
1475 instance->totemknet_target_set_completed (instance->context);
1476
1477 return (res);
1478}
1479
1481 void *knet_context)
1482{
1483 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1484 unsigned int res;
1486 struct msghdr msg_hdr;
1487 struct iovec iov_recv;
1488 struct pollfd ufd;
1489 int nfds;
1490 int msg_processed = 0;
1491
1492 iov_recv.iov_base = instance->iov_buffer;
1494
1495 msg_hdr.msg_name = &system_from;
1496 msg_hdr.msg_namelen = sizeof (struct sockaddr_storage);
1497 msg_hdr.msg_iov = &iov_recv;
1498 msg_hdr.msg_iovlen = 1;
1499#ifdef HAVE_MSGHDR_CONTROL
1500 msg_hdr.msg_control = 0;
1501#endif
1502#ifdef HAVE_MSGHDR_CONTROLLEN
1503 msg_hdr.msg_controllen = 0;
1504#endif
1505#ifdef HAVE_MSGHDR_FLAGS
1506 msg_hdr.msg_flags = 0;
1507#endif
1508#ifdef HAVE_MSGHDR_ACCRIGHTS
1509 msg_msg_hdr.msg_accrights = NULL;
1510#endif
1511#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1512 msg_msg_hdr.msg_accrightslen = 0;
1513#endif
1514
1515 do {
1516 ufd.fd = instance->knet_fd;
1517 ufd.events = POLLIN;
1518 nfds = poll (&ufd, 1, 0);
1519 if (nfds == 1 && ufd.revents & POLLIN) {
1521 if (res != -1) {
1522 msg_processed = 1;
1523 } else {
1524 msg_processed = -1;
1525 }
1526 }
1527 } while (nfds == 1);
1528
1529 return (msg_processed);
1530}
1531
1532int totemknet_iface_set (void *knet_context,
1533 const struct totem_ip_address *local_addr,
1534 unsigned short ip_port,
1535 unsigned int iface_no)
1536{
1537 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1538
1539 totemip_copy(&instance->my_ids[iface_no], local_addr);
1540
1541 knet_log_printf(LOG_INFO, "Configured link number %d: local addr: %s, port=%d", iface_no, totemip_print(local_addr), ip_port);
1542
1543 instance->ip_port[iface_no] = ip_port;
1544
1545 return 0;
1546}
1547
1548
1550 void *knet_context,
1551 const struct totem_ip_address *local,
1552 const struct totem_ip_address *member,
1553 int link_no)
1554{
1555 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1556 int err;
1557 int port = instance->ip_port[link_no];
1560 int addrlen;
1561 int i;
1562 int host_found = 0;
1564 size_t num_host_ids;
1565
1566 /* Only create 1 loopback link and use link 0 */
1567 if (member->nodeid == instance->our_nodeid) {
1568 if (!instance->loopback_link) {
1569 link_no = 0;
1570 instance->loopback_link = 1;
1571 } else {
1572 /* Already done */
1573 return 0;
1574 }
1575 }
1576
1577 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: " CS_PRI_NODE_ID " (%s), link=%d", member->nodeid, totemip_print(member), link_no);
1578 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: local: " CS_PRI_NODE_ID " (%s)", local->nodeid, totemip_print(local));
1579
1580
1581 /* Only add the host if it doesn't already exist in knet */
1583 if (err) {
1584 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_get_host_list");
1585 return -1;
1586 }
1587 for (i=0; i<num_host_ids; i++) {
1588 if (host_ids[i] == member->nodeid) {
1589 host_found = 1;
1590 }
1591 }
1592
1593 if (!host_found) {
1594 err = knet_host_add(instance->knet_handle, member->nodeid);
1595 if (err != 0 && errno != EEXIST) {
1596 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_host_add");
1597 return -1;
1598 }
1599 } else {
1600 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nodeid " CS_PRI_NODE_ID " already added", member->nodeid);
1601 }
1602
1603
1604 if (err == 0) {
1605 if (knet_host_set_policy(instance->knet_handle, member->nodeid, instance->link_mode)) {
1606 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_set_policy failed");
1607 return -1;
1608 }
1609 }
1610
1611 memset(&local_ss, 0, sizeof(local_ss));
1612 memset(&remote_ss, 0, sizeof(remote_ss));
1613 /* Casts to remove const */
1616
1617 if (member->nodeid == instance->our_nodeid) {
1618 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: loopback link is %d\n", link_no);
1619
1620 err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1623 }
1624 else {
1625 err = knet_link_set_config(instance->knet_handle, member->nodeid, link_no,
1628 }
1629 if (err) {
1630 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_config failed");
1631 return -1;
1632 }
1633
1634 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_add: Setting link prio to %d",
1636
1637 err = knet_link_set_priority(instance->knet_handle, member->nodeid, link_no,
1639 if (err) {
1640 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_priority for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1641 }
1642
1643 /*
1644 * Ping timeouts may be 0 here for a newly added interface (on a reload),
1645 * so we leave this till later, it will get done in totemknet_refresh_config.
1646 * For the initial startup, we are all preset and ready to go from here.
1647 */
1648 if (instance->totem_config->interfaces[link_no].knet_ping_interval != 0) {
1653 if (err) {
1654 /* Flush logs before reporting this error so that the knet message prints before ours */
1655 int saved_errno = errno;
1656 log_flush_messages(instance);
1658 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);
1659 return -1;
1660 }
1663 if (err) {
1664 /* Flush logs before reporting this error so that the knet message prints before ours */
1665 int saved_errno = errno;
1666 log_flush_messages(instance);
1668 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);
1669 return -1;
1670 }
1671 }
1672
1673 err = knet_link_set_enable(instance->knet_handle, member->nodeid, link_no, 1);
1674 if (err) {
1675 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_link_set_enable for nodeid " CS_PRI_NODE_ID ", link %d failed", member->nodeid, link_no);
1676 return -1;
1677 }
1678
1679 /* register stats */
1681 return (0);
1682}
1683
1685 void *knet_context,
1686 const struct totem_ip_address *token_target,
1687 int link_no)
1688{
1689 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1690 int res;
1692 size_t num_links;
1693
1694 knet_log_printf (LOGSYS_LEVEL_DEBUG, "knet: member_remove: " CS_PRI_NODE_ID ", link=%d", token_target->nodeid, link_no);
1695
1696 /* Don't remove the link with the loopback on it until we shut down */
1697 if (token_target->nodeid == instance->our_nodeid) {
1698 return 0;
1699 }
1700
1701 /* Tidy stats */
1703
1704 /* Remove the link first */
1706 if (res != 0) {
1707 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);
1708 return res;
1709 }
1710
1712 if (res != 0) {
1713 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);
1714 return res;
1715 }
1716
1717 /* If this is the last link, then remove the node */
1720 if (res) {
1721 return (0); /* not really failure */
1722 }
1723
1724 if (num_links == 0) {
1726 }
1727 return res;
1728}
1729
1731 void *knet_context)
1732{
1733 return (0);
1734}
1735
1736
1737static int totemknet_configure_compression (
1738 struct totemknet_instance *instance,
1739 struct totem_config *totem_config)
1740{
1742 int res = 0;
1743
1744 assert(strlen(totem_config->knet_compression_model) < sizeof(compress_cfg.compress_model));
1746
1749
1751 if (res) {
1752 KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_ERROR, "knet_handle_compress failed");
1753 }
1754 return res;
1755}
1756
1758 void *knet_context,
1759 struct totem_config *totem_config)
1760{
1761 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1762 int res = 0;
1763
1764 (void)totemknet_configure_compression(instance, totem_config);
1765
1766#ifdef HAVE_LIBNOZZLE
1767 /* Set up nozzle device(s). Return code is ignored, because inability
1768 * configure nozzle is not fatal problem, errors are logged and
1769 * there is not much else we can do */
1770 (void)setup_nozzle(instance);
1771#endif
1772
1774 /* Flip crypto_index */
1776 res = totemknet_set_knet_crypto(instance);
1777
1778 knet_log_printf(LOG_INFO, "kronosnet crypto reconfigured on index %d: %s/%s/%s", totem_config->crypto_index,
1782 }
1783 return (res);
1784}
1785
1786
1788 void *knet_context,
1789 struct totem_config *totem_config,
1791{
1792#ifdef HAVE_KNET_CRYPTO_RECONF
1793 int res;
1794 int config_to_use;
1795 int config_to_clear;
1797 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1798
1799 knet_log_printf(LOGSYS_LEVEL_DEBUG, "totemknet_crypto_reconfigure_phase %d, index=%d\n", phase, totem_config->crypto_index);
1800
1801 switch (phase) {
1804 if (!totemknet_is_crypto_enabled(instance)) {
1805 config_to_use = 0; /* we are clearing it */
1806 }
1807
1808 /* Enable the new config on this node */
1810 if (res == -1) {
1811 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_use_config %d failed: %s", config_to_use, strerror(errno));
1812 }
1813 break;
1814
1816 /*
1817 * All nodes should now have the new config. clear the old one out
1818 * OR disable crypto entirely if that's what the new config insists on.
1819 */
1821 knet_log_printf(LOGSYS_LEVEL_DEBUG, "Clearing old knet crypto config %d\n", config_to_clear);
1822
1823 strcpy(crypto_cfg.crypto_model, "none");
1824 strcpy(crypto_cfg.crypto_cipher_type, "none");
1825 strcpy(crypto_cfg.crypto_hash_type, "none");
1827 if (res == -1) {
1828 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config to clear index %d failed: %s", config_to_clear, strerror(errno));
1829 }
1830 if (res == -2) {
1831 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_set_config to clear index %d failed: -2", config_to_clear);
1832 }
1833
1834 /* If crypto is enabled then disable all cleartext reception */
1835 if (totemknet_is_crypto_enabled(instance)) {
1837 if (res) {
1838 knet_log_printf(LOGSYS_LEVEL_ERROR, "knet_handle_crypto_rx_clear_traffic(DISALLOW) failed %s", strerror(errno));
1839 }
1840 }
1841 }
1842#endif
1843 return 0;
1844}
1845
1853
1854/* For the stats module */
1857 struct knet_link_status *status)
1858{
1859 int res;
1860 int ret = CS_OK;
1861
1862 /* We are probably not using knet */
1863 if (!global_instance) {
1864 return CS_ERR_NOT_EXIST;
1865 }
1866
1867 if (link_no >= INTERFACE_MAX) {
1868 return CS_ERR_NOT_EXIST; /* Invalid link number */
1869 }
1870
1872 if (res) {
1873 switch (errno) {
1874 case EINVAL:
1876 break;
1877 case EBUSY:
1878 ret = CS_ERR_BUSY;
1879 break;
1880 case EDEADLK:
1882 break;
1883 default:
1885 break;
1886 }
1887 }
1888
1889 return (ret);
1890}
1891
1893 struct knet_handle_stats *stats)
1894{
1895 int res;
1896
1897 /* We are probably not using knet */
1898 if (!global_instance) {
1899 return CS_ERR_NOT_EXIST;
1900 }
1901
1903 if (res != 0) {
1904 return (qb_to_cs_error(-errno));
1905 }
1906
1907 return CS_OK;
1908}
1909
1910static void timer_function_merge_detect_timeout (
1911 void *data)
1912{
1913 struct totemknet_instance *instance = (struct totemknet_instance *)data;
1914
1915 if (instance->merge_detect_messages_sent_before_timeout == 0) {
1916 instance->send_merge_detect_message = 1;
1917 }
1918
1920
1921 totemknet_start_merge_detect_timeout(instance);
1922}
1923
1924static void totemknet_start_merge_detect_timeout(
1925 void *knet_context)
1926{
1927 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1928
1932 (void *)instance,
1933 timer_function_merge_detect_timeout,
1934 &instance->timer_merge_detect_timeout);
1935
1936}
1937
1938static void totemknet_stop_merge_detect_timeout(
1939 void *knet_context)
1940{
1941 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1942
1944 instance->timer_merge_detect_timeout);
1945}
1946
1947static void log_flush_messages (void *knet_context)
1948{
1949 struct pollfd pfd;
1950 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1951 int cont;
1952
1953 cont = 1;
1954
1955 while (cont) {
1956 pfd.fd = instance->logpipes[0];
1957 pfd.events = POLLIN;
1958 pfd.revents = 0;
1959
1960 if ((poll(&pfd, 1, 0) > 0) &&
1961 (pfd.revents & POLLIN) &&
1962 (log_deliver_fn(instance->logpipes[0], POLLIN, instance) == 0)) {
1963 cont = 1;
1964 } else {
1965 cont = 0;
1966 }
1967 }
1968}
1969
1970
1971#ifdef HAVE_LIBNOZZLE
1972#define NOZZLE_NAME "nozzle.name"
1973#define NOZZLE_IPADDR "nozzle.ipaddr"
1974#define NOZZLE_PREFIX "nozzle.ipprefix"
1975#define NOZZLE_MACADDR "nozzle.macaddr"
1976
1977#define NOZZLE_CHANNEL 1
1978
1979
1980static char *get_nozzle_script_dir(void *knet_context)
1981{
1982 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
1983 char filename[PATH_MAX + FILENAME_MAX + 1];
1984 static char updown_dirname[PATH_MAX + FILENAME_MAX + 1];
1985 int res;
1986 const char *dirname_res;
1987
1988 /*
1989 * Build script directory based on corosync.conf file location
1990 */
1991 res = snprintf(filename, sizeof(filename), "%s",
1993 if (res >= sizeof(filename)) {
1994 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
1995 return NULL;
1996 }
1997
1999
2000 res = snprintf(updown_dirname, sizeof(updown_dirname), "%s/%s",
2001 dirname_res, "updown.d");
2002 if (res >= sizeof(updown_dirname)) {
2003 knet_log_printf (LOGSYS_LEVEL_DEBUG, "nozzle up/down path too long");
2004 return NULL;
2005 }
2006 return updown_dirname;
2007}
2008
2009/*
2010 * Deliberately doesn't return the status as caller doesn't care.
2011 * The result will be logged though
2012 */
2013static void run_nozzle_script(struct totemknet_instance *instance, int type, const char *typename)
2014{
2015 int res;
2016 char *exec_string;
2017
2018 res = nozzle_run_updown(instance->nozzle_handle, type, &exec_string);
2019 if (res == -1 && errno != ENOENT) {
2020 knet_log_printf (LOGSYS_LEVEL_INFO, "exec nozzle %s script failed: %s", typename, strerror(errno));
2021 } else if (res == -2) {
2022 knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle %s script failed", typename);
2024 }
2025}
2026
2027/*
2028 * Reparse IP address to add in our node ID
2029 * IPv6 addresses must end in '::'
2030 * IPv4 addresses must just be valid
2031 * '/xx' lengths are optional for IPv6, mandatory for IPv4
2032 *
2033 * Returns the modified IP address as a string to pass into libnozzle
2034 */
2035static int reparse_nozzle_ip_address(struct totemknet_instance *instance,
2036 const char *input_addr,
2037 const char *prefix, int nodeid,
2038 char *output_addr, size_t output_len)
2039{
2040 char *coloncolon;
2041 int bits;
2042 int max_prefix = 64;
2046 struct in_addr *addr;
2048
2049 coloncolon = strstr(input_addr, "::");
2050 if (!coloncolon) {
2051 max_prefix = 30;
2052 }
2053
2054 bits = atoi(prefix);
2056 knet_log_printf(LOGSYS_LEVEL_ERROR, "nozzle IP address prefix must be >= 8 and <= %d (got %d)", max_prefix, bits);
2057 return -1;
2058 }
2059
2060 /* IPv6 is easy */
2061 if (coloncolon) {
2064 return 0;
2065 }
2066
2067 /* For IPv4 we need to parse the address into binary, mask off the required bits,
2068 * add in the masked_nodeid and 'print' it out again
2069 */
2070 nodeid_mask = UINT32_MAX & ((1<<(32 - bits)) - 1);
2073
2075 knet_log_printf(LOGSYS_LEVEL_ERROR, "Failed to parse IPv4 nozzle IP address");
2076 return -1;
2077 }
2078 addr = (struct in_addr *)&totemip.addr;
2079 addr->s_addr &= htonl(addr_mask);
2080 addr->s_addr |= htonl(masked_nodeid);
2081
2083 return 0;
2084}
2085
2086static int create_nozzle_device(void *knet_context, const char *name,
2087 const char *ipaddr, const char *prefix,
2088 const char *macaddr)
2089{
2090 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2091 char device_name[IFNAMSIZ+1];
2092 size_t size = IFNAMSIZ;
2095 int nozzle_fd;
2096 int res;
2097 char *updown_dir;
2099 char mac[19];
2100
2101 memset(device_name, 0, size);
2102 memset(&mac, 0, sizeof(mac));
2103 strncpy(device_name, name, size);
2104
2106 knet_log_printf (LOGSYS_LEVEL_INFO, "nozzle script dir is %s", updown_dir);
2107
2109 if (!nozzle_dev) {
2110 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to init nozzle device %s: %s", device_name, strerror(errno));
2111 return -1;
2112 }
2113 instance->nozzle_handle = nozzle_dev;
2114
2115 if (nozzle_set_mac(nozzle_dev, macaddr) < 0) {
2116 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle MAC to %s: %s", mac, strerror(errno));
2117 goto out_clean;
2118 }
2119
2120 if (reparse_nozzle_ip_address(instance, ipaddr, prefix, instance->our_nodeid, parsed_ipaddr, sizeof(parsed_ipaddr))) {
2121 /* Prints its own errors */
2122 goto out_clean;
2123 }
2124 knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle IP address is %s / %d", parsed_ipaddr, atoi(prefix));
2125 if (nozzle_add_ip(nozzle_dev, parsed_ipaddr, prefix) < 0) {
2126 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add set nozzle IP addr to %s/%s: %s", parsed_ipaddr, prefix, strerror(errno));
2127 goto out_clean;
2128 }
2129
2131 knet_log_printf (LOGSYS_LEVEL_INFO, "Opened '%s' on fd %d", device_name, nozzle_fd);
2132
2134 if (res != 0) {
2135 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to add nozzle FD to knet: %s", strerror(errno));
2136 goto out_clean;
2137 }
2138
2139 run_nozzle_script(instance, NOZZLE_PREUP, "pre-up");
2140
2142 if (res != 0) {
2143 knet_log_printf (LOGSYS_LEVEL_ERROR, "Unable to set nozzle interface UP: %s", strerror(errno));
2144 goto out_clean;
2145 }
2146 run_nozzle_script(instance, NOZZLE_UP, "up");
2147
2148 return 0;
2149
2150out_clean:
2152 return -1;
2153}
2154
2155static int remove_nozzle_device(void *knet_context)
2156{
2157 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2158 int res;
2159 int datafd;
2160
2162 if (res != 0) {
2163 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't find datafd for channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
2164 return -1;
2165 }
2166
2168 if (res != 0) {
2169 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't remove datafd for nozzle channel %d: %s", NOZZLE_CHANNEL, strerror(errno));
2170 return -1;
2171 }
2172
2173 run_nozzle_script(instance, NOZZLE_DOWN, "pre-down");
2174 res = nozzle_set_down(instance->nozzle_handle);
2175 if (res != 0) {
2176 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't set nozzle device down: %s", strerror(errno));
2177 return -1;
2178 }
2179 run_nozzle_script(instance, NOZZLE_POSTDOWN, "post-down");
2180
2181 res = nozzle_close(instance->nozzle_handle);
2182 if (res != 0) {
2183 knet_log_printf (LOGSYS_LEVEL_ERROR, "Can't close nozzle device: %s", strerror(errno));
2184 return -1;
2185 }
2186 knet_log_printf (LOGSYS_LEVEL_INFO, "Removed nozzle device");
2187 return 0;
2188}
2189
2190static void free_nozzle(struct totemknet_instance *instance)
2191{
2192 free(instance->nozzle_name);
2193 free(instance->nozzle_ipaddr);
2194 free(instance->nozzle_prefix);
2195 free(instance->nozzle_macaddr);
2196
2197 instance->nozzle_name = instance->nozzle_ipaddr = instance->nozzle_prefix =
2198 instance->nozzle_macaddr = NULL;
2199}
2200
2201static int setup_nozzle(void *knet_context)
2202{
2203 struct totemknet_instance *instance = (struct totemknet_instance *)knet_context;
2204 char *ipaddr_str = NULL;
2205 char *name_str = NULL;
2206 char *prefix_str = NULL;
2207 char *macaddr_str = NULL;
2208 char mac[32];
2209 int name_res;
2210 int macaddr_res;
2211 int res = -1;
2212
2213 /*
2214 * Return value ignored on purpose. icmap_get_string changes
2215 * ipaddr_str/prefix_str only on success.
2216 */
2221
2222 /* Is is being removed? */
2223 if (name_res == CS_ERR_NOT_EXIST && instance->nozzle_handle) {
2224 remove_nozzle_device(instance);
2225 free_nozzle(instance);
2226 goto out_free;
2227 }
2228
2229 if (!name_str) {
2230 /* no nozzle */
2231 goto out_free;
2232 }
2233
2234 if (!ipaddr_str) {
2235 knet_log_printf (LOGSYS_LEVEL_ERROR, "No IP address supplied for Nozzle device");
2236 goto out_free;
2237 }
2238
2239 if (!prefix_str) {
2240 knet_log_printf (LOGSYS_LEVEL_ERROR, "No prefix supplied for Nozzle IP address");
2241 goto out_free;
2242 }
2243
2244 if (macaddr_str && strlen(macaddr_str) != 17) {
2245 knet_log_printf (LOGSYS_LEVEL_ERROR, "macaddr for nozzle device is not in the correct format '%s'", macaddr_str);
2246 goto out_free;
2247 }
2248 if (!macaddr_str) {
2249 macaddr_str = (char*)"54:54:01:00:00:00";
2250 }
2251
2252 if (instance->nozzle_name &&
2253 (strcmp(name_str, instance->nozzle_name) == 0) &&
2254 (strcmp(ipaddr_str, instance->nozzle_ipaddr) == 0) &&
2255 (strcmp(prefix_str, instance->nozzle_prefix) == 0) &&
2256 (instance->nozzle_macaddr == NULL ||
2257 strcmp(macaddr_str, instance->nozzle_macaddr) == 0)) {
2258 /* Nothing has changed */
2259 knet_log_printf (LOGSYS_LEVEL_DEBUG, "Nozzle device info not changed");
2260 goto out_free;
2261 }
2262
2263 /* Add nodeid into MAC address */
2264 memcpy(mac, macaddr_str, 12);
2265 snprintf(mac+12, sizeof(mac) - 13, "%02x:%02x",
2266 instance->our_nodeid >> 8,
2267 instance->our_nodeid & 0xFF);
2268 knet_log_printf (LOGSYS_LEVEL_INFO, "Local nozzle MAC address is %s", mac);
2269
2270 if (name_res == CS_OK && name_str) {
2271 /* Reconfigure */
2272 if (instance->nozzle_name) {
2273 remove_nozzle_device(instance);
2274 free_nozzle(instance);
2275 }
2276
2278 mac);
2279
2280 instance->nozzle_name = strdup(name_str);
2281 instance->nozzle_ipaddr = strdup(ipaddr_str);
2282 instance->nozzle_prefix = strdup(prefix_str);
2283 instance->nozzle_macaddr = strdup(macaddr_str);
2284 if (!instance->nozzle_name || !instance->nozzle_ipaddr ||
2285 !instance->nozzle_prefix) {
2286 knet_log_printf (LOGSYS_LEVEL_ERROR, "strdup failed in nozzle allocation");
2287 /*
2288 * This 'free' will cause a complete reconfigure of the device next time we reload
2289 * but will also let the the current device keep working until then.
2290 * remove_nozzle() only needs the, statically-allocated, nozzle_handle
2291 */
2292 free_nozzle(instance);
2293 }
2294 }
2295
2296out_free:
2297 free(name_str);
2300 if (macaddr_res == CS_OK) {
2302 }
2303
2304 return res;
2305}
2306#endif // HAVE_LIBNOZZLE
#define INTERFACE_MAX
Definition coroapi.h:88
unsigned int nodeid
Definition coroapi.h:0
unsigned char addr[TOTEMIP_ADDRLEN]
Definition coroapi.h:2
#define PROCESSOR_COUNT_MAX
Definition coroapi.h:96
#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:868
#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:1159
#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:856
#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:806
#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:435
#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:224
unsigned int private_key_len
Definition totem.h:177
unsigned int knet_mtu
Definition totem.h:170
unsigned int node_id
Definition totem.h:167
uint32_t knet_compression_threshold
Definition totem.h:236
struct totem_logging_configuration totem_logging_configuration
Definition totem.h:208
struct totem_interface * interfaces
Definition totem.h:165
int crypto_changed
Definition totem.h:232
unsigned int merge_timeout
Definition totem.h:198
int knet_compression_level
Definition totem.h:238
unsigned int net_mtu
Definition totem.h:210
char knet_compression_model[CONFIG_STRING_LEN_MAX]
Definition totem.h:234
unsigned int block_unlisted_ips
Definition totem.h:246
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
Definition totem.h:175
int crypto_index
Definition totem.h:230
unsigned int knet_pmtud_interval
Definition totem.h:169
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
Definition totem.h:226
char link_mode[TOTEM_LINK_MODE_BYTES]
Definition totem.h:206
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
Definition totem.h:228
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:119
pthread_mutex_t log_mutex
Definition totemknet.c:176
void(* totemknet_mtu_changed)(void *context, int net_mtu)
Definition totemknet.c:115
struct crypto_instance * crypto_inst
Definition totemknet.c:94
struct totem_config * totem_config
Definition totemknet.c:161
qb_loop_timer_handle timer_netif_check_timeout
Definition totemknet.c:165
char * link_status[INTERFACE_MAX]
Definition totemknet.c:151
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:138
knet_handle_t knet_handle
Definition totemknet.c:98
uint16_t ip_port[INTERFACE_MAX]
Definition totemknet.c:155
int(* totemknet_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no)
Definition totemknet.c:110
int totemknet_log_level_debug
Definition totemknet.c:132
struct totem_ip_address token_target
Definition totemknet.c:163
qb_loop_timer_handle timer_merge_detect_timeout
Definition totemknet.c:167
void(*) void knet_context)
Definition totemknet.c:147
int totemknet_log_level_warning
Definition totemknet.c:128
struct totem_ip_address my_ids[INTERFACE_MAX]
Definition totemknet.c:153
int(* totemknet_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
Definition totemknet.c:104
char iov_buffer[KNET_MAX_PACKET_SIZE]
Definition totemknet.c:149
unsigned int merge_detect_messages_sent_before_timeout
Definition totemknet.c:171
int send_merge_detect_message
Definition totemknet.c:169
int totemknet_log_level_error
Definition totemknet.c:126
int totemknet_log_level_security
Definition totemknet.c:124
qb_loop_t * poll_handle
Definition totemknet.c:96
int totemknet_log_level_notice
Definition totemknet.c:130
const void * msg
Definition totemknet.c:190
unsigned int msg_len
Definition totemknet.c:191
struct totemknet_instance * instance
Definition totemknet.c:192
typedef __attribute__
cfg_message_crypto_reconfig_phase_t
Definition totem.h:154
@ CRYPTO_RECONFIG_PHASE_CLEANUP
Definition totem.h:156
@ CRYPTO_RECONFIG_PHASE_ACTIVATE
Definition totem.h:155
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:1422
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:1532
int totemknet_finalize(void *knet_context)
Definition totemknet.c:664
int totemknet_recv_flush(void *knet_context)
Definition totemknet.c:1400
int totemknet_member_list_rebind_ip(void *knet_context)
Definition totemknet.c:1730
void * totemknet_buffer_alloc(void)
Definition totemknet.c:1382
int totemknet_processor_count_set(void *knet_context, int processor_count)
Definition totemknet.c:1393
int totemknet_mcast_noflush_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition totemknet.c:1435
struct totemknet_instance * global_instance
Definition totemknet.c:187
void totemknet_buffer_release(void *ptr)
Definition totemknet.c:1388
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:1123
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:1549
int totemknet_crypto_set(void *knet_context, const char *cipher_type, const char *hash_type)
Definition totemknet.c:363
int totemknet_member_remove(void *knet_context, const struct totem_ip_address *token_target, int link_no)
Definition totemknet.c:1684
int totemknet_token_send(void *knet_context, const void *msg, unsigned int msg_len)
Definition totemknet.c:1410
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition totemknet.c:91
int totemknet_link_get_status(knet_node_id_t node, uint8_t link_no, struct knet_link_status *status)
Definition totemknet.c:1855
#define OWN_INDEX_NONE
Definition totemknet.c:488
void totemknet_configure_log_level()
Definition totemknet.c:901
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:1892
#define MSG_NOSIGNAL
Definition totemknet.c:83
void totemknet_stats_clear(void *knet_context)
Definition totemknet.c:1846
int totemknet_send_flush(void *knet_context)
Definition totemknet.c:1405
void totemknet_net_mtu_adjust(void *knet_context, struct totem_config *totem_config)
Definition totemknet.c:1459
#define knet_log_printf(level, format, args...)
Definition totemknet.c:233
int totemknet_token_target_set(void *knet_context, unsigned int nodeid)
Definition totemknet.c:1466
#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...)
Definition totemknet.c:249
int totemknet_reconfigure(void *knet_context, struct totem_config *totem_config)
Definition totemknet.c:1757
int totemknet_crypto_reconfigure_phase(void *knet_context, struct totem_config *totem_config, cfg_message_crypto_reconfig_phase_t phase)
Definition totemknet.c:1787
#define libknet_log_printf(level, format, args...)
Definition totemknet.c:241
int totemknet_recv_mcast_empty(void *knet_context)
Definition totemknet.c:1480
int totemknet_iface_check(void *knet_context)
Definition totemknet.c:1449
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