mars/kernel/mars_net.h

199 lines
5.8 KiB
C
Raw Normal View History

2014-11-21 10:51:34 +00:00
/*
* MARS Long Distance Replication Software
*
* This file is part of MARS project: http://schoebel.github.io/mars/
*
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
* Copyright (C) 2011-2014 1&1 Internet AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
2011-02-23 20:48:06 +00:00
#ifndef MARS_NET_H
#define MARS_NET_H
#include <net/sock.h>
#include <net/ipconfig.h>
#include <net/tcp.h>
#include "brick.h"
2013-04-09 13:03:46 +00:00
extern int mars_net_default_port;
2012-08-06 13:04:32 +00:00
extern bool mars_net_is_alive;
2019-08-05 07:42:41 +00:00
extern __u32 enabled_net_compressions;
extern __u32 used_net_compression;
/* This needs to be incremented when low-level network protocol
* details (as opposed to mid-level changes to struct meta)
* are changing.
* Another use case is high-level changes in the order of messages
* which cannot be neither encoded into usable_features_version
* nor into usable_strategy_version.
*/
#define MARS_PROTO_LEVEL 2
2012-11-29 15:29:36 +00:00
#define MAX_FIELD_LEN 32
#define MAX_DESC_CACHE 16
struct mars_desc_cache {
u64 cache_sender_cookie;
u64 cache_recver_cookie;
s32 cache_items;
};
struct mars_desc_item {
char field_name[MAX_FIELD_LEN];
s32 field_type;
s32 field_size;
s32 field_sender_offset;
s32 field_recver_offset;
};
/* The original struct socket has no refcount. This leads to problems
* during long-lasting system calls when racing with socket shutdown.
2012-08-06 13:04:32 +00:00
*
2012-11-29 15:29:36 +00:00
* The original idea of struct mars_socket was just a small wrapper
2012-08-06 13:04:32 +00:00
* adding a refcount and some debugging aid.
2012-11-29 15:29:36 +00:00
* Later, some buffering was added in order to take advantage of
2012-08-06 13:04:32 +00:00
* kernel_sendpage().
2012-11-29 15:29:36 +00:00
* Caching of meta description has also been added.
*/
struct mars_socket {
struct socket *s_socket;
2012-08-06 13:04:32 +00:00
void *s_buffer;
atomic_t s_count;
int s_remote_proto_level; /* corresponds to MARS_PROTO_LEVEL of remote site */
2019-07-12 07:04:23 +00:00
int s_common_proto_level; /* common denominator of protocol levels */
2012-08-06 13:04:32 +00:00
int s_pos;
int s_debug_nr;
int s_send_abort;
int s_recv_abort;
int s_send_cnt;
int s_recv_cnt;
bool s_shutdown_on_err;
2013-01-10 07:40:33 +00:00
bool s_alive;
2017-09-08 12:10:11 +00:00
bool s_connected;
2012-11-29 15:29:36 +00:00
struct mars_desc_cache *s_desc_send[MAX_DESC_CACHE];
struct mars_desc_cache *s_desc_recv[MAX_DESC_CACHE];
};
2011-08-31 11:42:04 +00:00
2011-02-23 20:48:06 +00:00
struct mars_tcp_params {
int ip_tos;
int tcp_window_size;
int tcp_nodelay;
2011-02-23 20:48:06 +00:00
int tcp_timeout;
int tcp_keepcnt;
int tcp_keepintvl;
int tcp_keepidle;
};
2018-05-10 08:04:28 +00:00
enum mars_traffic_types {
MARS_TRAFFIC_META,
MARS_TRAFFIC_REPLICATION,
MARS_TRAFFIC_SYNC,
MARS_TRAFFIC_MAX /* this must come last */
};
2018-05-10 09:16:34 +00:00
extern struct mars_tcp_params mars_tcp_params[MARS_TRAFFIC_MAX];
2020-07-17 08:20:44 +00:00
/* Do not change the order, only append new members */
2011-02-23 20:48:06 +00:00
enum {
CMD_NOP,
2012-01-17 14:37:14 +00:00
CMD_NOTIFY,
CMD_CONNECT,
2011-02-23 20:48:06 +00:00
CMD_GETINFO,
CMD_GETENTS,
CMD_MREF,
CMD_CB,
2020-07-17 08:20:44 +00:00
CMD_PUSH_LINK,
2020-10-19 09:01:38 +00:00
CMD_PUSH_CHECK,
2020-07-17 08:20:44 +00:00
/* keep last element */
CMD_LAST
2011-02-23 20:48:06 +00:00
};
2012-08-01 10:09:49 +00:00
#define CMD_FLAG_MASK 255
#define CMD_FLAG_HAS_DATA 256
2011-02-23 20:48:06 +00:00
struct mars_cmd {
2019-02-19 09:18:29 +00:00
struct lamport_time cmd_stamp; // for automatic lamport clock
int cmd_proto;
2011-02-23 20:48:06 +00:00
int cmd_code;
2019-08-05 07:42:41 +00:00
__u32 cmd_compr_flags;
int cmd_compr_len;
2011-02-23 20:48:06 +00:00
int cmd_int1;
//int cmd_int2;
//int cmd_int3;
2020-07-17 07:40:34 +00:00
const char *cmd_str1;
const char *cmd_str2;
2011-02-23 20:48:06 +00:00
//char *cmd_str3;
};
2011-07-22 10:43:40 +00:00
extern char *(*mars_translate_hostname)(const char *name);
2011-02-27 14:17:58 +00:00
2011-02-23 20:48:06 +00:00
/* Low-level network traffic
*/
extern int mars_create_sockaddr(struct sockaddr_storage *addr, const char *spec);
2011-08-31 11:42:04 +00:00
extern int mars_create_socket(struct mars_socket *msock,
struct sockaddr_storage *addr,
struct mars_tcp_params *params,
bool is_server);
extern int mars_accept_socket(struct mars_socket *new_msock,
struct mars_socket *old_msock,
struct mars_tcp_params *params);
extern bool mars_get_socket(struct mars_socket *msock);
2011-08-31 11:42:04 +00:00
extern void mars_put_socket(struct mars_socket *msock);
extern void mars_shutdown_socket(struct mars_socket *msock);
extern bool mars_socket_is_alive(struct mars_socket *msock);
extern long mars_socket_send_space_available(struct mars_socket *msock);
2011-08-31 11:42:04 +00:00
2012-11-29 15:29:36 +00:00
extern int mars_send_raw(struct mars_socket *msock, const void *buf, int len, bool cork);
extern int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen);
2011-02-23 20:48:06 +00:00
/* Mid-level generic field data exchange
*/
2017-04-12 07:50:19 +00:00
extern int mars_send_struct(struct mars_socket *msock, const void *data, const struct meta *meta, bool cork);
2011-08-25 10:16:32 +00:00
#define mars_recv_struct(_sock_,_data_,_meta_) \
({ \
2012-11-29 15:29:36 +00:00
_mars_recv_struct(_sock_, _data_, _meta_, __LINE__); \
2011-08-25 10:16:32 +00:00
})
2012-11-29 15:29:36 +00:00
extern int _mars_recv_struct(struct mars_socket *msock, void *data, const struct meta *meta, int line);
2011-02-23 20:48:06 +00:00
/* High-level transport of mars structures
*/
extern int mars_send_cmd(struct mars_socket *msock, struct mars_cmd *cmd, bool cork);
extern int _mars_recv_cmd(struct mars_socket *msock, struct mars_cmd *cmd, int line);
#define mars_recv_cmd(_sock_,_cmd_) \
({ \
_mars_recv_cmd(_sock_, _cmd_, __LINE__); \
})
2017-04-12 07:56:40 +00:00
extern int mars_send_mref(struct mars_socket *msock, struct mref_object *mref, bool cork);
2012-08-01 10:09:49 +00:00
extern int mars_recv_mref(struct mars_socket *msock, struct mref_object *mref, struct mars_cmd *cmd);
2017-04-12 07:59:57 +00:00
extern int mars_send_cb(struct mars_socket *msock, struct mref_object *mref, bool cork);
2012-08-01 10:09:49 +00:00
extern int mars_recv_cb(struct mars_socket *msock, struct mref_object *mref, struct mars_cmd *cmd);
2011-02-23 20:48:06 +00:00
2011-08-25 10:16:32 +00:00
/////////////////////////////////////////////////////////////////////////
// init
extern int init_mars_net(void);
extern void exit_mars_net(void);
2011-02-23 20:48:06 +00:00
#endif