Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1 | /* |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 2 | * Sample management functions. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 5 | * Copyright (C) 2012 Willy Tarreau <w@1wt.eu> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <string.h> |
| 15 | #include <arpa/inet.h> |
Willy Tarreau | dd2f85e | 2012-09-02 22:34:23 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 17 | |
Willy Tarreau | 7e2c647 | 2012-10-29 20:44:36 +0100 | [diff] [blame] | 18 | #include <types/global.h> |
| 19 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 20 | #include <common/chunk.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 21 | #include <common/standard.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 22 | #include <common/uri_auth.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 23 | |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 24 | #include <proto/arg.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 25 | #include <proto/auth.h> |
| 26 | #include <proto/log.h> |
| 27 | #include <proto/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 28 | #include <proto/sample.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 29 | #include <proto/stick_table.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 30 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 31 | /* static sample used in sample_process() when <p> is NULL */ |
Willy Tarreau | b4a88f0 | 2012-04-23 21:35:11 +0200 | [diff] [blame] | 32 | static struct sample temp_smp; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 33 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 34 | /* list head of all known sample fetch keywords */ |
| 35 | static struct sample_fetch_kw_list sample_fetches = { |
| 36 | .list = LIST_HEAD_INIT(sample_fetches.list) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 39 | /* list head of all known sample format conversion keywords */ |
| 40 | static struct sample_conv_kw_list sample_convs = { |
| 41 | .list = LIST_HEAD_INIT(sample_convs.list) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 44 | const unsigned int fetch_cap[SMP_SRC_ENTRIES] = { |
| 45 | [SMP_SRC_INTRN] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 46 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 47 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 48 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 49 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 50 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 51 | SMP_VAL_FE_LOG_END), |
| 52 | |
| 53 | [SMP_SRC_LISTN] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 54 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 55 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 56 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 57 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 58 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 59 | SMP_VAL_FE_LOG_END), |
| 60 | |
| 61 | [SMP_SRC_FTEND] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 62 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 63 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 64 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 65 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 66 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 67 | SMP_VAL_FE_LOG_END), |
| 68 | |
| 69 | [SMP_SRC_L4CLI] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 70 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 71 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 72 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 73 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 74 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 75 | SMP_VAL_FE_LOG_END), |
| 76 | |
| 77 | [SMP_SRC_L5CLI] = (SMP_VAL___________ | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 78 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 79 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 80 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 81 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 82 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 83 | SMP_VAL_FE_LOG_END), |
| 84 | |
| 85 | [SMP_SRC_TRACK] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 86 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 87 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 88 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 89 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 90 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 91 | SMP_VAL_FE_LOG_END), |
| 92 | |
| 93 | [SMP_SRC_L6REQ] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 94 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 95 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 96 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 97 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 98 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 99 | SMP_VAL___________), |
| 100 | |
| 101 | [SMP_SRC_HRQHV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 102 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 103 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 104 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 105 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 106 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 107 | SMP_VAL___________), |
| 108 | |
| 109 | [SMP_SRC_HRQHP] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 110 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 111 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 112 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 113 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 114 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 115 | SMP_VAL_FE_LOG_END), |
| 116 | |
| 117 | [SMP_SRC_HRQBO] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 118 | SMP_VAL___________ | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 119 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 120 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 121 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 122 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 123 | SMP_VAL___________), |
| 124 | |
| 125 | [SMP_SRC_BKEND] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 126 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 127 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 128 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 129 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 130 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 131 | SMP_VAL_FE_LOG_END), |
| 132 | |
| 133 | [SMP_SRC_SERVR] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 134 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 135 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 136 | SMP_VAL___________ | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 137 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 138 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 139 | SMP_VAL_FE_LOG_END), |
| 140 | |
| 141 | [SMP_SRC_L4SRV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 142 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 143 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 144 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 145 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 146 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 147 | SMP_VAL_FE_LOG_END), |
| 148 | |
| 149 | [SMP_SRC_L5SRV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 150 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 151 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 152 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 153 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 154 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 155 | SMP_VAL_FE_LOG_END), |
| 156 | |
| 157 | [SMP_SRC_L6RES] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 158 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 159 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 160 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 161 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 162 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 163 | SMP_VAL___________), |
| 164 | |
| 165 | [SMP_SRC_HRSHV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 166 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 167 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 168 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 169 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 170 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 171 | SMP_VAL___________), |
| 172 | |
| 173 | [SMP_SRC_HRSHP] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 174 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 175 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 176 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 177 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 178 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 179 | SMP_VAL_FE_LOG_END), |
| 180 | |
| 181 | [SMP_SRC_HRSBO] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 182 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 183 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 184 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 185 | SMP_VAL___________ | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 186 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 187 | SMP_VAL___________), |
| 188 | |
| 189 | [SMP_SRC_RQFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 190 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 191 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 192 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 193 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 194 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 195 | SMP_VAL_FE_LOG_END), |
| 196 | |
| 197 | [SMP_SRC_RSFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 198 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 199 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 200 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 201 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 202 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 203 | SMP_VAL_FE_LOG_END), |
| 204 | |
| 205 | [SMP_SRC_TXFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 206 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 207 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 208 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 209 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 210 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 211 | SMP_VAL_FE_LOG_END), |
| 212 | |
| 213 | [SMP_SRC_SSFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 214 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 215 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 216 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 217 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 218 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 219 | SMP_VAL_FE_LOG_END), |
| 220 | }; |
| 221 | |
| 222 | static const char *fetch_src_names[SMP_SRC_ENTRIES] = { |
| 223 | [SMP_SRC_INTRN] = "internal state", |
| 224 | [SMP_SRC_LISTN] = "listener", |
| 225 | [SMP_SRC_FTEND] = "frontend", |
| 226 | [SMP_SRC_L4CLI] = "client address", |
| 227 | [SMP_SRC_L5CLI] = "client-side connection", |
| 228 | [SMP_SRC_TRACK] = "track counters", |
| 229 | [SMP_SRC_L6REQ] = "request buffer", |
| 230 | [SMP_SRC_HRQHV] = "HTTP request headers", |
| 231 | [SMP_SRC_HRQHP] = "HTTP request", |
| 232 | [SMP_SRC_HRQBO] = "HTTP request body", |
| 233 | [SMP_SRC_BKEND] = "backend", |
| 234 | [SMP_SRC_SERVR] = "server", |
| 235 | [SMP_SRC_L4SRV] = "server address", |
| 236 | [SMP_SRC_L5SRV] = "server-side connection", |
| 237 | [SMP_SRC_L6RES] = "response buffer", |
| 238 | [SMP_SRC_HRSHV] = "HTTP response headers", |
| 239 | [SMP_SRC_HRSHP] = "HTTP response", |
| 240 | [SMP_SRC_HRSBO] = "HTTP response body", |
| 241 | [SMP_SRC_RQFIN] = "request buffer statistics", |
| 242 | [SMP_SRC_RSFIN] = "response buffer statistics", |
| 243 | [SMP_SRC_TXFIN] = "transaction statistics", |
| 244 | [SMP_SRC_SSFIN] = "session statistics", |
| 245 | }; |
| 246 | |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 247 | static const char *fetch_ckp_names[SMP_CKP_ENTRIES] = { |
| 248 | [SMP_CKP_FE_CON_ACC] = "frontend tcp-request connection rule", |
| 249 | [SMP_CKP_FE_SES_ACC] = "frontend tcp-request session rule", |
| 250 | [SMP_CKP_FE_REQ_CNT] = "frontend tcp-request content rule", |
| 251 | [SMP_CKP_FE_HRQ_HDR] = "frontend http-request header rule", |
| 252 | [SMP_CKP_FE_HRQ_BDY] = "frontend http-request body rule", |
| 253 | [SMP_CKP_FE_SET_BCK] = "frontend use-backend rule", |
| 254 | [SMP_CKP_BE_REQ_CNT] = "backend tcp-request content rule", |
| 255 | [SMP_CKP_BE_HRQ_HDR] = "backend http-request header rule", |
| 256 | [SMP_CKP_BE_HRQ_BDY] = "backend http-request body rule", |
| 257 | [SMP_CKP_BE_SET_SRV] = "backend use-server, balance or stick-match rule", |
| 258 | [SMP_CKP_BE_SRV_CON] = "server source selection", |
| 259 | [SMP_CKP_BE_RES_CNT] = "backend tcp-response content rule", |
| 260 | [SMP_CKP_BE_HRS_HDR] = "backend http-response header rule", |
| 261 | [SMP_CKP_BE_HRS_BDY] = "backend http-response body rule", |
| 262 | [SMP_CKP_BE_STO_RUL] = "backend stick-store rule", |
| 263 | [SMP_CKP_FE_RES_CNT] = "frontend tcp-response content rule", |
| 264 | [SMP_CKP_FE_HRS_HDR] = "frontend http-response header rule", |
| 265 | [SMP_CKP_FE_HRS_BDY] = "frontend http-response body rule", |
| 266 | [SMP_CKP_FE_LOG_END] = "logs", |
| 267 | }; |
| 268 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 269 | /* fill the trash with a comma-delimited list of source names for the <use> bit |
| 270 | * field which must be composed of a non-null set of SMP_USE_* flags. The return |
| 271 | * value is the pointer to the string in the trash buffer. |
| 272 | */ |
| 273 | const char *sample_src_names(unsigned int use) |
| 274 | { |
| 275 | int bit; |
| 276 | |
| 277 | trash.len = 0; |
| 278 | trash.str[0] = '\0'; |
| 279 | for (bit = 0; bit < SMP_SRC_ENTRIES; bit++) { |
| 280 | if (!(use & ~((1 << bit) - 1))) |
| 281 | break; /* no more bits */ |
| 282 | |
| 283 | if (!(use & (1 << bit))) |
| 284 | continue; /* bit not set */ |
| 285 | |
| 286 | trash.len += snprintf(trash.str + trash.len, trash.size - trash.len, "%s%s", |
| 287 | (use & ((1 << bit) - 1)) ? "," : "", |
| 288 | fetch_src_names[bit]); |
| 289 | } |
| 290 | return trash.str; |
| 291 | } |
| 292 | |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 293 | /* return a pointer to the correct sample checkpoint name, or "unknown" when |
| 294 | * the flags are invalid. Only the lowest bit is used, higher bits are ignored |
| 295 | * if set. |
| 296 | */ |
| 297 | const char *sample_ckp_names(unsigned int use) |
| 298 | { |
| 299 | int bit; |
| 300 | |
| 301 | for (bit = 0; bit < SMP_CKP_ENTRIES; bit++) |
| 302 | if (use & (1 << bit)) |
| 303 | return fetch_ckp_names[bit]; |
| 304 | return "unknown sample check place, please report this bug"; |
| 305 | } |
| 306 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 307 | /* |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 308 | * Registers the sample fetch keyword list <kwl> as a list of valid keywords |
| 309 | * for next parsing sessions. The fetch keywords capabilities are also computed |
| 310 | * from their ->use field. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 311 | */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 312 | void sample_register_fetches(struct sample_fetch_kw_list *kwl) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 313 | { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 314 | struct sample_fetch *sf; |
| 315 | int bit; |
| 316 | |
| 317 | for (sf = kwl->kw; sf->kw != NULL; sf++) { |
| 318 | for (bit = 0; bit < SMP_SRC_ENTRIES; bit++) |
| 319 | if (sf->use & (1 << bit)) |
| 320 | sf->val |= fetch_cap[bit]; |
| 321 | } |
| 322 | LIST_ADDQ(&sample_fetches.list, &kwl->list); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 326 | * Registers the sample format coverstion keyword list <pckl> as a list of valid keywords for next |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 327 | * parsing sessions. |
| 328 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 329 | void sample_register_convs(struct sample_conv_kw_list *pckl) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 330 | { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 331 | LIST_ADDQ(&sample_convs.list, &pckl->list); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 335 | * Returns the pointer on sample fetch keyword structure identified by |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 336 | * string of <len> in buffer <kw>. |
| 337 | * |
| 338 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 339 | struct sample_fetch *find_sample_fetch(const char *kw, int len) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 340 | { |
| 341 | int index; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 342 | struct sample_fetch_kw_list *kwl; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 343 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 344 | list_for_each_entry(kwl, &sample_fetches.list, list) { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 345 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 346 | if (strncmp(kwl->kw[index].kw, kw, len) == 0 && |
| 347 | kwl->kw[index].kw[len] == '\0') |
| 348 | return &kwl->kw[index]; |
| 349 | } |
| 350 | } |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 355 | * Returns the pointer on sample format conversion keyword structure identified by |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 356 | * string of <len> in buffer <kw>. |
| 357 | * |
| 358 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 359 | struct sample_conv *find_sample_conv(const char *kw, int len) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 360 | { |
| 361 | int index; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 362 | struct sample_conv_kw_list *kwl; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 363 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 364 | list_for_each_entry(kwl, &sample_convs.list, list) { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 365 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 366 | if (strncmp(kwl->kw[index].kw, kw, len) == 0 && |
| 367 | kwl->kw[index].kw[len] == '\0') |
| 368 | return &kwl->kw[index]; |
| 369 | } |
| 370 | } |
| 371 | return NULL; |
| 372 | } |
| 373 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 374 | /******************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 375 | /* Sample casts functions */ |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 376 | /* Note: these functions do *NOT* set the output type on the */ |
| 377 | /* sample, the caller is responsible for doing this on return. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 378 | /******************************************************************/ |
| 379 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 380 | static int c_ip2int(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 381 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 382 | smp->data.uint = ntohl(smp->data.ipv4.s_addr); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 383 | return 1; |
| 384 | } |
| 385 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 386 | static int c_ip2str(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 387 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 388 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 389 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 390 | if (!inet_ntop(AF_INET, (void *)&smp->data.ipv4, trash->str, trash->size)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 391 | return 0; |
| 392 | |
| 393 | trash->len = strlen(trash->str); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 394 | smp->data.str = *trash; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 395 | |
| 396 | return 1; |
| 397 | } |
| 398 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 399 | static int c_ip2ipv6(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 400 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 401 | v4tov6(&smp->data.ipv6, &smp->data.ipv4); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 402 | return 1; |
| 403 | } |
| 404 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 405 | static int c_ipv62str(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 406 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 407 | struct chunk *trash = get_trash_chunk(); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 408 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 409 | if (!inet_ntop(AF_INET6, (void *)&smp->data.ipv6, trash->str, trash->size)) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 410 | return 0; |
| 411 | |
| 412 | trash->len = strlen(trash->str); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 413 | smp->data.str = *trash; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 414 | return 1; |
| 415 | } |
| 416 | |
| 417 | /* |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 418 | static int c_ipv62ip(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 419 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 420 | return v6tov4(&smp->data.ipv4, &smp->data.ipv6); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 421 | } |
| 422 | */ |
| 423 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 424 | static int c_int2ip(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 425 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 426 | smp->data.ipv4.s_addr = htonl(smp->data.uint); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 427 | return 1; |
| 428 | } |
| 429 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 430 | static int c_str2ip(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 431 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 432 | if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 433 | return 0; |
| 434 | return 1; |
| 435 | } |
| 436 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 437 | static int c_str2ipv6(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 438 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 439 | return inet_pton(AF_INET6, smp->data.str.str, &smp->data.ipv6); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 442 | static int c_bin2str(struct sample *smp) |
| 443 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 444 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 445 | unsigned char c; |
| 446 | int ptr = 0; |
| 447 | |
| 448 | trash->len = 0; |
| 449 | while (ptr < smp->data.str.len && trash->len <= trash->size - 2) { |
| 450 | c = smp->data.str.str[ptr++]; |
| 451 | trash->str[trash->len++] = hextab[(c >> 4) & 0xF]; |
| 452 | trash->str[trash->len++] = hextab[c & 0xF]; |
| 453 | } |
| 454 | smp->data.str = *trash; |
| 455 | return 1; |
| 456 | } |
| 457 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 458 | static int c_int2str(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 459 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 460 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 461 | char *pos; |
| 462 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 463 | pos = ultoa_r(smp->data.uint, trash->str, trash->size); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 464 | |
| 465 | if (!pos) |
| 466 | return 0; |
| 467 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 468 | trash->size = trash->size - (pos - trash->str); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 469 | trash->str = pos; |
| 470 | trash->len = strlen(pos); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 471 | smp->data.str = *trash; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 472 | return 1; |
| 473 | } |
| 474 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 475 | static int c_datadup(struct sample *smp) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 476 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 477 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 478 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 479 | trash->len = smp->data.str.len < trash->size ? smp->data.str.len : trash->size; |
| 480 | memcpy(trash->str, smp->data.str.str, trash->len); |
| 481 | smp->data.str = *trash; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 482 | return 1; |
| 483 | } |
| 484 | |
| 485 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 486 | static int c_none(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 487 | { |
| 488 | return 1; |
| 489 | } |
| 490 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 491 | static int c_str2int(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 492 | { |
| 493 | int i; |
| 494 | uint32_t ret = 0; |
| 495 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 496 | for (i = 0; i < smp->data.str.len; i++) { |
| 497 | uint32_t val = smp->data.str.str[i] - '0'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 498 | |
| 499 | if (val > 9) |
| 500 | break; |
| 501 | |
| 502 | ret = ret * 10 + val; |
| 503 | } |
| 504 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 505 | smp->data.uint = ret; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | /*****************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 510 | /* Sample casts matrix: */ |
| 511 | /* sample_casts[from type][to type] */ |
| 512 | /* NULL pointer used for impossible sample casts */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 513 | /*****************************************************************/ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 514 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 515 | typedef int (*sample_cast_fct)(struct sample *smp); |
| 516 | static sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = { |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 517 | /* to: BOOL UINT SINT IPV4 IPV6 STR BIN CSTR CBIN */ |
Willy Tarreau | d167e6d | 2012-12-21 17:38:05 +0100 | [diff] [blame] | 518 | /* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, c_int2str, NULL, c_int2str, NULL }, |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 519 | /* UINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL }, |
| 520 | /* SINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL }, |
| 521 | /* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_ip2ipv6, c_ip2str, NULL, c_ip2str, NULL }, |
| 522 | /* IPV6 */ { NULL, NULL, NULL, NULL, c_none, c_ipv62str, NULL, c_ipv62str, NULL }, |
| 523 | /* STR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_none, c_none, c_none, c_none }, |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 524 | /* BIN */ { NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_bin2str, c_none }, |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 525 | /* CSTR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_datadup, c_datadup, c_none, c_none }, |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 526 | /* CBIN */ { NULL, NULL, NULL, NULL, NULL, c_bin2str, c_datadup, c_bin2str, c_none }, |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 527 | }; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 528 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 529 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 530 | * Parse a sample expression configuration: |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 531 | * fetch keyword followed by format conversion keywords. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 532 | * Returns a pointer on allocated sample expression structure. |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 533 | * The caller must have set al->ctx. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 534 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 535 | struct sample_expr *sample_parse_expr(char **str, int *idx, char *err, int err_size, struct arg_list *al) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 536 | { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 537 | const char *begw; /* beginning of word */ |
| 538 | const char *endw; /* end of word */ |
| 539 | const char *endt; /* end of term */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 540 | struct sample_expr *expr; |
| 541 | struct sample_fetch *fetch; |
| 542 | struct sample_conv *conv; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 543 | unsigned long prev_type; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 544 | char *fkw = NULL; |
| 545 | char *ckw = NULL; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 546 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 547 | /* prepare a generic message if any further snprintf() fails */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 548 | snprintf(err, err_size, "memory error."); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 549 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 550 | begw = str[*idx]; |
| 551 | for (endw = begw; *endw && *endw != '(' && *endw != ','; endw++); |
| 552 | |
| 553 | if (endw == begw) { |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 554 | snprintf(err, err_size, "missing fetch method."); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 555 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 556 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 557 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 558 | /* keep a copy of the current fetch keyword for error reporting */ |
| 559 | fkw = my_strndup(begw, endw - begw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 560 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 561 | fetch = find_sample_fetch(begw, endw - begw); |
| 562 | if (!fetch) { |
| 563 | snprintf(err, err_size, "unknown fetch method '%s'.", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 564 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 565 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 566 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 567 | endt = endw; |
| 568 | if (*endt == '(') { |
| 569 | /* look for the end of this term */ |
| 570 | while (*endt && *endt != ')') |
| 571 | endt++; |
| 572 | if (*endt != ')') { |
| 573 | snprintf(err, err_size, "syntax error: missing ')' after fetch keyword '%s'.", fkw); |
| 574 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 575 | } |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 576 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 577 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 578 | /* At this point, we have : |
| 579 | * - begw : beginning of the keyword |
| 580 | * - endw : end of the keyword (points to next delimiter or '(') |
| 581 | * - endt : end of the term (=endw or last parenthesis if args are present) |
| 582 | */ |
| 583 | |
| 584 | if (fetch->out_type >= SMP_TYPES) { |
| 585 | snprintf(err, err_size, "returns type of fetch method '%s' is unknown.", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 586 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 587 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 588 | prev_type = fetch->out_type; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 589 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 590 | expr = calloc(1, sizeof(struct sample_expr)); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 591 | if (!expr) |
| 592 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 593 | |
| 594 | LIST_INIT(&(expr->conv_exprs)); |
| 595 | expr->fetch = fetch; |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 596 | expr->arg_p = empty_arg_list; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 597 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 598 | if (endt != endw) { |
Willy Tarreau | b27c0d3 | 2012-04-20 16:04:47 +0200 | [diff] [blame] | 599 | char *err_msg = NULL; |
| 600 | int err_arg; |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 601 | |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 602 | if (!fetch->arg_mask) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 603 | snprintf(err, err_size, "fetch method '%s' does not support any args.", fkw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 604 | goto out_error; |
| 605 | } |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 606 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 607 | al->kw = expr->fetch->kw; |
| 608 | al->conv = NULL; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 609 | if (make_arg_list(endw + 1, endt - endw - 1, fetch->arg_mask, &expr->arg_p, &err_msg, NULL, &err_arg, al) < 0) { |
| 610 | snprintf(err, err_size, "invalid arg %d in fetch method '%s' : %s.", err_arg+1, fkw, err_msg); |
Willy Tarreau | b27c0d3 | 2012-04-20 16:04:47 +0200 | [diff] [blame] | 611 | free(err_msg); |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 612 | goto out_error; |
| 613 | } |
| 614 | |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 615 | if (!expr->arg_p) |
| 616 | expr->arg_p = empty_arg_list; |
| 617 | |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 618 | if (fetch->val_args && !fetch->val_args(expr->arg_p, &err_msg)) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 619 | snprintf(err, err_size, "invalid args in fetch method '%s' : %s.", fkw, err_msg); |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 620 | free(err_msg); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 621 | goto out_error; |
| 622 | } |
| 623 | } |
Willy Tarreau | f22a508 | 2012-10-19 16:47:23 +0200 | [diff] [blame] | 624 | else if (ARGM(fetch->arg_mask)) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 625 | snprintf(err, err_size, "missing args for fetch method '%s'.", fkw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 626 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 627 | } |
| 628 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 629 | /* Now process the converters if any. We have two supported syntaxes |
| 630 | * for the converters, which can be combined : |
| 631 | * - comma-delimited list of converters just after the keyword and args ; |
| 632 | * - one converter per keyword |
| 633 | * The combination allows to have each keyword being a comma-delimited |
| 634 | * series of converters. |
| 635 | * |
| 636 | * We want to process the former first, then the latter. For this we start |
| 637 | * from the beginning of the supposed place in the exiting conv chain, which |
| 638 | * starts at the last comma (endt). |
| 639 | */ |
| 640 | |
| 641 | while (1) { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 642 | struct sample_conv_expr *conv_expr; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 643 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 644 | if (*endt == ')') /* skip last closing parenthesis */ |
| 645 | endt++; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 646 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 647 | if (*endt && *endt != ',') { |
| 648 | if (ckw) |
| 649 | snprintf(err, err_size, "missing comma after conv keyword '%s'.", ckw); |
| 650 | else |
| 651 | snprintf(err, err_size, "missing comma after fetch keyword '%s'.", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 652 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 653 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 654 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 655 | while (*endt == ',') /* then trailing commas */ |
| 656 | endt++; |
| 657 | |
| 658 | begw = endt; /* start of conv keyword */ |
| 659 | |
| 660 | if (!*begw) { |
| 661 | /* none ? skip to next string */ |
| 662 | (*idx)++; |
| 663 | begw = str[*idx]; |
| 664 | if (!begw || !*begw) |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | for (endw = begw; *endw && *endw != '(' && *endw != ','; endw++); |
| 669 | |
| 670 | free(ckw); |
| 671 | ckw = my_strndup(begw, endw - begw); |
| 672 | |
| 673 | conv = find_sample_conv(begw, endw - begw); |
| 674 | if (!conv) { |
| 675 | /* we found an isolated keyword that we don't know, it's not ours */ |
| 676 | if (begw == str[*idx]) |
| 677 | break; |
| 678 | snprintf(err, err_size, "unknown conv method '%s'.", ckw); |
| 679 | goto out_error; |
| 680 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 681 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 682 | endt = endw; |
| 683 | if (*endt == '(') { |
| 684 | /* look for the end of this term */ |
| 685 | while (*endt && *endt != ')') |
| 686 | endt++; |
| 687 | if (*endt != ')') { |
| 688 | snprintf(err, err_size, "syntax error: missing ')' after conv keyword '%s'.", ckw); |
| 689 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 690 | } |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | if (conv->in_type >= SMP_TYPES || conv->out_type >= SMP_TYPES) { |
| 694 | snprintf(err, err_size, "returns type of conv method '%s' is unknown.", ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 695 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 696 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 697 | |
| 698 | /* If impossible type conversion */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 699 | if (!sample_casts[prev_type][conv->in_type]) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 700 | snprintf(err, err_size, "conv method '%s' cannot be applied.", ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 701 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 702 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 703 | |
| 704 | prev_type = conv->out_type; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 705 | conv_expr = calloc(1, sizeof(struct sample_conv_expr)); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 706 | if (!conv_expr) |
| 707 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 708 | |
| 709 | LIST_ADDQ(&(expr->conv_exprs), &(conv_expr->list)); |
| 710 | conv_expr->conv = conv; |
| 711 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 712 | if (endt != endw) { |
Willy Tarreau | b27c0d3 | 2012-04-20 16:04:47 +0200 | [diff] [blame] | 713 | char *err_msg = NULL; |
| 714 | int err_arg; |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 715 | |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 716 | if (!conv->arg_mask) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 717 | snprintf(err, err_size, "conv method '%s' does not support any args.", ckw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 718 | goto out_error; |
| 719 | } |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 720 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 721 | al->kw = expr->fetch->kw; |
| 722 | al->conv = conv_expr->conv->kw; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 723 | if (make_arg_list(endw + 1, endt - endw - 1, conv->arg_mask, &conv_expr->arg_p, &err_msg, NULL, &err_arg, al) < 0) { |
| 724 | snprintf(err, err_size, "invalid arg %d in conv method '%s' : %s.", err_arg+1, ckw, err_msg); |
Willy Tarreau | b27c0d3 | 2012-04-20 16:04:47 +0200 | [diff] [blame] | 725 | free(err_msg); |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 726 | goto out_error; |
| 727 | } |
| 728 | |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 729 | if (!conv_expr->arg_p) |
| 730 | conv_expr->arg_p = empty_arg_list; |
| 731 | |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 732 | if (conv->val_args && !conv->val_args(conv_expr->arg_p, &err_msg)) { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 733 | snprintf(err, err_size, "invalid args in conv method '%s' : %s.", ckw, err_msg); |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 734 | free(err_msg); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 735 | goto out_error; |
| 736 | } |
| 737 | } |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 738 | else if (ARGM(conv->arg_mask)) { |
| 739 | snprintf(err, err_size, "missing args for conv method '%s'.", ckw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 740 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 741 | } |
| 742 | } |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 743 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 744 | out: |
| 745 | free(fkw); |
| 746 | free(ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 747 | return expr; |
| 748 | |
| 749 | out_error: |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 750 | /* TODO: prune_sample_expr(expr); */ |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 751 | expr = NULL; |
| 752 | goto out; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 756 | * Process a fetch + format conversion of defined by the sample expression <expr> |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 757 | * on request or response considering the <opt> parameter. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 758 | * Returns a pointer on a typed sample structure containing the result or NULL if |
| 759 | * sample is not found or when format conversion failed. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 760 | * If <p> is not null, function returns results in structure pointed by <p>. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 761 | * If <p> is null, functions returns a pointer on a static sample structure. |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 762 | * |
| 763 | * Note: the fetch functions are required to properly set the return type. The |
| 764 | * conversion functions must do so too. However the cast functions do not need |
| 765 | * to since they're made to cast mutiple types according to what is required. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 766 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 767 | struct sample *sample_process(struct proxy *px, struct session *l4, void *l7, |
| 768 | unsigned int opt, |
| 769 | struct sample_expr *expr, struct sample *p) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 770 | { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 771 | struct sample_conv_expr *conv_expr; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 772 | |
Willy Tarreau | 18387e2 | 2013-07-25 12:02:38 +0200 | [diff] [blame] | 773 | if (p == NULL) { |
Willy Tarreau | b4a88f0 | 2012-04-23 21:35:11 +0200 | [diff] [blame] | 774 | p = &temp_smp; |
Willy Tarreau | 18387e2 | 2013-07-25 12:02:38 +0200 | [diff] [blame] | 775 | p->flags = 0; |
| 776 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 777 | |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame^] | 778 | if (!expr->fetch->process(px, l4, l7, opt, expr->arg_p, p, expr->fetch->kw)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 779 | return NULL; |
| 780 | |
Willy Tarreau | 18387e2 | 2013-07-25 12:02:38 +0200 | [diff] [blame] | 781 | if ((p->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 782 | return NULL; /* we can only use stable samples */ |
Willy Tarreau | 40aebd9 | 2012-04-26 11:05:50 +0200 | [diff] [blame] | 783 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 784 | list_for_each_entry(conv_expr, &expr->conv_exprs, list) { |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 785 | /* we want to ensure that p->type can be casted into |
| 786 | * conv_expr->conv->in_type. We have 3 possibilities : |
| 787 | * - NULL => not castable. |
| 788 | * - c_none => nothing to do (let's optimize it) |
| 789 | * - other => apply cast and prepare to fail |
| 790 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 791 | if (!sample_casts[p->type][conv_expr->conv->in_type]) |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 792 | return NULL; |
| 793 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 794 | if (sample_casts[p->type][conv_expr->conv->in_type] != c_none && |
| 795 | !sample_casts[p->type][conv_expr->conv->in_type](p)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 796 | return NULL; |
| 797 | |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 798 | /* OK cast succeeded */ |
| 799 | |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 800 | /* force the output type after a cast */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 801 | p->type = conv_expr->conv->in_type; |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 802 | if (!conv_expr->conv->process(conv_expr->arg_p, p)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 803 | return NULL; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 804 | } |
| 805 | return p; |
| 806 | } |
| 807 | |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 808 | /* |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 809 | * Resolve all remaining arguments in proxy <p>. Returns the number of |
| 810 | * errors or 0 if everything is fine. |
| 811 | */ |
| 812 | int smp_resolve_args(struct proxy *p) |
| 813 | { |
| 814 | struct arg_list *cur, *bak; |
| 815 | const char *ctx, *where; |
| 816 | const char *conv_ctx, *conv_pre, *conv_pos; |
| 817 | struct userlist *ul; |
| 818 | struct arg *arg; |
| 819 | int cfgerr = 0; |
| 820 | |
| 821 | list_for_each_entry_safe(cur, bak, &p->conf.args.list, list) { |
| 822 | struct proxy *px; |
| 823 | struct server *srv; |
| 824 | char *pname, *sname; |
| 825 | |
| 826 | arg = cur->arg; |
| 827 | |
| 828 | /* prepare output messages */ |
| 829 | conv_pre = conv_pos = conv_ctx = ""; |
| 830 | if (cur->conv) { |
| 831 | conv_ctx = cur->conv; |
| 832 | conv_pre = "conversion keyword '"; |
| 833 | conv_pos = "' for "; |
| 834 | } |
| 835 | |
| 836 | where = "in"; |
| 837 | ctx = "sample fetch keyword"; |
| 838 | switch (cur->ctx) { |
| 839 | case ARGC_STK:where = "in stick rule in"; break; |
| 840 | case ARGC_TRK: where = "in tracking rule in"; break; |
| 841 | case ARGC_LOG: where = "in log-format string in"; break; |
| 842 | case ARGC_HDR: where = "in HTTP header format string in"; break; |
| 843 | case ARGC_UIF: where = "in unique-id-format string in"; break; |
| 844 | case ARGC_ACL: ctx = "ACL keyword"; break; |
| 845 | } |
| 846 | |
| 847 | /* set a few default settings */ |
| 848 | px = p; |
| 849 | pname = p->id; |
| 850 | |
| 851 | switch (arg->type) { |
| 852 | case ARGT_SRV: |
| 853 | if (!arg->data.str.len) { |
| 854 | Alert("parsing [%s:%d] : missing server name in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 855 | cur->file, cur->line, |
| 856 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 857 | cfgerr++; |
| 858 | continue; |
| 859 | } |
| 860 | |
| 861 | /* we support two formats : "bck/srv" and "srv" */ |
| 862 | sname = strrchr(arg->data.str.str, '/'); |
| 863 | |
| 864 | if (sname) { |
| 865 | *sname++ = '\0'; |
| 866 | pname = arg->data.str.str; |
| 867 | |
| 868 | px = findproxy(pname, PR_CAP_BE); |
| 869 | if (!px) { |
| 870 | Alert("parsing [%s:%d] : unable to find proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 871 | cur->file, cur->line, pname, |
| 872 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 873 | cfgerr++; |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | else |
| 878 | sname = arg->data.str.str; |
| 879 | |
| 880 | srv = findserver(px, sname); |
| 881 | if (!srv) { |
| 882 | Alert("parsing [%s:%d] : unable to find server '%s' in proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 883 | cur->file, cur->line, sname, pname, |
| 884 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 885 | cfgerr++; |
| 886 | break; |
| 887 | } |
| 888 | |
| 889 | free(arg->data.str.str); |
| 890 | arg->data.str.str = NULL; |
| 891 | arg->unresolved = 0; |
| 892 | arg->data.srv = srv; |
| 893 | break; |
| 894 | |
| 895 | case ARGT_FE: |
| 896 | if (arg->data.str.len) { |
| 897 | pname = arg->data.str.str; |
| 898 | px = findproxy(pname, PR_CAP_FE); |
| 899 | } |
| 900 | |
| 901 | if (!px) { |
| 902 | Alert("parsing [%s:%d] : unable to find frontend '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 903 | cur->file, cur->line, pname, |
| 904 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 905 | cfgerr++; |
| 906 | break; |
| 907 | } |
| 908 | |
| 909 | if (!(px->cap & PR_CAP_FE)) { |
| 910 | Alert("parsing [%s:%d] : proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s', has not frontend capability.\n", |
| 911 | cur->file, cur->line, pname, |
| 912 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 913 | cfgerr++; |
| 914 | break; |
| 915 | } |
| 916 | |
| 917 | free(arg->data.str.str); |
| 918 | arg->data.str.str = NULL; |
| 919 | arg->unresolved = 0; |
| 920 | arg->data.prx = px; |
| 921 | break; |
| 922 | |
| 923 | case ARGT_BE: |
| 924 | if (arg->data.str.len) { |
| 925 | pname = arg->data.str.str; |
| 926 | px = findproxy(pname, PR_CAP_BE); |
| 927 | } |
| 928 | |
| 929 | if (!px) { |
| 930 | Alert("parsing [%s:%d] : unable to find backend '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 931 | cur->file, cur->line, pname, |
| 932 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 933 | cfgerr++; |
| 934 | break; |
| 935 | } |
| 936 | |
| 937 | if (!(px->cap & PR_CAP_BE)) { |
| 938 | Alert("parsing [%s:%d] : proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s', has not backend capability.\n", |
| 939 | cur->file, cur->line, pname, |
| 940 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 941 | cfgerr++; |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | free(arg->data.str.str); |
| 946 | arg->data.str.str = NULL; |
| 947 | arg->unresolved = 0; |
| 948 | arg->data.prx = px; |
| 949 | break; |
| 950 | |
| 951 | case ARGT_TAB: |
| 952 | if (arg->data.str.len) { |
| 953 | pname = arg->data.str.str; |
| 954 | px = find_stktable(pname); |
| 955 | } |
| 956 | |
| 957 | if (!px) { |
| 958 | Alert("parsing [%s:%d] : unable to find table '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 959 | cur->file, cur->line, pname, |
| 960 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 961 | cfgerr++; |
| 962 | break; |
| 963 | } |
| 964 | |
| 965 | if (!px->table.size) { |
| 966 | Alert("parsing [%s:%d] : no table in proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 967 | cur->file, cur->line, pname, |
| 968 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 969 | cfgerr++; |
| 970 | break; |
| 971 | } |
| 972 | |
| 973 | free(arg->data.str.str); |
| 974 | arg->data.str.str = NULL; |
| 975 | arg->unresolved = 0; |
| 976 | arg->data.prx = px; |
| 977 | break; |
| 978 | |
| 979 | case ARGT_USR: |
| 980 | if (!arg->data.str.len) { |
| 981 | Alert("parsing [%s:%d] : missing userlist name in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 982 | cur->file, cur->line, |
| 983 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 984 | cfgerr++; |
| 985 | break; |
| 986 | } |
| 987 | |
| 988 | if (p->uri_auth && p->uri_auth->userlist && |
| 989 | !strcmp(p->uri_auth->userlist->name, arg->data.str.str)) |
| 990 | ul = p->uri_auth->userlist; |
| 991 | else |
| 992 | ul = auth_find_userlist(arg->data.str.str); |
| 993 | |
| 994 | if (!ul) { |
| 995 | Alert("parsing [%s:%d] : unable to find userlist '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 996 | cur->file, cur->line, arg->data.str.str, |
| 997 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 998 | cfgerr++; |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | free(arg->data.str.str); |
| 1003 | arg->data.str.str = NULL; |
| 1004 | arg->unresolved = 0; |
| 1005 | arg->data.usr = ul; |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | LIST_DEL(&cur->list); |
| 1010 | free(cur); |
| 1011 | } /* end of args processing */ |
| 1012 | |
| 1013 | return cfgerr; |
| 1014 | } |
| 1015 | |
| 1016 | /* |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1017 | * Process a fetch + format conversion as defined by the sample expression <expr> |
| 1018 | * on request or response considering the <opt> parameter. The output is always of |
| 1019 | * type string. Returns either NULL if no sample could be extracted, or a pointer |
| 1020 | * to the converted result stored in static temp_smp in format string. |
| 1021 | */ |
| 1022 | struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l7, |
| 1023 | unsigned int opt, struct sample_expr *expr) |
| 1024 | { |
| 1025 | struct sample *smp; |
| 1026 | |
| 1027 | smp = sample_process(px, l4, l7, opt, expr, NULL); |
| 1028 | if (!smp) |
| 1029 | return NULL; |
| 1030 | |
| 1031 | if (!sample_casts[smp->type][SMP_T_CSTR]) |
| 1032 | return NULL; |
| 1033 | |
| 1034 | if (!sample_casts[smp->type][SMP_T_CSTR](smp)) |
| 1035 | return NULL; |
| 1036 | |
| 1037 | smp->type = SMP_T_CSTR; |
| 1038 | return smp; |
| 1039 | } |
| 1040 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1041 | /*****************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1042 | /* Sample format convert functions */ |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1043 | /* These functions set the data type on return. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1044 | /*****************************************************************/ |
| 1045 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1046 | static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1047 | { |
| 1048 | int i; |
| 1049 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1050 | if (!smp->data.str.size) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1051 | return 0; |
| 1052 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1053 | for (i = 0; i < smp->data.str.len; i++) { |
| 1054 | if ((smp->data.str.str[i] >= 'A') && (smp->data.str.str[i] <= 'Z')) |
| 1055 | smp->data.str.str[i] += 'a' - 'A'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1056 | } |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1057 | smp->type = SMP_T_STR; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1058 | return 1; |
| 1059 | } |
| 1060 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1061 | static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1062 | { |
| 1063 | int i; |
| 1064 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1065 | if (!smp->data.str.size) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1066 | return 0; |
| 1067 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1068 | for (i = 0; i < smp->data.str.len; i++) { |
| 1069 | if ((smp->data.str.str[i] >= 'a') && (smp->data.str.str[i] <= 'z')) |
| 1070 | smp->data.str.str[i] += 'A' - 'a'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1071 | } |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1072 | smp->type = SMP_T_STR; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1073 | return 1; |
| 1074 | } |
| 1075 | |
Willy Tarreau | f995410 | 2012-04-20 14:03:29 +0200 | [diff] [blame] | 1076 | /* takes the netmask in arg_p */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1077 | static int sample_conv_ipmask(const struct arg *arg_p, struct sample *smp) |
Willy Tarreau | d31d6eb | 2010-01-26 18:01:41 +0100 | [diff] [blame] | 1078 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1079 | smp->data.ipv4.s_addr &= arg_p->data.ipv4.s_addr; |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1080 | smp->type = SMP_T_IPV4; |
Willy Tarreau | d31d6eb | 2010-01-26 18:01:41 +0100 | [diff] [blame] | 1081 | return 1; |
| 1082 | } |
| 1083 | |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1084 | /************************************************************************/ |
| 1085 | /* All supported sample fetch functions must be declared here */ |
| 1086 | /************************************************************************/ |
| 1087 | |
| 1088 | /* force TRUE to be returned at the fetch level */ |
| 1089 | static int |
| 1090 | smp_fetch_true(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame^] | 1091 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1092 | { |
| 1093 | smp->type = SMP_T_BOOL; |
| 1094 | smp->data.uint = 1; |
| 1095 | return 1; |
| 1096 | } |
| 1097 | |
| 1098 | /* force FALSE to be returned at the fetch level */ |
| 1099 | static int |
| 1100 | smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame^] | 1101 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1102 | { |
| 1103 | smp->type = SMP_T_BOOL; |
| 1104 | smp->data.uint = 0; |
| 1105 | return 1; |
| 1106 | } |
| 1107 | |
| 1108 | /* retrieve environment variable $1 as a string */ |
| 1109 | static int |
| 1110 | smp_fetch_env(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame^] | 1111 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1112 | { |
| 1113 | char *env; |
| 1114 | |
| 1115 | if (!args || args[0].type != ARGT_STR) |
| 1116 | return 0; |
| 1117 | |
| 1118 | env = getenv(args[0].data.str.str); |
| 1119 | if (!env) |
| 1120 | return 0; |
| 1121 | |
| 1122 | smp->type = SMP_T_CSTR; |
| 1123 | smp->data.str.str = env; |
| 1124 | smp->data.str.len = strlen(env); |
| 1125 | return 1; |
| 1126 | } |
| 1127 | |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1128 | /* retrieve the current local date in epoch time, and applies an optional offset |
| 1129 | * of args[0] seconds. |
| 1130 | */ |
| 1131 | static int |
| 1132 | smp_fetch_date(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame^] | 1133 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1134 | { |
| 1135 | smp->data.uint = date.tv_sec; |
| 1136 | |
| 1137 | /* add offset */ |
| 1138 | if (args && (args[0].type == ARGT_SINT || args[0].type == ARGT_UINT)) |
| 1139 | smp->data.uint += args[0].data.sint; |
| 1140 | |
| 1141 | smp->type = SMP_T_UINT; |
| 1142 | smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE; |
| 1143 | return 1; |
| 1144 | } |
| 1145 | |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1146 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1147 | * Note: fetches that may return multiple types must be declared as the lowest |
| 1148 | * common denominator, the type that can be casted into all other ones. For |
| 1149 | * instance IPv4/IPv6 must be declared IPv4. |
| 1150 | */ |
| 1151 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
| 1152 | { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, |
| 1153 | { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, |
| 1154 | { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN }, |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1155 | { "date", smp_fetch_date, ARG1(0,SINT), NULL, SMP_T_UINT, SMP_USE_INTRN }, |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1156 | { /* END */ }, |
| 1157 | }}; |
| 1158 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1159 | /* Note: must not be declared <const> as its list will be overwritten */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 1160 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1161 | { "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, |
| 1162 | { "lower", sample_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR }, |
| 1163 | { "ipmask", sample_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 }, |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 1164 | { NULL, NULL, 0, 0, 0 }, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1165 | }}; |
| 1166 | |
| 1167 | __attribute__((constructor)) |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1168 | static void __sample_init(void) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1169 | { |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1170 | /* register sample fetch and format conversion keywords */ |
| 1171 | sample_register_fetches(&smp_kws); |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1172 | sample_register_convs(&sample_conv_kws); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1173 | } |