blob: b46e02b99c30ae650a78ec4e9fd8eac85ec4c368 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau0a3dd742012-05-08 19:47:01 +02002 * 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 Tarreaubaaee002006-06-26 02:48:02 +020021
Willy Tarreau2dd0d472006-06-29 17:53:05 +020022#ifndef _COMMON_CFGPARSE_H
23#define _COMMON_CFGPARSE_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreau5b2c3362008-07-09 19:39:06 +020025#include <common/compat.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020026#include <common/config.h>
Willy Tarreaue6552512018-11-26 11:33:13 +010027#include <common/initcall.h>
Willy Tarreau5b2c3362008-07-09 19:39:06 +020028#include <common/mini-clist.h>
29
Willy Tarreau272adea2014-03-31 10:39:59 +020030#include <proto/log.h>
31#include <proto/proxy.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020032
Willy Tarreaubaaee002006-06-26 02:48:02 +020033/* configuration sections */
34#define CFG_NONE 0
35#define CFG_GLOBAL 1
36#define CFG_LISTEN 2
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +010037#define CFG_USERLIST 3
Emeric Brun32da3c42010-09-23 18:39:19 +020038#define CFG_PEERS 4
Willy Tarreaubaaee002006-06-26 02:48:02 +020039
Willy Tarreau36b9e222018-11-11 15:19:52 +010040/* various keyword modifiers */
41enum 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 Tarreau5b2c3362008-07-09 19:39:06 +020047struct cfg_keyword {
48 int section; /* section type for this keyword */
49 const char *kw; /* the keyword itself */
Willy Tarreau39f23b62008-07-09 20:22:56 +020050 int (*parse)( /* 0=OK, <0=Alert, >0=Warning */
51 char **args, /* command line and arguments */
Willy Tarreau5b2c3362008-07-09 19:39:06 +020052 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 Tarreau28a47d62012-09-18 20:02:48 +020055 const char *file, /* config file name */
56 int line, /* config file line number */
Willy Tarreau0a3dd742012-05-08 19:47:01 +020057 char **err); /* error or warning message output pointer */
Willy Tarreau5b2c3362008-07-09 19:39:06 +020058};
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 */
65struct cfg_kw_list {
66 struct list list;
67 struct cfg_keyword kw[VAR_ARRAY];
68};
69
Willy Tarreau36b9e222018-11-11 15:19:52 +010070/* permit to store configuration section */
71struct 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
80struct cfg_postparser {
81 struct list list;
82 char *name;
83 int (*func)();
84};
85
Willy Tarreaubaaee002006-06-26 02:48:02 +020086extern int cfg_maxpconn;
87extern int cfg_maxconn;
Christopher Faulet79bdef32016-11-04 22:36:15 +010088extern char *cfg_scope;
Willy Tarreau36b9e222018-11-11 15:19:52 +010089extern struct cfg_kw_list cfg_keywords;
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +010090extern char *cursection;
91extern struct proxy defproxy;
Willy Tarreaubaaee002006-06-26 02:48:02 +020092
Krzysztof Oledzki336d4752007-12-25 02:40:22 +010093int cfg_parse_global(const char *file, int linenum, char **args, int inv);
94int cfg_parse_listen(const char *file, int linenum, char **args, int inv);
Frédéric Lécaillea41d5312018-01-29 12:05:07 +010095int cfg_parse_track_sc_num(unsigned int *track_sc_num,
96 const char *arg, const char *end, char **err);
Willy Tarreaub17916e2006-10-15 15:17:57 +020097int readcfgfile(const char *file);
Willy Tarreau5b2c3362008-07-09 19:39:06 +020098void cfg_register_keywords(struct cfg_kw_list *kwl);
99void cfg_unregister_keywords(struct cfg_kw_list *kwl);
Willy Tarreau915e1eb2009-06-22 15:48:36 +0200100void init_default_instance();
101int check_config_validity();
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200102int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err);
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +0100103int cfg_register_section(char *section_name,
William Lallemandd2ff56d2017-10-16 11:06:50 +0200104 int (*section_parser)(const char *, int, char **, int),
105 int (*post_section_parser)());
William Lallemand48b4bb42017-10-23 14:36:34 +0200106int cfg_register_postparser(char *name, int (*func)());
David Carlier845efb52015-09-25 11:49:18 +0100107void cfg_unregister_sections(void);
Christopher Faulet7110b402016-10-26 11:09:44 +0200108void cfg_backup_sections(struct list *backup_sections);
109void cfg_restore_sections(struct list *backup_sections);
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200110int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg);
Willy Tarreau620408f2016-10-21 16:37:51 +0200111int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg);
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200112int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100113int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line);
Willy Tarreauece9b072016-12-21 22:41:44 +0100114int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code);
115int too_many_args(int maxarg, char **args, char **msg, int *err_code);
116int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code);
117int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code);
Christopher Faulet26028f62017-11-22 15:01:51 +0100118int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100119unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err);
Willy Tarreau3a1f5fd2018-11-11 15:40:36 +0100120void free_email_alert(struct proxy *p);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200121
Willy Tarreau272adea2014-03-31 10:39:59 +0200122/*
123 * Sends a warning if proxy <proxy> does not have at least one of the
Dave Chiluk8618a6a2018-06-21 11:03:20 -0500124 * capabilities in <cap>. An optional <hint> may be added at the end
Willy Tarreau272adea2014-03-31 10:39:59 +0200125 * of the warning to help the user. Returns 1 if a warning was emitted
126 * or 0 if the condition is valid.
127 */
128static 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 Tarreau272adea2014-03-31 10:39:59 +0200135 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 Faulet767a84b2017-11-24 16:50:31 +0100140 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 Tarreau272adea2014-03-31 10:39:59 +0200142 return 1;
143 }
144 return 0;
145}
146
Willy Tarreaue6552512018-11-26 11:33:13 +0100147/* 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 Tarreau2dd0d472006-06-29 17:53:05 +0200154#endif /* _COMMON_CFGPARSE_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200155
156/*
157 * Local variables:
158 * c-indent-level: 8
159 * c-basic-offset: 8
160 * End:
161 */