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); |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 69 | int cfg_parse_track_sc_num(unsigned int *track_sc_num, |
| 70 | const char *arg, const char *end, char **err); |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 71 | int readcfgfile(const char *file); |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 72 | void cfg_register_keywords(struct cfg_kw_list *kwl); |
| 73 | void cfg_unregister_keywords(struct cfg_kw_list *kwl); |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 74 | void init_default_instance(); |
| 75 | int check_config_validity(); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 76 | 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] | 77 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 78 | int (*section_parser)(const char *, int, char **, int), |
| 79 | int (*post_section_parser)()); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 80 | int cfg_register_postparser(char *name, int (*func)()); |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 81 | void cfg_unregister_sections(void); |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 82 | void cfg_backup_sections(struct list *backup_sections); |
| 83 | void cfg_restore_sections(struct list *backup_sections); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 84 | 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] | 85 | 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] | 86 | 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] | 87 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code); |
| 88 | int too_many_args(int maxarg, char **args, char **msg, int *err_code); |
| 89 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code); |
| 90 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 91 | int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 93 | /* |
| 94 | * Sends a warning if proxy <proxy> does not have at least one of the |
| 95 | * capabilities in <cap>. An optionnal <hint> may be added at the end |
| 96 | * of the warning to help the user. Returns 1 if a warning was emitted |
| 97 | * or 0 if the condition is valid. |
| 98 | */ |
| 99 | static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
| 100 | { |
| 101 | char *msg; |
| 102 | |
| 103 | switch (cap) { |
| 104 | case PR_CAP_BE: msg = "no backend"; break; |
| 105 | case PR_CAP_FE: msg = "no frontend"; break; |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 106 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
| 107 | default: msg = "not enough"; break; |
| 108 | } |
| 109 | |
| 110 | if (!(proxy->cap & cap)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 111 | ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
| 112 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 113 | return 1; |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 118 | #endif /* _COMMON_CFGPARSE_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * Local variables: |
| 122 | * c-indent-level: 8 |
| 123 | * c-basic-offset: 8 |
| 124 | * End: |
| 125 | */ |