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