FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
igmp.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 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 #ifndef _IGMP_H_
19 #define _IGMP_H_
20 
21 #include <vlib/vlib.h>
22 #include <vnet/ip/ip.h>
24 #include <vnet/ip/igmp_packet.h>
25 #include <vnet/adj/adj_mcast.h>
26 #include <igmp/igmp_format.h>
27 
28 #define IGMP_QUERY_TIMER (60)
29 #define IGMP_SG_TIMER (3 * IGMP_QUERY_TIMER)
30 #define IGMP_DEFAULT_ROBUSTNESS_VARIABLE (2)
31 
32 #define IGMP_DBG 1
33 
34 #if IGMP_DBG
35 #define DBG(...) clib_warning(__VA_ARGS__)
36 #else
37 #define DBG(...)
38 #endif /* IGMP_DBG */
39 
40 #define group_ptr(p, l) ((igmp_membership_group_v3_t *)((char*)p + l))
41 
42 enum
43 {
46 
47 typedef enum
48 {
52 } igmp_ver_t;
53 
54 struct igmp_config_t_;
55 
57 
58 /* populate supplied bufefr with IGMP message */
59 typedef void (create_msg_t) (vlib_buffer_t * b, igmp_config_t * config);
60 
61 typedef struct igmp_index_t_
62 {
65 } igmp_index_t;
66 
67 typedef struct igmp_sg_key_t_
68 {
69  ip46_address_t gaddr;
70  ip46_address_t saddr;
72 
73 typedef struct igmp_sg_t_
74 {
75  ip46_address_t gaddr;
76  ip46_address_t saddr;
77 
79 
80  /* check if expired (S,G) timer is valid */
82 
84 } igmp_sg_t;
85 
86 typedef struct igmp_config_t_
87 {
89 
91 
93 
95 
97 
99 
101 #define IGMP_CONFIG_FLAG_QUERY_RESP_RECVED (1 << 0)
102 #define IGMP_CONFIG_FLAG_CAN_SEND_REPORT (1 << 1)
103 
105 
106  /* pool of (S,G)s per interface */
108 } igmp_config_t;
109 
110 struct igmp_timer_t_;
111 
113 
114 typedef struct
115 {
119 
120 typedef struct
121 {
125 
126 typedef struct igmp_main_t_
127 {
128  /** API message ID base */
130 
131  /* get api client by client_index */
133 
134  /** pool of api clients registered for join/leave notifications */
136 
137  /* get config index by config key */
139 
140  /** pool of igmp configurations */
142 
143  /** buffer cache */
145 
146  /* next report/deletion */
148 
149  /** pool of igmp timers */
151 
154 
157 
158 } igmp_main_t;
159 
160 extern igmp_main_t igmp_main;
161 
163  vlib_node_runtime_t * rt,
164  igmp_main_t * im, igmp_timer_t * timer);
165 
166 typedef struct igmp_timer_t_
167 {
170 
172  void *data;
173 } igmp_timer_t;
174 
179 
180 int igmp_listen (vlib_main_t * vm, u8 enable, u32 sw_if_index,
181  ip46_address_t saddr, ip46_address_t gaddr,
182  u8 cli_api_configured);
183 
184 void igmp_clear_config (igmp_config_t * config);
185 
187 
188 void igmp_create_int_timer (f64 time, u32 sw_if_index,
189  igmp_timer_function_t * func);
190 void igmp_create_sg_timer (f64 time, u32 sw_if_index, igmp_sg_key_t * key,
191  igmp_timer_function_t * func);
192 
194  igmp_main_t * im, igmp_timer_t * timer);
196  igmp_main_t * im, igmp_timer_t * timer);
198  igmp_main_t * im, igmp_timer_t * timer);
200  igmp_main_t * im, igmp_timer_t * timer);
202  igmp_main_t * im, igmp_timer_t * timer);
203 
204 static inline igmp_type_info_t *
206 {
207  uword *p;
208 
209  p = hash_get (im->type_info_by_type, type);
210  return p ? vec_elt_at_index (im->type_infos, p[0]) : 0;
211 }
212 
213 static inline igmp_report_type_info_t *
215 {
216  uword *p;
217 
218  p = hash_get (im->report_type_info_by_report_type, report_type);
219  return p ? vec_elt_at_index (im->report_type_infos, p[0]) : 0;
220 }
221 
222 void igmp_event (igmp_main_t * im, igmp_config_t * config, igmp_sg_t * sg);
223 
224 typedef enum
225 {
229 } igmp_next_t;
230 
231 
233 igmp_config_lookup (igmp_main_t * im, u32 sw_if_index)
234 {
235  uword *p;
236  igmp_config_t *config = NULL;
237 
238  p = hash_get (im->igmp_config_by_sw_if_index, sw_if_index);
239  if (p)
240  config = vec_elt_at_index (im->configs, p[0]);
241 
242  return config;
243 }
244 
247 {
248  uword *p;
249  igmp_sg_t *sg = NULL;
250  if (!config)
251  return NULL;
252 
253  p = hash_get_mem (config->igmp_sg_by_key, key);
254  if (p)
255  sg = vec_elt_at_index (config->sg, p[0]);
256 
257  return sg;
258 }
259 
260 #endif /* _IGMP_H_ */
261 
262 /*
263  * fd.io coding-style-patch-verification: ON
264  *
265  * Local Variables:
266  * eval: (c-set-style "gnu")
267  * End:
268  */
u32 sg_index
Definition: igmp.h:64
u32 sw_if_index
Definition: igmp.h:171
void * data
Definition: igmp.h:172
void igmp_query_resp_exp(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.c:435
void igmp_create_int_timer(f64 time, u32 sw_if_index, igmp_timer_function_t *func)
Definition: igmp.c:86
void igmp_sg_exp(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.c:513
Definition: igmp.h:49
igmp_index_t next_index
Definition: igmp.h:147
static igmp_sg_t * igmp_sg_lookup(igmp_config_t *config, igmp_sg_key_t *key)
Definition: igmp.h:246
#define NULL
Definition: clib.h:55
igmp_config_t * configs
pool of igmp configurations
Definition: igmp.h:141
igmp_ver_t
Definition: igmp.h:47
adj_index_t adj_index
Definition: igmp.h:90
struct igmp_index_t_ igmp_index_t
igmp_membership_group_v3_type_t
Definition: igmp_packet.h:112
vlib_node_registration_t igmp_parse_query_node
(constructor) VLIB_REGISTER_NODE (igmp_parse_query_node)
Definition: input.c:328
u16 msg_id_base
API message ID base.
Definition: igmp.h:129
void igmp_sort_timers(igmp_timer_t *timers)
Definition: igmp.c:68
ip46_address_t saddr
Definition: igmp.h:76
igmp_type_info_t * type_infos
Definition: igmp.h:152
struct igmp_sg_key_t_ igmp_sg_key_t
#define always_inline
Definition: clib.h:92
f64 exp_time
Definition: igmp.h:81
static timer_callback_t * timers
Definition: timer.c:57
igmp_type_t type
Definition: igmp.h:117
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static igmp_report_type_info_t * igmp_get_report_type_info(igmp_main_t *im, u8 report_type)
Definition: igmp.h:214
igmp_membership_group_v3_type_t group_type
Definition: igmp.h:78
Definition: igmp.h:50
#define hash_get(h, key)
Definition: hash.h:248
igmp_main_t igmp_main
Definition: igmp.c:34
enum @378 igmp_process_event_t
uword * igmp_config_by_sw_if_index
Definition: igmp.h:138
Definition: igmp.h:51
void( igmp_timer_function_t)(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.h:162
vlib_node_registration_t igmp_parse_report_node
(constructor) VLIB_REGISTER_NODE (igmp_parse_report_node)
Definition: input.c:525
vlib_main_t * vm
Definition: buffer.c:294
void igmp_event(igmp_main_t *im, igmp_config_t *config, igmp_sg_t *sg)
Definition: igmp_api.c:292
vpe_client_registration_t * api_clients
pool of api clients registered for join/leave notifications
Definition: igmp.h:135
vlib_node_registration_t igmp_input_node
(constructor) VLIB_REGISTER_NODE (igmp_input_node)
Definition: input.c:221
void igmp_clear_config(igmp_config_t *config)
Definition: igmp.c:38
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
int igmp_listen(vlib_main_t *vm, u8 enable, u32 sw_if_index, ip46_address_t saddr, ip46_address_t gaddr, u8 cli_api_configured)
Definition: igmp.c:595
igmp_next_t
Definition: igmp.h:224
void igmp_create_sg_timer(f64 time, u32 sw_if_index, igmp_sg_key_t *key, igmp_timer_function_t *func)
Definition: igmp.c:102
igmp_sg_key_t * key
Definition: igmp.h:83
unsigned int u32
Definition: types.h:88
void igmp_send_state_changed(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.c:479
ip46_address_t gaddr
Definition: igmp.h:69
igmp_sg_t * sg
Definition: igmp.h:107
void( create_msg_t)(vlib_buffer_t *b, igmp_config_t *config)
Definition: igmp.h:59
igmp_membership_group_v3_type_t type
Definition: igmp.h:123
u32 ** buffers
buffer cache
Definition: igmp.h:144
ip46_address_t saddr
Definition: igmp.h:70
struct igmp_sg_t_ igmp_sg_t
u8 robustness_var
Definition: igmp.h:98
uword * report_type_info_by_report_type
Definition: igmp.h:156
u64 uword
Definition: types.h:112
struct igmp_config_t_ igmp_config_t
Definition: igmp.h:56
void igmp_send_query(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.c:413
struct _vlib_node_registration vlib_node_registration_t
unsigned short u16
Definition: types.h:57
static igmp_config_t * igmp_config_lookup(igmp_main_t *im, u32 sw_if_index)
Definition: igmp.h:233
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u8 cli_api_configured
Definition: igmp.h:92
u32 sw_if_index
Definition: igmp.h:88
void igmp_send_report(vlib_main_t *vm, vlib_node_runtime_t *rt, igmp_main_t *im, igmp_timer_t *timer)
Definition: igmp.c:455
igmp_timer_t * timers
pool of igmp timers
Definition: igmp.h:150
#define hash_get_mem(h, key)
Definition: hash.h:268
f64 exp_time
Definition: igmp.h:168
ip46_address_t gaddr
Definition: igmp.h:75
uword * igmp_sg_by_key
Definition: igmp.h:104
struct igmp_main_t_ igmp_main_t
igmp_timer_function_t * func
Definition: igmp.h:169
uword * igmp_api_client_by_client_index
Definition: igmp.h:132
vlib_node_registration_t igmp_timer_process_node
(constructor) VLIB_REGISTER_NODE (igmp_timer_process_node)
Definition: igmp.c:581
static igmp_type_info_t * igmp_get_type_info(igmp_main_t *im, u32 type)
Definition: igmp.h:205
igmp_type_t
Definition: igmp_packet.h:61
u32 config_index
Definition: igmp.h:63
struct igmp_timer_t_ igmp_timer_t
Definition: igmp.h:112
igmp_ver_t igmp_ver
Definition: igmp.h:96
uword * type_info_by_type
Definition: igmp.h:155
igmp_report_type_info_t * report_type_infos
Definition: igmp.h:153
create_msg_t * next_create_msg
Definition: igmp.h:94