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