39 #include <sys/types.h> 41 #include <sys/socket.h> 44 #include <sys/ioctl.h> 45 #include <sys/param.h> 46 #include <netinet/in.h> 47 #include <net/ethernet.h> 48 #include <arpa/inet.h> 62 #include <qb/qbdefs.h> 63 #include <qb/qbloop.h> 66 #include <libnozzle.h> 83 #define MSG_NOSIGNAL 0 87 static 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,
177 #ifdef HAVE_LIBNOZZLE 181 char *nozzle_macaddr;
182 nozzle_t nozzle_handle;
199 static int totemknet_configure_compression (
203 static void totemknet_start_merge_detect_timeout(
206 static void totemknet_stop_merge_detect_timeout(
209 static 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); \ 260 #ifdef HAVE_LIBNOZZLE 261 static inline int is_ether_addr_multicast(
const uint8_t *
addr)
263 return (addr[0] & 0x01);
265 static inline int is_ether_addr_zero(
const uint8_t *
addr)
267 return (!addr[0] && !addr[1] && !addr[2] && !addr[3] && !addr[4] && !addr[5]);
270 static 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;
300 static 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)
313 #ifdef HAVE_LIBNOZZLE 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;
336 static 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);
346 static void host_change_callback_fn(
void *private_data, knet_node_id_t host_id, uint8_t reachable, uint8_t remote, uint8_t external)
354 static void pmtu_change_callback_fn(
void *private_data,
unsigned int data_mtu)
365 const char *cipher_type,
366 const char *hash_type)
372 static 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)");
422 static 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;
477 static 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);
543 for (i=0; i < num_links; i++) {
551 sizeof(link_status));
553 node_status->
link_status[i].enabled = link_status.enabled;
554 node_status->
link_status[i].connected = link_status.connected;
555 node_status->
link_status[i].dynconnected = link_status.dynconnected;
557 memcpy(node_status->
link_status[i].src_ipaddr, link_status.src_ipaddr, KNET_MAX_HOST_LEN);
558 memcpy(node_status->
link_status[i].dst_ipaddr, link_status.dst_ipaddr, KNET_MAX_HOST_LEN);
570 unsigned int *iface_count)
573 struct knet_link_status link_status;
574 knet_node_id_t host_list[KNET_MAX_HOST];
575 uint8_t link_list[KNET_MAX_LINK];
590 res = knet_host_get_host_list(instance->
knet_handle,
591 host_list, &num_hosts);
595 qsort(host_list, num_hosts,
sizeof(uint16_t), node_compare);
597 for (j=0; j<num_hosts; j++) {
615 for (j=0; j<num_hosts; j++) {
620 res = knet_link_get_link_list(instance->
knet_handle,
621 host_list[j], link_list, &num_links);
627 for (i=0; i < num_links; i++) {
642 sizeof(link_status));
644 ptr[j] =
'0' + (link_status.enabled |
645 link_status.connected<<1 |
646 link_status.dynconnected<<2);
650 "totemknet_ifaces_get: Cannot get link status: %s", strerror(errno));
669 static knet_node_id_t nodes[KNET_MAX_HOST];
670 uint8_t links[KNET_MAX_LINK];
682 res = knet_handle_setfwd(instance->
knet_handle, 0);
687 res = knet_host_get_host_list(instance->
knet_handle, nodes, &num_nodes);
695 for (i=0; i<num_nodes; i++) {
697 res = knet_link_get_link_list(instance->
knet_handle, nodes[i], links, &num_links);
702 for (j=0; j<num_links; j++) {
703 res = knet_link_set_enable(instance->
knet_handle, nodes[i], links[j], 0);
707 res = knet_link_clear_config(instance->
knet_handle, nodes[i], links[j]);
712 res = knet_host_remove(instance->
knet_handle, nodes[i]);
724 totemknet_stop_merge_detect_timeout(instance);
726 log_flush_messages(instance);
731 (void)pthread_mutex_destroy(&instance->
log_mutex);
736 static int log_deliver_fn (
742 char buffer[
sizeof(
struct knet_log_msg)*4];
743 char *bufptr = buffer;
747 len = read(fd, buffer,
sizeof(buffer));
749 struct knet_log_msg *msg = (
struct knet_log_msg *)bufptr;
750 switch (msg->msglevel) {
753 knet_log_get_subsystem_name(msg->subsystem),
758 knet_log_get_subsystem_name(msg->subsystem),
763 knet_log_get_subsystem_name(msg->subsystem),
768 knet_log_get_subsystem_name(msg->subsystem),
772 bufptr +=
sizeof(
struct knet_log_msg);
773 done +=
sizeof(
struct knet_log_msg);
778 static int data_deliver_fn (
784 struct msghdr msg_hdr;
785 struct iovec iov_recv;
786 struct sockaddr_storage system_from;
788 int truncated_packet;
791 iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
794 msg_hdr.msg_namelen =
sizeof (
struct sockaddr_storage);
795 msg_hdr.msg_iov = &iov_recv;
796 msg_hdr.msg_iovlen = 1;
797 #ifdef HAVE_MSGHDR_CONTROL 798 msg_hdr.msg_control = 0;
800 #ifdef HAVE_MSGHDR_CONTROLLEN 801 msg_hdr.msg_controllen = 0;
803 #ifdef HAVE_MSGHDR_FLAGS 804 msg_hdr.msg_flags = 0;
806 #ifdef HAVE_MSGHDR_ACCRIGHTS 807 msg_hdr.msg_accrights = NULL;
809 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN 810 msg_hdr.msg_accrightslen = 0;
813 msg_len = recvmsg (fd, &msg_hdr,
MSG_NOSIGNAL | MSG_DONTWAIT);
818 truncated_packet = 0;
820 #ifdef HAVE_MSGHDR_FLAGS 821 if (msg_hdr.msg_flags & MSG_TRUNC) {
822 truncated_packet = 1;
829 if (bytes_received == KNET_MAX_PACKET_SIZE) {
830 truncated_packet = 1;
834 if (truncated_packet) {
836 "Received too big message. This may be because something bad is happening" 837 "on the network (attack?), or you tried join more nodes than corosync is" 838 "compiled with (%u) or bug in the code (bad estimation of " 855 static void timer_function_netif_check_timeout (
873 #ifdef HAVE_KNET_ACCESS_LIST 880 err = knet_handle_enable_access_lists(instance->
knet_handle, value);
889 static void totemknet_refresh_config(
891 const char *key_name,
900 knet_node_id_t host_ids[KNET_MAX_HOST];
911 if (
icmap_get_uint8(
"config.totemconfig_reload_in_progress", &reloading) ==
CS_OK && reloading) {
915 knet_set_access_list_config(instance);
928 err = knet_host_get_host_list(instance->
knet_handle, host_ids, &num_nodes);
933 for (i=0; i<num_nodes; i++) {
939 err = knet_link_set_ping_timers(instance->
knet_handle, host_ids[i], link_no,
946 err = knet_link_set_pong_count(instance->
knet_handle, host_ids[i], link_no,
951 err = knet_link_set_priority(instance->
knet_handle, host_ids[i], link_no,
972 totemknet_refresh_config,
978 totemknet_refresh_config,
980 &icmap_track_reload);
995 struct knet_handle_crypto_cfg crypto_cfg;
1005 #ifdef HAVE_KNET_CRYPTO_RECONF 1008 crypto_cfg.crypto_model,
1009 crypto_cfg.crypto_cipher_type,
1010 crypto_cfg.crypto_hash_type,
1015 if (!totemknet_is_crypto_enabled(instance)) {
1016 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_ALLOW_CLEAR_TRAFFIC);
1034 crypto_cfg.crypto_model,
1035 crypto_cfg.crypto_cipher_type,
1036 crypto_cfg.crypto_hash_type
1039 res = knet_handle_crypto(instance->
knet_handle, &crypto_cfg);
1059 qb_loop_t *poll_handle,
1065 void (*deliver_fn) (
1068 unsigned int msg_len,
1071 void (*iface_change_fn) (
1074 unsigned int link_no),
1076 void (*mtu_changed) (
1080 void (*target_set_completed) (
1086 int allow_knet_handle_fallback=0;
1091 if (instance == NULL) {
1095 totemknet_instance_initialize (instance);
1145 if (fcntl(instance->
logpipes[0], F_SETFL, O_NONBLOCK) == -1 ||
1146 fcntl(instance->
logpipes[1], F_SETFL, O_NONBLOCK) == -1) {
1152 if (strcmp(tmp_str,
"yes") == 0) {
1153 allow_knet_handle_fallback = 1;
1158 #if defined(KNET_API_VER) && (KNET_API_VER == 2) 1164 if (allow_knet_handle_fallback && !instance->
knet_handle && errno == ENAMETOOLONG) {
1166 #if defined(KNET_API_VER) && (KNET_API_VER == 2) 1178 knet_set_access_list_config(instance);
1184 res = knet_handle_enable_filter(instance->
knet_handle, instance, dst_host_filter_callback_fn);
1188 res = knet_handle_enable_sock_notify(instance->
knet_handle, instance, socket_error_callback_fn);
1192 res = knet_host_enable_status_change_notify(instance->
knet_handle, instance, host_change_callback_fn);
1196 res = knet_handle_enable_pmtud_notify(instance->
knet_handle, instance, pmtu_change_callback_fn);
1200 global_instance = instance;
1206 knet_log_printf(LOG_DEBUG,
"knet_handle_add_datafd failed: %s", strerror(errno));
1211 #ifdef HAVE_KNET_CRYPTO_RECONF 1212 if (totemknet_is_crypto_enabled(instance)) {
1213 res = totemknet_set_knet_crypto(instance);
1217 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_use_config failed: %s", strerror(errno));
1224 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_DISALLOW_CLEAR_TRAFFIC);
1226 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_rx_clear_traffic (DISALLOW) failed: %s", strerror(errno));
1231 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_ALLOW_CLEAR_TRAFFIC);
1233 knet_log_printf(LOG_DEBUG,
"knet_handle_crypto_rx_clear_traffic (ALLOW) failed: %s", strerror(errno));
1238 if (totemknet_is_crypto_enabled(instance)) {
1239 res = totemknet_set_knet_crypto(instance);
1250 (void)totemknet_configure_compression(instance, totem_config);
1255 instance->
link_mode = KNET_LINK_POLICY_PASSIVE;
1257 instance->
link_mode = KNET_LINK_POLICY_ACTIVE;
1260 instance->
link_mode = KNET_LINK_POLICY_RR;
1273 POLLIN, instance, log_deliver_fn);
1278 POLLIN, instance, data_deliver_fn);
1286 100*QB_TIME_NS_IN_MSEC,
1288 timer_function_netif_check_timeout,
1289 &instance->timer_netif_check_timeout);
1291 totemknet_start_merge_detect_timeout(instance);
1294 totemknet_add_config_notifications(instance);
1300 *knet_context = instance;
1305 log_flush_messages(instance);
1313 return malloc(KNET_MAX_PACKET_SIZE + 512);
1323 int processor_count)
1341 unsigned int msg_len)
1346 ucast_sendmsg (instance, &instance->
token_target, msg, msg_len);
1353 unsigned int msg_len)
1358 mcast_sendmsg (instance, msg, msg_len, 0);
1366 unsigned int msg_len)
1371 mcast_sendmsg (instance, msg, msg_len, 1);
1413 struct sockaddr_storage system_from;
1414 struct msghdr msg_hdr;
1415 struct iovec iov_recv;
1418 int msg_processed = 0;
1421 iov_recv.iov_len = KNET_MAX_PACKET_SIZE;
1424 msg_hdr.msg_namelen =
sizeof (
struct sockaddr_storage);
1425 msg_hdr.msg_iov = &iov_recv;
1426 msg_hdr.msg_iovlen = 1;
1427 #ifdef HAVE_MSGHDR_CONTROL 1428 msg_hdr.msg_control = 0;
1430 #ifdef HAVE_MSGHDR_CONTROLLEN 1431 msg_hdr.msg_controllen = 0;
1433 #ifdef HAVE_MSGHDR_FLAGS 1434 msg_hdr.msg_flags = 0;
1436 #ifdef HAVE_MSGHDR_ACCRIGHTS 1437 msg_msg_hdr.msg_accrights = NULL;
1439 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN 1440 msg_msg_hdr.msg_accrightslen = 0;
1445 ufd.events = POLLIN;
1446 nfds = poll (&ufd, 1, 0);
1447 if (nfds == 1 && ufd.revents & POLLIN) {
1455 }
while (nfds == 1);
1457 return (msg_processed);
1463 unsigned int iface_no)
1485 int port = instance->
ip_port[link_no];
1486 struct sockaddr_storage remote_ss;
1487 struct sockaddr_storage local_ss;
1491 knet_node_id_t host_ids[KNET_MAX_HOST];
1492 size_t num_host_ids;
1510 err = knet_host_get_host_list(instance->
knet_handle, host_ids, &num_host_ids);
1515 for (i=0; i<num_host_ids; i++) {
1516 if (host_ids[i] == member->
nodeid) {
1523 if (err != 0 && errno != EEXIST) {
1539 memset(&local_ss, 0,
sizeof(local_ss));
1540 memset(&remote_ss, 0,
sizeof(remote_ss));
1549 KNET_TRANSPORT_LOOPBACK,
1550 &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1555 &local_ss, &remote_ss, KNET_LINK_FLAG_TRAFFICHIPRIO);
1606 uint8_t link_list[KNET_MAX_LINK];
1620 res = knet_link_set_enable(instance->
knet_handle, token_target->
nodeid, link_no, 0);
1626 res = knet_link_clear_config(instance->
knet_handle, token_target->
nodeid, link_no);
1633 res = knet_link_get_link_list(instance->
knet_handle,
1634 token_target->
nodeid, link_list, &num_links);
1639 if (num_links == 0) {
1652 static int totemknet_configure_compression (
1654 struct totem_config *totem_config)
1656 struct knet_handle_compress_cfg compress_cfg;
1665 res = knet_handle_compress(instance->
knet_handle, &compress_cfg);
1674 struct totem_config *totem_config)
1679 (void)totemknet_configure_compression(instance, totem_config);
1681 #ifdef HAVE_LIBNOZZLE 1685 (void)setup_nozzle(instance);
1691 res = totemknet_set_knet_crypto(instance);
1704 struct totem_config *totem_config,
1707 #ifdef HAVE_KNET_CRYPTO_RECONF 1710 int config_to_clear;
1711 struct knet_handle_crypto_cfg crypto_cfg;
1719 if (!totemknet_is_crypto_enabled(instance)) {
1724 res = knet_handle_crypto_use_config(instance->
knet_handle, config_to_use);
1738 strcpy(crypto_cfg.crypto_model,
"none");
1739 strcpy(crypto_cfg.crypto_cipher_type,
"none");
1740 strcpy(crypto_cfg.crypto_hash_type,
"none");
1741 res = knet_handle_crypto_set_config(instance->
knet_handle, &crypto_cfg, config_to_clear);
1750 if (totemknet_is_crypto_enabled(instance)) {
1751 res = knet_handle_crypto_rx_clear_traffic(instance->
knet_handle, KNET_CRYPTO_RX_DISALLOW_CLEAR_TRAFFIC);
1766 (void) knet_handle_clear_stats(instance->
knet_handle, KNET_CLEARSTATS_HANDLE_AND_LINK);
1771 knet_node_id_t node, uint8_t link_no,
1772 struct knet_link_status *status)
1778 if (!global_instance) {
1786 res = knet_link_get_status(global_instance->
knet_handle, node, link_no, status,
sizeof(
struct knet_link_status));
1808 struct knet_handle_stats *stats)
1813 if (!global_instance) {
1817 res = knet_handle_get_stats(global_instance->
knet_handle, stats,
sizeof(
struct knet_handle_stats));
1825 static void timer_function_merge_detect_timeout (
1836 totemknet_start_merge_detect_timeout(instance);
1839 static void totemknet_start_merge_detect_timeout(
1848 timer_function_merge_detect_timeout,
1849 &instance->timer_merge_detect_timeout);
1853 static void totemknet_stop_merge_detect_timeout(
1862 static void log_flush_messages (
void *knet_context)
1872 pfd.events = POLLIN;
1875 if ((poll(&pfd, 1, 0) > 0) &&
1876 (pfd.revents & POLLIN) &&
1877 (log_deliver_fn(instance->
logpipes[0], POLLIN, instance) == 0)) {
1886 #ifdef HAVE_LIBNOZZLE 1887 #define NOZZLE_NAME "nozzle.name" 1888 #define NOZZLE_IPADDR "nozzle.ipaddr" 1889 #define NOZZLE_PREFIX "nozzle.ipprefix" 1890 #define NOZZLE_MACADDR "nozzle.macaddr" 1892 #define NOZZLE_CHANNEL 1 1895 static char *get_nozzle_script_dir(
void *knet_context)
1898 char filename[PATH_MAX + FILENAME_MAX + 1];
1899 static char updown_dirname[PATH_MAX + FILENAME_MAX + 1];
1901 const char *dirname_res;
1906 res = snprintf(filename,
sizeof(filename),
"%s",
1908 if (res >=
sizeof(filename)) {
1913 dirname_res = dirname(filename);
1915 res = snprintf(updown_dirname,
sizeof(updown_dirname),
"%s/%s",
1916 dirname_res,
"updown.d");
1917 if (res >=
sizeof(updown_dirname)) {
1921 return updown_dirname;
1933 res = nozzle_run_updown(instance->nozzle_handle, type, &exec_string);
1934 if (res == -1 && errno != ENOENT) {
1936 }
else if (res == -2) {
1951 const char *input_addr,
1952 const char *prefix,
int nodeid,
1953 char *output_addr,
size_t output_len)
1957 int max_prefix = 64;
1958 uint32_t nodeid_mask;
1960 uint32_t masked_nodeid;
1961 struct in_addr *
addr;
1964 coloncolon = strstr(input_addr,
"::");
1969 bits = atoi(prefix);
1970 if (bits < 8 || bits > max_prefix) {
1977 memcpy(output_addr, input_addr, coloncolon-input_addr);
1978 sprintf(output_addr + (coloncolon-input_addr),
"::%x", nodeid);
1985 nodeid_mask = UINT32_MAX & ((1<<(32 - bits)) - 1);
1986 addr_mask = UINT32_MAX ^ nodeid_mask;
1987 masked_nodeid = nodeid & nodeid_mask;
1993 addr = (
struct in_addr *)&totemip.
addr;
1994 addr->s_addr &= htonl(addr_mask);
1995 addr->s_addr |= htonl(masked_nodeid);
1997 inet_ntop(AF_INET, addr, output_addr, output_len);
2001 static int create_nozzle_device(
void *knet_context,
const char *name,
2002 const char *ipaddr,
const char *prefix,
2003 const char *macaddr)
2006 char device_name[IFNAMSIZ+1];
2007 size_t size = IFNAMSIZ;
2008 int8_t channel = NOZZLE_CHANNEL;
2009 nozzle_t nozzle_dev;
2013 char parsed_ipaddr[INET6_ADDRSTRLEN];
2016 memset(device_name, 0, size);
2017 memset(&mac, 0,
sizeof(mac));
2018 strncpy(device_name, name, size);
2020 updown_dir = get_nozzle_script_dir(knet_context);
2023 nozzle_dev = nozzle_open(device_name, size, updown_dir);
2028 instance->nozzle_handle = nozzle_dev;
2030 if (nozzle_set_mac(nozzle_dev, macaddr) < 0) {
2035 if (reparse_nozzle_ip_address(instance, ipaddr, prefix, instance->
our_nodeid, parsed_ipaddr,
sizeof(parsed_ipaddr))) {
2040 if (nozzle_add_ip(nozzle_dev, parsed_ipaddr, prefix) < 0) {
2045 nozzle_fd = nozzle_get_fd(nozzle_dev);
2048 res = knet_handle_add_datafd(instance->
knet_handle, &nozzle_fd, &channel);
2054 run_nozzle_script(instance, NOZZLE_PREUP,
"pre-up");
2056 res = nozzle_set_up(nozzle_dev);
2061 run_nozzle_script(instance, NOZZLE_UP,
"up");
2066 nozzle_close(nozzle_dev);
2070 static int remove_nozzle_device(
void *knet_context)
2076 res = knet_handle_get_datafd(instance->
knet_handle, NOZZLE_CHANNEL, &datafd);
2082 res = knet_handle_remove_datafd(instance->
knet_handle, datafd);
2088 run_nozzle_script(instance, NOZZLE_DOWN,
"pre-down");
2089 res = nozzle_set_down(instance->nozzle_handle);
2094 run_nozzle_script(instance, NOZZLE_POSTDOWN,
"post-down");
2096 res = nozzle_close(instance->nozzle_handle);
2107 free(instance->nozzle_name);
2108 free(instance->nozzle_ipaddr);
2109 free(instance->nozzle_prefix);
2110 free(instance->nozzle_macaddr);
2112 instance->nozzle_name = instance->nozzle_ipaddr = instance->nozzle_prefix =
2113 instance->nozzle_macaddr = NULL;
2116 static int setup_nozzle(
void *knet_context)
2119 char *ipaddr_str = NULL;
2120 char *name_str = NULL;
2121 char *prefix_str = NULL;
2122 char *macaddr_str = NULL;
2139 remove_nozzle_device(instance);
2140 free_nozzle(instance);
2159 if (macaddr_str && strlen(macaddr_str) != 17) {
2164 macaddr_str = (
char*)
"54:54:01:00:00:00";
2167 if (instance->nozzle_name &&
2168 (strcmp(name_str, instance->nozzle_name) == 0) &&
2169 (strcmp(ipaddr_str, instance->nozzle_ipaddr) == 0) &&
2170 (strcmp(prefix_str, instance->nozzle_prefix) == 0) &&
2171 (instance->nozzle_macaddr == NULL ||
2172 strcmp(macaddr_str, instance->nozzle_macaddr) == 0)) {
2179 memcpy(mac, macaddr_str, 12);
2180 snprintf(mac+12,
sizeof(mac) - 13,
"%02x:%02x",
2185 if (name_res ==
CS_OK && name_str) {
2187 if (instance->nozzle_name) {
2188 remove_nozzle_device(instance);
2189 free_nozzle(instance);
2192 res = create_nozzle_device(knet_context, name_str, ipaddr_str, prefix_str,
2195 instance->nozzle_name = strdup(name_str);
2196 instance->nozzle_ipaddr = strdup(ipaddr_str);
2197 instance->nozzle_prefix = strdup(prefix_str);
2198 instance->nozzle_macaddr = strdup(macaddr_str);
2199 if (!instance->nozzle_name || !instance->nozzle_ipaddr ||
2200 !instance->nozzle_prefix) {
2207 free_nozzle(instance);
2215 if (macaddr_res ==
CS_OK) {
2221 #endif // HAVE_LIBNOZZLE
uint16_t ip_port[INTERFACE_MAX]
char knet_compression_model[CONFIG_STRING_LEN_MAX]
int totemknet_log_level_security
cfg_message_crypto_reconfig_phase_t
char * link_status[INTERFACE_MAX]
int totemknet_member_remove(void *knet_context, const struct totem_ip_address *token_target, int link_no)
struct knet_link_status link_status[KNET_MAX_LINK]
#define LOGSYS_LEVEL_INFO
qb_loop_timer_handle timer_merge_detect_timeout
struct totem_interface * interfaces
void stats_knet_add_handle(void)
int totemknet_log_level_error
unsigned int merge_detect_messages_sent_before_timeout
#define libknet_log_printf(level, format, args...)
struct totem_ip_address my_ids[INTERFACE_MAX]
The totem_ip_address struct.
#define CFG_INTERFACE_STATUS_MAX_LEN
const char * totemip_print(const struct totem_ip_address *addr)
unsigned char addr[TOTEMIP_ADDRLEN]
#define knet_log_printf(level, format, args...)
int send_merge_detect_message
int totemknet_finalize(void *knet_context)
uint32_t knet_compression_threshold
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
void(* totemknet_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int link_no)
char link_mode[TOTEM_LINK_MODE_BYTES]
unsigned int knet_pmtud_interval
unsigned char addr[TOTEMIP_ADDRLEN]
int totemknet_link_get_status(knet_node_id_t node, uint8_t link_no, struct knet_link_status *status)
void totemknet_buffer_release(void *ptr)
void totemknet_stats_clear(void *knet_context)
#define KNET_LOGSYS_PERROR(err_num, level, fmt, args...)
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
void stats_knet_del_member(knet_node_id_t nodeid, uint8_t link)
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
unsigned int private_key_len
int totemknet_log_level_notice
#define ICMAP_TRACK_DELETE
int totemknet_crypto_set(void *knet_context, const char *cipher_type, const char *hash_type)
unsigned int block_unlisted_ips
qb_loop_timer_handle timer_netif_check_timeout
int totemknet_mcast_flush_send(void *knet_context, const void *msg, unsigned int msg_len)
int totemknet_iface_check(void *knet_context)
void(*) void knet_context)
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
#define LOGSYS_LEVEL_WARNING
#define ICMAP_TRACK_MODIFY
int totemknet_log_level_warning
const char * corosync_get_config_file(void)
int totemknet_token_target_set(void *knet_context, unsigned int nodeid)
struct totem_config * totem_config
int totemknet_reconfigure(void *knet_context, struct totem_config *totem_config)
int totemknet_iface_set(void *knet_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
int totemknet_processor_count_set(void *knet_context, int processor_count)
#define LOGSYS_LEVEL_ERROR
int totemknet_recv_flush(void *knet_context)
int totemknet_send_flush(void *knet_context)
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
cs_error_t
The cs_error_t enum.
#define LOGSYS_LEVEL_DEBUG
int totemknet_crypto_reconfigure_phase(void *knet_context, struct totem_config *totem_config, cfg_message_crypto_reconfig_phase_t phase)
struct totem_ip_address boundto
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
char iov_buffer[KNET_MAX_PACKET_SIZE]
void(* log_printf)(int level, int subsys, const char *function_name, const char *file_name, int file_line, const char *format,...) __attribute__((format(printf
int totemknet_handle_get_stats(struct knet_handle_stats *stats)
struct totemknet_instance * global_instance
struct totem_message_header header
int knet_compression_level
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
struct crypto_instance * crypto_inst
void(* totemknet_target_set_completed)(void *context)
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
struct totem_ip_address token_target
#define PROCESSOR_COUNT_MAX
pthread_mutex_t log_mutex
char crypto_model[CONFIG_STRING_LEN_MAX]
int totemknet_member_add(void *knet_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int link_no)
struct totemknet_instance * instance
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define LOGSYS_LEVEL_CRIT
void(* totemknet_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
void(* totemknet_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
struct totem_logging_configuration totem_logging_configuration
void(* totemknet_mtu_changed)(void *context, int net_mtu)
void stats_knet_add_member(knet_node_id_t nodeid, uint8_t link)
struct srp_addr system_from
void totemknet_net_mtu_adjust(void *knet_context, struct totem_config *totem_config)
int totemknet_member_list_rebind_ip(void *knet_context)
unsigned int merge_timeout
int totemknet_mcast_noflush_send(void *knet_context, const void *msg, unsigned int msg_len)
int totemknet_log_level_debug
int totemknet_token_send(void *knet_context, const void *msg, unsigned int msg_len)
struct totem_ip_address bindnet
int totemknet_recv_mcast_empty(void *knet_context)
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
int totemknet_nodestatus_get(void *knet_context, unsigned int nodeid, struct totem_node_status *node_status)
int totemknet_initialize(qb_loop_t *poll_handle, void **knet_context, struct totem_config *totem_config, totemsrp_stats_t *stats, void *context, void(*deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from), void(*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)
Structure passed as new_value and old_value in change callback.
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.nodeid", "totem.version", ...
void * totemknet_buffer_alloc(void)
knet_handle_t knet_handle