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