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;
293 "sendmsg(ucast) failed (non-critical)");
297static inline void mcast_sendmsg (
300 unsigned int msg_len)
308 iovec.iov_base = (
void *)msg;
309 iovec.iov_len = msg_len;
330 "sendmsg(mcast) failed (non-critical)");
347 "sendmsg(local mcast loop) failed (non-critical)");
385static int net_deliver_fn (
425 "Received too big message. This may be because something bad is happening "
426 "on the network (attack?), or you tried join more nodes than corosync is "
427 "compiled with (%u) or bug in the code (bad estimation of "
447static int netif_determine (
457 interface_up, interface_num,
469static void timer_function_netif_check_timeout (
480 netif_determine (instance,
483 &interface_up, &interface_num);
489 interface_up == 0) ||
493 interface_up == 1)) {
499 timer_function_netif_check_timeout,
500 &instance->timer_netif_check_timeout);
528 if (interface_up == 0) {
542 timer_function_netif_check_timeout,
543 &instance->timer_netif_check_timeout);
554 (
void)totemudp_build_sockets (instance,
564 POLLIN, instance, net_deliver_fn);
570 POLLIN, instance, net_deliver_fn);
576 POLLIN, instance, net_deliver_fn);
586 "The network interface [%s] is now up.",
599 timer_function_netif_check_timeout,
600 &instance->timer_netif_check_timeout);
606 "The network interface is down.");
627static int totemudp_build_sockets_ip (
656 if (
sockets->mcast_recv == -1) {
666 "Could not set non-blocking operation on multicast socket");
676 "setsockopt(SO_REUSEADDR) failed");
689 for (
i = 0;
i < 2;
i++) {
694 "Could not set non-blocking operation on multicast socket");
705 if (
sockets->mcast_send == -1) {
715 "Could not set non-blocking operation on multicast socket");
725 "setsockopt(SO_REUSEADDR) failed");
733 "Could not set IP_TOS bits");
747 "Unable to bind the socket to send multicast packets");
775 "Could not set non-blocking operation on token socket");
785 "setsockopt(SO_REUSEADDR) failed");
792 "Could not set IP_TOS bits");
809 "Unable to bind UDP unicast socket");
831 "Unable to set SO_RCVBUF size on UDP mcast socket");
837 "Unable to set SO_SNDBUF size on UDP mcast socket");
843 "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
849 "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
856 "Receive multicast socket recv buffer size (%d bytes).",
recvbuf_size);
862 "Transmit multicast socket send buffer size (%d bytes).",
sendbuf_size);
868 "Local receive multicast loop socket recv buffer size (%d bytes).",
recvbuf_size);
874 "Local transmit multicast loop socket send buffer size (%d bytes).",
sendbuf_size);
885 unsigned int broadcast = 1;
890 "setting broadcast option failed");
896 "setting broadcast option failed");
909 "join ipv4 multicast group failed");
916 mreq6.ipv6mr_interface = interface_num;
922 "join ipv6 multicast group failed");
946 "Unable to turn off multicast loopback");
959 "set mcast v6 TTL failed");
968 "set mcast v4 TTL failed");
981 "cannot select interface for multicast packets (send)");
987 "cannot select interface for multicast packets (recv)");
993 &interface_num,
sizeof (interface_num)) < 0) {
995 "cannot select interface for multicast packets (send v6)");
999 &interface_num,
sizeof (interface_num)) < 0) {
1001 "cannot select interface for multicast packets (recv v6)");
1023 "Unable to bind the socket to receive multicast packets");
1040static int totemudp_build_sockets (
1054 res = netif_determine (instance,
1066 res = totemudp_build_sockets_ip (instance, mcast_address,
1072 "Unable to create sockets, exiting");
1077 totemudp_traffic_control_set(instance,
sockets->token);
1100 unsigned int msg_len,
1112 void (*target_set_completed) (
1118 if (instance ==
NULL) {
1122 totemudp_instance_initialize (instance);
1168 timer_function_netif_check_timeout,
1200 timer_function_netif_check_timeout,
1201 &instance->timer_netif_check_timeout);
1218 for (
i = 0;
i < 2;
i++) {
1233 net_deliver_fn (
sock,
ufd.revents, instance);
1235 }
while (
nfds == 1);
1251 unsigned int msg_len)
1256 ucast_sendmsg (instance, &instance->
token_target, msg, msg_len);
1263 unsigned int msg_len)
1268 mcast_sendmsg (instance, msg, msg_len);
1276 unsigned int msg_len)
1281 mcast_sendmsg (instance, msg, msg_len);
1291 timer_function_netif_check_timeout (instance);
1392 for (
i = 0;
i < 2;
i++) {
1414 }
while (
nfds == 1);
1481 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
int totemudp_log_level_security
struct totem_ip_address my_id
struct totem_interface * totem_interface
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)
char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX+1]
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)
char iov_buffer_flush[UDP_RECEIVE_FRAME_SIZE_MAX+1]
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)
int set_socket_dscp(int socket, unsigned char dscp)