FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
igmp_config.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17 
18 #include <igmp/igmp_config.h>
19 #include <igmp/igmp.h>
20 
21 void
23 {
24  igmp_group_t *group;
25  u32 ii;
26 
27  IGMP_DBG ("clear-config: %U",
29  vnet_get_main (), config->sw_if_index);
30 
31  /* *INDENT-OFF* */
32  FOR_EACH_GROUP (group, config,
33  ({
34  igmp_group_clear (&group);
35  }));
36  /* *INDENT-ON* */
37 
38  for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
39  {
40  igmp_timer_retire (&config->timers[ii]);
41  }
42 }
43 
46 {
47  igmp_main_t *im;
48 
49  im = &igmp_main;
50 
51  if (vec_len (im->igmp_config_by_sw_if_index) > sw_if_index)
52  {
53  u32 index;
54 
55  index = im->igmp_config_by_sw_if_index[sw_if_index];
56 
57  if (~0 != index)
58  return (vec_elt_at_index (im->configs, index));
59  }
60  return NULL;
61 }
62 
63 u32
65 {
66  return (c - igmp_main.configs);
67 }
68 
71 {
73 }
74 
77 {
78  uword *p;
79  igmp_group_t *group = NULL;
80  if (!config)
81  return NULL;
82 
83  p = hash_get_mem (config->igmp_group_by_key, key);
84  if (p)
85  group = pool_elt_at_index (igmp_main.groups, p[0]);
86 
87  return group;
88 }
89 
90 u8 *
91 format_igmp_config_timer_type (u8 * s, va_list * args)
92 {
94 
95  switch (type)
96  {
97 #define _(v,t) case IGMP_CONFIG_TIMER_##v: return (format (s, "%s", t));
99 #undef _
100  }
101  return (s);
102 }
103 
104 
105 u8 *
106 format_igmp_config (u8 * s, va_list * args)
107 {
108  igmp_config_t *config;
109  igmp_group_t *group;
110  vnet_main_t *vnm;
111  u32 ii;
112 
113  config = va_arg (*args, igmp_config_t *);
114  vnm = vnet_get_main ();
115 
116  s = format (s, "interface: %U mode: %U %U",
118  format_igmp_mode, config->mode,
120 
121  for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
122  {
123  s = format (s, "\n %U:%U",
125  format_igmp_timer_id, config->timers[ii]);
126  }
127 
128  /* *INDENT-OFF* */
129  FOR_EACH_GROUP (group, config,
130  ({
131  s = format (s, "\n%U", format_igmp_group, group, 4);
132  }));
133  /* *INDENT-ON* */
134 
135  return (s);
136 }
137 
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */
igmp_main_t_::configs
igmp_config_t * configs
pool of configs
Definition: igmp.h:95
FOR_EACH_GROUP
#define FOR_EACH_GROUP(_group, _config, _body)
Definition: igmp_config.h:85
im
vnet_interface_main_t * im
Definition: interface_output.c:415
IGMP_DBG
#define IGMP_DBG(...)
Definition: igmp.h:38
igmp_config_get
igmp_config_t * igmp_config_get(u32 index)
Get the config from the pool index.
Definition: igmp_config.c:70
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
igmp_timer_retire
void igmp_timer_retire(igmp_timer_id_t *tid)
Definition: igmp_timer.c:221
igmp_config_t_
IGMP interface configuration.
Definition: igmp_config.h:47
igmp.h
igmp_group_clear
void igmp_group_clear(igmp_group_t **group)
Definition: igmp_group.c:68
igmp_config_t_::sw_if_index
u32 sw_if_index
Definition: igmp_config.h:52
igmp_group_t_
IGMP group A multicast group address for which reception has been requested.
Definition: igmp_group.h:56
format_igmp_timer_id
u8 * format_igmp_timer_id(u8 *s, va_list *args)
Definition: igmp_timer.c:235
igmp_config_lookup
igmp_config_t * igmp_config_lookup(u32 sw_if_index)
igmp config lookup
Definition: igmp_config.c:45
key
typedef key
Definition: ipsec_types.api:91
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
format_igmp_mode
u8 * format_igmp_mode(u8 *s, va_list *args)
Definition: igmp_format.c:65
IGMP_CONFIG_N_TIMERS
#define IGMP_CONFIG_N_TIMERS
Definition: igmp_config.h:40
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
igmp_config_t_::timers
igmp_timer_id_t timers[IGMP_CONFIG_N_TIMERS]
A vector of scheduled query-response timers.
Definition: igmp_config.h:77
igmp_config_index
u32 igmp_config_index(const igmp_config_t *c)
Get the pool index for a config.
Definition: igmp_config.c:64
igmp_group_lookup
igmp_group_t * igmp_group_lookup(igmp_config_t *config, const igmp_key_t *key)
igmp group lookup
Definition: igmp_config.c:76
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
igmp_main_t_::groups
igmp_group_t * groups
pool of groups
Definition: igmp.h:100
igmp_config_t_::proxy_device_id
u32 proxy_device_id
ID of a proxy device this configuration is on.
Definition: igmp_config.h:82
uword
u64 uword
Definition: types.h:112
format_igmp_group
u8 * format_igmp_group(u8 *s, va_list *args)
Definition: igmp_group.c:299
foreach_igmp_config_timer_type
@ foreach_igmp_config_timer_type
Definition: igmp_config.h:36
format_igmp_config_timer_type
u8 * format_igmp_config_timer_type(u8 *s, va_list *args)
Definition: igmp_config.c:91
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vnet_main_t
Definition: vnet.h:76
index
u32 index
Definition: flow_types.api:221
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
format
description fragment has unexpected format
Definition: map.api:433
igmp_config_t_::mode
igmp_mode_t mode
Definition: igmp_config.h:62
u32
unsigned int u32
Definition: types.h:88
igmp_config.h
format_igmp_config
u8 * format_igmp_config(u8 *s, va_list *args)
Definition: igmp_config.c:106
igmp_config_t_::igmp_group_by_key
uword * igmp_group_by_key
Database of groups joined on the link.
Definition: igmp_config.h:72
u8
unsigned char u8
Definition: types.h:56
igmp_config_timer_type_t
enum igmp_config_timer_type_t_ igmp_config_timer_type_t
igmp_main
igmp_main_t igmp_main
Definition: igmp.c:36
igmp_clear_config
void igmp_clear_config(igmp_config_t *config)
igmp clear config
Definition: igmp_config.c:22
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
igmp_main_t_
collection of data related to IGMP
Definition: igmp.h:63
format_igmp_proxy_device_id
u8 * format_igmp_proxy_device_id(u8 *s, va_list *args)
Definition: igmp_format.c:213
igmp_key_t
ip46_address_t igmp_key_t
IGMP Key Used to index groups within an interface config and sources within a list.
Definition: igmp_types.h:49