]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
Merge pull request #3532 from donaldsharp/community_list_speedup
[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_zebra.h"
34 #include "sharpd/sharp_vty.h"
35 #ifndef VTYSH_EXTRACT_PL
36 #include "sharpd/sharp_vty_clippy.c"
37 #endif
38
39 extern uint32_t total_routes;
40 extern uint32_t installed_routes;
41 extern uint32_t removed_routes;
42
43 uint8_t inst;
44 struct prefix prefix;
45 struct prefix orig_prefix;
46 struct nexthop nhop;
47 struct nexthop_group nhop_group;
48 uint32_t rts;
49 int32_t repeat;
50
51 DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
52 "sharp watch nexthop X:X::X:X$nhop",
53 "Sharp routing Protocol\n"
54 "Watch for changes\n"
55 "Watch for nexthop changes\n"
56 "The v6 nexthop to signal for watching\n")
57 {
58 struct prefix p;
59
60 memset(&p, 0, sizeof(p));
61
62 p.prefixlen = 128;
63 memcpy(&p.u.prefix6, &nhop, 16);
64 p.family = AF_INET6;
65
66 sharp_zebra_nexthop_watch(&p, true);
67
68 return CMD_SUCCESS;
69 }
70
71 DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
72 "sharp watch nexthop A.B.C.D$nhop",
73 "Sharp routing Protocol\n"
74 "Watch for changes\n"
75 "Watch for nexthop changes\n"
76 "The v4 nexthop to signal for watching\n")
77 {
78 struct prefix p;
79
80 memset(&p, 0, sizeof(p));
81
82 p.prefixlen = 32;
83 p.u.prefix4 = nhop;
84 p.family = AF_INET;
85
86 sharp_zebra_nexthop_watch(&p, true);
87
88 return CMD_SUCCESS;
89 }
90
91 DEFPY (install_routes,
92 install_routes_cmd,
93 "sharp install routes <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]",
94 "Sharp routing Protocol\n"
95 "install some routes\n"
96 "Routes to install\n"
97 "v4 Address to start /32 generation at\n"
98 "v6 Address to start /32 generation at\n"
99 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
100 "V4 Nexthop address to use\n"
101 "V6 Nexthop address to use\n"
102 "Nexthop-Group to use\n"
103 "The Name of the nexthop-group\n"
104 "How many to create\n"
105 "Instance to use\n"
106 "Instance\n"
107 "Should we repeat this command\n"
108 "How many times to repeat this command\n")
109 {
110 total_routes = routes;
111 installed_routes = 0;
112
113 if (rpt >= 2)
114 repeat = rpt * 2;
115 else
116 repeat = 0;
117
118 memset(&prefix, 0, sizeof(prefix));
119 memset(&orig_prefix, 0, sizeof(orig_prefix));
120 memset(&nhop, 0, sizeof(nhop));
121 memset(&nhop_group, 0, sizeof(nhop_group));
122
123 if (start4.s_addr != 0) {
124 prefix.family = AF_INET;
125 prefix.prefixlen = 32;
126 prefix.u.prefix4 = start4;
127 } else {
128 prefix.family = AF_INET6;
129 prefix.prefixlen = 128;
130 prefix.u.prefix6 = start6;
131 }
132 orig_prefix = prefix;
133
134 if (nexthop_group) {
135 struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
136 if (!nhgc) {
137 vty_out(vty,
138 "Specified Nexthop Group: %s does not exist\n",
139 nexthop_group);
140 return CMD_WARNING;
141 }
142
143 nhop_group.nexthop = nhgc->nhg.nexthop;
144 } else {
145 if (nexthop4.s_addr != INADDR_ANY) {
146 nhop.gate.ipv4 = nexthop4;
147 nhop.type = NEXTHOP_TYPE_IPV4;
148 } else {
149 nhop.gate.ipv6 = nexthop6;
150 nhop.type = NEXTHOP_TYPE_IPV6;
151 }
152
153 nhop_group.nexthop = &nhop;
154 }
155
156 inst = instance;
157 rts = routes;
158 sharp_install_routes_helper(&prefix, inst, &nhop_group, rts);
159
160 return CMD_SUCCESS;
161 }
162
163 DEFPY(vrf_label, vrf_label_cmd,
164 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
165 "Sharp Routing Protocol\n"
166 "Give a vrf a label\n"
167 "Pop and forward for IPv4\n"
168 "Pop and forward for IPv6\n"
169 VRF_CMD_HELP_STR
170 "The label to use, 0 specifies remove the label installed from previous\n"
171 "Specified range to use\n")
172 {
173 struct vrf *vrf;
174 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
175
176 if (strcmp(name, "default") == 0)
177 vrf = vrf_lookup_by_id(VRF_DEFAULT);
178 else
179 vrf = vrf_lookup_by_name(name);
180
181 if (!vrf) {
182 vty_out(vty, "Unable to find vrf you silly head");
183 return CMD_WARNING_CONFIG_FAILED;
184 }
185
186 if (label == 0)
187 label = MPLS_LABEL_NONE;
188
189 vrf_label_add(vrf->vrf_id, afi, label);
190 return CMD_SUCCESS;
191 }
192
193 DEFPY (remove_routes,
194 remove_routes_cmd,
195 "sharp remove routes <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
196 "Sharp Routing Protocol\n"
197 "Remove some routes\n"
198 "Routes to remove\n"
199 "v4 Starting spot\n"
200 "v6 Starting spot\n"
201 "Routes to uninstall\n"
202 "instance to use\n"
203 "Value of instance\n")
204 {
205 total_routes = routes;
206 removed_routes = 0;
207
208 memset(&prefix, 0, sizeof(prefix));
209
210 if (start4.s_addr != 0) {
211 prefix.family = AF_INET;
212 prefix.prefixlen = 32;
213 prefix.u.prefix4 = start4;
214 } else {
215 prefix.family = AF_INET6;
216 prefix.prefixlen = 128;
217 prefix.u.prefix6 = start6;
218 }
219
220 inst = instance;
221 rts = routes;
222 sharp_remove_routes_helper(&prefix, inst, rts);
223
224 return CMD_SUCCESS;
225 }
226
227 DEFUN_NOSH (show_debugging_sharpd,
228 show_debugging_sharpd_cmd,
229 "show debugging [sharp]",
230 SHOW_STR
231 DEBUG_STR
232 "Sharp Information\n")
233 {
234 vty_out(vty, "Sharp debugging status\n");
235
236 return CMD_SUCCESS;
237 }
238
239 void sharp_vty_init(void)
240 {
241 install_element(ENABLE_NODE, &install_routes_cmd);
242 install_element(ENABLE_NODE, &remove_routes_cmd);
243 install_element(ENABLE_NODE, &vrf_label_cmd);
244 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
245 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
246
247 install_element(VIEW_NODE, &show_debugging_sharpd_cmd);
248
249 return;
250 }