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