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 | e655251 | 2018-11-26 11:33:13 +0100 | [diff] [blame] | 27 | #include <common/initcall.h> |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 28 | #include <common/mini-clist.h> |
| 29 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 30 | #include <proto/log.h> |
| 31 | #include <proto/proxy.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | /* configuration sections */ |
| 34 | #define CFG_NONE 0 |
| 35 | #define CFG_GLOBAL 1 |
| 36 | #define CFG_LISTEN 2 |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 37 | #define CFG_USERLIST 3 |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 38 | #define CFG_PEERS 4 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 40 | /* various keyword modifiers */ |
| 41 | enum kw_mod { |
| 42 | KWM_STD = 0, /* normal */ |
| 43 | KWM_NO, /* "no" prefixed before the keyword */ |
| 44 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 45 | }; |
| 46 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 47 | struct cfg_keyword { |
| 48 | int section; /* section type for this keyword */ |
| 49 | const char *kw; /* the keyword itself */ |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 50 | int (*parse)( /* 0=OK, <0=Alert, >0=Warning */ |
| 51 | char **args, /* command line and arguments */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 52 | int section_type, /* current section CFG_{GLOBAL|LISTEN} */ |
| 53 | struct proxy *curpx, /* current proxy (NULL in GLOBAL) */ |
| 54 | struct proxy *defpx, /* default proxy (NULL in GLOBAL) */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 55 | const char *file, /* config file name */ |
| 56 | int line, /* config file line number */ |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 57 | char **err); /* error or warning message output pointer */ |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* A keyword list. It is a NULL-terminated array of keywords. It embeds a |
| 61 | * struct list in order to be linked to other lists, allowing it to easily |
| 62 | * be declared where it is needed, and linked without duplicating data nor |
| 63 | * allocating memory. |
| 64 | */ |
| 65 | struct cfg_kw_list { |
| 66 | struct list list; |
| 67 | struct cfg_keyword kw[VAR_ARRAY]; |
| 68 | }; |
| 69 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 70 | /* permit to store configuration section */ |
| 71 | struct cfg_section { |
| 72 | struct list list; |
| 73 | char *section_name; |
| 74 | int (*section_parser)(const char *, int, char **, int); |
| 75 | int (*post_section_parser)(); |
| 76 | }; |
| 77 | |
| 78 | /* store post configuration parsing */ |
| 79 | |
| 80 | struct cfg_postparser { |
| 81 | struct list list; |
| 82 | char *name; |
| 83 | int (*func)(); |
| 84 | }; |
| 85 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 86 | extern int cfg_maxpconn; |
| 87 | extern int cfg_maxconn; |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 88 | extern char *cfg_scope; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 89 | extern struct cfg_kw_list cfg_keywords; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 90 | extern char *cursection; |
| 91 | extern struct proxy defproxy; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 93 | int cfg_parse_global(const char *file, int linenum, char **args, int inv); |
| 94 | int cfg_parse_listen(const char *file, int linenum, char **args, int inv); |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 95 | int cfg_parse_track_sc_num(unsigned int *track_sc_num, |
| 96 | const char *arg, const char *end, char **err); |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 97 | int readcfgfile(const char *file); |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 98 | void cfg_register_keywords(struct cfg_kw_list *kwl); |
| 99 | void cfg_unregister_keywords(struct cfg_kw_list *kwl); |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 100 | void init_default_instance(); |
| 101 | int check_config_validity(); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 102 | 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] | 103 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 104 | int (*section_parser)(const char *, int, char **, int), |
| 105 | int (*post_section_parser)()); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 106 | int cfg_register_postparser(char *name, int (*func)()); |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 107 | void cfg_unregister_sections(void); |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 108 | void cfg_backup_sections(struct list *backup_sections); |
| 109 | void cfg_restore_sections(struct list *backup_sections); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 110 | 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] | 111 | 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] | 112 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 113 | int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line); |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 114 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code); |
| 115 | int too_many_args(int maxarg, char **args, char **msg, int *err_code); |
| 116 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code); |
| 117 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code); |
Willy Tarreau | c9a82e4 | 2019-01-26 13:25:14 +0100 | [diff] [blame] | 118 | int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 119 | unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 120 | void free_email_alert(struct proxy *p); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 121 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 122 | /* |
| 123 | * Sends a warning if proxy <proxy> does not have at least one of the |
Dave Chiluk | 8618a6a | 2018-06-21 11:03:20 -0500 | [diff] [blame] | 124 | * capabilities in <cap>. An optional <hint> may be added at the end |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 125 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 126 | * or 0 if the condition is valid. |
| 127 | */ |
| 128 | static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
| 129 | { |
| 130 | char *msg; |
| 131 | |
| 132 | switch (cap) { |
| 133 | case PR_CAP_BE: msg = "no backend"; break; |
| 134 | case PR_CAP_FE: msg = "no frontend"; break; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 135 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 136 | default: msg = "not enough"; break; |
| 137 | } |
| 138 | |
| 139 | if (!(proxy->cap & cap)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 140 | ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
| 141 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 142 | return 1; |
| 143 | } |
| 144 | return 0; |
| 145 | } |
| 146 | |
Willy Tarreau | e655251 | 2018-11-26 11:33:13 +0100 | [diff] [blame] | 147 | /* simplified way to define a section parser */ |
| 148 | #define REGISTER_CONFIG_SECTION(name, parse, post) \ |
| 149 | INITCALL3(STG_REGISTER, cfg_register_section, (name), (parse), (post)) |
| 150 | |
| 151 | #define REGISTER_CONFIG_POSTPARSER(name, parser) \ |
| 152 | INITCALL2(STG_REGISTER, cfg_register_postparser, (name), (parser)) |
| 153 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 154 | #endif /* _COMMON_CFGPARSE_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Local variables: |
| 158 | * c-indent-level: 8 |
| 159 | * c-basic-offset: 8 |
| 160 | * End: |
| 161 | */ |