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