]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
Merge pull request #3908 from Tuetuopay/fix-unnumbered-no-ip
[mirror_frr.git] / sharpd / sharp_vty.c
1 /*
2 * SHARP - vty code
3 * Copyright (C) Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include <zebra.h>
23
24 #include "vty.h"
25 #include "command.h"
26 #include "prefix.h"
27 #include "nexthop.h"
28 #include "log.h"
29 #include "vrf.h"
30 #include "zclient.h"
31 #include "nexthop_group.h"
32
33 #include "sharpd/sharp_globals.h"
34 #include "sharpd/sharp_zebra.h"
35 #include "sharpd/sharp_nht.h"
36 #include "sharpd/sharp_vty.h"
37 #ifndef VTYSH_EXTRACT_PL
38 #include "sharpd/sharp_vty_clippy.c"
39 #endif
40
41 DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
42 "sharp watch [vrf NAME$name] <nexthop$n|import$import> X:X::X:X$nhop [connected$connected]",
43 "Sharp routing Protocol\n"
44 "Watch for changes\n"
45 "The vrf we would like to watch if non-default\n"
46 "The NAME of the vrf\n"
47 "Watch for nexthop changes\n"
48 "Watch for import check changes\n"
49 "The v6 nexthop to signal for watching\n"
50 "Should the route be connected\n")
51 {
52 struct vrf *vrf;
53 struct prefix p;
54 bool type_import;
55
56 if (!name)
57 name = VRF_DEFAULT_NAME;
58 vrf = vrf_lookup_by_name(name);
59 if (!vrf) {
60 vty_out(vty, "The vrf NAME specified: %s does not exist\n",
61 name);
62 return CMD_WARNING;
63 }
64
65 if (n)
66 type_import = false;
67 else
68 type_import = true;
69
70 memset(&p, 0, sizeof(p));
71
72 p.prefixlen = 128;
73 memcpy(&p.u.prefix6, &nhop, 16);
74 p.family = AF_INET6;
75
76 sharp_nh_tracker_get(&p);
77 sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import,
78 true, !!connected);
79
80 return CMD_SUCCESS;
81 }
82
83 DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
84 "sharp watch [vrf NAME$name] <nexthop$n|import$import> A.B.C.D$nhop [connected$connected]",
85 "Sharp routing Protocol\n"
86 "Watch for changes\n"
87 "The vrf we would like to watch if non-default\n"
88 "The NAME of the vrf\n"
89 "Watch for nexthop changes\n"
90 "Watch for import check changes\n"
91 "The v4 nexthop to signal for watching\n"
92 "Should the route be connected\n")
93 {
94 struct vrf *vrf;
95 struct prefix p;
96 bool type_import;
97
98 if (!name)
99 name = VRF_DEFAULT_NAME;
100 vrf = vrf_lookup_by_name(name);
101 if (!vrf) {
102 vty_out(vty, "The vrf NAME specified: %s does not exist\n",
103 name);
104 return CMD_WARNING;
105 }
106
107 memset(&p, 0, sizeof(p));
108
109 if (n)
110 type_import = false;
111 else
112 type_import = true;
113
114 p.prefixlen = 32;
115 p.u.prefix4 = nhop;
116 p.family = AF_INET;
117
118 sharp_nh_tracker_get(&p);
119 sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import,
120 true, !!connected);
121
122 return CMD_SUCCESS;
123 }
124
125 DEFPY(sharp_nht_data_dump,
126 sharp_nht_data_dump_cmd,
127 "sharp data nexthop",
128 "Sharp routing Protocol\n"
129 "Nexthop information\n"
130 "Data Dump\n")
131 {
132 sharp_nh_tracker_dump(vty);
133
134 return CMD_SUCCESS;
135 }
136
137 DEFPY (install_routes_data_dump,
138 install_routes_data_dump_cmd,
139 "sharp data route",
140 "Sharp routing Protocol\n"
141 "Data about what is going on\n"
142 "Route Install/Removal Information\n")
143 {
144 char buf[PREFIX_STRLEN];
145 struct timeval r;
146
147 timersub(&sg.r.t_end, &sg.r.t_start, &r);
148 vty_out(vty, "Prefix: %s Total: %u %u %u Time: %ld.%ld\n",
149 prefix2str(&sg.r.orig_prefix, buf, sizeof(buf)),
150 sg.r.total_routes,
151 sg.r.installed_routes,
152 sg.r.removed_routes,
153 r.tv_sec, r.tv_usec);
154
155 return CMD_SUCCESS;
156 }
157
158 DEFPY (install_routes,
159 install_routes_cmd,
160 "sharp install routes [vrf NAME$name] <A.B.C.D$start4|X:X::X:X$start6> <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]",
161 "Sharp routing Protocol\n"
162 "install some routes\n"
163 "Routes to install\n"
164 "The vrf we would like to install into if non-default\n"
165 "The NAME of the vrf\n"
166 "v4 Address to start /32 generation at\n"
167 "v6 Address to start /32 generation at\n"
168 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
169 "V4 Nexthop address to use\n"
170 "V6 Nexthop address to use\n"
171 "Nexthop-Group to use\n"
172 "The Name of the nexthop-group\n"
173 "How many to create\n"
174 "Instance to use\n"
175 "Instance\n"
176 "Should we repeat this command\n"
177 "How many times to repeat this command\n")
178 {
179 struct vrf *vrf;
180 struct prefix prefix;
181 uint32_t rts;
182
183 sg.r.total_routes = routes;
184 sg.r.installed_routes = 0;
185
186 if (rpt >= 2)
187 sg.r.repeat = rpt * 2;
188 else
189 sg.r.repeat = 0;
190
191 memset(&prefix, 0, sizeof(prefix));
192 memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
193 memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
194 memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
195
196 if (start4.s_addr != 0) {
197 prefix.family = AF_INET;
198 prefix.prefixlen = 32;
199 prefix.u.prefix4 = start4;
200 } else {
201 prefix.family = AF_INET6;
202 prefix.prefixlen = 128;
203 prefix.u.prefix6 = start6;
204 }
205 sg.r.orig_prefix = prefix;
206
207 if (!name)
208 name = VRF_DEFAULT_NAME;
209
210 vrf = vrf_lookup_by_name(name);
211 if (!vrf) {
212 vty_out(vty, "The vrf NAME specified: %s does not exist\n",
213 name);
214 return CMD_WARNING;
215 }
216
217 if (nexthop_group) {
218 struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
219 if (!nhgc) {
220 vty_out(vty,
221 "Specified Nexthop Group: %s does not exist\n",
222 nexthop_group);
223 return CMD_WARNING;
224 }
225
226 sg.r.nhop_group.nexthop = nhgc->nhg.nexthop;
227 } else {
228 if (nexthop4.s_addr != INADDR_ANY) {
229 sg.r.nhop.gate.ipv4 = nexthop4;
230 sg.r.nhop.type = NEXTHOP_TYPE_IPV4;
231 } else {
232 sg.r.nhop.gate.ipv6 = nexthop6;
233 sg.r.nhop.type = NEXTHOP_TYPE_IPV6;
234 }
235
236 sg.r.nhop.vrf_id = vrf->vrf_id;
237 sg.r.nhop_group.nexthop = &sg.r.nhop;
238 }
239
240 sg.r.inst = instance;
241 sg.r.vrf_id = vrf->vrf_id;
242 rts = routes;
243 sharp_install_routes_helper(&prefix, sg.r.vrf_id,
244 sg.r.inst, &sg.r.nhop_group, rts);
245
246 return CMD_SUCCESS;
247 }
248
249 DEFPY(vrf_label, vrf_label_cmd,
250 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
251 "Sharp Routing Protocol\n"
252 "Give a vrf a label\n"
253 "Pop and forward for IPv4\n"
254 "Pop and forward for IPv6\n"
255 VRF_CMD_HELP_STR
256 "The label to use, 0 specifies remove the label installed from previous\n"
257 "Specified range to use\n")
258 {
259 struct vrf *vrf;
260 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
261
262 if (strcmp(name, "default") == 0)
263 vrf = vrf_lookup_by_id(VRF_DEFAULT);
264 else
265 vrf = vrf_lookup_by_name(name);
266
267 if (!vrf) {
268 vty_out(vty, "Unable to find vrf you silly head");
269 return CMD_WARNING_CONFIG_FAILED;
270 }
271
272 if (label == 0)
273 label = MPLS_LABEL_NONE;
274
275 vrf_label_add(vrf->vrf_id, afi, label);
276 return CMD_SUCCESS;
277 }
278
279 DEFPY (remove_routes,
280 remove_routes_cmd,
281 "sharp remove routes [vrf NAME$name] <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
282 "Sharp Routing Protocol\n"
283 "Remove some routes\n"
284 "Routes to remove\n"
285 "The vrf we would like to remove from if non-default\n"
286 "The NAME of the vrf\n"
287 "v4 Starting spot\n"
288 "v6 Starting spot\n"
289 "Routes to uninstall\n"
290 "instance to use\n"
291 "Value of instance\n")
292 {
293 struct vrf *vrf;
294 struct prefix prefix;
295
296 sg.r.total_routes = routes;
297 sg.r.removed_routes = 0;
298 uint32_t rts;
299
300 memset(&prefix, 0, sizeof(prefix));
301
302 if (start4.s_addr != 0) {
303 prefix.family = AF_INET;
304 prefix.prefixlen = 32;
305 prefix.u.prefix4 = start4;
306 } else {
307 prefix.family = AF_INET6;
308 prefix.prefixlen = 128;
309 prefix.u.prefix6 = start6;
310 }
311
312 vrf = vrf_lookup_by_name(name ? name : VRF_DEFAULT_NAME);
313 if (!vrf) {
314 vty_out(vty, "The vrf NAME specified: %s does not exist\n",
315 name ? name : VRF_DEFAULT_NAME);
316 return CMD_WARNING;
317 }
318
319 sg.r.inst = instance;
320 sg.r.vrf_id = vrf->vrf_id;
321 rts = routes;
322 sharp_remove_routes_helper(&prefix, sg.r.vrf_id,
323 sg.r.inst, rts);
324
325 return CMD_SUCCESS;
326 }
327
328 DEFUN_NOSH (show_debugging_sharpd,
329 show_debugging_sharpd_cmd,
330 "show debugging [sharp]",
331 SHOW_STR
332 DEBUG_STR
333 "Sharp Information\n")
334 {
335 vty_out(vty, "Sharp debugging status\n");
336
337 return CMD_SUCCESS;
338 }
339
340 void sharp_vty_init(void)
341 {
342 install_element(ENABLE_NODE, &install_routes_data_dump_cmd);
343 install_element(ENABLE_NODE, &install_routes_cmd);
344 install_element(ENABLE_NODE, &remove_routes_cmd);
345 install_element(ENABLE_NODE, &vrf_label_cmd);
346 install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd);
347 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
348 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
349
350 install_element(VIEW_NODE, &show_debugging_sharpd_cmd);
351
352 return;
353 }