FD.io VPP  v18.07.1-19-g511ce25
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 
63  igmp_group_src_remove (group, src);
64  igmp_src_free (src);
65 
66  if (0 == igmp_group_n_srcs (group, IGMP_FILTER_MODE_INCLUDE))
67  igmp_group_clear (group);
68 }
69 
70 igmp_src_t *
71 igmp_src_alloc (u32 group_index, const igmp_key_t * skey, igmp_mode_t mode)
72 {
73  igmp_main_t *im = &igmp_main;
74  igmp_src_t *src;
75 
76  IGMP_DBG ("new-src: (%U)", format_igmp_key, skey);
77 
78  pool_get (im->srcs, src);
79  memset (src, 0, sizeof (igmp_src_t));
80  src->mode = mode;
81  src->key = clib_mem_alloc (sizeof (*skey));
82  src->group = group_index;
83  clib_memcpy (src->key, skey, sizeof (*skey));
84 
85  if (IGMP_MODE_ROUTER == mode)
86  {
87  igmp_config_t *config;
88  igmp_group_t *group;
89  /*
90  * start a timer that determines whether the source is still
91  * active o nthe link
92  */
94  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_SRC),
95  src - im->srcs, igmp_src_exp, NULL);
96 
97  /*
98  * inform interest parties
99  */
100  group = igmp_group_get (src->group);
101  config = igmp_config_get (group->config);
102 
103  igmp_event (IGMP_FILTER_MODE_INCLUDE,
104  config->sw_if_index, src->key, group->key);
105  }
106  else
107  {
109  }
110 
111  return (src);
112 }
113 
114 void
116 {
117  IGMP_DBG ("refresh-src: (%U)", format_igmp_key, src->key);
118 
120 
121  src->timers[IGMP_SRC_TIMER_EXP] =
122  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_SRC),
124 }
125 
126 void
128 {
129  IGMP_DBG ("block-src: (%U)", format_igmp_key, src->key);
130 
132 
133  src->timers[IGMP_SRC_TIMER_EXP] =
134  igmp_timer_schedule (igmp_timer_type_get (IGMP_TIMER_LEAVE),
136 }
137 
138 u32
140 {
141  return (src - igmp_main.srcs);
142 }
143 
144 
145 /*
146  * fd.io coding-style-patch-verification: ON
147  *
148  * Local Variables:
149  * eval: (c-set-style "gnu")
150  * End:
151  */
u8 * format_igmp_key(u8 *s, va_list *args)
Definition: igmp_format.c:188
void igmp_timer_retire(igmp_timer_id_t *tid)
Definition: igmp_timer.c:222
u32 group
The group this source is on.
Definition: igmp_src.h:57
igmp_main_t igmp_main
Definition: igmp.c:36
#define NULL
Definition: clib.h:55
u32 timers[IGMP_SRC_N_TIMERS]
Timers.
Definition: igmp_src.h:67
void igmp_src_blocked(igmp_src_t *src)
Definition: igmp_src.c:127
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:228
void igmp_src_free(igmp_src_t *src)
Definition: igmp_src.c:23
#define IGMP_DBG(...)
Definition: igmp.h:37
igmp_timer_id_t igmp_timer_schedule(f64 when, u32 obj, igmp_timer_function_t fn, void *data)
Scehdule a timer to expire in &#39;when&#39; seconds.
Definition: igmp_timer.c:196
void igmp_src_refresh(igmp_src_t *src)
Definition: igmp_src.c:115
u32 igmp_timer_type_get(igmp_timer_type_t t)
Definition: igmp_timer.c:68
igmp_src_t * igmp_src_alloc(u32 group_index, const igmp_key_t *skey, igmp_mode_t mode)
Definition: igmp_src.c:71
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:382
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:464
u32 config
The pool index of the config object this group is in.
Definition: igmp_group.h:76
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:274
collection of data related to IGMP
Definition: igmp.h:62
#define clib_memcpy(a, b, c)
Definition: string.h:75
#define IGMP_TIMER_ID_INVALID
Definition: igmp_timer.h:28
igmp_group_t * igmp_group_get(u32 index)
Definition: igmp_group.c:261
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:139
static void clib_mem_free(void *p)
Definition: mem.h:179
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:112
IGMP interface configuration.
Definition: igmp_config.h:43
igmp_key_t * key
The group&#39;s key within the per-interface config.
Definition: igmp_group.h:58
IGMP group A multicast group address for which reception has been requested.
Definition: igmp_group.h:55
igmp_key_t * key
The source&#39;s key.
Definition: igmp_src.h:46
enum igmp_mode_t_ igmp_mode_t
u32 igmp_group_n_srcs(const igmp_group_t *group, igmp_filter_mode_t mode)
Definition: igmp_group.c:233
void igmp_group_clear(igmp_group_t *group)
Definition: igmp_group.c:68
igmp_src_t * srcs
pool of sources
Definition: igmp.h:103
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