vrrp: fix vrrp_garp_or_na_send()'s memory leak
[vpp.git] / src / plugins / igmp / igmp_config.c
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
22 igmp_clear_config (igmp_config_t * config)
23 {
24   igmp_group_t *group;
25   u32 ii;
26
27   IGMP_DBG ("clear-config: %U",
28             format_vnet_sw_if_index_name,
29             vnet_get_main (), config->sw_if_index);
30
31   FOR_EACH_GROUP (group, config,
32     ({
33       igmp_group_clear (&group);
34     }));
35
36   for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
37     {
38       igmp_timer_retire (&config->timers[ii]);
39     }
40 }
41
42 igmp_config_t *
43 igmp_config_lookup (u32 sw_if_index)
44 {
45   igmp_main_t *im;
46
47   im = &igmp_main;
48
49   if (vec_len (im->igmp_config_by_sw_if_index) > sw_if_index)
50     {
51       u32 index;
52
53       index = im->igmp_config_by_sw_if_index[sw_if_index];
54
55       if (~0 != index)
56         return (vec_elt_at_index (im->configs, index));
57     }
58   return NULL;
59 }
60
61 u32
62 igmp_config_index (const igmp_config_t * c)
63 {
64   return (c - igmp_main.configs);
65 }
66
67 igmp_config_t *
68 igmp_config_get (u32 index)
69 {
70   return (pool_elt_at_index (igmp_main.configs, index));
71 }
72
73 igmp_group_t *
74 igmp_group_lookup (igmp_config_t * config, const igmp_key_t * key)
75 {
76   uword *p;
77   igmp_group_t *group = NULL;
78   if (!config)
79     return NULL;
80
81   p = hash_get_mem (config->igmp_group_by_key, key);
82   if (p)
83     group = pool_elt_at_index (igmp_main.groups, p[0]);
84
85   return group;
86 }
87
88 u8 *
89 format_igmp_config_timer_type (u8 * s, va_list * args)
90 {
91   igmp_config_timer_type_t type = va_arg (*args, igmp_config_timer_type_t);
92
93   switch (type)
94     {
95 #define _(v,t) case IGMP_CONFIG_TIMER_##v: return (format (s, "%s", t));
96       foreach_igmp_config_timer_type
97 #undef _
98     }
99   return (s);
100 }
101
102
103 u8 *
104 format_igmp_config (u8 * s, va_list * args)
105 {
106   igmp_config_t *config;
107   igmp_group_t *group;
108   vnet_main_t *vnm;
109   u32 ii;
110
111   config = va_arg (*args, igmp_config_t *);
112   vnm = vnet_get_main ();
113
114   s = format (s, "interface: %U mode: %U %U",
115               format_vnet_sw_if_index_name, vnm, config->sw_if_index,
116               format_igmp_mode, config->mode,
117               format_igmp_proxy_device_id, config->proxy_device_id);
118
119   for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
120     {
121       s = format (s, "\n  %U:%U",
122                   format_igmp_config_timer_type, ii,
123                   format_igmp_timer_id, config->timers[ii]);
124     }
125
126   FOR_EACH_GROUP (group, config,
127     ({
128       s = format (s, "\n%U", format_igmp_group, group, 4);
129     }));
130
131   return (s);
132 }
133
134 /*
135  * fd.io coding-style-patch-verification: ON
136  *
137  * Local Variables:
138  * eval: (c-set-style "gnu")
139  * End:
140  */