41#include <sys/socket.h>
46#include <netinet/in.h>
47#include <net/ethernet.h>
87static int setup_nozzle(
void *knet_context);
91#define CFG_INTERFACE_STATUS_MAX_LEN 512
107 unsigned int msg_len,
113 unsigned int link_no);
141 const char *function,
181 char *nozzle_macaddr;
182 nozzle_t nozzle_handle;
199static int totemknet_configure_compression (
203static void totemknet_start_merge_detect_timeout(
206static void totemknet_stop_merge_detect_timeout(
209static void log_flush_messages (
217 res = pthread_mutex_init(&instance->
log_mutex, NULL);
224#define knet_log_printf_lock(level, subsys, function, file, line, format, args...) \
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); \
233#define knet_log_printf(level, format, args...) \
235 knet_log_printf_lock ( \
236 level, instance->totemknet_subsys_id, \
237 __FUNCTION__, __FILE__, __LINE__, \
238 (const char *)format, ##args); \
241#define libknet_log_printf(level, format, args...) \
243 knet_log_printf_lock ( \
244 level, instance->knet_subsys_id, \
245 __FUNCTION__, "libknet.h", __LINE__, \
246 (const char *)format, ##args); \
249#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...) \
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); \
261static inline int is_ether_addr_multicast(
const uint8_t *
addr)
263 return (
addr[0] & 0x01);
265static inline int is_ether_addr_zero(
const uint8_t *
addr)
270static int ether_host_filter_fn(
void *private_data,
271 const unsigned char *outdata,
274 knet_node_id_t this_host_id,
275 knet_node_id_t src_host_id,
277 knet_node_id_t *dst_host_ids,
278 size_t *dst_host_ids_entries)
280 struct ether_header *eth_h = (
struct ether_header *)outdata;
281 uint8_t *dst_mac = (uint8_t *)eth_h->ether_dhost;
282 uint16_t dst_host_id;
284 if (is_ether_addr_zero(dst_mac))
287 if (is_ether_addr_multicast(dst_mac)) {
291 memmove(&dst_host_id, &dst_mac[4], 2);
293 dst_host_ids[0] = ntohs(dst_host_id);
294 *dst_host_ids_entries = 1;
300static int dst_host_filter_callback_fn(
void *private_data,
301 const unsigned char *outdata,
304 knet_node_id_t this_host_id,
305 knet_node_id_t src_host_id,
307 knet_node_id_t *dst_host_ids,
308 size_t *dst_host_ids_entries)
315 return ether_host_filter_fn(private_data,
316 outdata, outdata_len,
318 this_host_id, src_host_id,
321 dst_host_ids_entries);
326 *dst_host_ids_entries = 1;
330 *dst_host_ids_entries = 0;
336static void socket_error_callback_fn(
void *private_data,
int datafd, int8_t channel, uint8_t tx_rx,
int error,
int errorno)
341 if ((error == -1 && errorno != EAGAIN) || (error == 0)) {
342 knet_handle_remove_datafd(instance->
knet_handle, datafd);
346static void host_change_callback_fn(
void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
354static void pmtu_change_callback_fn(
void *private_data,
unsigned int data_mtu)
365 const char *cipher_type,
366 const char *hash_type)
372static inline void ucast_sendmsg (
376 unsigned int msg_len)
380 struct msghdr msg_ucast;
385 iovec.iov_base = (
void *)msg;
386 iovec.iov_len = msg_len;
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;
397#ifdef HAVE_MSGHDR_CONTROLLEN
398 msg_ucast.msg_controllen = 0;
400#ifdef HAVE_MSGHDR_FLAGS
401 msg_ucast.msg_flags = 0;
403#ifdef HAVE_MSGHDR_ACCRIGHTS
404 msg_ucast.msg_accrights = NULL;
406#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
407 msg_ucast.msg_accrightslen = 0;
418 "sendmsg(ucast) failed (non-critical)");
422static inline void mcast_sendmsg (
425 unsigned int msg_len,
430 struct msghdr msg_mcast;
433 iovec.iov_base = (
void *)msg;
434 iovec.iov_len = msg_len;
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;
447#ifdef HAVE_MSGHDR_CONTROLLEN
448 msg_mcast.msg_controllen = 0;
450#ifdef HAVE_MSGHDR_FLAGS
451 msg_mcast.msg_flags = 0;
453#ifdef HAVE_MSGHDR_ACCRIGHTS
454 msg_mcast.msg_accrights = NULL;
456#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
457 msg_mcast.msg_accrightslen = 0;
477static int node_compare(
const void *aptr,
const void *bptr)
481 a = *(uint16_t *)aptr;
482 b = *(uint16_t *)bptr;
487#ifndef OWN_INDEX_NONE
488#define OWN_INDEX_NONE -1
498 struct knet_link_status link_status;
500 struct knet_host_status knet_host_status;
501 uint8_t link_list[KNET_MAX_LINK];
520 node_status->
reachable = knet_host_status.reachable;
521 node_status->
remote = knet_host_status.remote;
522 node_status->
external = knet_host_status.external;
524#ifdef HAVE_KNET_ONWIRE_VER
525 res = knet_handle_get_onwire_ver(instance->
knet_handle,
536 res = knet_link_get_link_list(instance->
knet_handle,
537 nodeid, link_list, &num_links);
544 for (i=0; i < num_links; i++) {
552 sizeof(link_status));
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);
571 unsigned int *iface_count)
574 struct knet_link_status link_status;
575 knet_node_id_t host_list[KNET_MAX_HOST];
576 uint8_t link_list[KNET_MAX_LINK];
591 res = knet_host_get_host_list(instance->
knet_handle,
592 host_list, &num_hosts);
596 qsort(host_list, num_hosts,
sizeof(uint16_t), node_compare);
598 for (j=0; j<num_hosts; j++) {
616 for (j=0; j<num_hosts; j++) {
621 res = knet_link_get_link_list(instance->
knet_handle,
622 host_list[j], link_list, &num_links);
628 for (i=0; i < num_links; i++) {
643 sizeof(link_status));
645 ptr[j] =
'0' + (link_status.enabled |
646 link_status.connected<<1 |
647 link_status.dynconnected<<2);
651 "totemknet_ifaces_get: Cannot get link status: %s", strerror(errno));
670 static knet_node_id_t nodes[KNET_MAX_HOST];
671 uint8_t links[KNET_MAX_LINK];
683 res = knet_handle_setfwd(instance->
knet_handle, 0);
688 res = knet_host_get_host_list(instance->
knet_handle, nodes, &num_nodes);
696 for (i=0; i<num_nodes; i++) {
698 res = knet_link_get_link_list(instance->
knet_handle, nodes[i], links, &num_links);
703 for (j=0; j<num_links; j++) {
704 res = knet_link_set_enable(instance->
knet_handle, nodes[i], links[j], 0);
708 res = knet_link_clear_config(instance->
knet_handle, nodes[i], links[j]);
713 res = knet_host_remove(instance->
knet_handle, nodes[i]);
725 totemknet_stop_merge_detect_timeout(instance);
727 log_flush_messages(instance);
732 (void)pthread_mutex_destroy(&instance->
log_mutex);
737static int log_deliver_fn (
743 char buffer[
sizeof(
struct knet_log_msg)*4];
744 char *bufptr = buffer;
748 len = read(fd, buffer,
sizeof(buffer));
750 struct knet_log_msg *msg = (
struct knet_log_msg *)bufptr;
751 switch (msg->msglevel) {
754 knet_log_get_subsystem_name(msg->subsystem),
759 knet_log_get_subsystem_name(msg->subsystem),
764 knet_log_get_subsystem_name(msg->subsystem),
769 knet_log_get_subsystem_name(msg->subsystem),
775 knet_log_get_subsystem_name(msg->subsystem),
780 bufptr +=
sizeof(
struct knet_log_msg);
781 done +=
sizeof(
struct knet_log_msg);
786static int data_deliver_fn (
792 struct msghdr msg_hdr;
793 struct iovec iov_recv;
796 int truncated_packet;
799 iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
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;
808#ifdef HAVE_MSGHDR_CONTROLLEN
809 msg_hdr.msg_controllen = 0;
811#ifdef HAVE_MSGHDR_FLAGS
812 msg_hdr.msg_flags = 0;
814#ifdef HAVE_MSGHDR_ACCRIGHTS
815 msg_hdr.msg_accrights = NULL;
817#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
818 msg_hdr.msg_accrightslen = 0;
821 msg_len = recvmsg (fd, &msg_hdr,
MSG_NOSIGNAL | MSG_DONTWAIT);
826 truncated_packet = 0;
828#ifdef HAVE_MSGHDR_FLAGS
829 if (msg_hdr.msg_flags & MSG_TRUNC) {
830 truncated_packet = 1;
837 if (bytes_received == KNET_MAX_PACKET_SIZE) {
838 truncated_packet = 1;
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 "
863static void timer_function_netif_check_timeout (
887#ifdef HAVE_KNET_ACCESS_LIST
904 int knet_log_mode = KNET_LOG_INFO;
915 switch (logsys_log_mode) {
917 knet_log_mode = KNET_LOG_INFO;
920 knet_log_mode = KNET_LOG_DEBUG;
924 knet_log_mode = KNET_LOG_TRACE;
926 knet_log_mode = KNET_LOG_DEBUG;
932 for (s = 0; s<KNET_MAX_SUBSYSTEMS; s++) {
944static void totemknet_refresh_config(
946 const char *key_name,
955 knet_node_id_t host_ids[KNET_MAX_HOST];
966 if (
icmap_get_uint8(
"config.totemconfig_reload_in_progress", &reloading) ==
CS_OK && reloading) {
970 after_reload = (strcmp(key_name,
"config.totemconfig_reload_in_progress") == 0);
972 knet_set_access_list_config(instance);
974 if (strcmp(key_name,
"totem.knet_pmtud_interval") == 0 || after_reload) {
983 if (strcmp(key_name,
"totem.knet_mtu") == 0 || after_reload) {
992 err = knet_host_get_host_list(instance->
knet_handle, host_ids, &num_nodes);
997 for (i=0; i<num_nodes; i++) {
1003 err = knet_link_set_ping_timers(instance->
knet_handle, host_ids[i], link_no,
1010 err = knet_link_set_pong_count(instance->
knet_handle, host_ids[i], link_no,
1015 err = knet_link_set_priority(instance->
knet_handle, host_ids[i], link_no,
1037 totemknet_refresh_config,
1039 &icmap_track_totem);
1043 totemknet_refresh_config,
1045 &icmap_track_reload);
1060 struct knet_handle_crypto_cfg crypto_cfg;
1070#ifdef HAVE_KNET_CRYPTO_RECONF
1073 crypto_cfg.crypto_model,
1074 crypto_cfg.crypto_cipher_type,
1075 crypto_cfg.crypto_hash_type,
1080 if (!totemknet_is_crypto_enabled(instance)) {
1081 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_ALLOW_CLEAR_TRAFFIC);
1099 crypto_cfg.crypto_model,
1100 crypto_cfg.crypto_cipher_type,
1101 crypto_cfg.crypto_hash_type
1104 res = knet_handle_crypto(instance->
knet_handle, &crypto_cfg);
1124 qb_loop_t *poll_handle,
1125 void **knet_context,
1133 unsigned int msg_len,
1136 int (*iface_change_fn) (
1139 unsigned int link_no),
1141 void (*mtu_changed) (
1145 void (*target_set_completed) (
1151 int allow_knet_handle_fallback=0;
1156 if (instance == NULL) {
1160 totemknet_instance_initialize (instance);
1210 if (fcntl(instance->
logpipes[0], F_SETFL, O_NONBLOCK) == -1 ||
1211 fcntl(instance->
logpipes[1], F_SETFL, O_NONBLOCK) == -1) {
1217 if (strcmp(tmp_str,
"yes") == 0) {
1218 allow_knet_handle_fallback = 1;
1223#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1229 if (allow_knet_handle_fallback && !instance->
knet_handle && errno == ENAMETOOLONG) {
1231#if defined(KNET_API_VER) && (KNET_API_VER == 2)
1243 knet_set_access_list_config(instance);
1253 res = knet_handle_enable_filter(instance->
knet_handle, instance, dst_host_filter_callback_fn);
1257 res = knet_handle_enable_sock_notify(instance->
knet_handle, instance, socket_error_callback_fn);
1261 res = knet_host_enable_status_change_notify(instance->
knet_handle, instance, host_change_callback_fn);
1265 res = knet_handle_enable_pmtud_notify(instance->
knet_handle, instance, pmtu_change_callback_fn);
1278 knet_log_printf(LOG_DEBUG,
"knet_handle_add_datafd failed: %s", strerror(errno));
1283#ifdef HAVE_KNET_CRYPTO_RECONF
1284 if (totemknet_is_crypto_enabled(instance)) {
1285 res = totemknet_set_knet_crypto(instance);
1289 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_use_config failed: %s", strerror(errno));
1296 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_DISALLOW_CLEAR_TRAFFIC);
1298 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_rx_clear_traffic (DISALLOW) failed: %s", strerror(errno));
1303 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_ALLOW_CLEAR_TRAFFIC);
1305 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_rx_clear_traffic (ALLOW) failed: %s", strerror(errno));
1310 if (totemknet_is_crypto_enabled(instance)) {
1311 res = totemknet_set_knet_crypto(instance);
1322 (void)totemknet_configure_compression(instance,
totem_config);
1327 instance->
link_mode = KNET_LINK_POLICY_PASSIVE;
1329 instance->
link_mode = KNET_LINK_POLICY_ACTIVE;
1332 instance->
link_mode = KNET_LINK_POLICY_RR;
1345 POLLIN, instance, log_deliver_fn);
1350 POLLIN, instance, data_deliver_fn);
1358 100*QB_TIME_NS_IN_MSEC,
1360 timer_function_netif_check_timeout,
1363 totemknet_start_merge_detect_timeout(instance);
1366 totemknet_add_config_notifications(instance);
1377 log_flush_messages(instance);
1385 return malloc(KNET_MAX_PACKET_SIZE + 512);
1395 int processor_count)
1413 unsigned int msg_len)
1418 ucast_sendmsg (instance, &instance->
token_target, msg, msg_len);
1425 unsigned int msg_len)
1430 mcast_sendmsg (instance, msg, msg_len, 0);
1438 unsigned int msg_len)
1443 mcast_sendmsg (instance, msg, msg_len, 1);
1486 struct msghdr msg_hdr;
1487 struct iovec iov_recv;
1490 int msg_processed = 0;
1493 iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
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;
1502#ifdef HAVE_MSGHDR_CONTROLLEN
1503 msg_hdr.msg_controllen = 0;
1505#ifdef HAVE_MSGHDR_FLAGS
1506 msg_hdr.msg_flags = 0;
1508#ifdef HAVE_MSGHDR_ACCRIGHTS
1509 msg_msg_hdr.msg_accrights = NULL;
1511#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1512 msg_msg_hdr.msg_accrightslen = 0;
1517 ufd.events = POLLIN;
1518 nfds = poll (&ufd, 1, 0);
1519 if (nfds == 1 && ufd.revents & POLLIN) {
1527 }
while (nfds == 1);
1529 return (msg_processed);
1534 unsigned short ip_port,
1535 unsigned int iface_no)
1557 int port = instance->
ip_port[link_no];
1558 struct sockaddr_storage remote_ss;
1559 struct sockaddr_storage local_ss;
1563 knet_node_id_t host_ids[KNET_MAX_HOST];
1564 size_t num_host_ids;
1582 err = knet_host_get_host_list(instance->
knet_handle, host_ids, &num_host_ids);
1587 for (i=0; i<num_host_ids; i++) {
1588 if (host_ids[i] == member->
nodeid) {
1595 if (err != 0 && errno != EEXIST) {
1611 memset(&local_ss, 0,
sizeof(local_ss));
1612 memset(&remote_ss, 0,
sizeof(remote_ss));
1621 KNET_TRANSPORT_LOOPBACK,
1622 &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1627 &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1655 int saved_errno = errno;
1656 log_flush_messages(instance);
1657 errno = saved_errno;
1665 int saved_errno = errno;
1666 log_flush_messages(instance);
1667 errno = saved_errno;
1691 uint8_t link_list[KNET_MAX_LINK];
1718 res = knet_link_get_link_list(instance->
knet_handle,
1724 if (num_links == 0) {
1737static int totemknet_configure_compression (
1741 struct knet_handle_compress_cfg compress_cfg;
1750 res = knet_handle_compress(instance->
knet_handle, &compress_cfg);
1764 (void)totemknet_configure_compression(instance,
totem_config);
1766#ifdef HAVE_LIBNOZZLE
1770 (void)setup_nozzle(instance);
1776 res = totemknet_set_knet_crypto(instance);
1792#ifdef HAVE_KNET_CRYPTO_RECONF
1795 int config_to_clear;
1796 struct knet_handle_crypto_cfg crypto_cfg;
1804 if (!totemknet_is_crypto_enabled(instance)) {
1809 res = knet_handle_crypto_use_config(instance->
knet_handle, config_to_use);
1823 strcpy(crypto_cfg.crypto_model,
"none");
1824 strcpy(crypto_cfg.crypto_cipher_type,
"none");
1825 strcpy(crypto_cfg.crypto_hash_type,
"none");
1826 res = knet_handle_crypto_set_config(instance->
knet_handle, &crypto_cfg, config_to_clear);
1835 if (totemknet_is_crypto_enabled(instance)) {
1836 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_DISALLOW_CLEAR_TRAFFIC);
1851 (void) knet_handle_clear_stats(instance->
knet_handle, KNET_CLEARSTATS_HANDLE_AND_LINK);
1856 knet_node_id_t node, uint8_t link_no,
1857 struct knet_link_status *status)
1893 struct knet_handle_stats *stats)
1910static void timer_function_merge_detect_timeout (
1921 totemknet_start_merge_detect_timeout(instance);
1924static void totemknet_start_merge_detect_timeout(
1933 timer_function_merge_detect_timeout,
1934 &instance->timer_merge_detect_timeout);
1938static void totemknet_stop_merge_detect_timeout(
1957 pfd.events = POLLIN;
1960 if ((poll(&pfd, 1, 0) > 0) &&
1961 (pfd.revents & POLLIN) &&
1962 (log_deliver_fn(instance->
logpipes[0], POLLIN, instance) == 0)) {
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"
1977#define NOZZLE_CHANNEL 1
1983 char filename[PATH_MAX + FILENAME_MAX + 1];
1984 static char updown_dirname[PATH_MAX + FILENAME_MAX + 1];
1986 const char *dirname_res;
1991 res = snprintf(filename,
sizeof(filename),
"%s",
1993 if (res >=
sizeof(filename)) {
1998 dirname_res = dirname(filename);
2000 res = snprintf(updown_dirname,
sizeof(updown_dirname),
"%s/%s",
2001 dirname_res,
"updown.d");
2002 if (res >=
sizeof(updown_dirname)) {
2006 return updown_dirname;
2018 res = nozzle_run_updown(instance->nozzle_handle,
type, &exec_string);
2019 if (res == -1 && errno != ENOENT) {
2021 }
else if (res == -2) {
2036 const char *input_addr,
2037 const char *prefix,
int nodeid,
2038 char *output_addr,
size_t output_len)
2042 int max_prefix = 64;
2043 uint32_t nodeid_mask;
2045 uint32_t masked_nodeid;
2046 struct in_addr *
addr;
2049 coloncolon = strstr(input_addr,
"::");
2054 bits = atoi(prefix);
2055 if (bits < 8 || bits > max_prefix) {
2062 memcpy(output_addr, input_addr, coloncolon-input_addr);
2063 sprintf(output_addr + (coloncolon-input_addr),
"::%x",
nodeid);
2070 nodeid_mask = UINT32_MAX & ((1<<(32 - bits)) - 1);
2071 addr_mask = UINT32_MAX ^ nodeid_mask;
2072 masked_nodeid =
nodeid & nodeid_mask;
2078 addr = (
struct in_addr *)&totemip.addr;
2079 addr->s_addr &= htonl(addr_mask);
2080 addr->s_addr |= htonl(masked_nodeid);
2082 inet_ntop(AF_INET,
addr, output_addr, output_len);
2086static int create_nozzle_device(
void *knet_context,
const char *name,
2087 const char *ipaddr,
const char *prefix,
2088 const char *macaddr)
2091 char device_name[IFNAMSIZ+1];
2092 size_t size = IFNAMSIZ;
2093 int8_t channel = NOZZLE_CHANNEL;
2094 nozzle_t nozzle_dev;
2098 char parsed_ipaddr[INET6_ADDRSTRLEN];
2101 memset(device_name, 0, size);
2102 memset(&mac, 0,
sizeof(mac));
2103 strncpy(device_name, name, size);
2108 nozzle_dev = nozzle_open(device_name, size, updown_dir);
2113 instance->nozzle_handle = nozzle_dev;
2115 if (nozzle_set_mac(nozzle_dev, macaddr) < 0) {
2120 if (reparse_nozzle_ip_address(instance, ipaddr, prefix, instance->
our_nodeid, parsed_ipaddr,
sizeof(parsed_ipaddr))) {
2125 if (nozzle_add_ip(nozzle_dev, parsed_ipaddr, prefix) < 0) {
2130 nozzle_fd = nozzle_get_fd(nozzle_dev);
2133 res = knet_handle_add_datafd(instance->
knet_handle, &nozzle_fd, &channel);
2139 run_nozzle_script(instance, NOZZLE_PREUP,
"pre-up");
2141 res = nozzle_set_up(nozzle_dev);
2146 run_nozzle_script(instance, NOZZLE_UP,
"up");
2151 nozzle_close(nozzle_dev);
2161 res = knet_handle_get_datafd(instance->
knet_handle, NOZZLE_CHANNEL, &datafd);
2167 res = knet_handle_remove_datafd(instance->
knet_handle, datafd);
2173 run_nozzle_script(instance, NOZZLE_DOWN,
"pre-down");
2174 res = nozzle_set_down(instance->nozzle_handle);
2179 run_nozzle_script(instance, NOZZLE_POSTDOWN,
"post-down");
2181 res = nozzle_close(instance->nozzle_handle);
2192 free(instance->nozzle_name);
2193 free(instance->nozzle_ipaddr);
2194 free(instance->nozzle_prefix);
2195 free(instance->nozzle_macaddr);
2197 instance->nozzle_name = instance->nozzle_ipaddr = instance->nozzle_prefix =
2198 instance->nozzle_macaddr = NULL;
2204 char *ipaddr_str = NULL;
2205 char *name_str = NULL;
2206 char *prefix_str = NULL;
2207 char *macaddr_str = NULL;
2224 remove_nozzle_device(instance);
2225 free_nozzle(instance);
2244 if (macaddr_str && strlen(macaddr_str) != 17) {
2249 macaddr_str = (
char*)
"54:54:01:00:00:00";
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)) {
2264 memcpy(mac, macaddr_str, 12);
2265 snprintf(mac+12,
sizeof(mac) - 13,
"%02x:%02x",
2270 if (name_res ==
CS_OK && name_str) {
2272 if (instance->nozzle_name) {
2273 remove_nozzle_device(instance);
2274 free_nozzle(instance);
2277 res = create_nozzle_device(
knet_context, name_str, ipaddr_str, prefix_str,
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) {
2292 free_nozzle(instance);
2300 if (macaddr_res ==
CS_OK) {
unsigned char addr[TOTEMIP_ADDRLEN]
#define PROCESSOR_COUNT_MAX
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
cs_error_t
The cs_error_t enum.
#define corosync_exit_error(err)
@ COROSYNC_DONE_MAINCONFIGREAD
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
#define ICMAP_TRACK_MODIFY
#define ICMAP_TRACK_DELETE
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.
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
#define LOGSYS_LEVEL_INFO
#define LOGSYS_LEVEL_CRIT
int logsys_config_debug_get(const char *subsys)
Return the debug flag for this subsys.
#define LOGSYS_DEBUG_TRACE
#define LOGSYS_LEVEL_WARNING
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
#define LOGSYS_LEVEL_DEBUG
#define LOGSYS_LEVEL_TRACE
const char * corosync_get_config_file(void)
Structure passed as new_value and old_value in change callback.
char crypto_model[CONFIG_STRING_LEN_MAX]
unsigned int private_key_len
uint32_t knet_compression_threshold
struct totem_logging_configuration totem_logging_configuration
struct totem_interface * interfaces
unsigned int merge_timeout
int knet_compression_level
char knet_compression_model[CONFIG_STRING_LEN_MAX]
unsigned int block_unlisted_ips
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
unsigned int knet_pmtud_interval
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
char link_mode[TOTEM_LINK_MODE_BYTES]
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
struct totem_ip_address boundto
struct totem_ip_address bindnet
The totem_ip_address struct.
void(* log_printf)(int level, int subsys, const char *function_name, const char *file_name, int file_line, const char *format,...) __attribute__((format(printf
struct knet_link_status link_status[KNET_MAX_LINK]
void(* totemknet_target_set_completed)(void *context)
pthread_mutex_t log_mutex
void(* totemknet_mtu_changed)(void *context, int net_mtu)
struct crypto_instance * crypto_inst
struct totem_config * totem_config
qb_loop_timer_handle timer_netif_check_timeout
char * link_status[INTERFACE_MAX]
void(* totemknet_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
knet_handle_t knet_handle
uint16_t ip_port[INTERFACE_MAX]
int(* totemknet_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no)
int totemknet_log_level_debug
struct totem_ip_address token_target
qb_loop_timer_handle timer_merge_detect_timeout
void(*) void knet_context)
int totemknet_log_level_warning
struct totem_ip_address my_ids[INTERFACE_MAX]
int(* totemknet_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
char iov_buffer[KNET_MAX_PACKET_SIZE]
unsigned int merge_detect_messages_sent_before_timeout
int send_merge_detect_message
int totemknet_log_level_error
int totemknet_log_level_security
int totemknet_log_level_notice
struct totemknet_instance * instance
cfg_message_crypto_reconfig_phase_t
@ CRYPTO_RECONFIG_PHASE_CLEANUP
@ CRYPTO_RECONFIG_PHASE_ACTIVATE
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
const char * totemip_print(const struct totem_ip_address *addr)
int totemknet_mcast_flush_send(void *knet_context, const void *msg, unsigned int msg_len)
int totemknet_iface_set(void *knet_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
int totemknet_finalize(void *knet_context)
int totemknet_recv_flush(void *knet_context)
int totemknet_member_list_rebind_ip(void *knet_context)
void * totemknet_buffer_alloc(void)
int totemknet_processor_count_set(void *knet_context, int processor_count)
int totemknet_mcast_noflush_send(void *knet_context, const void *msg, unsigned int msg_len)
struct totemknet_instance * global_instance
void totemknet_buffer_release(void *ptr)
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))
int totemknet_ifaces_get(void *knet_context, char ***status, unsigned int *iface_count)
int totemknet_member_add(void *knet_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int link_no)
int totemknet_crypto_set(void *knet_context, const char *cipher_type, const char *hash_type)
int totemknet_member_remove(void *knet_context, const struct totem_ip_address *token_target, int link_no)
int totemknet_token_send(void *knet_context, const void *msg, unsigned int msg_len)
#define CFG_INTERFACE_STATUS_MAX_LEN
int totemknet_link_get_status(knet_node_id_t node, uint8_t link_no, struct knet_link_status *status)
void totemknet_configure_log_level()
int totemknet_nodestatus_get(void *knet_context, unsigned int nodeid, struct totem_node_status *node_status)
int totemknet_handle_get_stats(struct knet_handle_stats *stats)
void totemknet_stats_clear(void *knet_context)
int totemknet_send_flush(void *knet_context)
void totemknet_net_mtu_adjust(void *knet_context, struct totem_config *totem_config)
#define knet_log_printf(level, format, args...)
int totemknet_token_target_set(void *knet_context, unsigned int nodeid)
#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...)
int totemknet_reconfigure(void *knet_context, struct totem_config *totem_config)
int totemknet_crypto_reconfigure_phase(void *knet_context, struct totem_config *totem_config, cfg_message_crypto_reconfig_phase_t phase)
#define libknet_log_printf(level, format, args...)
int totemknet_recv_mcast_empty(void *knet_context)
int totemknet_iface_check(void *knet_context)
struct totem_message_header header
struct srp_addr system_from
void stats_knet_add_handle(void)
void stats_knet_del_member(knet_node_id_t nodeid, uint8_t link)
void stats_knet_add_member(knet_node_id_t nodeid, uint8_t link)