42#include <sys/socket.h>
47#include <netinet/in.h>
67#define LOGSYS_UTILS_ONLY 1
77#define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * UDP_RECEIVE_FRAME_SIZE_MAX)
78#define NETIF_STATE_REPORT_UP 1
79#define NETIF_STATE_REPORT_DOWN 2
81#define BIND_STATE_UNBOUND 0
82#define BIND_STATE_REGULAR 1
83#define BIND_STATE_LOOPBACK 2
106 unsigned int msg_len,
191static int totemudpu_build_sockets (
196static int totemudpu_create_sending_socket(
203static void totemudpu_start_merge_detect_timeout(
206static void totemudpu_stop_merge_detect_timeout(
227#define log_printf(level, format, args...) \
229 instance->totemudpu_log_printf ( \
230 level, instance->totemudpu_subsys_id, \
231 __FUNCTION__, __FILE__, __LINE__, \
232 (const char *)format, ##args); \
234#define LOGSYS_PERROR(err_num, level, fmt, args...) \
236 char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
237 const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
238 instance->totemudpu_log_printf ( \
239 level, instance->totemudpu_subsys_id, \
240 __FUNCTION__, __FILE__, __LINE__, \
241 fmt ": %s (%d)", ##args, _error_ptr, err_num); \
254static inline void ucast_sendmsg (
258 unsigned int msg_len)
267 iovec.iov_base = (
void *)msg;
268 iovec.iov_len = msg_len;
280#ifdef HAVE_MSGHDR_CONTROL
283#ifdef HAVE_MSGHDR_CONTROLLEN
286#ifdef HAVE_MSGHDR_FLAGS
289#ifdef HAVE_MSGHDR_ACCRIGHTS
292#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
312 "sendmsg(ucast) failed (non-critical)");
316static inline void mcast_sendmsg (
319 unsigned int msg_len,
330 iovec.iov_base = (
void *)msg;
331 iovec.iov_len = msg_len;
355 #ifdef HAVE_MSGHDR_CONTROL
358 #ifdef HAVE_MSGHDR_CONTROLLEN
361 #ifdef HAVE_MSGHDR_FLAGS
364 #ifdef HAVE_MSGHDR_ACCRIGHTS
367 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
378 "sendmsg(mcast) failed (non-critical)");
398 #ifdef HAVE_MSGHDR_CONTROL
401 #ifdef HAVE_MSGHDR_CONTROLLEN
404 #ifdef HAVE_MSGHDR_FLAGS
407 #ifdef HAVE_MSGHDR_ACCRIGHTS
410 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
418 "sendmsg(local mcast loop) failed (non-critical)");
442 totemudpu_stop_merge_detect_timeout(instance);
448 const void *udpu_context,
473static int net_deliver_fn (
494#ifdef HAVE_MSGHDR_CONTROL
497#ifdef HAVE_MSGHDR_CONTROLLEN
500#ifdef HAVE_MSGHDR_FLAGS
503#ifdef HAVE_MSGHDR_ACCRIGHTS
506#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
519#ifdef HAVE_MSGHDR_FLAGS
535 "Received too big message. This may be because something bad is happening"
536 "on the network (attack?), or you tried join more nodes than corosync is"
537 "compiled with (%u) or bug in the code (bad estimation of "
566static int netif_determine (
576 interface_up, interface_num,
588static void timer_function_netif_check_timeout (
598 netif_determine (instance,
601 &interface_up, &interface_num);
607 interface_up == 0) ||
611 interface_up == 1)) {
617 timer_function_netif_check_timeout,
618 &instance->timer_netif_check_timeout);
633 if (interface_up == 0) {
636 "One of your ip addresses are now bound to localhost. "
637 "Corosync would not work correctly.");
653 timer_function_netif_check_timeout,
654 &instance->timer_netif_check_timeout);
664 totemudpu_build_sockets (instance,
672 POLLIN, instance, net_deliver_fn);
683 "The network interface [%s] is now up.",
696 timer_function_netif_check_timeout,
697 &instance->timer_netif_check_timeout);
703 "The network interface is down.");
720 "Could not set traffic priority");
725static int totemudpu_build_sockets_ip (
752 "Could not set non-blocking operation on token socket");
767 "bind token socket failed");
791 "Could not set recvbuf size");
841static int totemudpu_build_local_sockets(
859 for (
i = 0;
i < 2;
i++) {
864 "Could not set non-blocking operation on multicast socket");
875 "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
881 "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
888 "Local receive multicast loop socket recv buffer size (%d bytes).",
recvbuf_size);
894 "Local transmit multicast loop socket send buffer size (%d bytes).",
sendbuf_size);
900static int totemudpu_build_sockets (
912 res = netif_determine (instance,
924 res = totemudpu_build_sockets_ip (instance,
930 "Unable to create sockets, exiting");
935 totemudpu_traffic_control_set(instance, instance->
token_socket);
963 unsigned int msg_len,
975 void (*target_set_completed) (
981 if (instance ==
NULL) {
985 totemudpu_instance_initialize (instance);
1021 if (totemudpu_build_local_sockets(instance) == -1) {
1030 POLLIN, instance, net_deliver_fn);
1040 timer_function_netif_check_timeout,
1043 totemudpu_start_merge_detect_timeout((
void*)instance);
1074 timer_function_netif_check_timeout,
1075 &instance->timer_netif_check_timeout);
1098 unsigned int msg_len)
1103 ucast_sendmsg (instance, &instance->
token_target, msg, msg_len);
1110 unsigned int msg_len)
1115 mcast_sendmsg (instance, msg, msg_len, 0);
1123 unsigned int msg_len)
1128 mcast_sendmsg (instance, msg, msg_len, 1);
1138 timer_function_netif_check_timeout (instance);
1194#ifdef HAVE_MSGHDR_CONTROL
1197#ifdef HAVE_MSGHDR_CONTROLLEN
1200#ifdef HAVE_MSGHDR_FLAGS
1203#ifdef HAVE_MSGHDR_ACCRIGHTS
1206#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1210 for (
i = 0;
i < 2;
i++) {
1236 }
while (
nfds == 1);
1242static int totemudpu_create_sending_socket(
1257 "Could not create socket for new member");
1264 "Could not set non-blocking operation on token socket");
1277 "Could not set sendbuf size");
1290 "bind token socket failed");
1303 unsigned short ip_port,
1359 "removing UDPU member {%s}",
1362 if (member->
fd > 0) {
1364 "Closing socket to: {%s}",
1399 if (member->
fd > 0) {
1410static void timer_function_merge_detect_timeout (
1421 totemudpu_start_merge_detect_timeout(instance);
1424static void totemudpu_start_merge_detect_timeout(
1433 timer_function_merge_detect_timeout,
1434 &instance->timer_merge_detect_timeout);
1438static void totemudpu_stop_merge_detect_timeout(
#define PROCESSOR_COUNT_MAX
@ COROSYNC_DONE_FATAL_ERR
#define LOGSYS_LEVEL_NOTICE
#define LOGSYS_LEVEL_DEBUG
struct totem_logging_configuration totem_logging_configuration
unsigned int downcheck_timeout
struct totem_interface * interfaces
unsigned int clear_node_high_bit
unsigned int merge_timeout
unsigned int block_unlisted_ips
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
int(* totemudpu_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
struct totem_config * totem_config
qb_loop_t * totemudpu_poll_handle
void(* totemudpu_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
struct totem_ip_address my_id
int totemudpu_log_level_notice
qb_loop_timer_handle timer_netif_check_timeout
int(* totemudpu_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int ring_no)
qb_loop_timer_handle timer_merge_detect_timeout
unsigned int my_memb_entries
int totemudpu_log_level_security
struct totem_ip_address token_target
unsigned int merge_detect_messages_sent_before_timeout
int send_merge_detect_message
struct timeval stats_tv_start
int totemudpu_log_level_warning
char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX]
struct iovec totemudpu_iov_recv
struct totem_interface * totem_interface
int totemudpu_log_level_debug
int totemudpu_log_level_error
void(* totemudpu_target_set_completed)(void *context)
struct qb_list_head member_list
void(*) void udpu_context)
struct totem_ip_address member
struct totemudpu_instance * instance
#define BIND_RETRIES_INTERVAL
#define UDP_RECEIVE_FRAME_SIZE_MAX
const char * totemip_sa_print(const struct sockaddr *sa)
int totemip_sa_equal(const struct totem_ip_address *totem_ip, const struct sockaddr *sa)
int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit)
#define totemip_nosigpipe(s)
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
size_t totemip_udpip_header_size(int family)
int totemip_compare(const void *a, const void *b)
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)
struct srp_addr system_from
void totemudpu_buffer_release(void *ptr)
int totemudpu_ifaces_get(void *net_context, char ***status, unsigned int *iface_count)
#define NETIF_STATE_REPORT_UP
#define log_printf(level, format, args...)
int totemudpu_send_flush(void *udpu_context)
int totemudpu_token_target_set(void *udpu_context, unsigned int nodeid)
void * totemudpu_buffer_alloc(void)
#define BIND_STATE_LOOPBACK
#define NETIF_STATE_REPORT_DOWN
int totemudpu_member_list_rebind_ip(void *udpu_context)
int totemudpu_recv_mcast_empty(void *udpu_context)
int totemudpu_processor_count_set(void *udpu_context, int processor_count)
int totemudpu_token_send(void *udpu_context, const void *msg, unsigned int msg_len)
int totemudpu_iface_set(void *net_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
int totemudpu_crypto_set(void *udpu_context, const char *cipher_type, const char *hash_type)
#define MCAST_SOCKET_BUFFER_SIZE
int totemudpu_recv_flush(void *udpu_context)
int totemudpu_mcast_noflush_send(void *udpu_context, const void *msg, unsigned int msg_len)
int totemudpu_member_remove(void *udpu_context, const struct totem_ip_address *token_target, int ring_no)
int totemudpu_finalize(void *udpu_context)
int totemudpu_mcast_flush_send(void *udpu_context, const void *msg, unsigned int msg_len)
int totemudpu_iface_check(void *udpu_context)
int totemudpu_reconfigure(void *udpu_context, struct totem_config *totem_config)
#define LOGSYS_PERROR(err_num, level, fmt, args...)
int totemudpu_initialize(qb_loop_t *poll_handle, void **udpu_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 ring_no), void(*mtu_changed)(void *context, int net_mtu), void(*target_set_completed)(void *context))
Create an instance.
#define BIND_STATE_UNBOUND
#define BIND_STATE_REGULAR
void totemudpu_net_mtu_adjust(void *udpu_context, struct totem_config *totem_config)
int totemudpu_nodestatus_get(void *udpu_context, unsigned int nodeid, struct totem_node_status *node_status)
int totemudpu_member_add(void *udpu_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int ring_no)