Coverage Report

Created: 2023-06-07 06:12

/src/haproxy/include/haproxy/protocol.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * include/haproxy/protocol.h
3
 * This file declares generic protocol management primitives.
4
 *
5
 * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
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 _HAPROXY_PROTOCOL_H
23
#define _HAPROXY_PROTOCOL_H
24
25
#include <sys/socket.h>
26
#include <haproxy/protocol-t.h>
27
#include <haproxy/thread.h>
28
29
/* [AF][sock_dgram][ctrl_dgram] */
30
extern struct protocol *__protocol_by_family[AF_CUST_MAX][PROTO_NUM_TYPES][2];
31
__decl_thread(extern HA_SPINLOCK_T proto_lock);
32
33
/* Registers the protocol <proto> */
34
void protocol_register(struct protocol *proto);
35
36
/* Unregisters the protocol <proto>. Note that all listeners must have
37
 * previously been unbound.
38
 */
39
void protocol_unregister(struct protocol *proto);
40
41
/* clears flag <flag> on all protocols. */
42
void protocol_clrf_all(uint flag);
43
44
/* sets flag <flag> on all protocols. */
45
void protocol_setf_all(uint flag);
46
47
/* Checks if protocol <proto> supports PROTO_F flag <flag>. Returns zero if not,
48
 * non-zero if supported. It may return a cached value from a previous test,
49
 * and may run live tests then update the proto's flags to cache a result. It's
50
 * better to call it only if needed so that it doesn't result in modules being
51
 * loaded in case of a live test.
52
 */
53
int protocol_supports_flag(struct protocol *proto, uint flag);
54
55
/* binds all listeners of all registered protocols. Returns a composition
56
 * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
57
 */
58
int protocol_bind_all(int verbose);
59
60
/* unbinds all listeners of all registered protocols. They are also closed.
61
 * This must be performed before calling exit() in order to get a chance to
62
 * remove file-system based sockets and pipes.
63
 * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
64
 */
65
int protocol_unbind_all(void);
66
67
/* stops all listeners of all registered protocols. This will normally catch
68
 * every single listener, all protocols included. This is to be used during
69
 * soft_stop() only. It does not return any error.
70
 */
71
void protocol_stop_now(void);
72
73
/* pauses all listeners of all registered protocols. This is typically
74
 * used on SIG_TTOU to release all listening sockets for the time needed to
75
 * try to bind a new process. The listeners enter LI_PAUSED. It returns
76
 * ERR_NONE, with ERR_FATAL on failure.
77
 */
78
int protocol_pause_all(void);
79
80
/* resumes all listeners of all registered protocols. This is typically used on
81
 * SIG_TTIN to re-enable listening sockets after a new process failed to bind.
82
 * The listeners switch to LI_READY/LI_FULL. It returns ERR_NONE, with ERR_FATAL
83
 * on failure.
84
 */
85
int protocol_resume_all(void);
86
87
/* enables all listeners of all registered protocols. This is intended to be
88
 * used after a fork() to enable reading on all file descriptors. Returns a
89
 * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
90
 */
91
int protocol_enable_all(void);
92
93
/* returns the protocol associated to family <family> with proto_type among the
94
 * supported protocol types, and ctrl_type of either SOCK_STREAM or SOCK_DGRAM
95
 * depending on the requested values, or NULL if not found.
96
 */
97
static inline struct protocol *protocol_lookup(int family, enum proto_type proto_type, int ctrl_dgram)
98
0
{
99
0
  if (family >= 0 && family < AF_CUST_MAX)
100
0
    return __protocol_by_family[family][proto_type][!!ctrl_dgram];
101
0
  return NULL;
102
0
}
Unexecuted instantiation: cfgparse.c:protocol_lookup
Unexecuted instantiation: cli.c:protocol_lookup
Unexecuted instantiation: haproxy.c:protocol_lookup
Unexecuted instantiation: listener.c:protocol_lookup
Unexecuted instantiation: proto_sockpair.c:protocol_lookup
Unexecuted instantiation: protocol.c:protocol_lookup
Unexecuted instantiation: proxy.c:protocol_lookup
Unexecuted instantiation: resolvers.c:protocol_lookup
Unexecuted instantiation: server.c:protocol_lookup
Unexecuted instantiation: tcpcheck.c:protocol_lookup
Unexecuted instantiation: tools.c:protocol_lookup
Unexecuted instantiation: backend.c:protocol_lookup
Unexecuted instantiation: cfgparse-global.c:protocol_lookup
Unexecuted instantiation: cfgparse-listen.c:protocol_lookup
Unexecuted instantiation: check.c:protocol_lookup
Unexecuted instantiation: proto_tcp.c:protocol_lookup
103
104
#endif /* _HAPROXY_PROTOCOL_H */
105
106
/*
107
 * Local variables:
108
 *  c-indent-level: 8
109
 *  c-basic-offset: 8
110
 * End:
111
 */