]>
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" | |
e5c83d9b | 29 | #include "debug.h" |
8c28c034 | 30 | #include "pbr.h" |
e5c83d9b DS |
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 | ||
9a55f79a | 41 | DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map WORD seq (1-700)", |
e5c83d9b DS |
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 | ||
9a55f79a | 57 | DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map WORD [seq (1-700)]", |
e5c83d9b DS |
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 | ||
7bec514c QY |
88 | DEFPY(pbr_set_table_range, |
89 | pbr_set_table_range_cmd, | |
90 | "[no] pbr table range (10000-4294966272)$lb (10000-4294966272)$ub", | |
91 | NO_STR | |
92 | PBR_STR | |
93 | "Set table ID range\n" | |
94 | "Set table ID range\n" | |
95 | "Lower bound for table ID range\n" | |
96 | "Upper bound for table ID range\n") | |
97 | { | |
98 | /* upper bound is 2^32 - 2^10 */ | |
99 | int ret = CMD_WARNING; | |
a4044dc1 | 100 | const int minrange = 1000; |
7bec514c QY |
101 | |
102 | /* validate given bounds */ | |
103 | if (lb > ub) | |
104 | vty_out(vty, "%% Lower bound must be less than upper bound\n"); | |
a4044dc1 QY |
105 | else if (ub - lb < minrange) |
106 | vty_out(vty, "%% Range breadth must be at least %d\n", minrange); | |
7bec514c QY |
107 | else { |
108 | ret = CMD_SUCCESS; | |
109 | pbr_nht_set_tableid_range((uint32_t) lb, (uint32_t) ub); | |
110 | } | |
111 | ||
112 | return ret; | |
113 | } | |
114 | ||
115 | ||
e5c83d9b DS |
116 | DEFPY(pbr_map_match_src, pbr_map_match_src_cmd, |
117 | "[no] match src-ip <A.B.C.D/M|X:X::X:X/M>$prefix", | |
118 | NO_STR | |
119 | "Match the rest of the command\n" | |
120 | "Choose the src ip or ipv6 prefix to use\n" | |
121 | "v4 Prefix\n" | |
122 | "v6 Prefix\n") | |
123 | { | |
124 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
e5c83d9b | 125 | |
49027ce8 DS |
126 | pbrms->family = prefix->family; |
127 | ||
e5c83d9b | 128 | if (!no) { |
b8eb036f DS |
129 | if (prefix_same(pbrms->src, prefix)) |
130 | return CMD_SUCCESS; | |
131 | ||
e5c83d9b DS |
132 | if (!pbrms->src) |
133 | pbrms->src = prefix_new(); | |
134 | prefix_copy(pbrms->src, prefix); | |
135 | } else { | |
136 | prefix_free(pbrms->src); | |
137 | pbrms->src = 0; | |
138 | } | |
139 | ||
b13e5ad6 | 140 | pbr_map_check(pbrms); |
e5c83d9b DS |
141 | |
142 | return CMD_SUCCESS; | |
143 | } | |
144 | ||
145 | DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd, | |
146 | "[no] match dst-ip <A.B.C.D/M|X:X::X:X/M>$prefix", | |
147 | NO_STR | |
148 | "Match the rest of the command\n" | |
149 | "Choose the src ip or ipv6 prefix to use\n" | |
150 | "v4 Prefix\n" | |
151 | "v6 Prefix\n") | |
152 | { | |
153 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
e5c83d9b | 154 | |
49027ce8 DS |
155 | pbrms->family = prefix->family; |
156 | ||
e5c83d9b | 157 | if (!no) { |
b8eb036f DS |
158 | if (prefix_same(pbrms->dst, prefix)) |
159 | return CMD_SUCCESS; | |
160 | ||
e5c83d9b DS |
161 | if (!pbrms->dst) |
162 | pbrms->dst = prefix_new(); | |
163 | prefix_copy(pbrms->dst, prefix); | |
164 | } else { | |
165 | prefix_free(pbrms->dst); | |
b13e5ad6 | 166 | pbrms->dst = NULL; |
e5c83d9b DS |
167 | } |
168 | ||
b13e5ad6 | 169 | pbr_map_check(pbrms); |
e5c83d9b DS |
170 | |
171 | return CMD_SUCCESS; | |
172 | } | |
173 | ||
174 | DEFPY(pbr_map_nexthop_group, pbr_map_nexthop_group_cmd, | |
175 | "[no] set nexthop-group NAME$name", | |
176 | NO_STR | |
177 | "Set for the PBR-MAP\n" | |
178 | "nexthop-group to use\n" | |
179 | "The name of the nexthop-group\n") | |
180 | { | |
181 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
182 | struct nexthop_group_cmd *nhgc; | |
e5c83d9b | 183 | |
e042a421 DS |
184 | if (pbrms->nhg) { |
185 | vty_out(vty, | |
186 | "A `set nexthop XX` command already exists, please remove that first\n"); | |
3a9210c2 | 187 | return CMD_WARNING_CONFIG_FAILED; |
e042a421 DS |
188 | } |
189 | ||
e5c83d9b DS |
190 | nhgc = nhgc_find(name); |
191 | if (!nhgc) { | |
192 | vty_out(vty, "Specified nexthop-group %s does not exist\n", | |
193 | name); | |
194 | vty_out(vty, "PBR-MAP will not be applied until it is created\n"); | |
195 | } | |
196 | ||
197 | if (no) { | |
198 | if (pbrms->nhgrp_name && strcmp(name, pbrms->nhgrp_name) == 0) | |
b13e5ad6 | 199 | pbr_map_delete_nexthop_group(pbrms); |
e5c83d9b DS |
200 | else { |
201 | vty_out(vty, | |
202 | "Nexthop Group specified: %s does not exist to remove", | |
203 | name); | |
3a9210c2 | 204 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
205 | } |
206 | } else { | |
207 | if (pbrms->nhgrp_name) { | |
208 | if (strcmp(name, pbrms->nhgrp_name) != 0) { | |
209 | vty_out(vty, | |
210 | "Please delete current nexthop group before modifying current one"); | |
3a9210c2 | 211 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
212 | } |
213 | ||
214 | return CMD_SUCCESS; | |
215 | } | |
216 | pbrms->nhgrp_name = XSTRDUP(MTYPE_TMP, name); | |
b13e5ad6 | 217 | pbr_map_check(pbrms); |
e5c83d9b DS |
218 | } |
219 | ||
e5c83d9b DS |
220 | return CMD_SUCCESS; |
221 | } | |
222 | ||
223 | DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd, | |
224 | "[no] set nexthop <A.B.C.D|X:X::X:X>$addr [INTERFACE]$intf [nexthop-vrf NAME$name]", | |
225 | NO_STR | |
226 | "Set for the PBR-MAP\n" | |
227 | "Specify one of the nexthops in this map\n" | |
228 | "v4 Address\n" | |
229 | "v6 Address\n" | |
230 | "Interface to use\n" | |
231 | "If the nexthop is in a different vrf tell us\n" | |
232 | "The nexthop-vrf Name\n") | |
233 | { | |
234 | struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); | |
235 | struct vrf *vrf; | |
236 | struct nexthop nhop; | |
237 | struct nexthop *nh; | |
e5c83d9b DS |
238 | |
239 | if (pbrms->nhgrp_name) { | |
240 | vty_out(vty, | |
241 | "Please unconfigure the nexthop group before adding an individual nexthop"); | |
3a9210c2 | 242 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
243 | } |
244 | ||
245 | if (name) | |
246 | vrf = vrf_lookup_by_name(name); | |
247 | else | |
248 | vrf = vrf_lookup_by_id(VRF_DEFAULT); | |
249 | ||
250 | if (!vrf) { | |
251 | vty_out(vty, "Specified: %s is non-existent\n", name); | |
3a9210c2 | 252 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
253 | } |
254 | ||
255 | memset(&nhop, 0, sizeof(nhop)); | |
256 | nhop.vrf_id = vrf->vrf_id; | |
257 | ||
10a00758 DS |
258 | /* |
259 | * Make SA happy. CLIPPY is not going to give us a NULL | |
260 | * addr. | |
261 | */ | |
262 | assert(addr); | |
e5c83d9b DS |
263 | if (addr->sa.sa_family == AF_INET) { |
264 | nhop.gate.ipv4.s_addr = addr->sin.sin_addr.s_addr; | |
265 | if (intf) { | |
266 | nhop.type = NEXTHOP_TYPE_IPV4_IFINDEX; | |
267 | nhop.ifindex = ifname2ifindex(intf, vrf->vrf_id); | |
268 | if (nhop.ifindex == IFINDEX_INTERNAL) { | |
269 | vty_out(vty, | |
270 | "Specified Intf %s does not exist in vrf: %s\n", | |
271 | intf, vrf->name); | |
3a9210c2 | 272 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
273 | } |
274 | } else | |
275 | nhop.type = NEXTHOP_TYPE_IPV4; | |
276 | } else { | |
277 | memcpy(&nhop.gate.ipv6, &addr->sin6.sin6_addr, 16); | |
278 | if (intf) { | |
279 | nhop.type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
280 | nhop.ifindex = ifname2ifindex(intf, vrf->vrf_id); | |
281 | if (nhop.ifindex == IFINDEX_INTERNAL) { | |
282 | vty_out(vty, | |
283 | "Specified Intf %s does not exist in vrf: %s\n", | |
284 | intf, vrf->name); | |
3a9210c2 | 285 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b | 286 | } |
cafec8da DS |
287 | } else { |
288 | if (IN6_IS_ADDR_LINKLOCAL(&nhop.gate.ipv6)) { | |
289 | vty_out(vty, | |
290 | "Specified a v6 LL with no interface, rejecting\n"); | |
291 | return CMD_WARNING_CONFIG_FAILED; | |
292 | } | |
e5c83d9b | 293 | nhop.type = NEXTHOP_TYPE_IPV6; |
cafec8da | 294 | } |
e5c83d9b DS |
295 | } |
296 | ||
297 | if (pbrms->nhg) | |
298 | nh = nexthop_exists(pbrms->nhg, &nhop); | |
299 | else { | |
06210d1f | 300 | char buf[PBR_NHC_NAMELEN]; |
e5c83d9b DS |
301 | |
302 | if (no) { | |
220c5830 | 303 | vty_out(vty, "No nexthops to delete\n"); |
3a9210c2 | 304 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
305 | } |
306 | ||
307 | pbrms->nhg = nexthop_group_new(); | |
308 | pbrms->internal_nhg_name = | |
309 | XSTRDUP(MTYPE_TMP, | |
310 | pbr_nht_nexthop_make_name(pbrms->parent->name, | |
06210d1f | 311 | PBR_NHC_NAMELEN, |
e5c83d9b DS |
312 | pbrms->seqno, |
313 | buf)); | |
314 | nh = NULL; | |
315 | } | |
316 | ||
317 | if (no) { | |
b13e5ad6 DS |
318 | if (nh) |
319 | pbr_nht_delete_individual_nexthop(pbrms); | |
e5c83d9b DS |
320 | } else if (!nh) { |
321 | ||
322 | if (pbrms->nhg->nexthop) { | |
323 | vty_out(vty, | |
324 | "If you would like more than one nexthop please use nexthop-groups"); | |
3a9210c2 | 325 | return CMD_WARNING_CONFIG_FAILED; |
e5c83d9b DS |
326 | } |
327 | ||
328 | /* must be adding new nexthop since !no and !nexthop_exists */ | |
329 | nh = nexthop_new(); | |
330 | ||
331 | memcpy(nh, &nhop, sizeof(nhop)); | |
332 | nexthop_add(&pbrms->nhg->nexthop, nh); | |
333 | ||
b13e5ad6 DS |
334 | pbr_nht_add_individual_nexthop(pbrms); |
335 | pbr_map_check(pbrms); | |
e5c83d9b DS |
336 | } |
337 | ||
338 | return CMD_SUCCESS; | |
339 | } | |
340 | ||
e5c83d9b DS |
341 | DEFPY (pbr_policy, |
342 | pbr_policy_cmd, | |
343 | "[no] pbr-policy NAME$mapname", | |
344 | NO_STR | |
345 | "Policy to use\n" | |
346 | "Name of the pbr-map to apply\n") | |
347 | { | |
348 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
349 | struct pbr_map *pbrm, *old_pbrm; | |
350 | struct pbr_interface *pbr_ifp = ifp->info; | |
351 | ||
6eb499b0 | 352 | old_pbrm = NULL; |
e5c83d9b DS |
353 | pbrm = pbrm_find(mapname); |
354 | ||
b13e5ad6 | 355 | if (!pbr_ifp) { |
d6416967 QY |
356 | /* we don't want one and we don't have one, so... */ |
357 | if (no) | |
358 | return CMD_SUCCESS; | |
359 | ||
360 | /* Some one could have fat fingered the interface name */ | |
b13e5ad6 DS |
361 | pbr_ifp = pbr_if_new(ifp); |
362 | } | |
363 | ||
e5c83d9b DS |
364 | if (no) { |
365 | if (strcmp(pbr_ifp->mapname, mapname) == 0) { | |
5f504f14 | 366 | pbr_ifp->mapname[0] = '\0'; |
e5c83d9b DS |
367 | if (pbrm) |
368 | pbr_map_interface_delete(pbrm, ifp); | |
369 | } | |
370 | } else { | |
5f504f14 QY |
371 | if (strcmp(pbr_ifp->mapname, "") != 0) { |
372 | old_pbrm = pbrm_find(pbr_ifp->mapname); | |
6eb499b0 DS |
373 | |
374 | /* | |
375 | * So if we have an old pbrm we should only | |
376 | * delete it if we are actually deleting and | |
377 | * moving to a new pbrm | |
378 | */ | |
379 | if (old_pbrm && old_pbrm != pbrm) | |
5f504f14 | 380 | pbr_map_interface_delete(old_pbrm, ifp); |
e5c83d9b | 381 | } |
5f504f14 QY |
382 | snprintf(pbr_ifp->mapname, sizeof(pbr_ifp->mapname), |
383 | "%s", mapname); | |
6eb499b0 DS |
384 | |
385 | /* | |
386 | * So only reinstall if the old_pbrm and this pbrm are | |
387 | * different. | |
388 | */ | |
389 | if (pbrm && pbrm != old_pbrm) | |
5f504f14 | 390 | pbr_map_add_interface(pbrm, ifp); |
e5c83d9b DS |
391 | } |
392 | ||
393 | return CMD_SUCCESS; | |
394 | } | |
395 | ||
396 | DEFPY (show_pbr, | |
397 | show_pbr_cmd, | |
ef18ed6e | 398 | "show pbr", |
e5c83d9b | 399 | SHOW_STR |
24a21176 | 400 | PBR_STR) |
e5c83d9b DS |
401 | { |
402 | pbr_nht_write_table_range(vty); | |
403 | pbr_nht_write_rule_range(vty); | |
404 | ||
405 | return CMD_SUCCESS; | |
406 | } | |
407 | ||
408 | DEFPY (show_pbr_map, | |
409 | show_pbr_map_cmd, | |
ef18ed6e | 410 | "show pbr map [NAME$name] [detail$detail]", |
e5c83d9b | 411 | SHOW_STR |
24a21176 | 412 | PBR_STR |
e5c83d9b DS |
413 | "PBR Map\n" |
414 | "PBR Map Name\n" | |
ef18ed6e | 415 | "Detailed information\n") |
e5c83d9b DS |
416 | { |
417 | struct pbr_map_sequence *pbrms; | |
418 | struct pbr_map *pbrm; | |
419 | struct listnode *node; | |
420 | char buf[PREFIX_STRLEN]; | |
421 | char rbuf[64]; | |
422 | ||
423 | RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) { | |
424 | if (name && strcmp(name, pbrm->name) != 0) | |
425 | continue; | |
426 | ||
427 | vty_out(vty, " pbr-map %s valid: %d\n", pbrm->name, | |
428 | pbrm->valid); | |
429 | ||
430 | for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) { | |
431 | if (pbrms->reason) | |
432 | pbr_map_reason_string(pbrms->reason, rbuf, | |
433 | sizeof(rbuf)); | |
434 | vty_out(vty, | |
37c606ff | 435 | " Seq: %u rule: %u Installed: %" PRIu64 "(%u) Reason: %s\n", |
e5c83d9b DS |
436 | pbrms->seqno, pbrms->ruleno, pbrms->installed, |
437 | pbrms->unique, pbrms->reason ? rbuf : "Valid"); | |
438 | ||
439 | if (pbrms->src) | |
440 | vty_out(vty, "\tSRC Match: %s\n", | |
441 | prefix2str(pbrms->src, buf, | |
442 | sizeof(buf))); | |
443 | if (pbrms->dst) | |
444 | vty_out(vty, "\tDST Match: %s\n", | |
445 | prefix2str(pbrms->dst, buf, | |
446 | sizeof(buf))); | |
447 | ||
448 | if (pbrms->nhgrp_name) { | |
449 | vty_out(vty, | |
450 | "\tNexthop-Group: %s(%u) Installed: %u(%d)\n", | |
451 | pbrms->nhgrp_name, | |
452 | pbr_nht_get_table(pbrms->nhgrp_name), | |
453 | pbrms->nhs_installed, | |
454 | pbr_nht_get_installed( | |
455 | pbrms->nhgrp_name)); | |
456 | } else if (pbrms->nhg) { | |
457 | vty_out(vty, " "); | |
458 | nexthop_group_write_nexthop( | |
459 | vty, pbrms->nhg->nexthop); | |
460 | vty_out(vty, | |
461 | "\tInstalled: %u(%d) Tableid: %d\n", | |
462 | pbrms->nhs_installed, | |
463 | pbr_nht_get_installed( | |
464 | pbrms->internal_nhg_name), | |
465 | pbr_nht_get_table( | |
466 | pbrms->internal_nhg_name)); | |
467 | } else { | |
468 | vty_out(vty, | |
469 | "\tNexthop-Group: Unknown Installed: 0(0)\n"); | |
470 | } | |
471 | } | |
472 | } | |
473 | return CMD_SUCCESS; | |
474 | } | |
475 | ||
476 | DEFPY(show_pbr_nexthop_group, | |
477 | show_pbr_nexthop_group_cmd, | |
478 | "show pbr nexthop-groups [WORD$word]", | |
479 | SHOW_STR | |
24a21176 | 480 | PBR_STR |
e5c83d9b DS |
481 | "Nexthop Groups\n" |
482 | "Optional Name of the nexthop group\n") | |
483 | { | |
484 | pbr_nht_show_nexthop_group(vty, word); | |
485 | ||
486 | return CMD_SUCCESS; | |
487 | } | |
488 | ||
489 | DEFPY (show_pbr_interface, | |
490 | show_pbr_interface_cmd, | |
ef18ed6e | 491 | "show pbr interface [NAME$name]", |
e5c83d9b | 492 | SHOW_STR |
24a21176 | 493 | PBR_STR |
e5c83d9b | 494 | "PBR Interface\n" |
ef18ed6e | 495 | "PBR Interface Name\n") |
e5c83d9b | 496 | { |
d3765386 | 497 | struct interface *ifp; |
e5c83d9b DS |
498 | struct vrf *vrf; |
499 | struct pbr_interface *pbr_ifp; | |
500 | ||
501 | RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { | |
502 | FOR_ALL_INTERFACES(vrf, ifp) { | |
503 | struct pbr_map *pbrm; | |
504 | ||
1c33fb1d DS |
505 | if (!ifp->info) |
506 | continue; | |
507 | ||
e5c83d9b DS |
508 | if (name && strcmp(ifp->name, name) != 0) |
509 | continue; | |
510 | ||
511 | pbr_ifp = ifp->info; | |
512 | ||
513 | if (strcmp(pbr_ifp->mapname, "") == 0) | |
514 | continue; | |
515 | ||
516 | pbrm = pbrm_find(pbr_ifp->mapname); | |
517 | vty_out(vty, " %s(%d) with pbr-policy %s", ifp->name, | |
518 | ifp->ifindex, pbr_ifp->mapname); | |
519 | if (!pbrm) | |
520 | vty_out(vty, " (map doesn't exist)"); | |
521 | vty_out(vty, "\n"); | |
522 | } | |
523 | } | |
524 | ||
525 | return CMD_SUCCESS; | |
526 | } | |
527 | ||
e14f43cc | 528 | /* PBR debugging CLI ------------------------------------------------------- */ |
e14f43cc QY |
529 | |
530 | static struct cmd_node debug_node = {DEBUG_NODE, "", 1}; | |
531 | ||
532 | DEFPY(debug_pbr, | |
533 | debug_pbr_cmd, | |
534 | "[no] debug pbr [{map$map|zebra$zebra|nht$nht|events$events}]", | |
535 | NO_STR | |
536 | DEBUG_STR | |
24a21176 | 537 | PBR_STR |
e14f43cc QY |
538 | "Policy maps\n" |
539 | "PBRD <-> Zebra communications\n" | |
540 | "Nexthop tracking\n" | |
541 | "Events\n") | |
542 | { | |
543 | uint32_t mode = DEBUG_NODE2MODE(vty->node); | |
544 | ||
545 | if (map) | |
546 | DEBUG_MODE_SET(&pbr_dbg_map, mode, !no); | |
547 | if (zebra) | |
548 | DEBUG_MODE_SET(&pbr_dbg_zebra, mode, !no); | |
549 | if (nht) | |
550 | DEBUG_MODE_SET(&pbr_dbg_nht, mode, !no); | |
551 | if (events) | |
552 | DEBUG_MODE_SET(&pbr_dbg_event, mode, !no); | |
553 | ||
554 | /* no specific debug --> act on all of them */ | |
555 | if (strmatch(argv[argc - 1]->text, "pbr")) | |
556 | pbr_debug_set_all(mode, !no); | |
557 | ||
558 | return CMD_SUCCESS; | |
559 | } | |
560 | ||
561 | DEFUN_NOSH(show_debugging_pbr, | |
562 | show_debugging_pbr_cmd, | |
563 | "show debugging [pbr]", | |
564 | SHOW_STR | |
565 | DEBUG_STR | |
24a21176 | 566 | PBR_STR) |
e14f43cc QY |
567 | { |
568 | vty_out(vty, "PBR debugging status:\n"); | |
569 | ||
570 | pbr_debug_config_write_helper(vty, false); | |
571 | ||
572 | return CMD_SUCCESS; | |
573 | } | |
574 | ||
e14f43cc QY |
575 | /* ------------------------------------------------------------------------- */ |
576 | ||
577 | ||
e5c83d9b DS |
578 | static struct cmd_node interface_node = { |
579 | INTERFACE_NODE, "%s(config-if)# ", 1 /* vtysh ? yes */ | |
580 | }; | |
581 | ||
582 | static int pbr_interface_config_write(struct vty *vty) | |
583 | { | |
584 | struct interface *ifp; | |
585 | struct vrf *vrf; | |
586 | ||
587 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
588 | FOR_ALL_INTERFACES (vrf, ifp) { | |
589 | if (vrf->vrf_id == VRF_DEFAULT) | |
590 | vty_frame(vty, "interface %s\n", ifp->name); | |
591 | else | |
592 | vty_frame(vty, "interface %s vrf %s\n", | |
593 | ifp->name, vrf->name); | |
594 | ||
91e5b43a RW |
595 | if (ifp->desc) |
596 | vty_out(vty, " description %s\n", ifp->desc); | |
597 | ||
e5c83d9b DS |
598 | pbr_map_write_interfaces(vty, ifp); |
599 | ||
600 | vty_endframe(vty, "!\n"); | |
601 | } | |
602 | } | |
603 | ||
604 | return 1; | |
605 | } | |
606 | ||
607 | /* PBR map node structure. */ | |
608 | static struct cmd_node pbr_map_node = {PBRMAP_NODE, "%s(config-pbr-map)# ", 1}; | |
609 | ||
610 | static int pbr_vty_map_config_write_sequence(struct vty *vty, | |
611 | struct pbr_map *pbrm, | |
612 | struct pbr_map_sequence *pbrms) | |
613 | { | |
614 | char buff[PREFIX_STRLEN]; | |
615 | ||
5e44f18f | 616 | vty_out(vty, "pbr-map %s seq %u\n", pbrm->name, pbrms->seqno); |
e5c83d9b DS |
617 | |
618 | if (pbrms->src) | |
619 | vty_out(vty, " match src-ip %s\n", | |
d3765386 | 620 | prefix2str(pbrms->src, buff, sizeof(buff))); |
e5c83d9b DS |
621 | |
622 | if (pbrms->dst) | |
623 | vty_out(vty, " match dst-ip %s\n", | |
d3765386 | 624 | prefix2str(pbrms->dst, buff, sizeof(buff))); |
e5c83d9b DS |
625 | |
626 | if (pbrms->nhgrp_name) | |
627 | vty_out(vty, " set nexthop-group %s\n", pbrms->nhgrp_name); | |
628 | ||
629 | if (pbrms->nhg) { | |
57cdafc4 | 630 | vty_out(vty, " set "); |
e5c83d9b DS |
631 | nexthop_group_write_nexthop(vty, pbrms->nhg->nexthop); |
632 | } | |
633 | ||
5e44f18f | 634 | vty_out(vty, "!\n"); |
e5c83d9b DS |
635 | return 1; |
636 | } | |
637 | ||
638 | static int pbr_vty_map_config_write(struct vty *vty) | |
639 | { | |
640 | struct pbr_map *pbrm; | |
641 | ||
642 | pbr_nht_write_table_range(vty); | |
643 | pbr_nht_write_rule_range(vty); | |
644 | ||
645 | RB_FOREACH(pbrm, pbr_map_entry_head, &pbr_maps) { | |
646 | struct pbr_map_sequence *pbrms; | |
647 | struct listnode *node; | |
648 | ||
d3765386 | 649 | for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) |
e5c83d9b | 650 | pbr_vty_map_config_write_sequence(vty, pbrm, pbrms); |
e5c83d9b DS |
651 | } |
652 | ||
653 | return 1; | |
654 | } | |
655 | ||
656 | void pbr_vty_init(void) | |
657 | { | |
658 | install_node(&interface_node, | |
659 | pbr_interface_config_write); | |
660 | if_cmd_init(); | |
661 | ||
662 | install_node(&pbr_map_node, | |
663 | pbr_vty_map_config_write); | |
664 | ||
e14f43cc QY |
665 | /* debug */ |
666 | install_node(&debug_node, pbr_debug_config_write); | |
667 | install_element(VIEW_NODE, &debug_pbr_cmd); | |
668 | install_element(CONFIG_NODE, &debug_pbr_cmd); | |
669 | install_element(VIEW_NODE, &show_debugging_pbr_cmd); | |
670 | ||
e5c83d9b DS |
671 | install_default(PBRMAP_NODE); |
672 | ||
673 | install_element(CONFIG_NODE, &pbr_map_cmd); | |
674 | install_element(CONFIG_NODE, &no_pbr_map_cmd); | |
7bec514c | 675 | install_element(CONFIG_NODE, &pbr_set_table_range_cmd); |
e5c83d9b | 676 | install_element(INTERFACE_NODE, &pbr_policy_cmd); |
e5c83d9b DS |
677 | install_element(PBRMAP_NODE, &pbr_map_match_src_cmd); |
678 | install_element(PBRMAP_NODE, &pbr_map_match_dst_cmd); | |
679 | install_element(PBRMAP_NODE, &pbr_map_nexthop_group_cmd); | |
680 | install_element(PBRMAP_NODE, &pbr_map_nexthop_cmd); | |
681 | install_element(VIEW_NODE, &show_pbr_cmd); | |
682 | install_element(VIEW_NODE, &show_pbr_map_cmd); | |
683 | install_element(VIEW_NODE, &show_pbr_interface_cmd); | |
684 | install_element(VIEW_NODE, &show_pbr_nexthop_group_cmd); | |
e5c83d9b | 685 | } |