xref: /openbmc/linux/fs/ocfs2/cluster/tcp.h (revision e581595e)
1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
298211489SZach Brown /* -*- mode: c; c-basic-offset: 8; -*-
398211489SZach Brown  * vim: noexpandtab sw=8 ts=8 sts=0:
498211489SZach Brown  *
598211489SZach Brown  * tcp.h
698211489SZach Brown  *
798211489SZach Brown  * Function prototypes
898211489SZach Brown  *
998211489SZach Brown  * Copyright (C) 2004 Oracle.  All rights reserved.
1098211489SZach Brown  */
1198211489SZach Brown 
1298211489SZach Brown #ifndef O2CLUSTER_TCP_H
1398211489SZach Brown #define O2CLUSTER_TCP_H
1498211489SZach Brown 
1598211489SZach Brown #include <linux/socket.h>
1698211489SZach Brown #ifdef __KERNEL__
1798211489SZach Brown #include <net/sock.h>
1898211489SZach Brown #include <linux/tcp.h>
1998211489SZach Brown #else
2098211489SZach Brown #include <sys/socket.h>
2198211489SZach Brown #endif
2298211489SZach Brown #include <linux/inet.h>
2398211489SZach Brown #include <linux/in.h>
2498211489SZach Brown 
2598211489SZach Brown struct o2net_msg
2698211489SZach Brown {
2798211489SZach Brown 	__be16 magic;
2898211489SZach Brown 	__be16 data_len;
2998211489SZach Brown 	__be16 msg_type;
3098211489SZach Brown 	__be16 pad1;
3198211489SZach Brown 	__be32 sys_status;
3298211489SZach Brown 	__be32 status;
3398211489SZach Brown 	__be32 key;
3498211489SZach Brown 	__be32 msg_num;
3598211489SZach Brown 	__u8  buf[0];
3698211489SZach Brown };
3798211489SZach Brown 
38d74c9803SKurt Hackel typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
39d74c9803SKurt Hackel 				     void **ret_data);
40d74c9803SKurt Hackel typedef void (o2net_post_msg_handler_func)(int status, void *data,
41d74c9803SKurt Hackel 					   void *ret_data);
4298211489SZach Brown 
4398211489SZach Brown #define O2NET_MAX_PAYLOAD_BYTES  (4096 - sizeof(struct o2net_msg))
4498211489SZach Brown 
45b5dd8030SJeff Mahoney /* same as hb delay, we're waiting for another node to recognize our hb */
46b5dd8030SJeff Mahoney #define O2NET_RECONNECT_DELAY_MS_DEFAULT	2000
47b5dd8030SJeff Mahoney 
4817104683SSunil Mushran #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT	2000
4917104683SSunil Mushran #define O2NET_IDLE_TIMEOUT_MS_DEFAULT		30000
50b5dd8030SJeff Mahoney 
518e9801dfSJunxiao Bi #define O2NET_TCP_USER_TIMEOUT			0x7fffffff
52b5dd8030SJeff Mahoney 
5398211489SZach Brown /* TODO: figure this out.... */
5498211489SZach Brown static inline int o2net_link_down(int err, struct socket *sock)
5598211489SZach Brown {
5698211489SZach Brown 	if (sock) {
5798211489SZach Brown 		if (sock->sk->sk_state != TCP_ESTABLISHED &&
5898211489SZach Brown 	    	    sock->sk->sk_state != TCP_CLOSE_WAIT)
5998211489SZach Brown 			return 1;
6098211489SZach Brown 	}
6198211489SZach Brown 
6298211489SZach Brown 	if (err >= 0)
6398211489SZach Brown 		return 0;
6498211489SZach Brown 	switch (err) {
6598211489SZach Brown 		/* ????????????????????????? */
6698211489SZach Brown 		case -ERESTARTSYS:
6798211489SZach Brown 		case -EBADF:
6898211489SZach Brown 		/* When the server has died, an ICMP port unreachable
6998211489SZach Brown 		 * message prompts ECONNREFUSED. */
7098211489SZach Brown 		case -ECONNREFUSED:
7198211489SZach Brown 		case -ENOTCONN:
7298211489SZach Brown 		case -ECONNRESET:
7398211489SZach Brown 		case -EPIPE:
7498211489SZach Brown 			return 1;
7598211489SZach Brown 	}
7698211489SZach Brown 	return 0;
7798211489SZach Brown }
7898211489SZach Brown 
7998211489SZach Brown enum {
8098211489SZach Brown 	O2NET_DRIVER_UNINITED,
8198211489SZach Brown 	O2NET_DRIVER_READY,
8298211489SZach Brown };
8398211489SZach Brown 
8498211489SZach Brown int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
8598211489SZach Brown 		       u8 target_node, int *status);
8698211489SZach Brown int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
8798211489SZach Brown 			   size_t veclen, u8 target_node, int *status);
8898211489SZach Brown 
8998211489SZach Brown int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
9098211489SZach Brown 			   o2net_msg_handler_func *func, void *data,
91d74c9803SKurt Hackel 			   o2net_post_msg_handler_func *post_func,
9298211489SZach Brown 			   struct list_head *unreg_list);
9398211489SZach Brown void o2net_unregister_handler_list(struct list_head *list);
9498211489SZach Brown 
953ba169ccSSunil Mushran void o2net_fill_node_map(unsigned long *map, unsigned bytes);
963ba169ccSSunil Mushran 
9798211489SZach Brown struct o2nm_node;
9898211489SZach Brown int o2net_register_hb_callbacks(void);
9998211489SZach Brown void o2net_unregister_hb_callbacks(void);
10098211489SZach Brown int o2net_start_listening(struct o2nm_node *node);
10198211489SZach Brown void o2net_stop_listening(struct o2nm_node *node);
10298211489SZach Brown void o2net_disconnect_node(struct o2nm_node *node);
103828ae6afSAndrew Beekhof int o2net_num_connected_peers(void);
10498211489SZach Brown 
10598211489SZach Brown int o2net_init(void);
10698211489SZach Brown void o2net_exit(void);
10798211489SZach Brown 
1082309e9e0SSunil Mushran struct o2net_send_tracking;
1092309e9e0SSunil Mushran struct o2net_sock_container;
1102309e9e0SSunil Mushran 
1112309e9e0SSunil Mushran #ifdef CONFIG_DEBUG_FS
112e581595eSGreg Kroah-Hartman void o2net_debugfs_init(void);
1132309e9e0SSunil Mushran void o2net_debugfs_exit(void);
1142309e9e0SSunil Mushran void o2net_debug_add_nst(struct o2net_send_tracking *nst);
1152309e9e0SSunil Mushran void o2net_debug_del_nst(struct o2net_send_tracking *nst);
1162309e9e0SSunil Mushran void o2net_debug_add_sc(struct o2net_sock_container *sc);
1172309e9e0SSunil Mushran void o2net_debug_del_sc(struct o2net_sock_container *sc);
1182309e9e0SSunil Mushran #else
119e581595eSGreg Kroah-Hartman static inline void o2net_debugfs_init(void)
1202309e9e0SSunil Mushran {
1212309e9e0SSunil Mushran }
122271d772dSSunil Mushran static inline void o2net_debugfs_exit(void)
1232309e9e0SSunil Mushran {
1242309e9e0SSunil Mushran }
125271d772dSSunil Mushran static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
1262309e9e0SSunil Mushran {
1272309e9e0SSunil Mushran }
128271d772dSSunil Mushran static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
1292309e9e0SSunil Mushran {
1302309e9e0SSunil Mushran }
131271d772dSSunil Mushran static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
1322309e9e0SSunil Mushran {
1332309e9e0SSunil Mushran }
134271d772dSSunil Mushran static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
1352309e9e0SSunil Mushran {
1362309e9e0SSunil Mushran }
1372309e9e0SSunil Mushran #endif	/* CONFIG_DEBUG_FS */
1382309e9e0SSunil Mushran 
13998211489SZach Brown #endif /* O2CLUSTER_TCP_H */
140