Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * tcp.h |
| 5 | * |
| 6 | * Function prototypes |
| 7 | * |
| 8 | * Copyright (C) 2004 Oracle. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public |
| 21 | * License along with this program; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 021110-1307, USA. |
| 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 | |
| 40 | struct 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 | |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 53 | typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data, |
| 54 | void **ret_data); |
| 55 | typedef void (o2net_post_msg_handler_func)(int status, void *data, |
| 56 | void *ret_data); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 57 | |
| 58 | #define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg)) |
| 59 | |
Jeff Mahoney | b5dd803 | 2006-12-04 14:04:54 +0100 | [diff] [blame] | 60 | /* same as hb delay, we're waiting for another node to recognize our hb */ |
| 61 | #define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000 |
| 62 | |
Sunil Mushran | 1710468 | 2007-11-06 16:10:23 -0800 | [diff] [blame] | 63 | #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000 |
| 64 | #define O2NET_IDLE_TIMEOUT_MS_DEFAULT 30000 |
Jeff Mahoney | b5dd803 | 2006-12-04 14:04:54 +0100 | [diff] [blame] | 65 | |
| 66 | |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 67 | /* TODO: figure this out.... */ |
| 68 | static inline int o2net_link_down(int err, struct socket *sock) |
| 69 | { |
| 70 | if (sock) { |
| 71 | if (sock->sk->sk_state != TCP_ESTABLISHED && |
| 72 | sock->sk->sk_state != TCP_CLOSE_WAIT) |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | if (err >= 0) |
| 77 | return 0; |
| 78 | switch (err) { |
| 79 | /* ????????????????????????? */ |
| 80 | case -ERESTARTSYS: |
| 81 | case -EBADF: |
| 82 | /* When the server has died, an ICMP port unreachable |
| 83 | * message prompts ECONNREFUSED. */ |
| 84 | case -ECONNREFUSED: |
| 85 | case -ENOTCONN: |
| 86 | case -ECONNRESET: |
| 87 | case -EPIPE: |
| 88 | return 1; |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | enum { |
| 94 | O2NET_DRIVER_UNINITED, |
| 95 | O2NET_DRIVER_READY, |
| 96 | }; |
| 97 | |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 98 | int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len, |
| 99 | u8 target_node, int *status); |
| 100 | int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec, |
| 101 | size_t veclen, u8 target_node, int *status); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 102 | |
| 103 | int o2net_register_handler(u32 msg_type, u32 key, u32 max_len, |
| 104 | o2net_msg_handler_func *func, void *data, |
Kurt Hackel | d74c980 | 2007-01-17 17:04:25 -0800 | [diff] [blame] | 105 | o2net_post_msg_handler_func *post_func, |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 106 | struct list_head *unreg_list); |
| 107 | void o2net_unregister_handler_list(struct list_head *list); |
| 108 | |
Sunil Mushran | 3ba169c | 2011-07-24 10:32:54 -0700 | [diff] [blame] | 109 | void o2net_fill_node_map(unsigned long *map, unsigned bytes); |
| 110 | |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 111 | struct o2nm_node; |
| 112 | int o2net_register_hb_callbacks(void); |
| 113 | void o2net_unregister_hb_callbacks(void); |
| 114 | int o2net_start_listening(struct o2nm_node *node); |
| 115 | void o2net_stop_listening(struct o2nm_node *node); |
| 116 | void o2net_disconnect_node(struct o2nm_node *node); |
Andrew Beekhof | 828ae6a | 2006-12-04 14:04:55 +0100 | [diff] [blame] | 117 | int o2net_num_connected_peers(void); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 118 | |
| 119 | int o2net_init(void); |
| 120 | void o2net_exit(void); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 121 | |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 122 | struct o2net_send_tracking; |
| 123 | struct o2net_sock_container; |
| 124 | |
| 125 | #ifdef CONFIG_DEBUG_FS |
| 126 | int o2net_debugfs_init(void); |
| 127 | void o2net_debugfs_exit(void); |
| 128 | void o2net_debug_add_nst(struct o2net_send_tracking *nst); |
| 129 | void o2net_debug_del_nst(struct o2net_send_tracking *nst); |
| 130 | void o2net_debug_add_sc(struct o2net_sock_container *sc); |
| 131 | void o2net_debug_del_sc(struct o2net_sock_container *sc); |
| 132 | #else |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 133 | static inline int o2net_debugfs_init(void) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 134 | { |
| 135 | return 0; |
| 136 | } |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 137 | static inline void o2net_debugfs_exit(void) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 138 | { |
| 139 | } |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 140 | static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 141 | { |
| 142 | } |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 143 | static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 144 | { |
| 145 | } |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 146 | static inline void o2net_debug_add_sc(struct o2net_sock_container *sc) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 147 | { |
| 148 | } |
Sunil Mushran | 271d772 | 2008-05-12 18:31:35 -0700 | [diff] [blame] | 149 | static inline void o2net_debug_del_sc(struct o2net_sock_container *sc) |
Sunil Mushran | 2309e9e | 2008-04-14 10:46:19 -0700 | [diff] [blame] | 150 | { |
| 151 | } |
| 152 | #endif /* CONFIG_DEBUG_FS */ |
| 153 | |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 154 | #endif /* O2CLUSTER_TCP_H */ |