xref: /openbmc/linux/fs/ocfs2/cluster/tcp.h (revision fa60ce2c)
1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*fa60ce2cSMasahiro Yamada /*
398211489SZach Brown  * tcp.h
498211489SZach Brown  *
598211489SZach Brown  * Function prototypes
698211489SZach Brown  *
798211489SZach Brown  * Copyright (C) 2004 Oracle.  All rights reserved.
898211489SZach Brown  */
998211489SZach Brown 
1098211489SZach Brown #ifndef O2CLUSTER_TCP_H
1198211489SZach Brown #define O2CLUSTER_TCP_H
1298211489SZach Brown 
1398211489SZach Brown #include <linux/socket.h>
1498211489SZach Brown #ifdef __KERNEL__
1598211489SZach Brown #include <net/sock.h>
1698211489SZach Brown #include <linux/tcp.h>
1798211489SZach Brown #else
1898211489SZach Brown #include <sys/socket.h>
1998211489SZach Brown #endif
2098211489SZach Brown #include <linux/inet.h>
2198211489SZach Brown #include <linux/in.h>
2298211489SZach Brown 
2398211489SZach Brown struct o2net_msg
2498211489SZach Brown {
2598211489SZach Brown 	__be16 magic;
2698211489SZach Brown 	__be16 data_len;
2798211489SZach Brown 	__be16 msg_type;
2898211489SZach Brown 	__be16 pad1;
2998211489SZach Brown 	__be32 sys_status;
3098211489SZach Brown 	__be32 status;
3198211489SZach Brown 	__be32 key;
3298211489SZach Brown 	__be32 msg_num;
33fa803cf8SGustavo A. R. Silva 	__u8  buf[];
3498211489SZach Brown };
3598211489SZach Brown 
36d74c9803SKurt Hackel typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
37d74c9803SKurt Hackel 				     void **ret_data);
38d74c9803SKurt Hackel typedef void (o2net_post_msg_handler_func)(int status, void *data,
39d74c9803SKurt Hackel 					   void *ret_data);
4098211489SZach Brown 
4198211489SZach Brown #define O2NET_MAX_PAYLOAD_BYTES  (4096 - sizeof(struct o2net_msg))
4298211489SZach Brown 
43b5dd8030SJeff Mahoney /* same as hb delay, we're waiting for another node to recognize our hb */
44b5dd8030SJeff Mahoney #define O2NET_RECONNECT_DELAY_MS_DEFAULT	2000
45b5dd8030SJeff Mahoney 
4617104683SSunil Mushran #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT	2000
4717104683SSunil Mushran #define O2NET_IDLE_TIMEOUT_MS_DEFAULT		30000
48b5dd8030SJeff Mahoney 
498e9801dfSJunxiao Bi #define O2NET_TCP_USER_TIMEOUT			0x7fffffff
50b5dd8030SJeff Mahoney 
5198211489SZach Brown /* TODO: figure this out.... */
o2net_link_down(int err,struct socket * sock)5298211489SZach Brown static inline int o2net_link_down(int err, struct socket *sock)
5398211489SZach Brown {
5498211489SZach Brown 	if (sock) {
5598211489SZach Brown 		if (sock->sk->sk_state != TCP_ESTABLISHED &&
5698211489SZach Brown 	    	    sock->sk->sk_state != TCP_CLOSE_WAIT)
5798211489SZach Brown 			return 1;
5898211489SZach Brown 	}
5998211489SZach Brown 
6098211489SZach Brown 	if (err >= 0)
6198211489SZach Brown 		return 0;
6298211489SZach Brown 	switch (err) {
6398211489SZach Brown 		/* ????????????????????????? */
6498211489SZach Brown 		case -ERESTARTSYS:
6598211489SZach Brown 		case -EBADF:
6698211489SZach Brown 		/* When the server has died, an ICMP port unreachable
6798211489SZach Brown 		 * message prompts ECONNREFUSED. */
6898211489SZach Brown 		case -ECONNREFUSED:
6998211489SZach Brown 		case -ENOTCONN:
7098211489SZach Brown 		case -ECONNRESET:
7198211489SZach Brown 		case -EPIPE:
7298211489SZach Brown 			return 1;
7398211489SZach Brown 	}
7498211489SZach Brown 	return 0;
7598211489SZach Brown }
7698211489SZach Brown 
7798211489SZach Brown enum {
7898211489SZach Brown 	O2NET_DRIVER_UNINITED,
7998211489SZach Brown 	O2NET_DRIVER_READY,
8098211489SZach Brown };
8198211489SZach Brown 
8298211489SZach Brown int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
8398211489SZach Brown 		       u8 target_node, int *status);
8498211489SZach Brown int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
8598211489SZach Brown 			   size_t veclen, u8 target_node, int *status);
8698211489SZach Brown 
8798211489SZach Brown int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
8898211489SZach Brown 			   o2net_msg_handler_func *func, void *data,
89d74c9803SKurt Hackel 			   o2net_post_msg_handler_func *post_func,
9098211489SZach Brown 			   struct list_head *unreg_list);
9198211489SZach Brown void o2net_unregister_handler_list(struct list_head *list);
9298211489SZach Brown 
933ba169ccSSunil Mushran void o2net_fill_node_map(unsigned long *map, unsigned bytes);
943ba169ccSSunil Mushran 
9598211489SZach Brown struct o2nm_node;
9698211489SZach Brown int o2net_register_hb_callbacks(void);
9798211489SZach Brown void o2net_unregister_hb_callbacks(void);
9898211489SZach Brown int o2net_start_listening(struct o2nm_node *node);
9998211489SZach Brown void o2net_stop_listening(struct o2nm_node *node);
10098211489SZach Brown void o2net_disconnect_node(struct o2nm_node *node);
101828ae6afSAndrew Beekhof int o2net_num_connected_peers(void);
10298211489SZach Brown 
10398211489SZach Brown int o2net_init(void);
10498211489SZach Brown void o2net_exit(void);
10598211489SZach Brown 
1062309e9e0SSunil Mushran struct o2net_send_tracking;
1072309e9e0SSunil Mushran struct o2net_sock_container;
1082309e9e0SSunil Mushran 
1092309e9e0SSunil Mushran #ifdef CONFIG_DEBUG_FS
110e581595eSGreg Kroah-Hartman void o2net_debugfs_init(void);
1112309e9e0SSunil Mushran void o2net_debugfs_exit(void);
1122309e9e0SSunil Mushran void o2net_debug_add_nst(struct o2net_send_tracking *nst);
1132309e9e0SSunil Mushran void o2net_debug_del_nst(struct o2net_send_tracking *nst);
1142309e9e0SSunil Mushran void o2net_debug_add_sc(struct o2net_sock_container *sc);
1152309e9e0SSunil Mushran void o2net_debug_del_sc(struct o2net_sock_container *sc);
1162309e9e0SSunil Mushran #else
o2net_debugfs_init(void)117e581595eSGreg Kroah-Hartman static inline void o2net_debugfs_init(void)
1182309e9e0SSunil Mushran {
1192309e9e0SSunil Mushran }
o2net_debugfs_exit(void)120271d772dSSunil Mushran static inline void o2net_debugfs_exit(void)
1212309e9e0SSunil Mushran {
1222309e9e0SSunil Mushran }
o2net_debug_add_nst(struct o2net_send_tracking * nst)123271d772dSSunil Mushran static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
1242309e9e0SSunil Mushran {
1252309e9e0SSunil Mushran }
o2net_debug_del_nst(struct o2net_send_tracking * nst)126271d772dSSunil Mushran static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
1272309e9e0SSunil Mushran {
1282309e9e0SSunil Mushran }
o2net_debug_add_sc(struct o2net_sock_container * sc)129271d772dSSunil Mushran static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
1302309e9e0SSunil Mushran {
1312309e9e0SSunil Mushran }
o2net_debug_del_sc(struct o2net_sock_container * sc)132271d772dSSunil Mushran static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
1332309e9e0SSunil Mushran {
1342309e9e0SSunil Mushran }
1352309e9e0SSunil Mushran #endif	/* CONFIG_DEBUG_FS */
1362309e9e0SSunil Mushran 
13798211489SZach Brown #endif /* O2CLUSTER_TCP_H */
138