tcp.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #ifndef O2CLUSTER_TCP_H
  27. #define O2CLUSTER_TCP_H
  28. #include <linux/socket.h>
  29. #ifdef __KERNEL__
  30. #include <net/sock.h>
  31. #include <linux/tcp.h>
  32. #else
  33. #include <sys/socket.h>
  34. #endif
  35. #include <linux/inet.h>
  36. #include <linux/in.h>
  37. struct o2net_msg
  38. {
  39. __be16 magic;
  40. __be16 data_len;
  41. __be16 msg_type;
  42. __be16 pad1;
  43. __be32 sys_status;
  44. __be32 status;
  45. __be32 key;
  46. __be32 msg_num;
  47. __u8 buf[0];
  48. };
  49. typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
  50. void **ret_data);
  51. typedef void (o2net_post_msg_handler_func)(int status, void *data,
  52. void *ret_data);
  53. #define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg))
  54. /* same as hb delay, we're waiting for another node to recognize our hb */
  55. #define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000
  56. #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 2000
  57. #define O2NET_IDLE_TIMEOUT_MS_DEFAULT 30000
  58. /* TODO: figure this out.... */
  59. static inline int o2net_link_down(int err, struct socket *sock)
  60. {
  61. if (sock) {
  62. if (sock->sk->sk_state != TCP_ESTABLISHED &&
  63. sock->sk->sk_state != TCP_CLOSE_WAIT)
  64. return 1;
  65. }
  66. if (err >= 0)
  67. return 0;
  68. switch (err) {
  69. /* ????????????????????????? */
  70. case -ERESTARTSYS:
  71. case -EBADF:
  72. /* When the server has died, an ICMP port unreachable
  73. * message prompts ECONNREFUSED. */
  74. case -ECONNREFUSED:
  75. case -ENOTCONN:
  76. case -ECONNRESET:
  77. case -EPIPE:
  78. return 1;
  79. }
  80. return 0;
  81. }
  82. enum {
  83. O2NET_DRIVER_UNINITED,
  84. O2NET_DRIVER_READY,
  85. };
  86. int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
  87. u8 target_node, int *status);
  88. int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
  89. size_t veclen, u8 target_node, int *status);
  90. int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
  91. o2net_msg_handler_func *func, void *data,
  92. o2net_post_msg_handler_func *post_func,
  93. struct list_head *unreg_list);
  94. void o2net_unregister_handler_list(struct list_head *list);
  95. void o2net_fill_node_map(unsigned long *map, unsigned bytes);
  96. struct o2nm_node;
  97. int o2net_register_hb_callbacks(void);
  98. void o2net_unregister_hb_callbacks(void);
  99. int o2net_start_listening(struct o2nm_node *node);
  100. void o2net_stop_listening(struct o2nm_node *node);
  101. void o2net_disconnect_node(struct o2nm_node *node);
  102. int o2net_num_connected_peers(void);
  103. int o2net_init(void);
  104. void o2net_exit(void);
  105. struct o2net_send_tracking;
  106. struct o2net_sock_container;
  107. #ifdef CONFIG_DEBUG_FS
  108. int o2net_debugfs_init(void);
  109. void o2net_debugfs_exit(void);
  110. void o2net_debug_add_nst(struct o2net_send_tracking *nst);
  111. void o2net_debug_del_nst(struct o2net_send_tracking *nst);
  112. void o2net_debug_add_sc(struct o2net_sock_container *sc);
  113. void o2net_debug_del_sc(struct o2net_sock_container *sc);
  114. #else
  115. static inline int o2net_debugfs_init(void)
  116. {
  117. return 0;
  118. }
  119. static inline void o2net_debugfs_exit(void)
  120. {
  121. }
  122. static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
  123. {
  124. }
  125. static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
  126. {
  127. }
  128. static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
  129. {
  130. }
  131. static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
  132. {
  133. }
  134. #endif /* CONFIG_DEBUG_FS */
  135. #endif /* O2CLUSTER_TCP_H */