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