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