paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Route map function. |
| 2 | * Copyright (C) 1998 Kunihiro Ishiguro |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef _ZEBRA_ROUTEMAP_H |
| 23 | #define _ZEBRA_ROUTEMAP_H |
| 24 | |
| 25 | /* Route map's type. */ |
| 26 | enum route_map_type |
| 27 | { |
| 28 | RMAP_PERMIT, |
| 29 | RMAP_DENY, |
| 30 | RMAP_ANY |
| 31 | }; |
| 32 | |
| 33 | typedef enum |
| 34 | { |
| 35 | RMAP_MATCH, |
| 36 | RMAP_DENYMATCH, |
| 37 | RMAP_NOMATCH, |
| 38 | RMAP_ERROR, |
| 39 | RMAP_OKAY |
| 40 | } route_map_result_t; |
| 41 | |
| 42 | typedef enum |
| 43 | { |
| 44 | RMAP_RIP, |
| 45 | RMAP_RIPNG, |
| 46 | RMAP_OSPF, |
| 47 | RMAP_OSPF6, |
| 48 | RMAP_BGP |
| 49 | } route_map_object_t; |
| 50 | |
| 51 | typedef enum |
| 52 | { |
| 53 | RMAP_EXIT, |
| 54 | RMAP_GOTO, |
| 55 | RMAP_NEXT |
| 56 | } route_map_end_t; |
| 57 | |
| 58 | typedef enum |
| 59 | { |
| 60 | RMAP_EVENT_SET_ADDED, |
| 61 | RMAP_EVENT_SET_DELETED, |
| 62 | RMAP_EVENT_SET_REPLACED, |
| 63 | RMAP_EVENT_MATCH_ADDED, |
| 64 | RMAP_EVENT_MATCH_DELETED, |
| 65 | RMAP_EVENT_MATCH_REPLACED, |
| 66 | RMAP_EVENT_INDEX_ADDED, |
| 67 | RMAP_EVENT_INDEX_DELETED |
| 68 | } route_map_event_t; |
| 69 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 70 | /* Depth limit in RMAP recursion using RMAP_CALL. */ |
| 71 | #define RMAP_RECURSION_LIMIT 10 |
| 72 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | /* Route map rule structure for matching and setting. */ |
| 74 | struct route_map_rule_cmd |
| 75 | { |
| 76 | /* Route map rule name (e.g. as-path, metric) */ |
hasso | 27a43a8 | 2004-10-08 06:29:12 +0000 | [diff] [blame] | 77 | const char *str; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | |
| 79 | /* Function for value set or match. */ |
| 80 | route_map_result_t (*func_apply)(void *, struct prefix *, |
| 81 | route_map_object_t, void *); |
| 82 | |
| 83 | /* Compile argument and return result as void *. */ |
paul | c9eca01 | 2004-10-11 11:28:44 +0000 | [diff] [blame] | 84 | void *(*func_compile)(const char *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 85 | |
| 86 | /* Free allocated value by func_compile (). */ |
| 87 | void (*func_free)(void *); |
| 88 | }; |
| 89 | |
| 90 | /* Route map apply error. */ |
| 91 | enum |
| 92 | { |
| 93 | /* Route map rule is missing. */ |
| 94 | RMAP_RULE_MISSING = 1, |
| 95 | |
| 96 | /* Route map rule can't compile */ |
| 97 | RMAP_COMPILE_ERROR |
| 98 | }; |
| 99 | |
| 100 | /* Route map rule list. */ |
| 101 | struct route_map_rule_list |
| 102 | { |
| 103 | struct route_map_rule *head; |
| 104 | struct route_map_rule *tail; |
| 105 | }; |
| 106 | |
| 107 | /* Route map index structure. */ |
| 108 | struct route_map_index |
| 109 | { |
| 110 | struct route_map *map; |
hasso | 4a8164e | 2005-04-08 14:20:18 +0000 | [diff] [blame] | 111 | char *description; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | |
| 113 | /* Preference of this route map rule. */ |
| 114 | int pref; |
| 115 | |
| 116 | /* Route map type permit or deny. */ |
| 117 | enum route_map_type type; |
| 118 | |
| 119 | /* Do we follow old rules, or hop forward? */ |
| 120 | route_map_end_t exitpolicy; |
| 121 | |
| 122 | /* If we're using "GOTO", to where do we go? */ |
| 123 | int nextpref; |
| 124 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 125 | /* If we're using "CALL", to which route-map do ew go? */ |
| 126 | char *nextrm; |
| 127 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | /* Matching rule list. */ |
| 129 | struct route_map_rule_list match_list; |
| 130 | struct route_map_rule_list set_list; |
| 131 | |
| 132 | /* Make linked list. */ |
| 133 | struct route_map_index *next; |
| 134 | struct route_map_index *prev; |
| 135 | }; |
| 136 | |
| 137 | /* Route map list structure. */ |
| 138 | struct route_map |
| 139 | { |
| 140 | /* Name of route map. */ |
| 141 | char *name; |
| 142 | |
| 143 | /* Route map's rule. */ |
| 144 | struct route_map_index *head; |
| 145 | struct route_map_index *tail; |
| 146 | |
| 147 | /* Make linked list. */ |
| 148 | struct route_map *next; |
| 149 | struct route_map *prev; |
| 150 | }; |
| 151 | |
| 152 | /* Prototypes. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 153 | extern void route_map_init (void); |
| 154 | extern void route_map_init_vty (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | |
| 156 | /* Add match statement to route map. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 157 | extern int route_map_add_match (struct route_map_index *index, |
| 158 | const char *match_name, |
| 159 | const char *match_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | |
| 161 | /* Delete specified route match rule. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 162 | extern int route_map_delete_match (struct route_map_index *index, |
| 163 | const char *match_name, |
| 164 | const char *match_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 165 | |
| 166 | /* Add route-map set statement to the route map. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 167 | extern int route_map_add_set (struct route_map_index *index, |
| 168 | const char *set_name, |
| 169 | const char *set_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | |
| 171 | /* Delete route map set rule. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 172 | extern int route_map_delete_set (struct route_map_index *index, |
| 173 | const char *set_name, |
| 174 | const char *set_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | |
| 176 | /* Install rule command to the match list. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 177 | extern void route_map_install_match (struct route_map_rule_cmd *cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 178 | |
| 179 | /* Install rule command to the set list. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 180 | extern void route_map_install_set (struct route_map_rule_cmd *cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | |
| 182 | /* Lookup route map by name. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 183 | extern struct route_map * route_map_lookup_by_name (const char *name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 184 | |
| 185 | /* Apply route map to the object. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 186 | extern route_map_result_t route_map_apply (struct route_map *map, |
| 187 | struct prefix *, |
| 188 | route_map_object_t object_type, |
| 189 | void *object); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 190 | |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 191 | extern void route_map_add_hook (void (*func) (const char *)); |
| 192 | extern void route_map_delete_hook (void (*func) (const char *)); |
| 193 | extern void route_map_event_hook (void (*func) (route_map_event_t, const char *)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 194 | |
| 195 | #endif /* _ZEBRA_ROUTEMAP_H */ |