]>
Commit | Line | Data |
---|---|---|
e5c83d9b DS |
1 | /* |
2 | * PBR - vty code | |
3 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
6 | * FRR 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 | * FRR is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | #include <zebra.h> | |
21 | ||
22 | #include "vty.h" | |
23 | #include "command.h" | |
24 | #include "prefix.h" | |
25 | #include "vrf.h" | |
26 | #include "nexthop.h" | |
27 | #include "nexthop_group.h" | |
28 | #include "log.h" | |
29 | #include "json.h" | |
30 | #include "debug.h" | |
31 | ||
32 | #include "pbrd/pbr_nht.h" | |
33 | #include "pbrd/pbr_map.h" | |
34 | #include "pbrd/pbr_zebra.h" | |
35 | #include "pbrd/pbr_vty.h" | |
e5c83d9b DS |
36 | #include "pbrd/pbr_debug.h" |
37 | #ifndef VTYSH_EXTRACT_PL | |
38 | #include "pbrd/pbr_vty_clippy.c" | |
39 | #endif | |
40 | ||
41 | DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map WORD seq (1-1000)", | |
42 | "Create pbr-map or enter pbr-map command mode\n" | |
43 | "The name of the PBR MAP\n" | |
44 | "Sequence to insert in existing pbr-map entry\n" | |
45 | "Sequence number\n") | |
46 | { | |
47 | const char *pbrm_name = argv[1]->arg; | |
48 | uint32_t seqno = atoi(argv[3]->arg); | |
49 | struct pbr_map_sequence *pbrms; | |
50 | ||
51 | pbrms = pbrms_get(pbrm_name, seqno); | |
52 | VTY_PUSH_CONTEXT(PBRMAP_NODE, pbrms); | |
53 | ||
54 | return CMD_SUCCESS; | |
55 | } | |
56 | ||
57 | DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map WORD [seq (1-65535)]", | |
58 | NO_STR | |
59 | "Delete pbr-map\n" | |
60 | "The name of the PBR MAP\n" | |
61 | "Sequence to delete from existing pbr-map entry\n" | |
62 | "Sequence number\n") | |
63 | { | |
64 | const char *pbrm_name = argv[2]->arg; | |
65 | uint32_t seqno = 0; | |
66 | struct pbr_map *pbrm = pbrm_find(pbrm_name); | |
e5c83d9b DS |
67 | struct pbr_map_sequence *pbrms; |
68 | struct listnode *node, *next_node; | |
69 | ||
70 | if (argc > 3) | |
71 | seqno = atoi(argv[4]->arg); | |
72 | ||
73 | if (!pbrm) { | |
74 | vty_out(vty, "pbr-map %s not found\n", pbrm_name); | |
75 | return CMD_SUCCESS; | |
76 | } | |
77 | ||
b13e5ad6 DS |
78 | for (ALL_LIST_ELEMENTS(pbrm->seqnumbers, node, next_node, pbrms)) { |
79 | if (seqno && pbrms->seqno != seqno) | |
80 | continue; | |
e5c83d9b | 81 | |
b13e5ad6 DS |
82 | pbr_map_delete(pbrms); |
83 | } | |
e5c83d9b DS |
84 | |
85 | return CMD_SUCCESS; | |
86 | } | |
87 | ||
88 | DEFPY(pbr_map_match_src, pbr_map_match_src_cmd, | |
89 | "[no] match src-ip <A.B.C.D/M|X:X::X:X/M>$prefix", | |
90 | NO_STR | |
91 | "Match the rest of the command\n" | |
92 | "Choose the src ip or ipv6 prefix to use\n" | |
93 | "v4 Prefix\n" | |
94 | "v6 Prefix\n") | |
95 | { | |
96 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
e5c83d9b | 97 | |
49027ce8 DS |
98 | pbrms->family = prefix->family; |
99 | ||
e5c83d9b | 100 | if (!no) { |
b8eb036f DS |
101 | if (prefix_same(pbrms->src, prefix)) |
102 | return CMD_SUCCESS; | |
103 | ||
e5c83d9b DS |
104 | if (!pbrms->src) |
105 | pbrms->src = prefix_new(); | |
106 | prefix_copy(pbrms->src, prefix); | |
107 | } else { | |
108 | prefix_free(pbrms->src); | |
109 | pbrms->src = 0; | |
110 | } | |
111 | ||
b13e5ad6 | 112 | pbr_map_check(pbrms); |
e5c83d9b DS |
113 | |
114 | return CMD_SUCCESS; | |
115 | } | |
116 | ||
117 | DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd, | |
118 | "[no] match dst-ip <A.B.C.D/M|X:X::X:X/M>$prefix", | |
119 | NO_STR | |
120 | "Match the rest of the command\n" | |
121 | "Choose the src ip or ipv6 prefix to use\n" | |
122 | "v4 Prefix\n" | |
123 | "v6 Prefix\n") | |
124 | { | |
125 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
e5c83d9b | 126 | |
49027ce8 DS |
127 | pbrms->family = prefix->family; |
128 | ||
e5c83d9b | 129 | if (!no) { |
b8eb036f DS |
130 | if (prefix_same(pbrms->dst, prefix)) |
131 | return CMD_SUCCESS; | |
132 | ||
e5c83d9b DS |
133 | if (!pbrms->dst) |
134 | pbrms->dst = prefix_new(); | |
135 | prefix_copy(pbrms->dst, prefix); | |
136 | } else { | |
137 | prefix_free(pbrms->dst); | |
b13e5ad6 | 138 | pbrms->dst = NULL; |
e5c83d9b DS |
139 | } |
140 | ||
b13e5ad6 | 141 | pbr_map_check(pbrms); |
e5c83d9b DS |
142 | |
143 | return CMD_SUCCESS; | |
144 | } | |
145 | ||
146 | DEFPY(pbr_map_nexthop_group, pbr_map_nexthop_group_cmd, | |
147 | "[no] set nexthop-group NAME$name", | |
148 | NO_STR | |
149 | "Set for the PBR-MAP\n" | |
150 | "nexthop-group to use\n" | |
151 | "The name of the nexthop-group\n") | |
152 | { | |
153 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
154 | struct nexthop_group_cmd *nhgc; | |
e5c83d9b | 155 | |
e042a421 DS |
156 | if (pbrms->nhg) { |
157 | vty_out(vty, | |
158 | "A `set nexthop XX` command already exists, please remove that first\n"); | |
3a9210c2 | 159 | return CMD_WARNING_CONFIG_FAILED; |
e042a421 DS |
160 | } |
161 | ||
e5c83d9b DS |
162 | nhgc = nhgc_find(name); |
163 | if (!nhgc) { | |
164 | vty_out(vty, "Specified nexthop-group %s does not exist\n", | |
165 | name); | |
166 | vty_out(vty, "PBR-MAP will not be applied until it is created\n"); | |
167 | } | |
168 | ||
169 | if (no) { | |
170 | if (pbrms->nhgrp_name && strcmp(name, pbrms->nhgrp_name) == 0) | |
b13e5ad6 | 171 | pbr_map_delete_nexthop_group(pbrms); |
e5c83d9b DS |
172 | else { |
173 | vty_out(vty, | |
174 | "Nexthop Group specified: %s does not exist to remove", | |
175 | name); | |
3a9210c2 | 176 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
177 | } |
178 | } else { | |
179 | if (pbrms->nhgrp_name) { | |
180 | if (strcmp(name, pbrms->nhgrp_name) != 0) { | |
181 | vty_out(vty, | |
182 | "Please delete current nexthop group before modifying current one"); | |
3a9210c2 | 183 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
184 | } |
185 | ||
186 | return CMD_SUCCESS; | |
187 | } | |
188 | pbrms->nhgrp_name = XSTRDUP(MTYPE_TMP, name); | |
b13e5ad6 | 189 | pbr_map_check(pbrms); |
e5c83d9b DS |
190 | } |
191 | ||
e5c83d9b DS |
192 | return CMD_SUCCESS; |
193 | } | |
194 | ||
195 | DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd, | |
196 | "[no] set nexthop <A.B.C.D|X:X::X:X>$addr [INTERFACE]$intf [nexthop-vrf NAME$name]", | |
197 | NO_STR | |
198 | "Set for the PBR-MAP\n" | |
199 | "Specify one of the nexthops in this map\n" | |
200 | "v4 Address\n" | |
201 | "v6 Address\n" | |
202 | "Interface to use\n" | |
203 | "If the nexthop is in a different vrf tell us\n" | |
204 | "The nexthop-vrf Name\n") | |
205 | { | |
206 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
207 | struct vrf *vrf; | |
208 | struct nexthop nhop; | |
209 | struct nexthop *nh; | |
e5c83d9b DS |
210 | |
211 | if (pbrms->nhgrp_name) { | |
212 | vty_out(vty, | |
213 | "Please unconfigure the nexthop group before adding an individual nexthop"); | |
3a9210c2 | 214 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
215 | } |
216 | ||
217 | if (name) | |
218 | vrf = vrf_lookup_by_name(name); | |
219 | else | |
220 | vrf = vrf_lookup_by_id(VRF_DEFAULT); | |
221 | ||
222 | if (!vrf) { | |
223 | vty_out(vty, "Specified: %s is non-existent\n", name); | |
3a9210c2 | 224 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
225 | } |
226 | ||
227 | memset(&nhop, 0, sizeof(nhop)); | |
228 | nhop.vrf_id = vrf->vrf_id; | |
229 | ||
230 | if (addr->sa.sa_family == AF_INET) { | |
231 | nhop.gate.ipv4.s_addr = addr->sin.sin_addr.s_addr; | |
232 | if (intf) { | |
233 | nhop.type = NEXTHOP_TYPE_IPV4_IFINDEX; | |
234 | nhop.ifindex = ifname2ifindex(intf, vrf->vrf_id); | |
235 | if (nhop.ifindex == IFINDEX_INTERNAL) { | |
236 | vty_out(vty, | |
237 | "Specified Intf %s does not exist in vrf: %s\n", | |
238 | intf, vrf->name); | |
3a9210c2 | 239 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
240 | } |
241 | } else | |
242 | nhop.type = NEXTHOP_TYPE_IPV4; | |
243 | } else { | |
244 | memcpy(&nhop.gate.ipv6, &addr->sin6.sin6_addr, 16); | |
245 | if (intf) { | |
246 | nhop.type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
247 | nhop.ifindex = ifname2ifindex(intf, vrf->vrf_id); | |
248 | if (nhop.ifindex == IFINDEX_INTERNAL) { | |
249 | vty_out(vty, | |
250 | "Specified Intf %s does not exist in vrf: %s\n", | |
251 | intf, vrf->name); | |
3a9210c2 | 252 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
253 | } |
254 | } else | |
255 | nhop.type = NEXTHOP_TYPE_IPV6; | |
256 | } | |
257 | ||
258 | if (pbrms->nhg) | |
259 | nh = nexthop_exists(pbrms->nhg, &nhop); | |
260 | else { | |
261 | char buf[100]; | |
262 | ||
263 | if (no) { | |
264 | vty_out(vty, "No nexthops to delete"); | |
3a9210c2 | 265 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
266 | } |
267 | ||
268 | pbrms->nhg = nexthop_group_new(); | |
269 | pbrms->internal_nhg_name = | |
270 | XSTRDUP(MTYPE_TMP, | |
271 | pbr_nht_nexthop_make_name(pbrms->parent->name, | |
272 | PBR_MAP_NAMELEN, | |
273 | pbrms->seqno, | |
274 | buf)); | |
275 | nh = NULL; | |
276 | } | |
277 | ||
278 | if (no) { | |
b13e5ad6 DS |
279 | if (nh) |
280 | pbr_nht_delete_individual_nexthop(pbrms); | |
e5c83d9b DS |
281 | } else if (!nh) { |
282 | ||
283 | if (pbrms->nhg->nexthop) { | |
284 | vty_out(vty, | |
285 | "If you would like more than one nexthop please use nexthop-groups"); | |
3a9210c2 | 286 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
287 | } |
288 | ||
289 | /* must be adding new nexthop since !no and !nexthop_exists */ | |
290 | nh = nexthop_new(); | |
291 | ||
292 | memcpy(nh, &nhop, sizeof(nhop)); | |
293 | nexthop_add(&pbrms->nhg->nexthop, nh); | |
294 | ||
b13e5ad6 DS |
295 | pbr_nht_add_individual_nexthop(pbrms); |
296 | pbr_map_check(pbrms); | |
e5c83d9b DS |
297 | } |
298 | ||
299 | return CMD_SUCCESS; | |
300 | } | |
301 | ||
e5c83d9b DS |
302 | DEFPY (pbr_policy, |
303 | pbr_policy_cmd, | |
304 | "[no] pbr-policy NAME$mapname", | |
305 | NO_STR | |
306 | "Policy to use\n" | |
307 | "Name of the pbr-map to apply\n") | |
308 | { | |
309 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
310 | struct pbr_map *pbrm, *old_pbrm; | |
311 | struct pbr_interface *pbr_ifp = ifp->info; | |
312 | ||
313 | pbrm = pbrm_find(mapname); | |
314 | ||
b13e5ad6 DS |
315 | if (!pbr_ifp) { |
316 | /* | |
317 | * Some one could have fat fingered the interface | |
318 | * name | |
319 | */ | |
320 | pbr_ifp = pbr_if_new(ifp); | |
321 | } | |
322 | ||
e5c83d9b DS |
323 | if (no) { |
324 | if (strcmp(pbr_ifp->mapname, mapname) == 0) { | |
5f504f14 | 325 | pbr_ifp->mapname[0] = '\0'; |
e5c83d9b DS |
326 | if (pbrm) |
327 | pbr_map_interface_delete(pbrm, ifp); | |
328 | } | |
329 | } else { | |
5f504f14 QY |
330 | if (strcmp(pbr_ifp->mapname, "") != 0) { |
331 | old_pbrm = pbrm_find(pbr_ifp->mapname); | |
332 | if (old_pbrm) | |
333 | pbr_map_interface_delete(old_pbrm, ifp); | |
e5c83d9b | 334 | } |
5f504f14 QY |
335 | snprintf(pbr_ifp->mapname, sizeof(pbr_ifp->mapname), |
336 | "%s", mapname); | |
337 | if (pbrm) | |
338 | pbr_map_add_interface(pbrm, ifp); | |
e5c83d9b DS |
339 | } |
340 | ||
341 | return CMD_SUCCESS; | |
342 | } | |
343 | ||
344 | DEFPY (show_pbr, | |
345 | show_pbr_cmd, | |
346 | "show pbr [json$json]", | |
347 | SHOW_STR | |
348 | "Policy Based Routing\n" | |
349 | JSON_STR) | |
350 | { | |
351 | pbr_nht_write_table_range(vty); | |
352 | pbr_nht_write_rule_range(vty); | |
353 | ||
354 | return CMD_SUCCESS; | |
355 | } | |
356 | ||
357 | DEFPY (show_pbr_map, | |
358 | show_pbr_map_cmd, | |
359 | "show pbr map [NAME$name] [detail$detail] [json$json]", | |
360 | SHOW_STR | |
361 | "Policy Based Routing\n" | |
362 | "PBR Map\n" | |
363 | "PBR Map Name\n" | |
364 | "Detailed information\n" | |
365 | JSON_STR) | |
366 | { | |
367 | struct pbr_map_sequence *pbrms; | |
368 | struct pbr_map *pbrm; | |
369 | struct listnode *node; | |
370 | char buf[PREFIX_STRLEN]; | |
371 | char rbuf[64]; | |
372 | ||
373 | RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) { | |
374 | if (name && strcmp(name, pbrm->name) != 0) | |
375 | continue; | |
376 | ||
377 | vty_out(vty, " pbr-map %s valid: %d\n", pbrm->name, | |
378 | pbrm->valid); | |
379 | ||
380 | for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) { | |
381 | if (pbrms->reason) | |
382 | pbr_map_reason_string(pbrms->reason, rbuf, | |
383 | sizeof(rbuf)); | |
384 | vty_out(vty, | |
385 | " Seq: %u rule: %u Installed: %d(%u) Reason: %s\n", | |
386 | pbrms->seqno, pbrms->ruleno, pbrms->installed, | |
387 | pbrms->unique, pbrms->reason ? rbuf : "Valid"); | |
388 | ||
389 | if (pbrms->src) | |
390 | vty_out(vty, "\tSRC Match: %s\n", | |
391 | prefix2str(pbrms->src, buf, | |
392 | sizeof(buf))); | |
393 | if (pbrms->dst) | |
394 | vty_out(vty, "\tDST Match: %s\n", | |
395 | prefix2str(pbrms->dst, buf, | |
396 | sizeof(buf))); | |
397 | ||
398 | if (pbrms->nhgrp_name) { | |
399 | vty_out(vty, | |
400 | "\tNexthop-Group: %s(%u) Installed: %u(%d)\n", | |
401 | pbrms->nhgrp_name, | |
402 | pbr_nht_get_table(pbrms->nhgrp_name), | |
403 | pbrms->nhs_installed, | |
404 | pbr_nht_get_installed( | |
405 | pbrms->nhgrp_name)); | |
406 | } else if (pbrms->nhg) { | |
407 | vty_out(vty, " "); | |
408 | nexthop_group_write_nexthop( | |
409 | vty, pbrms->nhg->nexthop); | |
410 | vty_out(vty, | |
411 | "\tInstalled: %u(%d) Tableid: %d\n", | |
412 | pbrms->nhs_installed, | |
413 | pbr_nht_get_installed( | |
414 | pbrms->internal_nhg_name), | |
415 | pbr_nht_get_table( | |
416 | pbrms->internal_nhg_name)); | |
417 | } else { | |
418 | vty_out(vty, | |
419 | "\tNexthop-Group: Unknown Installed: 0(0)\n"); | |
420 | } | |
421 | } | |
422 | } | |
423 | return CMD_SUCCESS; | |
424 | } | |
425 | ||
426 | DEFPY(show_pbr_nexthop_group, | |
427 | show_pbr_nexthop_group_cmd, | |
428 | "show pbr nexthop-groups [WORD$word]", | |
429 | SHOW_STR | |
430 | "Policy Based Routing\n" | |
431 | "Nexthop Groups\n" | |
432 | "Optional Name of the nexthop group\n") | |
433 | { | |
434 | pbr_nht_show_nexthop_group(vty, word); | |
435 | ||
436 | return CMD_SUCCESS; | |
437 | } | |
438 | ||
439 | DEFPY (show_pbr_interface, | |
440 | show_pbr_interface_cmd, | |
441 | "show pbr interface [NAME$name] [json$json]", | |
442 | SHOW_STR | |
443 | "Policy Based Routing\n" | |
444 | "PBR Interface\n" | |
445 | "PBR Interface Name\n" | |
446 | JSON_STR) | |
447 | { | |
d3765386 | 448 | struct interface *ifp; |
e5c83d9b DS |
449 | struct vrf *vrf; |
450 | struct pbr_interface *pbr_ifp; | |
451 | ||
452 | RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { | |
453 | FOR_ALL_INTERFACES(vrf, ifp) { | |
454 | struct pbr_map *pbrm; | |
455 | ||
1c33fb1d DS |
456 | if (!ifp->info) |
457 | continue; | |
458 | ||
e5c83d9b DS |
459 | if (name && strcmp(ifp->name, name) != 0) |
460 | continue; | |
461 | ||
462 | pbr_ifp = ifp->info; | |
463 | ||
464 | if (strcmp(pbr_ifp->mapname, "") == 0) | |
465 | continue; | |
466 | ||
467 | pbrm = pbrm_find(pbr_ifp->mapname); | |
468 | vty_out(vty, " %s(%d) with pbr-policy %s", ifp->name, | |
469 | ifp->ifindex, pbr_ifp->mapname); | |
470 | if (!pbrm) | |
471 | vty_out(vty, " (map doesn't exist)"); | |
472 | vty_out(vty, "\n"); | |
473 | } | |
474 | } | |
475 | ||
476 | return CMD_SUCCESS; | |
477 | } | |
478 | ||
479 | static struct cmd_node interface_node = { | |
480 | INTERFACE_NODE, "%s(config-if)# ", 1 /* vtysh ? yes */ | |
481 | }; | |
482 | ||
483 | static int pbr_interface_config_write(struct vty *vty) | |
484 | { | |
485 | struct interface *ifp; | |
486 | struct vrf *vrf; | |
487 | ||
488 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
489 | FOR_ALL_INTERFACES (vrf, ifp) { | |
490 | if (vrf->vrf_id == VRF_DEFAULT) | |
491 | vty_frame(vty, "interface %s\n", ifp->name); | |
492 | else | |
493 | vty_frame(vty, "interface %s vrf %s\n", | |
494 | ifp->name, vrf->name); | |
495 | ||
496 | pbr_map_write_interfaces(vty, ifp); | |
497 | ||
498 | vty_endframe(vty, "!\n"); | |
499 | } | |
500 | } | |
501 | ||
502 | return 1; | |
503 | } | |
504 | ||
505 | /* PBR map node structure. */ | |
506 | static struct cmd_node pbr_map_node = {PBRMAP_NODE, "%s(config-pbr-map)# ", 1}; | |
507 | ||
508 | static int pbr_vty_map_config_write_sequence(struct vty *vty, | |
509 | struct pbr_map *pbrm, | |
510 | struct pbr_map_sequence *pbrms) | |
511 | { | |
512 | char buff[PREFIX_STRLEN]; | |
513 | ||
5e44f18f | 514 | vty_out(vty, "pbr-map %s seq %u\n", pbrm->name, pbrms->seqno); |
e5c83d9b DS |
515 | |
516 | if (pbrms->src) | |
517 | vty_out(vty, " match src-ip %s\n", | |
d3765386 | 518 | prefix2str(pbrms->src, buff, sizeof(buff))); |
e5c83d9b DS |
519 | |
520 | if (pbrms->dst) | |
521 | vty_out(vty, " match dst-ip %s\n", | |
d3765386 | 522 | prefix2str(pbrms->dst, buff, sizeof(buff))); |
e5c83d9b DS |
523 | |
524 | if (pbrms->nhgrp_name) | |
525 | vty_out(vty, " set nexthop-group %s\n", pbrms->nhgrp_name); | |
526 | ||
527 | if (pbrms->nhg) { | |
57cdafc4 | 528 | vty_out(vty, " set "); |
e5c83d9b DS |
529 | nexthop_group_write_nexthop(vty, pbrms->nhg->nexthop); |
530 | } | |
531 | ||
5e44f18f | 532 | vty_out(vty, "!\n"); |
e5c83d9b DS |
533 | return 1; |
534 | } | |
535 | ||
536 | static int pbr_vty_map_config_write(struct vty *vty) | |
537 | { | |
538 | struct pbr_map *pbrm; | |
539 | ||
540 | pbr_nht_write_table_range(vty); | |
541 | pbr_nht_write_rule_range(vty); | |
542 | ||
543 | RB_FOREACH(pbrm, pbr_map_entry_head, &pbr_maps) { | |
544 | struct pbr_map_sequence *pbrms; | |
545 | struct listnode *node; | |
546 | ||
d3765386 | 547 | for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) |
e5c83d9b | 548 | pbr_vty_map_config_write_sequence(vty, pbrm, pbrms); |
e5c83d9b DS |
549 | } |
550 | ||
551 | return 1; | |
552 | } | |
553 | ||
554 | void pbr_vty_init(void) | |
555 | { | |
556 | install_node(&interface_node, | |
557 | pbr_interface_config_write); | |
558 | if_cmd_init(); | |
559 | ||
560 | install_node(&pbr_map_node, | |
561 | pbr_vty_map_config_write); | |
562 | ||
563 | install_default(PBRMAP_NODE); | |
564 | ||
565 | install_element(CONFIG_NODE, &pbr_map_cmd); | |
566 | install_element(CONFIG_NODE, &no_pbr_map_cmd); | |
567 | install_element(INTERFACE_NODE, &pbr_policy_cmd); | |
e5c83d9b DS |
568 | install_element(PBRMAP_NODE, &pbr_map_match_src_cmd); |
569 | install_element(PBRMAP_NODE, &pbr_map_match_dst_cmd); | |
570 | install_element(PBRMAP_NODE, &pbr_map_nexthop_group_cmd); | |
571 | install_element(PBRMAP_NODE, &pbr_map_nexthop_cmd); | |
572 | install_element(VIEW_NODE, &show_pbr_cmd); | |
573 | install_element(VIEW_NODE, &show_pbr_map_cmd); | |
574 | install_element(VIEW_NODE, &show_pbr_interface_cmd); | |
575 | install_element(VIEW_NODE, &show_pbr_nexthop_group_cmd); | |
576 | ||
577 | pbr_debug_init_vty(); | |
e5c83d9b | 578 | } |