198211489SZach Brown /* -*- mode: c; c-basic-offset: 8; -*- 298211489SZach Brown * vim: noexpandtab sw=8 ts=8 sts=0: 398211489SZach Brown * 498211489SZach Brown * tcp.h 598211489SZach Brown * 698211489SZach Brown * Function prototypes 798211489SZach Brown * 898211489SZach Brown * Copyright (C) 2004 Oracle. All rights reserved. 998211489SZach Brown * 1098211489SZach Brown * This program is free software; you can redistribute it and/or 1198211489SZach Brown * modify it under the terms of the GNU General Public 1298211489SZach Brown * License as published by the Free Software Foundation; either 1398211489SZach Brown * version 2 of the License, or (at your option) any later version. 1498211489SZach Brown * 1598211489SZach Brown * This program is distributed in the hope that it will be useful, 1698211489SZach Brown * but WITHOUT ANY WARRANTY; without even the implied warranty of 1798211489SZach Brown * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1898211489SZach Brown * General Public License for more details. 1998211489SZach Brown * 2098211489SZach Brown * You should have received a copy of the GNU General Public 2198211489SZach Brown * License along with this program; if not, write to the 2298211489SZach Brown * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 2398211489SZach Brown * Boston, MA 021110-1307, USA. 2498211489SZach Brown * 2598211489SZach Brown */ 2698211489SZach Brown 2798211489SZach Brown #ifndef O2CLUSTER_TCP_H 2898211489SZach Brown #define O2CLUSTER_TCP_H 2998211489SZach Brown 3098211489SZach Brown #include <linux/socket.h> 3198211489SZach Brown #ifdef __KERNEL__ 3298211489SZach Brown #include <net/sock.h> 3398211489SZach Brown #include <linux/tcp.h> 3498211489SZach Brown #else 3598211489SZach Brown #include <sys/socket.h> 3698211489SZach Brown #endif 3798211489SZach Brown #include <linux/inet.h> 3898211489SZach Brown #include <linux/in.h> 3998211489SZach Brown 4098211489SZach Brown struct o2net_msg 4198211489SZach Brown { 4298211489SZach Brown __be16 magic; 4398211489SZach Brown __be16 data_len; 4498211489SZach Brown __be16 msg_type; 4598211489SZach Brown __be16 pad1; 4698211489SZach Brown __be32 sys_status; 4798211489SZach Brown __be32 status; 4898211489SZach Brown __be32 key; 4998211489SZach Brown __be32 msg_num; 5098211489SZach Brown __u8 buf[0]; 5198211489SZach Brown }; 5298211489SZach Brown 53d74c9803SKurt Hackel typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data, 54d74c9803SKurt Hackel void **ret_data); 55d74c9803SKurt Hackel typedef void (o2net_post_msg_handler_func)(int status, void *data, 56d74c9803SKurt Hackel void *ret_data); 5798211489SZach Brown 5898211489SZach Brown #define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg)) 5998211489SZach Brown 60b5dd8030SJeff Mahoney /* same as hb delay, we're waiting for another node to recognize our hb */ 61b5dd8030SJeff Mahoney #define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000 62b5dd8030SJeff Mahoney 6317104683SSunil Mushran #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000 6417104683SSunil Mushran #define O2NET_IDLE_TIMEOUT_MS_DEFAULT 30000 65b5dd8030SJeff Mahoney 668e9801dfSJunxiao Bi #define O2NET_TCP_USER_TIMEOUT 0x7fffffff 67b5dd8030SJeff Mahoney 6898211489SZach Brown /* TODO: figure this out.... */ 6998211489SZach Brown static inline int o2net_link_down(int err, struct socket *sock) 7098211489SZach Brown { 7198211489SZach Brown if (sock) { 7298211489SZach Brown if (sock->sk->sk_state != TCP_ESTABLISHED && 7398211489SZach Brown sock->sk->sk_state != TCP_CLOSE_WAIT) 7498211489SZach Brown return 1; 7598211489SZach Brown } 7698211489SZach Brown 7798211489SZach Brown if (err >= 0) 7898211489SZach Brown return 0; 7998211489SZach Brown switch (err) { 8098211489SZach Brown /* ????????????????????????? */ 8198211489SZach Brown case -ERESTARTSYS: 8298211489SZach Brown case -EBADF: 8398211489SZach Brown /* When the server has died, an ICMP port unreachable 8498211489SZach Brown * message prompts ECONNREFUSED. */ 8598211489SZach Brown case -ECONNREFUSED: 8698211489SZach Brown case -ENOTCONN: 8798211489SZach Brown case -ECONNRESET: 8898211489SZach Brown case -EPIPE: 8998211489SZach Brown return 1; 9098211489SZach Brown } 9198211489SZach Brown return 0; 9298211489SZach Brown } 9398211489SZach Brown 9498211489SZach Brown enum { 9598211489SZach Brown O2NET_DRIVER_UNINITED, 9698211489SZach Brown O2NET_DRIVER_READY, 9798211489SZach Brown }; 9898211489SZach Brown 9998211489SZach Brown int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len, 10098211489SZach Brown u8 target_node, int *status); 10198211489SZach Brown int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, 10298211489SZach Brown size_t veclen, u8 target_node, int *status); 10398211489SZach Brown 10498211489SZach Brown int o2net_register_handler(u32 msg_type, u32 key, u32 max_len, 10598211489SZach Brown o2net_msg_handler_func *func, void *data, 106d74c9803SKurt Hackel o2net_post_msg_handler_func *post_func, 10798211489SZach Brown struct list_head *unreg_list); 10898211489SZach Brown void o2net_unregister_handler_list(struct list_head *list); 10998211489SZach Brown 1103ba169ccSSunil Mushran void o2net_fill_node_map(unsigned long *map, unsigned bytes); 1113ba169ccSSunil Mushran 11298211489SZach Brown struct o2nm_node; 11398211489SZach Brown int o2net_register_hb_callbacks(void); 11498211489SZach Brown void o2net_unregister_hb_callbacks(void); 11598211489SZach Brown int o2net_start_listening(struct o2nm_node *node); 11698211489SZach Brown void o2net_stop_listening(struct o2nm_node *node); 11798211489SZach Brown void o2net_disconnect_node(struct o2nm_node *node); 118828ae6afSAndrew Beekhof int o2net_num_connected_peers(void); 11998211489SZach Brown 12098211489SZach Brown int o2net_init(void); 12198211489SZach Brown void o2net_exit(void); 12298211489SZach Brown 1232309e9e0SSunil Mushran struct o2net_send_tracking; 1242309e9e0SSunil Mushran struct o2net_sock_container; 1252309e9e0SSunil Mushran 1262309e9e0SSunil Mushran #ifdef CONFIG_DEBUG_FS 1272309e9e0SSunil Mushran int o2net_debugfs_init(void); 1282309e9e0SSunil Mushran void o2net_debugfs_exit(void); 1292309e9e0SSunil Mushran void o2net_debug_add_nst(struct o2net_send_tracking *nst); 1302309e9e0SSunil Mushran void o2net_debug_del_nst(struct o2net_send_tracking *nst); 1312309e9e0SSunil Mushran void o2net_debug_add_sc(struct o2net_sock_container *sc); 1322309e9e0SSunil Mushran void o2net_debug_del_sc(struct o2net_sock_container *sc); 1332309e9e0SSunil Mushran #else 134271d772dSSunil Mushran static inline int o2net_debugfs_init(void) 1352309e9e0SSunil Mushran { 1362309e9e0SSunil Mushran return 0; 1372309e9e0SSunil Mushran } 138271d772dSSunil Mushran static inline void o2net_debugfs_exit(void) 1392309e9e0SSunil Mushran { 1402309e9e0SSunil Mushran } 141271d772dSSunil Mushran static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst) 1422309e9e0SSunil Mushran { 1432309e9e0SSunil Mushran } 144271d772dSSunil Mushran static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst) 1452309e9e0SSunil Mushran { 1462309e9e0SSunil Mushran } 147271d772dSSunil Mushran static inline void o2net_debug_add_sc(struct o2net_sock_container *sc) 1482309e9e0SSunil Mushran { 1492309e9e0SSunil Mushran } 150271d772dSSunil Mushran static inline void o2net_debug_del_sc(struct o2net_sock_container *sc) 1512309e9e0SSunil Mushran { 1522309e9e0SSunil Mushran } 1532309e9e0SSunil Mushran #endif /* CONFIG_DEBUG_FS */ 1542309e9e0SSunil Mushran 15598211489SZach Brown #endif /* O2CLUSTER_TCP_H */ 156