Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/proto/acl.h |
| 3 | This file provides interface definitions for ACL manipulation. |
| 4 | |
| 5 | Copyright (C) 2000-2007 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 _PROTO_ACL_H |
| 23 | #define _PROTO_ACL_H |
| 24 | |
| 25 | #include <common/config.h> |
| 26 | #include <types/acl.h> |
| 27 | |
| 28 | /* |
| 29 | * FIXME: we need destructor functions too ! |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | /* Return a pointer to the ACL <name> within the list starting at <head>, or |
| 34 | * NULL if not found. |
| 35 | */ |
| 36 | struct acl *find_acl_by_name(const char *name, struct list *head); |
| 37 | |
| 38 | /* Return a pointer to the ACL keyword <kw> within the list starting at <head>, |
| 39 | * or NULL if not found. Note that if <kw> contains an opening parenthesis, |
| 40 | * only the left part of it is checked. |
| 41 | */ |
| 42 | struct acl_keyword *find_acl_kw(const char *kw); |
| 43 | |
| 44 | /* Parse an ACL expression starting at <args>[0], and return it. |
| 45 | * Right now, the only accepted syntax is : |
| 46 | * <subject> [<value>...] |
| 47 | */ |
| 48 | struct acl_expr *parse_acl_expr(const char **args); |
| 49 | |
| 50 | /* Parse an ACL with the name starting at <args>[0], and with a list of already |
| 51 | * known ACLs in <acl>. If the ACL was not in the list, it will be added. |
| 52 | * A pointer to that ACL is returned. |
| 53 | * |
| 54 | * args syntax: <aclname> <acl_expr> |
| 55 | */ |
| 56 | struct acl *parse_acl(const char **args, struct list *known_acl); |
| 57 | |
| 58 | /* Purge everything in the acl_cond <cond>, then return <cond>. */ |
| 59 | struct acl_cond *prune_acl_cond(struct acl_cond *cond); |
| 60 | |
| 61 | /* Parse an ACL condition starting at <args>[0], relying on a list of already |
| 62 | * known ACLs passed in <known_acl>. The new condition is returned (or NULL in |
| 63 | * case of low memory). Supports multiple conditions separated by "or". |
| 64 | */ |
| 65 | struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl, int pol); |
| 66 | |
| 67 | /* Execute condition <cond> and return 0 if test fails or 1 if test succeeds. |
| 68 | * This function only computes the condition, it does not apply the polarity |
| 69 | * required by IF/UNLESS, it's up to the caller to do this. |
| 70 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 71 | int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, int dir); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 72 | |
| 73 | /* Return a pointer to the ACL <name> within the list starting at <head>, or |
| 74 | * NULL if not found. |
| 75 | */ |
| 76 | struct acl *find_acl_by_name(const char *name, struct list *head); |
| 77 | |
| 78 | /* |
| 79 | * Registers the ACL keyword list <kwl> as a list of valid keywords for next |
| 80 | * parsing sessions. |
| 81 | */ |
| 82 | void acl_register_keywords(struct acl_kw_list *kwl); |
| 83 | |
| 84 | /* |
| 85 | * Unregisters the ACL keyword list <kwl> from the list of valid keywords. |
| 86 | */ |
| 87 | void acl_unregister_keywords(struct acl_kw_list *kwl); |
| 88 | |
| 89 | |
| 90 | /* |
| 91 | * |
| 92 | * The following functions are general purpose ACL matching functions. |
| 93 | * |
| 94 | */ |
| 95 | |
| 96 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 97 | /* NB: For two strings to be identical, it is required that their lengths match */ |
| 98 | int acl_match_str(struct acl_test *test, struct acl_pattern *pattern); |
| 99 | |
| 100 | /* Checks that the integer in <test> is included between min and max */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 101 | int acl_match_int(struct acl_test *test, struct acl_pattern *pattern); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 102 | |
| 103 | /* Parse an integer. It is put both in min and max. */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 104 | int acl_parse_int(const char **text, struct acl_pattern *pattern, int *opaque); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 105 | |
| 106 | /* Parse a range of integers delimited by either ':' or '-'. If only one |
| 107 | * integer is read, it is set as both min and max. |
| 108 | */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 109 | int acl_parse_range(const char **text, struct acl_pattern *pattern, int *opaque); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 110 | |
| 111 | /* Parse a string. It is allocated and duplicated. */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 112 | int acl_parse_str(const char **text, struct acl_pattern *pattern, int *opaque); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 113 | |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 114 | /* Parse a regex. It is allocated. */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 115 | int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque); |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 116 | |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 117 | /* Parse an IP address and an optional mask in the form addr[/mask]. |
| 118 | * The addr may either be an IPv4 address or a hostname. The mask |
| 119 | * may either be a dotted mask or a number of bits. Returns 1 if OK, |
| 120 | * otherwise 0. |
| 121 | */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 122 | int acl_parse_ip(const char **text, struct acl_pattern *pattern, int *opaque); |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 123 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 124 | /* Checks that the pattern matches the end of the tested string. */ |
| 125 | int acl_match_end(struct acl_test *test, struct acl_pattern *pattern); |
| 126 | |
| 127 | /* Checks that the pattern matches the beginning of the tested string. */ |
| 128 | int acl_match_beg(struct acl_test *test, struct acl_pattern *pattern); |
| 129 | |
| 130 | /* Checks that the pattern is included inside the tested string. */ |
| 131 | int acl_match_sub(struct acl_test *test, struct acl_pattern *pattern); |
| 132 | |
| 133 | /* Checks that the pattern is included inside the tested string, but enclosed |
| 134 | * between slashes or at the beginning or end of the string. Slashes at the |
| 135 | * beginning or end of the pattern are ignored. |
| 136 | */ |
| 137 | int acl_match_dir(struct acl_test *test, struct acl_pattern *pattern); |
| 138 | |
| 139 | /* Checks that the pattern is included inside the tested string, but enclosed |
| 140 | * between dots or at the beginning or end of the string. Dots at the beginning |
| 141 | * or end of the pattern are ignored. |
| 142 | */ |
| 143 | int acl_match_dom(struct acl_test *test, struct acl_pattern *pattern); |
| 144 | |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 145 | /* Check that the IPv4 address in <test> matches the IP/mask in pattern */ |
| 146 | int acl_match_ip(struct acl_test *test, struct acl_pattern *pattern); |
| 147 | |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 148 | /* Executes a regex. It needs to change the data. If it is marked READ_ONLY |
| 149 | * then it will be allocated and duplicated in place so that others may use |
| 150 | * it later on. Note that this is embarrassing because we always try to avoid |
| 151 | * allocating memory at run time. |
| 152 | */ |
| 153 | int acl_match_reg(struct acl_test *test, struct acl_pattern *pattern); |
| 154 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 155 | #endif /* _PROTO_ACL_H */ |
| 156 | |
| 157 | /* |
| 158 | * Local variables: |
| 159 | * c-indent-level: 8 |
| 160 | * c-basic-offset: 8 |
| 161 | * End: |
| 162 | */ |