Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * tcp.h
0004  *
0005  * Function prototypes
0006  *
0007  * Copyright (C) 2004 Oracle.  All rights reserved.
0008  */
0009 
0010 #ifndef O2CLUSTER_TCP_H
0011 #define O2CLUSTER_TCP_H
0012 
0013 #include <linux/socket.h>
0014 #ifdef __KERNEL__
0015 #include <net/sock.h>
0016 #include <linux/tcp.h>
0017 #else
0018 #include <sys/socket.h>
0019 #endif
0020 #include <linux/inet.h>
0021 #include <linux/in.h>
0022 
0023 struct o2net_msg
0024 {
0025     __be16 magic;
0026     __be16 data_len;
0027     __be16 msg_type;
0028     __be16 pad1;
0029     __be32 sys_status;
0030     __be32 status;
0031     __be32 key;
0032     __be32 msg_num;
0033     __u8  buf[];
0034 };
0035 
0036 typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
0037                      void **ret_data);
0038 typedef void (o2net_post_msg_handler_func)(int status, void *data,
0039                        void *ret_data);
0040 
0041 #define O2NET_MAX_PAYLOAD_BYTES  (4096 - sizeof(struct o2net_msg))
0042 
0043 /* same as hb delay, we're waiting for another node to recognize our hb */
0044 #define O2NET_RECONNECT_DELAY_MS_DEFAULT    2000
0045 
0046 #define O2NET_KEEPALIVE_DELAY_MS_DEFAULT    2000
0047 #define O2NET_IDLE_TIMEOUT_MS_DEFAULT       30000
0048 
0049 #define O2NET_TCP_USER_TIMEOUT          0x7fffffff
0050 
0051 /* TODO: figure this out.... */
0052 static inline int o2net_link_down(int err, struct socket *sock)
0053 {
0054     if (sock) {
0055         if (sock->sk->sk_state != TCP_ESTABLISHED &&
0056                 sock->sk->sk_state != TCP_CLOSE_WAIT)
0057             return 1;
0058     }
0059 
0060     if (err >= 0)
0061         return 0;
0062     switch (err) {
0063         /* ????????????????????????? */
0064         case -ERESTARTSYS:
0065         case -EBADF:
0066         /* When the server has died, an ICMP port unreachable
0067          * message prompts ECONNREFUSED. */
0068         case -ECONNREFUSED:
0069         case -ENOTCONN:
0070         case -ECONNRESET:
0071         case -EPIPE:
0072             return 1;
0073     }
0074     return 0;
0075 }
0076 
0077 enum {
0078     O2NET_DRIVER_UNINITED,
0079     O2NET_DRIVER_READY,
0080 };
0081 
0082 int o2net_send_message(u32 msg_type, u32 key, void *data, u32 len,
0083                u8 target_node, int *status);
0084 int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *vec,
0085                size_t veclen, u8 target_node, int *status);
0086 
0087 int o2net_register_handler(u32 msg_type, u32 key, u32 max_len,
0088                o2net_msg_handler_func *func, void *data,
0089                o2net_post_msg_handler_func *post_func,
0090                struct list_head *unreg_list);
0091 void o2net_unregister_handler_list(struct list_head *list);
0092 
0093 void o2net_fill_node_map(unsigned long *map, unsigned bytes);
0094 
0095 struct o2nm_node;
0096 int o2net_register_hb_callbacks(void);
0097 void o2net_unregister_hb_callbacks(void);
0098 int o2net_start_listening(struct o2nm_node *node);
0099 void o2net_stop_listening(struct o2nm_node *node);
0100 void o2net_disconnect_node(struct o2nm_node *node);
0101 int o2net_num_connected_peers(void);
0102 
0103 int o2net_init(void);
0104 void o2net_exit(void);
0105 
0106 struct o2net_send_tracking;
0107 struct o2net_sock_container;
0108 
0109 #ifdef CONFIG_DEBUG_FS
0110 void o2net_debugfs_init(void);
0111 void o2net_debugfs_exit(void);
0112 void o2net_debug_add_nst(struct o2net_send_tracking *nst);
0113 void o2net_debug_del_nst(struct o2net_send_tracking *nst);
0114 void o2net_debug_add_sc(struct o2net_sock_container *sc);
0115 void o2net_debug_del_sc(struct o2net_sock_container *sc);
0116 #else
0117 static inline void o2net_debugfs_init(void)
0118 {
0119 }
0120 static inline void o2net_debugfs_exit(void)
0121 {
0122 }
0123 static inline void o2net_debug_add_nst(struct o2net_send_tracking *nst)
0124 {
0125 }
0126 static inline void o2net_debug_del_nst(struct o2net_send_tracking *nst)
0127 {
0128 }
0129 static inline void o2net_debug_add_sc(struct o2net_sock_container *sc)
0130 {
0131 }
0132 static inline void o2net_debug_del_sc(struct o2net_sock_container *sc)
0133 {
0134 }
0135 #endif  /* CONFIG_DEBUG_FS */
0136 
0137 #endif /* O2CLUSTER_TCP_H */