FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
igmp_report.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_report.h>
19 #include <igmp/igmp_pkt.h>
20 
21 static ip46_address_t *
23 {
24  ip46_address_t *srcs = NULL;
25  const ip4_address_t *s;
26  u16 ii, n;
27 
28  /*
29  * we validated this packet when we accepted it in the DP, so
30  * this number is safe to use
31  */
32  n = clib_net_to_host_u16 (r->n_src_addresses);
33 
34  if (0 == n)
35  {
36  /* a (*,G) join has no source address specified */
37  vec_validate (srcs, 0);
38  srcs[0].ip4.as_u32 = 0;
39  }
40  else
41  {
42  vec_validate (srcs, n - 1);
43  s = r->src_addresses;
44 
45  for (ii = 0; ii < n; ii++)
46  {
47  srcs[ii].ip4 = *s;
48  s++;
49  }
50  }
51 
52  return (srcs);
53 }
54 
55 static void
58 {
59  ip46_address_t key = {
60  .ip4 = igmp_group->group_address,
61  };
62  u16 n;
63 
64  /*
65  * treat an exclude all sources as a *,G join
66  */
67  n = clib_net_to_host_u16 (igmp_group->n_src_addresses);
68 
69  if (0 == n)
70  {
71  ip46_address_t *src, *srcs;
72  igmp_group_t *group;
73 
74  group = igmp_group_lookup (config, &key);
76 
77  IGMP_DBG (" ..group-update: %U (*, %U)",
80 
81  if (NULL == group)
82  {
83  group = igmp_group_alloc (config, &key, IGMP_FILTER_MODE_INCLUDE);
84  }
85  vec_foreach (src, srcs)
86  {
87  igmp_group_src_update (group, src, IGMP_MODE_ROUTER);
88  }
89 
90  vec_free (srcs);
91  }
92  else
93  {
94  IGMP_DBG (" ..group-update: %U (*, %U) source exclude ignored",
97  }
98 }
99 
100 static void
103 {
104  ip46_address_t *s, *srcs;
106  igmp_group_t *group;
107  ip46_address_t key = {
108  .ip4 = igmp_group->group_address,
109  };
110 
112  group = igmp_group_lookup (config, &key);
113 
114  IGMP_DBG (" ..group-block: %U (%U, %U)",
116  vnet_get_main (), config->sw_if_index,
118 
119  if (group)
120  {
121  igmp_src_t *src;
122  /*
123  * send a group+source specific query
124  */
125  igmp_pkt_build_query_init (&bq, config->sw_if_index);
126  igmp_pkt_query_v3_add_group (&bq, group, srcs);
128 
129  /*
130  * for each source left/blocked drop the source expire timer to the leave
131  * latency timer
132  */
133  vec_foreach (s, srcs)
134  {
135  src = igmp_src_lookup (group, s);
136  if (NULL != src)
138  }
139  }
140  /*
141  * a block/leave from a group for which we have no state
142  */
143 
144  vec_free (srcs);
145 }
146 
147 static void
150 {
151  ip46_address_t *src, *srcs;
152  igmp_group_t *group;
153  ip46_address_t key = {
154  .ip4 = igmp_group->group_address,
155  };
156 
157  /*
158  * treat a TO_INC({}) as a (*,G) leave
159  */
160  if (0 == clib_net_to_host_u16 (igmp_group->n_src_addresses))
161  {
162  return (igmp_handle_group_block (config, igmp_group));
163  }
164 
166  group = igmp_group_lookup (config, &key);
167 
168  IGMP_DBG (" ..group-update: %U (%U, %U)",
170  vnet_get_main (), config->sw_if_index,
172 
173  if (NULL == group)
174  {
175  group = igmp_group_alloc (config, &key, IGMP_FILTER_MODE_INCLUDE);
176  }
177 
178  /* create or update all sources */
179  vec_foreach (src, srcs)
180  {
181  igmp_group_src_update (group, src, IGMP_MODE_ROUTER);
182  }
183 
184  vec_free (srcs);
185 }
186 
187 static void
190 {
191  IGMP_DBG ("rx-group-report: %U",
193  vnet_get_main (), config->sw_if_index);
194 
195  switch (igmp_group->type)
196  {
197  case IGMP_MEMBERSHIP_GROUP_mode_is_include:
198  case IGMP_MEMBERSHIP_GROUP_change_to_include:
199  case IGMP_MEMBERSHIP_GROUP_allow_new_sources:
201  break;
202  case IGMP_MEMBERSHIP_GROUP_block_old_sources:
204  break;
205  case IGMP_MEMBERSHIP_GROUP_mode_is_exclude:
206  case IGMP_MEMBERSHIP_GROUP_change_to_exclude:
208  break;
209  /*
210  * all other types ignored
211  */
212  }
213 }
214 
215 void
217 {
219  igmp_config_t *config;
220  u16 n_groups, ii;
221 
222  config = igmp_config_lookup (args->sw_if_index);
223 
224  if (!config)
225  /*
226  * no IGMP config on the interface. quit
227  */
228  return;
229 
230  if (IGMP_MODE_HOST == config->mode)
231  {
232  /*
233  * Hosts need not listen to the reports of other hosts.
234  * we're done here
235  */
236  return;
237  }
238 
239  /*
240  * we validated this packet when we accepted it in the DP, so
241  * this number is safe to use
242  */
243  n_groups = clib_net_to_host_u16 (args->report[0].n_groups);
244  igmp_group = args->report[0].groups;
245 
246  for (ii = 0; ii < n_groups; ii++)
247  {
248  igmp_handle_group (config, igmp_group);
249 
252  }
253 
254  igmp_proxy_device_merge_config (config, 0);
255 }
256 
257 /*
258  * fd.io coding-style-patch-verification: ON
259  *
260  * Local Variables:
261  * eval: (c-set-style "gnu")
262  * End:
263  */
igmp_src_t_
IGMP source The representation of a specified source address with in multicast group.
Definition: igmp_src.h:41
IGMP_DBG
#define IGMP_DBG(...)
Definition: igmp.h:38
igmp_report_args_t_
A copy of the report message sent from the worker to the main thread.
Definition: igmp_report.h:23
igmp_pkt_query_v3_add_group
void igmp_pkt_query_v3_add_group(igmp_pkt_build_query_t *bq, const igmp_group_t *group, const ip46_address_t *srcs)
Definition: igmp_pkt.c:447
igmp_config_t_
IGMP interface configuration.
Definition: igmp_config.h:47
igmp_src_lookup
igmp_src_t * igmp_src_lookup(igmp_group_t *group, const igmp_key_t *key)
igmp group lookup
Definition: igmp_group.c:258
igmp_pkt_query_v3_send
void igmp_pkt_query_v3_send(igmp_pkt_build_query_t *bq)
Definition: igmp_pkt.c:512
igmp_config_t_::sw_if_index
u32 sw_if_index
Definition: igmp_config.h:52
u16
unsigned short u16
Definition: types.h:57
igmp_group_t_
IGMP group A multicast group address for which reception has been requested.
Definition: igmp_group.h:56
igmp_report.h
igmp_report_args_t_::sw_if_index
u32 sw_if_index
Definition: igmp_report.h:25
igmp_membership_report_v3_t::n_groups
u16 n_groups
Definition: igmp_packet.h:187
igmp_config_lookup
igmp_config_t * igmp_config_lookup(u32 sw_if_index)
igmp config lookup
Definition: igmp_config.c:45
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
igmp_group_src_update
igmp_src_t * igmp_group_src_update(igmp_group_t *group, const igmp_key_t *skey, igmp_mode_t mode)
Definition: igmp_group.c:45
key
typedef key
Definition: ipsec_types.api:91
igmp_handle_group_exclude
static void igmp_handle_group_exclude(igmp_config_t *config, const igmp_membership_group_v3_t *igmp_group)
Definition: igmp_report.c:56
igmp_pkt_build_query_init
void igmp_pkt_build_query_init(igmp_pkt_build_query_t *bq, u32 sw_if_index)
Definition: igmp_pkt.c:522
igmp_membership_group_v3_length
static u32 igmp_membership_group_v3_length(const igmp_membership_group_v3_t *g)
Definition: igmp_packet.h:164
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
igmp_group_lookup
igmp_group_t * igmp_group_lookup(igmp_config_t *config, const igmp_key_t *key)
igmp group lookup
Definition: igmp_config.c:76
igmp_group_mk_source_list
static ip46_address_t * igmp_group_mk_source_list(const igmp_membership_group_v3_t *r)
Definition: igmp_report.c:22
group_cptr
#define group_cptr(p, l)
Definition: igmp.h:58
igmp_pkt_build_query_t_
Definition: igmp_pkt.h:55
igmp_handle_report
void igmp_handle_report(const igmp_report_args_t *args)
Definition: igmp_report.c:216
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
igmp_handle_group_block
static void igmp_handle_group_block(igmp_config_t *config, const igmp_membership_group_v3_t *igmp_group)
Definition: igmp_report.c:101
igmp_handle_group
static void igmp_handle_group(igmp_config_t *config, const igmp_membership_group_v3_t *igmp_group)
Definition: igmp_report.c:188
igmp_report_args_t_::report
igmp_membership_report_v3_t report[0]
Definition: igmp_report.h:26
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
igmp_membership_group_v3_t
Definition: igmp_packet.h:147
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
igmp_config_t_::mode
igmp_mode_t mode
Definition: igmp_config.h:62
igmp_src_blocked
void igmp_src_blocked(igmp_src_t *src)
Definition: igmp_src.c:129
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
igmp_handle_group_update
static void igmp_handle_group_update(igmp_config_t *config, const igmp_membership_group_v3_t *igmp_group)
Definition: igmp_report.c:148
format_igmp_src_addr_list
u8 * format_igmp_src_addr_list(u8 *s, va_list *args)
Definition: igmp_format.c:186
format_igmp_key
u8 * format_igmp_key(u8 *s, va_list *args)
Definition: igmp_format.c:203
igmp_proxy_device_merge_config
void igmp_proxy_device_merge_config(igmp_config_t *config, u8 block)
Definition: igmp_proxy.c:358
igmp_group_alloc
igmp_group_t * igmp_group_alloc(igmp_config_t *config, const igmp_key_t *gkey, igmp_filter_mode_t mode)
Definition: igmp_group.c:104
igmp_group
typedef igmp_group
Used by a 'host' to enable the reception/listening of packets for a specific multicast group.
Definition: igmp.api:66
igmp_pkt.h
igmp_membership_report_v3_t::groups
igmp_membership_group_v3_t groups[0]
Definition: igmp_packet.h:189