]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_routemap.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / eigrpd / eigrp_routemap.c
1 /*
2 * EIGRP Filter Functions.
3 * Copyright (C) 2013-2015
4 * Authors:
5 * Donnie Savage
6 * Jan Janovic
7 * Matej Perina
8 * Peter Orsag
9 * Peter Paluch
10 * Frantisek Gazo
11 * Tomas Hvorkovy
12 * Martin Kontsek
13 * Lukas Koribsky
14 *
15 * Note: This file contains skeleton for all possible matches and sets,
16 * but they are hidden in comment block and not properly implemented.
17 * At this time, the only function we consider useful for our use
18 * in distribute command in EIGRP is matching destination IP (with both
19 * access and prefix list).
20 *
21 *
22 * This file is part of GNU Zebra.
23 *
24 * GNU Zebra is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the
26 * Free Software Foundation; either version 2, or (at your option) any
27 * later version.
28 *
29 * GNU Zebra is distributed in the hope that it will be useful, but
30 * WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License along
35 * with this program; see the file COPYING; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 */
38
39 #include <zebra.h>
40
41 #include "memory.h"
42 #include "prefix.h"
43 #include "if_rmap.h"
44 #include "routemap.h"
45 #include "command.h"
46 #include "filter.h"
47 #include "log.h"
48 #include "sockunion.h" /* for inet_aton () */
49 #include "plist.h"
50
51 #include "eigrpd/eigrpd.h"
52 #include "eigrpd/eigrp_structs.h"
53 #include "eigrpd/eigrp_const.h"
54 #include "eigrpd/eigrp_macros.h"
55 #include "eigrpd/eigrp_routemap.h"
56
57 void
58 eigrp_if_rmap_update (struct if_rmap *if_rmap)
59 {
60 struct interface *ifp;
61 struct eigrp_interface *ei, *ei2;
62 struct listnode *node, *nnode;
63 struct route_map *rmap;
64 struct eigrp *e;
65
66 ifp = if_lookup_by_name (if_rmap->ifname);
67 if (ifp == NULL)
68 return;
69
70 ei = NULL;
71 e = eigrp_lookup();
72 for (ALL_LIST_ELEMENTS (e->eiflist, node, nnode, ei2))
73 {
74 if(strcmp(ei2->ifp->name,ifp->name) == 0){
75 ei = ei2;
76 break;
77 }
78 }
79
80 if (if_rmap->routemap[IF_RMAP_IN])
81 {
82 rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_IN]);
83 if (rmap)
84 ei->routemap[IF_RMAP_IN] = rmap;
85 else
86 ei->routemap[IF_RMAP_IN] = NULL;
87 }
88 else
89 ei->routemap[EIGRP_FILTER_IN] = NULL;
90
91 if (if_rmap->routemap[IF_RMAP_OUT])
92 {
93 rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_OUT]);
94 if (rmap)
95 ei->routemap[IF_RMAP_OUT] = rmap;
96 else
97 ei->routemap[IF_RMAP_OUT] = NULL;
98 }
99 else
100 ei->routemap[EIGRP_FILTER_OUT] = NULL;
101 }
102
103 void
104 eigrp_if_rmap_update_interface (struct interface *ifp)
105 {
106 struct if_rmap *if_rmap;
107
108 if_rmap = if_rmap_lookup (ifp->name);
109 if (if_rmap)
110 eigrp_if_rmap_update (if_rmap);
111 }
112
113 void
114 eigrp_routemap_update_redistribute (void)
115 {
116 int i;
117 struct eigrp *e;
118
119 e = eigrp_lookup();
120
121 if (e)
122 {
123 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
124 {
125 if (e->route_map[i].name)
126 e->route_map[i].map =
127 route_map_lookup_by_name (e->route_map[i].name);
128 }
129 }
130 }
131
132 /* ARGSUSED */
133 void
134 eigrp_rmap_update (const char *notused)
135 {
136 struct interface *ifp;
137 struct listnode *node, *nnode;
138
139 for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
140 eigrp_if_rmap_update_interface (ifp);
141
142 eigrp_routemap_update_redistribute ();
143 }
144
145 /* Add eigrp route map rule. */
146 static int
147 eigrp_route_match_add (struct vty *vty, struct route_map_index *index,
148 const char *command, const char *arg)
149 {
150 int ret;
151 ret = route_map_add_match (index, command, arg);
152 if (ret)
153 {
154 switch (ret)
155 {
156 case RMAP_RULE_MISSING:
157 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
158 return CMD_WARNING;
159 case RMAP_COMPILE_ERROR:
160 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
161 return CMD_WARNING;
162 }
163 }
164 return CMD_SUCCESS;
165 }
166
167 /* Delete rip route map rule. */
168 static int
169 eigrp_route_match_delete (struct vty *vty, struct route_map_index *index,
170 const char *command, const char *arg)
171 {
172 int ret;
173 ret = route_map_delete_match (index, command, arg);
174 if (ret)
175 {
176 switch (ret)
177 {
178 case RMAP_RULE_MISSING:
179 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
180 return CMD_WARNING;
181 case RMAP_COMPILE_ERROR:
182 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
183 return CMD_WARNING;
184 }
185 }
186 return CMD_SUCCESS;
187 }
188
189 /* Add eigrp route map rule. */
190 static int
191 eigrp_route_set_add (struct vty *vty, struct route_map_index *index,
192 const char *command, const char *arg)
193 {
194 int ret;
195
196 ret = route_map_add_set (index, command, arg);
197 if (ret)
198 {
199 switch (ret)
200 {
201 case RMAP_RULE_MISSING:
202 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
203 return CMD_WARNING;
204 case RMAP_COMPILE_ERROR:
205 /* rip, ripng and other protocols share the set metric command
206 but only values from 0 to 16 are valid for rip and ripng
207 if metric is out of range for rip and ripng, it is not for
208 other protocols. Do not return an error */
209 if (strcmp(command, "metric")) {
210 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
211 return CMD_WARNING;
212 }
213 }
214 }
215 return CMD_SUCCESS;
216 }
217
218 /* Delete eigrp route map rule. */
219 static int
220 eigrp_route_set_delete (struct vty *vty, struct route_map_index *index,
221 const char *command, const char *arg)
222 {
223 int ret;
224
225 ret = route_map_delete_set (index, command, arg);
226 if (ret)
227 {
228 switch (ret)
229 {
230 case RMAP_RULE_MISSING:
231 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
232 return CMD_WARNING;
233 case RMAP_COMPILE_ERROR:
234 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
235 return CMD_WARNING;
236 }
237 }
238 return CMD_SUCCESS;
239 }
240
241 /* Hook function for updating route_map assignment. */
242 /* ARGSUSED */
243 void
244 eigrp_route_map_update (const char *notused)
245 {
246 int i;
247 struct eigrp *e;
248 e = eigrp_lookup();
249
250 if (e)
251 {
252 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
253 {
254 if (e->route_map[i].name)
255 e->route_map[i].map =
256 route_map_lookup_by_name (e->route_map[i].name);
257 }
258 }
259 }
260
261
262
263 /* `match metric METRIC' */
264 /* Match function return 1 if match is success else return zero. */
265 static route_map_result_t
266 route_match_metric (void *rule, struct prefix *prefix,
267 route_map_object_t type, void *object)
268 {
269 // u_int32_t *metric;
270 // u_int32_t check;
271 // struct rip_info *rinfo;
272 // struct eigrp_neighbor_entry *te;
273 // struct eigrp_prefix_entry *pe;
274 // struct listnode *node, *node2, *nnode, *nnode2;
275 // struct eigrp *e;
276 //
277 // e = eigrp_lookup();
278 //
279 // if (type == RMAP_EIGRP)
280 // {
281 // metric = rule;
282 // rinfo = object;
283 //
284 // /* If external metric is available, the route-map should
285 // work on this one (for redistribute purpose) */
286 // /*check = (rinfo->external_metric) ? rinfo->external_metric :
287 // rinfo->metric;*/
288 //
289 // if (check == *metric)
290 // return RMAP_MATCH;
291 // else
292 // return RMAP_NOMATCH;
293 // }
294 return RMAP_NOMATCH;
295 }
296
297 /* Route map `match metric' match statement. `arg' is METRIC value */
298 static void *
299 route_match_metric_compile (const char *arg)
300 {
301 // u_int32_t *metric;
302 //
303 // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
304 // *metric = atoi (arg);
305 //
306 // if(*metric > 0)
307 // return metric;
308 //
309 // XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
310 return NULL;
311 }
312
313 /* Free route map's compiled `match metric' value. */
314 static void
315 route_match_metric_free (void *rule)
316 {
317 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
318 }
319
320 /* Route map commands for metric matching. */
321 struct route_map_rule_cmd route_match_metric_cmd =
322 {
323 "metric",
324 route_match_metric,
325 route_match_metric_compile,
326 route_match_metric_free
327 };
328
329 /* `match interface IFNAME' */
330 /* Match function return 1 if match is success else return zero. */
331 static route_map_result_t
332 route_match_interface (void *rule, struct prefix *prefix,
333 route_map_object_t type, void *object)
334 {
335 // struct rip_info *rinfo;
336 // struct interface *ifp;
337 // char *ifname;
338 //
339 // if (type == RMAP_EIGRP)
340 // {
341 // ifname = rule;
342 // ifp = if_lookup_by_name(ifname);
343 //
344 // if (!ifp)
345 // return RMAP_NOMATCH;
346 //
347 // rinfo = object;
348 //
349 // /*if (rinfo->ifindex_out == ifp->ifindex || rinfo->ifindex == ifp->ifindex)
350 // return RMAP_MATCH;
351 // else
352 // return RMAP_NOMATCH;*/
353 // }
354 return RMAP_NOMATCH;
355 }
356
357 /* Route map `match interface' match statement. `arg' is IFNAME value */
358 /* XXX I don`t know if I need to check does interface exist? */
359 static void *
360 route_match_interface_compile (const char *arg)
361 {
362 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
363 }
364
365 /* Free route map's compiled `match interface' value. */
366 static void
367 route_match_interface_free (void *rule)
368 {
369 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
370 }
371
372 /* Route map commands for interface matching. */
373 struct route_map_rule_cmd route_match_interface_cmd =
374 {
375 "interface",
376 route_match_interface,
377 route_match_interface_compile,
378 route_match_interface_free
379 };
380
381 /* `match ip next-hop IP_ACCESS_LIST' */
382
383 /* Match function return 1 if match is success else return zero. */
384 static route_map_result_t
385 route_match_ip_next_hop (void *rule, struct prefix *prefix,
386 route_map_object_t type, void *object)
387 {
388 // struct access_list *alist;
389 // struct rip_info *rinfo;
390 // struct prefix_ipv4 p;
391 //
392 // if (type == RMAP_EIGRP)
393 // {
394 // rinfo = object;
395 // p.family = AF_INET;
396 // /*p.prefix = (rinfo->nexthop.s_addr) ? rinfo->nexthop : rinfo->from;*/
397 // p.prefixlen = IPV4_MAX_BITLEN;
398 //
399 // alist = access_list_lookup (AFI_IP, (char *) rule);
400 // if (alist == NULL)
401 // return RMAP_NOMATCH;
402 //
403 // return (access_list_apply (alist, &p) == FILTER_DENY ?
404 // RMAP_NOMATCH : RMAP_MATCH);
405 // }
406 return RMAP_NOMATCH;
407 }
408
409 /* Route map `ip next-hop' match statement. `arg' should be
410 access-list name. */
411 static void *
412 route_match_ip_next_hop_compile (const char *arg)
413 {
414 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
415 }
416
417 /* Free route map's compiled `. */
418 static void
419 route_match_ip_next_hop_free (void *rule)
420 {
421 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
422 }
423
424 /* Route map commands for ip next-hop matching. */
425 static struct route_map_rule_cmd route_match_ip_next_hop_cmd =
426 {
427 "ip next-hop",
428 route_match_ip_next_hop,
429 route_match_ip_next_hop_compile,
430 route_match_ip_next_hop_free
431 };
432
433 /* `match ip next-hop prefix-list PREFIX_LIST' */
434
435 static route_map_result_t
436 route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
437 route_map_object_t type, void *object)
438 {
439 // struct prefix_list *plist;
440 // struct rip_info *rinfo;
441 // struct prefix_ipv4 p;
442 //
443 // if (type == RMAP_EIGRP)
444 // {
445 // rinfo = object;
446 // p.family = AF_INET;
447 // /*p.prefix = (rinfo->nexthop.s_addr) ? rinfo->nexthop : rinfo->from;*/
448 // p.prefixlen = IPV4_MAX_BITLEN;
449 //
450 // plist = prefix_list_lookup (AFI_IP, (char *) rule);
451 // if (plist == NULL)
452 // return RMAP_NOMATCH;
453 //
454 // return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
455 // RMAP_NOMATCH : RMAP_MATCH);
456 // }
457 return RMAP_NOMATCH;
458 }
459
460 static void *
461 route_match_ip_next_hop_prefix_list_compile (const char *arg)
462 {
463 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
464 }
465
466 static void
467 route_match_ip_next_hop_prefix_list_free (void *rule)
468 {
469 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
470 }
471
472 static struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
473 {
474 "ip next-hop prefix-list",
475 route_match_ip_next_hop_prefix_list,
476 route_match_ip_next_hop_prefix_list_compile,
477 route_match_ip_next_hop_prefix_list_free
478 };
479
480 /* `match ip address IP_ACCESS_LIST' */
481
482 /* Match function should return 1 if match is success else return
483 zero. */
484 static route_map_result_t
485 route_match_ip_address (void *rule, struct prefix *prefix,
486 route_map_object_t type, void *object)
487 {
488 struct access_list *alist;
489
490 if (type == RMAP_EIGRP)
491 {
492 alist = access_list_lookup (AFI_IP, (char *) rule);
493 if (alist == NULL)
494 return RMAP_NOMATCH;
495
496 return (access_list_apply (alist, prefix) == FILTER_DENY ?
497 RMAP_NOMATCH : RMAP_MATCH);
498 }
499 return RMAP_NOMATCH;
500 }
501
502 /* Route map `ip address' match statement. `arg' should be
503 access-list name. */
504 static void *
505 route_match_ip_address_compile (const char *arg)
506 {
507 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
508 }
509
510 /* Free route map's compiled `ip address' value. */
511 static void
512 route_match_ip_address_free (void *rule)
513 {
514 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
515 }
516
517 /* Route map commands for ip address matching. */
518 static struct route_map_rule_cmd route_match_ip_address_cmd =
519 {
520 "ip address",
521 route_match_ip_address,
522 route_match_ip_address_compile,
523 route_match_ip_address_free
524 };
525
526 /* `match ip address prefix-list PREFIX_LIST' */
527
528 static route_map_result_t
529 route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
530 route_map_object_t type, void *object)
531 {
532 struct prefix_list *plist;
533
534 if (type == RMAP_EIGRP)
535 {
536 plist = prefix_list_lookup (AFI_IP, (char *) rule);
537 if (plist == NULL)
538 return RMAP_NOMATCH;
539
540 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
541 RMAP_NOMATCH : RMAP_MATCH);
542 }
543 return RMAP_NOMATCH;
544 }
545
546 static void *
547 route_match_ip_address_prefix_list_compile (const char *arg)
548 {
549 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
550 }
551
552 static void
553 route_match_ip_address_prefix_list_free (void *rule)
554 {
555 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
556 }
557
558 static struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
559 {
560 "ip address prefix-list",
561 route_match_ip_address_prefix_list,
562 route_match_ip_address_prefix_list_compile,
563 route_match_ip_address_prefix_list_free
564 };
565
566 /* `match tag TAG' */
567 /* Match function return 1 if match is success else return zero. */
568 static route_map_result_t
569 route_match_tag (void *rule, struct prefix *prefix,
570 route_map_object_t type, void *object)
571 {
572 // u_short *tag;
573 // struct rip_info *rinfo;
574 //
575 // if (type == RMAP_EIGRP)
576 // {
577 // tag = rule;
578 // rinfo = object;
579 //
580 // /* The information stored by rinfo is host ordered. */
581 // /*if (rinfo->tag == *tag)
582 // return RMAP_MATCH;
583 // else
584 // return RMAP_NOMATCH;*/
585 // }
586 return RMAP_NOMATCH;
587 }
588
589 /* Route map `match tag' match statement. `arg' is TAG value */
590 static void *
591 route_match_tag_compile (const char *arg)
592 {
593 // u_short *tag;
594 //
595 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
596 // *tag = atoi (arg);
597 //
598 // return tag;
599 }
600
601 /* Free route map's compiled `match tag' value. */
602 static void
603 route_match_tag_free (void *rule)
604 {
605 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
606 }
607
608 /* Route map commands for tag matching. */
609 struct route_map_rule_cmd route_match_tag_cmd =
610 {
611 "tag",
612 route_match_tag,
613 route_match_tag_compile,
614 route_match_tag_free
615 };
616
617 /* Set metric to attribute. */
618 static route_map_result_t
619 route_set_metric (void *rule, struct prefix *prefix,
620 route_map_object_t type, void *object)
621 {
622 // if (type == RMAP_RIP)
623 // {
624 // struct rip_metric_modifier *mod;
625 // struct rip_info *rinfo;
626 //
627 // mod = rule;
628 // rinfo = object;
629 //
630 // /*if (mod->type == metric_increment)
631 // rinfo->metric_out += mod->metric;
632 // else if (mod->type == metric_decrement)
633 // rinfo->metric_out -= mod->metric;
634 // else if (mod->type == metric_absolute)
635 // rinfo->metric_out = mod->metric;
636 //
637 // if ((signed int)rinfo->metric_out < 1)
638 // rinfo->metric_out = 1;
639 // if (rinfo->metric_out > RIP_METRIC_INFINITY)
640 // rinfo->metric_out = RIP_METRIC_INFINITY;*/
641 //
642 // rinfo->metric_set = 1;
643 // }
644 return RMAP_OKAY;
645 }
646
647 /* set metric compilation. */
648 static void *
649 route_set_metric_compile (const char *arg)
650 {
651 // int len;
652 // const char *pnt;
653 // int type;
654 // long metric;
655 // char *endptr = NULL;
656 // struct rip_metric_modifier *mod;
657 //
658 // len = strlen (arg);
659 // pnt = arg;
660 //
661 // if (len == 0)
662 // return NULL;
663 //
664 // /* Examine first character. */
665 // if (arg[0] == '+')
666 // {
667 // //type = metric_increment;
668 // pnt++;
669 // }
670 // else if (arg[0] == '-')
671 // {
672 // //type = metric_decrement;
673 // pnt++;
674 // }
675 // /*else
676 // type = metric_absolute;*/
677 //
678 // /* Check beginning with digit string. */
679 // if (*pnt < '0' || *pnt > '9')
680 // return NULL;
681 //
682 // /* Convert string to integer. */
683 // metric = strtol (pnt, &endptr, 10);
684 //
685 // if (metric == LONG_MAX || *endptr != '\0')
686 // return NULL;
687 // /*if (metric < 0 || metric > RIP_METRIC_INFINITY)
688 // return NULL;*/
689 //
690 // mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
691 // sizeof (struct rip_metric_modifier));
692 // mod->type = type;
693 // mod->metric = metric;
694
695 // return mod;
696 }
697
698 /* Free route map's compiled `set metric' value. */
699 static void
700 route_set_metric_free (void *rule)
701 {
702 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
703 }
704
705 /* Set metric rule structure. */
706 static struct route_map_rule_cmd route_set_metric_cmd =
707 {
708 "metric",
709 route_set_metric,
710 route_set_metric_compile,
711 route_set_metric_free,
712 };
713
714 /* `set ip next-hop IP_ADDRESS' */
715
716 /* Set nexthop to object. ojbect must be pointer to struct attr. */
717 static route_map_result_t
718 route_set_ip_nexthop (void *rule, struct prefix *prefix,
719 route_map_object_t type, void *object)
720 {
721 // struct in_addr *address;
722 // struct rip_info *rinfo;
723 //
724 // if(type == RMAP_RIP)
725 // {
726 // /* Fetch routemap's rule information. */
727 // address = rule;
728 // rinfo = object;
729 //
730 // /* Set next hop value. */
731 // rinfo->nexthop_out = *address;
732 // }
733
734 return RMAP_OKAY;
735 }
736
737 /* Route map `ip nexthop' compile function. Given string is converted
738 to struct in_addr structure. */
739 static void *
740 route_set_ip_nexthop_compile (const char *arg)
741 {
742 // int ret;
743 // struct in_addr *address;
744 //
745 // address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
746 //
747 // ret = inet_aton (arg, address);
748 //
749 // if (ret == 0)
750 // {
751 // XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
752 // return NULL;
753 // }
754 //
755 // return address;
756 }
757
758 /* Free route map's compiled `ip nexthop' value. */
759 static void
760 route_set_ip_nexthop_free (void *rule)
761 {
762 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
763 }
764
765 /* Route map commands for ip nexthop set. */
766 static struct route_map_rule_cmd route_set_ip_nexthop_cmd =
767 {
768 "ip next-hop",
769 route_set_ip_nexthop,
770 route_set_ip_nexthop_compile,
771 route_set_ip_nexthop_free
772 };
773
774 /* `set tag TAG' */
775
776 /* Set tag to object. ojbect must be pointer to struct attr. */
777 static route_map_result_t
778 route_set_tag (void *rule, struct prefix *prefix,
779 route_map_object_t type, void *object)
780 {
781 // u_short *tag;
782 // struct rip_info *rinfo;
783 //
784 // if(type == RMAP_RIP)
785 // {
786 // /* Fetch routemap's rule information. */
787 // tag = rule;
788 // rinfo = object;
789 //
790 // /* Set next hop value. */
791 // rinfo->tag_out = *tag;
792 // }
793
794 return RMAP_OKAY;
795 }
796
797 /* Route map `tag' compile function. Given string is converted
798 to u_short. */
799 static void *
800 route_set_tag_compile (const char *arg)
801 {
802 // u_short *tag;
803 //
804 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
805 // *tag = atoi (arg);
806 //
807 // return tag;
808 }
809
810 /* Free route map's compiled `ip nexthop' value. */
811 static void
812 route_set_tag_free (void *rule)
813 {
814 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
815 }
816
817 /* Route map commands for tag set. */
818 static struct route_map_rule_cmd route_set_tag_cmd =
819 {
820 "tag",
821 route_set_tag,
822 route_set_tag_compile,
823 route_set_tag_free
824 };
825
826 #define MATCH_STR "Match values from routing table\n"
827 #define SET_STR "Set values in destination routing protocol\n"
828
829 DEFUN (match_metric,
830 match_metric_cmd,
831 "match metric <0-4294967295>",
832 MATCH_STR
833 "Match metric of route\n"
834 "Metric value\n")
835 {
836 return eigrp_route_match_add (vty, vty->index, "metric", argv[0]);
837 }
838
839 DEFUN (no_match_metric,
840 no_match_metric_cmd,
841 "no match metric",
842 NO_STR
843 MATCH_STR
844 "Match metric of route\n")
845 {
846 if (argc == 0)
847 return eigrp_route_match_delete (vty, vty->index, "metric", NULL);
848
849 return eigrp_route_match_delete (vty, vty->index, "metric", argv[0]);
850 }
851
852 ALIAS (no_match_metric,
853 no_match_metric_val_cmd,
854 "no match metric <0-4294967295>",
855 NO_STR
856 MATCH_STR
857 "Match metric of route\n"
858 "Metric value\n")
859
860 DEFUN (match_interface,
861 match_interface_cmd,
862 "match interface WORD",
863 MATCH_STR
864 "Match first hop interface of route\n"
865 "Interface name\n")
866 {
867 return eigrp_route_match_add (vty, vty->index, "interface", argv[0]);
868 }
869
870 DEFUN (no_match_interface,
871 no_match_interface_cmd,
872 "no match interface",
873 NO_STR
874 MATCH_STR
875 "Match first hop interface of route\n")
876 {
877 if (argc == 0)
878 return eigrp_route_match_delete (vty, vty->index, "interface", NULL);
879
880 return eigrp_route_match_delete (vty, vty->index, "interface", argv[0]);
881 }
882
883 ALIAS (no_match_interface,
884 no_match_interface_val_cmd,
885 "no match interface WORD",
886 NO_STR
887 MATCH_STR
888 "Match first hop interface of route\n"
889 "Interface name\n")
890
891 DEFUN (match_ip_next_hop,
892 match_ip_next_hop_cmd,
893 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
894 MATCH_STR
895 IP_STR
896 "Match next-hop address of route\n"
897 "IP access-list number\n"
898 "IP access-list number (expanded range)\n"
899 "IP Access-list name\n")
900 {
901 return eigrp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
902 }
903
904 DEFUN (no_match_ip_next_hop,
905 no_match_ip_next_hop_cmd,
906 "no match ip next-hop",
907 NO_STR
908 MATCH_STR
909 IP_STR
910 "Match next-hop address of route\n")
911 {
912 if (argc == 0)
913 return eigrp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
914
915 return eigrp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
916 }
917
918 ALIAS (no_match_ip_next_hop,
919 no_match_ip_next_hop_val_cmd,
920 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
921 NO_STR
922 MATCH_STR
923 IP_STR
924 "Match next-hop address of route\n"
925 "IP access-list number\n"
926 "IP access-list number (expanded range)\n"
927 "IP Access-list name\n")
928
929 DEFUN (match_ip_next_hop_prefix_list,
930 match_ip_next_hop_prefix_list_cmd,
931 "match ip next-hop prefix-list WORD",
932 MATCH_STR
933 IP_STR
934 "Match next-hop address of route\n"
935 "Match entries of prefix-lists\n"
936 "IP prefix-list name\n")
937 {
938 return eigrp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
939 }
940
941 DEFUN (no_match_ip_next_hop_prefix_list,
942 no_match_ip_next_hop_prefix_list_cmd,
943 "no match ip next-hop prefix-list",
944 NO_STR
945 MATCH_STR
946 IP_STR
947 "Match next-hop address of route\n"
948 "Match entries of prefix-lists\n")
949 {
950 if (argc == 0)
951 return eigrp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
952
953 return eigrp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
954 }
955
956 ALIAS (no_match_ip_next_hop_prefix_list,
957 no_match_ip_next_hop_prefix_list_val_cmd,
958 "no match ip next-hop prefix-list WORD",
959 NO_STR
960 MATCH_STR
961 IP_STR
962 "Match next-hop address of route\n"
963 "Match entries of prefix-lists\n"
964 "IP prefix-list name\n")
965
966 DEFUN (match_ip_address,
967 match_ip_address_cmd,
968 "match ip address (<1-199>|<1300-2699>|WORD)",
969 MATCH_STR
970 IP_STR
971 "Match address of route\n"
972 "IP access-list number\n"
973 "IP access-list number (expanded range)\n"
974 "IP Access-list name\n")
975 {
976 return eigrp_route_match_add (vty, vty->index, "ip address", argv[0]);
977 }
978
979 DEFUN (no_match_ip_address,
980 no_match_ip_address_cmd,
981 "no match ip address",
982 NO_STR
983 MATCH_STR
984 IP_STR
985 "Match address of route\n")
986 {
987 if (argc == 0)
988 return eigrp_route_match_delete (vty, vty->index, "ip address", NULL);
989
990 return eigrp_route_match_delete (vty, vty->index, "ip address", argv[0]);
991 }
992
993 ALIAS (no_match_ip_address,
994 no_match_ip_address_val_cmd,
995 "no match ip address (<1-199>|<1300-2699>|WORD)",
996 NO_STR
997 MATCH_STR
998 IP_STR
999 "Match address of route\n"
1000 "IP access-list number\n"
1001 "IP access-list number (expanded range)\n"
1002 "IP Access-list name\n")
1003
1004 DEFUN (match_ip_address_prefix_list,
1005 match_ip_address_prefix_list_cmd,
1006 "match ip address prefix-list WORD",
1007 MATCH_STR
1008 IP_STR
1009 "Match address of route\n"
1010 "Match entries of prefix-lists\n"
1011 "IP prefix-list name\n")
1012 {
1013 return eigrp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
1014 }
1015
1016 DEFUN (no_match_ip_address_prefix_list,
1017 no_match_ip_address_prefix_list_cmd,
1018 "no match ip address prefix-list",
1019 NO_STR
1020 MATCH_STR
1021 IP_STR
1022 "Match address of route\n"
1023 "Match entries of prefix-lists\n")
1024 {
1025 if (argc == 0)
1026 return eigrp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
1027
1028 return eigrp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
1029 }
1030
1031 ALIAS (no_match_ip_address_prefix_list,
1032 no_match_ip_address_prefix_list_val_cmd,
1033 "no match ip address prefix-list WORD",
1034 NO_STR
1035 MATCH_STR
1036 IP_STR
1037 "Match address of route\n"
1038 "Match entries of prefix-lists\n"
1039 "IP prefix-list name\n")
1040
1041 DEFUN (match_tag,
1042 match_tag_cmd,
1043 "match tag <0-65535>",
1044 MATCH_STR
1045 "Match tag of route\n"
1046 "Metric value\n")
1047 {
1048 return eigrp_route_match_add (vty, vty->index, "tag", argv[0]);
1049 }
1050
1051 DEFUN (no_match_tag,
1052 no_match_tag_cmd,
1053 "no match tag",
1054 NO_STR
1055 MATCH_STR
1056 "Match tag of route\n")
1057 {
1058 if (argc == 0)
1059 return eigrp_route_match_delete (vty, vty->index, "tag", NULL);
1060
1061 return eigrp_route_match_delete (vty, vty->index, "tag", argv[0]);
1062 }
1063
1064 ALIAS (no_match_tag,
1065 no_match_tag_val_cmd,
1066 "no match tag <0-65535>",
1067 NO_STR
1068 MATCH_STR
1069 "Match tag of route\n"
1070 "Metric value\n")
1071
1072 /* set functions */
1073
1074 DEFUN (set_metric,
1075 set_metric_cmd,
1076 "set metric <0-4294967295>",
1077 SET_STR
1078 "Metric value for destination routing protocol\n"
1079 "Metric value\n")
1080 {
1081 return eigrp_route_set_add (vty, vty->index, "metric", argv[0]);
1082 }
1083
1084 ALIAS (set_metric,
1085 set_metric_addsub_cmd,
1086 "set metric <+/-metric>",
1087 SET_STR
1088 "Metric value for destination routing protocol\n"
1089 "Add or subtract metric\n")
1090
1091 DEFUN (no_set_metric,
1092 no_set_metric_cmd,
1093 "no set metric",
1094 NO_STR
1095 SET_STR
1096 "Metric value for destination routing protocol\n")
1097 {
1098 if (argc == 0)
1099 return eigrp_route_set_delete (vty, vty->index, "metric", NULL);
1100
1101 return eigrp_route_set_delete (vty, vty->index, "metric", argv[0]);
1102 }
1103
1104 ALIAS (no_set_metric,
1105 no_set_metric_val_cmd,
1106 "no set metric (<0-4294967295>|<+/-metric>)",
1107 NO_STR
1108 SET_STR
1109 "Metric value for destination routing protocol\n"
1110 "Metric value\n"
1111 "Add or subtract metric\n")
1112
1113 DEFUN (set_ip_nexthop,
1114 set_ip_nexthop_cmd,
1115 "set ip next-hop A.B.C.D",
1116 SET_STR
1117 IP_STR
1118 "Next hop address\n"
1119 "IP address of next hop\n")
1120 {
1121 union sockunion su;
1122 int ret;
1123
1124 ret = str2sockunion (argv[0], &su);
1125 if (ret < 0)
1126 {
1127 vty_out (vty, "%% Malformed next-hop address%s", VTY_NEWLINE);
1128 return CMD_WARNING;
1129 }
1130
1131 return eigrp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
1132 }
1133
1134 DEFUN (no_set_ip_nexthop,
1135 no_set_ip_nexthop_cmd,
1136 "no set ip next-hop",
1137 NO_STR
1138 SET_STR
1139 IP_STR
1140 "Next hop address\n")
1141 {
1142 if (argc == 0)
1143 return eigrp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
1144
1145 return eigrp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
1146 }
1147
1148 ALIAS (no_set_ip_nexthop,
1149 no_set_ip_nexthop_val_cmd,
1150 "no set ip next-hop A.B.C.D",
1151 NO_STR
1152 SET_STR
1153 IP_STR
1154 "Next hop address\n"
1155 "IP address of next hop\n")
1156
1157 DEFUN (set_tag,
1158 set_tag_cmd,
1159 "set tag <0-65535>",
1160 SET_STR
1161 "Tag value for routing protocol\n"
1162 "Tag value\n")
1163 {
1164 return eigrp_route_set_add (vty, vty->index, "tag", argv[0]);
1165 }
1166
1167 DEFUN (no_set_tag,
1168 no_set_tag_cmd,
1169 "no set tag",
1170 NO_STR
1171 SET_STR
1172 "Tag value for routing protocol\n")
1173 {
1174 if (argc == 0)
1175 return eigrp_route_set_delete (vty, vty->index, "tag", NULL);
1176
1177 return eigrp_route_set_delete (vty, vty->index, "tag", argv[0]);
1178 }
1179
1180 ALIAS (no_set_tag,
1181 no_set_tag_val_cmd,
1182 "no set tag <0-65535>",
1183 NO_STR
1184 SET_STR
1185 "Tag value for routing protocol\n"
1186 "Tag value\n")
1187
1188
1189 /* Route-map init */
1190 void
1191 eigrp_route_map_init ()
1192 {
1193 route_map_init ();
1194 route_map_init_vty ();
1195 route_map_add_hook (eigrp_route_map_update);
1196 route_map_delete_hook (eigrp_route_map_update);
1197
1198 /*route_map_install_match (&route_match_metric_cmd);
1199 route_map_install_match (&route_match_interface_cmd);*/
1200 /*route_map_install_match (&route_match_ip_next_hop_cmd);
1201 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
1202 route_map_install_match (&route_match_ip_address_cmd);
1203 route_map_install_match (&route_match_ip_address_prefix_list_cmd);*/
1204 /*route_map_install_match (&route_match_tag_cmd);*/
1205
1206 /*route_map_install_set (&route_set_metric_cmd);
1207 route_map_install_set (&route_set_ip_nexthop_cmd);
1208 route_map_install_set (&route_set_tag_cmd);*/
1209
1210 /*install_element (RMAP_NODE, &route_match_metric_cmd);
1211 install_element (RMAP_NODE, &no_match_metric_cmd);
1212 install_element (RMAP_NODE, &no_match_metric_val_cmd);
1213 install_element (RMAP_NODE, &route_match_interface_cmd);
1214 install_element (RMAP_NODE, &no_match_interface_cmd);
1215 install_element (RMAP_NODE, &no_match_interface_val_cmd);
1216 install_element (RMAP_NODE, &route_match_ip_next_hop_cmd);
1217 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
1218 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
1219 install_element (RMAP_NODE, &route_match_ip_next_hop_prefix_list_cmd);
1220 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
1221 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);*/
1222 /*install_element (RMAP_NODE, &route_match_ip_address_cmd);
1223 install_element (RMAP_NODE, &no_match_ip_address_cmd);
1224 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
1225 install_element (RMAP_NODE, &route_match_ip_address_prefix_list_cmd);
1226 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
1227 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);*/
1228 /*install_element (RMAP_NODE, &route_match_tag_cmd);
1229 install_element (RMAP_NODE, &no_match_tag_cmd);
1230 install_element (RMAP_NODE, &no_match_tag_val_cmd);*/
1231
1232 /*install_element (RMAP_NODE, &set_metric_cmd);
1233 install_element (RMAP_NODE, &set_metric_addsub_cmd);
1234 install_element (RMAP_NODE, &no_set_metric_cmd);
1235 install_element (RMAP_NODE, &no_set_metric_val_cmd);
1236 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
1237 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
1238 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
1239 install_element (RMAP_NODE, &set_tag_cmd);
1240 install_element (RMAP_NODE, &no_set_tag_cmd);
1241 install_element (RMAP_NODE, &no_set_tag_val_cmd);*/
1242 }