]> git.proxmox.com Git - mirror_frr.git/blame - lib/routemap.h
Merge pull request #4423 from ton31337/feature/delete_prefix_list_by_sequence_number_7.1
[mirror_frr.git] / lib / routemap.h
CommitLineData
718e3744 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 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
21#ifndef _ZEBRA_ROUTEMAP_H
22#define _ZEBRA_ROUTEMAP_H
23
24873f0c 24#include "prefix.h"
4a1ab8e4 25#include "memory.h"
e80e7cce 26#include "qobj.h"
0a538fc9
QY
27#include "vty.h"
28
5e244469
RW
29#ifdef __cplusplus
30extern "C" {
31#endif
32
4a1ab8e4
DL
33DECLARE_MTYPE(ROUTE_MAP_NAME)
34DECLARE_MTYPE(ROUTE_MAP_RULE)
35DECLARE_MTYPE(ROUTE_MAP_COMPILED)
24873f0c 36
718e3744 37/* Route map's type. */
d62a17ae 38enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
39
40typedef enum {
41 RMAP_MATCH,
42 RMAP_DENYMATCH,
43 RMAP_NOMATCH,
44 RMAP_ERROR,
45 RMAP_OKAY
718e3744 46} route_map_result_t;
47
d62a17ae 48typedef enum {
49 RMAP_RIP,
50 RMAP_RIPNG,
51 RMAP_OSPF,
52 RMAP_OSPF6,
53 RMAP_BGP,
54 RMAP_ZEBRA,
55 RMAP_ISIS,
718e3744 56} route_map_object_t;
57
d62a17ae 58typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
59
60typedef enum {
61 RMAP_EVENT_SET_ADDED,
62 RMAP_EVENT_SET_DELETED,
63 RMAP_EVENT_SET_REPLACED,
64 RMAP_EVENT_MATCH_ADDED,
65 RMAP_EVENT_MATCH_DELETED,
66 RMAP_EVENT_MATCH_REPLACED,
67 RMAP_EVENT_INDEX_ADDED,
68 RMAP_EVENT_INDEX_DELETED,
69 RMAP_EVENT_CALL_ADDED, /* call to another routemap added */
70 RMAP_EVENT_CALL_DELETED,
71 RMAP_EVENT_PLIST_ADDED,
72 RMAP_EVENT_PLIST_DELETED,
73 RMAP_EVENT_CLIST_ADDED,
74 RMAP_EVENT_CLIST_DELETED,
75 RMAP_EVENT_ECLIST_ADDED,
76 RMAP_EVENT_ECLIST_DELETED,
77 RMAP_EVENT_LLIST_ADDED,
78 RMAP_EVENT_LLIST_DELETED,
79 RMAP_EVENT_ASLIST_ADDED,
80 RMAP_EVENT_ASLIST_DELETED,
81 RMAP_EVENT_FILTER_ADDED,
82 RMAP_EVENT_FILTER_DELETED,
718e3744 83} route_map_event_t;
84
fee0f4c6 85/* Depth limit in RMAP recursion using RMAP_CALL. */
86#define RMAP_RECURSION_LIMIT 10
87
718e3744 88/* Route map rule structure for matching and setting. */
d62a17ae 89struct route_map_rule_cmd {
90 /* Route map rule name (e.g. as-path, metric) */
91 const char *str;
718e3744 92
d62a17ae 93 /* Function for value set or match. */
123214ef
MS
94 route_map_result_t (*func_apply)(void *rule,
95 const struct prefix *prefix,
96 route_map_object_t type,
97 void *object);
718e3744 98
d62a17ae 99 /* Compile argument and return result as void *. */
100 void *(*func_compile)(const char *);
718e3744 101
d62a17ae 102 /* Free allocated value by func_compile (). */
103 void (*func_free)(void *);
718e3744 104};
105
106/* Route map apply error. */
996c9314 107enum { RMAP_COMPILE_SUCCESS,
9ca25fed 108
996c9314
LB
109 /* Route map rule is missing. */
110 RMAP_RULE_MISSING,
718e3744 111
996c9314
LB
112 /* Route map rule can't compile */
113 RMAP_COMPILE_ERROR };
718e3744 114
115/* Route map rule list. */
d62a17ae 116struct route_map_rule_list {
117 struct route_map_rule *head;
118 struct route_map_rule *tail;
718e3744 119};
120
121/* Route map index structure. */
d62a17ae 122struct route_map_index {
123 struct route_map *map;
124 char *description;
718e3744 125
d62a17ae 126 /* Preference of this route map rule. */
127 int pref;
718e3744 128
d62a17ae 129 /* Route map type permit or deny. */
130 enum route_map_type type;
718e3744 131
d62a17ae 132 /* Do we follow old rules, or hop forward? */
133 route_map_end_t exitpolicy;
718e3744 134
d62a17ae 135 /* If we're using "GOTO", to where do we go? */
136 int nextpref;
718e3744 137
d62a17ae 138 /* If we're using "CALL", to which route-map do ew go? */
139 char *nextrm;
fee0f4c6 140
d62a17ae 141 /* Matching rule list. */
142 struct route_map_rule_list match_list;
143 struct route_map_rule_list set_list;
718e3744 144
d62a17ae 145 /* Make linked list. */
146 struct route_map_index *next;
147 struct route_map_index *prev;
e80e7cce 148
279b0607
DS
149 /* Keep track how many times we've try to apply */
150 uint64_t applied;
151
d62a17ae 152 QOBJ_FIELDS
718e3744 153};
e80e7cce 154DECLARE_QOBJ_TYPE(route_map_index)
718e3744 155
156/* Route map list structure. */
d62a17ae 157struct route_map {
158 /* Name of route map. */
159 char *name;
718e3744 160
d62a17ae 161 /* Route map's rule. */
162 struct route_map_index *head;
163 struct route_map_index *tail;
718e3744 164
d62a17ae 165 /* Make linked list. */
166 struct route_map *next;
167 struct route_map *prev;
518f0eb1 168
d62a17ae 169 /* Maintain update info */
e4694d0d
DS
170 bool to_be_processed; /* True if modification isn't acted on yet */
171 bool deleted; /* If 1, then this node will be deleted */
e80e7cce 172
279b0607
DS
173 /* How many times have we applied this route-map */
174 uint64_t applied;
175
4a2a09d0 176 /* Counter to track active usage of this route-map */
177 uint16_t use_count;
178
d62a17ae 179 QOBJ_FIELDS
718e3744 180};
e80e7cce 181DECLARE_QOBJ_TYPE(route_map)
718e3744 182
183/* Prototypes. */
d62a17ae 184extern void route_map_init(void);
8619629a
DS
185
186/*
187 * This should only be called on shutdown
188 * Additionally this function sets the hooks to NULL
189 * before any processing is done.
190 */
d62a17ae 191extern void route_map_finish(void);
718e3744 192
193/* Add match statement to route map. */
d62a17ae 194extern int route_map_add_match(struct route_map_index *index,
195 const char *match_name, const char *match_arg);
718e3744 196
197/* Delete specified route match rule. */
d62a17ae 198extern int route_map_delete_match(struct route_map_index *index,
199 const char *match_name,
200 const char *match_arg);
718e3744 201
d62a17ae 202extern const char *route_map_get_match_arg(struct route_map_index *index,
203 const char *match_name);
518f0eb1 204
718e3744 205/* Add route-map set statement to the route map. */
d62a17ae 206extern int route_map_add_set(struct route_map_index *index,
207 const char *set_name, const char *set_arg);
718e3744 208
209/* Delete route map set rule. */
d62a17ae 210extern int route_map_delete_set(struct route_map_index *index,
211 const char *set_name, const char *set_arg);
718e3744 212
213/* Install rule command to the match list. */
d62a17ae 214extern void route_map_install_match(struct route_map_rule_cmd *cmd);
718e3744 215
6a74c5f9
DS
216/*
217 * Install rule command to the set list.
218 *
219 * When installing a particular item, Allow a difference of handling
220 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
221 * this form of the command(return a pointer and handle it appropriately
222 * in the apply command). See 'set metric' command
223 * as it is handled in ripd/ripngd and ospfd.
224 */
d62a17ae 225extern void route_map_install_set(struct route_map_rule_cmd *cmd);
718e3744 226
227/* Lookup route map by name. */
d62a17ae 228extern struct route_map *route_map_lookup_by_name(const char *name);
718e3744 229
1de27621
DA
230/* Simple helper to warn if route-map does not exist. */
231struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
232
718e3744 233/* Apply route map to the object. */
d62a17ae 234extern route_map_result_t route_map_apply(struct route_map *map,
123214ef 235 const struct prefix *prefix,
d62a17ae 236 route_map_object_t object_type,
237 void *object);
238
239extern void route_map_add_hook(void (*func)(const char *));
240extern void route_map_delete_hook(void (*func)(const char *));
241extern void route_map_event_hook(void (*func)(route_map_event_t, const char *));
7096e938 242extern int route_map_mark_updated(const char *name);
46a69f10 243extern void route_map_walk_update_list(void (*update_fn)(char *name));
d62a17ae 244extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
245 const char *rmap_name);
246extern void route_map_notify_dependencies(const char *affected_name,
247 route_map_event_t event);
248
249extern int generic_match_add(struct vty *vty, struct route_map_index *index,
250 const char *command, const char *arg,
251 route_map_event_t type);
252
253extern int generic_match_delete(struct vty *vty, struct route_map_index *index,
254 const char *command, const char *arg,
255 route_map_event_t type);
256extern int generic_set_add(struct vty *vty, struct route_map_index *index,
257 const char *command, const char *arg);
258extern int generic_set_delete(struct vty *vty, struct route_map_index *index,
259 const char *command, const char *arg);
82f97584
DW
260
261
262/* match interface */
d62a17ae 263extern void route_map_match_interface_hook(int (*func)(
264 struct vty *vty, struct route_map_index *index, const char *command,
265 const char *arg, route_map_event_t type));
82f97584 266/* no match interface */
d62a17ae 267extern void route_map_no_match_interface_hook(int (*func)(
268 struct vty *vty, struct route_map_index *index, const char *command,
269 const char *arg, route_map_event_t type));
82f97584 270/* match ip address */
d62a17ae 271extern void route_map_match_ip_address_hook(int (*func)(
272 struct vty *vty, struct route_map_index *index, const char *command,
273 const char *arg, route_map_event_t type));
82f97584 274/* no match ip address */
d62a17ae 275extern void route_map_no_match_ip_address_hook(int (*func)(
276 struct vty *vty, struct route_map_index *index, const char *command,
277 const char *arg, route_map_event_t type));
82f97584 278/* match ip address prefix list */
d62a17ae 279extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
280 struct vty *vty, struct route_map_index *index, const char *command,
281 const char *arg, route_map_event_t type));
82f97584 282/* no match ip address prefix list */
d62a17ae 283extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
284 struct vty *vty, struct route_map_index *index, const char *command,
285 const char *arg, route_map_event_t type));
82f97584 286/* match ip next hop */
d62a17ae 287extern void route_map_match_ip_next_hop_hook(int (*func)(
288 struct vty *vty, struct route_map_index *index, const char *command,
289 const char *arg, route_map_event_t type));
82f97584 290/* no match ip next hop */
d62a17ae 291extern void route_map_no_match_ip_next_hop_hook(int (*func)(
292 struct vty *vty, struct route_map_index *index, const char *command,
293 const char *arg, route_map_event_t type));
82f97584 294/* match ip next hop prefix list */
d62a17ae 295extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
296 struct vty *vty, struct route_map_index *index, const char *command,
297 const char *arg, route_map_event_t type));
82f97584 298/* no match ip next hop prefix list */
d62a17ae 299extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
300 struct vty *vty, struct route_map_index *index, const char *command,
301 const char *arg, route_map_event_t type));
61ad901e
DA
302/* match ip next hop type */
303extern void route_map_match_ip_next_hop_type_hook(int (*func)(
304 struct vty *vty, struct route_map_index *index, const char *command,
305 const char *arg, route_map_event_t type));
306/* no match ip next hop type */
307extern void route_map_no_match_ip_next_hop_type_hook(int (*func)(
308 struct vty *vty, struct route_map_index *index, const char *command,
309 const char *arg, route_map_event_t type));
82f97584 310/* match ipv6 address */
d62a17ae 311extern void route_map_match_ipv6_address_hook(int (*func)(
312 struct vty *vty, struct route_map_index *index, const char *command,
313 const char *arg, route_map_event_t type));
82f97584 314/* no match ipv6 address */
d62a17ae 315extern void route_map_no_match_ipv6_address_hook(int (*func)(
316 struct vty *vty, struct route_map_index *index, const char *command,
317 const char *arg, route_map_event_t type));
82f97584 318/* match ipv6 address prefix list */
d62a17ae 319extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
320 struct vty *vty, struct route_map_index *index, const char *command,
321 const char *arg, route_map_event_t type));
82f97584 322/* no match ipv6 address prefix list */
d62a17ae 323extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
324 struct vty *vty, struct route_map_index *index, const char *command,
325 const char *arg, route_map_event_t type));
61ad901e
DA
326/* match ipv6 next-hop type */
327extern void route_map_match_ipv6_next_hop_type_hook(int (*func)(
328 struct vty *vty, struct route_map_index *index, const char *command,
329 const char *arg, route_map_event_t type));
330/* no match ipv6 next-hop type */
331extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)(
332 struct vty *vty, struct route_map_index *index, const char *command,
333 const char *arg, route_map_event_t type));
82f97584 334/* match metric */
d62a17ae 335extern void route_map_match_metric_hook(int (*func)(
336 struct vty *vty, struct route_map_index *index, const char *command,
337 const char *arg, route_map_event_t type));
82f97584 338/* no match metric */
d62a17ae 339extern void route_map_no_match_metric_hook(int (*func)(
340 struct vty *vty, struct route_map_index *index, const char *command,
341 const char *arg, route_map_event_t type));
82f97584 342/* match tag */
d62a17ae 343extern void route_map_match_tag_hook(int (*func)(
344 struct vty *vty, struct route_map_index *index, const char *command,
345 const char *arg, route_map_event_t type));
82f97584 346/* no match tag */
d62a17ae 347extern void route_map_no_match_tag_hook(int (*func)(
348 struct vty *vty, struct route_map_index *index, const char *command,
349 const char *arg, route_map_event_t type));
82f97584 350/* set ip nexthop */
d62a17ae 351extern void route_map_set_ip_nexthop_hook(
352 int (*func)(struct vty *vty, struct route_map_index *index,
353 const char *command, const char *arg));
82f97584 354/* no set ip nexthop */
d62a17ae 355extern void route_map_no_set_ip_nexthop_hook(
356 int (*func)(struct vty *vty, struct route_map_index *index,
357 const char *command, const char *arg));
82f97584 358/* set ipv6 nexthop local */
d62a17ae 359extern void route_map_set_ipv6_nexthop_local_hook(
360 int (*func)(struct vty *vty, struct route_map_index *index,
361 const char *command, const char *arg));
82f97584 362/* no set ipv6 nexthop local */
d62a17ae 363extern void route_map_no_set_ipv6_nexthop_local_hook(
364 int (*func)(struct vty *vty, struct route_map_index *index,
365 const char *command, const char *arg));
82f97584 366/* set metric */
d62a17ae 367extern void route_map_set_metric_hook(int (*func)(struct vty *vty,
368 struct route_map_index *index,
369 const char *command,
370 const char *arg));
82f97584 371/* no set metric */
d62a17ae 372extern void route_map_no_set_metric_hook(
373 int (*func)(struct vty *vty, struct route_map_index *index,
374 const char *command, const char *arg));
82f97584 375/* set tag */
d62a17ae 376extern void route_map_set_tag_hook(int (*func)(struct vty *vty,
377 struct route_map_index *index,
378 const char *command,
379 const char *arg));
82f97584 380/* no set tag */
d62a17ae 381extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty,
382 struct route_map_index *index,
383 const char *command,
384 const char *arg));
e52702f2 385
d62a17ae 386extern void *route_map_rule_tag_compile(const char *arg);
387extern void route_map_rule_tag_free(void *rule);
dc9ffce8 388
4a2a09d0 389/* Increment the route-map used counter */
390extern void route_map_counter_increment(struct route_map *map);
391
392/* Decrement the route-map used counter */
393extern void route_map_counter_decrement(struct route_map *map);
394
5e244469
RW
395#ifdef __cplusplus
396}
397#endif
398
718e3744 399#endif /* _ZEBRA_ROUTEMAP_H */