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