FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
igmp_src.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_src.h>
19 #include <igmp/igmp_group.h>
20 #include <igmp/igmp.h>
21 
22 void
24 {
25  igmp_main_t *im = &igmp_main;
26 
27  IGMP_DBG ("free-src: (%U)", format_igmp_key, src->key);
28 
30 
31  clib_mem_free (src->key);
32  pool_put (im->srcs, src);
33 }
34 
35 static void
36 igmp_src_exp (u32 obj, void *dat)
37 {
38  igmp_group_t *group;
39  igmp_src_t *src;
40 
41  src = pool_elt_at_index (igmp_main.srcs, obj);
42  group = igmp_group_get (src->group);
43 
44  IGMP_DBG ("src-exp: %U", format_igmp_key, src->key);
45 
47 
48  if (IGMP_MODE_ROUTER == src->mode)
49  {
50  igmp_config_t *config;
51  igmp_group_t *group;
52 
53  /*
54  * inform interest parties
55  */
56  group = igmp_group_get (src->group);
57  config = igmp_config_get (group->config);
58 
59  igmp_event (IGMP_FILTER_MODE_EXCLUDE,
60  config->sw_if_index, src->key, group->key);
61 
62  igmp_proxy_device_block_src (config, group, src);
63  }
64 
65  igmp_group_src_remove (group, src);
66  igmp_src_free (src);
67 
68  if (0 == igmp_group_n_srcs (group, IGMP_FILTER_MODE_INCLUDE))
69  igmp_group_clear (&group);
70 }
71 
72 igmp_src_t *
73 igmp_src_alloc (u32 group_index, const igmp_key_t * skey, igmp_mode_t mode)
74 {
75  igmp_main_t *im = &igmp_main;
76  igmp_src_t *src;
77 
78  IGMP_DBG ("new-src: (%U)", format_igmp_key, skey);
79 
80  pool_get (im->srcs, src);
81  clib_memset (src, 0, sizeof (igmp_src_t));
82  src->mode = mode;
83  src->key = clib_mem_alloc (sizeof (*skey));
84  src->group = group_index;
85  clib_memcpy (src->key, skey, sizeof (*skey));
86 
87  if (IGMP_MODE_ROUTER == mode)
88  {
89  igmp_config_t *config;
90  igmp_group_t *group;
91  /*
92  * start a timer that determines whether the source is still
93  * active on the link
94  */
96  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_SRC),
97  src - im->srcs, igmp_src_exp, NULL);
98 
99  /*
100  * inform interest parties
101  */
102  group = igmp_group_get (src->group);
103  config = igmp_config_get (group->config);
104 
105  igmp_event (IGMP_FILTER_MODE_INCLUDE,
106  config->sw_if_index, src->key, group->key);
107  }
108  else
109  {
111  }
112 
113  return (src);
114 }
115 
116 void
118 {
119  IGMP_DBG ("refresh-src: (%U)", format_igmp_key, src->key);
120 
122 
123  src->timers[IGMP_SRC_TIMER_EXP] =
124  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_SRC),
125  igmp_src_index (src), igmp_src_exp, NULL);
126 }
127 
128 void
130 {
131  IGMP_DBG ("block-src: (%U)", format_igmp_key, src->key);
132 
134 
135  src->timers[IGMP_SRC_TIMER_EXP] =
136  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_LEAVE),
137  igmp_src_index (src), igmp_src_exp, NULL);
138 }
139 
140 u32
142 {
143  return (src - igmp_main.srcs);
144 }
145 
146 u8 *
147 format_igmp_src (u8 * s, va_list * args)
148 {
149  igmp_src_t *src = va_arg (*args, igmp_src_t *);
150  u32 indent = va_arg (*args, u32);
151 
152  s = format (s, "%U%U %U",
153  format_white_space, indent,
154  format_igmp_key, src->key,
156 
157  return (s);
158 }
159 
160 /*
161  * fd.io coding-style-patch-verification: ON
162  *
163  * Local Variables:
164  * eval: (c-set-style "gnu")
165  * End:
166  */
u8 * format_igmp_key(u8 *s, va_list *args)
Definition: igmp_format.c:203
void igmp_timer_retire(igmp_timer_id_t *tid)
Definition: igmp_timer.c:221
u32 group
The group this source is on.
Definition: igmp_src.h:57
igmp_main_t igmp_main
Definition: igmp.c:36
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vl_api_address_t src
Definition: gre.api:54
u32 timers[IGMP_SRC_N_TIMERS]
Timers.
Definition: igmp_src.h:67
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
void igmp_src_blocked(igmp_src_t *src)
Definition: igmp_src.c:129
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
unsigned char u8
Definition: types.h:56
void igmp_src_free(igmp_src_t *src)
Definition: igmp_src.c:23
#define IGMP_DBG(...)
Definition: igmp.h:38
igmp_timer_id_t igmp_timer_schedule(f64 when, u32 obj, igmp_timer_function_t fn, void *data)
Schedule a timer to expire in &#39;when&#39; seconds.
Definition: igmp_timer.c:195
void igmp_src_refresh(igmp_src_t *src)
Definition: igmp_src.c:117
#define clib_memcpy(d, s, n)
Definition: string.h:180
u32 igmp_timer_type_get(igmp_timer_type_t t)
Definition: igmp_timer.c:68
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
igmp_src_t * igmp_src_alloc(u32 group_index, const igmp_key_t *skey, igmp_mode_t mode)
Definition: igmp_src.c:73
igmp_config_t * igmp_config_get(u32 index)
Get the config from the pool index.
Definition: igmp_config.c:70
unsigned int u32
Definition: types.h:88
void igmp_event(igmp_filter_mode_t filter, u32 sw_if_index, const ip46_address_t *saddr, const ip46_address_t *gaddr)
Send an IGMP event to listening parties.
Definition: igmp_api.c:388
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
u8 * format_igmp_src(u8 *s, va_list *args)
Definition: igmp_src.c:147
u32 config
The pool index of the config object this group is in.
Definition: igmp_group.h:77
void igmp_group_src_remove(igmp_group_t *group, igmp_src_t *src)
Definition: igmp_group.c:38
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
void igmp_group_clear(igmp_group_t **group)
Definition: igmp_group.c:68
collection of data related to IGMP
Definition: igmp.h:63
vl_api_tunnel_mode_t mode
Definition: gre.api:48
#define IGMP_TIMER_ID_INVALID
Definition: igmp_timer.h:28
igmp_group_t * igmp_group_get(u32 index)
Definition: igmp_group.c:279
On expiry the source has not been refreshed by a query and can now be reaped.
Definition: igmp_src.h:32
igmp_mode_t mode
the mode that provided this source
Definition: igmp_src.h:62
u32 igmp_src_index(igmp_src_t *src)
Definition: igmp_src.c:141
static void clib_mem_free(void *p)
Definition: mem.h:215
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
static void * clib_mem_alloc(uword size)
Definition: mem.h:157
IGMP interface configuration.
Definition: igmp_config.h:47
u8 * format_igmp_timer_id(u8 *s, va_list *args)
Definition: igmp_timer.c:235
igmp_key_t * key
The group&#39;s key within the per-interface config.
Definition: igmp_group.h:59
IGMP group A multicast group address for which reception has been requested.
Definition: igmp_group.h:56
igmp_key_t * key
The source&#39;s key.
Definition: igmp_src.h:46
enum igmp_mode_t_ igmp_mode_t
void igmp_proxy_device_block_src(igmp_config_t *config, igmp_group_t *group, igmp_src_t *src)
Definition: igmp_proxy.c:195
u32 igmp_group_n_srcs(const igmp_group_t *group, igmp_filter_mode_t mode)
Definition: igmp_group.c:251
igmp_src_t * srcs
pool of sources
Definition: igmp.h:104
IGMP source The representation of a specified source address with in multicast group.
Definition: igmp_src.h:41
static void igmp_src_exp(u32 obj, void *dat)
Definition: igmp_src.c:36