/src/haproxy/include/haproxy/protocol.h
Line | Count | Source |
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 | | extern const struct proto_fam *__proto_fam_by_family[AF_CUST_MAX]; |
32 | | __decl_thread(extern HA_SPINLOCK_T proto_lock); |
33 | | |
34 | | /* Registers the protocol <proto> */ |
35 | | void protocol_register(struct protocol *proto); |
36 | | |
37 | | /* Unregisters the protocol <proto>. Note that all listeners must have |
38 | | * previously been unbound. |
39 | | */ |
40 | | void protocol_unregister(struct protocol *proto); |
41 | | |
42 | | /* clears flag <flag> on all protocols. */ |
43 | | void protocol_clrf_all(uint flag); |
44 | | |
45 | | /* sets flag <flag> on all protocols. */ |
46 | | void protocol_setf_all(uint flag); |
47 | | |
48 | | /* Checks if protocol <proto> supports PROTO_F flag <flag>. Returns zero if not, |
49 | | * non-zero if supported. It may return a cached value from a previous test, |
50 | | * and may run live tests then update the proto's flags to cache a result. It's |
51 | | * better to call it only if needed so that it doesn't result in modules being |
52 | | * loaded in case of a live test. |
53 | | */ |
54 | | int protocol_supports_flag(struct protocol *proto, uint flag); |
55 | | |
56 | | /* binds all listeners of all registered protocols. Returns a composition |
57 | | * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT. |
58 | | */ |
59 | | int protocol_bind_all(int verbose); |
60 | | |
61 | | /* unbinds all listeners of all registered protocols. They are also closed. |
62 | | * This must be performed before calling exit() in order to get a chance to |
63 | | * remove file-system based sockets and pipes. |
64 | | * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL. |
65 | | */ |
66 | | int protocol_unbind_all(void); |
67 | | |
68 | | /* stops all listeners of all registered protocols. This will normally catch |
69 | | * every single listener, all protocols included. This is to be used during |
70 | | * soft_stop() only. It does not return any error. |
71 | | */ |
72 | | void protocol_stop_now(void); |
73 | | |
74 | | /* pauses all listeners of all registered protocols. This is typically |
75 | | * used on SIG_TTOU to release all listening sockets for the time needed to |
76 | | * try to bind a new process. The listeners enter LI_PAUSED. It returns |
77 | | * ERR_NONE, with ERR_FATAL on failure. |
78 | | */ |
79 | | int protocol_pause_all(void); |
80 | | |
81 | | /* resumes all listeners of all registered protocols. This is typically used on |
82 | | * SIG_TTIN to re-enable listening sockets after a new process failed to bind. |
83 | | * The listeners switch to LI_READY/LI_FULL. It returns ERR_NONE, with ERR_FATAL |
84 | | * on failure. |
85 | | */ |
86 | | int protocol_resume_all(void); |
87 | | |
88 | | /* enables all listeners of all registered protocols. This is intended to be |
89 | | * used after a fork() to enable reading on all file descriptors. Returns a |
90 | | * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL. |
91 | | */ |
92 | | int protocol_enable_all(void); |
93 | | |
94 | | /* returns the protocol associated to family <family> with proto_type among the |
95 | | * supported protocol types, and index <alt> (0 or 1) selecting between the two |
96 | | * possible entries per (family, proto_type), or NULL if not found. |
97 | | */ |
98 | | static inline struct protocol *protocol_lookup(int family, enum proto_type proto_type, int alt) |
99 | 0 | { |
100 | 0 | if (family >= 0 && family < AF_CUST_MAX) |
101 | 0 | return __protocol_by_family[family][proto_type][!!alt]; |
102 | 0 | return NULL; |
103 | 0 | } Unexecuted instantiation: debug.c:protocol_lookup Unexecuted instantiation: fd.c:protocol_lookup Unexecuted instantiation: haproxy.c:protocol_lookup Unexecuted instantiation: http_htx.c:protocol_lookup Unexecuted instantiation: limits.c:protocol_lookup Unexecuted instantiation: listener.c:protocol_lookup Unexecuted instantiation: log.c:protocol_lookup Unexecuted instantiation: mworker.c:protocol_lookup Unexecuted instantiation: peers.c:protocol_lookup Unexecuted instantiation: pool.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: ring.c:protocol_lookup Unexecuted instantiation: sample.c:protocol_lookup Unexecuted instantiation: server.c:protocol_lookup Unexecuted instantiation: session.c:protocol_lookup Unexecuted instantiation: sink.c:protocol_lookup Unexecuted instantiation: sock.c:protocol_lookup Unexecuted instantiation: stats.c:protocol_lookup Unexecuted instantiation: stconn.c:protocol_lookup Unexecuted instantiation: stick_table.c:protocol_lookup Unexecuted instantiation: stream.c:protocol_lookup Unexecuted instantiation: tcp_rules.c:protocol_lookup Unexecuted instantiation: tcpcheck.c:protocol_lookup Unexecuted instantiation: thread.c:protocol_lookup Unexecuted instantiation: tools.c:protocol_lookup Unexecuted instantiation: trace.c:protocol_lookup Unexecuted instantiation: vars.c:protocol_lookup Unexecuted instantiation: activity.c:protocol_lookup Unexecuted instantiation: applet.c:protocol_lookup Unexecuted instantiation: backend.c:protocol_lookup Unexecuted instantiation: cfgparse-listen.c:protocol_lookup Unexecuted instantiation: cfgparse.c:protocol_lookup Unexecuted instantiation: channel.c:protocol_lookup Unexecuted instantiation: check.c:protocol_lookup Unexecuted instantiation: cli.c:protocol_lookup Unexecuted instantiation: connection.c:protocol_lookup Unexecuted instantiation: dns.c:protocol_lookup Unexecuted instantiation: dns_ring.c:protocol_lookup Unexecuted instantiation: errors.c:protocol_lookup Unexecuted instantiation: extcheck.c:protocol_lookup Unexecuted instantiation: filters.c:protocol_lookup Unexecuted instantiation: flt_http_comp.c:protocol_lookup Unexecuted instantiation: frontend.c:protocol_lookup Unexecuted instantiation: haterm.c:protocol_lookup Unexecuted instantiation: http_ana.c:protocol_lookup Unexecuted instantiation: http_ext.c:protocol_lookup Unexecuted instantiation: http_fetch.c:protocol_lookup Unexecuted instantiation: http_rules.c:protocol_lookup Unexecuted instantiation: mux_spop.c:protocol_lookup Unexecuted instantiation: pattern.c:protocol_lookup Unexecuted instantiation: payload.c:protocol_lookup Unexecuted instantiation: proto_rhttp.c:protocol_lookup Unexecuted instantiation: queue.c:protocol_lookup Unexecuted instantiation: stats-html.c:protocol_lookup Unexecuted instantiation: stats-json.c:protocol_lookup Unexecuted instantiation: stats-proxy.c:protocol_lookup Unexecuted instantiation: cache.c:protocol_lookup Unexecuted instantiation: cfgparse-global.c:protocol_lookup Unexecuted instantiation: compression.c:protocol_lookup Unexecuted instantiation: fcgi-app.c:protocol_lookup Unexecuted instantiation: flt_spoe.c:protocol_lookup Unexecuted instantiation: proto_tcp.c:protocol_lookup |
104 | | |
105 | | /* returns the proto_fam that matches ss_family. This supports custom address |
106 | | * families so it is suitable for use with ss_family as found in various config |
107 | | * element addresses. |
108 | | */ |
109 | | static inline const struct proto_fam *proto_fam_lookup(int ss_family) |
110 | 0 | { |
111 | 0 | if (ss_family >= 0 && ss_family < AF_CUST_MAX) |
112 | 0 | return __proto_fam_by_family[ss_family]; |
113 | 0 | return NULL; |
114 | 0 | } Unexecuted instantiation: debug.c:proto_fam_lookup Unexecuted instantiation: fd.c:proto_fam_lookup Unexecuted instantiation: haproxy.c:proto_fam_lookup Unexecuted instantiation: http_htx.c:proto_fam_lookup Unexecuted instantiation: limits.c:proto_fam_lookup Unexecuted instantiation: listener.c:proto_fam_lookup Unexecuted instantiation: log.c:proto_fam_lookup Unexecuted instantiation: mworker.c:proto_fam_lookup Unexecuted instantiation: peers.c:proto_fam_lookup Unexecuted instantiation: pool.c:proto_fam_lookup Unexecuted instantiation: proto_sockpair.c:proto_fam_lookup Unexecuted instantiation: protocol.c:proto_fam_lookup Unexecuted instantiation: proxy.c:proto_fam_lookup Unexecuted instantiation: resolvers.c:proto_fam_lookup Unexecuted instantiation: ring.c:proto_fam_lookup Unexecuted instantiation: sample.c:proto_fam_lookup Unexecuted instantiation: server.c:proto_fam_lookup Unexecuted instantiation: session.c:proto_fam_lookup Unexecuted instantiation: sink.c:proto_fam_lookup Unexecuted instantiation: sock.c:proto_fam_lookup Unexecuted instantiation: stats.c:proto_fam_lookup Unexecuted instantiation: stconn.c:proto_fam_lookup Unexecuted instantiation: stick_table.c:proto_fam_lookup Unexecuted instantiation: stream.c:proto_fam_lookup Unexecuted instantiation: tcp_rules.c:proto_fam_lookup Unexecuted instantiation: tcpcheck.c:proto_fam_lookup Unexecuted instantiation: thread.c:proto_fam_lookup Unexecuted instantiation: tools.c:proto_fam_lookup Unexecuted instantiation: trace.c:proto_fam_lookup Unexecuted instantiation: vars.c:proto_fam_lookup Unexecuted instantiation: activity.c:proto_fam_lookup Unexecuted instantiation: applet.c:proto_fam_lookup Unexecuted instantiation: backend.c:proto_fam_lookup Unexecuted instantiation: cfgparse-listen.c:proto_fam_lookup Unexecuted instantiation: cfgparse.c:proto_fam_lookup Unexecuted instantiation: channel.c:proto_fam_lookup Unexecuted instantiation: check.c:proto_fam_lookup Unexecuted instantiation: cli.c:proto_fam_lookup Unexecuted instantiation: connection.c:proto_fam_lookup Unexecuted instantiation: dns.c:proto_fam_lookup Unexecuted instantiation: dns_ring.c:proto_fam_lookup Unexecuted instantiation: errors.c:proto_fam_lookup Unexecuted instantiation: extcheck.c:proto_fam_lookup Unexecuted instantiation: filters.c:proto_fam_lookup Unexecuted instantiation: flt_http_comp.c:proto_fam_lookup Unexecuted instantiation: frontend.c:proto_fam_lookup Unexecuted instantiation: haterm.c:proto_fam_lookup Unexecuted instantiation: http_ana.c:proto_fam_lookup Unexecuted instantiation: http_ext.c:proto_fam_lookup Unexecuted instantiation: http_fetch.c:proto_fam_lookup Unexecuted instantiation: http_rules.c:proto_fam_lookup Unexecuted instantiation: mux_spop.c:proto_fam_lookup Unexecuted instantiation: pattern.c:proto_fam_lookup Unexecuted instantiation: payload.c:proto_fam_lookup Unexecuted instantiation: proto_rhttp.c:proto_fam_lookup Unexecuted instantiation: queue.c:proto_fam_lookup Unexecuted instantiation: stats-html.c:proto_fam_lookup Unexecuted instantiation: stats-json.c:proto_fam_lookup Unexecuted instantiation: stats-proxy.c:proto_fam_lookup Unexecuted instantiation: cache.c:proto_fam_lookup Unexecuted instantiation: cfgparse-global.c:proto_fam_lookup Unexecuted instantiation: compression.c:proto_fam_lookup Unexecuted instantiation: fcgi-app.c:proto_fam_lookup Unexecuted instantiation: flt_spoe.c:proto_fam_lookup Unexecuted instantiation: proto_tcp.c:proto_fam_lookup |
115 | | |
116 | | /* returns either the real family when known or AF_UNSPEC for non-existing |
117 | | * families. Note that real families that contain a custom value will be |
118 | | * returned as-is. This aims at simplifying address validation tests everywhere. |
119 | | */ |
120 | | static inline int real_family(int ss_family) |
121 | 0 | { |
122 | 0 | const struct proto_fam *fam = proto_fam_lookup(ss_family); |
123 | |
|
124 | 0 | return fam ? fam->real_family : AF_UNSPEC; |
125 | 0 | } Unexecuted instantiation: debug.c:real_family Unexecuted instantiation: fd.c:real_family Unexecuted instantiation: haproxy.c:real_family Unexecuted instantiation: http_htx.c:real_family Unexecuted instantiation: limits.c:real_family Unexecuted instantiation: listener.c:real_family Unexecuted instantiation: log.c:real_family Unexecuted instantiation: mworker.c:real_family Unexecuted instantiation: peers.c:real_family Unexecuted instantiation: pool.c:real_family Unexecuted instantiation: proto_sockpair.c:real_family Unexecuted instantiation: protocol.c:real_family Unexecuted instantiation: proxy.c:real_family Unexecuted instantiation: resolvers.c:real_family Unexecuted instantiation: ring.c:real_family Unexecuted instantiation: sample.c:real_family Unexecuted instantiation: server.c:real_family Unexecuted instantiation: session.c:real_family Unexecuted instantiation: sink.c:real_family Unexecuted instantiation: sock.c:real_family Unexecuted instantiation: stats.c:real_family Unexecuted instantiation: stconn.c:real_family Unexecuted instantiation: stick_table.c:real_family Unexecuted instantiation: stream.c:real_family Unexecuted instantiation: tcp_rules.c:real_family Unexecuted instantiation: tcpcheck.c:real_family Unexecuted instantiation: thread.c:real_family Unexecuted instantiation: tools.c:real_family Unexecuted instantiation: trace.c:real_family Unexecuted instantiation: vars.c:real_family Unexecuted instantiation: activity.c:real_family Unexecuted instantiation: applet.c:real_family Unexecuted instantiation: backend.c:real_family Unexecuted instantiation: cfgparse-listen.c:real_family Unexecuted instantiation: cfgparse.c:real_family Unexecuted instantiation: channel.c:real_family Unexecuted instantiation: check.c:real_family Unexecuted instantiation: cli.c:real_family Unexecuted instantiation: connection.c:real_family Unexecuted instantiation: dns.c:real_family Unexecuted instantiation: dns_ring.c:real_family Unexecuted instantiation: errors.c:real_family Unexecuted instantiation: extcheck.c:real_family Unexecuted instantiation: filters.c:real_family Unexecuted instantiation: flt_http_comp.c:real_family Unexecuted instantiation: frontend.c:real_family Unexecuted instantiation: haterm.c:real_family Unexecuted instantiation: http_ana.c:real_family Unexecuted instantiation: http_ext.c:real_family Unexecuted instantiation: http_fetch.c:real_family Unexecuted instantiation: http_rules.c:real_family Unexecuted instantiation: mux_spop.c:real_family Unexecuted instantiation: pattern.c:real_family Unexecuted instantiation: payload.c:real_family Unexecuted instantiation: proto_rhttp.c:real_family Unexecuted instantiation: queue.c:real_family Unexecuted instantiation: stats-html.c:real_family Unexecuted instantiation: stats-json.c:real_family Unexecuted instantiation: stats-proxy.c:real_family Unexecuted instantiation: cache.c:real_family Unexecuted instantiation: cfgparse-global.c:real_family Unexecuted instantiation: compression.c:real_family Unexecuted instantiation: fcgi-app.c:real_family Unexecuted instantiation: flt_spoe.c:real_family Unexecuted instantiation: proto_tcp.c:real_family |
126 | | |
127 | | static inline int proto_is_quic(const struct protocol *proto) |
128 | 0 | { |
129 | 0 | return (proto->proto_type == PROTO_TYPE_DGRAM && |
130 | 0 | proto->xprt_type == PROTO_TYPE_STREAM); |
131 | 0 | } Unexecuted instantiation: debug.c:proto_is_quic Unexecuted instantiation: fd.c:proto_is_quic Unexecuted instantiation: haproxy.c:proto_is_quic Unexecuted instantiation: http_htx.c:proto_is_quic Unexecuted instantiation: limits.c:proto_is_quic Unexecuted instantiation: listener.c:proto_is_quic Unexecuted instantiation: log.c:proto_is_quic Unexecuted instantiation: mworker.c:proto_is_quic Unexecuted instantiation: peers.c:proto_is_quic Unexecuted instantiation: pool.c:proto_is_quic Unexecuted instantiation: proto_sockpair.c:proto_is_quic Unexecuted instantiation: protocol.c:proto_is_quic Unexecuted instantiation: proxy.c:proto_is_quic Unexecuted instantiation: resolvers.c:proto_is_quic Unexecuted instantiation: ring.c:proto_is_quic Unexecuted instantiation: sample.c:proto_is_quic Unexecuted instantiation: server.c:proto_is_quic Unexecuted instantiation: session.c:proto_is_quic Unexecuted instantiation: sink.c:proto_is_quic Unexecuted instantiation: sock.c:proto_is_quic Unexecuted instantiation: stats.c:proto_is_quic Unexecuted instantiation: stconn.c:proto_is_quic Unexecuted instantiation: stick_table.c:proto_is_quic Unexecuted instantiation: stream.c:proto_is_quic Unexecuted instantiation: tcp_rules.c:proto_is_quic Unexecuted instantiation: tcpcheck.c:proto_is_quic Unexecuted instantiation: thread.c:proto_is_quic Unexecuted instantiation: tools.c:proto_is_quic Unexecuted instantiation: trace.c:proto_is_quic Unexecuted instantiation: vars.c:proto_is_quic Unexecuted instantiation: activity.c:proto_is_quic Unexecuted instantiation: applet.c:proto_is_quic Unexecuted instantiation: backend.c:proto_is_quic Unexecuted instantiation: cfgparse-listen.c:proto_is_quic Unexecuted instantiation: cfgparse.c:proto_is_quic Unexecuted instantiation: channel.c:proto_is_quic Unexecuted instantiation: check.c:proto_is_quic Unexecuted instantiation: cli.c:proto_is_quic Unexecuted instantiation: connection.c:proto_is_quic Unexecuted instantiation: dns.c:proto_is_quic Unexecuted instantiation: dns_ring.c:proto_is_quic Unexecuted instantiation: errors.c:proto_is_quic Unexecuted instantiation: extcheck.c:proto_is_quic Unexecuted instantiation: filters.c:proto_is_quic Unexecuted instantiation: flt_http_comp.c:proto_is_quic Unexecuted instantiation: frontend.c:proto_is_quic Unexecuted instantiation: haterm.c:proto_is_quic Unexecuted instantiation: http_ana.c:proto_is_quic Unexecuted instantiation: http_ext.c:proto_is_quic Unexecuted instantiation: http_fetch.c:proto_is_quic Unexecuted instantiation: http_rules.c:proto_is_quic Unexecuted instantiation: mux_spop.c:proto_is_quic Unexecuted instantiation: pattern.c:proto_is_quic Unexecuted instantiation: payload.c:proto_is_quic Unexecuted instantiation: proto_rhttp.c:proto_is_quic Unexecuted instantiation: queue.c:proto_is_quic Unexecuted instantiation: stats-html.c:proto_is_quic Unexecuted instantiation: stats-json.c:proto_is_quic Unexecuted instantiation: stats-proxy.c:proto_is_quic Unexecuted instantiation: cache.c:proto_is_quic Unexecuted instantiation: cfgparse-global.c:proto_is_quic Unexecuted instantiation: compression.c:proto_is_quic Unexecuted instantiation: fcgi-app.c:proto_is_quic Unexecuted instantiation: flt_spoe.c:proto_is_quic Unexecuted instantiation: proto_tcp.c:proto_is_quic |
132 | | |
133 | | #endif /* _HAPROXY_PROTOCOL_H */ |
134 | | |
135 | | /* |
136 | | * Local variables: |
137 | | * c-indent-level: 8 |
138 | | * c-basic-offset: 8 |
139 | | * End: |
140 | | */ |