FD.io VPP  v21.06-3-gbb25fbf28
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 {
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 
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);
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 {
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  */
95  src->timers[IGMP_SRC_TIMER_EXP] =
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  */
igmp_mode_t
enum igmp_mode_t_ igmp_mode_t
im
vnet_interface_main_t * im
Definition: interface_output.c:395
igmp_src_t_
IGMP source The representation of a specified source address with in multicast group.
Definition: igmp_src.h:41
IGMP_SRC_TIMER_EXP
@ IGMP_SRC_TIMER_EXP
On expiry the source has not been refreshed by a query and can now be reaped.
Definition: igmp_src.h:32
igmp_group_n_srcs
u32 igmp_group_n_srcs(const igmp_group_t *group, igmp_filter_mode_t mode)
Definition: igmp_group.c:251
igmp_main_t_::srcs
igmp_src_t * srcs
pool of sources
Definition: igmp.h:104
IGMP_DBG
#define IGMP_DBG(...)
Definition: igmp.h:38
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
igmp_group.h
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:553
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_TIMER_ID_INVALID
#define IGMP_TIMER_ID_INVALID
Definition: igmp_timer.h:28
igmp_src_refresh
void igmp_src_refresh(igmp_src_t *src)
Definition: igmp_src.c:117
igmp_group_src_remove
void igmp_group_src_remove(igmp_group_t *group, igmp_src_t *src)
Definition: igmp_group.c:38
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:311
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
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
igmp_src.h
format_igmp_timer_id
u8 * format_igmp_timer_id(u8 *s, va_list *args)
Definition: igmp_timer.c:235
igmp_group_t_::config
u32 config
The pool index of the config object this group is in.
Definition: igmp_group.h:77
igmp_timer_type_get
u32 igmp_timer_type_get(igmp_timer_type_t t)
Definition: igmp_timer.c:68
igmp_group_get
igmp_group_t * igmp_group_get(u32 index)
Definition: igmp_group.c:279
igmp_src_index
u32 igmp_src_index(igmp_src_t *src)
Definition: igmp_src.c:141
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
src
vl_api_address_t src
Definition: gre.api:54
igmp_src_free
void igmp_src_free(igmp_src_t *src)
Definition: igmp_src.c:23
igmp_group_t_::key
igmp_key_t * key
The group's key within the per-interface config.
Definition: igmp_group.h:59
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
igmp_src_blocked
void igmp_src_blocked(igmp_src_t *src)
Definition: igmp_src.c:129
format_igmp_key
u8 * format_igmp_key(u8 *s, va_list *args)
Definition: igmp_format.c:203
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u8
unsigned char u8
Definition: types.h:56
igmp_src_exp
static void igmp_src_exp(u32 obj, void *dat)
Definition: igmp_src.c:36
igmp_event
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
igmp_main
igmp_main_t igmp_main
Definition: igmp.c:36
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:253
format_igmp_src
u8 * format_igmp_src(u8 *s, va_list *args)
Definition: igmp_src.c:147
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
igmp_main_t_
collection of data related to IGMP
Definition: igmp.h:63
igmp_timer_schedule
igmp_timer_id_t igmp_timer_schedule(f64 when, u32 obj, igmp_timer_function_t fn, void *data)
Schedule a timer to expire in 'when' seconds.
Definition: igmp_timer.c:195
igmp_proxy_device_block_src
void igmp_proxy_device_block_src(igmp_config_t *config, igmp_group_t *group, igmp_src_t *src)
Definition: igmp_proxy.c:195
igmp_src_alloc
igmp_src_t * igmp_src_alloc(u32 group_index, const igmp_key_t *skey, igmp_mode_t mode)
Definition: igmp_src.c:73
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