Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * AF_INET/AF_INET6 SOCK_STREAM protocol layer (tcp) |
| 3 | * |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 4 | * Copyright 2000-2010 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <ctype.h> |
| 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <time.h> |
| 20 | |
| 21 | #include <sys/param.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/un.h> |
| 26 | |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 27 | #include <netinet/tcp.h> |
| 28 | |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 29 | #include <common/cfgparse.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 30 | #include <common/compat.h> |
| 31 | #include <common/config.h> |
| 32 | #include <common/debug.h> |
| 33 | #include <common/errors.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 34 | #include <common/mini-clist.h> |
| 35 | #include <common/standard.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 36 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 37 | #include <types/global.h> |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 38 | #include <types/server.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 39 | |
| 40 | #include <proto/acl.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 41 | #include <proto/buffers.h> |
Willy Tarreau | 03fa5df | 2010-05-24 21:02:37 +0200 | [diff] [blame] | 42 | #include <proto/frontend.h> |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 43 | #include <proto/log.h> |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 44 | #include <proto/pattern.h> |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 45 | #include <proto/port_range.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 46 | #include <proto/protocols.h> |
| 47 | #include <proto/proto_tcp.h> |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 48 | #include <proto/proxy.h> |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 49 | #include <proto/session.h> |
Willy Tarreau | a975b8f | 2010-06-05 19:13:27 +0200 | [diff] [blame] | 50 | #include <proto/stick_table.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 51 | #include <proto/stream_sock.h> |
Willy Tarreau | a975b8f | 2010-06-05 19:13:27 +0200 | [diff] [blame] | 52 | #include <proto/task.h> |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 53 | #include <proto/buffers.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 54 | |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_HAP_CTTPROXY |
| 56 | #include <import/ip_tproxy.h> |
| 57 | #endif |
| 58 | |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 59 | static int tcp_bind_listeners(struct protocol *proto, char *errmsg, int errlen); |
| 60 | static int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 61 | |
| 62 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 63 | static struct protocol proto_tcpv4 = { |
| 64 | .name = "tcpv4", |
| 65 | .sock_domain = AF_INET, |
| 66 | .sock_type = SOCK_STREAM, |
| 67 | .sock_prot = IPPROTO_TCP, |
| 68 | .sock_family = AF_INET, |
| 69 | .sock_addrlen = sizeof(struct sockaddr_in), |
| 70 | .l3_addrlen = 32/8, |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 71 | .accept = &stream_sock_accept, |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 72 | .read = &stream_sock_read, |
| 73 | .write = &stream_sock_write, |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 74 | .bind = tcp_bind_listener, |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 75 | .bind_all = tcp_bind_listeners, |
| 76 | .unbind_all = unbind_all_listeners, |
| 77 | .enable_all = enable_all_listeners, |
| 78 | .listeners = LIST_HEAD_INIT(proto_tcpv4.listeners), |
| 79 | .nb_listeners = 0, |
| 80 | }; |
| 81 | |
| 82 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 83 | static struct protocol proto_tcpv6 = { |
| 84 | .name = "tcpv6", |
| 85 | .sock_domain = AF_INET6, |
| 86 | .sock_type = SOCK_STREAM, |
| 87 | .sock_prot = IPPROTO_TCP, |
| 88 | .sock_family = AF_INET6, |
| 89 | .sock_addrlen = sizeof(struct sockaddr_in6), |
| 90 | .l3_addrlen = 128/8, |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 91 | .accept = &stream_sock_accept, |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 92 | .read = &stream_sock_read, |
| 93 | .write = &stream_sock_write, |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 94 | .bind = tcp_bind_listener, |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 95 | .bind_all = tcp_bind_listeners, |
| 96 | .unbind_all = unbind_all_listeners, |
| 97 | .enable_all = enable_all_listeners, |
| 98 | .listeners = LIST_HEAD_INIT(proto_tcpv6.listeners), |
| 99 | .nb_listeners = 0, |
| 100 | }; |
| 101 | |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 102 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 103 | /* Binds ipv4/ipv6 address <local> to socket <fd>, unless <flags> is set, in which |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 104 | * case we try to bind <remote>. <flags> is a 2-bit field consisting of : |
| 105 | * - 0 : ignore remote address (may even be a NULL pointer) |
| 106 | * - 1 : use provided address |
| 107 | * - 2 : use provided port |
| 108 | * - 3 : use both |
| 109 | * |
| 110 | * The function supports multiple foreign binding methods : |
| 111 | * - linux_tproxy: we directly bind to the foreign address |
| 112 | * - cttproxy: we bind to a local address then nat. |
| 113 | * The second one can be used as a fallback for the first one. |
| 114 | * This function returns 0 when everything's OK, 1 if it could not bind, to the |
| 115 | * local address, 2 if it could not bind to the foreign address. |
| 116 | */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 117 | int tcp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct sockaddr_storage *remote) |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 118 | { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 119 | struct sockaddr_storage bind_addr; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 120 | int foreign_ok = 0; |
| 121 | int ret; |
| 122 | |
| 123 | #ifdef CONFIG_HAP_LINUX_TPROXY |
| 124 | static int ip_transp_working = 1; |
| 125 | if (flags && ip_transp_working) { |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 126 | if (setsockopt(fd, SOL_IP, IP_TRANSPARENT, &one, sizeof(one)) == 0 |
| 127 | || setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == 0) |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 128 | foreign_ok = 1; |
| 129 | else |
| 130 | ip_transp_working = 0; |
| 131 | } |
| 132 | #endif |
| 133 | if (flags) { |
| 134 | memset(&bind_addr, 0, sizeof(bind_addr)); |
Willy Tarreau | 96dd079 | 2011-04-19 07:20:57 +0200 | [diff] [blame] | 135 | bind_addr.ss_family = remote->ss_family; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 136 | switch (remote->ss_family) { |
| 137 | case AF_INET: |
| 138 | if (flags & 1) |
| 139 | ((struct sockaddr_in *)&bind_addr)->sin_addr = ((struct sockaddr_in *)remote)->sin_addr; |
| 140 | if (flags & 2) |
| 141 | ((struct sockaddr_in *)&bind_addr)->sin_port = ((struct sockaddr_in *)remote)->sin_port; |
| 142 | break; |
| 143 | case AF_INET6: |
| 144 | if (flags & 1) |
| 145 | ((struct sockaddr_in6 *)&bind_addr)->sin6_addr = ((struct sockaddr_in6 *)remote)->sin6_addr; |
| 146 | if (flags & 2) |
| 147 | ((struct sockaddr_in6 *)&bind_addr)->sin6_port = ((struct sockaddr_in6 *)remote)->sin6_port; |
| 148 | break; |
Willy Tarreau | 5dc1e98 | 2011-12-16 21:25:11 +0100 | [diff] [blame] | 149 | default: |
| 150 | /* we don't want to try to bind to an unknown address family */ |
| 151 | foreign_ok = 0; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 152 | } |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 155 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 156 | if (foreign_ok) { |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 157 | ret = bind(fd, (struct sockaddr *)&bind_addr, get_addr_len(&bind_addr)); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 158 | if (ret < 0) |
| 159 | return 2; |
| 160 | } |
| 161 | else { |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 162 | ret = bind(fd, (struct sockaddr *)local, get_addr_len(local)); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 163 | if (ret < 0) |
| 164 | return 1; |
| 165 | } |
| 166 | |
| 167 | if (!flags) |
| 168 | return 0; |
| 169 | |
| 170 | #ifdef CONFIG_HAP_CTTPROXY |
Willy Tarreau | 6f831b4 | 2011-03-20 14:03:54 +0100 | [diff] [blame] | 171 | if (!foreign_ok && remote->ss_family == AF_INET) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 172 | struct in_tproxy itp1, itp2; |
| 173 | memset(&itp1, 0, sizeof(itp1)); |
| 174 | |
| 175 | itp1.op = TPROXY_ASSIGN; |
Willy Tarreau | 6f831b4 | 2011-03-20 14:03:54 +0100 | [diff] [blame] | 176 | itp1.v.addr.faddr = ((struct sockaddr_in *)&bind_addr)->sin_addr; |
| 177 | itp1.v.addr.fport = ((struct sockaddr_in *)&bind_addr)->sin_port; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 178 | |
| 179 | /* set connect flag on socket */ |
| 180 | itp2.op = TPROXY_FLAGS; |
| 181 | itp2.v.flags = ITP_CONNECT | ITP_ONCE; |
| 182 | |
| 183 | if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) != -1 && |
| 184 | setsockopt(fd, SOL_IP, IP_TPROXY, &itp2, sizeof(itp2)) != -1) { |
| 185 | foreign_ok = 1; |
| 186 | } |
| 187 | } |
| 188 | #endif |
| 189 | if (!foreign_ok) |
| 190 | /* we could not bind to a foreign address */ |
| 191 | return 2; |
| 192 | |
| 193 | return 0; |
| 194 | } |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 195 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 196 | |
| 197 | /* |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 198 | * This function initiates a connection to the target assigned to this session |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 199 | * (si->{target,addr.to}). A source address may be pointed to by si->addr.from |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 200 | * in case of transparent proxying. Normal source bind addresses are still |
| 201 | * determined locally (due to the possible need of a source port). |
| 202 | * si->target may point either to a valid server or to a backend, depending |
| 203 | * on si->target.type. Only TARG_TYPE_PROXY and TARG_TYPE_SERVER are supported. |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 204 | * |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 205 | * It can return one of : |
| 206 | * - SN_ERR_NONE if everything's OK |
| 207 | * - SN_ERR_SRVTO if there are no more servers |
| 208 | * - SN_ERR_SRVCL if the connection was refused by the server |
| 209 | * - SN_ERR_PRXCOND if the connection has been limited by the proxy (maxconn) |
| 210 | * - SN_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...) |
| 211 | * - SN_ERR_INTERNAL for any other purely internal errors |
| 212 | * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted. |
| 213 | */ |
Willy Tarreau | f153686 | 2011-03-03 18:27:32 +0100 | [diff] [blame] | 214 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 215 | int tcp_connect_server(struct stream_interface *si) |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 216 | { |
| 217 | int fd; |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 218 | struct server *srv; |
| 219 | struct proxy *be; |
| 220 | |
| 221 | switch (si->target.type) { |
| 222 | case TARG_TYPE_PROXY: |
| 223 | be = si->target.ptr.p; |
| 224 | srv = NULL; |
| 225 | break; |
| 226 | case TARG_TYPE_SERVER: |
| 227 | srv = si->target.ptr.s; |
| 228 | be = srv->proxy; |
| 229 | break; |
| 230 | default: |
| 231 | return SN_ERR_INTERNAL; |
| 232 | } |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 233 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 234 | if ((fd = si->fd = socket(si->addr.to.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 235 | qfprintf(stderr, "Cannot get a server socket.\n"); |
| 236 | |
| 237 | if (errno == ENFILE) |
| 238 | send_log(be, LOG_EMERG, |
| 239 | "Proxy %s reached system FD limit at %d. Please check system tunables.\n", |
| 240 | be->id, maxfd); |
| 241 | else if (errno == EMFILE) |
| 242 | send_log(be, LOG_EMERG, |
| 243 | "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", |
| 244 | be->id, maxfd); |
| 245 | else if (errno == ENOBUFS || errno == ENOMEM) |
| 246 | send_log(be, LOG_EMERG, |
| 247 | "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", |
| 248 | be->id, maxfd); |
| 249 | /* this is a resource error */ |
| 250 | return SN_ERR_RESOURCE; |
| 251 | } |
| 252 | |
| 253 | if (fd >= global.maxsock) { |
| 254 | /* do not log anything there, it's a normal condition when this option |
| 255 | * is used to serialize connections to a server ! |
| 256 | */ |
| 257 | Alert("socket(): not enough free sockets. Raise -n argument. Giving up.\n"); |
| 258 | close(fd); |
| 259 | return SN_ERR_PRXCOND; /* it is a configuration limit */ |
| 260 | } |
| 261 | |
| 262 | if ((fcntl(fd, F_SETFL, O_NONBLOCK)==-1) || |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 263 | (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) == -1)) { |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 264 | qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); |
| 265 | close(fd); |
| 266 | return SN_ERR_INTERNAL; |
| 267 | } |
| 268 | |
| 269 | if (be->options & PR_O_TCP_SRV_KA) |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 270 | setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 271 | |
| 272 | if (be->options & PR_O_TCP_NOLING) |
Willy Tarreau | f6f8225 | 2011-11-30 18:02:24 +0100 | [diff] [blame] | 273 | si->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 274 | |
| 275 | /* allow specific binding : |
| 276 | * - server-specific at first |
| 277 | * - proxy-specific next |
| 278 | */ |
| 279 | if (srv != NULL && srv->state & SRV_BIND_SRC) { |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 280 | int ret, flags = 0; |
| 281 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 282 | switch (srv->state & SRV_TPROXY_MASK) { |
| 283 | case SRV_TPROXY_ADDR: |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 284 | case SRV_TPROXY_CLI: |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 285 | flags = 3; |
| 286 | break; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 287 | case SRV_TPROXY_CIP: |
Willy Tarreau | 090466c | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 288 | case SRV_TPROXY_DYN: |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 289 | flags = 1; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 290 | break; |
| 291 | } |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 292 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 293 | #ifdef SO_BINDTODEVICE |
| 294 | /* Note: this might fail if not CAP_NET_RAW */ |
| 295 | if (srv->iface_name) |
| 296 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, srv->iface_name, srv->iface_len + 1); |
| 297 | #endif |
| 298 | |
| 299 | if (srv->sport_range) { |
| 300 | int attempts = 10; /* should be more than enough to find a spare port */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 301 | struct sockaddr_storage src; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 302 | |
| 303 | ret = 1; |
| 304 | src = srv->source_addr; |
| 305 | |
| 306 | do { |
| 307 | /* note: in case of retry, we may have to release a previously |
| 308 | * allocated port, hence this loop's construct. |
| 309 | */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 310 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 311 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 312 | |
| 313 | if (!attempts) |
| 314 | break; |
| 315 | attempts--; |
| 316 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 317 | fdinfo[fd].local_port = port_range_alloc_port(srv->sport_range); |
| 318 | if (!fdinfo[fd].local_port) |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 319 | break; |
| 320 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 321 | fdinfo[fd].port_range = srv->sport_range; |
Willy Tarreau | 86ad42c | 2011-08-27 12:29:07 +0200 | [diff] [blame] | 322 | set_host_port(&src, fdinfo[fd].local_port); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 323 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 324 | ret = tcp_bind_socket(fd, flags, &src, &si->addr.from); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 325 | } while (ret != 0); /* binding NOK */ |
| 326 | } |
| 327 | else { |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 328 | ret = tcp_bind_socket(fd, flags, &srv->source_addr, &si->addr.from); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | if (ret) { |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 332 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 333 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 334 | close(fd); |
| 335 | |
| 336 | if (ret == 1) { |
| 337 | Alert("Cannot bind to source address before connect() for server %s/%s. Aborting.\n", |
| 338 | be->id, srv->id); |
| 339 | send_log(be, LOG_EMERG, |
| 340 | "Cannot bind to source address before connect() for server %s/%s.\n", |
| 341 | be->id, srv->id); |
| 342 | } else { |
| 343 | Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n", |
| 344 | be->id, srv->id); |
| 345 | send_log(be, LOG_EMERG, |
| 346 | "Cannot bind to tproxy source address before connect() for server %s/%s.\n", |
| 347 | be->id, srv->id); |
| 348 | } |
| 349 | return SN_ERR_RESOURCE; |
| 350 | } |
| 351 | } |
| 352 | else if (be->options & PR_O_BIND_SRC) { |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 353 | int ret, flags = 0; |
| 354 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 355 | switch (be->options & PR_O_TPXY_MASK) { |
| 356 | case PR_O_TPXY_ADDR: |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 357 | case PR_O_TPXY_CLI: |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 358 | flags = 3; |
| 359 | break; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 360 | case PR_O_TPXY_CIP: |
Willy Tarreau | 090466c | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 361 | case PR_O_TPXY_DYN: |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 362 | flags = 1; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 363 | break; |
| 364 | } |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 365 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 366 | #ifdef SO_BINDTODEVICE |
| 367 | /* Note: this might fail if not CAP_NET_RAW */ |
| 368 | if (be->iface_name) |
| 369 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, be->iface_name, be->iface_len + 1); |
| 370 | #endif |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 371 | ret = tcp_bind_socket(fd, flags, &be->source_addr, &si->addr.from); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 372 | if (ret) { |
| 373 | close(fd); |
| 374 | if (ret == 1) { |
| 375 | Alert("Cannot bind to source address before connect() for proxy %s. Aborting.\n", |
| 376 | be->id); |
| 377 | send_log(be, LOG_EMERG, |
| 378 | "Cannot bind to source address before connect() for proxy %s.\n", |
| 379 | be->id); |
| 380 | } else { |
| 381 | Alert("Cannot bind to tproxy source address before connect() for proxy %s. Aborting.\n", |
| 382 | be->id); |
| 383 | send_log(be, LOG_EMERG, |
| 384 | "Cannot bind to tproxy source address before connect() for proxy %s.\n", |
| 385 | be->id); |
| 386 | } |
| 387 | return SN_ERR_RESOURCE; |
| 388 | } |
| 389 | } |
| 390 | |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 391 | #if defined(TCP_QUICKACK) |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 392 | /* disabling tcp quick ack now allows the first request to leave the |
| 393 | * machine with the first ACK. We only do this if there are pending |
| 394 | * data in the buffer. |
| 395 | */ |
| 396 | if ((be->options2 & PR_O2_SMARTCON) && si->ob->send_max) |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 397 | setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, &zero, sizeof(zero)); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 398 | #endif |
| 399 | |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 400 | if (global.tune.server_sndbuf) |
| 401 | setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &global.tune.server_sndbuf, sizeof(global.tune.server_sndbuf)); |
| 402 | |
| 403 | if (global.tune.server_rcvbuf) |
| 404 | setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf)); |
| 405 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 406 | if ((connect(fd, (struct sockaddr *)&si->addr.to, get_addr_len(&si->addr.to)) == -1) && |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 407 | (errno != EINPROGRESS) && (errno != EALREADY) && (errno != EISCONN)) { |
| 408 | |
| 409 | if (errno == EAGAIN || errno == EADDRINUSE) { |
| 410 | char *msg; |
| 411 | if (errno == EAGAIN) /* no free ports left, try again later */ |
| 412 | msg = "no free ports"; |
| 413 | else |
| 414 | msg = "local address already in use"; |
| 415 | |
| 416 | qfprintf(stderr,"Cannot connect: %s.\n",msg); |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 417 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 418 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 419 | close(fd); |
| 420 | send_log(be, LOG_EMERG, |
| 421 | "Connect() failed for server %s/%s: %s.\n", |
| 422 | be->id, srv->id, msg); |
| 423 | return SN_ERR_RESOURCE; |
| 424 | } else if (errno == ETIMEDOUT) { |
| 425 | //qfprintf(stderr,"Connect(): ETIMEDOUT"); |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 426 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 427 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 428 | close(fd); |
| 429 | return SN_ERR_SRVTO; |
| 430 | } else { |
| 431 | // (errno == ECONNREFUSED || errno == ENETUNREACH || errno == EACCES || errno == EPERM) |
| 432 | //qfprintf(stderr,"Connect(): %d", errno); |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 433 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 434 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 435 | close(fd); |
| 436 | return SN_ERR_SRVCL; |
| 437 | } |
| 438 | } |
| 439 | |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 440 | /* needs src ip/port for logging */ |
| 441 | if (si->flags & SI_FL_SRC_ADDR) { |
| 442 | socklen_t addrlen = sizeof(si->addr.to); |
| 443 | if (getsockname(fd, (struct sockaddr *)&si->addr.from, &addrlen) == -1) { |
| 444 | Warning("Cannot get source address for logging.\n"); |
| 445 | } |
| 446 | } |
| 447 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 448 | fdtab[fd].owner = si; |
| 449 | fdtab[fd].state = FD_STCONN; /* connection in progress */ |
| 450 | fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; |
| 451 | fdtab[fd].cb[DIR_RD].f = &stream_sock_read; |
| 452 | fdtab[fd].cb[DIR_RD].b = si->ib; |
| 453 | fdtab[fd].cb[DIR_WR].f = &stream_sock_write; |
| 454 | fdtab[fd].cb[DIR_WR].b = si->ob; |
| 455 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 456 | fdinfo[fd].peeraddr = (struct sockaddr *)&si->addr.to; |
| 457 | fdinfo[fd].peerlen = get_addr_len(&si->addr.to); |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 458 | |
| 459 | fd_insert(fd); |
| 460 | EV_FD_SET(fd, DIR_WR); /* for connect status */ |
| 461 | |
| 462 | si->state = SI_ST_CON; |
| 463 | si->flags |= SI_FL_CAP_SPLTCP; /* TCP supports splicing */ |
| 464 | si->exp = tick_add_ifset(now_ms, be->timeout.connect); |
| 465 | |
| 466 | return SN_ERR_NONE; /* connection is OK */ |
| 467 | } |
| 468 | |
| 469 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 470 | /* This function tries to bind a TCPv4/v6 listener. It may return a warning or |
| 471 | * an error message in <err> if the message is at most <errlen> bytes long |
| 472 | * (including '\0'). The return value is composed from ERR_ABORT, ERR_WARN, |
| 473 | * ERR_ALERT, ERR_RETRYABLE and ERR_FATAL. ERR_NONE indicates that everything |
| 474 | * was alright and that no message was returned. ERR_RETRYABLE means that an |
| 475 | * error occurred but that it may vanish after a retry (eg: port in use), and |
| 476 | * ERR_FATAL indicates a non-fixable error.ERR_WARN and ERR_ALERT do not alter |
| 477 | * the meaning of the error, but just indicate that a message is present which |
| 478 | * should be displayed with the respective level. Last, ERR_ABORT indicates |
| 479 | * that it's pointless to try to start other listeners. No error message is |
| 480 | * returned if errlen is NULL. |
| 481 | */ |
| 482 | int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) |
| 483 | { |
| 484 | __label__ tcp_return, tcp_close_return; |
| 485 | int fd, err; |
| 486 | const char *msg = NULL; |
| 487 | |
| 488 | /* ensure we never return garbage */ |
| 489 | if (errmsg && errlen) |
| 490 | *errmsg = 0; |
| 491 | |
| 492 | if (listener->state != LI_ASSIGNED) |
| 493 | return ERR_NONE; /* already bound */ |
| 494 | |
| 495 | err = ERR_NONE; |
| 496 | |
| 497 | if ((fd = socket(listener->addr.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { |
| 498 | err |= ERR_RETRYABLE | ERR_ALERT; |
| 499 | msg = "cannot create listening socket"; |
| 500 | goto tcp_return; |
| 501 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 502 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 503 | if (fd >= global.maxsock) { |
| 504 | err |= ERR_FATAL | ERR_ABORT | ERR_ALERT; |
| 505 | msg = "not enough free sockets (raise '-n' parameter)"; |
| 506 | goto tcp_close_return; |
| 507 | } |
| 508 | |
Willy Tarreau | fb14edc | 2009-06-14 15:24:37 +0200 | [diff] [blame] | 509 | if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 510 | err |= ERR_FATAL | ERR_ALERT; |
| 511 | msg = "cannot make socket non-blocking"; |
| 512 | goto tcp_close_return; |
| 513 | } |
| 514 | |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 515 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) { |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 516 | /* not fatal but should be reported */ |
| 517 | msg = "cannot do so_reuseaddr"; |
| 518 | err |= ERR_ALERT; |
| 519 | } |
| 520 | |
| 521 | if (listener->options & LI_O_NOLINGER) |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 522 | setsockopt(fd, SOL_SOCKET, SO_LINGER, &nolinger, sizeof(struct linger)); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 523 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 524 | #ifdef SO_REUSEPORT |
| 525 | /* OpenBSD supports this. As it's present in old libc versions of Linux, |
| 526 | * it might return an error that we will silently ignore. |
| 527 | */ |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 528 | setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 529 | #endif |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 530 | #ifdef CONFIG_HAP_LINUX_TPROXY |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 531 | if ((listener->options & LI_O_FOREIGN) |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 532 | && (setsockopt(fd, SOL_IP, IP_TRANSPARENT, &one, sizeof(one)) == -1) |
| 533 | && (setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == -1)) { |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 534 | msg = "cannot make listening socket transparent"; |
| 535 | err |= ERR_ALERT; |
| 536 | } |
| 537 | #endif |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 538 | #ifdef SO_BINDTODEVICE |
| 539 | /* Note: this might fail if not CAP_NET_RAW */ |
| 540 | if (listener->interface) { |
| 541 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 542 | listener->interface, strlen(listener->interface) + 1) == -1) { |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 543 | msg = "cannot bind listener to device"; |
| 544 | err |= ERR_WARN; |
| 545 | } |
| 546 | } |
| 547 | #endif |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 548 | #if defined(TCP_MAXSEG) |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 549 | if (listener->maxseg > 0) { |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 550 | if (setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, |
Willy Tarreau | be1b918 | 2009-06-14 18:48:19 +0200 | [diff] [blame] | 551 | &listener->maxseg, sizeof(listener->maxseg)) == -1) { |
| 552 | msg = "cannot set MSS"; |
| 553 | err |= ERR_WARN; |
| 554 | } |
| 555 | } |
| 556 | #endif |
Willy Tarreau | cb6cd43 | 2009-10-13 07:34:14 +0200 | [diff] [blame] | 557 | #if defined(TCP_DEFER_ACCEPT) |
| 558 | if (listener->options & LI_O_DEF_ACCEPT) { |
| 559 | /* defer accept by up to one second */ |
| 560 | int accept_delay = 1; |
| 561 | if (setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &accept_delay, sizeof(accept_delay)) == -1) { |
| 562 | msg = "cannot enable DEFER_ACCEPT"; |
| 563 | err |= ERR_WARN; |
| 564 | } |
| 565 | } |
| 566 | #endif |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 567 | if (bind(fd, (struct sockaddr *)&listener->addr, listener->proto->sock_addrlen) == -1) { |
| 568 | err |= ERR_RETRYABLE | ERR_ALERT; |
| 569 | msg = "cannot bind socket"; |
| 570 | goto tcp_close_return; |
| 571 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 572 | |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 573 | if (listen(fd, listener->backlog ? listener->backlog : listener->maxconn) == -1) { |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 574 | err |= ERR_RETRYABLE | ERR_ALERT; |
| 575 | msg = "cannot listen to socket"; |
| 576 | goto tcp_close_return; |
| 577 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 578 | |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 579 | #if defined(TCP_QUICKACK) |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 580 | if (listener->options & LI_O_NOQUICKACK) |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 581 | setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, &zero, sizeof(zero)); |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 582 | #endif |
| 583 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 584 | /* the socket is ready */ |
| 585 | listener->fd = fd; |
| 586 | listener->state = LI_LISTEN; |
| 587 | |
Willy Tarreau | eabf313 | 2008-08-29 23:36:51 +0200 | [diff] [blame] | 588 | fdtab[fd].owner = listener; /* reference the listener instead of a task */ |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 589 | fdtab[fd].state = FD_STLISTEN; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 590 | fdtab[fd].flags = FD_FL_TCP | ((listener->options & LI_O_NOLINGER) ? FD_FL_TCP_NOLING : 0); |
| 591 | fdtab[fd].cb[DIR_RD].f = listener->proto->accept; |
| 592 | fdtab[fd].cb[DIR_WR].f = NULL; /* never called */ |
| 593 | fdtab[fd].cb[DIR_RD].b = fdtab[fd].cb[DIR_WR].b = NULL; |
Willy Tarreau | 5d707e1 | 2009-06-28 11:09:07 +0200 | [diff] [blame] | 594 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 595 | fdinfo[fd].peeraddr = NULL; |
| 596 | fdinfo[fd].peerlen = 0; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 597 | fd_insert(fd); |
| 598 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 599 | tcp_return: |
Cyril Bonté | 43ba1b3 | 2010-11-01 19:26:01 +0100 | [diff] [blame] | 600 | if (msg && errlen) { |
| 601 | char pn[INET6_ADDRSTRLEN]; |
| 602 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 603 | addr_to_str(&listener->addr, pn, sizeof(pn)); |
| 604 | snprintf(errmsg, errlen, "%s [%s:%d]", msg, pn, get_host_port(&listener->addr)); |
Cyril Bonté | 43ba1b3 | 2010-11-01 19:26:01 +0100 | [diff] [blame] | 605 | } |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 606 | return err; |
| 607 | |
| 608 | tcp_close_return: |
| 609 | close(fd); |
| 610 | goto tcp_return; |
| 611 | } |
| 612 | |
| 613 | /* This function creates all TCP sockets bound to the protocol entry <proto>. |
| 614 | * It is intended to be used as the protocol's bind_all() function. |
| 615 | * The sockets will be registered but not added to any fd_set, in order not to |
| 616 | * loose them across the fork(). A call to enable_all_listeners() is needed |
| 617 | * to complete initialization. The return value is composed from ERR_*. |
| 618 | */ |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 619 | static int tcp_bind_listeners(struct protocol *proto, char *errmsg, int errlen) |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 620 | { |
| 621 | struct listener *listener; |
| 622 | int err = ERR_NONE; |
| 623 | |
| 624 | list_for_each_entry(listener, &proto->listeners, proto_list) { |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 625 | err |= tcp_bind_listener(listener, errmsg, errlen); |
| 626 | if (err & ERR_ABORT) |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | |
| 630 | return err; |
| 631 | } |
| 632 | |
| 633 | /* Add listener to the list of tcpv4 listeners. The listener's state |
| 634 | * is automatically updated from LI_INIT to LI_ASSIGNED. The number of |
| 635 | * listeners is updated. This is the function to use to add a new listener. |
| 636 | */ |
| 637 | void tcpv4_add_listener(struct listener *listener) |
| 638 | { |
| 639 | if (listener->state != LI_INIT) |
| 640 | return; |
| 641 | listener->state = LI_ASSIGNED; |
| 642 | listener->proto = &proto_tcpv4; |
| 643 | LIST_ADDQ(&proto_tcpv4.listeners, &listener->proto_list); |
| 644 | proto_tcpv4.nb_listeners++; |
| 645 | } |
| 646 | |
| 647 | /* Add listener to the list of tcpv4 listeners. The listener's state |
| 648 | * is automatically updated from LI_INIT to LI_ASSIGNED. The number of |
| 649 | * listeners is updated. This is the function to use to add a new listener. |
| 650 | */ |
| 651 | void tcpv6_add_listener(struct listener *listener) |
| 652 | { |
| 653 | if (listener->state != LI_INIT) |
| 654 | return; |
| 655 | listener->state = LI_ASSIGNED; |
| 656 | listener->proto = &proto_tcpv6; |
| 657 | LIST_ADDQ(&proto_tcpv6.listeners, &listener->proto_list); |
| 658 | proto_tcpv6.nb_listeners++; |
| 659 | } |
| 660 | |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 661 | /* This function performs the TCP request analysis on the current request. It |
| 662 | * returns 1 if the processing can continue on next analysers, or zero if it |
| 663 | * needs more data, encounters an error, or wants to immediately abort the |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 664 | * request. It relies on buffers flags, and updates s->req->analysers. The |
| 665 | * function may be called for frontend rules and backend rules. It only relies |
| 666 | * on the backend pointer so this works for both cases. |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 667 | */ |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 668 | int tcp_inspect_request(struct session *s, struct buffer *req, int an_bit) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 669 | { |
| 670 | struct tcp_rule *rule; |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 671 | struct stksess *ts; |
| 672 | struct stktable *t; |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 673 | int partial; |
| 674 | |
| 675 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 676 | now_ms, __FUNCTION__, |
| 677 | s, |
| 678 | req, |
| 679 | req->rex, req->wex, |
| 680 | req->flags, |
| 681 | req->l, |
| 682 | req->analysers); |
| 683 | |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 684 | /* We don't know whether we have enough data, so must proceed |
| 685 | * this way : |
| 686 | * - iterate through all rules in their declaration order |
| 687 | * - if one rule returns MISS, it means the inspect delay is |
| 688 | * not over yet, then return immediately, otherwise consider |
| 689 | * it as a non-match. |
| 690 | * - if one rule returns OK, then return OK |
| 691 | * - if one rule returns KO, then return KO |
| 692 | */ |
| 693 | |
Willy Tarreau | b824b00 | 2010-09-29 16:36:16 +0200 | [diff] [blame] | 694 | if (req->flags & (BF_SHUTR|BF_FULL) || !s->be->tcp_req.inspect_delay || tick_is_expired(req->analyse_exp, now_ms)) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 695 | partial = 0; |
| 696 | else |
| 697 | partial = ACL_PARTIAL; |
| 698 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 699 | list_for_each_entry(rule, &s->be->tcp_req.inspect_rules, list) { |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 700 | int ret = ACL_PAT_PASS; |
| 701 | |
| 702 | if (rule->cond) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 703 | ret = acl_exec_cond(rule->cond, s->be, s, &s->txn, ACL_DIR_REQ | partial); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 704 | if (ret == ACL_PAT_MISS) { |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 705 | buffer_dont_connect(req); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 706 | /* just set the request timeout once at the beginning of the request */ |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 707 | if (!tick_isset(req->analyse_exp) && s->be->tcp_req.inspect_delay) |
| 708 | req->analyse_exp = tick_add_ifset(now_ms, s->be->tcp_req.inspect_delay); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | ret = acl_pass(ret); |
| 713 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 714 | ret = !ret; |
| 715 | } |
| 716 | |
| 717 | if (ret) { |
| 718 | /* we have a matching rule. */ |
| 719 | if (rule->action == TCP_ACT_REJECT) { |
| 720 | buffer_abort(req); |
| 721 | buffer_abort(s->rep); |
| 722 | req->analysers = 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 723 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 724 | s->be->be_counters.denied_req++; |
| 725 | s->fe->fe_counters.denied_req++; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 726 | if (s->listener->counters) |
Willy Tarreau | 23968d8 | 2010-05-23 23:50:44 +0200 | [diff] [blame] | 727 | s->listener->counters->denied_req++; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 728 | |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 729 | if (!(s->flags & SN_ERR_MASK)) |
| 730 | s->flags |= SN_ERR_PRXCOND; |
| 731 | if (!(s->flags & SN_FINST_MASK)) |
| 732 | s->flags |= SN_FINST_R; |
| 733 | return 0; |
| 734 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 735 | else if (rule->action == TCP_ACT_TRK_SC1) { |
| 736 | if (!s->stkctr1_entry) { |
| 737 | /* only the first valid track-sc1 directive applies. |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 738 | * Also, note that right now we can only track SRC so we |
| 739 | * don't check how to get the key, but later we may need |
| 740 | * to consider rule->act_prm->trk_ctr.type. |
| 741 | */ |
| 742 | t = rule->act_prm.trk_ctr.table.t; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 743 | ts = stktable_get_entry(t, tcp_src_to_stktable_key(s)); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 744 | if (ts) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 745 | session_track_stkctr1(s, t, ts); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 746 | if (s->fe != s->be) |
| 747 | s->flags |= SN_BE_TRACK_SC1; |
| 748 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 749 | } |
| 750 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 751 | else if (rule->action == TCP_ACT_TRK_SC2) { |
| 752 | if (!s->stkctr2_entry) { |
| 753 | /* only the first valid track-sc2 directive applies. |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 754 | * Also, note that right now we can only track SRC so we |
| 755 | * don't check how to get the key, but later we may need |
| 756 | * to consider rule->act_prm->trk_ctr.type. |
| 757 | */ |
| 758 | t = rule->act_prm.trk_ctr.table.t; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 759 | ts = stktable_get_entry(t, tcp_src_to_stktable_key(s)); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 760 | if (ts) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 761 | session_track_stkctr2(s, t, ts); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 762 | if (s->fe != s->be) |
| 763 | s->flags |= SN_BE_TRACK_SC2; |
| 764 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | else { |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 768 | /* otherwise accept */ |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 769 | break; |
| 770 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
| 774 | /* if we get there, it means we have no rule which matches, or |
| 775 | * we have an explicit accept, so we apply the default accept. |
| 776 | */ |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 777 | req->analysers &= ~an_bit; |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 778 | req->analyse_exp = TICK_ETERNITY; |
| 779 | return 1; |
| 780 | } |
| 781 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 782 | /* This function performs the TCP response analysis on the current response. It |
| 783 | * returns 1 if the processing can continue on next analysers, or zero if it |
| 784 | * needs more data, encounters an error, or wants to immediately abort the |
| 785 | * response. It relies on buffers flags, and updates s->rep->analysers. The |
| 786 | * function may be called for backend rules. |
| 787 | */ |
| 788 | int tcp_inspect_response(struct session *s, struct buffer *rep, int an_bit) |
| 789 | { |
| 790 | struct tcp_rule *rule; |
| 791 | int partial; |
| 792 | |
| 793 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 794 | now_ms, __FUNCTION__, |
| 795 | s, |
| 796 | rep, |
| 797 | rep->rex, rep->wex, |
| 798 | rep->flags, |
| 799 | rep->l, |
| 800 | rep->analysers); |
| 801 | |
| 802 | /* We don't know whether we have enough data, so must proceed |
| 803 | * this way : |
| 804 | * - iterate through all rules in their declaration order |
| 805 | * - if one rule returns MISS, it means the inspect delay is |
| 806 | * not over yet, then return immediately, otherwise consider |
| 807 | * it as a non-match. |
| 808 | * - if one rule returns OK, then return OK |
| 809 | * - if one rule returns KO, then return KO |
| 810 | */ |
| 811 | |
| 812 | if (rep->flags & BF_SHUTR || tick_is_expired(rep->analyse_exp, now_ms)) |
| 813 | partial = 0; |
| 814 | else |
| 815 | partial = ACL_PARTIAL; |
| 816 | |
| 817 | list_for_each_entry(rule, &s->be->tcp_rep.inspect_rules, list) { |
| 818 | int ret = ACL_PAT_PASS; |
| 819 | |
| 820 | if (rule->cond) { |
| 821 | ret = acl_exec_cond(rule->cond, s->be, s, &s->txn, ACL_DIR_RTR | partial); |
| 822 | if (ret == ACL_PAT_MISS) { |
| 823 | /* just set the analyser timeout once at the beginning of the response */ |
| 824 | if (!tick_isset(rep->analyse_exp) && s->be->tcp_rep.inspect_delay) |
| 825 | rep->analyse_exp = tick_add_ifset(now_ms, s->be->tcp_rep.inspect_delay); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | ret = acl_pass(ret); |
| 830 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 831 | ret = !ret; |
| 832 | } |
| 833 | |
| 834 | if (ret) { |
| 835 | /* we have a matching rule. */ |
| 836 | if (rule->action == TCP_ACT_REJECT) { |
| 837 | buffer_abort(rep); |
| 838 | buffer_abort(s->req); |
| 839 | rep->analysers = 0; |
| 840 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 841 | s->be->be_counters.denied_resp++; |
| 842 | s->fe->fe_counters.denied_resp++; |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 843 | if (s->listener->counters) |
| 844 | s->listener->counters->denied_resp++; |
| 845 | |
| 846 | if (!(s->flags & SN_ERR_MASK)) |
| 847 | s->flags |= SN_ERR_PRXCOND; |
| 848 | if (!(s->flags & SN_FINST_MASK)) |
| 849 | s->flags |= SN_FINST_D; |
| 850 | return 0; |
| 851 | } |
| 852 | else { |
| 853 | /* otherwise accept */ |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /* if we get there, it means we have no rule which matches, or |
| 860 | * we have an explicit accept, so we apply the default accept. |
| 861 | */ |
| 862 | rep->analysers &= ~an_bit; |
| 863 | rep->analyse_exp = TICK_ETERNITY; |
| 864 | return 1; |
| 865 | } |
| 866 | |
| 867 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 868 | /* This function performs the TCP layer4 analysis on the current request. It |
| 869 | * returns 0 if a reject rule matches, otherwise 1 if either an accept rule |
| 870 | * matches or if no more rule matches. It can only use rules which don't need |
| 871 | * any data. |
| 872 | */ |
| 873 | int tcp_exec_req_rules(struct session *s) |
| 874 | { |
| 875 | struct tcp_rule *rule; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 876 | struct stksess *ts; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 877 | struct stktable *t = NULL; |
| 878 | int result = 1; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 879 | int ret; |
| 880 | |
| 881 | list_for_each_entry(rule, &s->fe->tcp_req.l4_rules, list) { |
| 882 | ret = ACL_PAT_PASS; |
| 883 | |
| 884 | if (rule->cond) { |
| 885 | ret = acl_exec_cond(rule->cond, s->fe, s, NULL, ACL_DIR_REQ); |
| 886 | ret = acl_pass(ret); |
| 887 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 888 | ret = !ret; |
| 889 | } |
| 890 | |
| 891 | if (ret) { |
| 892 | /* we have a matching rule. */ |
| 893 | if (rule->action == TCP_ACT_REJECT) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 894 | s->fe->fe_counters.denied_conn++; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 895 | if (s->listener->counters) |
Willy Tarreau | 2799e98 | 2010-06-05 15:43:21 +0200 | [diff] [blame] | 896 | s->listener->counters->denied_conn++; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 897 | |
| 898 | if (!(s->flags & SN_ERR_MASK)) |
| 899 | s->flags |= SN_ERR_PRXCOND; |
| 900 | if (!(s->flags & SN_FINST_MASK)) |
| 901 | s->flags |= SN_FINST_R; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 902 | result = 0; |
| 903 | break; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 904 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 905 | else if (rule->action == TCP_ACT_TRK_SC1) { |
| 906 | if (!s->stkctr1_entry) { |
| 907 | /* only the first valid track-sc1 directive applies. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 908 | * Also, note that right now we can only track SRC so we |
| 909 | * don't check how to get the key, but later we may need |
| 910 | * to consider rule->act_prm->trk_ctr.type. |
| 911 | */ |
| 912 | t = rule->act_prm.trk_ctr.table.t; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 913 | ts = stktable_get_entry(t, tcp_src_to_stktable_key(s)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 914 | if (ts) |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 915 | session_track_stkctr1(s, t, ts); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 916 | } |
| 917 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 918 | else if (rule->action == TCP_ACT_TRK_SC2) { |
| 919 | if (!s->stkctr2_entry) { |
| 920 | /* only the first valid track-sc2 directive applies. |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 921 | * Also, note that right now we can only track SRC so we |
| 922 | * don't check how to get the key, but later we may need |
| 923 | * to consider rule->act_prm->trk_ctr.type. |
| 924 | */ |
| 925 | t = rule->act_prm.trk_ctr.table.t; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 926 | ts = stktable_get_entry(t, tcp_src_to_stktable_key(s)); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 927 | if (ts) |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 928 | session_track_stkctr2(s, t, ts); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 929 | } |
| 930 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 931 | else { |
| 932 | /* otherwise it's an accept */ |
| 933 | break; |
| 934 | } |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 935 | } |
| 936 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 937 | return result; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 938 | } |
| 939 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 940 | /* Parse a tcp-response rule. Return a negative value in case of failure */ |
| 941 | static int tcp_parse_response_rule(char **args, int arg, int section_type, |
| 942 | struct proxy *curpx, struct proxy *defpx, |
| 943 | struct tcp_rule *rule, char *err, int errlen) |
| 944 | { |
| 945 | if (curpx == defpx || !(curpx->cap & PR_CAP_BE)) { |
| 946 | snprintf(err, errlen, "%s %s is only allowed in 'backend' sections", |
| 947 | args[0], args[1]); |
| 948 | return -1; |
| 949 | } |
| 950 | |
| 951 | if (strcmp(args[arg], "accept") == 0) { |
| 952 | arg++; |
| 953 | rule->action = TCP_ACT_ACCEPT; |
| 954 | } |
| 955 | else if (strcmp(args[arg], "reject") == 0) { |
| 956 | arg++; |
| 957 | rule->action = TCP_ACT_REJECT; |
| 958 | } |
| 959 | else { |
| 960 | snprintf(err, errlen, |
| 961 | "'%s %s' expects 'accept' or 'reject' in %s '%s' (was '%s')", |
| 962 | args[0], args[1], proxy_type_str(curpx), curpx->id, args[arg]); |
| 963 | return -1; |
| 964 | } |
| 965 | |
| 966 | if (strcmp(args[arg], "if") == 0 || strcmp(args[arg], "unless") == 0) { |
| 967 | if ((rule->cond = build_acl_cond(NULL, 0, curpx, (const char **)args+arg)) == NULL) { |
| 968 | snprintf(err, errlen, |
| 969 | "error detected in %s '%s' while parsing '%s' condition", |
| 970 | proxy_type_str(curpx), curpx->id, args[arg]); |
| 971 | return -1; |
| 972 | } |
| 973 | } |
| 974 | else if (*args[arg]) { |
| 975 | snprintf(err, errlen, |
| 976 | "'%s %s %s' only accepts 'if' or 'unless', in %s '%s' (was '%s')", |
| 977 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg]); |
| 978 | return -1; |
| 979 | } |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | |
| 984 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 985 | /* Parse a tcp-request rule. Return a negative value in case of failure */ |
| 986 | static int tcp_parse_request_rule(char **args, int arg, int section_type, |
| 987 | struct proxy *curpx, struct proxy *defpx, |
| 988 | struct tcp_rule *rule, char *err, int errlen) |
| 989 | { |
| 990 | if (curpx == defpx) { |
| 991 | snprintf(err, errlen, "%s %s is not allowed in 'defaults' sections", |
| 992 | args[0], args[1]); |
| 993 | return -1; |
| 994 | } |
| 995 | |
| 996 | if (!strcmp(args[arg], "accept")) { |
| 997 | arg++; |
| 998 | rule->action = TCP_ACT_ACCEPT; |
| 999 | } |
| 1000 | else if (!strcmp(args[arg], "reject")) { |
| 1001 | arg++; |
| 1002 | rule->action = TCP_ACT_REJECT; |
| 1003 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 1004 | else if (strcmp(args[arg], "track-sc1") == 0) { |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1005 | int ret; |
| 1006 | |
| 1007 | arg++; |
| 1008 | ret = parse_track_counters(args, &arg, section_type, curpx, |
| 1009 | &rule->act_prm.trk_ctr, defpx, err, errlen); |
| 1010 | |
| 1011 | if (ret < 0) /* nb: warnings are not handled yet */ |
| 1012 | return -1; |
| 1013 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 1014 | rule->action = TCP_ACT_TRK_SC1; |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1015 | } |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 1016 | else if (strcmp(args[arg], "track-sc2") == 0) { |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1017 | int ret; |
| 1018 | |
| 1019 | arg++; |
| 1020 | ret = parse_track_counters(args, &arg, section_type, curpx, |
| 1021 | &rule->act_prm.trk_ctr, defpx, err, errlen); |
| 1022 | |
| 1023 | if (ret < 0) /* nb: warnings are not handled yet */ |
| 1024 | return -1; |
| 1025 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 1026 | rule->action = TCP_ACT_TRK_SC2; |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1027 | } |
| 1028 | else { |
| 1029 | snprintf(err, errlen, |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 1030 | "'%s %s' expects 'accept', 'reject', 'track-sc1' " |
| 1031 | "or 'track-sc2' in %s '%s' (was '%s')", |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1032 | args[0], args[1], proxy_type_str(curpx), curpx->id, args[arg]); |
| 1033 | return -1; |
| 1034 | } |
| 1035 | |
| 1036 | if (strcmp(args[arg], "if") == 0 || strcmp(args[arg], "unless") == 0) { |
| 1037 | if ((rule->cond = build_acl_cond(NULL, 0, curpx, (const char **)args+arg)) == NULL) { |
| 1038 | snprintf(err, errlen, |
| 1039 | "error detected in %s '%s' while parsing '%s' condition", |
| 1040 | proxy_type_str(curpx), curpx->id, args[arg]); |
| 1041 | return -1; |
| 1042 | } |
| 1043 | } |
| 1044 | else if (*args[arg]) { |
| 1045 | snprintf(err, errlen, |
| 1046 | "'%s %s %s' only accepts 'if' or 'unless', in %s '%s' (was '%s')", |
| 1047 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg]); |
| 1048 | return -1; |
| 1049 | } |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1053 | /* This function should be called to parse a line starting with the "tcp-response" |
| 1054 | * keyword. |
| 1055 | */ |
| 1056 | static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx, |
| 1057 | struct proxy *defpx, char *err, int errlen) |
| 1058 | { |
| 1059 | const char *ptr = NULL; |
| 1060 | unsigned int val; |
| 1061 | int retlen; |
| 1062 | int warn = 0; |
| 1063 | int arg; |
| 1064 | struct tcp_rule *rule; |
| 1065 | |
| 1066 | if (!*args[1]) { |
| 1067 | snprintf(err, errlen, "missing argument for '%s' in %s '%s'", |
| 1068 | args[0], proxy_type_str(curpx), curpx->id); |
| 1069 | return -1; |
| 1070 | } |
| 1071 | |
| 1072 | if (strcmp(args[1], "inspect-delay") == 0) { |
| 1073 | if (curpx == defpx || !(curpx->cap & PR_CAP_BE)) { |
| 1074 | snprintf(err, errlen, "%s %s is only allowed in 'backend' sections", |
| 1075 | args[0], args[1]); |
| 1076 | return -1; |
| 1077 | } |
| 1078 | |
| 1079 | if (!*args[2] || (ptr = parse_time_err(args[2], &val, TIME_UNIT_MS))) { |
| 1080 | retlen = snprintf(err, errlen, |
| 1081 | "'%s %s' expects a positive delay in milliseconds, in %s '%s'", |
| 1082 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1083 | if (ptr && retlen < errlen) |
| 1084 | retlen += snprintf(err + retlen, errlen - retlen, |
| 1085 | " (unexpected character '%c')", *ptr); |
| 1086 | return -1; |
| 1087 | } |
| 1088 | |
| 1089 | if (curpx->tcp_rep.inspect_delay) { |
| 1090 | snprintf(err, errlen, "ignoring %s %s (was already defined) in %s '%s'", |
| 1091 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1092 | return 1; |
| 1093 | } |
| 1094 | curpx->tcp_rep.inspect_delay = val; |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 1098 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1099 | LIST_INIT(&rule->list); |
| 1100 | arg = 1; |
| 1101 | |
| 1102 | if (strcmp(args[1], "content") == 0) { |
| 1103 | arg++; |
| 1104 | if (tcp_parse_response_rule(args, arg, section_type, curpx, defpx, rule, err, errlen) < 0) |
| 1105 | goto error; |
| 1106 | |
| 1107 | if (rule->cond && (rule->cond->requires & ACL_USE_L6REQ_VOLATILE)) { |
| 1108 | struct acl *acl; |
| 1109 | const char *name; |
| 1110 | |
| 1111 | acl = cond_find_require(rule->cond, ACL_USE_L6REQ_VOLATILE); |
| 1112 | name = acl ? acl->name : "(unknown)"; |
| 1113 | |
| 1114 | retlen = snprintf(err, errlen, |
| 1115 | "acl '%s' involves some request-only criteria which will be ignored.", |
| 1116 | name); |
| 1117 | warn++; |
| 1118 | } |
| 1119 | |
| 1120 | LIST_ADDQ(&curpx->tcp_rep.inspect_rules, &rule->list); |
| 1121 | } |
| 1122 | else { |
| 1123 | retlen = snprintf(err, errlen, |
| 1124 | "'%s' expects 'inspect-delay' or 'content' in %s '%s' (was '%s')", |
| 1125 | args[0], proxy_type_str(curpx), curpx->id, args[1]); |
| 1126 | goto error; |
| 1127 | } |
| 1128 | |
| 1129 | return warn; |
| 1130 | error: |
| 1131 | free(rule); |
| 1132 | return -1; |
| 1133 | } |
| 1134 | |
| 1135 | |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1136 | /* This function should be called to parse a line starting with the "tcp-request" |
| 1137 | * keyword. |
| 1138 | */ |
| 1139 | static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx, |
| 1140 | struct proxy *defpx, char *err, int errlen) |
| 1141 | { |
| 1142 | const char *ptr = NULL; |
Willy Tarreau | c7e961e | 2008-08-17 17:13:47 +0200 | [diff] [blame] | 1143 | unsigned int val; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1144 | int retlen; |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1145 | int warn = 0; |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1146 | int arg; |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1147 | struct tcp_rule *rule; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1148 | |
| 1149 | if (!*args[1]) { |
| 1150 | snprintf(err, errlen, "missing argument for '%s' in %s '%s'", |
Willy Tarreau | f535683 | 2010-06-14 18:40:26 +0200 | [diff] [blame] | 1151 | args[0], proxy_type_str(curpx), curpx->id); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1152 | return -1; |
| 1153 | } |
| 1154 | |
| 1155 | if (!strcmp(args[1], "inspect-delay")) { |
| 1156 | if (curpx == defpx) { |
| 1157 | snprintf(err, errlen, "%s %s is not allowed in 'defaults' sections", |
| 1158 | args[0], args[1]); |
| 1159 | return -1; |
| 1160 | } |
| 1161 | |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1162 | if (!*args[2] || (ptr = parse_time_err(args[2], &val, TIME_UNIT_MS))) { |
| 1163 | retlen = snprintf(err, errlen, |
| 1164 | "'%s %s' expects a positive delay in milliseconds, in %s '%s'", |
Willy Tarreau | f535683 | 2010-06-14 18:40:26 +0200 | [diff] [blame] | 1165 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1166 | if (ptr && retlen < errlen) |
| 1167 | retlen += snprintf(err+retlen, errlen - retlen, |
| 1168 | " (unexpected character '%c')", *ptr); |
| 1169 | return -1; |
| 1170 | } |
| 1171 | |
| 1172 | if (curpx->tcp_req.inspect_delay) { |
| 1173 | snprintf(err, errlen, "ignoring %s %s (was already defined) in %s '%s'", |
Willy Tarreau | f535683 | 2010-06-14 18:40:26 +0200 | [diff] [blame] | 1174 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1175 | return 1; |
| 1176 | } |
| 1177 | curpx->tcp_req.inspect_delay = val; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 1181 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | fb024dc | 2010-08-20 13:35:41 +0200 | [diff] [blame] | 1182 | LIST_INIT(&rule->list); |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1183 | arg = 1; |
| 1184 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1185 | if (strcmp(args[1], "content") == 0) { |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 1186 | arg++; |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1187 | if (tcp_parse_request_rule(args, arg, section_type, curpx, defpx, rule, err, errlen) < 0) |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1188 | goto error; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1189 | |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1190 | if (rule->cond && (rule->cond->requires & ACL_USE_RTR_ANY)) { |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1191 | struct acl *acl; |
| 1192 | const char *name; |
| 1193 | |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1194 | acl = cond_find_require(rule->cond, ACL_USE_RTR_ANY); |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1195 | name = acl ? acl->name : "(unknown)"; |
| 1196 | |
| 1197 | retlen = snprintf(err, errlen, |
Willy Tarreau | 1a21194 | 2009-07-14 13:53:17 +0200 | [diff] [blame] | 1198 | "acl '%s' involves some response-only criteria which will be ignored.", |
| 1199 | name); |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1200 | warn++; |
| 1201 | } |
Willy Tarreau | fb024dc | 2010-08-20 13:35:41 +0200 | [diff] [blame] | 1202 | LIST_ADDQ(&curpx->tcp_req.inspect_rules, &rule->list); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1203 | } |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1204 | else if (strcmp(args[1], "connection") == 0) { |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1205 | arg++; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1206 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1207 | if (!(curpx->cap & PR_CAP_FE)) { |
| 1208 | snprintf(err, errlen, "%s %s is not allowed because %s %s is not a frontend", |
| 1209 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
Simon Horman | 6c54d8b | 2011-07-15 13:14:06 +0900 | [diff] [blame] | 1210 | goto error; |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1211 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1212 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1213 | if (tcp_parse_request_rule(args, arg, section_type, curpx, defpx, rule, err, errlen) < 0) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1214 | goto error; |
| 1215 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1216 | if (rule->cond && (rule->cond->requires & (ACL_USE_RTR_ANY|ACL_USE_L6_ANY|ACL_USE_L7_ANY))) { |
| 1217 | struct acl *acl; |
| 1218 | const char *name; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 1219 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1220 | acl = cond_find_require(rule->cond, ACL_USE_RTR_ANY|ACL_USE_L6_ANY|ACL_USE_L7_ANY); |
| 1221 | name = acl ? acl->name : "(unknown)"; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 1222 | |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1223 | if (acl->requires & (ACL_USE_L6_ANY|ACL_USE_L7_ANY)) { |
| 1224 | retlen = snprintf(err, errlen, |
| 1225 | "'%s %s' may not reference acl '%s' which makes use of " |
| 1226 | "payload in %s '%s'. Please use '%s content' for this.", |
| 1227 | args[0], args[1], name, proxy_type_str(curpx), curpx->id, args[0]); |
| 1228 | goto error; |
| 1229 | } |
| 1230 | if (acl->requires & ACL_USE_RTR_ANY) |
| 1231 | retlen = snprintf(err, errlen, |
| 1232 | "acl '%s' involves some response-only criteria which will be ignored.", |
| 1233 | name); |
| 1234 | warn++; |
| 1235 | } |
Willy Tarreau | fb024dc | 2010-08-20 13:35:41 +0200 | [diff] [blame] | 1236 | LIST_ADDQ(&curpx->tcp_req.l4_rules, &rule->list); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 1237 | } |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1238 | else { |
| 1239 | retlen = snprintf(err, errlen, |
Willy Tarreau | 68c03ab | 2010-08-06 15:08:45 +0200 | [diff] [blame] | 1240 | "'%s' expects 'inspect-delay', 'connection', or 'content' in %s '%s' (was '%s')", |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1241 | args[0], proxy_type_str(curpx), curpx->id, args[1]); |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1242 | goto error; |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
Willy Tarreau | 1a68794 | 2010-05-23 22:40:30 +0200 | [diff] [blame] | 1245 | return warn; |
Willy Tarreau | 6a984fa | 2010-06-14 16:44:27 +0200 | [diff] [blame] | 1246 | error: |
| 1247 | free(rule); |
| 1248 | return -1; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1249 | } |
| 1250 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1251 | |
| 1252 | /************************************************************************/ |
| 1253 | /* All supported ACL keywords must be declared here. */ |
| 1254 | /************************************************************************/ |
| 1255 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1256 | /* copy the source IPv4/v6 address into temp_pattern */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1257 | static int |
| 1258 | acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1259 | struct acl_expr *expr, struct acl_test *test) |
| 1260 | { |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1261 | switch (l4->si[0].addr.from.ss_family) { |
| 1262 | case AF_INET: |
| 1263 | temp_pattern.data.ip = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr; |
| 1264 | temp_pattern.type = PATTERN_TYPE_IP; |
| 1265 | break; |
| 1266 | case AF_INET6: |
| 1267 | temp_pattern.data.ipv6 = ((struct sockaddr_in6 *)(&l4->si[0].addr.from))->sin6_addr; |
| 1268 | temp_pattern.type = PATTERN_TYPE_IPV6; |
| 1269 | break; |
| 1270 | default: |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1271 | return 0; |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1272 | } |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1273 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1274 | test->flags = 0; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1275 | return 1; |
| 1276 | } |
| 1277 | |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1278 | /* extract the connection's source ipv4 address */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1279 | static int |
| 1280 | pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1281 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1282 | { |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1283 | if (l4->si[0].addr.from.ss_family != AF_INET ) |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1284 | return 0; |
| 1285 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1286 | data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr.s_addr; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1287 | return 1; |
| 1288 | } |
| 1289 | |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1290 | /* extract the connection's source ipv6 address */ |
| 1291 | static int |
| 1292 | pattern_fetch_src6(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1293 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
| 1294 | { |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1295 | if (l4->si[0].addr.from.ss_family != AF_INET6) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1296 | return 0; |
| 1297 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1298 | memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.from)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1299 | return 1; |
| 1300 | } |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1301 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1302 | /* set temp integer to the connection's source port */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1303 | static int |
| 1304 | acl_fetch_sport(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1305 | struct acl_expr *expr, struct acl_test *test) |
| 1306 | { |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1307 | if (!(temp_pattern.data.integer = get_host_port(&l4->si[0].addr.from))) |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1308 | return 0; |
| 1309 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1310 | test->flags = 0; |
| 1311 | return 1; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | /* set test->ptr to point to the frontend's IPv4/IPv6 address and test->i to the family */ |
| 1316 | static int |
| 1317 | acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1318 | struct acl_expr *expr, struct acl_test *test) |
| 1319 | { |
| 1320 | if (!(l4->flags & SN_FRT_ADDR_SET)) |
| 1321 | get_frt_addr(l4); |
| 1322 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1323 | switch (l4->si[0].addr.to.ss_family) { |
| 1324 | case AF_INET: |
| 1325 | temp_pattern.data.ip = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr; |
| 1326 | temp_pattern.type = PATTERN_TYPE_IP; |
| 1327 | break; |
| 1328 | case AF_INET6: |
| 1329 | temp_pattern.data.ipv6 = ((struct sockaddr_in6 *)(&l4->si[0].addr.to))->sin6_addr; |
| 1330 | temp_pattern.type = PATTERN_TYPE_IPV6; |
| 1331 | break; |
| 1332 | default: |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1333 | return 0; |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1334 | } |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1335 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 1336 | test->flags = 0; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1337 | return 1; |
| 1338 | } |
| 1339 | |
| 1340 | |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1341 | /* extract the connection's destination ipv4 address */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1342 | static int |
| 1343 | pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1344 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1345 | { |
emeric | 8aa6b37 | 2010-10-22 17:06:26 +0200 | [diff] [blame] | 1346 | if (!(l4->flags & SN_FRT_ADDR_SET)) |
| 1347 | get_frt_addr(l4); |
| 1348 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1349 | if (l4->si[0].addr.to.ss_family != AF_INET) |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1350 | return 0; |
| 1351 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1352 | data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr.s_addr; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1353 | return 1; |
| 1354 | } |
| 1355 | |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1356 | /* extract the connection's destination ipv6 address */ |
| 1357 | static int |
| 1358 | pattern_fetch_dst6(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1359 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
| 1360 | { |
| 1361 | if (!(l4->flags & SN_FRT_ADDR_SET)) |
| 1362 | get_frt_addr(l4); |
| 1363 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1364 | if (l4->si[0].addr.to.ss_family != AF_INET6) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1365 | return 0; |
| 1366 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1367 | memcpy(data->ipv6.s6_addr, ((struct sockaddr_in6 *)&l4->si[0].addr.to)->sin6_addr.s6_addr, sizeof(data->ipv6.s6_addr)); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
| 1370 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1371 | /* set temp integer to the frontend connexion's destination port */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1372 | static int |
| 1373 | acl_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1374 | struct acl_expr *expr, struct acl_test *test) |
| 1375 | { |
| 1376 | if (!(l4->flags & SN_FRT_ADDR_SET)) |
| 1377 | get_frt_addr(l4); |
| 1378 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1379 | if (!(temp_pattern.data.integer = get_host_port(&l4->si[0].addr.to))) |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1380 | return 0; |
| 1381 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1382 | test->flags = 0; |
| 1383 | return 1; |
| 1384 | } |
| 1385 | |
| 1386 | static int |
| 1387 | pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1388 | const struct pattern_arg *arg, int i, union pattern_data *data) |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1389 | { |
emeric | 8aa6b37 | 2010-10-22 17:06:26 +0200 | [diff] [blame] | 1390 | if (!(l4->flags & SN_FRT_ADDR_SET)) |
| 1391 | get_frt_addr(l4); |
| 1392 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 1393 | if (!(data->integer = get_host_port(&l4->si[0].addr.to))) |
Emeric Brun | f769f51 | 2010-10-22 17:14:01 +0200 | [diff] [blame] | 1394 | return 0; |
| 1395 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
| 1398 | |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1399 | static int |
| 1400 | pattern_arg_fetch_payloadlv(const char *arg, struct pattern_arg **arg_p, int *arg_i) |
| 1401 | { |
| 1402 | int member = 0; |
| 1403 | int len_offset = 0; |
| 1404 | int len_size = 0; |
| 1405 | int buf_offset = 0; |
| 1406 | int relative = 0; |
| 1407 | int arg_len = strlen(arg); |
| 1408 | int i; |
| 1409 | |
| 1410 | for (i = 0; i < arg_len; i++) { |
| 1411 | if (arg[i] == ',') { |
| 1412 | member++; |
| 1413 | } else if (member == 0) { |
| 1414 | if (arg[i] < '0' || arg[i] > '9') |
| 1415 | return 0; |
| 1416 | |
| 1417 | len_offset = 10 * len_offset + arg[i] - '0'; |
| 1418 | } else if (member == 1) { |
| 1419 | if (arg[i] < '0' || arg[i] > '9') |
| 1420 | return 0; |
| 1421 | |
| 1422 | len_size = 10 * len_size + arg[i] - '0'; |
| 1423 | } else if (member == 2) { |
| 1424 | if (!relative && !buf_offset && arg[i] == '+') { |
| 1425 | relative = 1; |
| 1426 | continue; |
| 1427 | } else if (!relative && !buf_offset && arg[i] == '-') { |
| 1428 | relative = 2; |
| 1429 | continue; |
| 1430 | } else if (arg[i] < '0' || arg[i] > '9') |
| 1431 | return 0; |
| 1432 | |
| 1433 | buf_offset = 10 * buf_offset + arg[i] - '0'; |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | if (member < 1) |
| 1438 | return 0; |
| 1439 | |
| 1440 | if (!len_size) |
| 1441 | return 0; |
| 1442 | |
| 1443 | if (member == 1) { |
| 1444 | buf_offset = len_offset + len_size; |
| 1445 | } |
| 1446 | else if (relative == 1) { |
| 1447 | buf_offset = len_offset + len_size + buf_offset; |
| 1448 | } |
| 1449 | else if (relative == 2) { |
| 1450 | if (len_offset + len_size < buf_offset) |
| 1451 | return 0; |
| 1452 | |
| 1453 | buf_offset = len_offset + len_size - buf_offset; |
| 1454 | } |
| 1455 | |
| 1456 | *arg_i = 3; |
| 1457 | *arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg)); |
| 1458 | (*arg_p)[0].type = PATTERN_ARG_TYPE_INTEGER; |
| 1459 | (*arg_p)[0].data.integer = len_offset; |
| 1460 | (*arg_p)[1].type = PATTERN_ARG_TYPE_INTEGER; |
| 1461 | (*arg_p)[1].data.integer = len_size; |
| 1462 | (*arg_p)[2].type = PATTERN_ARG_TYPE_INTEGER; |
| 1463 | (*arg_p)[2].data.integer = buf_offset; |
| 1464 | |
| 1465 | return 1; |
| 1466 | } |
| 1467 | |
| 1468 | static int |
| 1469 | pattern_fetch_payloadlv(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1470 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
| 1471 | { |
| 1472 | int len_offset = arg_p[0].data.integer; |
| 1473 | int len_size = arg_p[1].data.integer; |
| 1474 | int buf_offset = arg_p[2].data.integer; |
| 1475 | int buf_size = 0; |
| 1476 | struct buffer *b; |
| 1477 | int i; |
| 1478 | |
| 1479 | /* Format is (len offset, len size, buf offset) or (len offset, len size) */ |
| 1480 | /* by default buf offset == len offset + len size */ |
| 1481 | /* buf offset could be absolute or relative to len offset + len size if prefixed by + or - */ |
| 1482 | |
| 1483 | if (!l4) |
| 1484 | return 0; |
| 1485 | |
| 1486 | b = (dir & PATTERN_FETCH_RTR) ? l4->rep : l4->req; |
| 1487 | |
| 1488 | if (!b || !b->l) |
| 1489 | return 0; |
| 1490 | |
| 1491 | if (len_offset + len_size > b->l) |
| 1492 | return 0; |
| 1493 | |
| 1494 | for (i = 0; i < len_size; i++) { |
| 1495 | buf_size = (buf_size << 8) + ((unsigned char *)b->w)[i + len_offset]; |
| 1496 | } |
| 1497 | |
| 1498 | if (!buf_size) |
| 1499 | return 0; |
| 1500 | |
| 1501 | if (buf_offset + buf_size > b->l) |
| 1502 | return 0; |
| 1503 | |
| 1504 | /* init chunk as read only */ |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 1505 | chunk_initlen(&data->str, b->w + buf_offset, 0, buf_size); |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1506 | |
| 1507 | return 1; |
| 1508 | } |
| 1509 | |
| 1510 | static int |
| 1511 | pattern_arg_fetch_payload (const char *arg, struct pattern_arg **arg_p, int *arg_i) |
| 1512 | { |
| 1513 | int member = 0; |
| 1514 | int buf_offset = 0; |
| 1515 | int buf_size = 0; |
| 1516 | int arg_len = strlen(arg); |
| 1517 | int i; |
| 1518 | |
| 1519 | for (i = 0 ; i < arg_len ; i++) { |
| 1520 | if (arg[i] == ',') { |
| 1521 | member++; |
| 1522 | } else if (member == 0) { |
| 1523 | if (arg[i] < '0' || arg[i] > '9') |
| 1524 | return 0; |
| 1525 | |
| 1526 | buf_offset = 10 * buf_offset + arg[i] - '0'; |
| 1527 | } else if (member == 1) { |
| 1528 | if (arg[i] < '0' || arg[i] > '9') |
| 1529 | return 0; |
| 1530 | |
| 1531 | buf_size = 10 * buf_size + arg[i] - '0'; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | if (!buf_size) |
| 1536 | return 0; |
| 1537 | |
| 1538 | *arg_i = 2; |
| 1539 | *arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg)); |
| 1540 | (*arg_p)[0].type = PATTERN_ARG_TYPE_INTEGER; |
| 1541 | (*arg_p)[0].data.integer = buf_offset; |
| 1542 | (*arg_p)[1].type = PATTERN_ARG_TYPE_INTEGER; |
| 1543 | (*arg_p)[1].data.integer = buf_size; |
| 1544 | |
| 1545 | return 1; |
| 1546 | } |
| 1547 | |
| 1548 | static int |
| 1549 | pattern_fetch_payload(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1550 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
| 1551 | { |
| 1552 | int buf_offset = arg_p[0].data.integer; |
| 1553 | int buf_size = arg_p[1].data.integer; |
| 1554 | struct buffer *b; |
| 1555 | |
| 1556 | if (!l4) |
| 1557 | return 0; |
| 1558 | |
| 1559 | b = (dir & PATTERN_FETCH_RTR) ? l4->rep : l4->req; |
| 1560 | |
| 1561 | if (!b || !b->l) |
| 1562 | return 0; |
| 1563 | |
| 1564 | if (buf_offset + buf_size > b->l) |
| 1565 | return 0; |
| 1566 | |
| 1567 | /* init chunk as read only */ |
Simon Horman | de072bd | 2011-06-24 15:11:37 +0900 | [diff] [blame] | 1568 | chunk_initlen(&data->str, b->w + buf_offset, 0, buf_size); |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1569 | |
| 1570 | return 1; |
| 1571 | } |
| 1572 | |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 1573 | static int |
| 1574 | pattern_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, int dir, |
| 1575 | const struct pattern_arg *arg_p, int arg_i, union pattern_data *data) |
| 1576 | { |
| 1577 | int ret; |
| 1578 | struct acl_expr expr; |
| 1579 | struct acl_test test; |
| 1580 | |
| 1581 | if (!l4) |
| 1582 | return 0; |
| 1583 | |
| 1584 | memset(&expr, 0, sizeof(expr)); |
| 1585 | memset(&test, 0, sizeof(test)); |
| 1586 | |
| 1587 | expr.arg.str = arg_p[0].data.str.str; |
| 1588 | expr.arg_len = arg_p[0].data.str.len; |
| 1589 | |
| 1590 | ret = acl_fetch_rdp_cookie(px, l4, NULL, ACL_DIR_REQ, &expr, &test); |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 1591 | if (ret == 0 || (test.flags & ACL_TEST_F_MAY_CHANGE) || temp_pattern.data.str.len == 0) |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 1592 | return 0; |
| 1593 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 1594 | data->str = temp_pattern.data.str; |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 1595 | return 1; |
| 1596 | } |
| 1597 | |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1598 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 1599 | { CFG_LISTEN, "tcp-request", tcp_parse_tcp_req }, |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1600 | { CFG_LISTEN, "tcp-response", tcp_parse_tcp_rep }, |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1601 | { 0, NULL, NULL }, |
| 1602 | }}; |
| 1603 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1604 | /* Note: must not be declared <const> as its list will be overwritten */ |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1605 | static struct acl_kw_list acl_kws = {{ },{ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1606 | { "src_port", acl_parse_int, acl_fetch_sport, acl_match_int, ACL_USE_TCP_PERMANENT }, |
| 1607 | { "src", acl_parse_ip, acl_fetch_src, acl_match_ip, ACL_USE_TCP4_PERMANENT|ACL_MAY_LOOKUP }, |
| 1608 | { "dst", acl_parse_ip, acl_fetch_dst, acl_match_ip, ACL_USE_TCP4_PERMANENT|ACL_MAY_LOOKUP }, |
| 1609 | { "dst_port", acl_parse_int, acl_fetch_dport, acl_match_int, ACL_USE_TCP_PERMANENT }, |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1610 | { NULL, NULL, NULL, NULL }, |
| 1611 | }}; |
| 1612 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1613 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 1614 | static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{ |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1615 | { "src", pattern_fetch_src, NULL, PATTERN_TYPE_IP, PATTERN_FETCH_REQ }, |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1616 | { "src6", pattern_fetch_src6, NULL, PATTERN_TYPE_IPV6, PATTERN_FETCH_REQ }, |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1617 | { "dst", pattern_fetch_dst, NULL, PATTERN_TYPE_IP, PATTERN_FETCH_REQ }, |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 1618 | { "dst6", pattern_fetch_dst6, NULL, PATTERN_TYPE_IPV6, PATTERN_FETCH_REQ }, |
Emeric | f2d7cae | 2010-11-05 18:13:50 +0100 | [diff] [blame] | 1619 | { "dst_port", pattern_fetch_dport, NULL, PATTERN_TYPE_INTEGER, PATTERN_FETCH_REQ }, |
| 1620 | { "payload", pattern_fetch_payload, pattern_arg_fetch_payload, PATTERN_TYPE_CONSTDATA, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, |
| 1621 | { "payload_lv", pattern_fetch_payloadlv, pattern_arg_fetch_payloadlv, PATTERN_TYPE_CONSTDATA, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, |
Simon Horman | ab814e0 | 2011-06-24 14:50:20 +0900 | [diff] [blame] | 1622 | { "rdp_cookie", pattern_fetch_rdp_cookie, pattern_arg_str, PATTERN_TYPE_CONSTSTRING, PATTERN_FETCH_REQ }, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1623 | { NULL, NULL, NULL, 0, 0 }, |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1624 | }}; |
| 1625 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 1626 | __attribute__((constructor)) |
| 1627 | static void __tcp_protocol_init(void) |
| 1628 | { |
| 1629 | protocol_register(&proto_tcpv4); |
| 1630 | protocol_register(&proto_tcpv6); |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 1631 | pattern_register_fetches(&pattern_fetch_keywords); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1632 | cfg_register_keywords(&cfg_kws); |
| 1633 | acl_register_keywords(&acl_kws); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | |
| 1637 | /* |
| 1638 | * Local variables: |
| 1639 | * c-indent-level: 8 |
| 1640 | * c-basic-offset: 8 |
| 1641 | * End: |
| 1642 | */ |