]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* RIPng routemap. |
2 | * Copyright (C) 1999 Kunihiro Ishiguro | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | * 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "if.h" | |
25 | #include "memory.h" | |
26 | #include "prefix.h" | |
27 | #include "routemap.h" | |
28 | #include "command.h" | |
a94434b6 | 29 | #include "sockunion.h" |
718e3744 | 30 | |
31 | #include "ripngd/ripngd.h" | |
6b0655a2 | 32 | |
a94434b6 | 33 | struct rip_metric_modifier |
34 | { | |
35 | enum | |
36 | { | |
37 | metric_increment, | |
38 | metric_decrement, | |
39 | metric_absolute | |
40 | } type; | |
41 | ||
42 | u_char metric; | |
43 | }; | |
44 | ||
6b0655a2 | 45 | |
6ac29a51 | 46 | static int |
a94434b6 | 47 | ripng_route_match_add (struct vty *vty, struct route_map_index *index, |
98b718a9 | 48 | const char *command, const char *arg) |
a94434b6 | 49 | { |
50 | int ret; | |
51 | ||
52 | ret = route_map_add_match (index, command, arg); | |
53 | if (ret) | |
54 | { | |
55 | switch (ret) | |
56 | { | |
57 | case RMAP_RULE_MISSING: | |
5e3edbf5 | 58 | vty_out (vty, "RIPng Can't find rule.%s", VTY_NEWLINE); |
a94434b6 | 59 | return CMD_WARNING; |
a94434b6 | 60 | case RMAP_COMPILE_ERROR: |
5e3edbf5 | 61 | vty_out (vty, "RIPng Argument is malformed.%s", VTY_NEWLINE); |
a94434b6 | 62 | return CMD_WARNING; |
a94434b6 | 63 | } |
64 | } | |
65 | return CMD_SUCCESS; | |
66 | } | |
67 | ||
6ac29a51 | 68 | static int |
a94434b6 | 69 | ripng_route_match_delete (struct vty *vty, struct route_map_index *index, |
98b718a9 | 70 | const char *command, const char *arg) |
a94434b6 | 71 | { |
72 | int ret; | |
73 | ||
74 | ret = route_map_delete_match (index, command, arg); | |
75 | if (ret) | |
76 | { | |
77 | switch (ret) | |
78 | { | |
79 | case RMAP_RULE_MISSING: | |
5e3edbf5 | 80 | vty_out (vty, "RIPng Can't find rule.%s", VTY_NEWLINE); |
a94434b6 | 81 | return CMD_WARNING; |
a94434b6 | 82 | case RMAP_COMPILE_ERROR: |
5e3edbf5 | 83 | vty_out (vty, "RIPng Argument is malformed.%s", VTY_NEWLINE); |
a94434b6 | 84 | return CMD_WARNING; |
a94434b6 | 85 | } |
86 | } | |
87 | return CMD_SUCCESS; | |
88 | } | |
89 | ||
6ac29a51 | 90 | static int |
a94434b6 | 91 | ripng_route_set_add (struct vty *vty, struct route_map_index *index, |
98b718a9 | 92 | const char *command, const char *arg) |
a94434b6 | 93 | { |
94 | int ret; | |
95 | ||
96 | ret = route_map_add_set (index, command, arg); | |
97 | if (ret) | |
98 | { | |
99 | switch (ret) | |
100 | { | |
101 | case RMAP_RULE_MISSING: | |
5e3edbf5 | 102 | vty_out (vty, "RIPng Can't find rule.%s", VTY_NEWLINE); |
a94434b6 | 103 | return CMD_WARNING; |
a94434b6 | 104 | case RMAP_COMPILE_ERROR: |
5e3edbf5 | 105 | vty_out (vty, "RIPng Argument is malformed.%s", VTY_NEWLINE); |
a94434b6 | 106 | return CMD_WARNING; |
a94434b6 | 107 | } |
108 | } | |
109 | return CMD_SUCCESS; | |
110 | } | |
111 | ||
6ac29a51 | 112 | static int |
a94434b6 | 113 | ripng_route_set_delete (struct vty *vty, struct route_map_index *index, |
98b718a9 | 114 | const char *command, const char *arg) |
a94434b6 | 115 | { |
116 | int ret; | |
117 | ||
118 | ret = route_map_delete_set (index, command, arg); | |
119 | if (ret) | |
120 | { | |
121 | switch (ret) | |
122 | { | |
123 | case RMAP_RULE_MISSING: | |
5e3edbf5 | 124 | vty_out (vty, "RIPng Can't find rule.%s", VTY_NEWLINE); |
a94434b6 | 125 | return CMD_WARNING; |
a94434b6 | 126 | case RMAP_COMPILE_ERROR: |
5e3edbf5 | 127 | vty_out (vty, "RIPng Argument is malformed.%s", VTY_NEWLINE); |
a94434b6 | 128 | return CMD_WARNING; |
a94434b6 | 129 | } |
130 | } | |
131 | return CMD_SUCCESS; | |
132 | } | |
6b0655a2 | 133 | |
a94434b6 | 134 | /* `match metric METRIC' */ |
135 | /* Match function return 1 if match is success else return zero. */ | |
6ac29a51 | 136 | static route_map_result_t |
a94434b6 | 137 | route_match_metric (void *rule, struct prefix *prefix, |
138 | route_map_object_t type, void *object) | |
139 | { | |
140 | u_int32_t *metric; | |
141 | struct ripng_info *rinfo; | |
142 | ||
143 | if (type == RMAP_RIPNG) | |
144 | { | |
145 | metric = rule; | |
146 | rinfo = object; | |
147 | ||
148 | if (rinfo->metric == *metric) | |
149 | return RMAP_MATCH; | |
150 | else | |
151 | return RMAP_NOMATCH; | |
152 | } | |
153 | return RMAP_NOMATCH; | |
154 | } | |
155 | ||
156 | /* Route map `match metric' match statement. `arg' is METRIC value */ | |
6ac29a51 | 157 | static void * |
98b718a9 | 158 | route_match_metric_compile (const char *arg) |
a94434b6 | 159 | { |
160 | u_int32_t *metric; | |
161 | ||
162 | metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); | |
163 | *metric = atoi (arg); | |
164 | ||
165 | if(*metric > 0) | |
166 | return metric; | |
167 | ||
168 | XFREE (MTYPE_ROUTE_MAP_COMPILED, metric); | |
169 | return NULL; | |
170 | } | |
171 | ||
172 | /* Free route map's compiled `match metric' value. */ | |
6ac29a51 | 173 | static void |
a94434b6 | 174 | route_match_metric_free (void *rule) |
175 | { | |
176 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
177 | } | |
178 | ||
179 | /* Route map commands for metric matching. */ | |
6ac29a51 | 180 | static struct route_map_rule_cmd route_match_metric_cmd = |
a94434b6 | 181 | { |
182 | "metric", | |
183 | route_match_metric, | |
184 | route_match_metric_compile, | |
185 | route_match_metric_free | |
186 | }; | |
6b0655a2 | 187 | |
718e3744 | 188 | /* `match interface IFNAME' */ |
a94434b6 | 189 | /* Match function return 1 if match is success else return zero. */ |
6ac29a51 | 190 | static route_map_result_t |
718e3744 | 191 | route_match_interface (void *rule, struct prefix *prefix, |
192 | route_map_object_t type, void *object) | |
193 | { | |
194 | struct ripng_info *rinfo; | |
195 | struct interface *ifp; | |
196 | char *ifname; | |
197 | ||
a94434b6 | 198 | if (type == RMAP_RIPNG) |
718e3744 | 199 | { |
200 | ifname = rule; | |
201 | ifp = if_lookup_by_name(ifname); | |
202 | ||
203 | if (!ifp) | |
a94434b6 | 204 | return RMAP_NOMATCH; |
718e3744 | 205 | |
206 | rinfo = object; | |
207 | ||
208 | if (rinfo->ifindex == ifp->ifindex) | |
a94434b6 | 209 | return RMAP_MATCH; |
718e3744 | 210 | else |
a94434b6 | 211 | return RMAP_NOMATCH; |
718e3744 | 212 | } |
a94434b6 | 213 | return RMAP_NOMATCH; |
718e3744 | 214 | } |
215 | ||
a94434b6 | 216 | /* Route map `match interface' match statement. `arg' is IFNAME value */ |
6ac29a51 | 217 | static void * |
98b718a9 | 218 | route_match_interface_compile (const char *arg) |
718e3744 | 219 | { |
220 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); | |
221 | } | |
222 | ||
6ac29a51 | 223 | static void |
718e3744 | 224 | route_match_interface_free (void *rule) |
225 | { | |
226 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
227 | } | |
228 | ||
6ac29a51 | 229 | static struct route_map_rule_cmd route_match_interface_cmd = |
718e3744 | 230 | { |
231 | "interface", | |
232 | route_match_interface, | |
233 | route_match_interface_compile, | |
234 | route_match_interface_free | |
235 | }; | |
a94434b6 | 236 | |
237 | /* `match tag TAG' */ | |
238 | /* Match function return 1 if match is success else return zero. */ | |
6ac29a51 | 239 | static route_map_result_t |
a94434b6 | 240 | route_match_tag (void *rule, struct prefix *prefix, |
241 | route_map_object_t type, void *object) | |
718e3744 | 242 | { |
a94434b6 | 243 | u_short *tag; |
244 | struct ripng_info *rinfo; | |
718e3744 | 245 | |
a94434b6 | 246 | if (type == RMAP_RIPNG) |
247 | { | |
248 | tag = rule; | |
249 | rinfo = object; | |
250 | ||
251 | /* The information stored by rinfo is host ordered. */ | |
252 | if (rinfo->tag == *tag) | |
253 | return RMAP_MATCH; | |
254 | else | |
255 | return RMAP_NOMATCH; | |
256 | } | |
257 | return RMAP_NOMATCH; | |
258 | } | |
259 | ||
260 | /* Route map `match tag' match statement. `arg' is TAG value */ | |
6ac29a51 | 261 | static void * |
98b718a9 | 262 | route_match_tag_compile (const char *arg) |
a94434b6 | 263 | { |
264 | u_short *tag; | |
265 | ||
266 | tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); | |
267 | *tag = atoi (arg); | |
268 | ||
269 | return tag; | |
270 | } | |
271 | ||
272 | /* Free route map's compiled `match tag' value. */ | |
6ac29a51 | 273 | static void |
a94434b6 | 274 | route_match_tag_free (void *rule) |
275 | { | |
276 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
277 | } | |
278 | ||
279 | /* Route map commands for tag matching. */ | |
6ac29a51 | 280 | static struct route_map_rule_cmd route_match_tag_cmd = |
a94434b6 | 281 | { |
282 | "tag", | |
283 | route_match_tag, | |
284 | route_match_tag_compile, | |
285 | route_match_tag_free | |
718e3744 | 286 | }; |
6b0655a2 | 287 | |
a94434b6 | 288 | /* `set metric METRIC' */ |
718e3744 | 289 | |
a94434b6 | 290 | /* Set metric to attribute. */ |
6ac29a51 | 291 | static route_map_result_t |
718e3744 | 292 | route_set_metric (void *rule, struct prefix *prefix, |
293 | route_map_object_t type, void *object) | |
294 | { | |
295 | if (type == RMAP_RIPNG) | |
296 | { | |
297 | struct rip_metric_modifier *mod; | |
298 | struct ripng_info *rinfo; | |
299 | ||
300 | mod = rule; | |
301 | rinfo = object; | |
302 | ||
303 | if (mod->type == metric_increment) | |
a94434b6 | 304 | rinfo->metric_out += mod->metric; |
718e3744 | 305 | else if (mod->type == metric_decrement) |
a94434b6 | 306 | rinfo->metric_out-= mod->metric; |
718e3744 | 307 | else if (mod->type == metric_absolute) |
a94434b6 | 308 | rinfo->metric_out = mod->metric; |
718e3744 | 309 | |
a94434b6 | 310 | if (rinfo->metric_out < 1) |
311 | rinfo->metric_out = 1; | |
312 | if (rinfo->metric_out > RIPNG_METRIC_INFINITY) | |
313 | rinfo->metric_out = RIPNG_METRIC_INFINITY; | |
718e3744 | 314 | |
315 | rinfo->metric_set = 1; | |
316 | } | |
317 | return RMAP_OKAY; | |
318 | } | |
319 | ||
a94434b6 | 320 | /* set metric compilation. */ |
6ac29a51 | 321 | static void * |
98b718a9 | 322 | route_set_metric_compile (const char *arg) |
718e3744 | 323 | { |
324 | int len; | |
98b718a9 | 325 | const char *pnt; |
718e3744 | 326 | int type; |
327 | long metric; | |
328 | char *endptr = NULL; | |
329 | struct rip_metric_modifier *mod; | |
330 | ||
331 | len = strlen (arg); | |
332 | pnt = arg; | |
333 | ||
334 | if (len == 0) | |
335 | return NULL; | |
336 | ||
337 | /* Examine first character. */ | |
338 | if (arg[0] == '+') | |
339 | { | |
340 | type = metric_increment; | |
341 | pnt++; | |
342 | } | |
343 | else if (arg[0] == '-') | |
344 | { | |
345 | type = metric_decrement; | |
346 | pnt++; | |
347 | } | |
348 | else | |
349 | type = metric_absolute; | |
350 | ||
351 | /* Check beginning with digit string. */ | |
352 | if (*pnt < '0' || *pnt > '9') | |
353 | return NULL; | |
354 | ||
355 | /* Convert string to integer. */ | |
356 | metric = strtol (pnt, &endptr, 10); | |
357 | ||
358 | if (metric == LONG_MAX || *endptr != '\0') | |
359 | return NULL; | |
73ffb25b | 360 | /* Commented out by Hasso Tepper, to avoid problems in vtysh. */ |
361 | /* if (metric < 0 || metric > RIPNG_METRIC_INFINITY) */ | |
362 | if (metric < 0) | |
718e3744 | 363 | return NULL; |
364 | ||
365 | mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, | |
366 | sizeof (struct rip_metric_modifier)); | |
367 | mod->type = type; | |
368 | mod->metric = metric; | |
369 | ||
370 | return mod; | |
371 | } | |
372 | ||
a94434b6 | 373 | /* Free route map's compiled `set metric' value. */ |
6ac29a51 | 374 | static void |
718e3744 | 375 | route_set_metric_free (void *rule) |
376 | { | |
377 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
378 | } | |
379 | ||
6ac29a51 | 380 | static struct route_map_rule_cmd route_set_metric_cmd = |
718e3744 | 381 | { |
382 | "metric", | |
383 | route_set_metric, | |
384 | route_set_metric_compile, | |
385 | route_set_metric_free, | |
386 | }; | |
a94434b6 | 387 | |
388 | /* `set ipv6 next-hop local IP_ADDRESS' */ | |
389 | ||
390 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ | |
6ac29a51 | 391 | static route_map_result_t |
a94434b6 | 392 | route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix, |
393 | route_map_object_t type, void *object) | |
718e3744 | 394 | { |
a94434b6 | 395 | struct in6_addr *address; |
396 | struct ripng_info *rinfo; | |
718e3744 | 397 | |
a94434b6 | 398 | if(type == RMAP_RIPNG) |
718e3744 | 399 | { |
a94434b6 | 400 | /* Fetch routemap's rule information. */ |
401 | address = rule; | |
402 | rinfo = object; | |
403 | ||
404 | /* Set next hop value. */ | |
405 | rinfo->nexthop_out = *address; | |
718e3744 | 406 | } |
a94434b6 | 407 | |
408 | return RMAP_OKAY; | |
718e3744 | 409 | } |
410 | ||
a94434b6 | 411 | /* Route map `ipv6 nexthop local' compile function. Given string is converted |
412 | to struct in6_addr structure. */ | |
6ac29a51 | 413 | static void * |
98b718a9 | 414 | route_set_ipv6_nexthop_local_compile (const char *arg) |
718e3744 | 415 | { |
416 | int ret; | |
a94434b6 | 417 | struct in6_addr *address; |
718e3744 | 418 | |
7a559cbe | 419 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); |
a94434b6 | 420 | |
421 | ret = inet_pton (AF_INET6, arg, address); | |
422 | ||
423 | if (ret == 0) | |
718e3744 | 424 | { |
a94434b6 | 425 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
426 | return NULL; | |
718e3744 | 427 | } |
a94434b6 | 428 | |
429 | return address; | |
718e3744 | 430 | } |
431 | ||
a94434b6 | 432 | /* Free route map's compiled `ipv6 nexthop local' value. */ |
6ac29a51 | 433 | static void |
a94434b6 | 434 | route_set_ipv6_nexthop_local_free (void *rule) |
718e3744 | 435 | { |
a94434b6 | 436 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
437 | } | |
718e3744 | 438 | |
a94434b6 | 439 | /* Route map commands for ipv6 nexthop local set. */ |
6ac29a51 | 440 | static struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd = |
a94434b6 | 441 | { |
442 | "ipv6 next-hop local", | |
443 | route_set_ipv6_nexthop_local, | |
444 | route_set_ipv6_nexthop_local_compile, | |
445 | route_set_ipv6_nexthop_local_free | |
446 | }; | |
447 | ||
448 | /* `set tag TAG' */ | |
449 | ||
450 | /* Set tag to object. ojbect must be pointer to struct attr. */ | |
6ac29a51 | 451 | static route_map_result_t |
a94434b6 | 452 | route_set_tag (void *rule, struct prefix *prefix, |
453 | route_map_object_t type, void *object) | |
454 | { | |
455 | u_short *tag; | |
456 | struct ripng_info *rinfo; | |
457 | ||
458 | if(type == RMAP_RIPNG) | |
718e3744 | 459 | { |
a94434b6 | 460 | /* Fetch routemap's rule information. */ |
461 | tag = rule; | |
462 | rinfo = object; | |
463 | ||
464 | /* Set next hop value. */ | |
465 | rinfo->tag_out = *tag; | |
718e3744 | 466 | } |
a94434b6 | 467 | |
468 | return RMAP_OKAY; | |
718e3744 | 469 | } |
470 | ||
a94434b6 | 471 | /* Route map `tag' compile function. Given string is converted |
472 | to u_short. */ | |
6ac29a51 | 473 | static void * |
98b718a9 | 474 | route_set_tag_compile (const char *arg) |
718e3744 | 475 | { |
a94434b6 | 476 | u_short *tag; |
718e3744 | 477 | |
a94434b6 | 478 | tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); |
479 | *tag = atoi (arg); | |
480 | ||
481 | return tag; | |
482 | } | |
483 | ||
484 | /* Free route map's compiled `ip nexthop' value. */ | |
6ac29a51 | 485 | static void |
a94434b6 | 486 | route_set_tag_free (void *rule) |
487 | { | |
488 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); | |
718e3744 | 489 | } |
a94434b6 | 490 | |
491 | /* Route map commands for tag set. */ | |
6ac29a51 | 492 | static struct route_map_rule_cmd route_set_tag_cmd = |
a94434b6 | 493 | { |
494 | "tag", | |
495 | route_set_tag, | |
496 | route_set_tag_compile, | |
497 | route_set_tag_free | |
498 | }; | |
6b0655a2 | 499 | |
a94434b6 | 500 | #define MATCH_STR "Match values from routing table\n" |
501 | #define SET_STR "Set values in destination routing protocol\n" | |
502 | ||
503 | DEFUN (match_metric, | |
504 | match_metric_cmd, | |
505 | "match metric <0-4294967295>", | |
506 | MATCH_STR | |
507 | "Match metric of route\n" | |
508 | "Metric value\n") | |
509 | { | |
510 | return ripng_route_match_add (vty, vty->index, "metric", argv[0]); | |
511 | } | |
512 | ||
513 | DEFUN (no_match_metric, | |
514 | no_match_metric_cmd, | |
515 | "no match metric", | |
516 | NO_STR | |
517 | MATCH_STR | |
518 | "Match metric of route\n") | |
519 | { | |
520 | if (argc == 0) | |
521 | return ripng_route_match_delete (vty, vty->index, "metric", NULL); | |
522 | ||
523 | return ripng_route_match_delete (vty, vty->index, "metric", argv[0]); | |
524 | } | |
525 | ||
526 | ALIAS (no_match_metric, | |
527 | no_match_metric_val_cmd, | |
528 | "no match metric <0-4294967295>", | |
529 | NO_STR | |
530 | MATCH_STR | |
531 | "Match metric of route\n" | |
532 | "Metric value\n") | |
533 | ||
718e3744 | 534 | DEFUN (match_interface, |
535 | match_interface_cmd, | |
536 | "match interface WORD", | |
a94434b6 | 537 | MATCH_STR |
538 | "Match first hop interface of route\n" | |
718e3744 | 539 | "Interface name\n") |
540 | { | |
541 | return ripng_route_match_add (vty, vty->index, "interface", argv[0]); | |
542 | } | |
543 | ||
544 | DEFUN (no_match_interface, | |
545 | no_match_interface_cmd, | |
a94434b6 | 546 | "no match interface", |
547 | NO_STR | |
548 | MATCH_STR | |
549 | "Match first hop interface of route\n") | |
550 | { | |
551 | if (argc == 0) | |
552 | return ripng_route_match_delete (vty, vty->index, "interface", NULL); | |
553 | ||
554 | return ripng_route_match_delete (vty, vty->index, "interface", argv[0]); | |
555 | } | |
556 | ||
557 | ALIAS (no_match_interface, | |
558 | no_match_interface_val_cmd, | |
718e3744 | 559 | "no match interface WORD", |
560 | NO_STR | |
a94434b6 | 561 | MATCH_STR |
562 | "Match first hop interface of route\n" | |
718e3744 | 563 | "Interface name\n") |
a94434b6 | 564 | |
565 | DEFUN (match_tag, | |
566 | match_tag_cmd, | |
0d9551dc | 567 | "match tag <1-65535>", |
a94434b6 | 568 | MATCH_STR |
569 | "Match tag of route\n" | |
570 | "Metric value\n") | |
718e3744 | 571 | { |
a94434b6 | 572 | return ripng_route_match_add (vty, vty->index, "tag", argv[0]); |
573 | } | |
574 | ||
575 | DEFUN (no_match_tag, | |
576 | no_match_tag_cmd, | |
577 | "no match tag", | |
578 | NO_STR | |
579 | MATCH_STR | |
580 | "Match tag of route\n") | |
581 | { | |
582 | if (argc == 0) | |
583 | return ripng_route_match_delete (vty, vty->index, "tag", NULL); | |
584 | ||
585 | return ripng_route_match_delete (vty, vty->index, "tag", argv[0]); | |
718e3744 | 586 | } |
a94434b6 | 587 | |
588 | ALIAS (no_match_tag, | |
589 | no_match_tag_val_cmd, | |
0d9551dc | 590 | "no match tag <1-65535>", |
a94434b6 | 591 | NO_STR |
592 | MATCH_STR | |
593 | "Match tag of route\n" | |
594 | "Metric value\n") | |
595 | ||
596 | /* set functions */ | |
718e3744 | 597 | |
598 | DEFUN (set_metric, | |
599 | set_metric_cmd, | |
600 | "set metric <0-4294967295>", | |
601 | "Set value\n" | |
a94434b6 | 602 | "Metric value for destination routing protocol\n" |
603 | "Metric value\n") | |
718e3744 | 604 | { |
605 | return ripng_route_set_add (vty, vty->index, "metric", argv[0]); | |
606 | } | |
607 | ||
608 | DEFUN (no_set_metric, | |
609 | no_set_metric_cmd, | |
73ffb25b | 610 | "no set metric", |
718e3744 | 611 | NO_STR |
73ffb25b | 612 | SET_STR |
613 | "Metric value for destination routing protocol\n") | |
718e3744 | 614 | { |
73ffb25b | 615 | if (argc == 0) |
616 | return ripng_route_set_delete (vty, vty->index, "metric", NULL); | |
617 | ||
718e3744 | 618 | return ripng_route_set_delete (vty, vty->index, "metric", argv[0]); |
619 | } | |
620 | ||
73ffb25b | 621 | ALIAS (no_set_metric, |
622 | no_set_metric_val_cmd, | |
623 | "no set metric <0-4294967295>", | |
624 | NO_STR | |
625 | SET_STR | |
626 | "Metric value for destination routing protocol\n" | |
627 | "Metric value\n") | |
628 | ||
a94434b6 | 629 | DEFUN (set_ipv6_nexthop_local, |
630 | set_ipv6_nexthop_local_cmd, | |
631 | "set ipv6 next-hop local X:X::X:X", | |
632 | SET_STR | |
633 | IPV6_STR | |
634 | "IPv6 next-hop address\n" | |
635 | "IPv6 local address\n" | |
636 | "IPv6 address of next hop\n") | |
637 | { | |
638 | union sockunion su; | |
639 | int ret; | |
640 | ||
641 | ret = str2sockunion (argv[0], &su); | |
642 | if (ret < 0) | |
643 | { | |
644 | vty_out (vty, "%% Malformed next-hop local address%s", VTY_NEWLINE); | |
645 | return CMD_WARNING; | |
646 | } | |
647 | ||
bf8b3d27 DS |
648 | if (!IN6_IS_ADDR_LINKLOCAL(&su.sin6.sin6_addr)) |
649 | { | |
650 | vty_out (vty, "%% Invalid link-local nexthop address%s", VTY_NEWLINE); | |
651 | return CMD_WARNING; | |
652 | } | |
653 | ||
a94434b6 | 654 | return ripng_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]); |
655 | } | |
656 | ||
657 | DEFUN (no_set_ipv6_nexthop_local, | |
658 | no_set_ipv6_nexthop_local_cmd, | |
659 | "no set ipv6 next-hop local", | |
660 | NO_STR | |
661 | SET_STR | |
662 | IPV6_STR | |
663 | "IPv6 next-hop address\n" | |
664 | "IPv6 local address\n") | |
665 | { | |
666 | if (argc == 0) | |
667 | return ripng_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL); | |
668 | ||
669 | return ripng_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]); | |
670 | } | |
671 | ||
672 | ALIAS (no_set_ipv6_nexthop_local, | |
673 | no_set_ipv6_nexthop_local_val_cmd, | |
674 | "no set ipv6 next-hop local X:X::X:X", | |
675 | NO_STR | |
676 | SET_STR | |
677 | IPV6_STR | |
678 | "IPv6 next-hop address\n" | |
679 | "IPv6 local address\n" | |
680 | "IPv6 address of next hop\n") | |
681 | ||
682 | DEFUN (set_tag, | |
683 | set_tag_cmd, | |
0d9551dc | 684 | "set tag <1-65535>", |
a94434b6 | 685 | SET_STR |
686 | "Tag value for routing protocol\n" | |
687 | "Tag value\n") | |
688 | { | |
689 | return ripng_route_set_add (vty, vty->index, "tag", argv[0]); | |
690 | } | |
691 | ||
692 | DEFUN (no_set_tag, | |
693 | no_set_tag_cmd, | |
694 | "no set tag", | |
695 | NO_STR | |
696 | SET_STR | |
697 | "Tag value for routing protocol\n") | |
698 | { | |
699 | if (argc == 0) | |
700 | return ripng_route_set_delete (vty, vty->index, "tag", NULL); | |
701 | ||
702 | return ripng_route_set_delete (vty, vty->index, "tag", argv[0]); | |
703 | } | |
704 | ||
705 | ALIAS (no_set_tag, | |
706 | no_set_tag_val_cmd, | |
0d9551dc | 707 | "no set tag <1-65535>", |
a94434b6 | 708 | NO_STR |
709 | SET_STR | |
710 | "Tag value for routing protocol\n" | |
711 | "Tag value\n") | |
712 | ||
713 | void | |
714 | ripng_route_map_reset () | |
715 | { | |
716 | /* XXX ??? */ | |
717 | ; | |
718 | } | |
719 | ||
718e3744 | 720 | void |
721 | ripng_route_map_init () | |
722 | { | |
723 | route_map_init (); | |
724 | route_map_init_vty (); | |
725 | ||
a94434b6 | 726 | route_map_install_match (&route_match_metric_cmd); |
727 | route_map_install_match (&route_match_interface_cmd); | |
728 | route_map_install_match (&route_match_tag_cmd); | |
729 | ||
718e3744 | 730 | route_map_install_set (&route_set_metric_cmd); |
a94434b6 | 731 | route_map_install_set (&route_set_ipv6_nexthop_local_cmd); |
732 | route_map_install_set (&route_set_tag_cmd); | |
718e3744 | 733 | |
a94434b6 | 734 | install_element (RMAP_NODE, &match_metric_cmd); |
735 | install_element (RMAP_NODE, &no_match_metric_cmd); | |
736 | install_element (RMAP_NODE, &no_match_metric_val_cmd); | |
718e3744 | 737 | install_element (RMAP_NODE, &match_interface_cmd); |
738 | install_element (RMAP_NODE, &no_match_interface_cmd); | |
a94434b6 | 739 | install_element (RMAP_NODE, &no_match_interface_val_cmd); |
740 | install_element (RMAP_NODE, &match_tag_cmd); | |
741 | install_element (RMAP_NODE, &no_match_tag_cmd); | |
742 | install_element (RMAP_NODE, &no_match_tag_val_cmd); | |
718e3744 | 743 | |
744 | install_element (RMAP_NODE, &set_metric_cmd); | |
745 | install_element (RMAP_NODE, &no_set_metric_cmd); | |
a94434b6 | 746 | install_element (RMAP_NODE, &no_set_metric_val_cmd); |
747 | install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd); | |
748 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd); | |
749 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd); | |
750 | install_element (RMAP_NODE, &set_tag_cmd); | |
751 | install_element (RMAP_NODE, &no_set_tag_cmd); | |
752 | install_element (RMAP_NODE, &no_set_tag_val_cmd); | |
718e3744 | 753 | } |