| 1 | /* |
| 2 | * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License, version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #ifndef _LTTCOMM_INET_H |
| 19 | #define _LTTCOMM_INET_H |
| 20 | |
| 21 | #define _GNU_SOURCE |
| 22 | #include <limits.h> |
| 23 | |
| 24 | #include "sessiond-comm.h" |
| 25 | |
| 26 | /* See man tcp(7) for more detail about this value. */ |
| 27 | #define LTTCOMM_INET_PROC_SYN_RETRIES_PATH "/proc/sys/net/ipv4/tcp_syn_retries" |
| 28 | #define LTTCOMM_INET_PROC_FIN_TIMEOUT_PATH "/proc/sys/net/ipv4/tcp_fin_timeout" |
| 29 | |
| 30 | /* |
| 31 | * The timeout value of a connect() is computed with an algorithm inside the |
| 32 | * kernel using the defined TCP SYN retries so the end value in time is |
| 33 | * approximative. According to tcp(7) man page, a value of 5 is roughly 180 |
| 34 | * seconds of timeout. With that information, we've computed a factor of 36 |
| 35 | * (180/5) by considering that it grows linearly. This is of course uncertain |
| 36 | * but this is the best approximation we can do at runtime. |
| 37 | */ |
| 38 | #define LTTCOMM_INET_SYN_TIMEOUT_FACTOR 36 |
| 39 | |
| 40 | /* |
| 41 | * Maximum timeout value in seconds of a TCP connection for both send/recv and |
| 42 | * connect operations. |
| 43 | */ |
| 44 | extern unsigned long lttcomm_inet_tcp_timeout; |
| 45 | |
| 46 | /* Stub */ |
| 47 | struct lttcomm_sock; |
| 48 | |
| 49 | /* Net family callback */ |
| 50 | extern int lttcomm_create_inet_sock(struct lttcomm_sock *sock, int type, |
| 51 | int proto); |
| 52 | |
| 53 | extern struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock); |
| 54 | extern int lttcomm_bind_inet_sock(struct lttcomm_sock *sock); |
| 55 | extern int lttcomm_close_inet_sock(struct lttcomm_sock *sock); |
| 56 | extern int lttcomm_connect_inet_sock(struct lttcomm_sock *sock); |
| 57 | extern int lttcomm_listen_inet_sock(struct lttcomm_sock *sock, int backlog); |
| 58 | |
| 59 | extern ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, |
| 60 | size_t len, int flags); |
| 61 | extern ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, |
| 62 | size_t len, int flags); |
| 63 | |
| 64 | /* Initialize inet communication layer. */ |
| 65 | extern void lttcomm_inet_init(void); |
| 66 | |
| 67 | #endif /* _LTTCOMM_INET_H */ |