FD.io VPP  v18.07-rc0-415-g6c78436
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, igmp_type_t);
25  igmp_main_t *im = &igmp_main;
26  igmp_type_info_t *ti = igmp_get_type_info (im, type);
27 
28  if (ti)
29  return format (s, "%s", ti->name);
30  else
31  return format (s, "unknown %d", type);
32 }
33 
34 u8 *
35 format_igmp_report_type (u8 * s, va_list * args)
36 {
38  va_arg (*args, igmp_membership_group_v3_type_t);
39  igmp_main_t *im = &igmp_main;
40  igmp_report_type_info_t *rti = igmp_get_report_type_info (im, report_type);
41 
42  if (rti)
43  return format (s, "%s", rti->name);
44  else
45  return format (s, "unknown %d", report_type);
46 }
47 
48 u8 *
49 format_igmp_header (u8 * s, va_list * args)
50 {
51  igmp_header_t *hdr = va_arg (*args, igmp_header_t *);
52  u32 max_header_bytes = va_arg (*args, u32);
53  u32 indent;
54 
55  if (max_header_bytes < sizeof (hdr[0]))
56  return format (s, "IGMP header truncated");
57 
58  indent = format_get_indent (s);
59  indent += 2;
60 
61  s =
62  format (s, "%U%U: code %u, checksum 0x%04x", format_white_space, indent,
63  format_igmp_type, hdr->type, hdr->code,
64  clib_net_to_host_u16 (hdr->checksum));
65  return s;
66 }
67 
68 u8 *
69 format_igmp_report_v3 (u8 * s, va_list * args)
70 {
72  va_arg (*args, igmp_membership_report_v3_t *);
73  u32 max_header_bytes = va_arg (*args, u32);
75 
76  u32 len = sizeof (igmp_membership_report_v3_t);
77  u32 indent;
78 
79  if (max_header_bytes < sizeof (igmp[0]))
80  return format (s, "IGMP report truncated");
81 
82  indent = format_get_indent (s);
83  indent += 2;
84 
85  s =
86  format (s, "%Un_groups %u", format_white_space, indent,
87  clib_net_to_host_u16 (igmp->n_groups));
88  indent += 2;
89  int i, j = 0;
90  for (i = 0; i < clib_net_to_host_u16 (igmp->n_groups); i++)
91  {
92  group = group_ptr (igmp, len);
93  s =
94  format (s, "\n%U%U: %U, sources %u", format_white_space, indent,
96  &group->dst_address,
97  clib_net_to_host_u16 (group->n_src_addresses));
98  indent += 2;
99  for (j = 0; j < clib_net_to_host_u16 (group->n_src_addresses); j++)
100  {
101  s =
102  format (s, "\n%U%U", format_white_space, indent,
103  format_ip4_address, &group->src_addresses[j]);
104  }
105  indent -= 2;
106  len +=
107  sizeof (igmp_membership_group_v3_t) +
108  (sizeof (ip4_address_t) *
109  clib_net_to_host_u16 (group->n_src_addresses));
110  }
111  return s;
112 }
113 
114 u8 *
115 format_igmp_query_v3 (u8 * s, va_list * args)
116 {
118  va_arg (*args, igmp_membership_query_v3_t *);
119  u32 max_header_bytes = va_arg (*args, u32);
120  u32 indent;
121  int i;
122 
123  if (max_header_bytes < sizeof (igmp[0]))
124  return format (s, "IGMP query truncated");
125 
126  indent = format_get_indent (s);
127  indent += 2;
128 
129  ip4_address_t tmp;
130  tmp.as_u32 = 0;
131 
132  if ((!ip4_address_compare (&igmp->dst, &tmp))
133  && (igmp->n_src_addresses == 0))
134  s = format (s, "%UGeneral Query", format_white_space, indent);
135  else if (igmp->n_src_addresses == 0)
136  s = format (s, "%UGroup-Specific Query: %U", format_white_space, indent,
137  format_ip4_address, &igmp->dst);
138  else
139  {
140  s =
141  format (s, "%UGroup-and-Source-Specific Query: %U",
142  format_white_space, indent, format_ip4_address, &igmp->dst);
143  indent += 2;
144  for (i = 0; i < clib_net_to_host_u16 (igmp->n_src_addresses); i++)
145  {
146  s = format (s, "\n%U%U", format_white_space, indent,
147  format_ip4_address, &igmp->src_addresses[i]);
148  }
149  }
150  return s;
151 }
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
igmp_membership_group_v3_type_t type
Definition: igmp_packet.h:121
ip4_address_t src_addresses[0]
Definition: igmp_packet.h:101
igmp_main_t igmp_main
Definition: igmp.c:34
igmp_membership_group_v3_type_t
Definition: igmp_packet.h:112
u8 * format_igmp_report_type(u8 *s, va_list *args)
Definition: igmp_format.c:35
int i
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:69
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
static igmp_report_type_info_t * igmp_get_report_type_info(igmp_main_t *im, u8 report_type)
Definition: igmp.h:372
u8 * format_igmp_header(u8 *s, va_list *args)
Definition: igmp_format.c:49
igmp_type_t type
Definition: igmp_packet.h:70
igmp main
Definition: igmp.h:198
int ip4_address_compare(ip4_address_t *a1, ip4_address_t *a2)
Definition: ip46_cli.c:53
u8 * format_igmp_query_v3(u8 *s, va_list *args)
Definition: igmp_format.c:115
ip4_address_t src_addresses[0]
Definition: igmp_packet.h:132
u8 * format_igmp_type(u8 *s, va_list *args)
Definition: igmp_format.c:22
static igmp_type_info_t * igmp_get_type_info(igmp_main_t *im, u32 type)
Definition: igmp.h:363
#define group_ptr(p, l)
helper macro to get igmp mebership group from pointer plus offset
Definition: igmp.h:46
igmp_type_t
Definition: igmp_packet.h:61