blob: 66df33c3f753b1ecd1776db199d1eb01f323bc90 [file] [log] [blame]
Willy Tarreaue6b98942007-10-29 01:09:36 +01001/*
Willy Tarreaub1d67742010-03-29 19:36:59 +02002 * include/proto/proto_tcp.h
3 * This file contains TCP socket protocol definitions.
4 *
Willy Tarreaud4c33c82013-01-07 21:59:07 +01005 * Copyright (C) 2000-2013 Willy Tarreau - w@1wt.eu
Willy Tarreaub1d67742010-03-29 19:36:59 +02006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
Willy Tarreaue6b98942007-10-29 01:09:36 +010021
22#ifndef _PROTO_PROTO_TCP_H
23#define _PROTO_PROTO_TCP_H
24
25#include <common/config.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010026#include <types/task.h>
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020027#include <proto/stick_table.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010028
David du Colombier6f5ccb12011-03-10 22:26:24 +010029int tcp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct sockaddr_storage *remote);
Willy Tarreaue6b98942007-10-29 01:09:36 +010030void tcpv4_add_listener(struct listener *listener);
31void tcpv6_add_listener(struct listener *listener);
Willy Tarreau092d8652014-07-07 20:22:12 +020032int tcp_pause_listener(struct listener *l);
Willy Tarreauf0837b22012-11-24 10:24:27 +010033int tcp_connect_server(struct connection *conn, int data, int delack);
Willy Tarreau239d7182012-07-23 18:53:03 +020034int tcp_connect_probe(struct connection *conn);
Willy Tarreau59b94792012-05-11 16:16:40 +020035int tcp_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
36int tcp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
Willy Tarreau2b57cb82013-06-10 19:56:38 +020037int tcp_drain(int fd);
Willy Tarreau87b09662015-04-03 00:22:06 +020038int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit);
39int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit);
Willy Tarreaue73ef852015-04-04 16:41:45 +020040int tcp_exec_req_rules(struct session *sess);
Willy Tarreaue6b98942007-10-29 01:09:36 +010041
Thierry FOURNIERcc87a112014-12-12 19:41:33 +010042/* TCP keywords. */
Thierry FOURNIER36481b82015-08-19 09:01:53 +020043void tcp_req_conn_keywords_register(struct action_kw_list *kw_list);
44void tcp_req_cont_keywords_register(struct action_kw_list *kw_list);
45void tcp_res_cont_keywords_register(struct action_kw_list *kw_list);
Thierry FOURNIERcc87a112014-12-12 19:41:33 +010046
Thierry FOURNIERa123ad82015-07-24 09:12:15 +020047/* Export some samples. */
48int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private);
49
Willy Tarreau64ee4912012-08-30 22:59:48 +020050/* Converts the INET/INET6 source address to a stick_table key usable for table
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +020051 * lookups. <type> can be SMP_T_IPV4 or SMP_T_IPV6. The function
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020052 * try to convert the incoming IP to the type expected by the sticktable.
53 * Returns either NULL if the source cannot be converted (eg: not IPv4) or a
54 * pointer to the converted result in static_table_key in the appropriate format
55 * (IP).
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020056 */
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020057static inline struct stktable_key *addr_to_stktable_key(struct sockaddr_storage *addr, long type)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020058{
Willy Tarreau64ee4912012-08-30 22:59:48 +020059 switch (addr->ss_family) {
David du Colombier4f92d322011-03-24 11:09:31 +010060 case AF_INET:
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020061 /* Convert IPv4 to IPv4 key. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +020062 if (type == SMP_T_IPV4) {
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020063 static_table_key->key = (void *)&((struct sockaddr_in *)addr)->sin_addr;
64 break;
65 }
66 /* Convert IPv4 to IPv6 key. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +020067 if (type == SMP_T_IPV6) {
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020068 v4tov6(&static_table_key->data.ipv6, &((struct sockaddr_in *)addr)->sin_addr);
69 static_table_key->key = &static_table_key->data.ipv6;
70 break;
71 }
72 return NULL;
73
David du Colombier4f92d322011-03-24 11:09:31 +010074 case AF_INET6:
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020075 /* Convert IPv6 to IPv4 key. This conversion can be failed. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +020076 if (type == SMP_T_IPV4) {
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +020077 if (!v6tov4(&static_table_key->data.ipv4, &((struct sockaddr_in6 *)addr)->sin6_addr))
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020078 return NULL;
Thierry FOURNIERbc8c4042015-08-10 17:53:45 +020079 static_table_key->key = &static_table_key->data.ipv4;
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020080 break;
81 }
82 /* Convert IPv6 to IPv6 key. */
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +020083 if (type == SMP_T_IPV6) {
Thierry FOURNIER74c219d2014-04-14 14:35:40 +020084 static_table_key->key = (void *)&((struct sockaddr_in6 *)addr)->sin6_addr;
85 break;
86 }
87 return NULL;
Willy Tarreauc3a08a12012-08-30 22:52:28 +020088 default:
89 return NULL;
David du Colombier4f92d322011-03-24 11:09:31 +010090 }
Willy Tarreau07115412012-10-29 21:56:59 +010091 return static_table_key;
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020092}
93
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020094/* for a tcp-request action ACT_TCP_TRK_*, return a tracking index starting at
Willy Tarreau34c2fb62013-12-02 23:29:05 +010095 * zero for SC0. Unknown actions also return zero.
Willy Tarreaud5ca9ab2013-05-28 17:40:25 +020096 */
97static inline int tcp_trk_idx(int trk_action)
98{
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020099 return trk_action - ACT_ACTION_TRK_SC0;
Willy Tarreaud5ca9ab2013-05-28 17:40:25 +0200100}
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200101
Willy Tarreaue6b98942007-10-29 01:09:36 +0100102#endif /* _PROTO_PROTO_TCP_H */
103
104/*
105 * Local variables:
106 * c-indent-level: 8
107 * c-basic-offset: 8
108 * End:
109 */