FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
igmp_format.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.h>
19 #include <vnet/ip/ip.h>
20 
21 u8 *
22 format_igmp_type (u8 * s, va_list * args)
23 {
24  igmp_type_t type = va_arg (*args, int);
25 
26  switch (type)
27  {
28 #define _(n,f) case IGMP_TYPE_##f: return (format (s, "%s", #f));
30 #undef _
31  }
32  return format (s, "unknown:%d", type);
33 }
34 
35 u8 *
37 {
38  igmp_membership_group_v3_type_t type = va_arg (*args, int);
39 
40  switch (type)
41  {
42 #define _(n,f) case IGMP_MEMBERSHIP_GROUP_##f: return (format (s, "%s", #f));
44 #undef _
45  }
46  return (format (s, "unknown:%d", type));
47 }
48 
49 u8 *
50 format_igmp_filter_mode (u8 * s, va_list * args)
51 {
52  igmp_filter_mode_t mode = va_arg (*args, igmp_filter_mode_t);
53 
54  switch (mode)
55  {
56 #define _(n,f) case IGMP_FILTER_MODE_##f: return (format (s, "%s", #f));
58 #undef _
59  }
60  return (format (s, "unknown:%d", mode));
61 
62 }
63 
64 u8 *
65 format_igmp_header (u8 * s, va_list * args)
66 {
67  igmp_header_t *hdr = va_arg (*args, igmp_header_t *);
68  u32 max_header_bytes = va_arg (*args, u32);
69  u32 indent;
70 
71  if (max_header_bytes < sizeof (hdr[0]))
72  return format (s, "IGMP header truncated");
73 
74  indent = format_get_indent (s);
75  indent += 2;
76 
77  s =
78  format (s, "%U%U: code %u, checksum 0x%04x", format_white_space, indent,
79  format_igmp_type, hdr->type, hdr->code,
80  clib_net_to_host_u16 (hdr->checksum));
81  return s;
82 }
83 
84 u8 *
85 format_igmp_report_v3 (u8 * s, va_list * args)
86 {
88  va_arg (*args, igmp_membership_report_v3_t *);
89  u32 max_header_bytes = va_arg (*args, u32);
91 
92  u32 len = sizeof (igmp_membership_report_v3_t);
93  u32 indent;
94 
95  if (max_header_bytes < sizeof (igmp[0]))
96  return format (s, "IGMP report truncated");
97 
98  indent = format_get_indent (s);
99  indent += 2;
100 
101  s =
102  format (s, "%Un_groups %u", format_white_space, indent,
103  clib_net_to_host_u16 (igmp->n_groups));
104  indent += 2;
105  int i, j = 0;
106  for (i = 0; i < clib_net_to_host_u16 (igmp->n_groups); i++)
107  {
108  group = group_ptr (igmp, len);
109  s =
110  format (s, "\n%U%U: %U, sources %u", format_white_space, indent,
113  clib_net_to_host_u16 (group->n_src_addresses));
114  indent += 2;
115  for (j = 0; j < clib_net_to_host_u16 (group->n_src_addresses); j++)
116  {
117  s =
118  format (s, "\n%U%U", format_white_space, indent,
119  format_ip4_address, &group->src_addresses[j]);
120  }
121  indent -= 2;
122  len +=
123  sizeof (igmp_membership_group_v3_t) +
124  (sizeof (ip4_address_t) *
125  clib_net_to_host_u16 (group->n_src_addresses));
126  }
127  return s;
128 }
129 
130 u8 *
131 format_igmp_query_v3 (u8 * s, va_list * args)
132 {
134  va_arg (*args, igmp_membership_query_v3_t *);
135  u32 max_header_bytes = va_arg (*args, u32);
136  u32 indent;
137  int i;
138 
139  if (max_header_bytes < sizeof (igmp[0]))
140  return format (s, "IGMP query truncated");
141 
142  indent = format_get_indent (s);
143  indent += 2;
144 
145  ip4_address_t tmp;
146  tmp.as_u32 = 0;
147 
148  if ((!ip4_address_compare (&igmp->group_address, &tmp))
149  && (igmp->n_src_addresses == 0))
150  s = format (s, "%UGeneral Query", format_white_space, indent);
151  else if (igmp->n_src_addresses == 0)
152  s = format (s, "%UGroup-Specific Query: %U", format_white_space, indent,
154  else
155  {
156  s =
157  format (s, "%UGroup-and-Source-Specific Query: %U",
159  &igmp->group_address);
160  indent += 2;
161  for (i = 0; i < clib_net_to_host_u16 (igmp->n_src_addresses); i++)
162  {
163  s = format (s, "\n%U%U", format_white_space, indent,
164  format_ip4_address, &igmp->src_addresses[i]);
165  }
166  }
167  return s;
168 }
169 
170 u8 *
171 format_igmp_src_addr_list (u8 * s, va_list * args)
172 {
173  ip46_address_t *ss, *srcs;
174 
175  srcs = va_arg (*args, ip46_address_t *);
176 
177  s = format (s, "[");
178  vec_foreach (ss, srcs)
179  {
180  s = format (s, "%U ", format_ip46_address, ss, IP46_TYPE_ANY);
181  }
182  s = format (s, "]");
183 
184  return (s);
185 }
186 
187 u8 *
188 format_igmp_key (u8 * s, va_list * args)
189 {
190  const igmp_key_t *key = va_arg (*args, const igmp_key_t *);
191 
192  s = format (s, "%U", format_ip46_address, key, IP46_TYPE_ANY);
193 
194  return (s);
195 }
196 
197 /*
198  * fd.io coding-style-patch-verification: ON
199  *
200  * Local Variables:
201  * eval: (c-set-style "gnu")
202  * End:
203  */
u8 * format_igmp_src_addr_list(u8 *s, va_list *args)
Definition: igmp_format.c:171
igmp_membership_group_v3_type_t type
Definition: igmp_packet.h:149
u8 * format_igmp_key(u8 *s, va_list *args)
Definition: igmp_format.c:188
ip4_address_t src_addresses[0]
Definition: igmp_packet.h:115
igmp_membership_group_v3_type_t
Definition: igmp_packet.h:140
int i
format_function_t format_ip46_address
Definition: format.h:61
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 * format_igmp_report_v3(u8 *s, va_list *args)
Definition: igmp_format.c:85
unsigned char u8
Definition: types.h:56
format_function_t format_ip4_address
Definition: format.h:81
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
unsigned int u32
Definition: types.h:88
u8 * format_igmp_header(u8 *s, va_list *args)
Definition: igmp_format.c:65
igmp_type_t type
Definition: igmp_packet.h:70
int ip4_address_compare(ip4_address_t *a1, ip4_address_t *a2)
Definition: ip46_cli.c:53
enum igmp_filter_mode_t_ igmp_filter_mode_t
u8 * format_igmp_filter_mode(u8 *s, va_list *args)
Definition: igmp_format.c:50
ip4_address_t group_address
Definition: igmp_packet.h:158
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
u8 * format_igmp_query_v3(u8 *s, va_list *args)
Definition: igmp_format.c:131
ip4_address_t src_addresses[0]
Definition: igmp_packet.h:160
#define vec_foreach(var, vec)
Vector iterator.
u8 * format_igmp_type(u8 *s, va_list *args)
Definition: igmp_format.c:22
#define group_ptr(p, l)
helper macro to get igmp mebership group from pointer plus offset
Definition: igmp.h:56
igmp_type_t
Definition: igmp_packet.h:61
u8 * format_igmp_membership_group_type(u8 *s, va_list *args)
Definition: igmp_format.c:36
ip4_address_t group_address
Definition: igmp_packet.h:105