2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/fib/fib_entry.h>
26 #include <vnet/fib/fib_table.h>
27 #include <vnet/mfib/mfib_table.h>
29 #include <igmp/igmp.h>
32 igmp_clear_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
33 vlib_cli_command_t * cmd)
35 unformat_input_t _line_input, *line_input = &_line_input;
36 clib_error_t *error = NULL;
37 vnet_main_t *vnm = vnet_get_main ();
40 igmp_config_t *config;
42 if (!unformat_user (input, unformat_line_input, line_input))
45 clib_error_return (0, "'help clear igmp' or 'clear igmp ?' for help");
49 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
52 (line_input, "int %U", unformat_vnet_sw_interface, vnm,
57 clib_error_return (0, "unknown input '%U'", format_unformat_error,
63 config = igmp_config_lookup (sw_if_index);
65 igmp_clear_config (config);
68 unformat_free (line_input);
73 VLIB_CLI_COMMAND (igmp_clear_interface_command, static) = {
75 .short_help = "clear igmp int <interface>",
76 .function = igmp_clear_interface_command_fn,
81 igmp_listen_command_fn (vlib_main_t * vm, unformat_input_t * input,
82 vlib_cli_command_t * cmd)
84 unformat_input_t _line_input, *line_input = &_line_input;
85 clib_error_t *error = NULL;
87 ip46_address_t saddr, *saddrs = NULL, gaddr;
88 vnet_main_t *vnm = vnet_get_main ();
92 if (!unformat_user (input, unformat_line_input, line_input))
96 "'help igmp listen' or 'igmp listen ?' for help");
100 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
102 if (unformat (line_input, "enable"))
104 else if (unformat (line_input, "disable"))
108 (line_input, "int %U", unformat_vnet_sw_interface, vnm,
111 if (unformat (line_input, "saddr %U", unformat_ip46_address, &saddr))
112 vec_add1 (saddrs, saddr);
114 if (unformat (line_input, "gaddr %U", unformat_ip46_address, &gaddr));
118 clib_error_return (0, "unknown input '%U'", format_unformat_error,
124 if ((vnet_sw_interface_get_flags (vnm, sw_if_index)
125 && VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0)
127 error = clib_error_return (0, "Interface is down");
131 rv = igmp_listen (vm, enable, sw_if_index, saddrs, &gaddr);
137 clib_error_return (0, "This igmp configuration already exists");
140 clib_error_return (0, "This igmp configuration does not exist");
144 clib_error_return (0,
145 "Failed to add configuration, interface is in router mode");
148 unformat_free (line_input);
154 VLIB_CLI_COMMAND (igmp_listen_command, static) = {
155 .path = "igmp listen",
156 .short_help = "igmp listen [<enable|disable>] "
157 "int <interface> saddr <ip4-address> gaddr <ip4-address>",
158 .function = igmp_listen_command_fn,
162 static clib_error_t *
163 igmp_enable_cli (vlib_main_t * vm,
164 unformat_input_t * input, vlib_cli_command_t * cmd)
166 unformat_input_t _line_input, *line_input = &_line_input;
167 igmp_mode_t mode = IGMP_MODE_ROUTER;
168 vnet_main_t *vnm = vnet_get_main ();
169 clib_error_t *error = NULL;
170 u32 sw_if_index = ~0;
174 if (!unformat_user (input, unformat_line_input, line_input))
177 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
179 if (unformat (line_input, "enable"))
181 else if (unformat (line_input, "disable"))
183 if (unformat (line_input, "host"))
184 mode = IGMP_MODE_HOST;
185 else if (unformat (line_input, "router"))
186 mode = IGMP_MODE_ROUTER;
187 else if (unformat (line_input, "%U",
188 unformat_vnet_sw_interface, vnm, &sw_if_index));
192 clib_error_return (0, "unknown input '%U'", format_unformat_error,
198 if (~0 == sw_if_index)
200 error = clib_error_return (0, "interface must be specified");
204 rv = igmp_enable_disable (sw_if_index, enable, mode);
207 error = clib_error_return (0, "result: %d", rv);
210 unformat_free (line_input);
215 VLIB_CLI_COMMAND (igmp_enable_command, static) = {
217 .short_help = "igmp <enable|disable> <host|router> <interface>",
218 .function = igmp_enable_cli,
222 static clib_error_t *
223 igmp_proxy_device_add_del_command_fn (vlib_main_t * vm,
224 unformat_input_t * input,
225 vlib_cli_command_t * cmd)
227 unformat_input_t _line_input, *line_input = &_line_input;
228 vnet_main_t *vnm = vnet_get_main ();
229 clib_error_t *error = NULL;
230 u32 sw_if_index = ~0;
235 if (!unformat_user (input, unformat_line_input, line_input))
238 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
240 if (unformat (line_input, "add"))
242 else if (unformat (line_input, "del"))
244 else if (unformat (line_input, "vrf-id %u", &vrf_id))
246 else if (unformat (line_input, "%U",
247 unformat_vnet_sw_interface, vnm, &sw_if_index));
251 clib_error_return (0, "unknown input '%U'", format_unformat_error,
257 if (~0 == sw_if_index)
259 error = clib_error_return (0, "interface must be specified");
265 error = clib_error_return (0, "VRF must be specified");
269 rv = igmp_proxy_device_add_del (vrf_id, sw_if_index, add);
272 error = clib_error_return (0, "result: %d", rv);
275 unformat_free (line_input);
279 VLIB_CLI_COMMAND (igmp_proxy_device_add_del_command, static) = {
280 .path = "igmp proxy-dev",
281 .short_help = "igmp proxy-dev <add|del> vrf-id <table-id> <interface>",
282 .function = igmp_proxy_device_add_del_command_fn,
286 static clib_error_t *
287 igmp_proxy_device_add_del_interface_command_fn (vlib_main_t * vm,
288 unformat_input_t * input,
289 vlib_cli_command_t * cmd)
291 unformat_input_t _line_input, *line_input = &_line_input;
292 vnet_main_t *vnm = vnet_get_main ();
293 clib_error_t *error = NULL;
294 u32 sw_if_index = ~0;
299 if (!unformat_user (input, unformat_line_input, line_input))
302 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
304 if (unformat (line_input, "add"))
306 else if (unformat (line_input, "del"))
308 else if (unformat (line_input, "vrf-id %u", &vrf_id))
310 else if (unformat (line_input, "%U",
311 unformat_vnet_sw_interface, vnm, &sw_if_index));
315 clib_error_return (0, "unknown input '%U'", format_unformat_error,
321 if (~0 == sw_if_index)
323 error = clib_error_return (0, "interface must be specified");
329 error = clib_error_return (0, "VRF must be specified");
333 rv = igmp_proxy_device_add_del_interface (vrf_id, sw_if_index, add);
336 error = clib_error_return (0, "result: %d", rv);
339 unformat_free (line_input);
343 VLIB_CLI_COMMAND (igmp_proxy_device_add_del_interface_command, static) = {
344 .path = "igmp proxy-dev itf",
345 .short_help = "igmp proxy-dev itf <add|del> vrf-id <table-id> <interface>",
346 .function = igmp_proxy_device_add_del_interface_command_fn,
350 static clib_error_t *
351 igmp_show_command_fn (vlib_main_t * vm, unformat_input_t * input,
352 vlib_cli_command_t * cmd)
354 clib_error_t *error = NULL;
355 igmp_main_t *im = &igmp_main;
356 igmp_config_t *config;
359 pool_foreach (config, im->configs,
361 vlib_cli_output (vm, "%U", format_igmp_config, config);
369 VLIB_CLI_COMMAND (igmp_show_command, static) = {
370 .path = "show igmp config",
371 .short_help = "show igmp config",
372 .function = igmp_show_command_fn,
376 static clib_error_t *
377 igmp_show_timers_command_fn (vlib_main_t * vm,
378 unformat_input_t * input,
379 vlib_cli_command_t * cmd)
381 #define _(n,f) vlib_cli_output (vm, "%s: %d", #f, igmp_timer_type_get(n));
382 foreach_igmp_timer_type
388 VLIB_CLI_COMMAND (igmp_show_timers_command, static) = {
389 .path = "show igmp timers",
390 .short_help = "show igmp timers",
391 .function = igmp_show_timers_command_fn,
395 static clib_error_t *
396 test_igmp_command_fn (vlib_main_t * vm,
397 unformat_input_t * input, vlib_cli_command_t * cmd)
399 clib_error_t *error = NULL;
402 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
404 if (unformat (input, "query %d", &value))
405 igmp_timer_type_set (IGMP_TIMER_QUERY, value);
406 else if (unformat (input, "src %d", &value))
407 igmp_timer_type_set (IGMP_TIMER_SRC, value);
408 else if (unformat (input, "leave %d", &value))
409 igmp_timer_type_set (IGMP_TIMER_LEAVE, value);
411 error = clib_error_return (0, "query or src timers only");
418 VLIB_CLI_COMMAND (test_igmp_command, static) = {
419 .path = "test igmp timers",
420 .short_help = "Change the default values for IGMP timers - only sensible during unit tests",
421 .function = test_igmp_command_fn,
427 igmp_cli_init (vlib_main_t * vm)
432 VLIB_INIT_FUNCTION (igmp_cli_init);
435 * fd.io coding-style-patch-verification: ON
438 * eval: (c-set-style "gnu")