blob: b3e1e4429398a353cd482af6809586095d3ce6e1 [file] [log] [blame]
Emeric Brun2b920a12010-09-23 18:30:22 +02001/*
2 * include/types/peers.h
3 * This file defines everything related to peers.
4 *
5 * Copyright 2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
6 *
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 */
21
22#ifndef _TYPES_PEERS_H
23#define _TYPES_PEERS_H
24
25#include <sys/types.h>
26#include <sys/socket.h>
27#include <netinet/in.h>
28#include <arpa/inet.h>
29
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020030#include <haproxy/api-t.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020031#include <haproxy/list-t.h>
Emeric Brun2b920a12010-09-23 18:30:22 +020032#include <common/regex.h>
Willy Tarreau8d2b7772020-05-27 10:58:19 +020033#include <import/eb32tree.h>
Emeric Brun2b920a12010-09-23 18:30:22 +020034
Frédéric Lécaille74167b22019-05-28 19:02:42 +020035#include <types/dict.h>
36
Emeric Brun2b920a12010-09-23 18:30:22 +020037struct shared_table {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020038 struct stktable *table; /* stick table to sync */
Emeric Brunb3971ab2015-05-12 18:49:09 +020039 int local_id;
40 int remote_id;
41 int flags;
42 uint64_t remote_data;
43 unsigned int last_acked;
44 unsigned int last_pushed;
45 unsigned int last_get;
46 unsigned int teaching_origin;
47 unsigned int update;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020048 struct shared_table *next; /* next shared table in list */
Emeric Brun2b920a12010-09-23 18:30:22 +020049};
50
51struct peer {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020052 int local; /* proxy state */
Emeric Brun2b920a12010-09-23 18:30:22 +020053 char *id;
Emeric Brun2b920a12010-09-23 18:30:22 +020054 struct {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020055 const char *file; /* file where the section appears */
56 int line; /* line where the section appears */
57 } conf; /* config information */
Emeric Brun2b920a12010-09-23 18:30:22 +020058 time_t last_change;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020059 struct sockaddr_storage addr; /* peer address */
60 struct protocol *proto; /* peer address protocol */
61 struct xprt_ops *xprt; /* peer socket operations at transport layer */
62 void *sock_init_arg; /* socket operations's opaque init argument if needed */
63 unsigned int flags; /* peer session flags */
Emeric Brunb3971ab2015-05-12 18:49:09 +020064 unsigned int statuscode; /* current/last session status code */
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020065 unsigned int reconnect; /* next connect timer */
66 unsigned int heartbeat; /* next heartbeat timer */
Emeric Brunb3971ab2015-05-12 18:49:09 +020067 unsigned int confirm; /* confirm message counter */
Frédéric Lécaille33cab3c2019-11-06 11:51:26 +010068 uint32_t rx_hbt; /* received heartbeats counter */
69 uint32_t tx_hbt; /* transmitted heartbeats counter */
Frédéric Lécailleec1c10b2019-11-07 15:22:33 +010070 uint32_t no_hbt; /* no received heartbeat counter */
71 uint32_t new_conn; /* new connection after reconnection timeout expiration counter */
72 uint32_t proto_err; /* protocol errors counter */
Emeric Brunb3971ab2015-05-12 18:49:09 +020073 struct appctx *appctx; /* the appctx running it */
74 struct shared_table *remote_table;
75 struct shared_table *last_local_table;
76 struct shared_table *tables;
Frédéric Lécaille1055e682018-04-26 14:35:21 +020077 struct server *srv;
Frédéric Lécaille8d78fa72019-05-20 18:22:52 +020078 struct dcache *dcache; /* dictionary cache */
Christopher Faulet9dcf9b62017-11-13 10:34:01 +010079 __decl_hathreads(HA_SPINLOCK_T lock); /* lock used to handle this peer section */
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020080 struct peer *next; /* next peer in the list */
Emeric Brun2b920a12010-09-23 18:30:22 +020081};
82
83
84struct peers {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020085 int state; /* proxy state */
86 char *id; /* peer section name */
87 struct task *sync_task; /* main sync task */
88 struct sig_handler *sighandler; /* signal handler */
89 struct peer *remote; /* remote peers list */
90 struct peer *local; /* local peer list */
91 struct proxy *peers_fe; /* peer frontend */
Emeric Brun2b920a12010-09-23 18:30:22 +020092 struct {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020093 const char *file; /* file where the section appears */
94 int line; /* line where the section appears */
95 } conf; /* config information */
Emeric Brun2b920a12010-09-23 18:30:22 +020096 time_t last_change;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020097 struct peers *next; /* next peer section */
98 unsigned int flags; /* current peers section resync state */
99 unsigned int resync_timeout; /* resync timeout timer */
100 int count; /* total of peers */
Emeric Brun2b920a12010-09-23 18:30:22 +0200101};
102
Frédéric Lécaille74167b22019-05-28 19:02:42 +0200103/* LRU cache for dictionaies */
104struct dcache_tx {
105 /* The last recently used key */
106 unsigned int lru_key;
Frédéric Lécaille6c391982019-06-06 11:34:03 +0200107 /* An array of entries to store pointers to dictionary entries. */
108 struct ebpt_node *entries;
Frédéric Lécailleb65717f2019-06-07 14:25:25 +0200109 /* The previous lookup result. */
110 struct ebpt_node *prev_lookup;
Frédéric Lécaille6c391982019-06-06 11:34:03 +0200111 /* ebtree to store the previous entries. */
112 struct eb_root cached_entries;
Frédéric Lécaille74167b22019-05-28 19:02:42 +0200113};
114
115struct dcache_rx {
116 unsigned int id;
117 struct dict_entry *de;
118};
119
120struct dcache_tx_entry {
Frédéric Lécaille6c391982019-06-06 11:34:03 +0200121 unsigned int id;
122 struct ebpt_node entry;
Frédéric Lécaille74167b22019-05-28 19:02:42 +0200123};
124
125/* stick-table data type cache */
126struct dcache {
127 /* Cache used upon transmission */
128 struct dcache_tx *tx;
129 /* Cache used upon receipt */
130 struct dcache_rx *rx;
131 /* Maximum number of entries in this cache */
132 size_t max_entries;
133};
Emeric Brun2b920a12010-09-23 18:30:22 +0200134
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200135extern struct peers *cfg_peers;
Emeric Brun2b920a12010-09-23 18:30:22 +0200136
137#endif /* _TYPES_PEERS_H */
138