1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef O2CLUSTER_TCP_H
28#define O2CLUSTER_TCP_H
29
30#include <linux/socket.h>
31#ifdef __KERNEL__
32#include <net/sock.h>
33#include <linux/tcp.h>
34#else
35#include <sys/socket.h>
36#endif
37#include <linux/inet.h>
38#include <linux/in.h>
39
40struct o2net_msg
41{
42 __be16 magic;
43 __be16 data_len;
44 __be16 msg_type;
45 __be16 pad1;
46 __be32 sys_status;
47 __be32 status;
48 __be32 key;
49 __be32 msg_num;
50 __u8 buf[0];
51};
52
53typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
54 void **ret_data);
55typedef void (o2net_post_msg_handler_func)(int status, void *data,
56 void *ret_data);
57
58#define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg))
59
60
61#define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000
62
63#define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000
64#define O2NET_IDLE_TIMEOUT_MS_DEFAULT 30000
65
66#define O2NET_TCP_USER_TIMEOUT 0x7fffffff
67
68
69static inline int o2net_link_down(int err, struct socket *sock)
70{
71 if (sock) {
72 if (sock->sk->sk_state != TCP_ESTABLISHED &&
73 sock->sk->sk_state != TCP_CLOSE_WAIT)
74 return 1;
75 }
76
77 if (err >= 0)
78 return 0;
79 switch (err) {
80
81 case -ERESTARTSYS:
82 case -EBADF:
83
84
85 case -ECONNREFUSED:
86 case -ENOTCONN:
87 case -ECONNRESET:
88 case -EPIPE:
89 return 1;
90 }
91 return 0;
92}
93
94enum {
95 O2NET_DRIVER_UNINITED,
96 O2NET_DRIVER_READY,
97};
98
99int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
100 u8 target_node, int *status);
101int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
102 size_t veclen, u8 target_node, int *status);
103
104int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
105 o2net_msg_handler_func *func, void *data,
106 o2net_post_msg_handler_func *post_func,
107 struct list_head *unreg_list);
108void o2net_unregister_handler_list(struct list_head *list);
109
110void o2net_fill_node_map(unsigned long *map, unsigned bytes);
111
112struct o2nm_node;
113int o2net_register_hb_callbacks(void);
114void o2net_unregister_hb_callbacks(void);
115int o2net_start_listening(struct o2nm_node *node);
116void o2net_stop_listening(struct o2nm_node *node);
117void o2net_disconnect_node(struct o2nm_node *node);
118int o2net_num_connected_peers(void);
119
120int o2net_init(void);
121void o2net_exit(void);
122
123struct o2net_send_tracking;
124struct o2net_sock_container;
125
126#ifdef CONFIG_DEBUG_FS
127int o2net_debugfs_init(void);
128void o2net_debugfs_exit(void);
129void o2net_debug_add_nst(struct o2net_send_tracking *nst);
130void o2net_debug_del_nst(struct o2net_send_tracking *nst);
131void o2net_debug_add_sc(struct o2net_sock_container *sc);
132void o2net_debug_del_sc(struct o2net_sock_container *sc);
133#else
134static inline int o2net_debugfs_init(void)
135{
136 return 0;
137}
138static inline void o2net_debugfs_exit(void)
139{
140}
141static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
142{
143}
144static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
145{
146}
147static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
148{
149}
150static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
151{
152}
153#endif
154
155#endif
156