Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/arg.h |
| 3 | * This file contains structure declarations for generaic argument parsing. |
| 4 | * |
| 5 | * Copyright 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 | */ |
| 21 | |
| 22 | #ifndef _TYPES_ARG_H |
| 23 | #define _TYPES_ARG_H |
| 24 | |
| 25 | #include <sys/socket.h> |
| 26 | #include <netinet/in.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 27 | |
Willy Tarreau | c13ed53 | 2020-06-02 10:22:45 +0200 | [diff] [blame] | 28 | #include <haproxy/chunk.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 29 | #include <haproxy/list-t.h> |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 30 | |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 31 | #include <types/vars.h> |
Frédéric Lécaille | 3a463c9 | 2019-02-25 15:20:35 +0100 | [diff] [blame] | 32 | #include <types/protocol_buffers.h> |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 33 | #include <types/stick_table.h> |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 34 | |
Willy Tarreau | dbc79d0 | 2015-01-19 18:54:49 +0100 | [diff] [blame] | 35 | /* encoding of each arg type : up to 31 types are supported */ |
| 36 | #define ARGT_BITS 5 |
Willy Tarreau | 3d241e7 | 2015-01-19 18:44:07 +0100 | [diff] [blame] | 37 | #define ARGT_NBTYPES (1 << ARGT_BITS) |
| 38 | #define ARGT_MASK (ARGT_NBTYPES - 1) |
| 39 | |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 40 | /* encoding of the arg count : up to 12 args are possible. 4 bits are left |
Willy Tarreau | dbc79d0 | 2015-01-19 18:54:49 +0100 | [diff] [blame] | 41 | * unused at the top. |
| 42 | */ |
Willy Tarreau | 3d241e7 | 2015-01-19 18:44:07 +0100 | [diff] [blame] | 43 | #define ARGM_MASK ((1 << ARGM_BITS) - 1) |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 44 | #define ARGM_BITS 4 |
| 45 | #define ARGM_NBARGS (sizeof(uint64_t) * 8 - ARGM_BITS) / ARGT_BITS |
Willy Tarreau | 3d241e7 | 2015-01-19 18:44:07 +0100 | [diff] [blame] | 46 | |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 47 | enum { |
| 48 | ARGT_STOP = 0, /* end of the arg list */ |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 49 | ARGT_SINT, /* signed 64 bit integer. */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 50 | ARGT_STR, /* string */ |
| 51 | ARGT_IPV4, /* an IPv4 address */ |
| 52 | ARGT_MSK4, /* an IPv4 address mask (integer or dotted), stored as ARGT_IPV4 */ |
| 53 | ARGT_IPV6, /* an IPv6 address */ |
Tim Duesterhus | 92bb034 | 2018-01-25 16:24:47 +0100 | [diff] [blame] | 54 | ARGT_MSK6, /* an IPv6 address mask (integer or dotted), stored as ARGT_IPV6 */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 55 | ARGT_TIME, /* a delay in ms by default, stored as ARGT_UINT */ |
| 56 | ARGT_SIZE, /* a size in bytes by default, stored as ARGT_UINT */ |
| 57 | ARGT_FE, /* a pointer to a frontend only */ |
| 58 | ARGT_BE, /* a pointer to a backend only */ |
| 59 | ARGT_TAB, /* a pointer to a stick table */ |
| 60 | ARGT_SRV, /* a pointer to a server */ |
| 61 | ARGT_USR, /* a pointer to a user list */ |
Thierry FOURNIER | 4b5e422 | 2013-11-22 17:40:18 +0100 | [diff] [blame] | 62 | ARGT_MAP, /* a pointer to a map descriptor */ |
Willy Tarreau | 4694778 | 2015-01-19 19:00:58 +0100 | [diff] [blame] | 63 | ARGT_REG, /* a pointer to a regex */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 64 | ARGT_VAR, /* contains a variable description. */ |
Frédéric Lécaille | 3a463c9 | 2019-02-25 15:20:35 +0100 | [diff] [blame] | 65 | ARGT_PBUF_FNUM, /* a protocol buffer field number */ |
Willy Tarreau | f7ead61 | 2015-09-21 20:57:12 +0200 | [diff] [blame] | 66 | /* please update arg_type_names[] in args.c if you add entries here */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 69 | /* context where arguments are used, in order to help error reporting */ |
| 70 | enum { |
| 71 | ARGC_ACL = 0, /* ACL */ |
| 72 | ARGC_STK, /* sticking rule */ |
| 73 | ARGC_TRK, /* tracking rule */ |
| 74 | ARGC_LOG, /* log-format */ |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 75 | ARGC_LOGSD, /* log-format-sd */ |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 76 | ARGC_HRQ, /* http-request */ |
| 77 | ARGC_HRS, /* http-response */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 78 | ARGC_UIF, /* unique-id-format */ |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 79 | ARGC_RDR, /* redirect */ |
Willy Tarreau | 3a4ac42 | 2014-06-13 16:17:14 +0200 | [diff] [blame] | 80 | ARGC_CAP, /* capture rule */ |
Willy Tarreau | 28d976d | 2015-07-09 11:39:33 +0200 | [diff] [blame] | 81 | ARGC_SRV, /* server line */ |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 82 | ARGC_SPOE, /* spoe message args */ |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 83 | ARGC_UBK, /* use_backend message */ |
Jerome Magnin | 824186b | 2020-03-29 09:37:12 +0200 | [diff] [blame] | 84 | ARGC_USRV, /* use-server message */ |
Christopher Faulet | 3b967c1 | 2020-05-15 15:47:44 +0200 | [diff] [blame] | 85 | ARGC_HERR, /* http-error */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 86 | }; |
| 87 | |
Willy Tarreau | 4694778 | 2015-01-19 19:00:58 +0100 | [diff] [blame] | 88 | /* flags used when compiling and executing regex */ |
| 89 | #define ARGF_REG_ICASE 1 |
| 90 | #define ARGF_REG_GLOB 2 |
| 91 | |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 92 | /* some types that are externally defined */ |
| 93 | struct proxy; |
| 94 | struct server; |
| 95 | struct userlist; |
Willy Tarreau | 4694778 | 2015-01-19 19:00:58 +0100 | [diff] [blame] | 96 | struct my_regex; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 97 | |
| 98 | union arg_data { |
Thierry FOURNIER | bf65cd4 | 2015-07-20 17:45:02 +0200 | [diff] [blame] | 99 | long long int sint; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 100 | struct buffer str; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 101 | struct in_addr ipv4; |
| 102 | struct in6_addr ipv6; |
| 103 | struct proxy *prx; /* used for fe, be, tables */ |
| 104 | struct server *srv; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 105 | struct stktable *t; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 106 | struct userlist *usr; |
Thierry FOURNIER | 4b5e422 | 2013-11-22 17:40:18 +0100 | [diff] [blame] | 107 | struct map_descriptor *map; |
Willy Tarreau | 4694778 | 2015-01-19 19:00:58 +0100 | [diff] [blame] | 108 | struct my_regex *reg; |
Frédéric Lécaille | 3a463c9 | 2019-02-25 15:20:35 +0100 | [diff] [blame] | 109 | struct pbuf_fid fid; |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 110 | struct var_desc var; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct arg { |
Willy Tarreau | 496aa01 | 2012-06-01 10:38:29 +0200 | [diff] [blame] | 114 | unsigned char type; /* argument type, ARGT_* */ |
| 115 | unsigned char unresolved; /* argument contains a string in <str> that must be resolved and freed */ |
Willy Tarreau | 085dafa | 2015-01-21 15:51:47 +0100 | [diff] [blame] | 116 | unsigned char type_flags; /* type-specific extra flags (eg: case sensitivity for regex), ARGF_* */ |
Willy Tarreau | 496aa01 | 2012-06-01 10:38:29 +0200 | [diff] [blame] | 117 | union arg_data data; /* argument data */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 120 | /* arg lists are used to store information about arguments that could not be |
| 121 | * resolved when parsing the configuration. The head is an arg_list which |
| 122 | * serves as a template to create new entries. Nothing here is allocated, |
| 123 | * so plain copies are OK. |
| 124 | */ |
| 125 | struct arg_list { |
| 126 | struct list list; /* chaining with other arg_list, or list head */ |
| 127 | struct arg *arg; /* pointer to the arg, NULL on list head */ |
| 128 | int arg_pos; /* argument position */ |
| 129 | int ctx; /* context where the arg is used (ARGC_*) */ |
| 130 | const char *kw; /* keyword making use of these args */ |
| 131 | const char *conv; /* conv keyword when in conv, otherwise NULL */ |
| 132 | const char *file; /* file name where the args are referenced */ |
| 133 | int line; /* line number where the args are referenced */ |
| 134 | }; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 135 | |
| 136 | #endif /* _TYPES_ARG_H */ |
| 137 | |
| 138 | /* |
| 139 | * Local variables: |
| 140 | * c-indent-level: 8 |
| 141 | * c-basic-offset: 8 |
| 142 | * End: |
| 143 | */ |