]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_routemap.c
lib: make cmd_element & qobj_type const
[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
a36898e7 65 ifp = if_lookup_by_name(if_rmap->ifname);
d62a17ae 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{
cda7187d
DS
138 enum rmap_compile_rets ret;
139
e2c8d6ce 140 ret = route_map_add_match(index, command, arg, type);
9ca25fed
DS
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:
cda7187d
DS
151 /*
152 * Intentionally not handling these cases
153 */
9ca25fed 154 break;
d62a17ae 155 }
9ca25fed 156
d62a17ae 157 return CMD_SUCCESS;
7f57883e
DS
158}
159
160/* Delete rip route map rule. */
d62a17ae 161static int eigrp_route_match_delete(struct vty *vty,
162 struct route_map_index *index,
163 const char *command, const char *arg)
7f57883e 164{
cda7187d
DS
165 enum rmap_compile_rets ret;
166
909f3d56 167 ret = route_map_delete_match(index, command, arg, type);
9ca25fed
DS
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:
cda7187d
DS
178 /*
179 * These cases intentionally ignored
180 */
9ca25fed 181 break;
d62a17ae 182 }
9ca25fed 183
d62a17ae 184 return CMD_SUCCESS;
7f57883e
DS
185}
186
187/* Add eigrp route map rule. */
d62a17ae 188static int eigrp_route_set_add(struct vty *vty, struct route_map_index *index,
189 const char *command, const char *arg)
7f57883e 190{
cda7187d 191 enum rmap_compile_rets ret;
d62a17ae 192
193 ret = route_map_add_set(index, command, arg);
9ca25fed
DS
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");
d62a17ae 208 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 209 }
9ca25fed
DS
210 break;
211 case RMAP_COMPILE_SUCCESS:
cda7187d
DS
212 /*
213 * These cases intentionally left blank here
214 */
9ca25fed 215 break;
d62a17ae 216 }
9ca25fed 217
d62a17ae 218 return CMD_SUCCESS;
7f57883e
DS
219}
220
221/* Delete eigrp route map rule. */
d62a17ae 222static int eigrp_route_set_delete(struct vty *vty,
223 struct route_map_index *index,
224 const char *command, const char *arg)
7f57883e 225{
cda7187d 226 enum rmap_compile_rets ret;
d62a17ae 227
228 ret = route_map_delete_set(index, command, arg);
9ca25fed
DS
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:
cda7187d
DS
239 /*
240 * These cases intentionally not handled
241 */
9ca25fed 242 break;
d62a17ae 243 }
9ca25fed 244
d62a17ae 245 return CMD_SUCCESS;
7f57883e
DS
246}
247
248/* Hook function for updating route_map assignment. */
249/* ARGSUSED */
d62a17ae 250void eigrp_route_map_update(const char *notused)
7f57883e 251{
d62a17ae 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 }
7f57883e
DS
263}
264
265
7f57883e
DS
266/* `match metric METRIC' */
267/* Match function return 1 if match is success else return zero. */
b68885f9
LK
268static enum route_map_cmd_result_t
269route_match_metric(void *rule, struct prefix *prefix, route_map_object_t type,
270 void *object)
f9e5c9ca 271{
d7c0a89a
QY
272 // uint32_t *metric;
273 // uint32_t check;
d62a17ae 274 // struct rip_info *rinfo;
af0a6344 275 // struct eigrp_nexthop_entry *te;
d62a17ae 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;
7f57883e
DS
298}
299
300/* Route map `match metric' match statement. `arg' is METRIC value */
d62a17ae 301static void *route_match_metric_compile(const char *arg)
7f57883e 302{
d7c0a89a 303 // uint32_t *metric;
d62a17ae 304 //
d7c0a89a 305 // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (uint32_t));
d62a17ae 306 // *metric = atoi (arg);
307 //
308 // if(*metric > 0)
309 // return metric;
310 //
311 // XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
312 return NULL;
7f57883e
DS
313}
314
315/* Free route map's compiled `match metric' value. */
d62a17ae 316static void route_match_metric_free(void *rule)
7f57883e 317{
d62a17ae 318 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
319}
320
321/* Route map commands for metric matching. */
d62a17ae 322struct route_map_rule_cmd route_match_metric_cmd = {
323 "metric", route_match_metric, route_match_metric_compile,
324 route_match_metric_free};
7f57883e
DS
325
326/* `match interface IFNAME' */
327/* Match function return 1 if match is success else return zero. */
b68885f9
LK
328static enum route_map_cmd_result_t
329route_match_interface(void *rule, struct prefix *prefix,
330 route_map_object_t type, void *object)
f9e5c9ca 331{
d62a17ae 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;
7f57883e
DS
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? */
d62a17ae 357static void *route_match_interface_compile(const char *arg)
7f57883e 358{
d62a17ae 359 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
7f57883e
DS
360}
361
362/* Free route map's compiled `match interface' value. */
d62a17ae 363static void route_match_interface_free(void *rule)
7f57883e 364{
d62a17ae 365 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
366}
367
368/* Route map commands for interface matching. */
d62a17ae 369struct route_map_rule_cmd route_match_interface_cmd = {
370 "interface", route_match_interface, route_match_interface_compile,
371 route_match_interface_free};
7f57883e
DS
372
373/* `match ip next-hop IP_ACCESS_LIST' */
374
375/* Match function return 1 if match is success else return zero. */
b68885f9
LK
376static enum route_map_cmd_result_t
377route_match_ip_next_hop(void *rule, struct prefix *prefix,
378 route_map_object_t type, void *object)
f9e5c9ca 379{
d62a17ae 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;
7f57883e
DS
400}
401
402/* Route map `ip next-hop' match statement. `arg' should be
403 access-list name. */
d62a17ae 404static void *route_match_ip_next_hop_compile(const char *arg)
7f57883e 405{
d62a17ae 406 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
7f57883e
DS
407}
408
409/* Free route map's compiled `. */
d62a17ae 410static void route_match_ip_next_hop_free(void *rule)
7f57883e 411{
d62a17ae 412 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
413}
414
415/* Route map commands for ip next-hop matching. */
d62a17ae 416static 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};
7f57883e
DS
419
420/* `match ip next-hop prefix-list PREFIX_LIST' */
421
b68885f9 422static enum route_map_cmd_result_t
d62a17ae 423route_match_ip_next_hop_prefix_list(void *rule, struct prefix *prefix,
424 route_map_object_t type, void *object)
f9e5c9ca 425{
d62a17ae 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;
7f57883e
DS
446}
447
d62a17ae 448static void *route_match_ip_next_hop_prefix_list_compile(const char *arg)
7f57883e 449{
d62a17ae 450 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
7f57883e
DS
451}
452
d62a17ae 453static void route_match_ip_next_hop_prefix_list_free(void *rule)
7f57883e 454{
d62a17ae 455 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
456}
457
d62a17ae 458static 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};
7f57883e
DS
462
463/* `match ip address IP_ACCESS_LIST' */
464
465/* Match function should return 1 if match is success else return
466 zero. */
b68885f9
LK
467static enum route_map_cmd_result_t
468route_match_ip_address(void *rule, struct prefix *prefix,
469 route_map_object_t type, void *object)
7f57883e 470{
d62a17ae 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;
7f57883e
DS
483}
484
485/* Route map `ip address' match statement. `arg' should be
486 access-list name. */
d62a17ae 487static void *route_match_ip_address_compile(const char *arg)
7f57883e 488{
d62a17ae 489 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
7f57883e
DS
490}
491
492/* Free route map's compiled `ip address' value. */
d62a17ae 493static void route_match_ip_address_free(void *rule)
7f57883e 494{
d62a17ae 495 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
496}
497
498/* Route map commands for ip address matching. */
d62a17ae 499static 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};
7f57883e
DS
502
503/* `match ip address prefix-list PREFIX_LIST' */
504
b68885f9 505static enum route_map_cmd_result_t
d62a17ae 506route_match_ip_address_prefix_list(void *rule, struct prefix *prefix,
507 route_map_object_t type, void *object)
7f57883e 508{
d62a17ae 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;
7f57883e
DS
521}
522
d62a17ae 523static void *route_match_ip_address_prefix_list_compile(const char *arg)
7f57883e 524{
d62a17ae 525 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
7f57883e
DS
526}
527
d62a17ae 528static void route_match_ip_address_prefix_list_free(void *rule)
7f57883e 529{
d62a17ae 530 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
531}
532
d62a17ae 533static 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};
7f57883e
DS
537
538/* `match tag TAG' */
539/* Match function return 1 if match is success else return zero. */
b68885f9
LK
540static enum route_map_cmd_result_t
541route_match_tag(void *rule, struct prefix *prefix, route_map_object_t type,
542 void *object)
f9e5c9ca 543{
d7c0a89a 544 // unsigned short *tag;
d62a17ae 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;
7f57883e
DS
559}
560
561/* Route map `match tag' match statement. `arg' is TAG value */
d62a17ae 562static void *route_match_tag_compile(const char *arg)
7f57883e 563{
d7c0a89a 564 // unsigned short *tag;
d62a17ae 565 //
d7c0a89a 566 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short));
d62a17ae 567 // *tag = atoi (arg);
568 //
569 // return tag;
7f57883e
DS
570}
571
572/* Free route map's compiled `match tag' value. */
d62a17ae 573static void route_match_tag_free(void *rule)
7f57883e 574{
d62a17ae 575 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
576}
577
578/* Route map commands for tag matching. */
d62a17ae 579struct route_map_rule_cmd route_match_tag_cmd = {
580 "tag", route_match_tag, route_match_tag_compile, route_match_tag_free};
7f57883e
DS
581
582/* Set metric to attribute. */
b68885f9
LK
583static enum route_map_cmd_result_t
584route_set_metric(void *rule, struct prefix *prefix,
585 route_map_object_t type, void *object)
f9e5c9ca 586{
d62a17ae 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;
7f57883e
DS
610}
611
612/* set metric compilation. */
d62a17ae 613static void *route_set_metric_compile(const char *arg)
7f57883e 614{
d62a17ae 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;
7f57883e
DS
660}
661
662/* Free route map's compiled `set metric' value. */
d62a17ae 663static void route_set_metric_free(void *rule)
7f57883e 664{
d62a17ae 665 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
666}
667
668/* Set metric rule structure. */
d62a17ae 669static struct route_map_rule_cmd route_set_metric_cmd = {
9d303b37 670 "metric", route_set_metric, route_set_metric_compile,
d62a17ae 671 route_set_metric_free,
672};
7f57883e
DS
673
674/* `set ip next-hop IP_ADDRESS' */
675
676/* Set nexthop to object. ojbect must be pointer to struct attr. */
b68885f9
LK
677static enum route_map_cmd_result_t
678route_set_ip_nexthop(void *rule, struct prefix *prefix,
679 route_map_object_t type, void *object)
f9e5c9ca 680{
d62a17ae 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;
7f57883e
DS
695}
696
697/* Route map `ip nexthop' compile function. Given string is converted
698 to struct in_addr structure. */
d62a17ae 699static void *route_set_ip_nexthop_compile(const char *arg)
7f57883e 700{
d62a17ae 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;
7f57883e
DS
716}
717
718/* Free route map's compiled `ip nexthop' value. */
d62a17ae 719static void route_set_ip_nexthop_free(void *rule)
7f57883e 720{
d62a17ae 721 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
722}
723
724/* Route map commands for ip nexthop set. */
d62a17ae 725static 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};
7f57883e
DS
728
729/* `set tag TAG' */
730
731/* Set tag to object. ojbect must be pointer to struct attr. */
b68885f9
LK
732static enum route_map_cmd_result_t
733route_set_tag(void *rule, struct prefix *prefix,
734 route_map_object_t type, void *object)
f9e5c9ca 735{
d7c0a89a 736 // unsigned short *tag;
d62a17ae 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;
7f57883e
DS
750}
751
752/* Route map `tag' compile function. Given string is converted
d7c0a89a 753 to unsigned short. */
d62a17ae 754static void *route_set_tag_compile(const char *arg)
7f57883e 755{
d7c0a89a 756 // unsigned short *tag;
d62a17ae 757 //
d7c0a89a 758 // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short));
d62a17ae 759 // *tag = atoi (arg);
760 //
761 // return tag;
7f57883e
DS
762}
763
764/* Free route map's compiled `ip nexthop' value. */
d62a17ae 765static void route_set_tag_free(void *rule)
7f57883e 766{
d62a17ae 767 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
7f57883e
DS
768}
769
770/* Route map commands for tag set. */
d62a17ae 771static struct route_map_rule_cmd route_set_tag_cmd = {
772 "tag", route_set_tag, route_set_tag_compile, route_set_tag_free};
7f57883e
DS
773
774#define MATCH_STR "Match values from routing table\n"
775#define SET_STR "Set values in destination routing protocol\n"
776
777DEFUN (match_metric,
778 match_metric_cmd,
db684383 779 "match metric (0-4294967295)",
7f57883e
DS
780 MATCH_STR
781 "Match metric of route\n"
782 "Metric value\n")
783{
d62a17ae 784 return eigrp_route_match_add(vty, vty->index, "metric", argv[0]);
7f57883e
DS
785}
786
787DEFUN (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{
d62a17ae 794 if (argc == 0)
795 return eigrp_route_match_delete(vty, vty->index, "metric",
796 NULL);
7f57883e 797
d62a17ae 798 return eigrp_route_match_delete(vty, vty->index, "metric", argv[0]);
7f57883e
DS
799}
800
d62a17ae 801ALIAS(no_match_metric, no_match_metric_val_cmd,
db684383 802 "no match metric (0-4294967295)", NO_STR MATCH_STR
d62a17ae 803 "Match metric of route\n"
804 "Metric value\n")
7f57883e
DS
805
806DEFUN (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{
d62a17ae 813 return eigrp_route_match_add(vty, vty->index, "interface", argv[0]);
7f57883e
DS
814}
815
816DEFUN (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{
d62a17ae 823 if (argc == 0)
824 return eigrp_route_match_delete(vty, vty->index, "interface",
825 NULL);
7f57883e 826
d62a17ae 827 return eigrp_route_match_delete(vty, vty->index, "interface", argv[0]);
7f57883e
DS
828}
829
d62a17ae 830ALIAS(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")
7f57883e
DS
834
835DEFUN (match_ip_next_hop,
836 match_ip_next_hop_cmd,
db684383 837 "match ip next-hop ((1-199)|(1300-2699)|WORD)",
7f57883e
DS
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{
d62a17ae 845 return eigrp_route_match_add(vty, vty->index, "ip next-hop", argv[0]);
7f57883e
DS
846}
847
848DEFUN (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{
d62a17ae 856 if (argc == 0)
857 return eigrp_route_match_delete(vty, vty->index, "ip next-hop",
858 NULL);
7f57883e 859
d62a17ae 860 return eigrp_route_match_delete(vty, vty->index, "ip next-hop",
861 argv[0]);
7f57883e
DS
862}
863
d62a17ae 864ALIAS(no_match_ip_next_hop, no_match_ip_next_hop_val_cmd,
db684383 865 "no match ip next-hop ((1-199)|(1300-2699)|WORD)", NO_STR MATCH_STR IP_STR
d62a17ae 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")
7f57883e
DS
870
871DEFUN (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{
d62a17ae 880 return eigrp_route_match_add(vty, vty->index, "ip next-hop prefix-list",
881 argv[0]);
7f57883e
DS
882}
883
884DEFUN (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{
d62a17ae 893 if (argc == 0)
894 return eigrp_route_match_delete(
895 vty, vty->index, "ip next-hop prefix-list", NULL);
7f57883e 896
d62a17ae 897 return eigrp_route_match_delete(vty, vty->index,
898 "ip next-hop prefix-list", argv[0]);
7f57883e
DS
899}
900
d62a17ae 901ALIAS(no_match_ip_next_hop_prefix_list,
902 no_match_ip_next_hop_prefix_list_val_cmd,
9d303b37 903 "no match ip next-hop prefix-list WORD", NO_STR MATCH_STR IP_STR
d62a17ae 904 "Match next-hop address of route\n"
905 "Match entries of prefix-lists\n"
906 "IP prefix-list name\n")
7f57883e
DS
907
908DEFUN (match_ip_address,
909 match_ip_address_cmd,
db684383 910 "match ip address ((1-199)|(1300-2699)|WORD)",
7f57883e
DS
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")
7f57883e 917{
d62a17ae 918 return eigrp_route_match_add(vty, vty->index, "ip address", argv[0]);
7f57883e
DS
919}
920
921DEFUN (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{
d62a17ae 929 if (argc == 0)
930 return eigrp_route_match_delete(vty, vty->index, "ip address",
931 NULL);
7f57883e 932
d62a17ae 933 return eigrp_route_match_delete(vty, vty->index, "ip address", argv[0]);
7f57883e
DS
934}
935
d62a17ae 936ALIAS(no_match_ip_address, no_match_ip_address_val_cmd,
db684383 937 "no match ip address ((1-199)|(1300-2699)|WORD)", NO_STR MATCH_STR IP_STR
d62a17ae 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")
7f57883e
DS
942
943DEFUN (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{
d62a17ae 952 return eigrp_route_match_add(vty, vty->index, "ip address prefix-list",
953 argv[0]);
7f57883e
DS
954}
955
956DEFUN (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{
d62a17ae 965 if (argc == 0)
966 return eigrp_route_match_delete(vty, vty->index,
967 "ip address prefix-list", NULL);
7f57883e 968
d62a17ae 969 return eigrp_route_match_delete(vty, vty->index,
970 "ip address prefix-list", argv[0]);
7f57883e
DS
971}
972
d62a17ae 973ALIAS(no_match_ip_address_prefix_list, no_match_ip_address_prefix_list_val_cmd,
9d303b37 974 "no match ip address prefix-list WORD", NO_STR MATCH_STR IP_STR
d62a17ae 975 "Match address of route\n"
976 "Match entries of prefix-lists\n"
977 "IP prefix-list name\n")
7f57883e
DS
978
979DEFUN (match_tag,
980 match_tag_cmd,
db684383 981 "match tag (0-65535)",
7f57883e
DS
982 MATCH_STR
983 "Match tag of route\n"
984 "Metric value\n")
985{
d62a17ae 986 return eigrp_route_match_add(vty, vty->index, "tag", argv[0]);
7f57883e
DS
987}
988
989DEFUN (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{
d62a17ae 996 if (argc == 0)
997 return eigrp_route_match_delete(vty, vty->index, "tag", NULL);
7f57883e 998
d62a17ae 999 return eigrp_route_match_delete(vty, vty->index, "tag", argv[0]);
7f57883e
DS
1000}
1001
db684383 1002ALIAS(no_match_tag, no_match_tag_val_cmd, "no match tag (0-65535)",
d62a17ae 1003 NO_STR MATCH_STR
1004 "Match tag of route\n"
1005 "Metric value\n")
7f57883e
DS
1006
1007/* set functions */
1008
1009DEFUN (set_metric,
1010 set_metric_cmd,
db684383 1011 "set metric (0-4294967295)",
7f57883e
DS
1012 SET_STR
1013 "Metric value for destination routing protocol\n"
1014 "Metric value\n")
1015{
d62a17ae 1016 return eigrp_route_set_add(vty, vty->index, "metric", argv[0]);
7f57883e
DS
1017}
1018
9d303b37 1019ALIAS(set_metric, set_metric_addsub_cmd, "set metric <+/-metric>", SET_STR
d62a17ae 1020 "Metric value for destination routing protocol\n"
1021 "Add or subtract metric\n")
7f57883e
DS
1022
1023DEFUN (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{
d62a17ae 1030 if (argc == 0)
1031 return eigrp_route_set_delete(vty, vty->index, "metric", NULL);
7f57883e 1032
d62a17ae 1033 return eigrp_route_set_delete(vty, vty->index, "metric", argv[0]);
7f57883e
DS
1034}
1035
d62a17ae 1036ALIAS(no_set_metric, no_set_metric_val_cmd,
db684383 1037 "no set metric ((0-4294967295)|<+/-metric>)", NO_STR SET_STR
d62a17ae 1038 "Metric value for destination routing protocol\n"
1039 "Metric value\n"
1040 "Add or subtract metric\n")
7f57883e
DS
1041
1042DEFUN (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{
d62a17ae 1050 union sockunion su;
1051 int ret;
7f57883e 1052
d62a17ae 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 }
7f57883e 1058
d62a17ae 1059 return eigrp_route_set_add(vty, vty->index, "ip next-hop", argv[0]);
7f57883e
DS
1060}
1061
1062DEFUN (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{
d62a17ae 1070 if (argc == 0)
1071 return eigrp_route_set_delete(vty, vty->index, "ip next-hop",
1072 NULL);
7f57883e 1073
d62a17ae 1074 return eigrp_route_set_delete(vty, vty->index, "ip next-hop", argv[0]);
7f57883e
DS
1075}
1076
d62a17ae 1077ALIAS(no_set_ip_nexthop, no_set_ip_nexthop_val_cmd,
9d303b37 1078 "no set ip next-hop A.B.C.D", NO_STR SET_STR IP_STR
d62a17ae 1079 "Next hop address\n"
1080 "IP address of next hop\n")
7f57883e
DS
1081
1082DEFUN (set_tag,
1083 set_tag_cmd,
db684383 1084 "set tag (0-65535)",
7f57883e
DS
1085 SET_STR
1086 "Tag value for routing protocol\n"
1087 "Tag value\n")
1088{
d62a17ae 1089 return eigrp_route_set_add(vty, vty->index, "tag", argv[0]);
7f57883e
DS
1090}
1091
1092DEFUN (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{
d62a17ae 1099 if (argc == 0)
1100 return eigrp_route_set_delete(vty, vty->index, "tag", NULL);
7f57883e 1101
d62a17ae 1102 return eigrp_route_set_delete(vty, vty->index, "tag", argv[0]);
7f57883e
DS
1103}
1104
db684383 1105ALIAS(no_set_tag, no_set_tag_val_cmd, "no set tag (0-65535)", NO_STR SET_STR
d62a17ae 1106 "Tag value for routing protocol\n"
1107 "Tag value\n")
7f57883e
DS
1108
1109
1110/* Route-map init */
d62a17ae 1111void eigrp_route_map_init()
7f57883e 1112{
d62a17ae 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);*/
7f57883e 1164}