]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_routemap.c
Merge pull request #8842 from volta-networks/feat_pc_initiated
[mirror_frr.git] / bgpd / bgp_routemap.c
1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "prefix.h"
24 #include "filter.h"
25 #include "routemap.h"
26 #include "command.h"
27 #include "linklist.h"
28 #include "plist.h"
29 #include "memory.h"
30 #include "log.h"
31 #include "frrlua.h"
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
34 #else
35 #include <regex.h>
36 #endif /* HAVE_LIBPCREPOSIX */
37 #include "buffer.h"
38 #include "sockunion.h"
39 #include "hash.h"
40 #include "queue.h"
41 #include "frrstr.h"
42 #include "network.h"
43 #include "lib/northbound_cli.h"
44
45 #include "bgpd/bgpd.h"
46 #include "bgpd/bgp_table.h"
47 #include "bgpd/bgp_attr.h"
48 #include "bgpd/bgp_aspath.h"
49 #include "bgpd/bgp_packet.h"
50 #include "bgpd/bgp_route.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_community.h"
54 #include "bgpd/bgp_clist.h"
55 #include "bgpd/bgp_filter.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_ecommunity.h"
58 #include "bgpd/bgp_lcommunity.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_debug.h"
61 #include "bgpd/bgp_evpn.h"
62 #include "bgpd/bgp_evpn_private.h"
63 #include "bgpd/bgp_evpn_vty.h"
64 #include "bgpd/bgp_mplsvpn.h"
65 #include "bgpd/bgp_pbr.h"
66 #include "bgpd/bgp_flowspec_util.h"
67 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/bgp_mpath.h"
69 #include "bgpd/bgp_script.h"
70
71 #ifdef ENABLE_BGP_VNC
72 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #endif
74
75 #ifndef VTYSH_EXTRACT_PL
76 #include "bgpd/bgp_routemap_clippy.c"
77 #endif
78
79 /* Memo of route-map commands.
80
81 o Cisco route-map
82
83 match as-path : Done
84 community : Done
85 interface : Done
86 ip address : Done
87 ip next-hop : Done
88 ip route-source : Done
89 ip prefix-list : Done
90 ipv6 address : Done
91 ipv6 next-hop : Done
92 ipv6 route-source: (This will not be implemented by bgpd)
93 ipv6 prefix-list : Done
94 length : (This will not be implemented by bgpd)
95 metric : Done
96 route-type : (This will not be implemented by bgpd)
97 tag : Done
98 local-preference : Done
99
100 set as-path prepend : Done
101 as-path tag : Not yet
102 automatic-tag : (This will not be implemented by bgpd)
103 community : Done
104 large-community : Done
105 large-comm-list : Done
106 comm-list : Not yet
107 dampning : Not yet
108 default : (This will not be implemented by bgpd)
109 interface : (This will not be implemented by bgpd)
110 ip default : (This will not be implemented by bgpd)
111 ip next-hop : Done
112 ip precedence : (This will not be implemented by bgpd)
113 ip tos : (This will not be implemented by bgpd)
114 level : (This will not be implemented by bgpd)
115 local-preference : Done
116 metric : Done
117 metric-type : Not yet
118 origin : Done
119 tag : Done
120 weight : Done
121 table : Done
122
123 o Local extensions
124
125 set ipv6 next-hop global: Done
126 set ipv6 next-hop prefer-global: Done
127 set ipv6 next-hop local : Done
128 set as-path exclude : Done
129
130 */
131
132 /* generic value manipulation to be shared in multiple rules */
133
134 #define RMAP_VALUE_SET 0
135 #define RMAP_VALUE_ADD 1
136 #define RMAP_VALUE_SUB 2
137
138 struct rmap_value {
139 uint8_t action;
140 uint8_t variable;
141 uint32_t value;
142 };
143
144 static int route_value_match(struct rmap_value *rv, uint32_t value)
145 {
146 if (rv->variable == 0 && value == rv->value)
147 return RMAP_MATCH;
148
149 return RMAP_NOMATCH;
150 }
151
152 static uint32_t route_value_adjust(struct rmap_value *rv, uint32_t current,
153 struct peer *peer)
154 {
155 uint32_t value;
156
157 switch (rv->variable) {
158 case 1:
159 value = peer->rtt;
160 break;
161 default:
162 value = rv->value;
163 break;
164 }
165
166 switch (rv->action) {
167 case RMAP_VALUE_ADD:
168 if (current > UINT32_MAX - value)
169 return UINT32_MAX;
170 return current + value;
171 case RMAP_VALUE_SUB:
172 if (current <= value)
173 return 0;
174 return current - value;
175 default:
176 return value;
177 }
178 }
179
180 static void *route_value_compile(const char *arg)
181 {
182 uint8_t action = RMAP_VALUE_SET, var = 0;
183 unsigned long larg = 0;
184 char *endptr = NULL;
185 struct rmap_value *rv;
186
187 if (arg[0] == '+') {
188 action = RMAP_VALUE_ADD;
189 arg++;
190 } else if (arg[0] == '-') {
191 action = RMAP_VALUE_SUB;
192 arg++;
193 }
194
195 if (all_digit(arg)) {
196 errno = 0;
197 larg = strtoul(arg, &endptr, 10);
198 if (*arg == 0 || *endptr != 0 || errno || larg > UINT32_MAX)
199 return NULL;
200 } else {
201 if (strcmp(arg, "rtt") == 0)
202 var = 1;
203 else
204 return NULL;
205 }
206
207 rv = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_value));
208
209 rv->action = action;
210 rv->variable = var;
211 rv->value = larg;
212 return rv;
213 }
214
215 static void route_value_free(void *rule)
216 {
217 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
218 }
219
220 /* generic as path object to be shared in multiple rules */
221
222 static void *route_aspath_compile(const char *arg)
223 {
224 struct aspath *aspath;
225
226 aspath = aspath_str2aspath(arg);
227 if (!aspath)
228 return NULL;
229 return aspath;
230 }
231
232 static void route_aspath_free(void *rule)
233 {
234 struct aspath *aspath = rule;
235 aspath_free(aspath);
236 }
237
238 struct bgp_match_peer_compiled {
239 char *interface;
240 union sockunion su;
241 };
242
243 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
244
245 /* Compares the peer specified in the 'match peer' clause with the peer
246 received in bgp_path_info->peer. If it is the same, or if the peer structure
247 received is a peer_group containing it, returns RMAP_MATCH. */
248 static enum route_map_cmd_result_t
249 route_match_peer(void *rule, const struct prefix *prefix, void *object)
250 {
251 struct bgp_match_peer_compiled *pc;
252 union sockunion *su;
253 union sockunion su_def = {
254 .sin = {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY}};
255 struct peer_group *group;
256 struct peer *peer;
257 struct listnode *node, *nnode;
258
259 pc = rule;
260 su = &pc->su;
261 peer = ((struct bgp_path_info *)object)->peer;
262
263 if (pc->interface) {
264 if (!peer->conf_if)
265 return RMAP_NOMATCH;
266
267 if (strcmp(peer->conf_if, pc->interface) == 0)
268 return RMAP_MATCH;
269
270 return RMAP_NOMATCH;
271 }
272
273 /* If su='0.0.0.0' (command 'match peer local'), and it's a
274 NETWORK,
275 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
276 => return RMAP_MATCH
277 */
278 if (sockunion_same(su, &su_def)) {
279 int ret;
280 if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_NETWORK)
281 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE)
282 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_AGGREGATE)
283 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
284 ret = RMAP_MATCH;
285 else
286 ret = RMAP_NOMATCH;
287 return ret;
288 }
289
290 if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
291 if (sockunion_same(su, &peer->su))
292 return RMAP_MATCH;
293
294 return RMAP_NOMATCH;
295 } else {
296 group = peer->group;
297 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
298 if (sockunion_same(su, &peer->su))
299 return RMAP_MATCH;
300 }
301 return RMAP_NOMATCH;
302 }
303
304 return RMAP_NOMATCH;
305 }
306
307 static void *route_match_peer_compile(const char *arg)
308 {
309 struct bgp_match_peer_compiled *pc;
310 int ret;
311
312 pc = XCALLOC(MTYPE_ROUTE_MAP_COMPILED,
313 sizeof(struct bgp_match_peer_compiled));
314
315 ret = str2sockunion(strcmp(arg, "local") ? arg : "0.0.0.0", &pc->su);
316 if (ret < 0) {
317 pc->interface = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
318 return pc;
319 }
320
321 return pc;
322 }
323
324 /* Free route map's compiled `ip address' value. */
325 static void route_match_peer_free(void *rule)
326 {
327 struct bgp_match_peer_compiled *pc = rule;
328
329 XFREE(MTYPE_ROUTE_MAP_COMPILED, pc->interface);
330
331 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
332 }
333
334 /* Route map commands for ip address matching. */
335 static const struct route_map_rule_cmd route_match_peer_cmd = {
336 "peer",
337 route_match_peer,
338 route_match_peer_compile,
339 route_match_peer_free
340 };
341
342 #ifdef HAVE_SCRIPTING
343
344 enum frrlua_rm_status {
345 /*
346 * Script function run failure. This will translate into a deny
347 */
348 LUA_RM_FAILURE = 0,
349 /*
350 * No Match was found for the route map function
351 */
352 LUA_RM_NOMATCH,
353 /*
354 * Match was found but no changes were made to the incoming data.
355 */
356 LUA_RM_MATCH,
357 /*
358 * Match was found and data was modified, so figure out what changed
359 */
360 LUA_RM_MATCH_AND_CHANGE,
361 };
362
363 static enum route_map_cmd_result_t
364 route_match_script(void *rule, const struct prefix *prefix, void *object)
365 {
366 const char *scriptname = rule;
367 struct bgp_path_info *path = (struct bgp_path_info *)object;
368
369 struct frrscript *fs = frrscript_load(scriptname, NULL);
370
371 if (!fs) {
372 zlog_err("Issue loading script rule; defaulting to no match");
373 return RMAP_NOMATCH;
374 }
375
376 enum frrlua_rm_status status_failure = LUA_RM_FAILURE,
377 status_nomatch = LUA_RM_NOMATCH,
378 status_match = LUA_RM_MATCH,
379 status_match_and_change = LUA_RM_MATCH_AND_CHANGE;
380
381 /* Make result values available */
382 struct frrscript_env env[] = {
383 {"integer", "RM_FAILURE", &status_failure},
384 {"integer", "RM_NOMATCH", &status_nomatch},
385 {"integer", "RM_MATCH", &status_match},
386 {"integer", "RM_MATCH_AND_CHANGE", &status_match_and_change},
387 {"integer", "action", &status_failure},
388 {"prefix", "prefix", prefix},
389 {"attr", "attributes", path->attr},
390 {"peer", "peer", path->peer},
391 {}};
392
393 struct frrscript_env results[] = {
394 {"integer", "action"},
395 {"attr", "attributes"},
396 {},
397 };
398
399 int result = frrscript_call(fs, env);
400
401 if (result) {
402 zlog_err("Issue running script rule; defaulting to no match");
403 return RMAP_NOMATCH;
404 }
405
406 enum frrlua_rm_status *lrm_status =
407 frrscript_get_result(fs, &results[0]);
408
409 int status = RMAP_NOMATCH;
410
411 switch (*lrm_status) {
412 case LUA_RM_FAILURE:
413 zlog_err(
414 "Executing route-map match script '%s' failed; defaulting to no match",
415 scriptname);
416 status = RMAP_NOMATCH;
417 break;
418 case LUA_RM_NOMATCH:
419 status = RMAP_NOMATCH;
420 break;
421 case LUA_RM_MATCH_AND_CHANGE:
422 status = RMAP_MATCH;
423 zlog_debug("Updating attribute based on script's values");
424
425 uint32_t locpref = 0;
426 struct attr *newattr = frrscript_get_result(fs, &results[1]);
427
428 path->attr->med = newattr->med;
429
430 if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
431 locpref = path->attr->local_pref;
432 if (locpref != newattr->local_pref) {
433 SET_FLAG(path->attr->flag,
434 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF));
435 path->attr->local_pref = newattr->local_pref;
436 }
437
438 aspath_free(newattr->aspath);
439 XFREE(MTYPE_TMP, newattr);
440 break;
441 case LUA_RM_MATCH:
442 status = RMAP_MATCH;
443 break;
444 }
445
446 XFREE(MTYPE_TMP, lrm_status);
447 frrscript_unload(fs);
448
449 return status;
450 }
451
452 static void *route_match_script_compile(const char *arg)
453 {
454 char *scriptname;
455
456 scriptname = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
457
458 return scriptname;
459 }
460
461 static void route_match_script_free(void *rule)
462 {
463 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
464 }
465
466 static const struct route_map_rule_cmd route_match_script_cmd = {
467 "script",
468 route_match_script,
469 route_match_script_compile,
470 route_match_script_free
471 };
472
473 #endif /* HAVE_SCRIPTING */
474
475 /* `match ip address IP_ACCESS_LIST' */
476
477 /* Match function should return 1 if match is success else return
478 zero. */
479 static enum route_map_cmd_result_t
480 route_match_ip_address(void *rule, const struct prefix *prefix, void *object)
481 {
482 struct access_list *alist;
483
484 if (prefix->family == AF_INET) {
485 alist = access_list_lookup(AFI_IP, (char *)rule);
486 if (alist == NULL)
487 return RMAP_NOMATCH;
488
489 return (access_list_apply(alist, prefix) == FILTER_DENY
490 ? RMAP_NOMATCH
491 : RMAP_MATCH);
492 }
493 return RMAP_NOMATCH;
494 }
495
496 /* Route map `ip address' match statement. `arg' should be
497 access-list name. */
498 static void *route_match_ip_address_compile(const char *arg)
499 {
500 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
501 }
502
503 /* Free route map's compiled `ip address' value. */
504 static void route_match_ip_address_free(void *rule)
505 {
506 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
507 }
508
509 /* Route map commands for ip address matching. */
510 static const struct route_map_rule_cmd route_match_ip_address_cmd = {
511 "ip address",
512 route_match_ip_address,
513 route_match_ip_address_compile,
514 route_match_ip_address_free
515 };
516
517 /* `match ip next-hop IP_ADDRESS' */
518
519 /* Match function return 1 if match is success else return zero. */
520 static enum route_map_cmd_result_t
521 route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object)
522 {
523 struct access_list *alist;
524 struct bgp_path_info *path;
525 struct prefix_ipv4 p;
526
527 if (prefix->family == AF_INET) {
528 path = object;
529 p.family = AF_INET;
530 p.prefix = path->attr->nexthop;
531 p.prefixlen = IPV4_MAX_BITLEN;
532
533 alist = access_list_lookup(AFI_IP, (char *)rule);
534 if (alist == NULL)
535 return RMAP_NOMATCH;
536
537 return (access_list_apply(alist, &p) == FILTER_DENY
538 ? RMAP_NOMATCH
539 : RMAP_MATCH);
540 }
541 return RMAP_NOMATCH;
542 }
543
544 /* Route map `ip next-hop' match statement. `arg' is
545 access-list name. */
546 static void *route_match_ip_next_hop_compile(const char *arg)
547 {
548 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
549 }
550
551 /* Free route map's compiled `ip address' value. */
552 static void route_match_ip_next_hop_free(void *rule)
553 {
554 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
555 }
556
557 /* Route map commands for ip next-hop matching. */
558 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd = {
559 "ip next-hop",
560 route_match_ip_next_hop,
561 route_match_ip_next_hop_compile,
562 route_match_ip_next_hop_free
563 };
564
565 /* `match ip route-source ACCESS-LIST' */
566
567 /* Match function return 1 if match is success else return zero. */
568 static enum route_map_cmd_result_t
569 route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object)
570 {
571 struct access_list *alist;
572 struct bgp_path_info *path;
573 struct peer *peer;
574 struct prefix_ipv4 p;
575
576 if (pfx->family == AF_INET) {
577 path = object;
578 peer = path->peer;
579
580 if (!peer || sockunion_family(&peer->su) != AF_INET)
581 return RMAP_NOMATCH;
582
583 p.family = AF_INET;
584 p.prefix = peer->su.sin.sin_addr;
585 p.prefixlen = IPV4_MAX_BITLEN;
586
587 alist = access_list_lookup(AFI_IP, (char *)rule);
588 if (alist == NULL)
589 return RMAP_NOMATCH;
590
591 return (access_list_apply(alist, &p) == FILTER_DENY
592 ? RMAP_NOMATCH
593 : RMAP_MATCH);
594 }
595 return RMAP_NOMATCH;
596 }
597
598 /* Route map `ip route-source' match statement. `arg' is
599 access-list name. */
600 static void *route_match_ip_route_source_compile(const char *arg)
601 {
602 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
603 }
604
605 /* Free route map's compiled `ip address' value. */
606 static void route_match_ip_route_source_free(void *rule)
607 {
608 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
609 }
610
611 /* Route map commands for ip route-source matching. */
612 static const struct route_map_rule_cmd route_match_ip_route_source_cmd = {
613 "ip route-source",
614 route_match_ip_route_source,
615 route_match_ip_route_source_compile,
616 route_match_ip_route_source_free
617 };
618
619 static enum route_map_cmd_result_t
620 route_match_prefix_list_flowspec(afi_t afi, struct prefix_list *plist,
621 const struct prefix *p)
622 {
623 int ret;
624 struct bgp_pbr_entry_main api;
625
626 memset(&api, 0, sizeof(api));
627
628 if (family2afi(p->u.prefix_flowspec.family) != afi)
629 return RMAP_NOMATCH;
630
631 /* extract match from flowspec entries */
632 ret = bgp_flowspec_match_rules_fill(
633 (uint8_t *)p->u.prefix_flowspec.ptr,
634 p->u.prefix_flowspec.prefixlen, &api,
635 afi);
636 if (ret < 0)
637 return RMAP_NOMATCH;
638 if (api.match_bitmask & PREFIX_DST_PRESENT ||
639 api.match_bitmask_iprule & PREFIX_DST_PRESENT) {
640 if (family2afi((&api.dst_prefix)->family) != afi)
641 return RMAP_NOMATCH;
642 return prefix_list_apply(plist, &api.dst_prefix) == PREFIX_DENY
643 ? RMAP_NOMATCH
644 : RMAP_MATCH;
645 } else if (api.match_bitmask & PREFIX_SRC_PRESENT ||
646 api.match_bitmask_iprule & PREFIX_SRC_PRESENT) {
647 if (family2afi((&api.src_prefix)->family) != afi)
648 return RMAP_NOMATCH;
649 return (prefix_list_apply(plist, &api.src_prefix) == PREFIX_DENY
650 ? RMAP_NOMATCH
651 : RMAP_MATCH);
652 }
653 return RMAP_NOMATCH;
654 }
655
656 static enum route_map_cmd_result_t
657 route_match_address_prefix_list(void *rule, afi_t afi,
658 const struct prefix *prefix, void *object)
659 {
660 struct prefix_list *plist;
661
662 plist = prefix_list_lookup(afi, (char *)rule);
663 if (plist == NULL)
664 return RMAP_NOMATCH;
665
666 if (prefix->family == AF_FLOWSPEC)
667 return route_match_prefix_list_flowspec(afi, plist,
668 prefix);
669 return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH
670 : RMAP_MATCH);
671 }
672
673 static enum route_map_cmd_result_t
674 route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
675 void *object)
676 {
677 return route_match_address_prefix_list(rule, AFI_IP, prefix, object);
678 }
679
680 static void *route_match_ip_address_prefix_list_compile(const char *arg)
681 {
682 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
683 }
684
685 static void route_match_ip_address_prefix_list_free(void *rule)
686 {
687 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
688 }
689
690 static const struct route_map_rule_cmd
691 route_match_ip_address_prefix_list_cmd = {
692 "ip address prefix-list",
693 route_match_ip_address_prefix_list,
694 route_match_ip_address_prefix_list_compile,
695 route_match_ip_address_prefix_list_free
696 };
697
698 /* `match ip next-hop prefix-list PREFIX_LIST' */
699
700 static enum route_map_cmd_result_t
701 route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
702 void *object)
703 {
704 struct prefix_list *plist;
705 struct bgp_path_info *path;
706 struct prefix_ipv4 p;
707
708 if (prefix->family == AF_INET) {
709 path = object;
710 p.family = AF_INET;
711 p.prefix = path->attr->nexthop;
712 p.prefixlen = IPV4_MAX_BITLEN;
713
714 plist = prefix_list_lookup(AFI_IP, (char *)rule);
715 if (plist == NULL)
716 return RMAP_NOMATCH;
717
718 return (prefix_list_apply(plist, &p) == PREFIX_DENY
719 ? RMAP_NOMATCH
720 : RMAP_MATCH);
721 }
722 return RMAP_NOMATCH;
723 }
724
725 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg)
726 {
727 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
728 }
729
730 static void route_match_ip_next_hop_prefix_list_free(void *rule)
731 {
732 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
733 }
734
735 static const struct route_map_rule_cmd
736 route_match_ip_next_hop_prefix_list_cmd = {
737 "ip next-hop prefix-list",
738 route_match_ip_next_hop_prefix_list,
739 route_match_ip_next_hop_prefix_list_compile,
740 route_match_ip_next_hop_prefix_list_free
741 };
742
743 /* `match ip next-hop type <blackhole>' */
744
745 static enum route_map_cmd_result_t
746 route_match_ip_next_hop_type(void *rule, const struct prefix *prefix,
747 void *object)
748 {
749 struct bgp_path_info *path;
750
751 if (prefix->family == AF_INET) {
752 path = (struct bgp_path_info *)object;
753 if (!path)
754 return RMAP_NOMATCH;
755
756 /* If nexthop interface's index can't be resolved and nexthop is
757 set to any address then mark it as type `blackhole`.
758 This logic works for matching kernel/static routes like:
759 `ip route add blackhole 10.0.0.1`. */
760 if (path->attr->nexthop.s_addr == INADDR_ANY
761 && !path->attr->nh_ifindex)
762 return RMAP_MATCH;
763 }
764 return RMAP_NOMATCH;
765 }
766
767 static void *route_match_ip_next_hop_type_compile(const char *arg)
768 {
769 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
770 }
771
772 static void route_match_ip_next_hop_type_free(void *rule)
773 {
774 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
775 }
776
777 static const struct route_map_rule_cmd
778 route_match_ip_next_hop_type_cmd = {
779 "ip next-hop type",
780 route_match_ip_next_hop_type,
781 route_match_ip_next_hop_type_compile,
782 route_match_ip_next_hop_type_free
783 };
784
785 /* `match ip route-source prefix-list PREFIX_LIST' */
786
787 static enum route_map_cmd_result_t
788 route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix,
789 void *object)
790 {
791 struct prefix_list *plist;
792 struct bgp_path_info *path;
793 struct peer *peer;
794 struct prefix_ipv4 p;
795
796 if (prefix->family == AF_INET) {
797 path = object;
798 peer = path->peer;
799
800 if (!peer || sockunion_family(&peer->su) != AF_INET)
801 return RMAP_NOMATCH;
802
803 p.family = AF_INET;
804 p.prefix = peer->su.sin.sin_addr;
805 p.prefixlen = IPV4_MAX_BITLEN;
806
807 plist = prefix_list_lookup(AFI_IP, (char *)rule);
808 if (plist == NULL)
809 return RMAP_NOMATCH;
810
811 return (prefix_list_apply(plist, &p) == PREFIX_DENY
812 ? RMAP_NOMATCH
813 : RMAP_MATCH);
814 }
815 return RMAP_NOMATCH;
816 }
817
818 static void *route_match_ip_route_source_prefix_list_compile(const char *arg)
819 {
820 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
821 }
822
823 static void route_match_ip_route_source_prefix_list_free(void *rule)
824 {
825 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
826 }
827
828 static const struct route_map_rule_cmd
829 route_match_ip_route_source_prefix_list_cmd = {
830 "ip route-source prefix-list",
831 route_match_ip_route_source_prefix_list,
832 route_match_ip_route_source_prefix_list_compile,
833 route_match_ip_route_source_prefix_list_free
834 };
835
836 /* `match evpn default-route' */
837
838 /* Match function should return 1 if match is success else 0 */
839 static enum route_map_cmd_result_t
840 route_match_evpn_default_route(void *rule, const struct prefix *p, void *object)
841 {
842 if (is_evpn_prefix_default(p))
843 return RMAP_MATCH;
844
845 return RMAP_NOMATCH;
846 }
847
848 /* Route map commands for default-route matching. */
849 static const struct route_map_rule_cmd
850 route_match_evpn_default_route_cmd = {
851 "evpn default-route",
852 route_match_evpn_default_route,
853 NULL,
854 NULL
855 };
856
857 /* `match mac address MAC_ACCESS_LIST' */
858
859 /* Match function should return 1 if match is success else return
860 zero. */
861 static enum route_map_cmd_result_t
862 route_match_mac_address(void *rule, const struct prefix *prefix, void *object)
863 {
864 struct access_list *alist;
865 struct prefix p;
866
867 alist = access_list_lookup(AFI_L2VPN, (char *)rule);
868 if (alist == NULL)
869 return RMAP_NOMATCH;
870
871 if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE)
872 return RMAP_NOMATCH;
873
874 p.family = AF_ETHERNET;
875 p.prefixlen = ETH_ALEN * 8;
876 p.u.prefix_eth = prefix->u.prefix_evpn.macip_addr.mac;
877
878 return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH
879 : RMAP_MATCH);
880 }
881
882 /* Route map `mac address' match statement. `arg' should be
883 access-list name. */
884 static void *route_match_mac_address_compile(const char *arg)
885 {
886 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
887 }
888
889 /* Free route map's compiled `ip address' value. */
890 static void route_match_mac_address_free(void *rule)
891 {
892 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
893 }
894
895 /* Route map commands for mac address matching. */
896 static const struct route_map_rule_cmd route_match_mac_address_cmd = {
897 "mac address",
898 route_match_mac_address,
899 route_match_mac_address_compile,
900 route_match_mac_address_free
901 };
902
903 /*
904 * Match function returns:
905 * ...RMAP_MATCH if match is found.
906 * ...RMAP_NOMATCH if match is not found.
907 * ...RMAP_NOOP to ignore this match check.
908 */
909 static enum route_map_cmd_result_t
910 route_match_vni(void *rule, const struct prefix *prefix, void *object)
911 {
912 vni_t vni = 0;
913 unsigned int label_cnt = 0;
914 struct bgp_path_info *path = NULL;
915 struct prefix_evpn *evp = (struct prefix_evpn *) prefix;
916
917 vni = *((vni_t *)rule);
918 path = (struct bgp_path_info *)object;
919
920 /*
921 * This rmap filter is valid for vxlan tunnel type only.
922 * For any other tunnel type, return noop to ignore
923 * this check.
924 */
925 if (path->attr->encap_tunneltype != BGP_ENCAP_TYPE_VXLAN)
926 return RMAP_NOOP;
927
928 /*
929 * Apply filter to type 1, 2, 5 routes only.
930 * Other route types do not have vni label.
931 */
932 if (evp
933 && (evp->prefix.route_type != BGP_EVPN_AD_ROUTE
934 && evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE
935 && evp->prefix.route_type != BGP_EVPN_IP_PREFIX_ROUTE))
936 return RMAP_NOOP;
937
938 if (path->extra == NULL)
939 return RMAP_NOMATCH;
940
941 for (;
942 label_cnt < BGP_MAX_LABELS && label_cnt < path->extra->num_labels;
943 label_cnt++) {
944 if (vni == label2vni(&path->extra->label[label_cnt]))
945 return RMAP_MATCH;
946 }
947
948 return RMAP_NOMATCH;
949 }
950
951 /* Route map `vni' match statement. */
952 static void *route_match_vni_compile(const char *arg)
953 {
954 vni_t *vni = NULL;
955 char *end = NULL;
956
957 vni = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(vni_t));
958
959 *vni = strtoul(arg, &end, 10);
960 if (*end != '\0') {
961 XFREE(MTYPE_ROUTE_MAP_COMPILED, vni);
962 return NULL;
963 }
964
965 return vni;
966 }
967
968 /* Free route map's compiled `vni' value. */
969 static void route_match_vni_free(void *rule)
970 {
971 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
972 }
973
974 /* Route map commands for vni matching. */
975 static const struct route_map_rule_cmd route_match_evpn_vni_cmd = {
976 "evpn vni",
977 route_match_vni,
978 route_match_vni_compile,
979 route_match_vni_free
980 };
981
982 /* `match evpn route-type' */
983
984 /* Match function should return 1 if match is success else return
985 zero. */
986 static enum route_map_cmd_result_t
987 route_match_evpn_route_type(void *rule, const struct prefix *pfx, void *object)
988 {
989 uint8_t route_type = 0;
990
991 route_type = *((uint8_t *)rule);
992
993 if (route_type == pfx->u.prefix_evpn.route_type)
994 return RMAP_MATCH;
995
996 return RMAP_NOMATCH;
997 }
998
999 /* Route map `route-type' match statement. */
1000 static void *route_match_evpn_route_type_compile(const char *arg)
1001 {
1002 uint8_t *route_type = NULL;
1003
1004 route_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t));
1005
1006 if (strncmp(arg, "ma", 2) == 0)
1007 *route_type = BGP_EVPN_MAC_IP_ROUTE;
1008 else if (strncmp(arg, "mu", 2) == 0)
1009 *route_type = BGP_EVPN_IMET_ROUTE;
1010 else
1011 *route_type = BGP_EVPN_IP_PREFIX_ROUTE;
1012
1013 return route_type;
1014 }
1015
1016 /* Free route map's compiled `route-type' value. */
1017 static void route_match_evpn_route_type_free(void *rule)
1018 {
1019 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1020 }
1021
1022 /* Route map commands for evpn route-type matching. */
1023 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd = {
1024 "evpn route-type",
1025 route_match_evpn_route_type,
1026 route_match_evpn_route_type_compile,
1027 route_match_evpn_route_type_free
1028 };
1029
1030 /* `match rd' */
1031
1032 /* Match function should return 1 if match is success else return zero. */
1033 static enum route_map_cmd_result_t
1034 route_match_rd(void *rule, const struct prefix *prefix, void *object)
1035 {
1036 struct prefix_rd *prd_rule = NULL;
1037 const struct prefix_rd *prd_route = NULL;
1038 struct bgp_path_info *path = NULL;
1039
1040 if (prefix->family != AF_EVPN)
1041 return RMAP_NOMATCH;
1042
1043 prd_rule = (struct prefix_rd *)rule;
1044 path = (struct bgp_path_info *)object;
1045
1046 if (path->net == NULL || path->net->pdest == NULL)
1047 return RMAP_NOMATCH;
1048
1049 prd_route = (struct prefix_rd *)bgp_dest_get_prefix(path->net->pdest);
1050 if (memcmp(prd_route->val, prd_rule->val, ECOMMUNITY_SIZE) == 0)
1051 return RMAP_MATCH;
1052
1053 return RMAP_NOMATCH;
1054 }
1055
1056 /* Route map `rd' match statement. */
1057 static void *route_match_rd_compile(const char *arg)
1058 {
1059 struct prefix_rd *prd;
1060 int ret;
1061
1062 prd = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct prefix_rd));
1063
1064 ret = str2prefix_rd(arg, prd);
1065 if (!ret) {
1066 XFREE(MTYPE_ROUTE_MAP_COMPILED, prd);
1067 return NULL;
1068 }
1069
1070 return prd;
1071 }
1072
1073 /* Free route map's compiled `rd' value. */
1074 static void route_match_rd_free(void *rule)
1075 {
1076 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1077 }
1078
1079 /* Route map commands for rd matching. */
1080 static const struct route_map_rule_cmd route_match_evpn_rd_cmd = {
1081 "evpn rd",
1082 route_match_rd,
1083 route_match_rd_compile,
1084 route_match_rd_free
1085 };
1086
1087 static enum route_map_cmd_result_t
1088 route_set_evpn_gateway_ip(void *rule, const struct prefix *prefix, void *object)
1089 {
1090 struct ipaddr *gw_ip = rule;
1091 struct bgp_path_info *path;
1092 struct prefix_evpn *evp;
1093
1094 if (prefix->family != AF_EVPN)
1095 return RMAP_OKAY;
1096
1097 evp = (struct prefix_evpn *)prefix;
1098 if (evp->prefix.route_type != BGP_EVPN_IP_PREFIX_ROUTE)
1099 return RMAP_OKAY;
1100
1101 if ((is_evpn_prefix_ipaddr_v4(evp) && IPADDRSZ(gw_ip) != 4)
1102 || (is_evpn_prefix_ipaddr_v6(evp) && IPADDRSZ(gw_ip) != 16))
1103 return RMAP_OKAY;
1104
1105 path = object;
1106
1107 /* Set gateway-ip value. */
1108 path->attr->evpn_overlay.type = OVERLAY_INDEX_GATEWAY_IP;
1109 memcpy(&path->attr->evpn_overlay.gw_ip, &gw_ip->ip.addr,
1110 IPADDRSZ(gw_ip));
1111
1112 return RMAP_OKAY;
1113 }
1114
1115 /*
1116 * Route map `evpn gateway-ip' compile function.
1117 * Given string is converted to struct ipaddr structure
1118 */
1119 static void *route_set_evpn_gateway_ip_compile(const char *arg)
1120 {
1121 struct ipaddr *gw_ip = NULL;
1122 int ret;
1123
1124 gw_ip = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct ipaddr));
1125
1126 ret = str2ipaddr(arg, gw_ip);
1127 if (ret < 0) {
1128 XFREE(MTYPE_ROUTE_MAP_COMPILED, gw_ip);
1129 return NULL;
1130 }
1131 return gw_ip;
1132 }
1133
1134 /* Free route map's compiled `evpn gateway_ip' value. */
1135 static void route_set_evpn_gateway_ip_free(void *rule)
1136 {
1137 struct ipaddr *gw_ip = rule;
1138
1139 XFREE(MTYPE_ROUTE_MAP_COMPILED, gw_ip);
1140 }
1141
1142 /* Route map commands for set evpn gateway-ip ipv4. */
1143 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd = {
1144 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip,
1145 route_set_evpn_gateway_ip_compile, route_set_evpn_gateway_ip_free};
1146
1147 /* Route map commands for set evpn gateway-ip ipv6. */
1148 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd = {
1149 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip,
1150 route_set_evpn_gateway_ip_compile, route_set_evpn_gateway_ip_free};
1151
1152 /* Route map commands for VRF route leak with source vrf matching */
1153 static enum route_map_cmd_result_t
1154 route_match_vrl_source_vrf(void *rule, const struct prefix *prefix,
1155 void *object)
1156 {
1157 struct bgp_path_info *path;
1158 char *vrf_name;
1159
1160 vrf_name = rule;
1161 path = (struct bgp_path_info *)object;
1162
1163 if (strncmp(vrf_name, "n/a", VRF_NAMSIZ) == 0)
1164 return RMAP_NOMATCH;
1165
1166 if (path->extra == NULL)
1167 return RMAP_NOMATCH;
1168
1169 if (strncmp(vrf_name, vrf_id_to_name(path->extra->bgp_orig->vrf_id),
1170 VRF_NAMSIZ)
1171 == 0)
1172 return RMAP_MATCH;
1173
1174 return RMAP_NOMATCH;
1175 }
1176
1177 static void *route_match_vrl_source_vrf_compile(const char *arg)
1178 {
1179 uint8_t *vrf_name = NULL;
1180
1181 vrf_name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1182
1183 return vrf_name;
1184 }
1185
1186 /* Free route map's compiled `route-type' value. */
1187 static void route_match_vrl_source_vrf_free(void *rule)
1188 {
1189 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1190 }
1191
1192 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd = {
1193 "source-vrf",
1194 route_match_vrl_source_vrf,
1195 route_match_vrl_source_vrf_compile,
1196 route_match_vrl_source_vrf_free
1197 };
1198
1199 /* `match local-preference LOCAL-PREF' */
1200
1201 /* Match function return 1 if match is success else return zero. */
1202 static enum route_map_cmd_result_t
1203 route_match_local_pref(void *rule, const struct prefix *prefix, void *object)
1204 {
1205 uint32_t *local_pref;
1206 struct bgp_path_info *path;
1207
1208 local_pref = rule;
1209 path = object;
1210
1211 if (path->attr->local_pref == *local_pref)
1212 return RMAP_MATCH;
1213 else
1214 return RMAP_NOMATCH;
1215 }
1216
1217 /*
1218 * Route map `match local-preference' match statement.
1219 * `arg' is local-pref value
1220 */
1221 static void *route_match_local_pref_compile(const char *arg)
1222 {
1223 uint32_t *local_pref;
1224 char *endptr = NULL;
1225 unsigned long tmpval;
1226
1227 /* Locpref value shoud be integer. */
1228 if (!all_digit(arg))
1229 return NULL;
1230
1231 errno = 0;
1232 tmpval = strtoul(arg, &endptr, 10);
1233 if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
1234 return NULL;
1235
1236 local_pref = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
1237
1238 *local_pref = tmpval;
1239 return local_pref;
1240 }
1241
1242 /* Free route map's compiled `match local-preference' value. */
1243 static void route_match_local_pref_free(void *rule)
1244 {
1245 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1246 }
1247
1248 /* Route map commands for metric matching. */
1249 static const struct route_map_rule_cmd route_match_local_pref_cmd = {
1250 "local-preference",
1251 route_match_local_pref,
1252 route_match_local_pref_compile,
1253 route_match_local_pref_free
1254 };
1255
1256 /* `match metric METRIC' */
1257
1258 /* Match function return 1 if match is success else return zero. */
1259 static enum route_map_cmd_result_t
1260 route_match_metric(void *rule, const struct prefix *prefix, void *object)
1261 {
1262 struct rmap_value *rv;
1263 struct bgp_path_info *path;
1264
1265 rv = rule;
1266 path = object;
1267 return route_value_match(rv, path->attr->med);
1268 }
1269
1270 /* Route map commands for metric matching. */
1271 static const struct route_map_rule_cmd route_match_metric_cmd = {
1272 "metric",
1273 route_match_metric,
1274 route_value_compile,
1275 route_value_free,
1276 };
1277
1278 /* `match as-path ASPATH' */
1279
1280 /* Match function for as-path match. I assume given object is */
1281 static enum route_map_cmd_result_t
1282 route_match_aspath(void *rule, const struct prefix *prefix, void *object)
1283 {
1284
1285 struct as_list *as_list;
1286 struct bgp_path_info *path;
1287
1288 as_list = as_list_lookup((char *)rule);
1289 if (as_list == NULL)
1290 return RMAP_NOMATCH;
1291
1292 path = object;
1293
1294 /* Perform match. */
1295 return ((as_list_apply(as_list, path->attr->aspath) == AS_FILTER_DENY)
1296 ? RMAP_NOMATCH
1297 : RMAP_MATCH);
1298 }
1299
1300 /* Compile function for as-path match. */
1301 static void *route_match_aspath_compile(const char *arg)
1302 {
1303 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1304 }
1305
1306 /* Compile function for as-path match. */
1307 static void route_match_aspath_free(void *rule)
1308 {
1309 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1310 }
1311
1312 /* Route map commands for aspath matching. */
1313 static const struct route_map_rule_cmd route_match_aspath_cmd = {
1314 "as-path",
1315 route_match_aspath,
1316 route_match_aspath_compile,
1317 route_match_aspath_free
1318 };
1319
1320 /* `match community COMMUNIY' */
1321 struct rmap_community {
1322 char *name;
1323 uint32_t name_hash;
1324 int exact;
1325 };
1326
1327 /* Match function for community match. */
1328 static enum route_map_cmd_result_t
1329 route_match_community(void *rule, const struct prefix *prefix, void *object)
1330 {
1331 struct community_list *list;
1332 struct bgp_path_info *path;
1333 struct rmap_community *rcom = rule;
1334
1335 path = object;
1336 rcom = rule;
1337
1338 list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash,
1339 COMMUNITY_LIST_MASTER);
1340 if (!list)
1341 return RMAP_NOMATCH;
1342
1343 if (rcom->exact) {
1344 if (community_list_exact_match(path->attr->community, list))
1345 return RMAP_MATCH;
1346 } else {
1347 if (community_list_match(path->attr->community, list))
1348 return RMAP_MATCH;
1349 }
1350
1351 return RMAP_NOMATCH;
1352 }
1353
1354 /* Compile function for community match. */
1355 static void *route_match_community_compile(const char *arg)
1356 {
1357 struct rmap_community *rcom;
1358 int len;
1359 char *p;
1360
1361 rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community));
1362
1363 p = strchr(arg, ' ');
1364 if (p) {
1365 len = p - arg;
1366 rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1);
1367 memcpy(rcom->name, arg, len);
1368 rcom->exact = 1;
1369 } else {
1370 rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1371 rcom->exact = 0;
1372 }
1373
1374 rcom->name_hash = bgp_clist_hash_key(rcom->name);
1375 return rcom;
1376 }
1377
1378 /* Compile function for community match. */
1379 static void route_match_community_free(void *rule)
1380 {
1381 struct rmap_community *rcom = rule;
1382
1383 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name);
1384 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
1385 }
1386
1387 /*
1388 * In routemap processing there is a need to add the
1389 * name as a rule_key in the dependency table. Routemap
1390 * lib is unaware of rule_key when exact-match clause
1391 * is in use. routemap lib uses the compiled output to
1392 * get the rule_key value.
1393 */
1394 static void *route_match_get_community_key(void *rule)
1395 {
1396 struct rmap_community *rcom;
1397
1398 rcom = rule;
1399 return rcom->name;
1400 }
1401
1402
1403 /* Route map commands for community matching. */
1404 static const struct route_map_rule_cmd route_match_community_cmd = {
1405 "community",
1406 route_match_community,
1407 route_match_community_compile,
1408 route_match_community_free,
1409 route_match_get_community_key
1410 };
1411
1412 /* Match function for lcommunity match. */
1413 static enum route_map_cmd_result_t
1414 route_match_lcommunity(void *rule, const struct prefix *prefix, void *object)
1415 {
1416 struct community_list *list;
1417 struct bgp_path_info *path;
1418 struct rmap_community *rcom = rule;
1419
1420 path = object;
1421
1422 list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash,
1423 LARGE_COMMUNITY_LIST_MASTER);
1424 if (!list)
1425 return RMAP_NOMATCH;
1426
1427 if (rcom->exact) {
1428 if (lcommunity_list_exact_match(path->attr->lcommunity, list))
1429 return RMAP_MATCH;
1430 } else {
1431 if (lcommunity_list_match(path->attr->lcommunity, list))
1432 return RMAP_MATCH;
1433 }
1434
1435 return RMAP_NOMATCH;
1436 }
1437
1438 /* Compile function for community match. */
1439 static void *route_match_lcommunity_compile(const char *arg)
1440 {
1441 struct rmap_community *rcom;
1442 int len;
1443 char *p;
1444
1445 rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community));
1446
1447 p = strchr(arg, ' ');
1448 if (p) {
1449 len = p - arg;
1450 rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1);
1451 memcpy(rcom->name, arg, len);
1452 rcom->exact = 1;
1453 } else {
1454 rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1455 rcom->exact = 0;
1456 }
1457
1458 rcom->name_hash = bgp_clist_hash_key(rcom->name);
1459 return rcom;
1460 }
1461
1462 /* Compile function for community match. */
1463 static void route_match_lcommunity_free(void *rule)
1464 {
1465 struct rmap_community *rcom = rule;
1466
1467 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name);
1468 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
1469 }
1470
1471 /* Route map commands for community matching. */
1472 static const struct route_map_rule_cmd route_match_lcommunity_cmd = {
1473 "large-community",
1474 route_match_lcommunity,
1475 route_match_lcommunity_compile,
1476 route_match_lcommunity_free,
1477 route_match_get_community_key
1478 };
1479
1480
1481 /* Match function for extcommunity match. */
1482 static enum route_map_cmd_result_t
1483 route_match_ecommunity(void *rule, const struct prefix *prefix, void *object)
1484 {
1485 struct community_list *list;
1486 struct bgp_path_info *path;
1487 struct rmap_community *rcom = rule;
1488
1489 path = object;
1490
1491 list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash,
1492 EXTCOMMUNITY_LIST_MASTER);
1493 if (!list)
1494 return RMAP_NOMATCH;
1495
1496 if (ecommunity_list_match(path->attr->ecommunity, list))
1497 return RMAP_MATCH;
1498
1499 return RMAP_NOMATCH;
1500 }
1501
1502 /* Compile function for extcommunity match. */
1503 static void *route_match_ecommunity_compile(const char *arg)
1504 {
1505 struct rmap_community *rcom;
1506
1507 rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community));
1508 rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1509 rcom->name_hash = bgp_clist_hash_key(rcom->name);
1510
1511 return rcom;
1512 }
1513
1514 /* Compile function for extcommunity match. */
1515 static void route_match_ecommunity_free(void *rule)
1516 {
1517 struct rmap_community *rcom = rule;
1518
1519 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name);
1520 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
1521 }
1522
1523 /* Route map commands for community matching. */
1524 static const struct route_map_rule_cmd route_match_ecommunity_cmd = {
1525 "extcommunity",
1526 route_match_ecommunity,
1527 route_match_ecommunity_compile,
1528 route_match_ecommunity_free
1529 };
1530
1531 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1532 and `address-family vpnv4'. */
1533
1534 /* `match origin' */
1535 static enum route_map_cmd_result_t
1536 route_match_origin(void *rule, const struct prefix *prefix, void *object)
1537 {
1538 uint8_t *origin;
1539 struct bgp_path_info *path;
1540
1541 origin = rule;
1542 path = object;
1543
1544 if (path->attr->origin == *origin)
1545 return RMAP_MATCH;
1546
1547 return RMAP_NOMATCH;
1548 }
1549
1550 static void *route_match_origin_compile(const char *arg)
1551 {
1552 uint8_t *origin;
1553
1554 origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t));
1555
1556 if (strcmp(arg, "igp") == 0)
1557 *origin = 0;
1558 else if (strcmp(arg, "egp") == 0)
1559 *origin = 1;
1560 else
1561 *origin = 2;
1562
1563 return origin;
1564 }
1565
1566 /* Free route map's compiled `ip address' value. */
1567 static void route_match_origin_free(void *rule)
1568 {
1569 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1570 }
1571
1572 /* Route map commands for origin matching. */
1573 static const struct route_map_rule_cmd route_match_origin_cmd = {
1574 "origin",
1575 route_match_origin,
1576 route_match_origin_compile,
1577 route_match_origin_free
1578 };
1579
1580 /* match probability { */
1581
1582 static enum route_map_cmd_result_t
1583 route_match_probability(void *rule, const struct prefix *prefix, void *object)
1584 {
1585 long r = frr_weak_random();
1586
1587 switch (*(long *)rule) {
1588 case 0:
1589 break;
1590 case RAND_MAX:
1591 return RMAP_MATCH;
1592 default:
1593 if (r < *(long *)rule) {
1594 return RMAP_MATCH;
1595 }
1596 }
1597
1598 return RMAP_NOMATCH;
1599 }
1600
1601 static void *route_match_probability_compile(const char *arg)
1602 {
1603 long *lobule;
1604 unsigned perc;
1605
1606 perc = atoi(arg);
1607 lobule = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(long));
1608
1609 switch (perc) {
1610 case 0:
1611 *lobule = 0;
1612 break;
1613 case 100:
1614 *lobule = RAND_MAX;
1615 break;
1616 default:
1617 *lobule = RAND_MAX / 100 * perc;
1618 }
1619
1620 return lobule;
1621 }
1622
1623 static void route_match_probability_free(void *rule)
1624 {
1625 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1626 }
1627
1628 static const struct route_map_rule_cmd route_match_probability_cmd = {
1629 "probability",
1630 route_match_probability,
1631 route_match_probability_compile,
1632 route_match_probability_free
1633 };
1634
1635 /* `match interface IFNAME' */
1636 /* Match function should return 1 if match is success else return
1637 zero. */
1638 static enum route_map_cmd_result_t
1639 route_match_interface(void *rule, const struct prefix *prefix, void *object)
1640 {
1641 struct interface *ifp;
1642 struct bgp_path_info *path;
1643
1644 path = object;
1645
1646 if (!path)
1647 return RMAP_NOMATCH;
1648
1649 ifp = if_lookup_by_name_all_vrf((char *)rule);
1650
1651 if (ifp == NULL || ifp->ifindex != path->attr->nh_ifindex)
1652 return RMAP_NOMATCH;
1653
1654 return RMAP_MATCH;
1655 }
1656
1657 /* Route map `interface' match statement. `arg' should be
1658 interface name. */
1659 static void *route_match_interface_compile(const char *arg)
1660 {
1661 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
1662 }
1663
1664 /* Free route map's compiled `interface' value. */
1665 static void route_match_interface_free(void *rule)
1666 {
1667 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1668 }
1669
1670 /* Route map commands for ip address matching. */
1671 static const struct route_map_rule_cmd route_match_interface_cmd = {
1672 "interface",
1673 route_match_interface,
1674 route_match_interface_compile,
1675 route_match_interface_free
1676 };
1677
1678 /* } */
1679
1680 /* `set ip next-hop IP_ADDRESS' */
1681
1682 /* Match function return 1 if match is success else return zero. */
1683 static enum route_map_cmd_result_t
1684 route_match_tag(void *rule, const struct prefix *prefix, void *object)
1685 {
1686 route_tag_t *tag;
1687 struct bgp_path_info *path;
1688
1689 tag = rule;
1690 path = object;
1691
1692 return ((path->attr->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH);
1693 }
1694
1695
1696 /* Route map commands for tag matching. */
1697 static const struct route_map_rule_cmd route_match_tag_cmd = {
1698 "tag",
1699 route_match_tag,
1700 route_map_rule_tag_compile,
1701 route_map_rule_tag_free,
1702 };
1703
1704 static enum route_map_cmd_result_t
1705 route_set_srte_color(void *rule, const struct prefix *prefix, void *object)
1706 {
1707 uint32_t *srte_color = rule;
1708 struct bgp_path_info *path;
1709
1710 path = object;
1711
1712 path->attr->srte_color = *srte_color;
1713 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR);
1714
1715 return RMAP_OKAY;
1716 }
1717
1718 /* Route map `sr-te color' compile function */
1719 static void *route_set_srte_color_compile(const char *arg)
1720 {
1721 uint32_t *color;
1722
1723 color = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
1724 *color = atoi(arg);
1725
1726 return color;
1727 }
1728
1729 /* Free route map's compiled `sr-te color' value. */
1730 static void route_set_srte_color_free(void *rule)
1731 {
1732 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1733 }
1734
1735 /* Route map commands for sr-te color set. */
1736 struct route_map_rule_cmd route_set_srte_color_cmd = {
1737 "sr-te color", route_set_srte_color, route_set_srte_color_compile,
1738 route_set_srte_color_free};
1739
1740 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1741 struct rmap_ip_nexthop_set {
1742 struct in_addr *address;
1743 int peer_address;
1744 int unchanged;
1745 };
1746
1747 static enum route_map_cmd_result_t
1748 route_set_ip_nexthop(void *rule, const struct prefix *prefix, void *object)
1749 {
1750 struct rmap_ip_nexthop_set *rins = rule;
1751 struct bgp_path_info *path;
1752 struct peer *peer;
1753
1754 if (prefix->family == AF_INET6)
1755 return RMAP_OKAY;
1756
1757 path = object;
1758 peer = path->peer;
1759
1760 if (rins->unchanged) {
1761 SET_FLAG(path->attr->rmap_change_flags,
1762 BATTR_RMAP_NEXTHOP_UNCHANGED);
1763 } else if (rins->peer_address) {
1764 if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
1765 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
1766 && peer->su_remote
1767 && sockunion_family(peer->su_remote) == AF_INET) {
1768 path->attr->nexthop.s_addr =
1769 sockunion2ip(peer->su_remote);
1770 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
1771 } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) {
1772 /* The next hop value will be set as part of
1773 * packet rewrite. Set the flags here to indicate
1774 * that rewrite needs to be done.
1775 * Also, clear the value.
1776 */
1777 SET_FLAG(path->attr->rmap_change_flags,
1778 BATTR_RMAP_NEXTHOP_PEER_ADDRESS);
1779 path->attr->nexthop.s_addr = INADDR_ANY;
1780 }
1781 } else {
1782 /* Set next hop value. */
1783 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
1784 path->attr->nexthop = *rins->address;
1785 SET_FLAG(path->attr->rmap_change_flags,
1786 BATTR_RMAP_IPV4_NHOP_CHANGED);
1787 /* case for MP-BGP : MPLS VPN */
1788 path->attr->mp_nexthop_global_in = *rins->address;
1789 path->attr->mp_nexthop_len = sizeof(*rins->address);
1790 }
1791
1792 return RMAP_OKAY;
1793 }
1794
1795 /* Route map `ip nexthop' compile function. Given string is converted
1796 to struct in_addr structure. */
1797 static void *route_set_ip_nexthop_compile(const char *arg)
1798 {
1799 struct rmap_ip_nexthop_set *rins;
1800 struct in_addr *address = NULL;
1801 int peer_address = 0;
1802 int unchanged = 0;
1803 int ret;
1804
1805 if (strcmp(arg, "peer-address") == 0)
1806 peer_address = 1;
1807 else if (strcmp(arg, "unchanged") == 0)
1808 unchanged = 1;
1809 else {
1810 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
1811 sizeof(struct in_addr));
1812 ret = inet_aton(arg, address);
1813
1814 if (ret == 0) {
1815 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
1816 return NULL;
1817 }
1818 }
1819
1820 rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED,
1821 sizeof(struct rmap_ip_nexthop_set));
1822
1823 rins->address = address;
1824 rins->peer_address = peer_address;
1825 rins->unchanged = unchanged;
1826
1827 return rins;
1828 }
1829
1830 /* Free route map's compiled `ip nexthop' value. */
1831 static void route_set_ip_nexthop_free(void *rule)
1832 {
1833 struct rmap_ip_nexthop_set *rins = rule;
1834
1835 XFREE(MTYPE_ROUTE_MAP_COMPILED, rins->address);
1836
1837 XFREE(MTYPE_ROUTE_MAP_COMPILED, rins);
1838 }
1839
1840 /* Route map commands for ip nexthop set. */
1841 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd = {
1842 "ip next-hop",
1843 route_set_ip_nexthop,
1844 route_set_ip_nexthop_compile,
1845 route_set_ip_nexthop_free
1846 };
1847
1848 /* `set local-preference LOCAL_PREF' */
1849
1850 /* Set local preference. */
1851 static enum route_map_cmd_result_t
1852 route_set_local_pref(void *rule, const struct prefix *prefix, void *object)
1853 {
1854 struct rmap_value *rv;
1855 struct bgp_path_info *path;
1856 uint32_t locpref = 0;
1857
1858 /* Fetch routemap's rule information. */
1859 rv = rule;
1860 path = object;
1861
1862 /* Set local preference value. */
1863 if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
1864 locpref = path->attr->local_pref;
1865
1866 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
1867 path->attr->local_pref = route_value_adjust(rv, locpref, path->peer);
1868
1869 return RMAP_OKAY;
1870 }
1871
1872 /* Set local preference rule structure. */
1873 static const struct route_map_rule_cmd route_set_local_pref_cmd = {
1874 "local-preference",
1875 route_set_local_pref,
1876 route_value_compile,
1877 route_value_free,
1878 };
1879
1880 /* `set weight WEIGHT' */
1881
1882 /* Set weight. */
1883 static enum route_map_cmd_result_t
1884 route_set_weight(void *rule, const struct prefix *prefix, void *object)
1885 {
1886 struct rmap_value *rv;
1887 struct bgp_path_info *path;
1888
1889 /* Fetch routemap's rule information. */
1890 rv = rule;
1891 path = object;
1892
1893 /* Set weight value. */
1894 path->attr->weight = route_value_adjust(rv, 0, path->peer);
1895
1896 return RMAP_OKAY;
1897 }
1898
1899 /* Set local preference rule structure. */
1900 static const struct route_map_rule_cmd route_set_weight_cmd = {
1901 "weight",
1902 route_set_weight,
1903 route_value_compile,
1904 route_value_free,
1905 };
1906
1907 /* `set distance DISTANCE */
1908 static enum route_map_cmd_result_t
1909 route_set_distance(void *rule, const struct prefix *prefix, void *object)
1910 {
1911 struct bgp_path_info *path = object;
1912 struct rmap_value *rv = rule;
1913
1914 path->attr->distance = rv->value;
1915
1916 return RMAP_OKAY;
1917 }
1918
1919 /* set distance rule structure */
1920 static const struct route_map_rule_cmd route_set_distance_cmd = {
1921 "distance",
1922 route_set_distance,
1923 route_value_compile,
1924 route_value_free,
1925 };
1926
1927 /* `set metric METRIC' */
1928
1929 /* Set metric to attribute. */
1930 static enum route_map_cmd_result_t
1931 route_set_metric(void *rule, const struct prefix *prefix, void *object)
1932 {
1933 struct rmap_value *rv;
1934 struct bgp_path_info *path;
1935 uint32_t med = 0;
1936
1937 /* Fetch routemap's rule information. */
1938 rv = rule;
1939 path = object;
1940
1941 if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
1942 med = path->attr->med;
1943
1944 path->attr->med = route_value_adjust(rv, med, path->peer);
1945 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
1946
1947 return RMAP_OKAY;
1948 }
1949
1950 /* Set metric rule structure. */
1951 static const struct route_map_rule_cmd route_set_metric_cmd = {
1952 "metric",
1953 route_set_metric,
1954 route_value_compile,
1955 route_value_free,
1956 };
1957
1958 /* `set table (1-4294967295)' */
1959
1960 static enum route_map_cmd_result_t
1961 route_set_table_id(void *rule, const struct prefix *prefix,
1962
1963 void *object)
1964 {
1965 struct rmap_value *rv;
1966 struct bgp_path_info *path;
1967
1968 /* Fetch routemap's rule information. */
1969 rv = rule;
1970 path = object;
1971
1972 path->attr->rmap_table_id = rv->value;
1973
1974 return RMAP_OKAY;
1975 }
1976
1977 /* Set table_id rule structure. */
1978 static const struct route_map_rule_cmd route_set_table_id_cmd = {
1979 "table",
1980 route_set_table_id,
1981 route_value_compile,
1982 route_value_free
1983 };
1984
1985 /* `set as-path prepend ASPATH' */
1986
1987 /* For AS path prepend mechanism. */
1988 static enum route_map_cmd_result_t
1989 route_set_aspath_prepend(void *rule, const struct prefix *prefix, void *object)
1990 {
1991 struct aspath *aspath;
1992 struct aspath *new;
1993 struct bgp_path_info *path;
1994
1995 path = object;
1996
1997 if (path->attr->aspath->refcnt)
1998 new = aspath_dup(path->attr->aspath);
1999 else
2000 new = path->attr->aspath;
2001
2002 if ((uintptr_t)rule > 10) {
2003 aspath = rule;
2004 aspath_prepend(aspath, new);
2005 } else {
2006 as_t as = aspath_leftmost(new);
2007 if (!as)
2008 as = path->peer->as;
2009 new = aspath_add_seq_n(new, as, (uintptr_t)rule);
2010 }
2011
2012 path->attr->aspath = new;
2013
2014 return RMAP_OKAY;
2015 }
2016
2017 static void *route_set_aspath_prepend_compile(const char *arg)
2018 {
2019 unsigned int num;
2020
2021 if (sscanf(arg, "last-as %u", &num) == 1 && num > 0 && num <= 10)
2022 return (void *)(uintptr_t)num;
2023
2024 return route_aspath_compile(arg);
2025 }
2026
2027 static void route_set_aspath_prepend_free(void *rule)
2028 {
2029 if ((uintptr_t)rule > 10)
2030 route_aspath_free(rule);
2031 }
2032
2033
2034 /* Set as-path prepend rule structure. */
2035 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd = {
2036 "as-path prepend",
2037 route_set_aspath_prepend,
2038 route_set_aspath_prepend_compile,
2039 route_set_aspath_prepend_free,
2040 };
2041
2042 /* `set as-path exclude ASn' */
2043
2044 /* For ASN exclude mechanism.
2045 * Iterate over ASns requested and filter them from the given AS_PATH one by
2046 * one.
2047 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2048 */
2049 static enum route_map_cmd_result_t
2050 route_set_aspath_exclude(void *rule, const struct prefix *dummy, void *object)
2051 {
2052 struct aspath *new_path, *exclude_path;
2053 struct bgp_path_info *path;
2054
2055 exclude_path = rule;
2056 path = object;
2057 if (path->attr->aspath->refcnt)
2058 new_path = aspath_dup(path->attr->aspath);
2059 else
2060 new_path = path->attr->aspath;
2061 path->attr->aspath = aspath_filter_exclude(new_path, exclude_path);
2062
2063 return RMAP_OKAY;
2064 }
2065
2066 /* Set ASn exlude rule structure. */
2067 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd = {
2068 "as-path exclude",
2069 route_set_aspath_exclude,
2070 route_aspath_compile,
2071 route_aspath_free,
2072 };
2073
2074 /* `set community COMMUNITY' */
2075 struct rmap_com_set {
2076 struct community *com;
2077 int additive;
2078 int none;
2079 };
2080
2081 /* For community set mechanism. */
2082 static enum route_map_cmd_result_t
2083 route_set_community(void *rule, const struct prefix *prefix, void *object)
2084 {
2085 struct rmap_com_set *rcs;
2086 struct bgp_path_info *path;
2087 struct attr *attr;
2088 struct community *new = NULL;
2089 struct community *old;
2090 struct community *merge;
2091
2092 rcs = rule;
2093 path = object;
2094 attr = path->attr;
2095 old = attr->community;
2096
2097 /* "none" case. */
2098 if (rcs->none) {
2099 attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
2100 attr->community = NULL;
2101 /* See the longer comment down below. */
2102 if (old && old->refcnt == 0)
2103 community_free(&old);
2104 return RMAP_OKAY;
2105 }
2106
2107 /* "additive" case. */
2108 if (rcs->additive && old) {
2109 merge = community_merge(community_dup(old), rcs->com);
2110
2111 new = community_uniq_sort(merge);
2112 community_free(&merge);
2113 } else
2114 new = community_dup(rcs->com);
2115
2116 /* HACK: if the old community is not intern'd,
2117 * we should free it here, or all reference to it may be
2118 * lost.
2119 * Really need to cleanup attribute caching sometime.
2120 */
2121 if (old && old->refcnt == 0)
2122 community_free(&old);
2123
2124 /* will be interned by caller if required */
2125 attr->community = new;
2126
2127 attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
2128
2129 return RMAP_OKAY;
2130 }
2131
2132 /* Compile function for set community. */
2133 static void *route_set_community_compile(const char *arg)
2134 {
2135 struct rmap_com_set *rcs;
2136 struct community *com = NULL;
2137 char *sp;
2138 int additive = 0;
2139 int none = 0;
2140
2141 if (strcmp(arg, "none") == 0)
2142 none = 1;
2143 else {
2144 sp = strstr(arg, "additive");
2145
2146 if (sp && sp > arg) {
2147 /* "additive" keyword is included. */
2148 additive = 1;
2149 *(sp - 1) = '\0';
2150 }
2151
2152 com = community_str2com(arg);
2153
2154 if (additive)
2155 *(sp - 1) = ' ';
2156
2157 if (!com)
2158 return NULL;
2159 }
2160
2161 rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set));
2162 rcs->com = com;
2163 rcs->additive = additive;
2164 rcs->none = none;
2165
2166 return rcs;
2167 }
2168
2169 /* Free function for set community. */
2170 static void route_set_community_free(void *rule)
2171 {
2172 struct rmap_com_set *rcs = rule;
2173
2174 if (rcs->com)
2175 community_free(&rcs->com);
2176 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs);
2177 }
2178
2179 /* Set community rule structure. */
2180 static const struct route_map_rule_cmd route_set_community_cmd = {
2181 "community",
2182 route_set_community,
2183 route_set_community_compile,
2184 route_set_community_free,
2185 };
2186
2187 /* `set community COMMUNITY' */
2188 struct rmap_lcom_set {
2189 struct lcommunity *lcom;
2190 int additive;
2191 int none;
2192 };
2193
2194
2195 /* For lcommunity set mechanism. */
2196 static enum route_map_cmd_result_t
2197 route_set_lcommunity(void *rule, const struct prefix *prefix, void *object)
2198 {
2199 struct rmap_lcom_set *rcs;
2200 struct bgp_path_info *path;
2201 struct attr *attr;
2202 struct lcommunity *new = NULL;
2203 struct lcommunity *old;
2204 struct lcommunity *merge;
2205
2206 rcs = rule;
2207 path = object;
2208 attr = path->attr;
2209 old = attr->lcommunity;
2210
2211 /* "none" case. */
2212 if (rcs->none) {
2213 attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
2214 attr->lcommunity = NULL;
2215
2216 /* See the longer comment down below. */
2217 if (old && old->refcnt == 0)
2218 lcommunity_free(&old);
2219 return RMAP_OKAY;
2220 }
2221
2222 if (rcs->additive && old) {
2223 merge = lcommunity_merge(lcommunity_dup(old), rcs->lcom);
2224
2225 new = lcommunity_uniq_sort(merge);
2226 lcommunity_free(&merge);
2227 } else
2228 new = lcommunity_dup(rcs->lcom);
2229
2230 /* HACK: if the old large-community is not intern'd,
2231 * we should free it here, or all reference to it may be
2232 * lost.
2233 * Really need to cleanup attribute caching sometime.
2234 */
2235 if (old && old->refcnt == 0)
2236 lcommunity_free(&old);
2237
2238 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2239 attr->lcommunity = new;
2240
2241 attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
2242
2243 return RMAP_OKAY;
2244 }
2245
2246 /* Compile function for set community. */
2247 static void *route_set_lcommunity_compile(const char *arg)
2248 {
2249 struct rmap_lcom_set *rcs;
2250 struct lcommunity *lcom = NULL;
2251 char *sp;
2252 int additive = 0;
2253 int none = 0;
2254
2255 if (strcmp(arg, "none") == 0)
2256 none = 1;
2257 else {
2258 sp = strstr(arg, "additive");
2259
2260 if (sp && sp > arg) {
2261 /* "additive" keyworkd is included. */
2262 additive = 1;
2263 *(sp - 1) = '\0';
2264 }
2265
2266 lcom = lcommunity_str2com(arg);
2267
2268 if (additive)
2269 *(sp - 1) = ' ';
2270
2271 if (!lcom)
2272 return NULL;
2273 }
2274
2275 rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set));
2276 rcs->lcom = lcom;
2277 rcs->additive = additive;
2278 rcs->none = none;
2279
2280 return rcs;
2281 }
2282
2283 /* Free function for set lcommunity. */
2284 static void route_set_lcommunity_free(void *rule)
2285 {
2286 struct rmap_lcom_set *rcs = rule;
2287
2288 if (rcs->lcom) {
2289 lcommunity_free(&rcs->lcom);
2290 }
2291 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs);
2292 }
2293
2294 /* Set community rule structure. */
2295 static const struct route_map_rule_cmd route_set_lcommunity_cmd = {
2296 "large-community",
2297 route_set_lcommunity,
2298 route_set_lcommunity_compile,
2299 route_set_lcommunity_free,
2300 };
2301
2302 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2303
2304 /* For large community set mechanism. */
2305 static enum route_map_cmd_result_t
2306 route_set_lcommunity_delete(void *rule, const struct prefix *pfx, void *object)
2307 {
2308 struct community_list *list;
2309 struct lcommunity *merge;
2310 struct lcommunity *new;
2311 struct lcommunity *old;
2312 struct bgp_path_info *path;
2313 struct rmap_community *rcom = rule;
2314
2315 if (!rcom)
2316 return RMAP_OKAY;
2317
2318 path = object;
2319 list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash,
2320 LARGE_COMMUNITY_LIST_MASTER);
2321 old = path->attr->lcommunity;
2322
2323 if (list && old) {
2324 merge = lcommunity_list_match_delete(lcommunity_dup(old), list);
2325 new = lcommunity_uniq_sort(merge);
2326 lcommunity_free(&merge);
2327
2328 /* HACK: if the old community is not intern'd,
2329 * we should free it here, or all reference to it may be
2330 * lost.
2331 * Really need to cleanup attribute caching sometime.
2332 */
2333 if (old->refcnt == 0)
2334 lcommunity_free(&old);
2335
2336 if (new->size == 0) {
2337 path->attr->lcommunity = NULL;
2338 path->attr->flag &=
2339 ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
2340 lcommunity_free(&new);
2341 } else {
2342 path->attr->lcommunity = new;
2343 path->attr->flag |=
2344 ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
2345 }
2346 }
2347
2348 return RMAP_OKAY;
2349 }
2350
2351 /* Compile function for set lcommunity. */
2352 static void *route_set_lcommunity_delete_compile(const char *arg)
2353 {
2354 struct rmap_community *rcom;
2355 char **splits;
2356 int num;
2357
2358 frrstr_split(arg, " ", &splits, &num);
2359
2360 rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community));
2361 rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, splits[0]);
2362 rcom->name_hash = bgp_clist_hash_key(rcom->name);
2363
2364 for (int i = 0; i < num; i++)
2365 XFREE(MTYPE_TMP, splits[i]);
2366 XFREE(MTYPE_TMP, splits);
2367
2368 return rcom;
2369 }
2370
2371 /* Free function for set lcommunity. */
2372 static void route_set_lcommunity_delete_free(void *rule)
2373 {
2374 struct rmap_community *rcom = rule;
2375
2376 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name);
2377 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
2378 }
2379
2380 /* Set lcommunity rule structure. */
2381 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd = {
2382 "large-comm-list",
2383 route_set_lcommunity_delete,
2384 route_set_lcommunity_delete_compile,
2385 route_set_lcommunity_delete_free,
2386 };
2387
2388
2389 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2390
2391 /* For community set mechanism. */
2392 static enum route_map_cmd_result_t
2393 route_set_community_delete(void *rule, const struct prefix *prefix,
2394 void *object)
2395 {
2396 struct community_list *list;
2397 struct community *merge;
2398 struct community *new;
2399 struct community *old;
2400 struct bgp_path_info *path;
2401 struct rmap_community *rcom = rule;
2402
2403 if (!rcom)
2404 return RMAP_OKAY;
2405
2406 path = object;
2407 list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash,
2408 COMMUNITY_LIST_MASTER);
2409 old = path->attr->community;
2410
2411 if (list && old) {
2412 merge = community_list_match_delete(community_dup(old), list);
2413 new = community_uniq_sort(merge);
2414 community_free(&merge);
2415
2416 /* HACK: if the old community is not intern'd,
2417 * we should free it here, or all reference to it may be
2418 * lost.
2419 * Really need to cleanup attribute caching sometime.
2420 */
2421 if (old->refcnt == 0)
2422 community_free(&old);
2423
2424 if (new->size == 0) {
2425 path->attr->community = NULL;
2426 path->attr->flag &=
2427 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
2428 community_free(&new);
2429 } else {
2430 path->attr->community = new;
2431 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
2432 }
2433 }
2434
2435 return RMAP_OKAY;
2436 }
2437
2438 /* Compile function for set community. */
2439 static void *route_set_community_delete_compile(const char *arg)
2440 {
2441 struct rmap_community *rcom;
2442 char **splits;
2443 int num;
2444
2445 frrstr_split(arg, " ", &splits, &num);
2446
2447 rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community));
2448 rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, splits[0]);
2449 rcom->name_hash = bgp_clist_hash_key(rcom->name);
2450
2451 for (int i = 0; i < num; i++)
2452 XFREE(MTYPE_TMP, splits[i]);
2453 XFREE(MTYPE_TMP, splits);
2454
2455 return rcom;
2456 }
2457
2458 /* Free function for set community. */
2459 static void route_set_community_delete_free(void *rule)
2460 {
2461 struct rmap_community *rcom = rule;
2462
2463 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name);
2464 XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
2465 }
2466
2467 /* Set community rule structure. */
2468 static const struct route_map_rule_cmd route_set_community_delete_cmd = {
2469 "comm-list",
2470 route_set_community_delete,
2471 route_set_community_delete_compile,
2472 route_set_community_delete_free,
2473 };
2474
2475 /* `set extcommunity rt COMMUNITY' */
2476
2477 /* For community set mechanism. Used by _rt and _soo. */
2478 static enum route_map_cmd_result_t
2479 route_set_ecommunity(void *rule, const struct prefix *prefix, void *object)
2480 {
2481 struct ecommunity *ecom;
2482 struct ecommunity *new_ecom;
2483 struct ecommunity *old_ecom;
2484 struct bgp_path_info *path;
2485
2486 ecom = rule;
2487 path = object;
2488
2489 if (!ecom)
2490 return RMAP_OKAY;
2491
2492 /* We assume additive for Extended Community. */
2493 old_ecom = path->attr->ecommunity;
2494
2495 if (old_ecom) {
2496 new_ecom = ecommunity_merge(ecommunity_dup(old_ecom), ecom);
2497
2498 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2499 * bgp_update_receive()
2500 * ->refcnt = 0 => set by a previous route-map
2501 * statement */
2502 if (!old_ecom->refcnt)
2503 ecommunity_free(&old_ecom);
2504 } else
2505 new_ecom = ecommunity_dup(ecom);
2506
2507 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2508 path->attr->ecommunity = new_ecom;
2509
2510 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
2511
2512 return RMAP_OKAY;
2513 }
2514
2515 /* Compile function for set community. */
2516 static void *route_set_ecommunity_rt_compile(const char *arg)
2517 {
2518 struct ecommunity *ecom;
2519
2520 ecom = ecommunity_str2com(arg, ECOMMUNITY_ROUTE_TARGET, 0);
2521 if (!ecom)
2522 return NULL;
2523 return ecommunity_intern(ecom);
2524 }
2525
2526 /* Free function for set community. Used by _rt and _soo */
2527 static void route_set_ecommunity_free(void *rule)
2528 {
2529 struct ecommunity *ecom = rule;
2530 ecommunity_unintern(&ecom);
2531 }
2532
2533 /* Set community rule structure. */
2534 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd = {
2535 "extcommunity rt",
2536 route_set_ecommunity,
2537 route_set_ecommunity_rt_compile,
2538 route_set_ecommunity_free,
2539 };
2540
2541 /* `set extcommunity soo COMMUNITY' */
2542
2543 /* Compile function for set community. */
2544 static void *route_set_ecommunity_soo_compile(const char *arg)
2545 {
2546 struct ecommunity *ecom;
2547
2548 ecom = ecommunity_str2com(arg, ECOMMUNITY_SITE_ORIGIN, 0);
2549 if (!ecom)
2550 return NULL;
2551
2552 return ecommunity_intern(ecom);
2553 }
2554
2555 /* Set community rule structure. */
2556 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd = {
2557 "extcommunity soo",
2558 route_set_ecommunity,
2559 route_set_ecommunity_soo_compile,
2560 route_set_ecommunity_free,
2561 };
2562
2563 /* `set extcommunity bandwidth' */
2564
2565 struct rmap_ecomm_lb_set {
2566 uint8_t lb_type;
2567 #define RMAP_ECOMM_LB_SET_VALUE 1
2568 #define RMAP_ECOMM_LB_SET_CUMUL 2
2569 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2570 bool non_trans;
2571 uint32_t bw;
2572 };
2573
2574 static enum route_map_cmd_result_t
2575 route_set_ecommunity_lb(void *rule, const struct prefix *prefix, void *object)
2576 {
2577 struct rmap_ecomm_lb_set *rels = rule;
2578 struct bgp_path_info *path;
2579 struct peer *peer;
2580 struct ecommunity ecom_lb = {0};
2581 struct ecommunity_val lb_eval;
2582 uint32_t bw_bytes = 0;
2583 uint16_t mpath_count = 0;
2584 struct ecommunity *new_ecom;
2585 struct ecommunity *old_ecom;
2586 as_t as;
2587
2588 path = object;
2589 peer = path->peer;
2590 if (!peer || !peer->bgp)
2591 return RMAP_ERROR;
2592
2593 /* Build link bandwidth extended community */
2594 as = (peer->bgp->as > BGP_AS_MAX) ? BGP_AS_TRANS : peer->bgp->as;
2595 if (rels->lb_type == RMAP_ECOMM_LB_SET_VALUE) {
2596 bw_bytes = ((uint64_t)rels->bw * 1000 * 1000) / 8;
2597 } else if (rels->lb_type == RMAP_ECOMM_LB_SET_CUMUL) {
2598 /* process this only for the best path. */
2599 if (!CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
2600 return RMAP_OKAY;
2601
2602 bw_bytes = (uint32_t)bgp_path_info_mpath_cumbw(path);
2603 if (!bw_bytes)
2604 return RMAP_OKAY;
2605
2606 } else if (rels->lb_type == RMAP_ECOMM_LB_SET_NUM_MPATH) {
2607
2608 /* process this only for the best path. */
2609 if (!CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
2610 return RMAP_OKAY;
2611
2612 bw_bytes = ((uint64_t)peer->bgp->lb_ref_bw * 1000 * 1000) / 8;
2613 mpath_count = bgp_path_info_mpath_count(path) + 1;
2614 bw_bytes *= mpath_count;
2615 }
2616
2617 encode_lb_extcomm(as, bw_bytes, rels->non_trans, &lb_eval);
2618
2619 /* add to route or merge with existing */
2620 old_ecom = path->attr->ecommunity;
2621 if (old_ecom) {
2622 new_ecom = ecommunity_dup(old_ecom);
2623 ecommunity_add_val(new_ecom, &lb_eval, true, true);
2624 if (!old_ecom->refcnt)
2625 ecommunity_free(&old_ecom);
2626 } else {
2627 ecom_lb.size = 1;
2628 ecom_lb.unit_size = ECOMMUNITY_SIZE;
2629 ecom_lb.val = (uint8_t *)lb_eval.val;
2630 new_ecom = ecommunity_dup(&ecom_lb);
2631 }
2632
2633 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2634 path->attr->ecommunity = new_ecom;
2635 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
2636
2637 /* Mark that route-map has set link bandwidth; used in attribute
2638 * setting decisions.
2639 */
2640 SET_FLAG(path->attr->rmap_change_flags, BATTR_RMAP_LINK_BW_SET);
2641
2642 return RMAP_OKAY;
2643 }
2644
2645 static void *route_set_ecommunity_lb_compile(const char *arg)
2646 {
2647 struct rmap_ecomm_lb_set *rels;
2648 uint8_t lb_type;
2649 uint32_t bw = 0;
2650 char bw_str[40] = {0};
2651 char *p, *str;
2652 bool non_trans = false;
2653
2654 str = (char *)arg;
2655 p = strchr(arg, ' ');
2656 if (p) {
2657 int len;
2658
2659 len = p - arg;
2660 memcpy(bw_str, arg, len);
2661 non_trans = true;
2662 str = bw_str;
2663 }
2664
2665 if (strcmp(str, "cumulative") == 0)
2666 lb_type = RMAP_ECOMM_LB_SET_CUMUL;
2667 else if (strcmp(str, "num-multipaths") == 0)
2668 lb_type = RMAP_ECOMM_LB_SET_NUM_MPATH;
2669 else {
2670 char *end = NULL;
2671
2672 bw = strtoul(str, &end, 10);
2673 if (*end != '\0')
2674 return NULL;
2675 lb_type = RMAP_ECOMM_LB_SET_VALUE;
2676 }
2677
2678 rels = XCALLOC(MTYPE_ROUTE_MAP_COMPILED,
2679 sizeof(struct rmap_ecomm_lb_set));
2680 rels->lb_type = lb_type;
2681 rels->bw = bw;
2682 rels->non_trans = non_trans;
2683
2684 return rels;
2685 }
2686
2687 static void route_set_ecommunity_lb_free(void *rule)
2688 {
2689 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
2690 }
2691
2692 /* Set community rule structure. */
2693 struct route_map_rule_cmd route_set_ecommunity_lb_cmd = {
2694 "extcommunity bandwidth",
2695 route_set_ecommunity_lb,
2696 route_set_ecommunity_lb_compile,
2697 route_set_ecommunity_lb_free,
2698 };
2699
2700 /* `set origin ORIGIN' */
2701
2702 /* For origin set. */
2703 static enum route_map_cmd_result_t
2704 route_set_origin(void *rule, const struct prefix *prefix, void *object)
2705 {
2706 uint8_t *origin;
2707 struct bgp_path_info *path;
2708
2709 origin = rule;
2710 path = object;
2711
2712 path->attr->origin = *origin;
2713
2714 return RMAP_OKAY;
2715 }
2716
2717 /* Compile function for origin set. */
2718 static void *route_set_origin_compile(const char *arg)
2719 {
2720 uint8_t *origin;
2721
2722 origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t));
2723
2724 if (strcmp(arg, "igp") == 0)
2725 *origin = 0;
2726 else if (strcmp(arg, "egp") == 0)
2727 *origin = 1;
2728 else
2729 *origin = 2;
2730
2731 return origin;
2732 }
2733
2734 /* Compile function for origin set. */
2735 static void route_set_origin_free(void *rule)
2736 {
2737 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
2738 }
2739
2740 /* Set origin rule structure. */
2741 static const struct route_map_rule_cmd route_set_origin_cmd = {
2742 "origin",
2743 route_set_origin,
2744 route_set_origin_compile,
2745 route_set_origin_free,
2746 };
2747
2748 /* `set atomic-aggregate' */
2749
2750 /* For atomic aggregate set. */
2751 static enum route_map_cmd_result_t
2752 route_set_atomic_aggregate(void *rule, const struct prefix *pfx, void *object)
2753 {
2754 struct bgp_path_info *path;
2755
2756 path = object;
2757 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE);
2758
2759 return RMAP_OKAY;
2760 }
2761
2762 /* Compile function for atomic aggregate. */
2763 static void *route_set_atomic_aggregate_compile(const char *arg)
2764 {
2765 return (void *)1;
2766 }
2767
2768 /* Compile function for atomic aggregate. */
2769 static void route_set_atomic_aggregate_free(void *rule)
2770 {
2771 return;
2772 }
2773
2774 /* Set atomic aggregate rule structure. */
2775 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd = {
2776 "atomic-aggregate",
2777 route_set_atomic_aggregate,
2778 route_set_atomic_aggregate_compile,
2779 route_set_atomic_aggregate_free,
2780 };
2781
2782 /* `set aggregator as AS A.B.C.D' */
2783 struct aggregator {
2784 as_t as;
2785 struct in_addr address;
2786 };
2787
2788 static enum route_map_cmd_result_t
2789 route_set_aggregator_as(void *rule, const struct prefix *prefix, void *object)
2790 {
2791 struct bgp_path_info *path;
2792 struct aggregator *aggregator;
2793
2794 path = object;
2795 aggregator = rule;
2796
2797 path->attr->aggregator_as = aggregator->as;
2798 path->attr->aggregator_addr = aggregator->address;
2799 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR);
2800
2801 return RMAP_OKAY;
2802 }
2803
2804 static void *route_set_aggregator_as_compile(const char *arg)
2805 {
2806 struct aggregator *aggregator;
2807 char as[10];
2808 char address[20];
2809 int ret;
2810
2811 aggregator =
2812 XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct aggregator));
2813 if (sscanf(arg, "%s %s", as, address) != 2) {
2814 XFREE(MTYPE_ROUTE_MAP_COMPILED, aggregator);
2815 return NULL;
2816 }
2817
2818 aggregator->as = strtoul(as, NULL, 10);
2819 ret = inet_aton(address, &aggregator->address);
2820 if (ret == 0) {
2821 XFREE(MTYPE_ROUTE_MAP_COMPILED, aggregator);
2822 return NULL;
2823 }
2824 return aggregator;
2825 }
2826
2827 static void route_set_aggregator_as_free(void *rule)
2828 {
2829 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
2830 }
2831
2832 static const struct route_map_rule_cmd route_set_aggregator_as_cmd = {
2833 "aggregator as",
2834 route_set_aggregator_as,
2835 route_set_aggregator_as_compile,
2836 route_set_aggregator_as_free,
2837 };
2838
2839 /* Set tag to object. object must be pointer to struct bgp_path_info */
2840 static enum route_map_cmd_result_t
2841 route_set_tag(void *rule, const struct prefix *prefix, void *object)
2842 {
2843 route_tag_t *tag;
2844 struct bgp_path_info *path;
2845
2846 tag = rule;
2847 path = object;
2848
2849 /* Set tag value */
2850 path->attr->tag = *tag;
2851
2852 return RMAP_OKAY;
2853 }
2854
2855 /* Route map commands for tag set. */
2856 static const struct route_map_rule_cmd route_set_tag_cmd = {
2857 "tag",
2858 route_set_tag,
2859 route_map_rule_tag_compile,
2860 route_map_rule_tag_free,
2861 };
2862
2863 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2864 static enum route_map_cmd_result_t
2865 route_set_label_index(void *rule, const struct prefix *prefix, void *object)
2866 {
2867 struct rmap_value *rv;
2868 struct bgp_path_info *path;
2869 uint32_t label_index;
2870
2871 /* Fetch routemap's rule information. */
2872 rv = rule;
2873 path = object;
2874
2875 /* Set label-index value. */
2876 label_index = rv->value;
2877 if (label_index) {
2878 path->attr->label_index = label_index;
2879 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID);
2880 }
2881
2882 return RMAP_OKAY;
2883 }
2884
2885 /* Route map commands for label-index set. */
2886 static const struct route_map_rule_cmd route_set_label_index_cmd = {
2887 "label-index",
2888 route_set_label_index,
2889 route_value_compile,
2890 route_value_free,
2891 };
2892
2893 /* `match ipv6 address IP_ACCESS_LIST' */
2894
2895 static enum route_map_cmd_result_t
2896 route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object)
2897 {
2898 struct access_list *alist;
2899
2900 if (prefix->family == AF_INET6) {
2901 alist = access_list_lookup(AFI_IP6, (char *)rule);
2902 if (alist == NULL)
2903 return RMAP_NOMATCH;
2904
2905 return (access_list_apply(alist, prefix) == FILTER_DENY
2906 ? RMAP_NOMATCH
2907 : RMAP_MATCH);
2908 }
2909 return RMAP_NOMATCH;
2910 }
2911
2912 static void *route_match_ipv6_address_compile(const char *arg)
2913 {
2914 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
2915 }
2916
2917 static void route_match_ipv6_address_free(void *rule)
2918 {
2919 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
2920 }
2921
2922 /* Route map commands for ip address matching. */
2923 static const struct route_map_rule_cmd route_match_ipv6_address_cmd = {
2924 "ipv6 address",
2925 route_match_ipv6_address,
2926 route_match_ipv6_address_compile,
2927 route_match_ipv6_address_free
2928 };
2929
2930 /* `match ipv6 next-hop IP_ADDRESS' */
2931
2932 static enum route_map_cmd_result_t
2933 route_match_ipv6_next_hop(void *rule, const struct prefix *prefix, void *object)
2934 {
2935 struct in6_addr *addr = rule;
2936 struct bgp_path_info *path;
2937
2938 path = object;
2939
2940 if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr))
2941 return RMAP_MATCH;
2942
2943 if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2944 && IPV6_ADDR_SAME(&path->attr->mp_nexthop_local, rule))
2945 return RMAP_MATCH;
2946
2947 return RMAP_NOMATCH;
2948 }
2949
2950 static void *route_match_ipv6_next_hop_compile(const char *arg)
2951 {
2952 struct in6_addr *address;
2953 int ret;
2954
2955 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr));
2956
2957 ret = inet_pton(AF_INET6, arg, address);
2958 if (!ret) {
2959 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
2960 return NULL;
2961 }
2962
2963 return address;
2964 }
2965
2966 static void route_match_ipv6_next_hop_free(void *rule)
2967 {
2968 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
2969 }
2970
2971 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = {
2972 "ipv6 next-hop",
2973 route_match_ipv6_next_hop,
2974 route_match_ipv6_next_hop_compile,
2975 route_match_ipv6_next_hop_free
2976 };
2977
2978 /* `match ip next-hop IP_ADDRESS' */
2979
2980 static enum route_map_cmd_result_t
2981 route_match_ipv4_next_hop(void *rule, const struct prefix *prefix, void *object)
2982 {
2983 struct in_addr *addr = rule;
2984 struct bgp_path_info *path;
2985
2986 path = object;
2987
2988 if (path->attr->nexthop.s_addr == addr->s_addr
2989 || (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4
2990 && IPV4_ADDR_SAME(&path->attr->mp_nexthop_global_in, addr)))
2991 return RMAP_MATCH;
2992
2993 return RMAP_NOMATCH;
2994 }
2995
2996 static void *route_match_ipv4_next_hop_compile(const char *arg)
2997 {
2998 struct in_addr *address;
2999 int ret;
3000
3001 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr));
3002
3003 ret = inet_pton(AF_INET, arg, address);
3004 if (!ret) {
3005 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3006 return NULL;
3007 }
3008
3009 return address;
3010 }
3011
3012 static void route_match_ipv4_next_hop_free(void *rule)
3013 {
3014 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3015 }
3016
3017 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd = {
3018 "ip next-hop address",
3019 route_match_ipv4_next_hop,
3020 route_match_ipv4_next_hop_compile,
3021 route_match_ipv4_next_hop_free
3022 };
3023
3024 /* `match ipv6 address prefix-list PREFIX_LIST' */
3025
3026 static enum route_map_cmd_result_t
3027 route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix,
3028 void *object)
3029 {
3030 return route_match_address_prefix_list(rule, AFI_IP6, prefix, object);
3031 }
3032
3033 static void *route_match_ipv6_address_prefix_list_compile(const char *arg)
3034 {
3035 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
3036 }
3037
3038 static void route_match_ipv6_address_prefix_list_free(void *rule)
3039 {
3040 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3041 }
3042
3043 static const struct route_map_rule_cmd
3044 route_match_ipv6_address_prefix_list_cmd = {
3045 "ipv6 address prefix-list",
3046 route_match_ipv6_address_prefix_list,
3047 route_match_ipv6_address_prefix_list_compile,
3048 route_match_ipv6_address_prefix_list_free
3049 };
3050
3051 /* `match ipv6 next-hop type <TYPE>' */
3052
3053 static enum route_map_cmd_result_t
3054 route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix,
3055 void *object)
3056 {
3057 struct bgp_path_info *path;
3058 struct in6_addr *addr = rule;
3059
3060 if (prefix->family == AF_INET6) {
3061 path = (struct bgp_path_info *)object;
3062 if (!path)
3063 return RMAP_NOMATCH;
3064
3065 if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr)
3066 && !path->attr->nh_ifindex)
3067 return RMAP_MATCH;
3068 }
3069
3070 return RMAP_NOMATCH;
3071 }
3072
3073 static void *route_match_ipv6_next_hop_type_compile(const char *arg)
3074 {
3075 struct in6_addr *address;
3076 int ret;
3077
3078 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr));
3079
3080 ret = inet_pton(AF_INET6, "::0", address);
3081 if (!ret) {
3082 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3083 return NULL;
3084 }
3085
3086 return address;
3087 }
3088
3089 static void route_match_ipv6_next_hop_type_free(void *rule)
3090 {
3091 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3092 }
3093
3094 static const struct route_map_rule_cmd
3095 route_match_ipv6_next_hop_type_cmd = {
3096 "ipv6 next-hop type",
3097 route_match_ipv6_next_hop_type,
3098 route_match_ipv6_next_hop_type_compile,
3099 route_match_ipv6_next_hop_type_free
3100 };
3101
3102 /* `set ipv6 nexthop global IP_ADDRESS' */
3103
3104 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3105 static enum route_map_cmd_result_t
3106 route_set_ipv6_nexthop_global(void *rule, const struct prefix *p, void *object)
3107 {
3108 struct in6_addr *address;
3109 struct bgp_path_info *path;
3110
3111 /* Fetch routemap's rule information. */
3112 address = rule;
3113 path = object;
3114
3115 /* Set next hop value. */
3116 path->attr->mp_nexthop_global = *address;
3117
3118 /* Set nexthop length. */
3119 if (path->attr->mp_nexthop_len == 0)
3120 path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
3121
3122 SET_FLAG(path->attr->rmap_change_flags,
3123 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED);
3124
3125 return RMAP_OKAY;
3126 }
3127
3128 /* Route map `ip next-hop' compile function. Given string is converted
3129 to struct in_addr structure. */
3130 static void *route_set_ipv6_nexthop_global_compile(const char *arg)
3131 {
3132 int ret;
3133 struct in6_addr *address;
3134
3135 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr));
3136
3137 ret = inet_pton(AF_INET6, arg, address);
3138
3139 if (ret == 0) {
3140 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3141 return NULL;
3142 }
3143
3144 return address;
3145 }
3146
3147 /* Free route map's compiled `ip next-hop' value. */
3148 static void route_set_ipv6_nexthop_global_free(void *rule)
3149 {
3150 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3151 }
3152
3153 /* Route map commands for ip nexthop set. */
3154 static const struct route_map_rule_cmd
3155 route_set_ipv6_nexthop_global_cmd = {
3156 "ipv6 next-hop global",
3157 route_set_ipv6_nexthop_global,
3158 route_set_ipv6_nexthop_global_compile,
3159 route_set_ipv6_nexthop_global_free
3160 };
3161
3162 /* Set next-hop preference value. */
3163 static enum route_map_cmd_result_t
3164 route_set_ipv6_nexthop_prefer_global(void *rule, const struct prefix *prefix,
3165 void *object)
3166 {
3167 struct bgp_path_info *path;
3168 struct peer *peer;
3169
3170 /* Fetch routemap's rule information. */
3171 path = object;
3172 peer = path->peer;
3173
3174 if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
3175 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) {
3176 /* Set next hop preference to global */
3177 path->attr->mp_nexthop_prefer_global = true;
3178 SET_FLAG(path->attr->rmap_change_flags,
3179 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED);
3180 } else {
3181 path->attr->mp_nexthop_prefer_global = false;
3182 SET_FLAG(path->attr->rmap_change_flags,
3183 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED);
3184 }
3185
3186 return RMAP_OKAY;
3187 }
3188
3189 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg)
3190 {
3191 int *rins = NULL;
3192
3193 rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int));
3194 *rins = 1;
3195
3196 return rins;
3197 }
3198
3199 /* Free route map's compiled `ip next-hop' value. */
3200 static void route_set_ipv6_nexthop_prefer_global_free(void *rule)
3201 {
3202 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3203 }
3204
3205 /* Route map commands for ip nexthop set preferred. */
3206 static const struct route_map_rule_cmd
3207 route_set_ipv6_nexthop_prefer_global_cmd = {
3208 "ipv6 next-hop prefer-global",
3209 route_set_ipv6_nexthop_prefer_global,
3210 route_set_ipv6_nexthop_prefer_global_compile,
3211 route_set_ipv6_nexthop_prefer_global_free
3212 };
3213
3214 /* `set ipv6 nexthop local IP_ADDRESS' */
3215
3216 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3217 static enum route_map_cmd_result_t
3218 route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, void *object)
3219 {
3220 struct in6_addr *address;
3221 struct bgp_path_info *path;
3222
3223 /* Fetch routemap's rule information. */
3224 address = rule;
3225 path = object;
3226
3227 /* Set next hop value. */
3228 path->attr->mp_nexthop_local = *address;
3229
3230 /* Set nexthop length. */
3231 if (path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
3232 path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3233
3234 SET_FLAG(path->attr->rmap_change_flags,
3235 BATTR_RMAP_IPV6_LL_NHOP_CHANGED);
3236
3237 return RMAP_OKAY;
3238 }
3239
3240 /* Route map `ip nexthop' compile function. Given string is converted
3241 to struct in_addr structure. */
3242 static void *route_set_ipv6_nexthop_local_compile(const char *arg)
3243 {
3244 int ret;
3245 struct in6_addr *address;
3246
3247 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr));
3248
3249 ret = inet_pton(AF_INET6, arg, address);
3250
3251 if (ret == 0) {
3252 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3253 return NULL;
3254 }
3255
3256 return address;
3257 }
3258
3259 /* Free route map's compiled `ip nexthop' value. */
3260 static void route_set_ipv6_nexthop_local_free(void *rule)
3261 {
3262 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3263 }
3264
3265 /* Route map commands for ip nexthop set. */
3266 static const struct route_map_rule_cmd
3267 route_set_ipv6_nexthop_local_cmd = {
3268 "ipv6 next-hop local",
3269 route_set_ipv6_nexthop_local,
3270 route_set_ipv6_nexthop_local_compile,
3271 route_set_ipv6_nexthop_local_free
3272 };
3273
3274 /* `set ipv6 nexthop peer-address' */
3275
3276 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3277 static enum route_map_cmd_result_t
3278 route_set_ipv6_nexthop_peer(void *rule, const struct prefix *pfx, void *object)
3279 {
3280 struct in6_addr peer_address;
3281 struct bgp_path_info *path;
3282 struct peer *peer;
3283
3284 /* Fetch routemap's rule information. */
3285 path = object;
3286 peer = path->peer;
3287
3288 if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
3289 || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
3290 && peer->su_remote
3291 && sockunion_family(peer->su_remote) == AF_INET6) {
3292 peer_address = peer->su_remote->sin6.sin6_addr;
3293 /* Set next hop value and length in attribute. */
3294 if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) {
3295 path->attr->mp_nexthop_local = peer_address;
3296 if (path->attr->mp_nexthop_len
3297 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
3298 path->attr->mp_nexthop_len =
3299 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
3300 } else {
3301 path->attr->mp_nexthop_global = peer_address;
3302 if (path->attr->mp_nexthop_len == 0)
3303 path->attr->mp_nexthop_len =
3304 BGP_ATTR_NHLEN_IPV6_GLOBAL;
3305 }
3306
3307 } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) {
3308 /* The next hop value will be set as part of packet
3309 * rewrite.
3310 * Set the flags here to indicate that rewrite needs to
3311 * be done.
3312 * Also, clear the value - we clear both global and
3313 * link-local
3314 * nexthops, whether we send one or both is determined
3315 * elsewhere.
3316 */
3317 SET_FLAG(path->attr->rmap_change_flags,
3318 BATTR_RMAP_NEXTHOP_PEER_ADDRESS);
3319 /* clear next hop value. */
3320 memset(&(path->attr->mp_nexthop_global), 0,
3321 sizeof(struct in6_addr));
3322 memset(&(path->attr->mp_nexthop_local), 0,
3323 sizeof(struct in6_addr));
3324 }
3325
3326 return RMAP_OKAY;
3327 }
3328
3329 /* Route map `ip next-hop' compile function. Given string is converted
3330 to struct in_addr structure. */
3331 static void *route_set_ipv6_nexthop_peer_compile(const char *arg)
3332 {
3333 int *rins = NULL;
3334
3335 rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int));
3336 *rins = 1;
3337
3338 return rins;
3339 }
3340
3341 /* Free route map's compiled `ip next-hop' value. */
3342 static void route_set_ipv6_nexthop_peer_free(void *rule)
3343 {
3344 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3345 }
3346
3347 /* Route map commands for ip nexthop set. */
3348 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = {
3349 "ipv6 next-hop peer-address",
3350 route_set_ipv6_nexthop_peer,
3351 route_set_ipv6_nexthop_peer_compile,
3352 route_set_ipv6_nexthop_peer_free
3353 };
3354
3355 /* `set ipv4 vpn next-hop A.B.C.D' */
3356
3357 static enum route_map_cmd_result_t
3358 route_set_vpnv4_nexthop(void *rule, const struct prefix *prefix, void *object)
3359 {
3360 struct in_addr *address;
3361 struct bgp_path_info *path;
3362
3363 /* Fetch routemap's rule information. */
3364 address = rule;
3365 path = object;
3366
3367 /* Set next hop value. */
3368 path->attr->mp_nexthop_global_in = *address;
3369 path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
3370
3371 return RMAP_OKAY;
3372 }
3373
3374 static void *route_set_vpnv4_nexthop_compile(const char *arg)
3375 {
3376 int ret;
3377 struct in_addr *address;
3378
3379 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr));
3380
3381 ret = inet_aton(arg, address);
3382
3383 if (ret == 0) {
3384 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3385 return NULL;
3386 }
3387
3388 return address;
3389 }
3390
3391 /* `set ipv6 vpn next-hop A.B.C.D' */
3392
3393 static enum route_map_cmd_result_t
3394 route_set_vpnv6_nexthop(void *rule, const struct prefix *prefix, void *object)
3395 {
3396 struct in6_addr *address;
3397 struct bgp_path_info *path;
3398
3399 /* Fetch routemap's rule information. */
3400 address = rule;
3401 path = object;
3402
3403 /* Set next hop value. */
3404 memcpy(&path->attr->mp_nexthop_global, address,
3405 sizeof(struct in6_addr));
3406 path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL;
3407
3408 return RMAP_OKAY;
3409 }
3410
3411 static void *route_set_vpnv6_nexthop_compile(const char *arg)
3412 {
3413 int ret;
3414 struct in6_addr *address;
3415
3416 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr));
3417 ret = inet_pton(AF_INET6, arg, address);
3418
3419 if (ret == 0) {
3420 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3421 return NULL;
3422 }
3423
3424 return address;
3425 }
3426
3427 static void route_set_vpn_nexthop_free(void *rule)
3428 {
3429 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3430 }
3431
3432 /* Route map commands for ipv4 next-hop set. */
3433 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = {
3434 "ipv4 vpn next-hop",
3435 route_set_vpnv4_nexthop,
3436 route_set_vpnv4_nexthop_compile,
3437 route_set_vpn_nexthop_free
3438 };
3439
3440 /* Route map commands for ipv6 next-hop set. */
3441 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = {
3442 "ipv6 vpn next-hop",
3443 route_set_vpnv6_nexthop,
3444 route_set_vpnv6_nexthop_compile,
3445 route_set_vpn_nexthop_free
3446 };
3447
3448 /* `set originator-id' */
3449
3450 /* For origin set. */
3451 static enum route_map_cmd_result_t
3452 route_set_originator_id(void *rule, const struct prefix *prefix, void *object)
3453 {
3454 struct in_addr *address;
3455 struct bgp_path_info *path;
3456
3457 address = rule;
3458 path = object;
3459
3460 path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID);
3461 path->attr->originator_id = *address;
3462
3463 return RMAP_OKAY;
3464 }
3465
3466 /* Compile function for originator-id set. */
3467 static void *route_set_originator_id_compile(const char *arg)
3468 {
3469 int ret;
3470 struct in_addr *address;
3471
3472 address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr));
3473
3474 ret = inet_aton(arg, address);
3475
3476 if (ret == 0) {
3477 XFREE(MTYPE_ROUTE_MAP_COMPILED, address);
3478 return NULL;
3479 }
3480
3481 return address;
3482 }
3483
3484 /* Compile function for originator_id set. */
3485 static void route_set_originator_id_free(void *rule)
3486 {
3487 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
3488 }
3489
3490 /* Set originator-id rule structure. */
3491 static const struct route_map_rule_cmd route_set_originator_id_cmd = {
3492 "originator-id",
3493 route_set_originator_id,
3494 route_set_originator_id_compile,
3495 route_set_originator_id_free,
3496 };
3497
3498 /*
3499 * This is the workhorse routine for processing in/out routemap
3500 * modifications.
3501 */
3502 static void bgp_route_map_process_peer(const char *rmap_name,
3503 struct route_map *map, struct peer *peer,
3504 int afi, int safi, int route_update)
3505 {
3506 struct bgp_filter *filter;
3507
3508 if (!peer || !rmap_name)
3509 return;
3510
3511 filter = &peer->filter[afi][safi];
3512 /*
3513 * in is for non-route-server clients,
3514 * out is for all peers
3515 */
3516 if (filter->map[RMAP_IN].name
3517 && (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) {
3518 filter->map[RMAP_IN].map = map;
3519
3520 if (route_update && peer_established(peer)) {
3521 if (CHECK_FLAG(peer->af_flags[afi][safi],
3522 PEER_FLAG_SOFT_RECONFIG)) {
3523 if (bgp_debug_update(peer, NULL, NULL, 1))
3524 zlog_debug(
3525 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3526 rmap_name, afi2str(afi),
3527 safi2str(safi), peer->host);
3528
3529 bgp_soft_reconfig_in(peer, afi, safi);
3530 } else if (CHECK_FLAG(peer->cap,
3531 PEER_CAP_REFRESH_OLD_RCV)
3532 || CHECK_FLAG(peer->cap,
3533 PEER_CAP_REFRESH_NEW_RCV)) {
3534 if (bgp_debug_update(peer, NULL, NULL, 1))
3535 zlog_debug(
3536 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3537 rmap_name, afi2str(afi),
3538 safi2str(safi), peer->host);
3539 bgp_route_refresh_send(
3540 peer, afi, safi, 0, 0, 0,
3541 BGP_ROUTE_REFRESH_NORMAL);
3542 }
3543 }
3544 }
3545
3546 /*
3547 * For outbound, unsuppress and default-originate map change (content or
3548 * map created), merely update the "config" here, the actual route
3549 * announcement happens at the group level.
3550 */
3551 if (filter->map[RMAP_OUT].name
3552 && (strcmp(rmap_name, filter->map[RMAP_OUT].name) == 0))
3553 filter->map[RMAP_OUT].map = map;
3554
3555 if (filter->usmap.name && (strcmp(rmap_name, filter->usmap.name) == 0))
3556 filter->usmap.map = map;
3557
3558 if (filter->advmap.aname
3559 && (strcmp(rmap_name, filter->advmap.aname) == 0)) {
3560 filter->advmap.amap = map;
3561 }
3562
3563 if (filter->advmap.cname
3564 && (strcmp(rmap_name, filter->advmap.cname) == 0)) {
3565 filter->advmap.cmap = map;
3566 }
3567
3568 if (peer->default_rmap[afi][safi].name
3569 && (strcmp(rmap_name, peer->default_rmap[afi][safi].name) == 0))
3570 peer->default_rmap[afi][safi].map = map;
3571
3572 /* Notify BGP conditional advertisement scanner percess */
3573 peer->advmap_config_change[afi][safi] = true;
3574 }
3575
3576 static void bgp_route_map_update_peer_group(const char *rmap_name,
3577 struct route_map *map,
3578 struct bgp *bgp)
3579 {
3580 struct peer_group *group;
3581 struct listnode *node, *nnode;
3582 struct bgp_filter *filter;
3583 int afi, safi;
3584 int direct;
3585
3586 if (!bgp)
3587 return;
3588
3589 /* All the peers have been updated correctly already. This is
3590 * just updating the placeholder data. No real update required.
3591 */
3592 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3593 FOREACH_AFI_SAFI (afi, safi) {
3594 filter = &group->conf->filter[afi][safi];
3595
3596 for (direct = RMAP_IN; direct < RMAP_MAX; direct++) {
3597 if ((filter->map[direct].name)
3598 && (strcmp(rmap_name,
3599 filter->map[direct].name)
3600 == 0))
3601 filter->map[direct].map = map;
3602 }
3603
3604 if (filter->usmap.name
3605 && (strcmp(rmap_name, filter->usmap.name) == 0))
3606 filter->usmap.map = map;
3607 }
3608 }
3609 }
3610
3611 /*
3612 * Note that if an extreme number (tens of thousands) of route-maps are in use
3613 * and if bgp has an extreme number of peers, network statements, etc then this
3614 * function can consume a lot of cycles. This is due to this function being
3615 * called for each route-map and within this function we walk the list of peers,
3616 * network statements, etc looking to see if they use this route-map.
3617 */
3618 static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
3619 int route_update)
3620 {
3621 int i;
3622 bool matched;
3623 afi_t afi;
3624 safi_t safi;
3625 struct peer *peer;
3626 struct bgp_dest *bn;
3627 struct bgp_static *bgp_static;
3628 struct bgp_aggregate *aggregate;
3629 struct listnode *node, *nnode;
3630 struct route_map *map;
3631 char buf[INET6_ADDRSTRLEN];
3632
3633 map = route_map_lookup_by_name(rmap_name);
3634
3635 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3636
3637 /* Ignore dummy peer-group structure */
3638 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP))
3639 continue;
3640
3641 FOREACH_AFI_SAFI (afi, safi) {
3642 /* process in/out/import/export/default-orig
3643 * route-maps */
3644 bgp_route_map_process_peer(rmap_name, map, peer, afi,
3645 safi, route_update);
3646 }
3647 }
3648
3649 /* for outbound/default-orig route-maps, process for groups */
3650 update_group_policy_update(bgp, BGP_POLICY_ROUTE_MAP, rmap_name,
3651 route_update, 0);
3652
3653 /* update peer-group config (template) */
3654 bgp_route_map_update_peer_group(rmap_name, map, bgp);
3655
3656 FOREACH_AFI_SAFI (afi, safi) {
3657 /* For table route-map updates. */
3658 if (!bgp_fibupd_safi(safi))
3659 continue;
3660
3661 if (bgp->table_map[afi][safi].name
3662 && (strcmp(rmap_name, bgp->table_map[afi][safi].name)
3663 == 0)) {
3664
3665 /* bgp->table_map[afi][safi].map is NULL.
3666 * i.e Route map creation event.
3667 * So update applied_counter.
3668 * If it is not NULL, i.e It may be routemap updation or
3669 * deletion. so no need to update the counter.
3670 */
3671 if (!bgp->table_map[afi][safi].map)
3672 route_map_counter_increment(map);
3673 bgp->table_map[afi][safi].map = map;
3674
3675 if (BGP_DEBUG(zebra, ZEBRA))
3676 zlog_debug(
3677 "Processing route_map %s(%s:%s) update on table map",
3678 rmap_name, afi2str(afi),
3679 safi2str(safi));
3680 if (route_update)
3681 bgp_zebra_announce_table(bgp, afi, safi);
3682 }
3683
3684 /* For network route-map updates. */
3685 for (bn = bgp_table_top(bgp->route[afi][safi]); bn;
3686 bn = bgp_route_next(bn)) {
3687 bgp_static = bgp_dest_get_bgp_static_info(bn);
3688 if (!bgp_static)
3689 continue;
3690
3691 if (!bgp_static->rmap.name
3692 || (strcmp(rmap_name, bgp_static->rmap.name) != 0))
3693 continue;
3694
3695 if (!bgp_static->rmap.map)
3696 route_map_counter_increment(map);
3697
3698 bgp_static->rmap.map = map;
3699
3700 if (route_update && !bgp_static->backdoor) {
3701 const struct prefix *bn_p =
3702 bgp_dest_get_prefix(bn);
3703
3704 if (bgp_debug_zebra(bn_p))
3705 zlog_debug(
3706 "Processing route_map %s(%s:%s) update on static route %s",
3707 rmap_name, afi2str(afi),
3708 safi2str(safi),
3709 inet_ntop(bn_p->family,
3710 &bn_p->u.prefix, buf,
3711 INET6_ADDRSTRLEN));
3712 bgp_static_update(bgp, bn_p, bgp_static, afi,
3713 safi);
3714 }
3715 }
3716
3717 /* For aggregate-address route-map updates. */
3718 for (bn = bgp_table_top(bgp->aggregate[afi][safi]); bn;
3719 bn = bgp_route_next(bn)) {
3720 aggregate = bgp_dest_get_bgp_aggregate_info(bn);
3721 if (!aggregate)
3722 continue;
3723
3724 matched = false;
3725
3726 /* Update suppress map pointer. */
3727 if (aggregate->suppress_map_name
3728 && strmatch(aggregate->suppress_map_name,
3729 rmap_name)) {
3730 if (aggregate->rmap.map == NULL)
3731 route_map_counter_increment(map);
3732
3733 aggregate->suppress_map = map;
3734
3735 bgp_aggregate_toggle_suppressed(
3736 aggregate, bgp, bgp_dest_get_prefix(bn),
3737 afi, safi, false);
3738
3739 matched = true;
3740 }
3741
3742 if (aggregate->rmap.name
3743 && strmatch(rmap_name, aggregate->rmap.name)) {
3744 if (aggregate->rmap.map == NULL)
3745 route_map_counter_increment(map);
3746
3747 aggregate->rmap.map = map;
3748
3749 matched = true;
3750 }
3751
3752 if (matched && route_update) {
3753 const struct prefix *bn_p =
3754 bgp_dest_get_prefix(bn);
3755
3756 if (bgp_debug_zebra(bn_p))
3757 zlog_debug(
3758 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
3759 rmap_name, afi2str(afi),
3760 safi2str(safi),
3761 inet_ntop(bn_p->family,
3762 &bn_p->u.prefix, buf,
3763 INET6_ADDRSTRLEN));
3764 bgp_aggregate_route(bgp, bn_p, afi, safi,
3765 aggregate);
3766 }
3767 }
3768 }
3769
3770 /* For redistribute route-map updates. */
3771 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3772 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
3773 struct list *red_list;
3774 struct bgp_redist *red;
3775
3776 red_list = bgp->redist[afi][i];
3777 if (!red_list)
3778 continue;
3779
3780 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
3781 if (!red->rmap.name
3782 || (strcmp(rmap_name, red->rmap.name) != 0))
3783 continue;
3784
3785 if (!red->rmap.map)
3786 route_map_counter_increment(map);
3787
3788 red->rmap.map = map;
3789
3790 if (!route_update)
3791 continue;
3792
3793 if (BGP_DEBUG(zebra, ZEBRA))
3794 zlog_debug(
3795 "Processing route_map %s(%s:%s) update on redistributed routes",
3796 rmap_name, afi2str(afi),
3797 safi2str(safi));
3798
3799 bgp_redistribute_resend(bgp, afi, i,
3800 red->instance);
3801 }
3802 }
3803
3804 /* for type5 command route-maps */
3805 FOREACH_AFI_SAFI (afi, safi) {
3806 if (!bgp->adv_cmd_rmap[afi][safi].name
3807 || strcmp(rmap_name, bgp->adv_cmd_rmap[afi][safi].name)
3808 != 0)
3809 continue;
3810
3811 /* Make sure the route-map is populated here if not already done */
3812 bgp->adv_cmd_rmap[afi][safi].map = map;
3813
3814 if (BGP_DEBUG(zebra, ZEBRA))
3815 zlog_debug(
3816 "Processing route_map %s(%s:%s) update on advertise type5 route command",
3817 rmap_name, afi2str(afi), safi2str(safi));
3818
3819 if (route_update && advertise_type5_routes(bgp, afi)) {
3820 bgp_evpn_withdraw_type5_routes(bgp, afi, safi);
3821 bgp_evpn_advertise_type5_routes(bgp, afi, safi);
3822 }
3823 }
3824 }
3825
3826 static void bgp_route_map_process_update_cb(char *rmap_name)
3827 {
3828 struct listnode *node, *nnode;
3829 struct bgp *bgp;
3830
3831 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3832 bgp_route_map_process_update(bgp, rmap_name, 1);
3833
3834 #ifdef ENABLE_BGP_VNC
3835 vnc_routemap_update(bgp, __func__);
3836 #endif
3837 }
3838
3839 vpn_policy_routemap_event(rmap_name);
3840 }
3841
3842 int bgp_route_map_update_timer(struct thread *thread)
3843 {
3844 bm->t_rmap_update = NULL;
3845
3846 route_map_walk_update_list(bgp_route_map_process_update_cb);
3847
3848 return 0;
3849 }
3850
3851 static void bgp_route_map_mark_update(const char *rmap_name)
3852 {
3853 struct listnode *node, *nnode;
3854 struct bgp *bgp;
3855
3856 /* If new update is received before the current timer timed out,
3857 * turn it off and start a new timer.
3858 */
3859 THREAD_OFF(bm->t_rmap_update);
3860
3861 /* rmap_update_timer of 0 means don't do route updates */
3862 if (bm->rmap_update_timer) {
3863 thread_add_timer(bm->master, bgp_route_map_update_timer,
3864 NULL, bm->rmap_update_timer,
3865 &bm->t_rmap_update);
3866
3867 /* Signal the groups that a route-map update event has
3868 * started */
3869 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3870 update_group_policy_update(bgp,
3871 BGP_POLICY_ROUTE_MAP,
3872 rmap_name, 1, 1);
3873 } else {
3874 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3875 bgp_route_map_process_update(bgp, rmap_name, 0);
3876 #ifdef ENABLE_BGP_VNC
3877 vnc_routemap_update(bgp, __func__);
3878 #endif
3879 }
3880
3881 vpn_policy_routemap_event(rmap_name);
3882 }
3883 }
3884
3885 static void bgp_route_map_add(const char *rmap_name)
3886 {
3887 if (route_map_mark_updated(rmap_name) == 0)
3888 bgp_route_map_mark_update(rmap_name);
3889
3890 route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED);
3891 }
3892
3893 static void bgp_route_map_delete(const char *rmap_name)
3894 {
3895 if (route_map_mark_updated(rmap_name) == 0)
3896 bgp_route_map_mark_update(rmap_name);
3897
3898 route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED);
3899 }
3900
3901 static void bgp_route_map_event(const char *rmap_name)
3902 {
3903 if (route_map_mark_updated(rmap_name) == 0)
3904 bgp_route_map_mark_update(rmap_name);
3905
3906 route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED);
3907 }
3908
3909 DEFUN_YANG (match_mac_address,
3910 match_mac_address_cmd,
3911 "match mac address WORD",
3912 MATCH_STR
3913 "mac address\n"
3914 "Match address of route\n"
3915 "MAC Access-list name\n")
3916 {
3917 const char *xpath =
3918 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3919 char xpath_value[XPATH_MAXLEN];
3920
3921 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
3922 snprintf(xpath_value, sizeof(xpath_value),
3923 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath);
3924 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[3]->arg);
3925
3926 return nb_cli_apply_changes(vty, NULL);
3927 }
3928
3929 DEFUN_YANG (no_match_mac_address,
3930 no_match_mac_address_cmd,
3931 "no match mac address WORD",
3932 NO_STR
3933 MATCH_STR
3934 "mac\n"
3935 "Match address of route\n"
3936 "MAC acess-list name\n")
3937 {
3938 const char *xpath =
3939 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3940
3941 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
3942 return nb_cli_apply_changes(vty, NULL);
3943 }
3944
3945 /*
3946 * Helper to handle the case of the user passing in a number or type string
3947 */
3948 static const char *parse_evpn_rt_type(const char *num_rt_type)
3949 {
3950 switch (num_rt_type[0]) {
3951 case '1':
3952 return "ead";
3953 case '2':
3954 return "macip";
3955 case '3':
3956 return "multicast";
3957 case '4':
3958 return "es";
3959 case '5':
3960 return "prefix";
3961 default:
3962 break;
3963 }
3964
3965 /* Was already full type string */
3966 return num_rt_type;
3967 }
3968
3969 DEFUN_YANG (match_evpn_route_type,
3970 match_evpn_route_type_cmd,
3971 "match evpn route-type <macip|2|multicast|3|prefix|5>",
3972 MATCH_STR
3973 EVPN_HELP_STR
3974 EVPN_TYPE_HELP_STR
3975 EVPN_TYPE_2_HELP_STR
3976 EVPN_TYPE_2_HELP_STR
3977 EVPN_TYPE_3_HELP_STR
3978 EVPN_TYPE_3_HELP_STR
3979 EVPN_TYPE_5_HELP_STR
3980 EVPN_TYPE_5_HELP_STR)
3981 {
3982 const char *xpath =
3983 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
3984 char xpath_value[XPATH_MAXLEN];
3985
3986 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
3987 snprintf(xpath_value, sizeof(xpath_value),
3988 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
3989 xpath);
3990 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
3991 parse_evpn_rt_type(argv[3]->arg));
3992
3993 return nb_cli_apply_changes(vty, NULL);
3994 }
3995
3996 DEFUN_YANG (no_match_evpn_route_type,
3997 no_match_evpn_route_type_cmd,
3998 "no match evpn route-type <macip|2|multicast|3|prefix|5>",
3999 NO_STR
4000 MATCH_STR
4001 EVPN_HELP_STR
4002 EVPN_TYPE_HELP_STR
4003 EVPN_TYPE_2_HELP_STR
4004 EVPN_TYPE_2_HELP_STR
4005 EVPN_TYPE_3_HELP_STR
4006 EVPN_TYPE_3_HELP_STR
4007 EVPN_TYPE_5_HELP_STR
4008 EVPN_TYPE_5_HELP_STR)
4009 {
4010 const char *xpath =
4011 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4012
4013 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4014
4015 return nb_cli_apply_changes(vty, NULL);
4016 }
4017
4018
4019 DEFUN_YANG (match_evpn_vni,
4020 match_evpn_vni_cmd,
4021 "match evpn vni " CMD_VNI_RANGE,
4022 MATCH_STR
4023 EVPN_HELP_STR
4024 "Match VNI\n"
4025 "VNI ID\n")
4026 {
4027 const char *xpath =
4028 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4029 char xpath_value[XPATH_MAXLEN];
4030
4031 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4032 snprintf(xpath_value, sizeof(xpath_value),
4033 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath);
4034 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[3]->arg);
4035
4036 return nb_cli_apply_changes(vty, NULL);
4037 }
4038
4039 DEFUN_YANG (no_match_evpn_vni,
4040 no_match_evpn_vni_cmd,
4041 "no match evpn vni " CMD_VNI_RANGE,
4042 NO_STR
4043 MATCH_STR
4044 EVPN_HELP_STR
4045 "Match VNI\n"
4046 "VNI ID\n")
4047 {
4048 const char *xpath =
4049 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4050 char xpath_value[XPATH_MAXLEN];
4051
4052 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4053 snprintf(xpath_value, sizeof(xpath_value),
4054 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath);
4055 nb_cli_enqueue_change(vty, xpath_value, NB_OP_DESTROY, argv[3]->arg);
4056
4057 return nb_cli_apply_changes(vty, NULL);
4058 }
4059
4060 DEFUN_YANG (match_evpn_default_route,
4061 match_evpn_default_route_cmd,
4062 "match evpn default-route",
4063 MATCH_STR
4064 EVPN_HELP_STR
4065 "default EVPN type-5 route\n")
4066 {
4067 const char *xpath =
4068 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4069 char xpath_value[XPATH_MAXLEN];
4070
4071 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4072
4073 snprintf(xpath_value, sizeof(xpath_value),
4074 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4075 xpath);
4076 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, NULL);
4077
4078 return nb_cli_apply_changes(vty, NULL);
4079 }
4080
4081 DEFUN_YANG (no_match_evpn_default_route,
4082 no_match_evpn_default_route_cmd,
4083 "no match evpn default-route",
4084 NO_STR
4085 MATCH_STR
4086 EVPN_HELP_STR
4087 "default EVPN type-5 route\n")
4088 {
4089 const char *xpath =
4090 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4091
4092 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4093
4094 return nb_cli_apply_changes(vty, NULL);
4095 }
4096
4097 DEFUN_YANG (match_evpn_rd,
4098 match_evpn_rd_cmd,
4099 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4100 MATCH_STR
4101 EVPN_HELP_STR
4102 "Route Distinguisher\n"
4103 "ASN:XX or A.B.C.D:XX\n")
4104 {
4105 const char *xpath =
4106 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4107 char xpath_value[XPATH_MAXLEN];
4108
4109 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4110 snprintf(
4111 xpath_value, sizeof(xpath_value),
4112 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4113 xpath);
4114 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[3]->arg);
4115
4116 return nb_cli_apply_changes(vty, NULL);
4117 }
4118
4119 DEFUN_YANG (no_match_evpn_rd,
4120 no_match_evpn_rd_cmd,
4121 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4122 NO_STR
4123 MATCH_STR
4124 EVPN_HELP_STR
4125 "Route Distinguisher\n"
4126 "ASN:XX or A.B.C.D:XX\n")
4127 {
4128 const char *xpath =
4129 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4130
4131 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4132 return nb_cli_apply_changes(vty, NULL);
4133 }
4134
4135 DEFUN_YANG (set_evpn_gw_ip_ipv4,
4136 set_evpn_gw_ip_ipv4_cmd,
4137 "set evpn gateway-ip ipv4 A.B.C.D",
4138 SET_STR
4139 EVPN_HELP_STR
4140 "Set gateway IP for prefix advertisement route\n"
4141 "IPv4 address\n"
4142 "Gateway IP address in IPv4 format\n")
4143 {
4144 int ret;
4145 union sockunion su;
4146 const char *xpath =
4147 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4148 char xpath_value[XPATH_MAXLEN];
4149
4150 ret = str2sockunion(argv[4]->arg, &su);
4151 if (ret < 0) {
4152 vty_out(vty, "%% Malformed gateway IP\n");
4153 return CMD_WARNING_CONFIG_FAILED;
4154 }
4155
4156 if (su.sin.sin_addr.s_addr == 0
4157 || IPV4_CLASS_DE(ntohl(su.sin.sin_addr.s_addr))) {
4158 vty_out(vty,
4159 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4160 return CMD_WARNING_CONFIG_FAILED;
4161 }
4162
4163 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4164
4165 snprintf(xpath_value, sizeof(xpath_value),
4166 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4167 xpath);
4168
4169 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[4]->arg);
4170 return nb_cli_apply_changes(vty, NULL);
4171 }
4172
4173 DEFUN_YANG (no_set_evpn_gw_ip_ipv4,
4174 no_set_evpn_gw_ip_ipv4_cmd,
4175 "no set evpn gateway-ip ipv4 A.B.C.D",
4176 NO_STR
4177 SET_STR
4178 EVPN_HELP_STR
4179 "Set gateway IP for prefix advertisement route\n"
4180 "IPv4 address\n"
4181 "Gateway IP address in IPv4 format\n")
4182 {
4183 int ret;
4184 union sockunion su;
4185 const char *xpath =
4186 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4187
4188 ret = str2sockunion(argv[5]->arg, &su);
4189 if (ret < 0) {
4190 vty_out(vty, "%% Malformed gateway IP\n");
4191 return CMD_WARNING_CONFIG_FAILED;
4192 }
4193
4194 if (su.sin.sin_addr.s_addr == 0
4195 || IPV4_CLASS_DE(ntohl(su.sin.sin_addr.s_addr))) {
4196 vty_out(vty,
4197 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4198 return CMD_WARNING_CONFIG_FAILED;
4199 }
4200
4201 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4202
4203 return nb_cli_apply_changes(vty, NULL);
4204 }
4205
4206 DEFUN_YANG (set_evpn_gw_ip_ipv6,
4207 set_evpn_gw_ip_ipv6_cmd,
4208 "set evpn gateway-ip ipv6 X:X::X:X",
4209 SET_STR
4210 EVPN_HELP_STR
4211 "Set gateway IP for prefix advertisement route\n"
4212 "IPv6 address\n"
4213 "Gateway IP address in IPv6 format\n")
4214 {
4215 int ret;
4216 union sockunion su;
4217 const char *xpath =
4218 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4219 char xpath_value[XPATH_MAXLEN];
4220
4221 ret = str2sockunion(argv[4]->arg, &su);
4222 if (ret < 0) {
4223 vty_out(vty, "%% Malformed gateway IP\n");
4224 return CMD_WARNING_CONFIG_FAILED;
4225 }
4226
4227 if (IN6_IS_ADDR_LINKLOCAL(&su.sin6.sin6_addr)
4228 || IN6_IS_ADDR_MULTICAST(&su.sin6.sin6_addr)) {
4229 vty_out(vty,
4230 "%% Gateway IP cannot be a linklocal or multicast address\n");
4231 return CMD_WARNING_CONFIG_FAILED;
4232 }
4233
4234 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4235
4236 snprintf(xpath_value, sizeof(xpath_value),
4237 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4238 xpath);
4239
4240 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[4]->arg);
4241 return nb_cli_apply_changes(vty, NULL);
4242 }
4243
4244 DEFUN_YANG (no_set_evpn_gw_ip_ipv6,
4245 no_set_evpn_gw_ip_ipv6_cmd,
4246 "no set evpn gateway-ip ipv6 X:X::X:X",
4247 NO_STR
4248 SET_STR
4249 EVPN_HELP_STR
4250 "Set gateway IP for prefix advertisement route\n"
4251 "IPv4 address\n"
4252 "Gateway IP address in IPv4 format\n")
4253 {
4254 int ret;
4255 union sockunion su;
4256 const char *xpath =
4257 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4258
4259 ret = str2sockunion(argv[5]->arg, &su);
4260 if (ret < 0) {
4261 vty_out(vty, "%% Malformed gateway IP\n");
4262 return CMD_WARNING_CONFIG_FAILED;
4263 }
4264
4265 if (IN6_IS_ADDR_LINKLOCAL(&su.sin6.sin6_addr)
4266 || IN6_IS_ADDR_MULTICAST(&su.sin6.sin6_addr)) {
4267 vty_out(vty,
4268 "%% Gateway IP cannot be a linklocal or multicast address\n");
4269 return CMD_WARNING_CONFIG_FAILED;
4270 }
4271
4272 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4273
4274 return nb_cli_apply_changes(vty, NULL);
4275 }
4276
4277 DEFPY_YANG(match_vrl_source_vrf,
4278 match_vrl_source_vrf_cmd,
4279 "match source-vrf NAME$vrf_name",
4280 MATCH_STR
4281 "source vrf\n"
4282 "The VRF name\n")
4283 {
4284 const char *xpath =
4285 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4286 char xpath_value[XPATH_MAXLEN];
4287
4288 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4289 snprintf(xpath_value, sizeof(xpath_value),
4290 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath);
4291 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, vrf_name);
4292
4293 return nb_cli_apply_changes(vty, NULL);
4294 }
4295
4296 DEFPY_YANG(no_match_vrl_source_vrf,
4297 no_match_vrl_source_vrf_cmd,
4298 "no match source-vrf NAME$vrf_name",
4299 NO_STR MATCH_STR
4300 "source vrf\n"
4301 "The VRF name\n")
4302 {
4303 const char *xpath =
4304 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4305
4306 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4307 return nb_cli_apply_changes(vty, NULL);
4308 }
4309
4310 DEFPY_YANG (match_peer,
4311 match_peer_cmd,
4312 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4313 MATCH_STR
4314 "Match peer address\n"
4315 "IP address of peer\n"
4316 "IPv6 address of peer\n"
4317 "Interface name of peer\n")
4318 {
4319 const char *xpath =
4320 "./match-condition[condition='frr-bgp-route-map:peer']";
4321 char xpath_value[XPATH_MAXLEN];
4322
4323 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4324
4325 if (addrv4_str) {
4326 snprintf(
4327 xpath_value, sizeof(xpath_value),
4328 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4329 xpath);
4330 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4331 addrv4_str);
4332 } else if (addrv6_str) {
4333 snprintf(
4334 xpath_value, sizeof(xpath_value),
4335 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4336 xpath);
4337 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4338 addrv6_str);
4339 } else {
4340 snprintf(
4341 xpath_value, sizeof(xpath_value),
4342 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4343 xpath);
4344 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, intf);
4345 }
4346
4347 return nb_cli_apply_changes(vty, NULL);
4348 }
4349
4350 DEFUN_YANG (match_peer_local,
4351 match_peer_local_cmd,
4352 "match peer local",
4353 MATCH_STR
4354 "Match peer address\n"
4355 "Static or Redistributed routes\n")
4356 {
4357 const char *xpath =
4358 "./match-condition[condition='frr-bgp-route-map:peer']";
4359 char xpath_value[XPATH_MAXLEN];
4360
4361 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4362
4363 snprintf(xpath_value, sizeof(xpath_value),
4364 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath);
4365 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, "true");
4366
4367 return nb_cli_apply_changes(vty, NULL);
4368 }
4369
4370 DEFUN_YANG (no_match_peer,
4371 no_match_peer_cmd,
4372 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4373 NO_STR
4374 MATCH_STR
4375 "Match peer address\n"
4376 "Static or Redistributed routes\n"
4377 "IP address of peer\n"
4378 "IPv6 address of peer\n"
4379 "Interface name of peer\n")
4380 {
4381 const char *xpath =
4382 "./match-condition[condition='frr-bgp-route-map:peer']";
4383
4384 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4385
4386 return nb_cli_apply_changes(vty, NULL);
4387 }
4388
4389 #ifdef HAVE_SCRIPTING
4390 DEFUN_YANG (match_script,
4391 match_script_cmd,
4392 "[no] match script WORD",
4393 NO_STR
4394 MATCH_STR
4395 "Execute script to determine match\n"
4396 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4397 {
4398 bool no = strmatch(argv[0]->text, "no");
4399 int i = 0;
4400 argv_find(argv, argc, "WORD", &i);
4401 const char *script = argv[i]->arg;
4402 const char *xpath =
4403 "./match-condition[condition='frr-bgp-route-map:match-script']";
4404 char xpath_value[XPATH_MAXLEN];
4405
4406 if (no) {
4407 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4408 snprintf(xpath_value, sizeof(xpath_value),
4409 "%s/rmap-match-condition/frr-bgp-route-map:script",
4410 xpath);
4411 nb_cli_enqueue_change(vty, xpath_value, NB_OP_DESTROY,
4412 script);
4413
4414 return nb_cli_apply_changes(vty, NULL);
4415 }
4416
4417 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4418 snprintf(xpath_value, sizeof(xpath_value),
4419 "%s/rmap-match-condition/frr-bgp-route-map:script",
4420 xpath);
4421 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4422 script);
4423
4424 return nb_cli_apply_changes(vty, NULL);
4425 }
4426 #endif /* HAVE_SCRIPTING */
4427
4428 /* match probability */
4429 DEFUN_YANG (match_probability,
4430 match_probability_cmd,
4431 "match probability (0-100)",
4432 MATCH_STR
4433 "Match portion of routes defined by percentage value\n"
4434 "Percentage of routes\n")
4435 {
4436 int idx_number = 2;
4437
4438 const char *xpath =
4439 "./match-condition[condition='frr-bgp-route-map:probability']";
4440 char xpath_value[XPATH_MAXLEN];
4441
4442 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4443 snprintf(xpath_value, sizeof(xpath_value),
4444 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4445 xpath);
4446 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4447 argv[idx_number]->arg);
4448
4449 return nb_cli_apply_changes(vty, NULL);
4450 }
4451
4452
4453 DEFUN_YANG (no_match_probability,
4454 no_match_probability_cmd,
4455 "no match probability [(1-99)]",
4456 NO_STR
4457 MATCH_STR
4458 "Match portion of routes defined by percentage value\n"
4459 "Percentage of routes\n")
4460 {
4461 int idx_number = 3;
4462 const char *xpath =
4463 "./match-condition[condition='frr-bgp-route-map:probability']";
4464 char xpath_value[XPATH_MAXLEN];
4465
4466 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4467
4468 if (argc <= idx_number)
4469 return nb_cli_apply_changes(vty, NULL);
4470
4471 snprintf(xpath_value, sizeof(xpath_value),
4472 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4473 xpath);
4474 nb_cli_enqueue_change(vty, xpath_value, NB_OP_DESTROY,
4475 argv[idx_number]->arg);
4476
4477 return nb_cli_apply_changes(vty, NULL);
4478 }
4479
4480
4481 DEFPY_YANG (match_ip_route_source,
4482 match_ip_route_source_cmd,
4483 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4484 MATCH_STR
4485 IP_STR
4486 "Match advertising source address of route\n"
4487 "IP access-list number\n"
4488 "IP access-list number (expanded range)\n"
4489 "IP standard access-list name\n")
4490 {
4491 const char *xpath =
4492 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4493 char xpath_value[XPATH_MAXLEN + 32];
4494 int idx_acl = 3;
4495
4496 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4497 snprintf(xpath_value, sizeof(xpath_value),
4498 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4499 xpath);
4500 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4501 argv[idx_acl]->arg);
4502
4503 return nb_cli_apply_changes(vty, NULL);
4504 }
4505
4506
4507 DEFUN_YANG (no_match_ip_route_source,
4508 no_match_ip_route_source_cmd,
4509 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4510 NO_STR
4511 MATCH_STR
4512 IP_STR
4513 "Match advertising source address of route\n"
4514 "IP access-list number\n"
4515 "IP access-list number (expanded range)\n"
4516 "IP standard access-list name\n")
4517 {
4518 const char *xpath =
4519 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4520
4521 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4522 return nb_cli_apply_changes(vty, NULL);
4523 }
4524
4525 DEFUN_YANG (match_ip_route_source_prefix_list,
4526 match_ip_route_source_prefix_list_cmd,
4527 "match ip route-source prefix-list WORD",
4528 MATCH_STR
4529 IP_STR
4530 "Match advertising source address of route\n"
4531 "Match entries of prefix-lists\n"
4532 "IP prefix-list name\n")
4533 {
4534 int idx_word = 4;
4535 const char *xpath =
4536 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4537 char xpath_value[XPATH_MAXLEN + 32];
4538
4539 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4540 snprintf(xpath_value, sizeof(xpath_value),
4541 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath);
4542 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4543 argv[idx_word]->arg);
4544
4545 return nb_cli_apply_changes(vty, NULL);
4546 }
4547
4548
4549 DEFUN_YANG (no_match_ip_route_source_prefix_list,
4550 no_match_ip_route_source_prefix_list_cmd,
4551 "no match ip route-source prefix-list [WORD]",
4552 NO_STR
4553 MATCH_STR
4554 IP_STR
4555 "Match advertising source address of route\n"
4556 "Match entries of prefix-lists\n"
4557 "IP prefix-list name\n")
4558 {
4559 const char *xpath =
4560 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4561
4562 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4563 return nb_cli_apply_changes(vty, NULL);
4564 }
4565
4566 DEFUN_YANG (match_local_pref,
4567 match_local_pref_cmd,
4568 "match local-preference (0-4294967295)",
4569 MATCH_STR
4570 "Match local-preference of route\n"
4571 "Metric value\n")
4572 {
4573 int idx_number = 2;
4574
4575 const char *xpath =
4576 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4577 char xpath_value[XPATH_MAXLEN];
4578
4579 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4580 snprintf(xpath_value, sizeof(xpath_value),
4581 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4582 xpath);
4583 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4584 argv[idx_number]->arg);
4585
4586 return nb_cli_apply_changes(vty, NULL);
4587 }
4588
4589
4590 DEFUN_YANG (no_match_local_pref,
4591 no_match_local_pref_cmd,
4592 "no match local-preference [(0-4294967295)]",
4593 NO_STR
4594 MATCH_STR
4595 "Match local preference of route\n"
4596 "Local preference value\n")
4597 {
4598 int idx_localpref = 3;
4599 const char *xpath =
4600 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4601 char xpath_value[XPATH_MAXLEN];
4602
4603 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4604
4605 if (argc <= idx_localpref)
4606 return nb_cli_apply_changes(vty, NULL);
4607
4608 snprintf(xpath_value, sizeof(xpath_value),
4609 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4610 xpath);
4611 nb_cli_enqueue_change(vty, xpath_value, NB_OP_DESTROY,
4612 argv[idx_localpref]->arg);
4613
4614 return nb_cli_apply_changes(vty, NULL);
4615 }
4616
4617
4618 DEFPY_YANG (match_community,
4619 match_community_cmd,
4620 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4621 MATCH_STR
4622 "Match BGP community list\n"
4623 "Community-list number (standard)\n"
4624 "Community-list number (expanded)\n"
4625 "Community-list name\n"
4626 "Do exact matching of communities\n")
4627 {
4628 const char *xpath =
4629 "./match-condition[condition='frr-bgp-route-map:match-community']";
4630 char xpath_value[XPATH_MAXLEN];
4631 char xpath_match[XPATH_MAXLEN];
4632 int idx_comm_list = 2;
4633
4634 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4635
4636 snprintf(
4637 xpath_value, sizeof(xpath_value),
4638 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4639 xpath);
4640 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_comm_list]->arg);
4641
4642 if (argc == 4) {
4643 snprintf(
4644 xpath_match, sizeof(xpath_match),
4645 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4646 xpath);
4647 nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY,
4648 "true");
4649 } else {
4650 snprintf(
4651 xpath_match, sizeof(xpath_match),
4652 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4653 xpath);
4654 nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY,
4655 "false");
4656 }
4657
4658 return nb_cli_apply_changes(vty, NULL);
4659 }
4660
4661 DEFUN_YANG (no_match_community,
4662 no_match_community_cmd,
4663 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4664 NO_STR
4665 MATCH_STR
4666 "Match BGP community list\n"
4667 "Community-list number (standard)\n"
4668 "Community-list number (expanded)\n"
4669 "Community-list name\n"
4670 "Do exact matching of communities\n")
4671 {
4672 const char *xpath =
4673 "./match-condition[condition='frr-bgp-route-map:match-community']";
4674
4675 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4676 return nb_cli_apply_changes(vty, NULL);
4677 }
4678
4679 DEFPY_YANG (match_lcommunity,
4680 match_lcommunity_cmd,
4681 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4682 MATCH_STR
4683 "Match BGP large community list\n"
4684 "Large Community-list number (standard)\n"
4685 "Large Community-list number (expanded)\n"
4686 "Large Community-list name\n"
4687 "Do exact matching of communities\n")
4688 {
4689 const char *xpath =
4690 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4691 char xpath_value[XPATH_MAXLEN];
4692 char xpath_match[XPATH_MAXLEN];
4693 int idx_lcomm_list = 2;
4694
4695 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4696
4697 snprintf(
4698 xpath_value, sizeof(xpath_value),
4699 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4700 xpath);
4701 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_lcomm_list]->arg);
4702
4703 if (argc == 4) {
4704 snprintf(
4705 xpath_match, sizeof(xpath_match),
4706 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4707 xpath);
4708 nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY,
4709 "true");
4710 } else {
4711 snprintf(
4712 xpath_match, sizeof(xpath_match),
4713 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4714 xpath);
4715 nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY,
4716 "false");
4717 }
4718
4719 return nb_cli_apply_changes(vty, NULL);
4720 }
4721
4722 DEFUN_YANG (no_match_lcommunity,
4723 no_match_lcommunity_cmd,
4724 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4725 NO_STR
4726 MATCH_STR
4727 "Match BGP large community list\n"
4728 "Large Community-list number (standard)\n"
4729 "Large Community-list number (expanded)\n"
4730 "Large Community-list name\n"
4731 "Do exact matching of communities\n")
4732 {
4733 const char *xpath =
4734 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4735
4736 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4737 return nb_cli_apply_changes(vty, NULL);
4738 }
4739
4740 DEFPY_YANG (match_ecommunity,
4741 match_ecommunity_cmd,
4742 "match extcommunity <(1-99)|(100-500)|WORD>",
4743 MATCH_STR
4744 "Match BGP/VPN extended community list\n"
4745 "Extended community-list number (standard)\n"
4746 "Extended community-list number (expanded)\n"
4747 "Extended community-list name\n")
4748 {
4749 const char *xpath =
4750 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4751 char xpath_value[XPATH_MAXLEN];
4752 int idx_comm_list = 2;
4753
4754 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4755
4756 snprintf(
4757 xpath_value, sizeof(xpath_value),
4758 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4759 xpath);
4760 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_comm_list]->arg);
4761
4762 return nb_cli_apply_changes(vty, NULL);
4763 }
4764
4765
4766 DEFUN_YANG (no_match_ecommunity,
4767 no_match_ecommunity_cmd,
4768 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4769 NO_STR
4770 MATCH_STR
4771 "Match BGP/VPN extended community list\n"
4772 "Extended community-list number (standard)\n"
4773 "Extended community-list number (expanded)\n"
4774 "Extended community-list name\n")
4775 {
4776 const char *xpath =
4777 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4778
4779 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4780 return nb_cli_apply_changes(vty, NULL);
4781 }
4782
4783
4784 DEFUN_YANG (match_aspath,
4785 match_aspath_cmd,
4786 "match as-path WORD",
4787 MATCH_STR
4788 "Match BGP AS path list\n"
4789 "AS path access-list name\n")
4790 {
4791 int idx_word = 2;
4792
4793 const char *xpath =
4794 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4795 char xpath_value[XPATH_MAXLEN];
4796
4797 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4798 snprintf(xpath_value, sizeof(xpath_value),
4799 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath);
4800 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4801 argv[idx_word]->arg);
4802
4803 return nb_cli_apply_changes(vty, NULL);
4804 }
4805
4806
4807 DEFUN_YANG (no_match_aspath,
4808 no_match_aspath_cmd,
4809 "no match as-path [WORD]",
4810 NO_STR
4811 MATCH_STR
4812 "Match BGP AS path list\n"
4813 "AS path access-list name\n")
4814 {
4815 const char *xpath =
4816 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4817
4818 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4819
4820 return nb_cli_apply_changes(vty, NULL);
4821 }
4822
4823 DEFUN_YANG (match_origin,
4824 match_origin_cmd,
4825 "match origin <egp|igp|incomplete>",
4826 MATCH_STR
4827 "BGP origin code\n"
4828 "remote EGP\n"
4829 "local IGP\n"
4830 "unknown heritage\n")
4831 {
4832 int idx_origin = 2;
4833 const char *origin_type;
4834 const char *xpath =
4835 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4836 char xpath_value[XPATH_MAXLEN];
4837
4838 if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0)
4839 origin_type = "igp";
4840 else if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0)
4841 origin_type = "egp";
4842 else if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0)
4843 origin_type = "incomplete";
4844 else {
4845 vty_out(vty, "%% Invalid match origin type\n");
4846 return CMD_WARNING_CONFIG_FAILED;
4847 }
4848
4849 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4850 snprintf(xpath_value, sizeof(xpath_value),
4851 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath);
4852 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, origin_type);
4853
4854 return nb_cli_apply_changes(vty, NULL);
4855 }
4856
4857
4858 DEFUN_YANG (no_match_origin,
4859 no_match_origin_cmd,
4860 "no match origin [<egp|igp|incomplete>]",
4861 NO_STR
4862 MATCH_STR
4863 "BGP origin code\n"
4864 "remote EGP\n"
4865 "local IGP\n"
4866 "unknown heritage\n")
4867 {
4868 const char *xpath =
4869 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4870 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4871 return nb_cli_apply_changes(vty, NULL);
4872 }
4873
4874 DEFUN_YANG (set_table_id,
4875 set_table_id_cmd,
4876 "set table (1-4294967295)",
4877 SET_STR
4878 "export route to non-main kernel table\n"
4879 "Kernel routing table id\n")
4880 {
4881 int idx_number = 2;
4882 const char *xpath = "./set-action[action='frr-bgp-route-map:table']";
4883 char xpath_value[XPATH_MAXLEN];
4884
4885 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4886 snprintf(xpath_value, sizeof(xpath_value),
4887 "%s/rmap-set-action/frr-bgp-route-map:table", xpath);
4888 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4889 argv[idx_number]->arg);
4890 return nb_cli_apply_changes(vty, NULL);
4891 }
4892
4893 DEFUN_YANG (no_set_table_id,
4894 no_set_table_id_cmd,
4895 "no set table",
4896 NO_STR
4897 SET_STR
4898 "export route to non-main kernel table\n")
4899 {
4900 const char *xpath = "./set-action[action='frr-bgp-route-map:table']";
4901 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4902 return nb_cli_apply_changes(vty, NULL);
4903 }
4904
4905 DEFUN_YANG (set_ip_nexthop_peer,
4906 set_ip_nexthop_peer_cmd,
4907 "[no] set ip next-hop peer-address",
4908 NO_STR
4909 SET_STR
4910 IP_STR
4911 "Next hop address\n"
4912 "Use peer address (for BGP only)\n")
4913 {
4914 char xpath_value[XPATH_MAXLEN];
4915 const char *xpath =
4916 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4917
4918 if (strmatch(argv[0]->text, "no"))
4919 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4920 else {
4921 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4922 snprintf(xpath_value, sizeof(xpath_value),
4923 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4924 xpath);
4925 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4926 "peer-address");
4927 }
4928 return nb_cli_apply_changes(vty, NULL);
4929 }
4930
4931 DEFUN_YANG (set_ip_nexthop_unchanged,
4932 set_ip_nexthop_unchanged_cmd,
4933 "[no] set ip next-hop unchanged",
4934 NO_STR
4935 SET_STR
4936 IP_STR
4937 "Next hop address\n"
4938 "Don't modify existing Next hop address\n")
4939 {
4940 char xpath_value[XPATH_MAXLEN];
4941 const char *xpath =
4942 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4943
4944 if (strmatch(argv[0]->text, "no"))
4945 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4946 else {
4947 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4948 snprintf(xpath_value, sizeof(xpath_value),
4949 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4950 xpath);
4951 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4952 "unchanged");
4953 }
4954 return nb_cli_apply_changes(vty, NULL);
4955 }
4956
4957 DEFUN_YANG (set_distance,
4958 set_distance_cmd,
4959 "set distance (0-255)",
4960 SET_STR
4961 "BGP Administrative Distance to use\n"
4962 "Distance value\n")
4963 {
4964 int idx_number = 2;
4965 const char *xpath = "./set-action[action='frr-bgp-route-map:distance']";
4966 char xpath_value[XPATH_MAXLEN];
4967
4968 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
4969 snprintf(xpath_value, sizeof(xpath_value),
4970 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath);
4971 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
4972 argv[idx_number]->arg);
4973 return nb_cli_apply_changes(vty, NULL);
4974 }
4975
4976 DEFUN_YANG (no_set_distance,
4977 no_set_distance_cmd,
4978 "no set distance [(0-255)]",
4979 NO_STR SET_STR
4980 "BGP Administrative Distance to use\n"
4981 "Distance value\n")
4982 {
4983 const char *xpath = "./set-action[action='frr-bgp-route-map:distance']";
4984
4985 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
4986 return nb_cli_apply_changes(vty, NULL);
4987 }
4988
4989 DEFUN_YANG (set_local_pref,
4990 set_local_pref_cmd,
4991 "set local-preference WORD",
4992 SET_STR
4993 "BGP local preference path attribute\n"
4994 "Preference value (0-4294967295)\n")
4995 {
4996 int idx_number = 2;
4997 const char *xpath =
4998 "./set-action[action='frr-bgp-route-map:set-local-preference']";
4999 char xpath_value[XPATH_MAXLEN];
5000
5001 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5002 snprintf(xpath_value, sizeof(xpath_value),
5003 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath);
5004 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5005 argv[idx_number]->arg);
5006 return nb_cli_apply_changes(vty, NULL);
5007 }
5008
5009 DEFUN_YANG (no_set_local_pref,
5010 no_set_local_pref_cmd,
5011 "no set local-preference [WORD]",
5012 NO_STR
5013 SET_STR
5014 "BGP local preference path attribute\n"
5015 "Preference value (0-4294967295)\n")
5016 {
5017 const char *xpath =
5018 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5019
5020 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5021 return nb_cli_apply_changes(vty, NULL);
5022 }
5023
5024 DEFUN_YANG (set_weight,
5025 set_weight_cmd,
5026 "set weight (0-4294967295)",
5027 SET_STR
5028 "BGP weight for routing table\n"
5029 "Weight value\n")
5030 {
5031 int idx_number = 2;
5032 const char *xpath = "./set-action[action='frr-bgp-route-map:weight']";
5033 char xpath_value[XPATH_MAXLEN];
5034
5035 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5036 snprintf(xpath_value, sizeof(xpath_value),
5037 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath);
5038 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5039 argv[idx_number]->arg);
5040 return nb_cli_apply_changes(vty, NULL);
5041 }
5042
5043 DEFUN_YANG (no_set_weight,
5044 no_set_weight_cmd,
5045 "no set weight [(0-4294967295)]",
5046 NO_STR
5047 SET_STR
5048 "BGP weight for routing table\n"
5049 "Weight value\n")
5050 {
5051 const char *xpath = "./set-action[action='frr-bgp-route-map:weight']";
5052
5053 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5054 return nb_cli_apply_changes(vty, NULL);
5055 }
5056
5057 DEFUN_YANG (set_label_index,
5058 set_label_index_cmd,
5059 "set label-index (0-1048560)",
5060 SET_STR
5061 "Label index to associate with the prefix\n"
5062 "Label index value\n")
5063 {
5064 int idx_number = 2;
5065 const char *xpath =
5066 "./set-action[action='frr-bgp-route-map:label-index']";
5067 char xpath_value[XPATH_MAXLEN];
5068
5069 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5070 snprintf(xpath_value, sizeof(xpath_value),
5071 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath);
5072 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5073 argv[idx_number]->arg);
5074 return nb_cli_apply_changes(vty, NULL);
5075 }
5076
5077 DEFUN_YANG (no_set_label_index,
5078 no_set_label_index_cmd,
5079 "no set label-index [(0-1048560)]",
5080 NO_STR
5081 SET_STR
5082 "Label index to associate with the prefix\n"
5083 "Label index value\n")
5084 {
5085 const char *xpath =
5086 "./set-action[action='frr-bgp-route-map:label-index']";
5087
5088 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5089 return nb_cli_apply_changes(vty, NULL);
5090 }
5091
5092 DEFUN_YANG (set_aspath_prepend_asn,
5093 set_aspath_prepend_asn_cmd,
5094 "set as-path prepend (1-4294967295)...",
5095 SET_STR
5096 "Transform BGP AS_PATH attribute\n"
5097 "Prepend to the as-path\n"
5098 "AS number\n")
5099 {
5100 int idx_asn = 3;
5101 int ret;
5102 char *str;
5103
5104 str = argv_concat(argv, argc, idx_asn);
5105
5106 const char *xpath =
5107 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5108 char xpath_value[XPATH_MAXLEN];
5109
5110 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5111 snprintf(xpath_value, sizeof(xpath_value),
5112 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath);
5113 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5114 ret = nb_cli_apply_changes(vty, NULL);
5115 XFREE(MTYPE_TMP, str);
5116 return ret;
5117 }
5118
5119 DEFUN_YANG (set_aspath_prepend_lastas,
5120 set_aspath_prepend_lastas_cmd,
5121 "set as-path prepend last-as (1-10)",
5122 SET_STR
5123 "Transform BGP AS_PATH attribute\n"
5124 "Prepend to the as-path\n"
5125 "Use the peer's AS-number\n"
5126 "Number of times to insert\n")
5127 {
5128 int idx_num = 4;
5129
5130 const char *xpath =
5131 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5132 char xpath_value[XPATH_MAXLEN];
5133
5134 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5135 snprintf(xpath_value, sizeof(xpath_value),
5136 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath);
5137 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5138 argv[idx_num]->arg);
5139 return nb_cli_apply_changes(vty, NULL);
5140 }
5141
5142 DEFUN_YANG (no_set_aspath_prepend,
5143 no_set_aspath_prepend_cmd,
5144 "no set as-path prepend [(1-4294967295)]",
5145 NO_STR
5146 SET_STR
5147 "Transform BGP AS_PATH attribute\n"
5148 "Prepend to the as-path\n"
5149 "AS number\n")
5150 {
5151 const char *xpath =
5152 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5153
5154 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5155 return nb_cli_apply_changes(vty, NULL);
5156 }
5157
5158 DEFUN_YANG (no_set_aspath_prepend_lastas,
5159 no_set_aspath_prepend_lastas_cmd,
5160 "no set as-path prepend last-as [(1-10)]",
5161 NO_STR
5162 SET_STR
5163 "Transform BGP AS_PATH attribute\n"
5164 "Prepend to the as-path\n"
5165 "Use the peers AS-number\n"
5166 "Number of times to insert\n")
5167 {
5168 const char *xpath =
5169 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5170
5171 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5172 return nb_cli_apply_changes(vty, NULL);
5173 }
5174
5175 DEFUN_YANG (set_aspath_exclude,
5176 set_aspath_exclude_cmd,
5177 "set as-path exclude (1-4294967295)...",
5178 SET_STR
5179 "Transform BGP AS-path attribute\n"
5180 "Exclude from the as-path\n"
5181 "AS number\n")
5182 {
5183 int idx_asn = 3;
5184 int ret;
5185 char *str;
5186
5187 str = argv_concat(argv, argc, idx_asn);
5188
5189 const char *xpath =
5190 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5191 char xpath_value[XPATH_MAXLEN];
5192
5193 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5194 snprintf(xpath_value, sizeof(xpath_value),
5195 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath);
5196 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5197 ret = nb_cli_apply_changes(vty, NULL);
5198 XFREE(MTYPE_TMP, str);
5199 return ret;
5200 }
5201
5202 DEFUN_YANG (no_set_aspath_exclude,
5203 no_set_aspath_exclude_cmd,
5204 "no set as-path exclude (1-4294967295)...",
5205 NO_STR
5206 SET_STR
5207 "Transform BGP AS_PATH attribute\n"
5208 "Exclude from the as-path\n"
5209 "AS number\n")
5210 {
5211 const char *xpath =
5212 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5213
5214 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5215 return nb_cli_apply_changes(vty, NULL);
5216 }
5217
5218 ALIAS_YANG (no_set_aspath_exclude, no_set_aspath_exclude_all_cmd,
5219 "no set as-path exclude",
5220 NO_STR SET_STR
5221 "Transform BGP AS_PATH attribute\n"
5222 "Exclude from the as-path\n")
5223
5224 DEFUN_YANG (set_community,
5225 set_community_cmd,
5226 "set community AA:NN...",
5227 SET_STR
5228 "BGP community attribute\n"
5229 COMMUNITY_VAL_STR)
5230 {
5231 int idx_aa_nn = 2;
5232 int i;
5233 int first = 0;
5234 int additive = 0;
5235 struct buffer *b;
5236 struct community *com = NULL;
5237 char *str;
5238 char *argstr = NULL;
5239 int ret;
5240
5241 const char *xpath =
5242 "./set-action[action='frr-bgp-route-map:set-community']";
5243 char xpath_value[XPATH_MAXLEN];
5244
5245 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5246 snprintf(xpath_value, sizeof(xpath_value),
5247 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5248 xpath);
5249
5250 b = buffer_new(1024);
5251
5252 for (i = idx_aa_nn; i < argc; i++) {
5253 if (strncmp(argv[i]->arg, "additive", strlen(argv[i]->arg))
5254 == 0) {
5255 additive = 1;
5256 continue;
5257 }
5258
5259 if (first)
5260 buffer_putc(b, ' ');
5261 else
5262 first = 1;
5263
5264 if (strncmp(argv[i]->arg, "internet", strlen(argv[i]->arg))
5265 == 0) {
5266 buffer_putstr(b, "internet");
5267 continue;
5268 }
5269 if (strncmp(argv[i]->arg, "local-AS", strlen(argv[i]->arg))
5270 == 0) {
5271 buffer_putstr(b, "local-AS");
5272 continue;
5273 }
5274 if (strncmp(argv[i]->arg, "no-a", strlen("no-a")) == 0
5275 && strncmp(argv[i]->arg, "no-advertise",
5276 strlen(argv[i]->arg))
5277 == 0) {
5278 buffer_putstr(b, "no-advertise");
5279 continue;
5280 }
5281 if (strncmp(argv[i]->arg, "no-e", strlen("no-e")) == 0
5282 && strncmp(argv[i]->arg, "no-export", strlen(argv[i]->arg))
5283 == 0) {
5284 buffer_putstr(b, "no-export");
5285 continue;
5286 }
5287 if (strncmp(argv[i]->arg, "blackhole", strlen(argv[i]->arg))
5288 == 0) {
5289 buffer_putstr(b, "blackhole");
5290 continue;
5291 }
5292 if (strncmp(argv[i]->arg, "graceful-shutdown",
5293 strlen(argv[i]->arg))
5294 == 0) {
5295 buffer_putstr(b, "graceful-shutdown");
5296 continue;
5297 }
5298 buffer_putstr(b, argv[i]->arg);
5299 }
5300 buffer_putc(b, '\0');
5301
5302 /* Fetch result string then compile it to communities attribute. */
5303 str = buffer_getstr(b);
5304 buffer_free(b);
5305
5306 if (str) {
5307 com = community_str2com(str);
5308 XFREE(MTYPE_TMP, str);
5309 }
5310
5311 /* Can't compile user input into communities attribute. */
5312 if (!com) {
5313 vty_out(vty, "%% Malformed communities attribute\n");
5314 return CMD_WARNING_CONFIG_FAILED;
5315 }
5316
5317 /* Set communites attribute string. */
5318 str = community_str(com, false);
5319
5320 if (additive) {
5321 size_t argstr_sz = strlen(str) + strlen(" additive") + 1;
5322 argstr = XCALLOC(MTYPE_TMP, argstr_sz);
5323 strlcpy(argstr, str, argstr_sz);
5324 strlcat(argstr, " additive", argstr_sz);
5325 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argstr);
5326 } else
5327 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5328
5329 ret = nb_cli_apply_changes(vty, NULL);
5330
5331 if (argstr)
5332 XFREE(MTYPE_TMP, argstr);
5333 community_free(&com);
5334
5335 return ret;
5336 }
5337
5338 DEFUN_YANG (set_community_none,
5339 set_community_none_cmd,
5340 "set community none",
5341 SET_STR
5342 "BGP community attribute\n"
5343 "No community attribute\n")
5344 {
5345 const char *xpath =
5346 "./set-action[action='frr-bgp-route-map:set-community']";
5347 char xpath_value[XPATH_MAXLEN];
5348
5349 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5350
5351 snprintf(xpath_value, sizeof(xpath_value),
5352 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath);
5353 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, "true");
5354 return nb_cli_apply_changes(vty, NULL);
5355 }
5356
5357 DEFUN_YANG (no_set_community,
5358 no_set_community_cmd,
5359 "no set community AA:NN...",
5360 NO_STR
5361 SET_STR
5362 "BGP community attribute\n"
5363 COMMUNITY_VAL_STR)
5364 {
5365 const char *xpath =
5366 "./set-action[action='frr-bgp-route-map:set-community']";
5367
5368 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5369 return nb_cli_apply_changes(vty, NULL);
5370 }
5371
5372 ALIAS_YANG (no_set_community,
5373 no_set_community_short_cmd,
5374 "no set community",
5375 NO_STR
5376 SET_STR
5377 "BGP community attribute\n")
5378
5379 DEFPY_YANG (set_community_delete,
5380 set_community_delete_cmd,
5381 "set comm-list <(1-99)|(100-500)|WORD> delete",
5382 SET_STR
5383 "set BGP community list (for deletion)\n"
5384 "Community-list number (standard)\n"
5385 "Community-list number (expanded)\n"
5386 "Community-list name\n"
5387 "Delete matching communities\n")
5388 {
5389 const char *xpath =
5390 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5391 char xpath_value[XPATH_MAXLEN];
5392 int idx_comm_list = 2;
5393
5394 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5395
5396 snprintf(xpath_value, sizeof(xpath_value),
5397 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5398 xpath);
5399 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5400 argv[idx_comm_list]->arg);
5401
5402 return nb_cli_apply_changes(vty, NULL);
5403
5404 }
5405
5406 DEFUN_YANG (no_set_community_delete,
5407 no_set_community_delete_cmd,
5408 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
5409 NO_STR
5410 SET_STR
5411 "set BGP community list (for deletion)\n"
5412 "Community-list number (standard)\n"
5413 "Community-list number (expanded)\n"
5414 "Community-list name\n"
5415 "Delete matching communities\n")
5416 {
5417 const char *xpath =
5418 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5419
5420 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5421 return nb_cli_apply_changes(vty, NULL);
5422 }
5423
5424 DEFUN_YANG (set_lcommunity,
5425 set_lcommunity_cmd,
5426 "set large-community AA:BB:CC...",
5427 SET_STR
5428 "BGP large community attribute\n"
5429 "Large Community number in aa:bb:cc format or additive\n")
5430 {
5431 char *str;
5432 int ret;
5433 const char *xpath =
5434 "./set-action[action='frr-bgp-route-map:set-large-community']";
5435 char xpath_value[XPATH_MAXLEN];
5436
5437 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5438
5439 snprintf(xpath_value, sizeof(xpath_value),
5440 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5441 xpath);
5442 str = argv_concat(argv, argc, 2);
5443 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5444 ret = nb_cli_apply_changes(vty, NULL);
5445 XFREE(MTYPE_TMP, str);
5446 return ret;
5447 }
5448
5449 DEFUN_YANG (set_lcommunity_none,
5450 set_lcommunity_none_cmd,
5451 "set large-community none",
5452 SET_STR
5453 "BGP large community attribute\n"
5454 "No large community attribute\n")
5455 {
5456 const char *xpath =
5457 "./set-action[action='frr-bgp-route-map:set-large-community']";
5458 char xpath_value[XPATH_MAXLEN];
5459
5460 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5461
5462 snprintf(xpath_value, sizeof(xpath_value),
5463 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
5464 xpath);
5465 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, "true");
5466 return nb_cli_apply_changes(vty, NULL);
5467 }
5468
5469 DEFUN_YANG (no_set_lcommunity,
5470 no_set_lcommunity_cmd,
5471 "no set large-community none",
5472 NO_STR
5473 SET_STR
5474 "BGP large community attribute\n"
5475 "No community attribute\n")
5476 {
5477 const char *xpath =
5478 "./set-action[action='frr-bgp-route-map:set-large-community']";
5479
5480 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5481 return nb_cli_apply_changes(vty, NULL);
5482 }
5483
5484 DEFUN_YANG (no_set_lcommunity1,
5485 no_set_lcommunity1_cmd,
5486 "no set large-community AA:BB:CC...",
5487 NO_STR
5488 SET_STR
5489 "BGP large community attribute\n"
5490 "Large community in AA:BB:CC... format or additive\n")
5491 {
5492 const char *xpath =
5493 "./set-action[action='frr-bgp-route-map:set-large-community']";
5494
5495 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5496 return nb_cli_apply_changes(vty, NULL);
5497 }
5498
5499 ALIAS_YANG (no_set_lcommunity1,
5500 no_set_lcommunity1_short_cmd,
5501 "no set large-community",
5502 NO_STR
5503 SET_STR
5504 "BGP large community attribute\n")
5505
5506 DEFPY_YANG (set_lcommunity_delete,
5507 set_lcommunity_delete_cmd,
5508 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
5509 SET_STR
5510 "set BGP large community list (for deletion)\n"
5511 "Large Community-list number (standard)\n"
5512 "Large Communitly-list number (expanded)\n"
5513 "Large Community-list name\n"
5514 "Delete matching large communities\n")
5515 {
5516 const char *xpath =
5517 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5518 char xpath_value[XPATH_MAXLEN];
5519 int idx_lcomm_list = 2;
5520
5521 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5522
5523 snprintf(xpath_value, sizeof(xpath_value),
5524 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5525 xpath);
5526 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
5527 argv[idx_lcomm_list]->arg);
5528
5529 return nb_cli_apply_changes(vty, NULL);
5530 }
5531
5532 DEFUN_YANG (no_set_lcommunity_delete,
5533 no_set_lcommunity_delete_cmd,
5534 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
5535 NO_STR
5536 SET_STR
5537 "set BGP large community list (for deletion)\n"
5538 "Large Community-list number (standard)\n"
5539 "Large Communitly-list number (expanded)\n"
5540 "Large Community-list name\n"
5541 "Delete matching large communities\n")
5542 {
5543 const char *xpath =
5544 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5545
5546 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5547 return nb_cli_apply_changes(vty, NULL);
5548 }
5549
5550 ALIAS_YANG (no_set_lcommunity_delete,
5551 no_set_lcommunity_delete_short_cmd,
5552 "no set large-comm-list",
5553 NO_STR
5554 SET_STR
5555 "set BGP large community list (for deletion)\n")
5556
5557 DEFUN_YANG (set_ecommunity_rt,
5558 set_ecommunity_rt_cmd,
5559 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5560 SET_STR
5561 "BGP extended community attribute\n"
5562 "Route Target extended community\n"
5563 "VPN extended community\n")
5564 {
5565 int idx_asn_nn = 3;
5566 char *str;
5567 int ret;
5568 const char *xpath =
5569 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5570 char xpath_value[XPATH_MAXLEN];
5571
5572 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5573
5574 snprintf(xpath_value, sizeof(xpath_value),
5575 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath);
5576 str = argv_concat(argv, argc, idx_asn_nn);
5577 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5578 ret = nb_cli_apply_changes(vty, NULL);
5579 XFREE(MTYPE_TMP, str);
5580 return ret;
5581 }
5582
5583 DEFUN_YANG (no_set_ecommunity_rt,
5584 no_set_ecommunity_rt_cmd,
5585 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5586 NO_STR
5587 SET_STR
5588 "BGP extended community attribute\n"
5589 "Route Target extended community\n"
5590 "VPN extended community\n")
5591 {
5592 const char *xpath =
5593 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5594 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5595 return nb_cli_apply_changes(vty, NULL);
5596 }
5597
5598 ALIAS_YANG (no_set_ecommunity_rt,
5599 no_set_ecommunity_rt_short_cmd,
5600 "no set extcommunity rt",
5601 NO_STR
5602 SET_STR
5603 "BGP extended community attribute\n"
5604 "Route Target extended community\n")
5605
5606 DEFUN_YANG (set_ecommunity_soo,
5607 set_ecommunity_soo_cmd,
5608 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5609 SET_STR
5610 "BGP extended community attribute\n"
5611 "Site-of-Origin extended community\n"
5612 "VPN extended community\n")
5613 {
5614 int idx_asn_nn = 3;
5615 char *str;
5616 int ret;
5617 const char *xpath =
5618 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5619 char xpath_value[XPATH_MAXLEN];
5620
5621 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5622
5623 snprintf(xpath_value, sizeof(xpath_value),
5624 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
5625 xpath);
5626 str = argv_concat(argv, argc, idx_asn_nn);
5627 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
5628 ret = nb_cli_apply_changes(vty, NULL);
5629 XFREE(MTYPE_TMP, str);
5630 return ret;
5631 }
5632
5633 DEFUN_YANG (no_set_ecommunity_soo,
5634 no_set_ecommunity_soo_cmd,
5635 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5636 NO_STR
5637 SET_STR
5638 "BGP extended community attribute\n"
5639 "Site-of-Origin extended community\n"
5640 "VPN extended community\n")
5641 {
5642 const char *xpath =
5643 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5644 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5645 return nb_cli_apply_changes(vty, NULL);
5646 }
5647
5648 ALIAS_YANG (no_set_ecommunity_soo,
5649 no_set_ecommunity_soo_short_cmd,
5650 "no set extcommunity soo",
5651 NO_STR
5652 SET_STR
5653 "GP extended community attribute\n"
5654 "Site-of-Origin extended community\n")
5655
5656 DEFUN_YANG (set_ecommunity_lb,
5657 set_ecommunity_lb_cmd,
5658 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5659 SET_STR
5660 "BGP extended community attribute\n"
5661 "Link bandwidth extended community\n"
5662 "Bandwidth value in Mbps\n"
5663 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5664 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5665 "Attribute is set as non-transitive\n")
5666 {
5667 int idx_lb = 3;
5668 int idx_non_transitive = 4;
5669 const char *xpath =
5670 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5671 char xpath_lb_type[XPATH_MAXLEN];
5672 char xpath_bandwidth[XPATH_MAXLEN];
5673 char xpath_non_transitive[XPATH_MAXLEN];
5674
5675 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5676
5677 snprintf(xpath_lb_type, sizeof(xpath_lb_type),
5678 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
5679 xpath);
5680 snprintf(xpath_bandwidth, sizeof(xpath_bandwidth),
5681 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
5682 xpath);
5683 snprintf(xpath_non_transitive, sizeof(xpath_non_transitive),
5684 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
5685 xpath);
5686
5687 if ((strcmp(argv[idx_lb]->arg, "cumulative")) == 0)
5688 nb_cli_enqueue_change(vty, xpath_lb_type, NB_OP_MODIFY,
5689 "cumulative-bandwidth");
5690 else if ((strcmp(argv[idx_lb]->arg, "num-multipaths")) == 0)
5691 nb_cli_enqueue_change(vty, xpath_lb_type, NB_OP_MODIFY,
5692 "computed-bandwidth");
5693 else {
5694 nb_cli_enqueue_change(vty, xpath_lb_type, NB_OP_MODIFY,
5695 "explicit-bandwidth");
5696 nb_cli_enqueue_change(vty, xpath_bandwidth, NB_OP_MODIFY,
5697 argv[idx_lb]->arg);
5698 }
5699
5700 if (argv[idx_non_transitive])
5701 nb_cli_enqueue_change(vty, xpath_non_transitive, NB_OP_MODIFY,
5702 "true");
5703 else
5704 nb_cli_enqueue_change(vty, xpath_non_transitive, NB_OP_MODIFY,
5705 "false");
5706
5707 return nb_cli_apply_changes(vty, NULL);
5708 }
5709
5710 DEFUN_YANG (no_set_ecommunity_lb,
5711 no_set_ecommunity_lb_cmd,
5712 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5713 NO_STR
5714 SET_STR
5715 "BGP extended community attribute\n"
5716 "Link bandwidth extended community\n"
5717 "Bandwidth value in Mbps\n"
5718 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5719 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5720 "Attribute is set as non-transitive\n")
5721 {
5722 const char *xpath =
5723 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5724
5725 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5726 return nb_cli_apply_changes(vty, NULL);
5727 }
5728
5729 ALIAS_YANG (no_set_ecommunity_lb,
5730 no_set_ecommunity_lb_short_cmd,
5731 "no set extcommunity bandwidth",
5732 NO_STR
5733 SET_STR
5734 "BGP extended community attribute\n"
5735 "Link bandwidth extended community\n")
5736
5737 DEFUN_YANG (set_origin,
5738 set_origin_cmd,
5739 "set origin <egp|igp|incomplete>",
5740 SET_STR
5741 "BGP origin code\n"
5742 "remote EGP\n"
5743 "local IGP\n"
5744 "unknown heritage\n")
5745 {
5746 int idx_origin = 2;
5747 const char *origin_type;
5748 const char *xpath =
5749 "./set-action[action='frr-bgp-route-map:set-origin']";
5750 char xpath_value[XPATH_MAXLEN];
5751
5752 if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0)
5753 origin_type = "igp";
5754 else if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0)
5755 origin_type = "egp";
5756 else if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0)
5757 origin_type = "incomplete";
5758 else {
5759 vty_out(vty, "%% Invalid match origin type\n");
5760 return CMD_WARNING_CONFIG_FAILED;
5761 }
5762
5763 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5764 snprintf(xpath_value, sizeof(xpath_value),
5765 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath);
5766 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, origin_type);
5767
5768 return nb_cli_apply_changes(vty, NULL);
5769 }
5770
5771 DEFUN_YANG (no_set_origin,
5772 no_set_origin_cmd,
5773 "no set origin [<egp|igp|incomplete>]",
5774 NO_STR
5775 SET_STR
5776 "BGP origin code\n"
5777 "remote EGP\n"
5778 "local IGP\n"
5779 "unknown heritage\n")
5780 {
5781 const char *xpath =
5782 "./set-action[action='frr-bgp-route-map:set-origin']";
5783
5784 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5785 return nb_cli_apply_changes(vty, NULL);
5786 }
5787
5788 DEFUN_YANG (set_atomic_aggregate,
5789 set_atomic_aggregate_cmd,
5790 "set atomic-aggregate",
5791 SET_STR
5792 "BGP atomic aggregate attribute\n" )
5793 {
5794 const char *xpath =
5795 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5796 char xpath_value[XPATH_MAXLEN];
5797
5798 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5799 snprintf(xpath_value, sizeof(xpath_value),
5800 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
5801 xpath);
5802 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, NULL);
5803
5804 return nb_cli_apply_changes(vty, NULL);
5805 }
5806
5807 DEFUN_YANG (no_set_atomic_aggregate,
5808 no_set_atomic_aggregate_cmd,
5809 "no set atomic-aggregate",
5810 NO_STR
5811 SET_STR
5812 "BGP atomic aggregate attribute\n" )
5813 {
5814 const char *xpath =
5815 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5816
5817 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5818 return nb_cli_apply_changes(vty, NULL);
5819 }
5820
5821 DEFUN_YANG (set_aggregator_as,
5822 set_aggregator_as_cmd,
5823 "set aggregator as (1-4294967295) A.B.C.D",
5824 SET_STR
5825 "BGP aggregator attribute\n"
5826 "AS number of aggregator\n"
5827 "AS number\n"
5828 "IP address of aggregator\n")
5829 {
5830 int idx_number = 3;
5831 int idx_ipv4 = 4;
5832 char xpath_asn[XPATH_MAXLEN];
5833 char xpath_addr[XPATH_MAXLEN];
5834 const char *xpath =
5835 "./set-action[action='frr-bgp-route-map:aggregator']";
5836
5837 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5838
5839 snprintf(
5840 xpath_asn, sizeof(xpath_asn),
5841 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
5842 xpath);
5843 nb_cli_enqueue_change(vty, xpath_asn, NB_OP_MODIFY,
5844 argv[idx_number]->arg);
5845
5846 snprintf(
5847 xpath_addr, sizeof(xpath_addr),
5848 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
5849 xpath);
5850 nb_cli_enqueue_change(vty, xpath_addr, NB_OP_MODIFY,
5851 argv[idx_ipv4]->arg);
5852
5853 return nb_cli_apply_changes(vty, NULL);
5854 }
5855
5856 DEFUN_YANG (no_set_aggregator_as,
5857 no_set_aggregator_as_cmd,
5858 "no set aggregator as [(1-4294967295) A.B.C.D]",
5859 NO_STR
5860 SET_STR
5861 "BGP aggregator attribute\n"
5862 "AS number of aggregator\n"
5863 "AS number\n"
5864 "IP address of aggregator\n")
5865 {
5866 const char *xpath =
5867 "./set-action[action='frr-bgp-route-map:aggregator']";
5868
5869 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5870 return nb_cli_apply_changes(vty, NULL);
5871 }
5872
5873 DEFUN_YANG (match_ipv6_next_hop,
5874 match_ipv6_next_hop_cmd,
5875 "match ipv6 next-hop X:X::X:X",
5876 MATCH_STR
5877 IPV6_STR
5878 "Match IPv6 next-hop address of route\n"
5879 "IPv6 address of next hop\n")
5880 {
5881 const char *xpath =
5882 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5883 char xpath_value[XPATH_MAXLEN];
5884
5885 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5886 snprintf(xpath_value, sizeof(xpath_value),
5887 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
5888 xpath);
5889 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[3]->arg);
5890
5891 return nb_cli_apply_changes(vty, NULL);
5892 }
5893
5894 DEFUN_YANG (no_match_ipv6_next_hop,
5895 no_match_ipv6_next_hop_cmd,
5896 "no match ipv6 next-hop X:X::X:X",
5897 NO_STR
5898 MATCH_STR
5899 IPV6_STR
5900 "Match IPv6 next-hop address of route\n"
5901 "IPv6 address of next hop\n")
5902 {
5903 const char *xpath =
5904 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5905
5906 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5907 return nb_cli_apply_changes(vty, NULL);
5908 }
5909
5910 DEFPY_YANG (match_ipv4_next_hop,
5911 match_ipv4_next_hop_cmd,
5912 "match ip next-hop address A.B.C.D",
5913 MATCH_STR
5914 IP_STR
5915 "Match IP next-hop address of route\n"
5916 "IP address\n"
5917 "IP address of next-hop\n")
5918 {
5919 const char *xpath =
5920 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5921 char xpath_value[XPATH_MAXLEN];
5922
5923 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5924 snprintf(xpath_value, sizeof(xpath_value),
5925 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
5926 xpath);
5927 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[4]->arg);
5928
5929 return nb_cli_apply_changes(vty, NULL);
5930 }
5931
5932 DEFPY_YANG (no_match_ipv4_next_hop,
5933 no_match_ipv4_next_hop_cmd,
5934 "no match ip next-hop address [A.B.C.D]",
5935 NO_STR
5936 MATCH_STR
5937 IP_STR
5938 "Match IP next-hop address of route\n"
5939 "IP address\n"
5940 "IP address of next-hop\n")
5941 {
5942 const char *xpath =
5943 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5944
5945 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5946 return nb_cli_apply_changes(vty, NULL);
5947 }
5948
5949 DEFUN_YANG (set_ipv6_nexthop_peer,
5950 set_ipv6_nexthop_peer_cmd,
5951 "set ipv6 next-hop peer-address",
5952 SET_STR
5953 IPV6_STR
5954 "Next hop address\n"
5955 "Use peer address (for BGP only)\n")
5956 {
5957 const char *xpath =
5958 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5959 char xpath_value[XPATH_MAXLEN];
5960
5961 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5962 snprintf(xpath_value, sizeof(xpath_value),
5963 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath);
5964 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, "true");
5965
5966 return nb_cli_apply_changes(vty, NULL);
5967 }
5968
5969 DEFUN_YANG (no_set_ipv6_nexthop_peer,
5970 no_set_ipv6_nexthop_peer_cmd,
5971 "no set ipv6 next-hop peer-address",
5972 NO_STR
5973 SET_STR
5974 IPV6_STR
5975 "IPv6 next-hop address\n"
5976 "Use peer address (for BGP only)\n")
5977 {
5978 const char *xpath =
5979 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5980
5981 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
5982 return nb_cli_apply_changes(vty, NULL);
5983 }
5984
5985 DEFUN_YANG (set_ipv6_nexthop_prefer_global,
5986 set_ipv6_nexthop_prefer_global_cmd,
5987 "set ipv6 next-hop prefer-global",
5988 SET_STR
5989 IPV6_STR
5990 "IPv6 next-hop address\n"
5991 "Prefer global over link-local if both exist\n")
5992 {
5993 const char *xpath =
5994 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
5995 char xpath_value[XPATH_MAXLEN];
5996
5997 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
5998 snprintf(xpath_value, sizeof(xpath_value),
5999 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath);
6000 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, "true");
6001
6002 return nb_cli_apply_changes(vty, NULL);
6003 }
6004
6005 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global,
6006 no_set_ipv6_nexthop_prefer_global_cmd,
6007 "no set ipv6 next-hop prefer-global",
6008 NO_STR
6009 SET_STR
6010 IPV6_STR
6011 "IPv6 next-hop address\n"
6012 "Prefer global over link-local if both exist\n")
6013 {
6014 const char *xpath =
6015 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6016
6017 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6018 return nb_cli_apply_changes(vty, NULL);
6019 }
6020
6021 DEFUN_YANG (set_ipv6_nexthop_global,
6022 set_ipv6_nexthop_global_cmd,
6023 "set ipv6 next-hop global X:X::X:X",
6024 SET_STR
6025 IPV6_STR
6026 "IPv6 next-hop address\n"
6027 "IPv6 global address\n"
6028 "IPv6 address of next hop\n")
6029 {
6030 int idx_ipv6 = 4;
6031 const char *xpath =
6032 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6033 char xpath_value[XPATH_MAXLEN];
6034
6035 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6036 snprintf(xpath_value, sizeof(xpath_value),
6037 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath);
6038 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
6039 argv[idx_ipv6]->arg);
6040
6041 return nb_cli_apply_changes(vty, NULL);
6042 }
6043
6044 DEFUN_YANG (no_set_ipv6_nexthop_global,
6045 no_set_ipv6_nexthop_global_cmd,
6046 "no set ipv6 next-hop global X:X::X:X",
6047 NO_STR
6048 SET_STR
6049 IPV6_STR
6050 "IPv6 next-hop address\n"
6051 "IPv6 global address\n"
6052 "IPv6 address of next hop\n")
6053 {
6054 const char *xpath =
6055 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6056
6057 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6058 return nb_cli_apply_changes(vty, NULL);
6059 }
6060
6061 #ifdef KEEP_OLD_VPN_COMMANDS
6062 DEFUN_YANG (set_vpn_nexthop,
6063 set_vpn_nexthop_cmd,
6064 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6065 SET_STR
6066 "VPNv4 information\n"
6067 "VPN next-hop address\n"
6068 "IP address of next hop\n"
6069 "VPNv6 information\n"
6070 "VPN next-hop address\n"
6071 "IPv6 address of next hop\n")
6072 {
6073 int idx_ip = 3;
6074 afi_t afi;
6075 int idx = 0;
6076 char xpath_value[XPATH_MAXLEN];
6077
6078 if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) {
6079 if (afi == AFI_IP) {
6080 const char *xpath =
6081 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6082
6083 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6084 snprintf(
6085 xpath_value, sizeof(xpath_value),
6086 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6087 xpath);
6088 } else {
6089 const char *xpath =
6090 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6091
6092 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6093 snprintf(
6094 xpath_value, sizeof(xpath_value),
6095 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6096 xpath);
6097 }
6098
6099 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
6100 argv[idx_ip]->arg);
6101
6102 return nb_cli_apply_changes(vty, NULL);
6103 }
6104
6105 return CMD_SUCCESS;
6106 }
6107
6108 DEFUN_YANG (no_set_vpn_nexthop,
6109 no_set_vpn_nexthop_cmd,
6110 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6111 NO_STR
6112 SET_STR
6113 "VPNv4 information\n"
6114 "VPN next-hop address\n"
6115 "IP address of next hop\n"
6116 "VPNv6 information\n"
6117 "VPN next-hop address\n"
6118 "IPv6 address of next hop\n")
6119 {
6120 afi_t afi;
6121 int idx = 0;
6122
6123 if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) {
6124 if (afi == AFI_IP) {
6125 const char *xpath =
6126 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6127 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6128 } else {
6129 const char *xpath =
6130 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6131 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6132 }
6133 return nb_cli_apply_changes(vty, NULL);
6134 }
6135 return CMD_SUCCESS;
6136 }
6137 #endif /* KEEP_OLD_VPN_COMMANDS */
6138
6139 DEFUN_YANG (set_ipx_vpn_nexthop,
6140 set_ipx_vpn_nexthop_cmd,
6141 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
6142 SET_STR
6143 "IPv4 information\n"
6144 "IPv6 information\n"
6145 "VPN information\n"
6146 "VPN next-hop address\n"
6147 "IP address of next hop\n"
6148 "IPv6 address of next hop\n")
6149 {
6150 int idx_ip = 4;
6151 afi_t afi;
6152 int idx = 0;
6153 char xpath_value[XPATH_MAXLEN];
6154
6155 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
6156 if (afi == AFI_IP) {
6157 const char *xpath =
6158 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6159
6160 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6161 snprintf(
6162 xpath_value, sizeof(xpath_value),
6163 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6164 xpath);
6165 } else {
6166 const char *xpath =
6167 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6168
6169 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6170 snprintf(
6171 xpath_value, sizeof(xpath_value),
6172 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6173 xpath);
6174 }
6175 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
6176 argv[idx_ip]->arg);
6177 return nb_cli_apply_changes(vty, NULL);
6178 }
6179 return CMD_SUCCESS;
6180 }
6181
6182 DEFUN_YANG (no_set_ipx_vpn_nexthop,
6183 no_set_ipx_vpn_nexthop_cmd,
6184 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6185 NO_STR
6186 SET_STR
6187 "IPv4 information\n"
6188 "IPv6 information\n"
6189 "VPN information\n"
6190 "VPN next-hop address\n"
6191 "IP address of next hop\n"
6192 "IPv6 address of next hop\n")
6193 {
6194 afi_t afi;
6195 int idx = 0;
6196
6197 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
6198 if (afi == AFI_IP) {
6199 const char *xpath =
6200 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6201 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6202 } else {
6203 const char *xpath =
6204 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6205 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6206 }
6207 return nb_cli_apply_changes(vty, NULL);
6208 }
6209 return CMD_SUCCESS;
6210 }
6211
6212 DEFUN_YANG (set_originator_id,
6213 set_originator_id_cmd,
6214 "set originator-id A.B.C.D",
6215 SET_STR
6216 "BGP originator ID attribute\n"
6217 "IP address of originator\n")
6218 {
6219 int idx_ipv4 = 2;
6220 const char *xpath =
6221 "./set-action[action='frr-bgp-route-map:originator-id']";
6222 char xpath_value[XPATH_MAXLEN];
6223
6224 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
6225 snprintf(xpath_value, sizeof(xpath_value),
6226 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath);
6227 nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
6228 argv[idx_ipv4]->arg);
6229
6230 return nb_cli_apply_changes(vty, NULL);
6231 }
6232
6233 DEFUN_YANG (no_set_originator_id,
6234 no_set_originator_id_cmd,
6235 "no set originator-id [A.B.C.D]",
6236 NO_STR
6237 SET_STR
6238 "BGP originator ID attribute\n"
6239 "IP address of originator\n")
6240 {
6241 const char *xpath =
6242 "./set-action[action='frr-bgp-route-map:originator-id']";
6243
6244 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
6245 return nb_cli_apply_changes(vty, NULL);
6246 }
6247
6248 /* Initialization of route map. */
6249 void bgp_route_map_init(void)
6250 {
6251 route_map_init();
6252
6253 route_map_add_hook(bgp_route_map_add);
6254 route_map_delete_hook(bgp_route_map_delete);
6255 route_map_event_hook(bgp_route_map_event);
6256
6257 route_map_match_interface_hook(generic_match_add);
6258 route_map_no_match_interface_hook(generic_match_delete);
6259
6260 route_map_match_ip_address_hook(generic_match_add);
6261 route_map_no_match_ip_address_hook(generic_match_delete);
6262
6263 route_map_match_ip_address_prefix_list_hook(generic_match_add);
6264 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete);
6265
6266 route_map_match_ip_next_hop_hook(generic_match_add);
6267 route_map_no_match_ip_next_hop_hook(generic_match_delete);
6268
6269 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add);
6270 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete);
6271
6272 route_map_match_ip_next_hop_type_hook(generic_match_add);
6273 route_map_no_match_ip_next_hop_type_hook(generic_match_delete);
6274
6275 route_map_match_ipv6_address_hook(generic_match_add);
6276 route_map_no_match_ipv6_address_hook(generic_match_delete);
6277
6278 route_map_match_ipv6_address_prefix_list_hook(generic_match_add);
6279 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete);
6280
6281 route_map_match_ipv6_next_hop_type_hook(generic_match_add);
6282 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete);
6283
6284 route_map_match_metric_hook(generic_match_add);
6285 route_map_no_match_metric_hook(generic_match_delete);
6286
6287 route_map_match_tag_hook(generic_match_add);
6288 route_map_no_match_tag_hook(generic_match_delete);
6289
6290 route_map_set_srte_color_hook(generic_set_add);
6291 route_map_no_set_srte_color_hook(generic_set_delete);
6292
6293 route_map_set_ip_nexthop_hook(generic_set_add);
6294 route_map_no_set_ip_nexthop_hook(generic_set_delete);
6295
6296 route_map_set_ipv6_nexthop_local_hook(generic_set_add);
6297 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete);
6298
6299 route_map_set_metric_hook(generic_set_add);
6300 route_map_no_set_metric_hook(generic_set_delete);
6301
6302 route_map_set_tag_hook(generic_set_add);
6303 route_map_no_set_tag_hook(generic_set_delete);
6304
6305 route_map_install_match(&route_match_peer_cmd);
6306 route_map_install_match(&route_match_local_pref_cmd);
6307 #ifdef HAVE_SCRIPTING
6308 route_map_install_match(&route_match_script_cmd);
6309 #endif
6310 route_map_install_match(&route_match_ip_address_cmd);
6311 route_map_install_match(&route_match_ip_next_hop_cmd);
6312 route_map_install_match(&route_match_ip_route_source_cmd);
6313 route_map_install_match(&route_match_ip_address_prefix_list_cmd);
6314 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd);
6315 route_map_install_match(&route_match_ip_next_hop_type_cmd);
6316 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd);
6317 route_map_install_match(&route_match_aspath_cmd);
6318 route_map_install_match(&route_match_community_cmd);
6319 route_map_install_match(&route_match_lcommunity_cmd);
6320 route_map_install_match(&route_match_ecommunity_cmd);
6321 route_map_install_match(&route_match_local_pref_cmd);
6322 route_map_install_match(&route_match_metric_cmd);
6323 route_map_install_match(&route_match_origin_cmd);
6324 route_map_install_match(&route_match_probability_cmd);
6325 route_map_install_match(&route_match_interface_cmd);
6326 route_map_install_match(&route_match_tag_cmd);
6327 route_map_install_match(&route_match_mac_address_cmd);
6328 route_map_install_match(&route_match_evpn_vni_cmd);
6329 route_map_install_match(&route_match_evpn_route_type_cmd);
6330 route_map_install_match(&route_match_evpn_rd_cmd);
6331 route_map_install_match(&route_match_evpn_default_route_cmd);
6332 route_map_install_match(&route_match_vrl_source_vrf_cmd);
6333
6334 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd);
6335 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd);
6336 route_map_install_set(&route_set_table_id_cmd);
6337 route_map_install_set(&route_set_srte_color_cmd);
6338 route_map_install_set(&route_set_ip_nexthop_cmd);
6339 route_map_install_set(&route_set_local_pref_cmd);
6340 route_map_install_set(&route_set_weight_cmd);
6341 route_map_install_set(&route_set_label_index_cmd);
6342 route_map_install_set(&route_set_metric_cmd);
6343 route_map_install_set(&route_set_distance_cmd);
6344 route_map_install_set(&route_set_aspath_prepend_cmd);
6345 route_map_install_set(&route_set_aspath_exclude_cmd);
6346 route_map_install_set(&route_set_origin_cmd);
6347 route_map_install_set(&route_set_atomic_aggregate_cmd);
6348 route_map_install_set(&route_set_aggregator_as_cmd);
6349 route_map_install_set(&route_set_community_cmd);
6350 route_map_install_set(&route_set_community_delete_cmd);
6351 route_map_install_set(&route_set_lcommunity_cmd);
6352 route_map_install_set(&route_set_lcommunity_delete_cmd);
6353 route_map_install_set(&route_set_vpnv4_nexthop_cmd);
6354 route_map_install_set(&route_set_vpnv6_nexthop_cmd);
6355 route_map_install_set(&route_set_originator_id_cmd);
6356 route_map_install_set(&route_set_ecommunity_rt_cmd);
6357 route_map_install_set(&route_set_ecommunity_soo_cmd);
6358 route_map_install_set(&route_set_ecommunity_lb_cmd);
6359 route_map_install_set(&route_set_tag_cmd);
6360 route_map_install_set(&route_set_label_index_cmd);
6361
6362 install_element(RMAP_NODE, &match_peer_cmd);
6363 install_element(RMAP_NODE, &match_peer_local_cmd);
6364 install_element(RMAP_NODE, &no_match_peer_cmd);
6365 install_element(RMAP_NODE, &match_ip_route_source_cmd);
6366 install_element(RMAP_NODE, &no_match_ip_route_source_cmd);
6367 install_element(RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
6368 install_element(RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
6369 install_element(RMAP_NODE, &match_mac_address_cmd);
6370 install_element(RMAP_NODE, &no_match_mac_address_cmd);
6371 install_element(RMAP_NODE, &match_evpn_vni_cmd);
6372 install_element(RMAP_NODE, &no_match_evpn_vni_cmd);
6373 install_element(RMAP_NODE, &match_evpn_route_type_cmd);
6374 install_element(RMAP_NODE, &no_match_evpn_route_type_cmd);
6375 install_element(RMAP_NODE, &match_evpn_rd_cmd);
6376 install_element(RMAP_NODE, &no_match_evpn_rd_cmd);
6377 install_element(RMAP_NODE, &match_evpn_default_route_cmd);
6378 install_element(RMAP_NODE, &no_match_evpn_default_route_cmd);
6379 install_element(RMAP_NODE, &set_evpn_gw_ip_ipv4_cmd);
6380 install_element(RMAP_NODE, &no_set_evpn_gw_ip_ipv4_cmd);
6381 install_element(RMAP_NODE, &set_evpn_gw_ip_ipv6_cmd);
6382 install_element(RMAP_NODE, &no_set_evpn_gw_ip_ipv6_cmd);
6383 install_element(RMAP_NODE, &match_vrl_source_vrf_cmd);
6384 install_element(RMAP_NODE, &no_match_vrl_source_vrf_cmd);
6385
6386 install_element(RMAP_NODE, &match_aspath_cmd);
6387 install_element(RMAP_NODE, &no_match_aspath_cmd);
6388 install_element(RMAP_NODE, &match_local_pref_cmd);
6389 install_element(RMAP_NODE, &no_match_local_pref_cmd);
6390 install_element(RMAP_NODE, &match_community_cmd);
6391 install_element(RMAP_NODE, &no_match_community_cmd);
6392 install_element(RMAP_NODE, &match_lcommunity_cmd);
6393 install_element(RMAP_NODE, &no_match_lcommunity_cmd);
6394 install_element(RMAP_NODE, &match_ecommunity_cmd);
6395 install_element(RMAP_NODE, &no_match_ecommunity_cmd);
6396 install_element(RMAP_NODE, &match_origin_cmd);
6397 install_element(RMAP_NODE, &no_match_origin_cmd);
6398 install_element(RMAP_NODE, &match_probability_cmd);
6399 install_element(RMAP_NODE, &no_match_probability_cmd);
6400
6401 install_element(RMAP_NODE, &no_set_table_id_cmd);
6402 install_element(RMAP_NODE, &set_table_id_cmd);
6403 install_element(RMAP_NODE, &set_ip_nexthop_peer_cmd);
6404 install_element(RMAP_NODE, &set_ip_nexthop_unchanged_cmd);
6405 install_element(RMAP_NODE, &set_local_pref_cmd);
6406 install_element(RMAP_NODE, &set_distance_cmd);
6407 install_element(RMAP_NODE, &no_set_distance_cmd);
6408 install_element(RMAP_NODE, &no_set_local_pref_cmd);
6409 install_element(RMAP_NODE, &set_weight_cmd);
6410 install_element(RMAP_NODE, &set_label_index_cmd);
6411 install_element(RMAP_NODE, &no_set_weight_cmd);
6412 install_element(RMAP_NODE, &no_set_label_index_cmd);
6413 install_element(RMAP_NODE, &set_aspath_prepend_asn_cmd);
6414 install_element(RMAP_NODE, &set_aspath_prepend_lastas_cmd);
6415 install_element(RMAP_NODE, &set_aspath_exclude_cmd);
6416 install_element(RMAP_NODE, &no_set_aspath_prepend_cmd);
6417 install_element(RMAP_NODE, &no_set_aspath_prepend_lastas_cmd);
6418 install_element(RMAP_NODE, &no_set_aspath_exclude_cmd);
6419 install_element(RMAP_NODE, &no_set_aspath_exclude_all_cmd);
6420 install_element(RMAP_NODE, &set_origin_cmd);
6421 install_element(RMAP_NODE, &no_set_origin_cmd);
6422 install_element(RMAP_NODE, &set_atomic_aggregate_cmd);
6423 install_element(RMAP_NODE, &no_set_atomic_aggregate_cmd);
6424 install_element(RMAP_NODE, &set_aggregator_as_cmd);
6425 install_element(RMAP_NODE, &no_set_aggregator_as_cmd);
6426 install_element(RMAP_NODE, &set_community_cmd);
6427 install_element(RMAP_NODE, &set_community_none_cmd);
6428 install_element(RMAP_NODE, &no_set_community_cmd);
6429 install_element(RMAP_NODE, &no_set_community_short_cmd);
6430 install_element(RMAP_NODE, &set_community_delete_cmd);
6431 install_element(RMAP_NODE, &no_set_community_delete_cmd);
6432 install_element(RMAP_NODE, &set_lcommunity_cmd);
6433 install_element(RMAP_NODE, &set_lcommunity_none_cmd);
6434 install_element(RMAP_NODE, &no_set_lcommunity_cmd);
6435 install_element(RMAP_NODE, &no_set_lcommunity1_cmd);
6436 install_element(RMAP_NODE, &no_set_lcommunity1_short_cmd);
6437 install_element(RMAP_NODE, &set_lcommunity_delete_cmd);
6438 install_element(RMAP_NODE, &no_set_lcommunity_delete_cmd);
6439 install_element(RMAP_NODE, &no_set_lcommunity_delete_short_cmd);
6440 install_element(RMAP_NODE, &set_ecommunity_rt_cmd);
6441 install_element(RMAP_NODE, &no_set_ecommunity_rt_cmd);
6442 install_element(RMAP_NODE, &no_set_ecommunity_rt_short_cmd);
6443 install_element(RMAP_NODE, &set_ecommunity_soo_cmd);
6444 install_element(RMAP_NODE, &no_set_ecommunity_soo_cmd);
6445 install_element(RMAP_NODE, &no_set_ecommunity_soo_short_cmd);
6446 install_element(RMAP_NODE, &set_ecommunity_lb_cmd);
6447 install_element(RMAP_NODE, &no_set_ecommunity_lb_cmd);
6448 install_element(RMAP_NODE, &no_set_ecommunity_lb_short_cmd);
6449 #ifdef KEEP_OLD_VPN_COMMANDS
6450 install_element(RMAP_NODE, &set_vpn_nexthop_cmd);
6451 install_element(RMAP_NODE, &no_set_vpn_nexthop_cmd);
6452 #endif /* KEEP_OLD_VPN_COMMANDS */
6453 install_element(RMAP_NODE, &set_ipx_vpn_nexthop_cmd);
6454 install_element(RMAP_NODE, &no_set_ipx_vpn_nexthop_cmd);
6455 install_element(RMAP_NODE, &set_originator_id_cmd);
6456 install_element(RMAP_NODE, &no_set_originator_id_cmd);
6457
6458 route_map_install_match(&route_match_ipv6_address_cmd);
6459 route_map_install_match(&route_match_ipv6_next_hop_cmd);
6460 route_map_install_match(&route_match_ipv4_next_hop_cmd);
6461 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd);
6462 route_map_install_match(&route_match_ipv6_next_hop_type_cmd);
6463 route_map_install_set(&route_set_ipv6_nexthop_global_cmd);
6464 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd);
6465 route_map_install_set(&route_set_ipv6_nexthop_local_cmd);
6466 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd);
6467
6468 install_element(RMAP_NODE, &match_ipv6_next_hop_cmd);
6469 install_element(RMAP_NODE, &no_match_ipv6_next_hop_cmd);
6470 install_element(RMAP_NODE, &match_ipv4_next_hop_cmd);
6471 install_element(RMAP_NODE, &no_match_ipv4_next_hop_cmd);
6472 install_element(RMAP_NODE, &set_ipv6_nexthop_global_cmd);
6473 install_element(RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
6474 install_element(RMAP_NODE, &set_ipv6_nexthop_prefer_global_cmd);
6475 install_element(RMAP_NODE, &no_set_ipv6_nexthop_prefer_global_cmd);
6476 install_element(RMAP_NODE, &set_ipv6_nexthop_peer_cmd);
6477 install_element(RMAP_NODE, &no_set_ipv6_nexthop_peer_cmd);
6478 #ifdef HAVE_SCRIPTING
6479 install_element(RMAP_NODE, &match_script_cmd);
6480 #endif
6481 }
6482
6483 void bgp_route_map_terminate(void)
6484 {
6485 /* ToDo: Cleanup all the used memory */
6486 route_map_finish();
6487 }