tcp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg))
  51. /* same as hb delay, we're waiting for another node to recognize our hb */
  52. #define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000
  53. #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 5000
  54. #define O2NET_IDLE_TIMEOUT_MS_DEFAULT 10000
  55. /* TODO: figure this out.... */
  56. static inline int o2net_link_down(int err, struct socket *sock)
  57. {
  58. if (sock) {
  59. if (sock->sk->sk_state != TCP_ESTABLISHED &&
  60. sock->sk->sk_state != TCP_CLOSE_WAIT)
  61. return 1;
  62. }
  63. if (err >= 0)
  64. return 0;
  65. switch (err) {
  66. /* ????????????????????????? */
  67. case -ERESTARTSYS:
  68. case -EBADF:
  69. /* When the server has died, an ICMP port unreachable
  70. * message prompts ECONNREFUSED. */
  71. case -ECONNREFUSED:
  72. case -ENOTCONN:
  73. case -ECONNRESET:
  74. case -EPIPE:
  75. return 1;
  76. }
  77. return 0;
  78. }
  79. enum {
  80. O2NET_DRIVER_UNINITED,
  81. O2NET_DRIVER_READY,
  82. };
  83. int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
  84. u8 target_node, int *status);
  85. int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
  86. size_t veclen, u8 target_node, int *status);
  87. int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
  88. o2net_msg_handler_func *func, void *data,
  89. struct list_head *unreg_list);
  90. void o2net_unregister_handler_list(struct list_head *list);
  91. struct o2nm_node;
  92. int o2net_register_hb_callbacks(void);
  93. void o2net_unregister_hb_callbacks(void);
  94. int o2net_start_listening(struct o2nm_node *node);
  95. void o2net_stop_listening(struct o2nm_node *node);
  96. void o2net_disconnect_node(struct o2nm_node *node);
  97. int o2net_num_connected_peers(void);
  98. int o2net_init(void);
  99. void o2net_exit(void);
  100. #endif /* O2CLUSTER_TCP_H */