]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_routemap.c
Merge pull request #4447 from donaldsharp/pim_unused_functions
[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, type);
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 enum route_map_match_result_t
255 route_match_metric(void *rule, struct prefix *prefix, 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 enum route_map_match_result_t
315 route_match_interface(void *rule, struct prefix *prefix,
316 route_map_object_t type, void *object)
317 {
318 // struct rip_info *rinfo;
319 // struct interface *ifp;
320 // char *ifname;
321 //
322 // if (type == RMAP_EIGRP)
323 // {
324 // ifname = rule;
325 // ifp = if_lookup_by_name(ifname);
326 //
327 // if (!ifp)
328 // return RMAP_NOMATCH;
329 //
330 // rinfo = object;
331 //
332 // /*if (rinfo->ifindex_out == ifp->ifindex || rinfo->ifindex ==
333 // ifp->ifindex)
334 // return RMAP_MATCH;
335 // else
336 // return RMAP_NOMATCH;*/
337 // }
338 return RMAP_NOMATCH;
339 }
340
341 /* Route map `match interface' match statement. `arg' is IFNAME value */
342 /* XXX I don`t know if I need to check does interface exist? */
343 static void *route_match_interface_compile(const char *arg)
344 {
345 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
346 }
347
348 /* Free route map's compiled `match interface' value. */
349 static void route_match_interface_free(void *rule)
350 {
351 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
352 }
353
354 /* Route map commands for interface matching. */
355 struct route_map_rule_cmd route_match_interface_cmd = {
356 "interface", route_match_interface, route_match_interface_compile,
357 route_match_interface_free};
358
359 /* `match ip next-hop IP_ACCESS_LIST' */
360
361 /* Match function return 1 if match is success else return zero. */
362 static enum route_map_match_result_t
363 route_match_ip_next_hop(void *rule, struct prefix *prefix,
364 route_map_object_t type, void *object)
365 {
366 // struct access_list *alist;
367 // struct rip_info *rinfo;
368 // struct prefix_ipv4 p;
369 //
370 // if (type == RMAP_EIGRP)
371 // {
372 // rinfo = object;
373 // p.family = AF_INET;
374 // /*p.prefix = (rinfo->nexthop.s_addr) ? rinfo->nexthop :
375 // rinfo->from;*/
376 // p.prefixlen = IPV4_MAX_BITLEN;
377 //
378 // alist = access_list_lookup (AFI_IP, (char *) rule);
379 // if (alist == NULL)
380 // return RMAP_NOMATCH;
381 //
382 // return (access_list_apply (alist, &p) == FILTER_DENY ?
383 // RMAP_NOMATCH : RMAP_MATCH);
384 // }
385 return RMAP_NOMATCH;
386 }
387
388 /* Route map `ip next-hop' match statement. `arg' should be
389 access-list name. */
390 static void *route_match_ip_next_hop_compile(const char *arg)
391 {
392 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
393 }
394
395 /* Free route map's compiled `. */
396 static void route_match_ip_next_hop_free(void *rule)
397 {
398 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
399 }
400
401 /* Route map commands for ip next-hop matching. */
402 static struct route_map_rule_cmd route_match_ip_next_hop_cmd = {
403 "ip next-hop", route_match_ip_next_hop, route_match_ip_next_hop_compile,
404 route_match_ip_next_hop_free};
405
406 /* `match ip next-hop prefix-list PREFIX_LIST' */
407
408 static enum route_map_match_result_t
409 route_match_ip_next_hop_prefix_list(void *rule, struct prefix *prefix,
410 route_map_object_t type, void *object)
411 {
412 // struct prefix_list *plist;
413 // struct rip_info *rinfo;
414 // struct prefix_ipv4 p;
415 //
416 // if (type == RMAP_EIGRP)
417 // {
418 // rinfo = object;
419 // p.family = AF_INET;
420 // /*p.prefix = (rinfo->nexthop.s_addr) ? rinfo->nexthop :
421 // rinfo->from;*/
422 // p.prefixlen = IPV4_MAX_BITLEN;
423 //
424 // plist = prefix_list_lookup (AFI_IP, (char *) rule);
425 // if (plist == NULL)
426 // return RMAP_NOMATCH;
427 //
428 // return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
429 // RMAP_NOMATCH : RMAP_MATCH);
430 // }
431 return RMAP_NOMATCH;
432 }
433
434 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg)
435 {
436 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
437 }
438
439 static void route_match_ip_next_hop_prefix_list_free(void *rule)
440 {
441 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
442 }
443
444 static struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = {
445 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list,
446 route_match_ip_next_hop_prefix_list_compile,
447 route_match_ip_next_hop_prefix_list_free};
448
449 /* `match ip address IP_ACCESS_LIST' */
450
451 /* Match function should return 1 if match is success else return
452 zero. */
453 static enum route_map_match_result_t
454 route_match_ip_address(void *rule, struct prefix *prefix,
455 route_map_object_t type, void *object)
456 {
457 struct access_list *alist;
458
459 if (type == RMAP_EIGRP) {
460 alist = access_list_lookup(AFI_IP, (char *)rule);
461 if (alist == NULL)
462 return RMAP_NOMATCH;
463
464 return (access_list_apply(alist, prefix) == FILTER_DENY
465 ? RMAP_NOMATCH
466 : RMAP_MATCH);
467 }
468 return RMAP_NOMATCH;
469 }
470
471 /* Route map `ip address' match statement. `arg' should be
472 access-list name. */
473 static void *route_match_ip_address_compile(const char *arg)
474 {
475 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
476 }
477
478 /* Free route map's compiled `ip address' value. */
479 static void route_match_ip_address_free(void *rule)
480 {
481 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
482 }
483
484 /* Route map commands for ip address matching. */
485 static struct route_map_rule_cmd route_match_ip_address_cmd = {
486 "ip address", route_match_ip_address, route_match_ip_address_compile,
487 route_match_ip_address_free};
488
489 /* `match ip address prefix-list PREFIX_LIST' */
490
491 static enum route_map_match_result_t
492 route_match_ip_address_prefix_list(void *rule, struct prefix *prefix,
493 route_map_object_t type, void *object)
494 {
495 struct prefix_list *plist;
496
497 if (type == RMAP_EIGRP) {
498 plist = prefix_list_lookup(AFI_IP, (char *)rule);
499 if (plist == NULL)
500 return RMAP_NOMATCH;
501
502 return (prefix_list_apply(plist, prefix) == PREFIX_DENY
503 ? RMAP_NOMATCH
504 : RMAP_MATCH);
505 }
506 return RMAP_NOMATCH;
507 }
508
509 static void *route_match_ip_address_prefix_list_compile(const char *arg)
510 {
511 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
512 }
513
514 static void route_match_ip_address_prefix_list_free(void *rule)
515 {
516 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
517 }
518
519 static struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = {
520 "ip address prefix-list", route_match_ip_address_prefix_list,
521 route_match_ip_address_prefix_list_compile,
522 route_match_ip_address_prefix_list_free};
523
524 /* `match tag TAG' */
525 /* Match function return 1 if match is success else return zero. */
526 static enum route_map_match_result_t
527 route_match_tag(void *rule, struct prefix *prefix, route_map_object_t type,
528 void *object)
529 {
530 // unsigned short *tag;
531 // struct rip_info *rinfo;
532 //
533 // if (type == RMAP_EIGRP)
534 // {
535 // tag = rule;
536 // rinfo = object;
537 //
538 // /* The information stored by rinfo is host ordered. */
539 // /*if (rinfo->tag == *tag)
540 // return RMAP_MATCH;
541 // else
542 // return RMAP_NOMATCH;*/
543 // }
544 return RMAP_NOMATCH;
545 }
546
547 /* Route map `match tag' match statement. `arg' is TAG value */
548 static void *route_match_tag_compile(const char *arg)
549 {
550 // unsigned short *tag;
551 //
552 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short));
553 // *tag = atoi (arg);
554 //
555 // return tag;
556 }
557
558 /* Free route map's compiled `match tag' value. */
559 static void route_match_tag_free(void *rule)
560 {
561 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
562 }
563
564 /* Route map commands for tag matching. */
565 struct route_map_rule_cmd route_match_tag_cmd = {
566 "tag", route_match_tag, route_match_tag_compile, route_match_tag_free};
567
568 /* Set metric to attribute. */
569 static enum route_map_match_result_t
570 route_set_metric(void *rule, struct prefix *prefix,
571 route_map_object_t type, void *object)
572 {
573 // if (type == RMAP_RIP)
574 // {
575 // struct rip_metric_modifier *mod;
576 // struct rip_info *rinfo;
577 //
578 // mod = rule;
579 // rinfo = object;
580 //
581 // /*if (mod->type == metric_increment)
582 // rinfo->metric_out += mod->metric;
583 // else if (mod->type == metric_decrement)
584 // rinfo->metric_out -= mod->metric;
585 // else if (mod->type == metric_absolute)
586 // rinfo->metric_out = mod->metric;
587 //
588 // if ((signed int)rinfo->metric_out < 1)
589 // rinfo->metric_out = 1;
590 // if (rinfo->metric_out > RIP_METRIC_INFINITY)
591 // rinfo->metric_out = RIP_METRIC_INFINITY;*/
592 //
593 // rinfo->metric_set = 1;
594 // }
595 return RMAP_OKAY;
596 }
597
598 /* set metric compilation. */
599 static void *route_set_metric_compile(const char *arg)
600 {
601 // int len;
602 // const char *pnt;
603 // int type;
604 // long metric;
605 // char *endptr = NULL;
606 // struct rip_metric_modifier *mod;
607 //
608 // len = strlen (arg);
609 // pnt = arg;
610 //
611 // if (len == 0)
612 // return NULL;
613 //
614 // /* Examine first character. */
615 // if (arg[0] == '+')
616 // {
617 // //type = metric_increment;
618 // pnt++;
619 // }
620 // else if (arg[0] == '-')
621 // {
622 // //type = metric_decrement;
623 // pnt++;
624 // }
625 // /*else
626 // type = metric_absolute;*/
627 //
628 // /* Check beginning with digit string. */
629 // if (*pnt < '0' || *pnt > '9')
630 // return NULL;
631 //
632 // /* Convert string to integer. */
633 // metric = strtol (pnt, &endptr, 10);
634 //
635 // if (metric == LONG_MAX || *endptr != '\0')
636 // return NULL;
637 // /*if (metric < 0 || metric > RIP_METRIC_INFINITY)
638 // return NULL;*/
639 //
640 // mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
641 // sizeof (struct rip_metric_modifier));
642 // mod->type = type;
643 // mod->metric = metric;
644
645 // return mod;
646 }
647
648 /* Free route map's compiled `set metric' value. */
649 static void route_set_metric_free(void *rule)
650 {
651 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
652 }
653
654 /* Set metric rule structure. */
655 static struct route_map_rule_cmd route_set_metric_cmd = {
656 "metric", route_set_metric, route_set_metric_compile,
657 route_set_metric_free,
658 };
659
660 /* `set ip next-hop IP_ADDRESS' */
661
662 /* Set nexthop to object. ojbect must be pointer to struct attr. */
663 static enum route_map_match_result_t
664 route_set_ip_nexthop(void *rule, struct prefix *prefix,
665 route_map_object_t type, void *object)
666 {
667 // struct in_addr *address;
668 // struct rip_info *rinfo;
669 //
670 // if(type == RMAP_RIP)
671 // {
672 // /* Fetch routemap's rule information. */
673 // address = rule;
674 // rinfo = object;
675 //
676 // /* Set next hop value. */
677 // rinfo->nexthop_out = *address;
678 // }
679
680 return RMAP_OKAY;
681 }
682
683 /* Route map `ip nexthop' compile function. Given string is converted
684 to struct in_addr structure. */
685 static void *route_set_ip_nexthop_compile(const char *arg)
686 {
687 // int ret;
688 // struct in_addr *address;
689 //
690 // address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct
691 // in_addr));
692 //
693 // ret = inet_aton (arg, address);
694 //
695 // if (ret == 0)
696 // {
697 // XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
698 // return NULL;
699 // }
700 //
701 // return address;
702 }
703
704 /* Free route map's compiled `ip nexthop' value. */
705 static void route_set_ip_nexthop_free(void *rule)
706 {
707 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
708 }
709
710 /* Route map commands for ip nexthop set. */
711 static struct route_map_rule_cmd route_set_ip_nexthop_cmd = {
712 "ip next-hop", route_set_ip_nexthop, route_set_ip_nexthop_compile,
713 route_set_ip_nexthop_free};
714
715 /* `set tag TAG' */
716
717 /* Set tag to object. ojbect must be pointer to struct attr. */
718 static enum route_map_match_result_t
719 route_set_tag(void *rule, struct prefix *prefix,
720 route_map_object_t type, void *object)
721 {
722 // unsigned short *tag;
723 // struct rip_info *rinfo;
724 //
725 // if(type == RMAP_RIP)
726 // {
727 // /* Fetch routemap's rule information. */
728 // tag = rule;
729 // rinfo = object;
730 //
731 // /* Set next hop value. */
732 // rinfo->tag_out = *tag;
733 // }
734
735 return RMAP_OKAY;
736 }
737
738 /* Route map `tag' compile function. Given string is converted
739 to unsigned short. */
740 static void *route_set_tag_compile(const char *arg)
741 {
742 // unsigned short *tag;
743 //
744 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short));
745 // *tag = atoi (arg);
746 //
747 // return tag;
748 }
749
750 /* Free route map's compiled `ip nexthop' value. */
751 static void route_set_tag_free(void *rule)
752 {
753 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
754 }
755
756 /* Route map commands for tag set. */
757 static struct route_map_rule_cmd route_set_tag_cmd = {
758 "tag", route_set_tag, route_set_tag_compile, route_set_tag_free};
759
760 #define MATCH_STR "Match values from routing table\n"
761 #define SET_STR "Set values in destination routing protocol\n"
762
763 DEFUN (match_metric,
764 match_metric_cmd,
765 "match metric <0-4294967295>",
766 MATCH_STR
767 "Match metric of route\n"
768 "Metric value\n")
769 {
770 return eigrp_route_match_add(vty, vty->index, "metric", argv[0]);
771 }
772
773 DEFUN (no_match_metric,
774 no_match_metric_cmd,
775 "no match metric",
776 NO_STR
777 MATCH_STR
778 "Match metric of route\n")
779 {
780 if (argc == 0)
781 return eigrp_route_match_delete(vty, vty->index, "metric",
782 NULL);
783
784 return eigrp_route_match_delete(vty, vty->index, "metric", argv[0]);
785 }
786
787 ALIAS(no_match_metric, no_match_metric_val_cmd,
788 "no match metric <0-4294967295>", NO_STR MATCH_STR
789 "Match metric of route\n"
790 "Metric value\n")
791
792 DEFUN (match_interface,
793 match_interface_cmd,
794 "match interface WORD",
795 MATCH_STR
796 "Match first hop interface of route\n"
797 "Interface name\n")
798 {
799 return eigrp_route_match_add(vty, vty->index, "interface", argv[0]);
800 }
801
802 DEFUN (no_match_interface,
803 no_match_interface_cmd,
804 "no match interface",
805 NO_STR
806 MATCH_STR
807 "Match first hop interface of route\n")
808 {
809 if (argc == 0)
810 return eigrp_route_match_delete(vty, vty->index, "interface",
811 NULL);
812
813 return eigrp_route_match_delete(vty, vty->index, "interface", argv[0]);
814 }
815
816 ALIAS(no_match_interface, no_match_interface_val_cmd, "no match interface WORD",
817 NO_STR MATCH_STR
818 "Match first hop interface of route\n"
819 "Interface name\n")
820
821 DEFUN (match_ip_next_hop,
822 match_ip_next_hop_cmd,
823 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
824 MATCH_STR
825 IP_STR
826 "Match next-hop address of route\n"
827 "IP access-list number\n"
828 "IP access-list number (expanded range)\n"
829 "IP Access-list name\n")
830 {
831 return eigrp_route_match_add(vty, vty->index, "ip next-hop", argv[0]);
832 }
833
834 DEFUN (no_match_ip_next_hop,
835 no_match_ip_next_hop_cmd,
836 "no match ip next-hop",
837 NO_STR
838 MATCH_STR
839 IP_STR
840 "Match next-hop address of route\n")
841 {
842 if (argc == 0)
843 return eigrp_route_match_delete(vty, vty->index, "ip next-hop",
844 NULL);
845
846 return eigrp_route_match_delete(vty, vty->index, "ip next-hop",
847 argv[0]);
848 }
849
850 ALIAS(no_match_ip_next_hop, no_match_ip_next_hop_val_cmd,
851 "no match ip next-hop (<1-199>|<1300-2699>|WORD)", NO_STR MATCH_STR IP_STR
852 "Match next-hop address of route\n"
853 "IP access-list number\n"
854 "IP access-list number (expanded range)\n"
855 "IP Access-list name\n")
856
857 DEFUN (match_ip_next_hop_prefix_list,
858 match_ip_next_hop_prefix_list_cmd,
859 "match ip next-hop prefix-list WORD",
860 MATCH_STR
861 IP_STR
862 "Match next-hop address of route\n"
863 "Match entries of prefix-lists\n"
864 "IP prefix-list name\n")
865 {
866 return eigrp_route_match_add(vty, vty->index, "ip next-hop prefix-list",
867 argv[0]);
868 }
869
870 DEFUN (no_match_ip_next_hop_prefix_list,
871 no_match_ip_next_hop_prefix_list_cmd,
872 "no match ip next-hop prefix-list",
873 NO_STR
874 MATCH_STR
875 IP_STR
876 "Match next-hop address of route\n"
877 "Match entries of prefix-lists\n")
878 {
879 if (argc == 0)
880 return eigrp_route_match_delete(
881 vty, vty->index, "ip next-hop prefix-list", NULL);
882
883 return eigrp_route_match_delete(vty, vty->index,
884 "ip next-hop prefix-list", argv[0]);
885 }
886
887 ALIAS(no_match_ip_next_hop_prefix_list,
888 no_match_ip_next_hop_prefix_list_val_cmd,
889 "no match ip next-hop prefix-list WORD", NO_STR MATCH_STR IP_STR
890 "Match next-hop address of route\n"
891 "Match entries of prefix-lists\n"
892 "IP prefix-list name\n")
893
894 DEFUN (match_ip_address,
895 match_ip_address_cmd,
896 "match ip address (<1-199>|<1300-2699>|WORD)",
897 MATCH_STR
898 IP_STR
899 "Match address of route\n"
900 "IP access-list number\n"
901 "IP access-list number (expanded range)\n"
902 "IP Access-list name\n")
903 {
904 return eigrp_route_match_add(vty, vty->index, "ip address", argv[0]);
905 }
906
907 DEFUN (no_match_ip_address,
908 no_match_ip_address_cmd,
909 "no match ip address",
910 NO_STR
911 MATCH_STR
912 IP_STR
913 "Match address of route\n")
914 {
915 if (argc == 0)
916 return eigrp_route_match_delete(vty, vty->index, "ip address",
917 NULL);
918
919 return eigrp_route_match_delete(vty, vty->index, "ip address", argv[0]);
920 }
921
922 ALIAS(no_match_ip_address, no_match_ip_address_val_cmd,
923 "no match ip address (<1-199>|<1300-2699>|WORD)", NO_STR MATCH_STR IP_STR
924 "Match address of route\n"
925 "IP access-list number\n"
926 "IP access-list number (expanded range)\n"
927 "IP Access-list name\n")
928
929 DEFUN (match_ip_address_prefix_list,
930 match_ip_address_prefix_list_cmd,
931 "match ip address prefix-list WORD",
932 MATCH_STR
933 IP_STR
934 "Match address of route\n"
935 "Match entries of prefix-lists\n"
936 "IP prefix-list name\n")
937 {
938 return eigrp_route_match_add(vty, vty->index, "ip address prefix-list",
939 argv[0]);
940 }
941
942 DEFUN (no_match_ip_address_prefix_list,
943 no_match_ip_address_prefix_list_cmd,
944 "no match ip address prefix-list",
945 NO_STR
946 MATCH_STR
947 IP_STR
948 "Match 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,
953 "ip address prefix-list", NULL);
954
955 return eigrp_route_match_delete(vty, vty->index,
956 "ip address prefix-list", argv[0]);
957 }
958
959 ALIAS(no_match_ip_address_prefix_list, no_match_ip_address_prefix_list_val_cmd,
960 "no match ip address prefix-list WORD", NO_STR MATCH_STR IP_STR
961 "Match address of route\n"
962 "Match entries of prefix-lists\n"
963 "IP prefix-list name\n")
964
965 DEFUN (match_tag,
966 match_tag_cmd,
967 "match tag <0-65535>",
968 MATCH_STR
969 "Match tag of route\n"
970 "Metric value\n")
971 {
972 return eigrp_route_match_add(vty, vty->index, "tag", argv[0]);
973 }
974
975 DEFUN (no_match_tag,
976 no_match_tag_cmd,
977 "no match tag",
978 NO_STR
979 MATCH_STR
980 "Match tag of route\n")
981 {
982 if (argc == 0)
983 return eigrp_route_match_delete(vty, vty->index, "tag", NULL);
984
985 return eigrp_route_match_delete(vty, vty->index, "tag", argv[0]);
986 }
987
988 ALIAS(no_match_tag, no_match_tag_val_cmd, "no match tag <0-65535>",
989 NO_STR MATCH_STR
990 "Match tag of route\n"
991 "Metric value\n")
992
993 /* set functions */
994
995 DEFUN (set_metric,
996 set_metric_cmd,
997 "set metric <0-4294967295>",
998 SET_STR
999 "Metric value for destination routing protocol\n"
1000 "Metric value\n")
1001 {
1002 return eigrp_route_set_add(vty, vty->index, "metric", argv[0]);
1003 }
1004
1005 ALIAS(set_metric, set_metric_addsub_cmd, "set metric <+/-metric>", SET_STR
1006 "Metric value for destination routing protocol\n"
1007 "Add or subtract metric\n")
1008
1009 DEFUN (no_set_metric,
1010 no_set_metric_cmd,
1011 "no set metric",
1012 NO_STR
1013 SET_STR
1014 "Metric value for destination routing protocol\n")
1015 {
1016 if (argc == 0)
1017 return eigrp_route_set_delete(vty, vty->index, "metric", NULL);
1018
1019 return eigrp_route_set_delete(vty, vty->index, "metric", argv[0]);
1020 }
1021
1022 ALIAS(no_set_metric, no_set_metric_val_cmd,
1023 "no set metric (<0-4294967295>|<+/-metric>)", NO_STR SET_STR
1024 "Metric value for destination routing protocol\n"
1025 "Metric value\n"
1026 "Add or subtract metric\n")
1027
1028 DEFUN (set_ip_nexthop,
1029 set_ip_nexthop_cmd,
1030 "set ip next-hop A.B.C.D",
1031 SET_STR
1032 IP_STR
1033 "Next hop address\n"
1034 "IP address of next hop\n")
1035 {
1036 union sockunion su;
1037 int ret;
1038
1039 ret = str2sockunion(argv[0], &su);
1040 if (ret < 0) {
1041 vty_out(vty, "%% Malformed next-hop address\n");
1042 return CMD_WARNING_CONFIG_FAILED;
1043 }
1044
1045 return eigrp_route_set_add(vty, vty->index, "ip next-hop", argv[0]);
1046 }
1047
1048 DEFUN (no_set_ip_nexthop,
1049 no_set_ip_nexthop_cmd,
1050 "no set ip next-hop",
1051 NO_STR
1052 SET_STR
1053 IP_STR
1054 "Next hop address\n")
1055 {
1056 if (argc == 0)
1057 return eigrp_route_set_delete(vty, vty->index, "ip next-hop",
1058 NULL);
1059
1060 return eigrp_route_set_delete(vty, vty->index, "ip next-hop", argv[0]);
1061 }
1062
1063 ALIAS(no_set_ip_nexthop, no_set_ip_nexthop_val_cmd,
1064 "no set ip next-hop A.B.C.D", NO_STR SET_STR IP_STR
1065 "Next hop address\n"
1066 "IP address of next hop\n")
1067
1068 DEFUN (set_tag,
1069 set_tag_cmd,
1070 "set tag <0-65535>",
1071 SET_STR
1072 "Tag value for routing protocol\n"
1073 "Tag value\n")
1074 {
1075 return eigrp_route_set_add(vty, vty->index, "tag", argv[0]);
1076 }
1077
1078 DEFUN (no_set_tag,
1079 no_set_tag_cmd,
1080 "no set tag",
1081 NO_STR
1082 SET_STR
1083 "Tag value for routing protocol\n")
1084 {
1085 if (argc == 0)
1086 return eigrp_route_set_delete(vty, vty->index, "tag", NULL);
1087
1088 return eigrp_route_set_delete(vty, vty->index, "tag", argv[0]);
1089 }
1090
1091 ALIAS(no_set_tag, no_set_tag_val_cmd, "no set tag <0-65535>", NO_STR SET_STR
1092 "Tag value for routing protocol\n"
1093 "Tag value\n")
1094
1095
1096 /* Route-map init */
1097 void eigrp_route_map_init()
1098 {
1099 route_map_init();
1100 route_map_init_vty();
1101 route_map_add_hook(eigrp_route_map_update);
1102 route_map_delete_hook(eigrp_route_map_update);
1103
1104 /*route_map_install_match (&route_match_metric_cmd);
1105 route_map_install_match (&route_match_interface_cmd);*/
1106 /*route_map_install_match (&route_match_ip_next_hop_cmd);
1107 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
1108 route_map_install_match (&route_match_ip_address_cmd);
1109 route_map_install_match (&route_match_ip_address_prefix_list_cmd);*/
1110 /*route_map_install_match (&route_match_tag_cmd);*/
1111
1112 /*route_map_install_set (&route_set_metric_cmd);
1113 route_map_install_set (&route_set_ip_nexthop_cmd);
1114 route_map_install_set (&route_set_tag_cmd);*/
1115
1116 /*install_element (RMAP_NODE, &route_match_metric_cmd);
1117 install_element (RMAP_NODE, &no_match_metric_cmd);
1118 install_element (RMAP_NODE, &no_match_metric_val_cmd);
1119 install_element (RMAP_NODE, &route_match_interface_cmd);
1120 install_element (RMAP_NODE, &no_match_interface_cmd);
1121 install_element (RMAP_NODE, &no_match_interface_val_cmd);
1122 install_element (RMAP_NODE, &route_match_ip_next_hop_cmd);
1123 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
1124 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
1125 install_element (RMAP_NODE, &route_match_ip_next_hop_prefix_list_cmd);
1126 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
1127 install_element (RMAP_NODE,
1128 &no_match_ip_next_hop_prefix_list_val_cmd);*/
1129 /*install_element (RMAP_NODE, &route_match_ip_address_cmd);
1130 install_element (RMAP_NODE, &no_match_ip_address_cmd);
1131 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
1132 install_element (RMAP_NODE, &route_match_ip_address_prefix_list_cmd);
1133 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
1134 install_element (RMAP_NODE,
1135 &no_match_ip_address_prefix_list_val_cmd);*/
1136 /*install_element (RMAP_NODE, &route_match_tag_cmd);
1137 install_element (RMAP_NODE, &no_match_tag_cmd);
1138 install_element (RMAP_NODE, &no_match_tag_val_cmd);*/
1139
1140 /*install_element (RMAP_NODE, &set_metric_cmd);
1141 install_element (RMAP_NODE, &set_metric_addsub_cmd);
1142 install_element (RMAP_NODE, &no_set_metric_cmd);
1143 install_element (RMAP_NODE, &no_set_metric_val_cmd);
1144 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
1145 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
1146 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
1147 install_element (RMAP_NODE, &set_tag_cmd);
1148 install_element (RMAP_NODE, &no_set_tag_cmd);
1149 install_element (RMAP_NODE, &no_set_tag_val_cmd);*/
1150 }