tcp.h 2.7 KB

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