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