43#include <sys/socket.h>
48#include <netinet/in.h>
66#define LOGSYS_UTILS_ONLY 1
76#define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * FRAME_SIZE_MAX)
77#define NETIF_STATE_REPORT_UP 1
78#define NETIF_STATE_REPORT_DOWN 2
80#define BIND_STATE_UNBOUND 0
81#define BIND_STATE_REGULAR 1
82#define BIND_STATE_LOOPBACK 2
116 unsigned int msg_len,
201static int totemudp_build_sockets (
231#define log_printf(level, format, args...) \
233 instance->totemudp_log_printf ( \
234 level, instance->totemudp_subsys_id, \
235 __FUNCTION__, __FILE__, __LINE__, \
236 (const char *)format, ##args); \
239#define LOGSYS_PERROR(err_num, level, fmt, args...) \
241 char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
242 const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
243 instance->totemudp_log_printf ( \
244 level, instance->totemudp_subsys_id, \
245 __FUNCTION__, __FILE__, __LINE__, \
246 fmt ": %s (%d)\n", ##args, _error_ptr, err_num); \
259static inline void ucast_sendmsg (
263 unsigned int msg_len)
271 iovec.iov_base = (
void*)msg;
272 iovec.iov_len = msg_len;
284#ifdef HAVE_MSGHDR_CONTROL
287#ifdef HAVE_MSGHDR_CONTROLLEN
290#ifdef HAVE_MSGHDR_FLAGS
293#ifdef HAVE_MSGHDR_ACCRIGHTS
296#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
309 "sendmsg(ucast) failed (non-critical)");
313static inline void mcast_sendmsg (
316 unsigned int msg_len)
324 iovec.iov_base = (
void *)msg;
325 iovec.iov_len = msg_len;
337#ifdef HAVE_MSGHDR_CONTROL
340#ifdef HAVE_MSGHDR_CONTROLLEN
343#ifdef HAVE_MSGHDR_FLAGS
346#ifdef HAVE_MSGHDR_ACCRIGHTS
349#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
361 "sendmsg(mcast) failed (non-critical)");
378 "sendmsg(local mcast loop) failed (non-critical)");
416static int net_deliver_fn (
441#ifdef HAVE_MSGHDR_CONTROL
444#ifdef HAVE_MSGHDR_CONTROLLEN
447#ifdef HAVE_MSGHDR_FLAGS
450#ifdef HAVE_MSGHDR_ACCRIGHTS
453#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
466#ifdef HAVE_MSGHDR_FLAGS
482 "Received too big message. This may be because something bad is happening"
483 "on the network (attack?), or you tried join more nodes than corosync is"
484 "compiled with (%u) or bug in the code (bad estimation of "
504static int netif_determine (
514 interface_up, interface_num,
526static void timer_function_netif_check_timeout (
537 netif_determine (instance,
540 &interface_up, &interface_num);
546 interface_up == 0) ||
550 interface_up == 1)) {
556 timer_function_netif_check_timeout,
557 &instance->timer_netif_check_timeout);
585 if (interface_up == 0) {
599 timer_function_netif_check_timeout,
600 &instance->timer_netif_check_timeout);
611 (
void)totemudp_build_sockets (instance,
621 POLLIN, instance, net_deliver_fn);
627 POLLIN, instance, net_deliver_fn);
633 POLLIN, instance, net_deliver_fn);
643 "The network interface [%s] is now up.",
656 timer_function_netif_check_timeout,
657 &instance->timer_netif_check_timeout);
663 "The network interface is down.");
684static int totemudp_build_sockets_ip (
713 if (
sockets->mcast_recv == -1) {
723 "Could not set non-blocking operation on multicast socket");
733 "setsockopt(SO_REUSEADDR) failed");
746 for (
i = 0;
i < 2;
i++) {
751 "Could not set non-blocking operation on multicast socket");
762 if (
sockets->mcast_send == -1) {
772 "Could not set non-blocking operation on multicast socket");
782 "setsockopt(SO_REUSEADDR) failed");
796 "Unable to bind the socket to send multicast packets");
824 "Could not set non-blocking operation on token socket");
834 "setsockopt(SO_REUSEADDR) failed");
851 "Unable to bind UDP unicast socket");
873 "Unable to set SO_RCVBUF size on UDP mcast socket");
879 "Unable to set SO_SNDBUF size on UDP mcast socket");
885 "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
891 "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
898 "Receive multicast socket recv buffer size (%d bytes).",
recvbuf_size);
904 "Transmit multicast socket send buffer size (%d bytes).",
sendbuf_size);
910 "Local receive multicast loop socket recv buffer size (%d bytes).",
recvbuf_size);
916 "Local transmit multicast loop socket send buffer size (%d bytes).",
sendbuf_size);
927 unsigned int broadcast = 1;
932 "setting broadcast option failed");
938 "setting broadcast option failed");
951 "join ipv4 multicast group failed");
958 mreq6.ipv6mr_interface = interface_num;
964 "join ipv6 multicast group failed");
988 "Unable to turn off multicast loopback");
1001 "set mcast v6 TTL failed");
1010 "set mcast v4 TTL failed");
1023 "cannot select interface for multicast packets (send)");
1029 "cannot select interface for multicast packets (recv)");
1035 &interface_num,
sizeof (interface_num)) < 0) {
1037 "cannot select interface for multicast packets (send v6)");
1041 &interface_num,
sizeof (interface_num)) < 0) {
1043 "cannot select interface for multicast packets (recv v6)");
1065 "Unable to bind the socket to receive multicast packets");
1082static int totemudp_build_sockets (
1096 res = netif_determine (instance,
1108 res = totemudp_build_sockets_ip (instance, mcast_address,
1114 "Unable to create sockets, exiting");
1119 totemudp_traffic_control_set(instance,
sockets->token);
1142 unsigned int msg_len,
1154 void (*target_set_completed) (
1160 if (instance ==
NULL) {
1164 totemudp_instance_initialize (instance);
1209 timer_function_netif_check_timeout,
1241 timer_function_netif_check_timeout,
1242 &instance->timer_netif_check_timeout);
1259 for (
i = 0;
i < 2;
i++) {
1274 net_deliver_fn (
sock,
ufd.revents, instance);
1276 }
while (
nfds == 1);
1292 unsigned int msg_len)
1297 ucast_sendmsg (instance, &instance->
token_target, msg, msg_len);
1304 unsigned int msg_len)
1309 mcast_sendmsg (instance, msg, msg_len);
1317 unsigned int msg_len)
1322 mcast_sendmsg (instance, msg, msg_len);
1332 timer_function_netif_check_timeout (instance);
1431#ifdef HAVE_MSGHDR_CONTROL
1434#ifdef HAVE_MSGHDR_CONTROLLEN
1437#ifdef HAVE_MSGHDR_FLAGS
1440#ifdef HAVE_MSGHDR_ACCRIGHTS
1443#ifdef HAVE_MSGHDR_ACCRIGHTSLEN
1447 for (
i = 0;
i < 2;
i++) {
1469 }
while (
nfds == 1);
1536 unsigned short ip_port,
#define PROCESSOR_COUNT_MAX
unsigned int broadcast_use
struct totem_logging_configuration totem_logging_configuration
unsigned int downcheck_timeout
struct totem_interface * interfaces
unsigned int clear_node_high_bit
struct totem_ip_address boundto
struct totem_ip_address bindnet
struct totem_ip_address mcast_addr
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
uint32_t continuous_sendmsg_failures
qb_loop_timer_handle timer_netif_check_timeout
struct totem_ip_address mcast_address
struct qb_list_head member_list
qb_loop_t * totemudp_poll_handle
char iov_buffer_flush[UDP_RECEIVE_FRAME_SIZE_MAX]
int totemudp_log_level_security
struct totem_ip_address my_id
struct totem_interface * totem_interface
char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX]
struct iovec totemudp_iov_recv_flush
int totemudp_log_level_notice
void(* totemudp_log_printf)(int level, int subsys, const char *function, const char *file, int line, const char *format,...) __attribute__((format(printf
unsigned int my_memb_entries
int totemudp_log_level_debug
struct totem_config * totem_config
void(*) void udp_context)
int totemudp_log_level_warning
struct totem_ip_address token_target
void(* totemudp_target_set_completed)(void *context)
int(* totemudp_iface_change_fn)(void *context, const struct totem_ip_address *iface_address, unsigned int ring_no)
struct iovec totemudp_iov_recv
struct totemudp_socket totemudp_sockets
struct timeval stats_tv_start
int(* totemudp_deliver_fn)(void *context, const void *msg, unsigned int msg_len, const struct sockaddr_storage *system_from)
int totemudp_log_level_error
struct totem_ip_address member
struct totemudp_instance * instance
#define BIND_RETRIES_INTERVAL
#define UDP_RECEIVE_FRAME_SIZE_MAX
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)
int totemip_localhost(int family, struct totem_ip_address *localhost)
struct srp_addr system_from
int totemudp_iface_set(void *net_context, const struct totem_ip_address *local_addr, unsigned short ip_port, unsigned int iface_no)
#define NETIF_STATE_REPORT_UP
void totemudp_net_mtu_adjust(void *udp_context, struct totem_config *totem_config)
#define log_printf(level, format, args...)
void * totemudp_buffer_alloc(void)
int totemudp_send_flush(void *udp_context)
int totemudp_iface_check(void *udp_context)
int totemudp_recv_flush(void *udp_context)
#define BIND_STATE_LOOPBACK
#define NETIF_STATE_REPORT_DOWN
int totemudp_nodestatus_get(void *udp_context, unsigned int nodeid, struct totem_node_status *node_status)
int totemudp_token_target_set(void *udp_context, unsigned int nodeid)
int totemudp_ifaces_get(void *net_context, char ***status, unsigned int *iface_count)
int totemudp_reconfigure(void *udp_context, struct totem_config *totem_config)
#define MCAST_SOCKET_BUFFER_SIZE
int totemudp_mcast_flush_send(void *udp_context, const void *msg, unsigned int msg_len)
int totemudp_finalize(void *udp_context)
int totemudp_recv_mcast_empty(void *udp_context)
int totemudp_crypto_set(void *udp_context, const char *cipher_type, const char *hash_type)
#define LOGSYS_PERROR(err_num, level, fmt, args...)
int totemudp_processor_count_set(void *udp_context, int processor_count)
int totemudp_token_send(void *udp_context, const void *msg, unsigned int msg_len)
#define BIND_STATE_REGULAR
int totemudp_mcast_noflush_send(void *udp_context, const void *msg, unsigned int msg_len)
int totemudp_member_add(void *udp_context, const struct totem_ip_address *local, const struct totem_ip_address *member, int ring_no)
void totemudp_buffer_release(void *ptr)
int totemudp_initialize(qb_loop_t *poll_handle, void **udp_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.
int totemudp_member_remove(void *udp_context, const struct totem_ip_address *token_target, int ring_no)