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_main_t *im = &igmp_main;
41 igmp_config_t *config;
43 if (!unformat_user (input, unformat_line_input, line_input))
46 clib_error_return (0, "'help clear igmp' or 'clear igmp ?' for help");
50 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
53 (line_input, "int %U", unformat_vnet_sw_interface, vnm,
58 clib_error_return (0, "unknown input '%U'", format_unformat_error,
64 config = igmp_config_lookup (im, sw_if_index);
66 igmp_clear_config (config);
69 unformat_free (line_input);
74 VLIB_CLI_COMMAND (igmp_clear_interface_command, static) = {
76 .short_help = "clear igmp int <interface>",
77 .function = igmp_clear_interface_command_fn,
82 igmp_listen_command_fn (vlib_main_t * vm, unformat_input_t * input,
83 vlib_cli_command_t * cmd)
85 unformat_input_t _line_input, *line_input = &_line_input;
86 clib_error_t *error = NULL;
88 ip46_address_t saddr, gaddr;
89 vnet_main_t *vnm = vnet_get_main ();
93 if (!unformat_user (input, unformat_line_input, line_input))
97 "'help igmp listen' or 'igmp listen ?' for help");
101 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
103 if (unformat (line_input, "enable"))
105 else if (unformat (line_input, "disable"))
109 (line_input, "int %U", unformat_vnet_sw_interface, vnm,
112 if (unformat (line_input, "saddr %U", unformat_ip46_address, &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, saddr, gaddr,
132 /* cli_api_listen */ 1);
137 clib_error_return (0, "This igmp configuration already exists");
140 clib_error_return (0, "This igmp configuration does not nexist");
144 clib_error_return (0,
145 "Failed to add configuration, interface is in router mode");
148 unformat_free (line_input);
153 VLIB_CLI_COMMAND (igmp_listen_command, static) = {
154 .path = "igmp listen",
155 .short_help = "igmp listen [<enable|disable>] "
156 "int <interface> saddr <ip4-address> gaddr <ip4-address>",
157 .function = igmp_listen_command_fn,
161 static clib_error_t *
162 igmp_show_command_fn (vlib_main_t * vm, unformat_input_t * input,
163 vlib_cli_command_t * cmd)
165 clib_error_t *error = NULL;
166 igmp_main_t *im = &igmp_main;
167 vnet_main_t *vnm = vnet_get_main ();
168 igmp_config_t *config;
172 pool_foreach (config, im->configs, (
174 vlib_cli_output (vm, "interface: %U", format_vnet_sw_if_index_name,
175 vnm, config->sw_if_index);
176 pool_foreach (sg, config->sg, (
178 vlib_cli_output (vm, "\t(S,G): %U:%U:%U", format_ip46_address,
179 &sg->saddr, ip46_address_is_ip4 (&sg->saddr),
180 format_ip46_address, &sg->gaddr, ip46_address_is_ip4
181 (&sg->gaddr), format_igmp_report_type, sg->group_type);
190 VLIB_CLI_COMMAND (igmp_show_command, static) = {
191 .path = "show igmp config",
192 .short_help = "show igmp config",
193 .function = igmp_show_command_fn,
198 igmp_cli_init (vlib_main_t * vm)
203 VLIB_INIT_FUNCTION (igmp_cli_init);
206 * fd.io coding-style-patch-verification: ON
209 * eval: (c-set-style "gnu")