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