Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 2 | * include/common/cfgparse.h |
| 3 | * Configuration parsing functions. |
| 4 | * |
| 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 22 | #ifndef _COMMON_CFGPARSE_H |
| 23 | #define _COMMON_CFGPARSE_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 25 | #include <common/compat.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 27 | #include <common/mini-clist.h> |
| 28 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 29 | #include <proto/log.h> |
| 30 | #include <proto/proxy.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | /* configuration sections */ |
| 33 | #define CFG_NONE 0 |
| 34 | #define CFG_GLOBAL 1 |
| 35 | #define CFG_LISTEN 2 |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 36 | #define CFG_USERLIST 3 |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 37 | #define CFG_PEERS 4 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 39 | struct cfg_keyword { |
| 40 | int section; /* section type for this keyword */ |
| 41 | const char *kw; /* the keyword itself */ |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 42 | int (*parse)( /* 0=OK, <0=Alert, >0=Warning */ |
| 43 | char **args, /* command line and arguments */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 44 | int section_type, /* current section CFG_{GLOBAL|LISTEN} */ |
| 45 | struct proxy *curpx, /* current proxy (NULL in GLOBAL) */ |
| 46 | struct proxy *defpx, /* default proxy (NULL in GLOBAL) */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 47 | const char *file, /* config file name */ |
| 48 | int line, /* config file line number */ |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 49 | char **err); /* error or warning message output pointer */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /* A keyword list. It is a NULL-terminated array of keywords. It embeds a |
| 53 | * struct list in order to be linked to other lists, allowing it to easily |
| 54 | * be declared where it is needed, and linked without duplicating data nor |
| 55 | * allocating memory. |
| 56 | */ |
| 57 | struct cfg_kw_list { |
| 58 | struct list list; |
| 59 | struct cfg_keyword kw[VAR_ARRAY]; |
| 60 | }; |
| 61 | |
| 62 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 63 | extern int cfg_maxpconn; |
| 64 | extern int cfg_maxconn; |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 65 | extern char *cfg_scope; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 66 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 67 | int cfg_parse_global(const char *file, int linenum, char **args, int inv); |
| 68 | int cfg_parse_listen(const char *file, int linenum, char **args, int inv); |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 69 | int readcfgfile(const char *file); |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 70 | void cfg_register_keywords(struct cfg_kw_list *kwl); |
| 71 | void cfg_unregister_keywords(struct cfg_kw_list *kwl); |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 72 | void init_default_instance(); |
| 73 | int check_config_validity(); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 74 | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 75 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 76 | int (*section_parser)(const char *, int, char **, int), |
| 77 | int (*post_section_parser)()); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 78 | int cfg_register_postparser(char *name, int (*func)()); |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 79 | void cfg_unregister_sections(void); |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 80 | void cfg_backup_sections(struct list *backup_sections); |
| 81 | void cfg_restore_sections(struct list *backup_sections); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 82 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 83 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 84 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 85 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code); |
| 86 | int too_many_args(int maxarg, char **args, char **msg, int *err_code); |
| 87 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code); |
| 88 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 89 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 90 | /* |
| 91 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 92 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 93 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 94 | * or 0 if the condition is valid. |
| 95 | */ |
| 96 | static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
| 97 | { |
| 98 | char *msg; |
| 99 | |
| 100 | switch (cap) { |
| 101 | case PR_CAP_BE: msg = "no backend"; break; |
| 102 | case PR_CAP_FE: msg = "no frontend"; break; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 103 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 104 | default: msg = "not enough"; break; |
| 105 | } |
| 106 | |
| 107 | if (!(proxy->cap & cap)) { |
| 108 | Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
| 109 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
| 110 | return 1; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 115 | #endif /* _COMMON_CFGPARSE_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Local variables: |
| 119 | * c-indent-level: 8 |
| 120 | * c-basic-offset: 8 |
| 121 | * End: |
| 122 | */ |