Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 2 | * Listener management functions. |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 4 | * Copyright 2000-2013 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [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 | |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 13 | #include <errno.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
Willy Tarreau | 1bc4aab | 2012-10-08 20:11:03 +0200 | [diff] [blame] | 17 | #include <common/accept4.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 18 | #include <common/config.h> |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 19 | #include <common/errors.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 20 | #include <common/mini-clist.h> |
| 21 | #include <common/standard.h> |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 22 | #include <common/time.h> |
| 23 | |
| 24 | #include <types/global.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 25 | #include <types/protocol.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 26 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 27 | #include <proto/acl.h> |
Willy Tarreau | b648d63 | 2007-10-28 22:13:50 +0100 | [diff] [blame] | 28 | #include <proto/fd.h> |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 29 | #include <proto/freq_ctr.h> |
| 30 | #include <proto/log.h> |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 31 | #include <proto/sample.h> |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 32 | #include <proto/task.h> |
Willy Tarreau | b648d63 | 2007-10-28 22:13:50 +0100 | [diff] [blame] | 33 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 34 | /* List head of all known bind keywords */ |
| 35 | static struct bind_kw_list bind_keywords = { |
| 36 | .list = LIST_HEAD_INIT(bind_keywords.list) |
| 37 | }; |
| 38 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 39 | /* This function adds the specified listener's file descriptor to the polling |
| 40 | * lists if it is in the LI_LISTEN state. The listener enters LI_READY or |
| 41 | * LI_FULL state depending on its number of connections. |
| 42 | */ |
| 43 | void enable_listener(struct listener *listener) |
| 44 | { |
| 45 | if (listener->state == LI_LISTEN) { |
| 46 | if (listener->nbconn < listener->maxconn) { |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 47 | fd_want_recv(listener->fd); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 48 | listener->state = LI_READY; |
| 49 | } else { |
| 50 | listener->state = LI_FULL; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /* This function removes the specified listener's file descriptor from the |
| 56 | * polling lists if it is in the LI_READY or in the LI_FULL state. The listener |
| 57 | * enters LI_LISTEN. |
| 58 | */ |
| 59 | void disable_listener(struct listener *listener) |
| 60 | { |
| 61 | if (listener->state < LI_READY) |
| 62 | return; |
| 63 | if (listener->state == LI_READY) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 64 | fd_stop_recv(listener->fd); |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 65 | if (listener->state == LI_LIMITED) |
| 66 | LIST_DEL(&listener->wait_queue); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 67 | listener->state = LI_LISTEN; |
| 68 | } |
| 69 | |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 70 | /* This function tries to temporarily disable a listener, depending on the OS |
| 71 | * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores |
| 72 | * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but |
| 73 | * closes upon SHUT_WR and refuses to rebind. So a common validation path |
| 74 | * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling |
| 75 | * is disabled. It normally returns non-zero, unless an error is reported. |
| 76 | */ |
| 77 | int pause_listener(struct listener *l) |
| 78 | { |
| 79 | if (l->state <= LI_PAUSED) |
| 80 | return 1; |
| 81 | |
Willy Tarreau | b3fb60b | 2012-10-04 08:56:31 +0200 | [diff] [blame] | 82 | if (l->proto->sock_prot == IPPROTO_TCP) { |
| 83 | if (shutdown(l->fd, SHUT_WR) != 0) |
| 84 | return 0; /* Solaris dies here */ |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 85 | |
Willy Tarreau | b3fb60b | 2012-10-04 08:56:31 +0200 | [diff] [blame] | 86 | if (listen(l->fd, l->backlog ? l->backlog : l->maxconn) != 0) |
| 87 | return 0; /* OpenBSD dies here */ |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 88 | |
Willy Tarreau | b3fb60b | 2012-10-04 08:56:31 +0200 | [diff] [blame] | 89 | if (shutdown(l->fd, SHUT_RD) != 0) |
| 90 | return 0; /* should always be OK */ |
| 91 | } |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 92 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 93 | if (l->state == LI_LIMITED) |
| 94 | LIST_DEL(&l->wait_queue); |
| 95 | |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 96 | fd_stop_recv(l->fd); |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 97 | l->state = LI_PAUSED; |
| 98 | return 1; |
| 99 | } |
| 100 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 101 | /* This function tries to resume a temporarily disabled listener. Paused, full, |
| 102 | * limited and disabled listeners are handled, which means that this function |
| 103 | * may replace enable_listener(). The resulting state will either be LI_READY |
| 104 | * or LI_FULL. 0 is returned in case of failure to resume (eg: dead socket). |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 105 | */ |
| 106 | int resume_listener(struct listener *l) |
| 107 | { |
| 108 | if (l->state < LI_PAUSED) |
| 109 | return 0; |
| 110 | |
Willy Tarreau | b3fb60b | 2012-10-04 08:56:31 +0200 | [diff] [blame] | 111 | if (l->proto->sock_prot == IPPROTO_TCP && |
| 112 | l->state == LI_PAUSED && |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 113 | listen(l->fd, l->backlog ? l->backlog : l->maxconn) != 0) |
| 114 | return 0; |
| 115 | |
| 116 | if (l->state == LI_READY) |
| 117 | return 1; |
| 118 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 119 | if (l->state == LI_LIMITED) |
| 120 | LIST_DEL(&l->wait_queue); |
| 121 | |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 122 | if (l->nbconn >= l->maxconn) { |
| 123 | l->state = LI_FULL; |
| 124 | return 1; |
| 125 | } |
| 126 | |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 127 | fd_want_recv(l->fd); |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 128 | l->state = LI_READY; |
| 129 | return 1; |
| 130 | } |
| 131 | |
Willy Tarreau | 6279371 | 2011-07-24 19:23:38 +0200 | [diff] [blame] | 132 | /* Marks a ready listener as full so that the session code tries to re-enable |
| 133 | * it upon next close() using resume_listener(). |
| 134 | */ |
| 135 | void listener_full(struct listener *l) |
| 136 | { |
| 137 | if (l->state >= LI_READY) { |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 138 | if (l->state == LI_LIMITED) |
| 139 | LIST_DEL(&l->wait_queue); |
| 140 | |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 141 | fd_stop_recv(l->fd); |
Willy Tarreau | 6279371 | 2011-07-24 19:23:38 +0200 | [diff] [blame] | 142 | l->state = LI_FULL; |
| 143 | } |
| 144 | } |
| 145 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 146 | /* Marks a ready listener as limited so that we only try to re-enable it when |
| 147 | * resources are free again. It will be queued into the specified queue. |
| 148 | */ |
| 149 | void limit_listener(struct listener *l, struct list *list) |
| 150 | { |
| 151 | if (l->state == LI_READY) { |
| 152 | LIST_ADDQ(list, &l->wait_queue); |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 153 | fd_stop_recv(l->fd); |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 154 | l->state = LI_LIMITED; |
| 155 | } |
| 156 | } |
| 157 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 158 | /* This function adds all of the protocol's listener's file descriptors to the |
| 159 | * polling lists when they are in the LI_LISTEN state. It is intended to be |
| 160 | * used as a protocol's generic enable_all() primitive, for use after the |
| 161 | * fork(). It puts the listeners into LI_READY or LI_FULL states depending on |
| 162 | * their number of connections. It always returns ERR_NONE. |
| 163 | */ |
| 164 | int enable_all_listeners(struct protocol *proto) |
| 165 | { |
| 166 | struct listener *listener; |
| 167 | |
| 168 | list_for_each_entry(listener, &proto->listeners, proto_list) |
| 169 | enable_listener(listener); |
| 170 | return ERR_NONE; |
| 171 | } |
| 172 | |
| 173 | /* This function removes all of the protocol's listener's file descriptors from |
| 174 | * the polling lists when they are in the LI_READY or LI_FULL states. It is |
| 175 | * intended to be used as a protocol's generic disable_all() primitive. It puts |
| 176 | * the listeners into LI_LISTEN, and always returns ERR_NONE. |
| 177 | */ |
| 178 | int disable_all_listeners(struct protocol *proto) |
| 179 | { |
| 180 | struct listener *listener; |
| 181 | |
| 182 | list_for_each_entry(listener, &proto->listeners, proto_list) |
| 183 | disable_listener(listener); |
| 184 | return ERR_NONE; |
| 185 | } |
| 186 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 187 | /* Dequeues all of the listeners waiting for a resource in wait queue <queue>. */ |
| 188 | void dequeue_all_listeners(struct list *list) |
| 189 | { |
| 190 | struct listener *listener, *l_back; |
| 191 | |
| 192 | list_for_each_entry_safe(listener, l_back, list, wait_queue) { |
| 193 | /* This cannot fail because the listeners are by definition in |
| 194 | * the LI_LIMITED state. The function also removes the entry |
| 195 | * from the queue. |
| 196 | */ |
| 197 | resume_listener(listener); |
| 198 | } |
| 199 | } |
| 200 | |
Willy Tarreau | b648d63 | 2007-10-28 22:13:50 +0100 | [diff] [blame] | 201 | /* This function closes the listening socket for the specified listener, |
| 202 | * provided that it's already in a listening state. The listener enters the |
| 203 | * LI_ASSIGNED state. It always returns ERR_NONE. This function is intended |
| 204 | * to be used as a generic function for standard protocols. |
| 205 | */ |
| 206 | int unbind_listener(struct listener *listener) |
| 207 | { |
| 208 | if (listener->state == LI_READY) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 209 | fd_stop_recv(listener->fd); |
Willy Tarreau | b648d63 | 2007-10-28 22:13:50 +0100 | [diff] [blame] | 210 | |
Willy Tarreau | e6ca1fc | 2011-07-24 22:03:52 +0200 | [diff] [blame] | 211 | if (listener->state == LI_LIMITED) |
| 212 | LIST_DEL(&listener->wait_queue); |
| 213 | |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 214 | if (listener->state >= LI_PAUSED) { |
Willy Tarreau | b648d63 | 2007-10-28 22:13:50 +0100 | [diff] [blame] | 215 | fd_delete(listener->fd); |
| 216 | listener->state = LI_ASSIGNED; |
| 217 | } |
| 218 | return ERR_NONE; |
| 219 | } |
| 220 | |
Willy Tarreau | 3acf8c3 | 2007-10-28 22:35:41 +0100 | [diff] [blame] | 221 | /* This function closes all listening sockets bound to the protocol <proto>, |
| 222 | * and the listeners end in LI_ASSIGNED state if they were higher. It does not |
| 223 | * detach them from the protocol. It always returns ERR_NONE. |
| 224 | */ |
| 225 | int unbind_all_listeners(struct protocol *proto) |
| 226 | { |
| 227 | struct listener *listener; |
| 228 | |
| 229 | list_for_each_entry(listener, &proto->listeners, proto_list) |
| 230 | unbind_listener(listener); |
| 231 | return ERR_NONE; |
| 232 | } |
| 233 | |
Willy Tarreau | 1a64d16 | 2007-10-28 22:26:05 +0100 | [diff] [blame] | 234 | /* Delete a listener from its protocol's list of listeners. The listener's |
| 235 | * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's |
| 236 | * number of listeners is updated. Note that the listener must have previously |
| 237 | * been unbound. This is the generic function to use to remove a listener. |
| 238 | */ |
| 239 | void delete_listener(struct listener *listener) |
| 240 | { |
| 241 | if (listener->state != LI_ASSIGNED) |
| 242 | return; |
| 243 | listener->state = LI_INIT; |
| 244 | LIST_DEL(&listener->proto_list); |
| 245 | listener->proto->nb_listeners--; |
| 246 | } |
| 247 | |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 248 | /* This function is called on a read event from a listening socket, corresponding |
| 249 | * to an accept. It tries to accept as many connections as possible, and for each |
| 250 | * calls the listener's accept handler (generally the frontend's accept handler). |
| 251 | */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 252 | void listener_accept(int fd) |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 253 | { |
| 254 | struct listener *l = fdtab[fd].owner; |
| 255 | struct proxy *p = l->frontend; |
Willy Tarreau | 50de90a | 2012-11-23 20:11:45 +0100 | [diff] [blame] | 256 | int max_accept = l->maxaccept ? l->maxaccept : 1; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 257 | int cfd; |
| 258 | int ret; |
| 259 | |
| 260 | if (unlikely(l->nbconn >= l->maxconn)) { |
| 261 | listener_full(l); |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 262 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | if (global.cps_lim && !(l->options & LI_O_UNLIMITED)) { |
| 266 | int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0); |
| 267 | |
| 268 | if (unlikely(!max)) { |
| 269 | /* frontend accept rate limit was reached */ |
| 270 | limit_listener(l, &global_listener_queue); |
| 271 | task_schedule(global_listener_queue_task, tick_add(now_ms, next_event_delay(&global.conn_per_sec, global.cps_lim, 0))); |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 272 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | if (max_accept > max) |
| 276 | max_accept = max; |
| 277 | } |
| 278 | |
| 279 | if (p && p->fe_sps_lim) { |
| 280 | int max = freq_ctr_remain(&p->fe_sess_per_sec, p->fe_sps_lim, 0); |
| 281 | |
| 282 | if (unlikely(!max)) { |
| 283 | /* frontend accept rate limit was reached */ |
| 284 | limit_listener(l, &p->listener_queue); |
| 285 | task_schedule(p->task, tick_add(now_ms, next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0))); |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 286 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | if (max_accept > max) |
| 290 | max_accept = max; |
| 291 | } |
| 292 | |
| 293 | /* Note: if we fail to allocate a connection because of configured |
| 294 | * limits, we'll schedule a new attempt worst 1 second later in the |
| 295 | * worst case. If we fail due to system limits or temporary resource |
| 296 | * shortage, we try again 100ms later in the worst case. |
| 297 | */ |
| 298 | while (max_accept--) { |
| 299 | struct sockaddr_storage addr; |
| 300 | socklen_t laddr = sizeof(addr); |
| 301 | |
| 302 | if (unlikely(actconn >= global.maxconn) && !(l->options & LI_O_UNLIMITED)) { |
| 303 | limit_listener(l, &global_listener_queue); |
| 304 | task_schedule(global_listener_queue_task, tick_add(now_ms, 1000)); /* try again in 1 second */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 305 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | if (unlikely(p && p->feconn >= p->maxconn)) { |
| 309 | limit_listener(l, &p->listener_queue); |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 310 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Willy Tarreau | 1bc4aab | 2012-10-08 20:11:03 +0200 | [diff] [blame] | 313 | #ifdef USE_ACCEPT4 |
| 314 | cfd = accept4(fd, (struct sockaddr *)&addr, &laddr, SOCK_NONBLOCK); |
Willy Tarreau | 6b3b0d4 | 2012-10-22 19:32:55 +0200 | [diff] [blame] | 315 | if (unlikely(cfd == -1 && errno == EINVAL)) { |
| 316 | /* unsupported syscall, fallback to normal accept()+fcntl() */ |
| 317 | if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) != -1) |
| 318 | fcntl(cfd, F_SETFL, O_NONBLOCK); |
| 319 | } |
Willy Tarreau | 1bc4aab | 2012-10-08 20:11:03 +0200 | [diff] [blame] | 320 | #else |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 321 | cfd = accept(fd, (struct sockaddr *)&addr, &laddr); |
Willy Tarreau | 1bc4aab | 2012-10-08 20:11:03 +0200 | [diff] [blame] | 322 | #endif |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 323 | if (unlikely(cfd == -1)) { |
| 324 | switch (errno) { |
| 325 | case EAGAIN: |
| 326 | case EINTR: |
| 327 | case ECONNABORTED: |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 328 | fd_poll_recv(fd); |
| 329 | return; /* nothing more to accept */ |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 330 | case ENFILE: |
| 331 | if (p) |
| 332 | send_log(p, LOG_EMERG, |
| 333 | "Proxy %s reached system FD limit at %d. Please check system tunables.\n", |
| 334 | p->id, maxfd); |
| 335 | limit_listener(l, &global_listener_queue); |
| 336 | task_schedule(global_listener_queue_task, tick_add(now_ms, 100)); /* try again in 100 ms */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 337 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 338 | case EMFILE: |
| 339 | if (p) |
| 340 | send_log(p, LOG_EMERG, |
| 341 | "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", |
| 342 | p->id, maxfd); |
| 343 | limit_listener(l, &global_listener_queue); |
| 344 | task_schedule(global_listener_queue_task, tick_add(now_ms, 100)); /* try again in 100 ms */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 345 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 346 | case ENOBUFS: |
| 347 | case ENOMEM: |
| 348 | if (p) |
| 349 | send_log(p, LOG_EMERG, |
| 350 | "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", |
| 351 | p->id, maxfd); |
| 352 | limit_listener(l, &global_listener_queue); |
| 353 | task_schedule(global_listener_queue_task, tick_add(now_ms, 100)); /* try again in 100 ms */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 354 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 355 | default: |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 356 | /* unexpected result, let's go back to poll */ |
| 357 | fd_poll_recv(fd); |
| 358 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | if (unlikely(cfd >= global.maxsock)) { |
| 363 | send_log(p, LOG_EMERG, |
| 364 | "Proxy %s reached the configured maximum connection limit. Please check the global 'maxconn' value.\n", |
| 365 | p->id); |
| 366 | close(cfd); |
| 367 | limit_listener(l, &global_listener_queue); |
| 368 | task_schedule(global_listener_queue_task, tick_add(now_ms, 1000)); /* try again in 1 second */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 369 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /* increase the per-process number of cumulated connections */ |
| 373 | if (!(l->options & LI_O_UNLIMITED)) { |
| 374 | update_freq_ctr(&global.conn_per_sec, 1); |
| 375 | if (global.conn_per_sec.curr_ctr > global.cps_max) |
| 376 | global.cps_max = global.conn_per_sec.curr_ctr; |
| 377 | actconn++; |
| 378 | } |
| 379 | |
| 380 | jobs++; |
| 381 | totalconn++; |
| 382 | l->nbconn++; |
| 383 | |
| 384 | if (l->counters) { |
| 385 | if (l->nbconn > l->counters->conn_max) |
| 386 | l->counters->conn_max = l->nbconn; |
| 387 | } |
| 388 | |
| 389 | ret = l->accept(l, cfd, &addr); |
| 390 | if (unlikely(ret <= 0)) { |
| 391 | /* The connection was closed by session_accept(). Either |
| 392 | * we just have to ignore it (ret == 0) or it's a critical |
| 393 | * error due to a resource shortage, and we must stop the |
| 394 | * listener (ret < 0). |
| 395 | */ |
| 396 | if (!(l->options & LI_O_UNLIMITED)) |
| 397 | actconn--; |
| 398 | jobs--; |
| 399 | l->nbconn--; |
| 400 | if (ret == 0) /* successful termination */ |
| 401 | continue; |
| 402 | |
| 403 | limit_listener(l, &global_listener_queue); |
| 404 | task_schedule(global_listener_queue_task, tick_add(now_ms, 100)); /* try again in 100 ms */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 405 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | if (l->nbconn >= l->maxconn) { |
| 409 | listener_full(l); |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 410 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 411 | } |
| 412 | |
Willy Tarreau | aece46a | 2012-07-06 12:25:58 +0200 | [diff] [blame] | 413 | } /* end of while (max_accept--) */ |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 414 | |
Willy Tarreau | aece46a | 2012-07-06 12:25:58 +0200 | [diff] [blame] | 415 | /* we've exhausted max_accept, so there is no need to poll again */ |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 416 | return; |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 419 | /* |
| 420 | * Registers the bind keyword list <kwl> as a list of valid keywords for next |
| 421 | * parsing sessions. |
| 422 | */ |
| 423 | void bind_register_keywords(struct bind_kw_list *kwl) |
| 424 | { |
| 425 | LIST_ADDQ(&bind_keywords.list, &kwl->list); |
| 426 | } |
| 427 | |
| 428 | /* Return a pointer to the bind keyword <kw>, or NULL if not found. If the |
| 429 | * keyword is found with a NULL ->parse() function, then an attempt is made to |
| 430 | * find one with a valid ->parse() function. This way it is possible to declare |
| 431 | * platform-dependant, known keywords as NULL, then only declare them as valid |
| 432 | * if some options are met. Note that if the requested keyword contains an |
| 433 | * opening parenthesis, everything from this point is ignored. |
| 434 | */ |
| 435 | struct bind_kw *bind_find_kw(const char *kw) |
| 436 | { |
| 437 | int index; |
| 438 | const char *kwend; |
| 439 | struct bind_kw_list *kwl; |
| 440 | struct bind_kw *ret = NULL; |
| 441 | |
| 442 | kwend = strchr(kw, '('); |
| 443 | if (!kwend) |
| 444 | kwend = kw + strlen(kw); |
| 445 | |
| 446 | list_for_each_entry(kwl, &bind_keywords.list, list) { |
| 447 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 448 | if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) && |
| 449 | kwl->kw[index].kw[kwend-kw] == 0) { |
| 450 | if (kwl->kw[index].parse) |
| 451 | return &kwl->kw[index]; /* found it !*/ |
| 452 | else |
| 453 | ret = &kwl->kw[index]; /* may be OK */ |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | return ret; |
| 458 | } |
| 459 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 460 | /* Dumps all registered "bind" keywords to the <out> string pointer. The |
| 461 | * unsupported keywords are only dumped if their supported form was not |
| 462 | * found. |
| 463 | */ |
| 464 | void bind_dump_kws(char **out) |
| 465 | { |
| 466 | struct bind_kw_list *kwl; |
| 467 | int index; |
| 468 | |
| 469 | *out = NULL; |
| 470 | list_for_each_entry(kwl, &bind_keywords.list, list) { |
| 471 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 472 | if (kwl->kw[index].parse || |
| 473 | bind_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) { |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 474 | memprintf(out, "%s[%4s] %s%s%s\n", *out ? *out : "", |
| 475 | kwl->scope, |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 476 | kwl->kw[index].kw, |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 477 | kwl->kw[index].skip ? " <arg>" : "", |
| 478 | kwl->kw[index].parse ? "" : " (not supported)"); |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 484 | /************************************************************************/ |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 485 | /* All supported sample and ACL keywords must be declared here. */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 486 | /************************************************************************/ |
| 487 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 488 | /* set temp integer to the number of connexions to the same listening socket */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 489 | static int |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 490 | smp_fetch_dconn(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 491 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 492 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 493 | smp->type = SMP_T_UINT; |
| 494 | smp->data.uint = l4->listener->nbconn; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 495 | return 1; |
| 496 | } |
| 497 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 498 | /* set temp integer to the id of the socket (listener) */ |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 499 | static int |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 500 | smp_fetch_so_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 501 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 502 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 503 | smp->type = SMP_T_UINT; |
| 504 | smp->data.uint = l4->listener->luid; |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 505 | return 1; |
| 506 | } |
| 507 | |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 508 | /* parse the "accept-proxy" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 509 | static int bind_parse_accept_proxy(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 510 | { |
| 511 | struct listener *l; |
| 512 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 513 | list_for_each_entry(l, &conf->listeners, by_bind) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 514 | l->options |= LI_O_ACC_PROXY; |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /* parse the "backlog" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 520 | static int bind_parse_backlog(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 521 | { |
| 522 | struct listener *l; |
| 523 | int val; |
| 524 | |
| 525 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 526 | memprintf(err, "'%s' : missing value", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 527 | return ERR_ALERT | ERR_FATAL; |
| 528 | } |
| 529 | |
| 530 | val = atol(args[cur_arg + 1]); |
| 531 | if (val <= 0) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 532 | memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 533 | return ERR_ALERT | ERR_FATAL; |
| 534 | } |
| 535 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 536 | list_for_each_entry(l, &conf->listeners, by_bind) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 537 | l->backlog = val; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /* parse the "id" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 543 | static int bind_parse_id(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 544 | { |
| 545 | struct eb32_node *node; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 546 | struct listener *l, *new; |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 547 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 548 | if (conf->listeners.n != conf->listeners.p) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 549 | memprintf(err, "'%s' can only be used with a single socket", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 550 | return ERR_ALERT | ERR_FATAL; |
| 551 | } |
| 552 | |
| 553 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 554 | memprintf(err, "'%s' : expects an integer argument", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 555 | return ERR_ALERT | ERR_FATAL; |
| 556 | } |
| 557 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 558 | new = LIST_NEXT(&conf->listeners, struct listener *, by_bind); |
| 559 | new->luid = atol(args[cur_arg + 1]); |
| 560 | new->conf.id.key = new->luid; |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 561 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 562 | if (new->luid <= 0) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 563 | memprintf(err, "'%s' : custom id has to be > 0", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 564 | return ERR_ALERT | ERR_FATAL; |
| 565 | } |
| 566 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 567 | node = eb32_lookup(&px->conf.used_listener_id, new->luid); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 568 | if (node) { |
| 569 | l = container_of(node, struct listener, conf.id); |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 570 | memprintf(err, "'%s' : custom id %d already used at %s:%d ('bind %s')", |
| 571 | args[cur_arg], l->luid, l->bind_conf->file, l->bind_conf->line, |
| 572 | l->bind_conf->arg); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 573 | return ERR_ALERT | ERR_FATAL; |
| 574 | } |
| 575 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 576 | eb32_insert(&px->conf.used_listener_id, &new->conf.id); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /* parse the "maxconn" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 581 | static int bind_parse_maxconn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 582 | { |
| 583 | struct listener *l; |
| 584 | int val; |
| 585 | |
| 586 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 587 | memprintf(err, "'%s' : missing value", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 588 | return ERR_ALERT | ERR_FATAL; |
| 589 | } |
| 590 | |
| 591 | val = atol(args[cur_arg + 1]); |
| 592 | if (val <= 0) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 593 | memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 594 | return ERR_ALERT | ERR_FATAL; |
| 595 | } |
| 596 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 597 | list_for_each_entry(l, &conf->listeners, by_bind) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 598 | l->maxconn = val; |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | /* parse the "name" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 604 | static int bind_parse_name(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 605 | { |
| 606 | struct listener *l; |
| 607 | |
| 608 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 609 | memprintf(err, "'%s' : missing name", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 610 | return ERR_ALERT | ERR_FATAL; |
| 611 | } |
| 612 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 613 | list_for_each_entry(l, &conf->listeners, by_bind) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 614 | l->name = strdup(args[cur_arg + 1]); |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | /* parse the "nice" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 620 | static int bind_parse_nice(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 621 | { |
| 622 | struct listener *l; |
| 623 | int val; |
| 624 | |
| 625 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 626 | memprintf(err, "'%s' : missing value", args[cur_arg]); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 627 | return ERR_ALERT | ERR_FATAL; |
| 628 | } |
| 629 | |
| 630 | val = atol(args[cur_arg + 1]); |
| 631 | if (val < -1024 || val > 1024) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 632 | memprintf(err, "'%s' : invalid value %d, allowed range is -1024..1024", args[cur_arg], val); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 633 | return ERR_ALERT | ERR_FATAL; |
| 634 | } |
| 635 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 636 | list_for_each_entry(l, &conf->listeners, by_bind) |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 637 | l->nice = val; |
| 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 643 | /* Note: must not be declared <const> as its list will be overwritten. |
| 644 | * Please take care of keeping this list alphabetically sorted. |
| 645 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 646 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 647 | { "dst_conn", smp_fetch_dconn, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, }, |
| 648 | { "so_id", smp_fetch_so_id, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, }, |
| 649 | { /* END */ }, |
| 650 | }}; |
| 651 | |
| 652 | /* Note: must not be declared <const> as its list will be overwritten. |
| 653 | * Please take care of keeping this list alphabetically sorted. |
| 654 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 655 | static struct acl_kw_list acl_kws = {ILH, { |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 656 | { /* END */ }, |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 657 | }}; |
| 658 | |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 659 | /* Note: must not be declared <const> as its list will be overwritten. |
| 660 | * Please take care of keeping this list alphabetically sorted, doing so helps |
| 661 | * all code contributors. |
| 662 | * Optional keywords are also declared with a NULL ->parse() function so that |
| 663 | * the config parser can report an appropriate error when a known keyword was |
| 664 | * not enabled. |
| 665 | */ |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 666 | static struct bind_kw_list bind_kws = { "ALL", { }, { |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 667 | { "accept-proxy", bind_parse_accept_proxy, 0 }, /* enable PROXY protocol */ |
| 668 | { "backlog", bind_parse_backlog, 1 }, /* set backlog of listening socket */ |
| 669 | { "id", bind_parse_id, 1 }, /* set id of listening socket */ |
| 670 | { "maxconn", bind_parse_maxconn, 1 }, /* set maxconn of listening socket */ |
| 671 | { "name", bind_parse_name, 1 }, /* set name of listening socket */ |
| 672 | { "nice", bind_parse_nice, 1 }, /* set nice of listening socket */ |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 673 | { /* END */ }, |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 674 | }}; |
| 675 | |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 676 | __attribute__((constructor)) |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 677 | static void __listener_init(void) |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 678 | { |
Willy Tarreau | 0ccb744 | 2013-01-07 22:54:17 +0100 | [diff] [blame] | 679 | sample_register_fetches(&smp_kws); |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 680 | acl_register_keywords(&acl_kws); |
Willy Tarreau | 3dcc341 | 2012-09-18 17:17:28 +0200 | [diff] [blame] | 681 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 645513a | 2010-05-24 20:55:15 +0200 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /* |
| 685 | * Local variables: |
| 686 | * c-indent-level: 8 |
| 687 | * c-basic-offset: 8 |
| 688 | * End: |
| 689 | */ |