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