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,
112 unsigned int ring_no);
134 const char *function,
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); \
246 const char *cipher_type,
247 const char *hash_type)
254static inline void ucast_sendmsg (
258 unsigned int msg_len)
260 struct msghdr msg_ucast;
262 struct sockaddr_storage sockaddr;
267 iovec.iov_base = (
void *)msg;
268 iovec.iov_len = msg_len;
275 memset(&msg_ucast, 0,
sizeof(msg_ucast));
276 msg_ucast.msg_name = &sockaddr;
277 msg_ucast.msg_namelen = addrlen;
278 msg_ucast.msg_iov = (
void *)&iovec;
279 msg_ucast.msg_iovlen = 1;
280#ifdef HAVE_MSGHDR_CONTROL
281 msg_ucast.msg_control = 0;
283#ifdef HAVE_MSGHDR_CONTROLLEN
284 msg_ucast.msg_controllen = 0;
286#ifdef HAVE_MSGHDR_FLAGS
287 msg_ucast.msg_flags = 0;
289#ifdef HAVE_MSGHDR_ACCRIGHTS
290 msg_ucast.msg_accrights = NULL;
292#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
293 msg_ucast.msg_accrightslen = 0;
300 msg_ucast.msg_name = NULL;
301 msg_ucast.msg_namelen = 0;
312 "sendmsg(ucast) failed (non-critical)");
316static inline void mcast_sendmsg (
319 unsigned int msg_len,
322 struct msghdr msg_mcast;
325 struct sockaddr_storage sockaddr;
327 struct qb_list_head *list;
330 iovec.iov_base = (
void *)msg;
331 iovec.iov_len = msg_len;
333 memset(&msg_mcast, 0,
sizeof(msg_mcast));
351 msg_mcast.msg_name = &sockaddr;
352 msg_mcast.msg_namelen = addrlen;
353 msg_mcast.msg_iov = (
void *)&iovec;
354 msg_mcast.msg_iovlen = 1;
355 #ifdef HAVE_MSGHDR_CONTROL
356 msg_mcast.msg_control = 0;
358 #ifdef HAVE_MSGHDR_CONTROLLEN
359 msg_mcast.msg_controllen = 0;
361 #ifdef HAVE_MSGHDR_FLAGS
362 msg_mcast.msg_flags = 0;
364 #ifdef HAVE_MSGHDR_ACCRIGHTS
365 msg_mcast.msg_accrights = NULL;
367 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
368 msg_mcast.msg_accrightslen = 0;
378 "sendmsg(mcast) failed (non-critical)");
394 msg_mcast.msg_name = NULL;
395 msg_mcast.msg_namelen = 0;
396 msg_mcast.msg_iov = (
void *)&iovec;
397 msg_mcast.msg_iovlen = 1;
398 #ifdef HAVE_MSGHDR_CONTROL
399 msg_mcast.msg_control = 0;
401 #ifdef HAVE_MSGHDR_CONTROLLEN
402 msg_mcast.msg_controllen = 0;
404 #ifdef HAVE_MSGHDR_FLAGS
405 msg_mcast.msg_flags = 0;
407 #ifdef HAVE_MSGHDR_ACCRIGHTS
408 msg_mcast.msg_accrights = NULL;
410 #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
411 msg_mcast.msg_accrightslen = 0;
418 "sendmsg(local mcast loop) failed (non-critical)");
442 totemudpu_stop_merge_detect_timeout(instance);
448 const void *udpu_context,
449 const struct sockaddr *sa)
451 struct qb_list_head *list;
459 member = qb_list_entry (list,
473static int net_deliver_fn (
479 struct msghdr msg_recv;
483 int truncated_packet;
491 msg_recv.msg_namelen =
sizeof (
struct sockaddr_storage);
492 msg_recv.msg_iov = iovec;
493 msg_recv.msg_iovlen = 1;
494#ifdef HAVE_MSGHDR_CONTROL
495 msg_recv.msg_control = 0;
497#ifdef HAVE_MSGHDR_CONTROLLEN
498 msg_recv.msg_controllen = 0;
500#ifdef HAVE_MSGHDR_FLAGS
501 msg_recv.msg_flags = 0;
503#ifdef HAVE_MSGHDR_ACCRIGHTS
504 msg_recv.msg_accrights = NULL;
506#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
507 msg_recv.msg_accrightslen = 0;
510 bytes_received = recvmsg (fd, &msg_recv,
MSG_NOSIGNAL | MSG_DONTWAIT);
511 if (bytes_received == -1) {
517 truncated_packet = 0;
519#ifdef HAVE_MSGHDR_FLAGS
520 if (msg_recv.msg_flags & MSG_TRUNC) {
521 truncated_packet = 1;
529 truncated_packet = 1;
533 if (truncated_packet) {
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 "
544 find_member_by_sockaddr(instance, (
const struct sockaddr *)&
system_from) == NULL) {
551 iovec->iov_len = bytes_received;
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.");
713static void totemudpu_traffic_control_set(
struct totemudpu_instance *instance,
int sock)
718 if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio,
sizeof(
int))) {
720 "Could not set traffic priority");
725static int totemudpu_build_sockets_ip (
731 struct sockaddr_storage sockaddr;
734 unsigned int recvbuf_size;
735 unsigned int optlen =
sizeof (recvbuf_size);
736 unsigned int retries = 0;
749 res = fcntl (instance->
token_socket, F_SETFL, O_NONBLOCK);
752 "Could not set non-blocking operation on token socket");
762 res = bind (instance->
token_socket, (
struct sockaddr *)&sockaddr, addrlen);
767 "bind token socket failed");
787 res = setsockopt (instance->
token_socket, SOL_SOCKET, SO_RCVBUF,
788 &recvbuf_size, optlen);
791 "Could not set recvbuf size");
801 struct qb_list_head *list;
828 unsigned int *iface_count)
841static int totemudpu_build_local_sockets(
845 unsigned int sendbuf_size;
846 unsigned int recvbuf_size;
847 unsigned int optlen =
sizeof (sendbuf_size);
853 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, instance->
local_loop_sock) == -1) {
859 for (i = 0; i < 2; i++) {
864 "Could not set non-blocking operation on multicast socket");
872 res = setsockopt (instance->
local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
875 "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
878 res = setsockopt (instance->
local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
881 "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
885 res = getsockopt (instance->
local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
888 "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
891 res = getsockopt (instance->
local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
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,
925 bindnet_address, bound_to, interface_num);
930 "Unable to create sockets, exiting");
935 totemudpu_traffic_control_set(instance, instance->
token_socket);
954 qb_loop_t *poll_handle,
963 unsigned int msg_len,
966 void (*iface_change_fn) (
969 unsigned int ring_no),
971 void (*mtu_changed) (
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);
1038 100*QB_TIME_NS_IN_MSEC,
1040 timer_function_netif_check_timeout,
1043 totemudpu_start_merge_detect_timeout((
void*)instance);
1061 int processor_count)
1069 if (processor_count == 1) {
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);
1155 struct qb_list_head *list;
1181 struct msghdr msg_recv;
1184 int msg_processed = 0;
1191 msg_recv.msg_namelen =
sizeof (
struct sockaddr_storage);
1193 msg_recv.msg_iovlen = 1;
1194#ifdef HAVE_MSGHDR_CONTROL
1195 msg_recv.msg_control = 0;
1197#ifdef HAVE_MSGHDR_CONTROLLEN
1198 msg_recv.msg_controllen = 0;
1200#ifdef HAVE_MSGHDR_FLAGS
1201 msg_recv.msg_flags = 0;
1203#ifdef HAVE_MSGHDR_ACCRIGHTS
1204 msg_recv.msg_accrights = NULL;
1206#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1207 msg_recv.msg_accrightslen = 0;
1210 for (i = 0; i < 2; i++) {
1226 ufd.events = POLLIN;
1227 nfds = poll (&ufd, 1, 0);
1228 if (nfds == 1 && ufd.revents & POLLIN) {
1229 res = recvmsg (sock, &msg_recv,
MSG_NOSIGNAL | MSG_DONTWAIT);
1236 }
while (nfds == 1);
1239 return (msg_processed);
1242static int totemudpu_create_sending_socket(
1249 unsigned int sendbuf_size;
1250 unsigned int optlen =
sizeof (sendbuf_size);
1251 struct sockaddr_storage sockaddr;
1254 fd = socket (member->
family, SOCK_DGRAM, 0);
1257 "Could not create socket for new member");
1261 res = fcntl (fd, F_SETFL, O_NONBLOCK);
1264 "Could not set non-blocking operation on token socket");
1265 goto error_close_fd;
1273 res = setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
1274 &sendbuf_size, optlen);
1277 "Could not set sendbuf size");
1287 res = bind (fd, (
struct sockaddr *)&sockaddr, addrlen);
1290 "bind token socket failed");
1291 goto error_close_fd;
1303 unsigned short ip_port,
1304 unsigned int iface_no)
1321 if (new_member == NULL) {
1325 memset(new_member, 0,
sizeof(*new_member));
1329 qb_list_init (&new_member->
list);
1332 new_member->
fd = totemudpu_create_sending_socket(udpu_context,
member);
1344 struct qb_list_head *list;
1352 qb_list_for_each(list, &(instance->
member_list)) {
1353 member = qb_list_entry (list,
1359 "removing UDPU member {%s}",
1362 if (member->
fd > 0) {
1364 "Closing socket to: {%s}",
1389 struct qb_list_head *list;
1394 qb_list_for_each(list, &(instance->
member_list)) {
1395 member = qb_list_entry (list,
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
struct knet_link_status link_status[KNET_MAX_LINK]
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
void(* totemudpu_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
struct totem_ip_address my_id
int totemudpu_log_level_notice
qb_loop_timer_handle timer_netif_check_timeout
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)
void(* totemudpu_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int ring_no)
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_initialize(qb_loop_t *poll_handle, void **udpu_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 ring_no), void(*mtu_changed)(void *context, int net_mtu), void(*target_set_completed)(void *context))
Create an instance.
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...)
#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)