]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
Merge pull request #2198 from LabNConsulting/working/master/bgpd-nht-crash
[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
32 #include "sharpd/sharp_zebra.h"
33 #include "sharpd/sharp_vty.h"
34 #ifndef VTYSH_EXTRACT_PL
35 #include "sharpd/sharp_vty_clippy.c"
36 #endif
37
38 extern uint32_t total_routes;
39 extern uint32_t installed_routes;
40 extern uint32_t removed_routes;
41
42 DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
43 "sharp watch nexthop X:X::X:X$nhop",
44 "Sharp routing Protocol\n"
45 "Watch for changes\n"
46 "Watch for nexthop changes\n"
47 "The v6 nexthop to signal for watching\n")
48 {
49 struct prefix p;
50
51 memset(&p, 0, sizeof(p));
52
53 p.prefixlen = 128;
54 memcpy(&p.u.prefix6, &nhop, 16);
55 p.family = AF_INET6;
56
57 sharp_zebra_nexthop_watch(&p, true);
58
59 return CMD_SUCCESS;
60 }
61
62 DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
63 "sharp watch nexthop A.B.C.D$nhop",
64 "Sharp routing Protocol\n"
65 "Watch for changes\n"
66 "Watch for nexthop changes\n"
67 "The v4 nexthop to signal for watching\n")
68 {
69 struct prefix p;
70
71 memset(&p, 0, sizeof(p));
72
73 p.prefixlen = 32;
74 p.u.prefix4 = nhop;
75 p.family = AF_INET;
76
77 sharp_zebra_nexthop_watch(&p, true);
78
79 return CMD_SUCCESS;
80 }
81
82 DEFPY (install_routes,
83 install_routes_cmd,
84 "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes [instance (0-255)$instance]",
85 "Sharp routing Protocol\n"
86 "install some routes\n"
87 "Routes to install\n"
88 "Address to start /32 generation at\n"
89 "Nexthop to use\n"
90 "Nexthop address\n"
91 "How many to create\n"
92 "Instance to use\n"
93 "Instance\n")
94 {
95 int i;
96 struct prefix p;
97 struct nexthop nhop;
98 uint32_t temp;
99
100 total_routes = routes;
101 installed_routes = 0;
102
103 memset(&p, 0, sizeof(p));
104 memset(&nhop, 0, sizeof(nhop));
105
106 p.family = AF_INET;
107 p.prefixlen = 32;
108 p.u.prefix4 = start;
109
110 nhop.gate.ipv4 = nexthop;
111 nhop.type = NEXTHOP_TYPE_IPV4;
112
113 zlog_debug("Inserting %ld routes", routes);
114
115 temp = ntohl(p.u.prefix4.s_addr);
116 for (i = 0; i < routes; i++) {
117 route_add(&p, (uint8_t)instance, &nhop);
118 p.u.prefix4.s_addr = htonl(++temp);
119 }
120
121 return CMD_SUCCESS;
122 }
123
124 DEFPY(vrf_label, vrf_label_cmd,
125 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
126 "Sharp Routing Protocol\n"
127 "Give a vrf a label\n"
128 "Pop and forward for IPv4\n"
129 "Pop and forward for IPv6\n"
130 VRF_CMD_HELP_STR
131 "The label to use, 0 specifies remove the label installed from previous\n"
132 "Specified range to use\n")
133 {
134 struct vrf *vrf;
135 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
136
137 if (strcmp(name, "default") == 0)
138 vrf = vrf_lookup_by_id(VRF_DEFAULT);
139 else
140 vrf = vrf_lookup_by_name(name);
141
142 if (!vrf) {
143 vty_out(vty, "Unable to find vrf you silly head");
144 return CMD_WARNING_CONFIG_FAILED;
145 }
146
147 if (label == 0)
148 label = MPLS_LABEL_NONE;
149
150 vrf_label_add(vrf->vrf_id, afi, label);
151 return CMD_SUCCESS;
152 }
153
154 DEFPY (remove_routes,
155 remove_routes_cmd,
156 "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
157 "Sharp Routing Protocol\n"
158 "Remove some routes\n"
159 "Routes to remove\n"
160 "Starting spot\n"
161 "Routes to uniinstall\n"
162 "instance to use\n"
163 "Value of instance\n")
164 {
165 int i;
166 struct prefix p;
167 uint32_t temp;
168 total_routes = routes;
169 removed_routes = 0;
170
171 memset(&p, 0, sizeof(p));
172
173 p.family = AF_INET;
174 p.prefixlen = 32;
175 p.u.prefix4 = start;
176
177 zlog_debug("Removing %ld routes", routes);
178
179 temp = ntohl(p.u.prefix4.s_addr);
180 for (i = 0; i < routes; i++) {
181 route_delete(&p, (uint8_t)instance);
182 p.u.prefix4.s_addr = htonl(++temp);
183 }
184
185 return CMD_SUCCESS;
186 }
187
188 void sharp_vty_init(void)
189 {
190 install_element(ENABLE_NODE, &install_routes_cmd);
191 install_element(ENABLE_NODE, &remove_routes_cmd);
192 install_element(ENABLE_NODE, &vrf_label_cmd);
193 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
194 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
195 return;
196 }