2006-06-15 19:48:13 +00:00
|
|
|
/*
|
2012-05-08 17:47:01 +00:00
|
|
|
* include/common/cfgparse.h
|
|
|
|
* Configuration parsing functions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-06-15 19:48:13 +00:00
|
|
|
|
2006-06-29 15:53:05 +00:00
|
|
|
#ifndef _COMMON_CFGPARSE_H
|
|
|
|
#define _COMMON_CFGPARSE_H
|
2006-06-26 00:48:02 +00:00
|
|
|
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
#include <common/compat.h>
|
2006-06-29 16:54:54 +00:00
|
|
|
#include <common/config.h>
|
2018-11-26 10:33:13 +00:00
|
|
|
#include <common/initcall.h>
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
#include <common/mini-clist.h>
|
|
|
|
|
2014-03-31 08:39:59 +00:00
|
|
|
#include <proto/log.h>
|
|
|
|
#include <proto/proxy.h>
|
2006-06-29 16:54:54 +00:00
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
/* configuration sections */
|
|
|
|
#define CFG_NONE 0
|
|
|
|
#define CFG_GLOBAL 1
|
|
|
|
#define CFG_LISTEN 2
|
2010-01-29 16:50:44 +00:00
|
|
|
#define CFG_USERLIST 3
|
2010-09-23 16:39:19 +00:00
|
|
|
#define CFG_PEERS 4
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2018-11-11 14:19:52 +00:00
|
|
|
/* various keyword modifiers */
|
|
|
|
enum kw_mod {
|
|
|
|
KWM_STD = 0, /* normal */
|
|
|
|
KWM_NO, /* "no" prefixed before the keyword */
|
|
|
|
KWM_DEF, /* "default" prefixed before the keyword */
|
|
|
|
};
|
|
|
|
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
struct cfg_keyword {
|
|
|
|
int section; /* section type for this keyword */
|
|
|
|
const char *kw; /* the keyword itself */
|
2008-07-09 18:22:56 +00:00
|
|
|
int (*parse)( /* 0=OK, <0=Alert, >0=Warning */
|
|
|
|
char **args, /* command line and arguments */
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
int section_type, /* current section CFG_{GLOBAL|LISTEN} */
|
|
|
|
struct proxy *curpx, /* current proxy (NULL in GLOBAL) */
|
|
|
|
struct proxy *defpx, /* default proxy (NULL in GLOBAL) */
|
2012-09-18 18:02:48 +00:00
|
|
|
const char *file, /* config file name */
|
|
|
|
int line, /* config file line number */
|
2012-05-08 17:47:01 +00:00
|
|
|
char **err); /* error or warning message output pointer */
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A keyword list. It is a NULL-terminated array of keywords. It embeds a
|
|
|
|
* struct list in order to be linked to other lists, allowing it to easily
|
|
|
|
* be declared where it is needed, and linked without duplicating data nor
|
|
|
|
* allocating memory.
|
|
|
|
*/
|
|
|
|
struct cfg_kw_list {
|
|
|
|
struct list list;
|
|
|
|
struct cfg_keyword kw[VAR_ARRAY];
|
|
|
|
};
|
|
|
|
|
2018-11-11 14:19:52 +00:00
|
|
|
/* permit to store configuration section */
|
|
|
|
struct cfg_section {
|
|
|
|
struct list list;
|
|
|
|
char *section_name;
|
|
|
|
int (*section_parser)(const char *, int, char **, int);
|
|
|
|
int (*post_section_parser)();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* store post configuration parsing */
|
|
|
|
|
|
|
|
struct cfg_postparser {
|
|
|
|
struct list list;
|
|
|
|
char *name;
|
|
|
|
int (*func)();
|
|
|
|
};
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
extern int cfg_maxpconn;
|
|
|
|
extern int cfg_maxconn;
|
2016-11-04 21:36:15 +00:00
|
|
|
extern char *cfg_scope;
|
2018-11-11 14:19:52 +00:00
|
|
|
extern struct cfg_kw_list cfg_keywords;
|
2018-11-11 14:40:36 +00:00
|
|
|
extern char *cursection;
|
|
|
|
extern struct proxy defproxy;
|
2006-06-15 19:48:13 +00:00
|
|
|
|
2007-12-25 01:40:22 +00:00
|
|
|
int cfg_parse_global(const char *file, int linenum, char **args, int inv);
|
|
|
|
int cfg_parse_listen(const char *file, int linenum, char **args, int inv);
|
2018-01-29 11:05:07 +00:00
|
|
|
int cfg_parse_track_sc_num(unsigned int *track_sc_num,
|
|
|
|
const char *arg, const char *end, char **err);
|
2006-10-15 13:17:57 +00:00
|
|
|
int readcfgfile(const char *file);
|
[MEDIUM] add support for configuration keyword registration
Any module which needs configuration keywords may now dynamically
register a keyword in a given section, and associate it with a
configuration parsing function using cfg_register_keywords() from
a constructor function. This makes the configuration parser more
modular because it is not required anymore to touch cfg_parse.c.
Example :
static int parse_global_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in global section\n");
return 0;
}
static int parse_listen_blah(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
printf("parsing blah in listen section\n");
if (*args[1]) {
snprintf(err, errlen, "missing arg for listen_blah!!!");
return -1;
}
return 0;
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "blah", parse_global_blah },
{ CFG_LISTEN, "blah", parse_listen_blah },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
2008-07-09 17:39:06 +00:00
|
|
|
void cfg_register_keywords(struct cfg_kw_list *kwl);
|
|
|
|
void cfg_unregister_keywords(struct cfg_kw_list *kwl);
|
2009-06-22 13:48:36 +00:00
|
|
|
void init_default_instance();
|
|
|
|
int check_config_validity();
|
2012-09-20 18:01:39 +00:00
|
|
|
int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err);
|
2014-03-18 12:54:18 +00:00
|
|
|
int cfg_register_section(char *section_name,
|
2017-10-16 09:06:50 +00:00
|
|
|
int (*section_parser)(const char *, int, char **, int),
|
|
|
|
int (*post_section_parser)());
|
2017-10-23 12:36:34 +00:00
|
|
|
int cfg_register_postparser(char *name, int (*func)());
|
2015-09-25 10:49:18 +00:00
|
|
|
void cfg_unregister_sections(void);
|
2016-10-26 09:09:44 +00:00
|
|
|
void cfg_backup_sections(struct list *backup_sections);
|
|
|
|
void cfg_restore_sections(struct list *backup_sections);
|
2014-09-16 13:39:51 +00:00
|
|
|
int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg);
|
2016-10-21 14:37:51 +00:00
|
|
|
int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg);
|
2014-09-16 13:39:51 +00:00
|
|
|
int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg);
|
2018-11-11 14:40:36 +00:00
|
|
|
int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line);
|
2016-12-21 21:41:44 +00:00
|
|
|
int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code);
|
|
|
|
int too_many_args(int maxarg, char **args, char **msg, int *err_code);
|
|
|
|
int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code);
|
|
|
|
int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code);
|
2017-11-22 14:01:51 +00:00
|
|
|
int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err);
|
2018-11-11 14:19:52 +00:00
|
|
|
unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err);
|
2018-11-11 14:40:36 +00:00
|
|
|
void free_email_alert(struct proxy *p);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2014-03-31 08:39:59 +00:00
|
|
|
/*
|
|
|
|
* Sends a warning if proxy <proxy> does not have at least one of the
|
2018-06-21 16:03:20 +00:00
|
|
|
* capabilities in <cap>. An optional <hint> may be added at the end
|
2014-03-31 08:39:59 +00:00
|
|
|
* of the warning to help the user. Returns 1 if a warning was emitted
|
|
|
|
* or 0 if the condition is valid.
|
|
|
|
*/
|
|
|
|
static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint)
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
switch (cap) {
|
|
|
|
case PR_CAP_BE: msg = "no backend"; break;
|
|
|
|
case PR_CAP_FE: msg = "no frontend"; break;
|
|
|
|
case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break;
|
|
|
|
default: msg = "not enough"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(proxy->cap & cap)) {
|
2017-11-24 15:50:31 +00:00
|
|
|
ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n",
|
|
|
|
file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : "");
|
2014-03-31 08:39:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-26 10:33:13 +00:00
|
|
|
/* simplified way to define a section parser */
|
|
|
|
#define REGISTER_CONFIG_SECTION(name, parse, post) \
|
|
|
|
INITCALL3(STG_REGISTER, cfg_register_section, (name), (parse), (post))
|
|
|
|
|
|
|
|
#define REGISTER_CONFIG_POSTPARSER(name, parser) \
|
|
|
|
INITCALL2(STG_REGISTER, cfg_register_postparser, (name), (parser))
|
|
|
|
|
2006-06-29 15:53:05 +00:00
|
|
|
#endif /* _COMMON_CFGPARSE_H */
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|