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 5398211489SZach Brown typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data); 5498211489SZach Brown 5598211489SZach Brown #define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg)) 5698211489SZach Brown 57b5dd8030SJeff Mahoney /* same as hb delay, we're waiting for another node to recognize our hb */ 58b5dd8030SJeff Mahoney #define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000 59b5dd8030SJeff Mahoney 60b5dd8030SJeff Mahoney #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 5000 61b5dd8030SJeff Mahoney #define O2NET_IDLE_TIMEOUT_MS_DEFAULT 10000 62b5dd8030SJeff Mahoney 63b5dd8030SJeff Mahoney 6498211489SZach Brown /* TODO: figure this out.... */ 6598211489SZach Brown static inline int o2net_link_down(int err, struct socket *sock) 6698211489SZach Brown { 6798211489SZach Brown if (sock) { 6898211489SZach Brown if (sock->sk->sk_state != TCP_ESTABLISHED && 6998211489SZach Brown sock->sk->sk_state != TCP_CLOSE_WAIT) 7098211489SZach Brown return 1; 7198211489SZach Brown } 7298211489SZach Brown 7398211489SZach Brown if (err >= 0) 7498211489SZach Brown return 0; 7598211489SZach Brown switch (err) { 7698211489SZach Brown /* ????????????????????????? */ 7798211489SZach Brown case -ERESTARTSYS: 7898211489SZach Brown case -EBADF: 7998211489SZach Brown /* When the server has died, an ICMP port unreachable 8098211489SZach Brown * message prompts ECONNREFUSED. */ 8198211489SZach Brown case -ECONNREFUSED: 8298211489SZach Brown case -ENOTCONN: 8398211489SZach Brown case -ECONNRESET: 8498211489SZach Brown case -EPIPE: 8598211489SZach Brown return 1; 8698211489SZach Brown } 8798211489SZach Brown return 0; 8898211489SZach Brown } 8998211489SZach Brown 9098211489SZach Brown enum { 9198211489SZach Brown O2NET_DRIVER_UNINITED, 9298211489SZach Brown O2NET_DRIVER_READY, 9398211489SZach Brown }; 9498211489SZach Brown 9598211489SZach Brown int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len, 9698211489SZach Brown u8 target_node, int *status); 9798211489SZach Brown int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, 9898211489SZach Brown size_t veclen, u8 target_node, int *status); 9998211489SZach Brown 10098211489SZach Brown int o2net_register_handler(u32 msg_type, u32 key, u32 max_len, 10198211489SZach Brown o2net_msg_handler_func *func, void *data, 10298211489SZach Brown struct list_head *unreg_list); 10398211489SZach Brown void o2net_unregister_handler_list(struct list_head *list); 10498211489SZach Brown 10598211489SZach Brown struct o2nm_node; 10698211489SZach Brown int o2net_register_hb_callbacks(void); 10798211489SZach Brown void o2net_unregister_hb_callbacks(void); 10898211489SZach Brown int o2net_start_listening(struct o2nm_node *node); 10998211489SZach Brown void o2net_stop_listening(struct o2nm_node *node); 11098211489SZach Brown void o2net_disconnect_node(struct o2nm_node *node); 111828ae6afSAndrew Beekhof int o2net_num_connected_peers(void); 11298211489SZach Brown 11398211489SZach Brown int o2net_init(void); 11498211489SZach Brown void o2net_exit(void); 11598211489SZach Brown 11698211489SZach Brown #endif /* O2CLUSTER_TCP_H */ 117