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